DEFLATE ã¯ãLZ77 ã¢ã«ãŽãªãºã ãšãããã³ç¬Šå·åïŒHuffman CodingïŒãçµã¿åããããéå¯éããŒã¿å§çž®ã¢ã«ãŽãªãºã ã§ããå ã 㯠Phil Katz ã圌㮠PKZIP ãœãããŠã§ã¢ã®ç¬¬ 2 çã§å®çŸ©ããåŸã« RFC 1951 ã§æšæºåãããŸãããDEFLATE ã¯ãzipãgzipãããã³ png ãã¡ã€ã«ã§äœ¿çšãããŠããŸãã
ã€ã³ãããã¯ã·ã§ã³#
DEFLATE ã¢ã«ãŽãªãºã ã¯ãæ¹è¯ããã LZ77 å§çž®ã¢ã«ãŽãªãºã ãš Huffman 笊å·åã¢ã«ãŽãªãºã ã§æ§æãããŠããŸããæ¹è¯ããã LZ77 ã¢ã«ãŽãªãºã ãš Huffman 笊å·åã¢ã«ãŽãªãºã ã¯ãå ã®ã¢ã«ãŽãªãºã ã®åºæ¬åçãä¿æããªãããå§çž®é床ãåäžãããã¢ã«ãŽãªãºã ã®æè»æ§ãé«ããé©å¿æ§ãæãããããã«æ¹è¯ãããŠããŸãã
DEFLATE ã¢ã«ãŽãªãºã ã§ã¯ããŸãæ¹è¯ããã LZ77 ã¢ã«ãŽãªãºã ã䜿çšããŠå ã®ããŒã¿ãå§çž®ãã次ã«æ¹è¯ããã Huffman 笊å·åã䜿çšã㊠LZ77 å§çž®ããŒã¿ãäºæ¬¡å§çž®ããŸããæçµçãªå§çž®ããŒã¿ã¯ãHuffman 笊å·åããã LZ77 å§çž®ããŒã¿ã§ãã
æ¹è¯ããã LZ77#
LZ77 å§çž®ã¢ã«ãŽãªãºã ã¯ããã¹ãŠã®ããŒã¿ãäžã€çµã®æååãšããŠåŠçããåäžã€çµã¯å°ãªããšã 3 ãã€ãã§è¡šãããŸããåçèŸæžã«äžèŽããæååãèŠã€ãããªãå Žåã1 ãã€ãã 3 ãã€ãã«åºåãããããããã€ãã®æµªè²»ãçºçããŸãããã®ãããDEFLATE ã¢ã«ãŽãªãºã ã§ã¯ã以äžã®æ¹è¯ãè¡ãããŠããŸãïŒ
- é·ãã 3 æªæºã®äžèŽããæååã¯å§çž®ããªãããªããªããé·ãã 3 æªæºã®æååã¯ãäžã€çµã§è¡šããããããå ã®ããŒã¿ãå§çž®ããå¹æããªãããã§ãã
- æååã®äžèŽé·ãå¶éããç¯å²ã¯ïŒ-128ã127ïŒã§ããã8 ãããã§è¡šãããŸããã¹ã©ã€ãã£ã³ã°ãŠã£ã³ããŠã®ãµã€ãºã¯ 32KB ã§ããã15 ãããã§è¡šãããŸããå§çž®ããŒã¿ã¯ãèå¥å + ããŒã¿ã®åœ¢åŒã§æ§ç¯ãããŸããå ·äœçãªå 容ã¯ä»¥äžã®è¡šã«ç€ºãããŠããŸãããã®ã¹ãã¬ãŒãžæ¹åŒã«ãããå§çž®ããŒã¿ã®ã¹ãã¬ãŒãžã¹ããŒã¹ãåæžãããŸãã
- 3 以äžã®äžèŽé·ã®æååã®ã¿ãæ€çŽ¢ãããããã¢ã«ãŽãªãºã ã®é床ãåäžãããããã«ãäžèŽããæååã®æ€çŽ¢æã«ããã·ã¥ãã§ã€ã³æ§é ã®æ€çŽ¢ã¢ã«ãŽãªãºã ã䜿çšããŠããŸããããã·ã¥ã¢ã«ãŽãªãºã 㯠3 ãã€ãã 2 ãã€ãã«å§çž®ããŸããããã·ã¥ãã§ã€ã³æ§é ã«ã¯èª€ã£ãçµæãåŸãããå¯èœæ§ããããŸãããæ€çŽ¢é床ã¯å€§å¹ ã«åäžããŸãã
å ã®ããŒã¿ | å§çž®åŸããŒã¿ | ||
---|---|---|---|
èå¥å(1ããã) | ããŒã¿(8ããã) | ãªãã»ãã(15ããã) | |
äžèŽé·ã3æªæº | 0 | å ã®ããŒã¿ | ãªã |
äžèŽé·ã3ä»¥äž | 1 | äžèŽé· | ãªãã»ããè·é¢ |
æ¹è¯ããã Huffman#
Huffman 笊å·åãããå§çž®ããŒã¿ã¯ãã³ãŒãè¡šãšç¬Šå·åããŒã¿ã® 2 ã€ã®éšåã§æ§æãããŠããŸããDEFLATE ã¢ã«ãŽãªãºã ã§äœ¿çšããã Huffman 笊å·åã¢ã«ãŽãªãºã ã¯ãã³ãŒãè¡šã®çææ¹æ³ã«ãã£ãŠéç Huffman 笊å·åãšåç Huffman 笊å·åã«åããããŸããéç Huffman 笊å·åã¯äºåã«å®çŸ©ãããã³ãŒãè¡šã䜿çšããåžžã«åºå®ãããŠãããããå§çž®ããŒã¿ã«æ ŒçŽããå¿ èŠã¯ãããŸãããåç Huffman 笊å·åã¯ãåŠçããããŒã¿ã®ç¶æ³ã«å¿ããŠåçãªã³ãŒãè¡šãçæããå§çž®ããŒã¿ã«æ ŒçŽããå¿ èŠããããŸããDEFLATE ã¢ã«ãŽãªãºã ã§ã¯ãäž»ã«åç Huffman 笊å·åã¢ã«ãŽãªãºã ãæ¹è¯ããŠããŸãïŒ
- åºå®ããã Huffman ã³ãŒãè¡šã®çæã«ãŒã«ãHuffman 笊å·åã®æ§é ãããããããã«ãåãããŒã¿ã§ãäºåæšã®çææ¹æ³ãé åºãç°ãªããããç°ãªã Huffman ã³ãŒãè¡šãåŸãããŸããåºå®ãããäºåæšã®çææ¹æ³ãšé åºã䜿çšããããšã§ãåãããŒã¿ã«å¯ŸããŠåã Huffman ã³ãŒãè¡šãåŸãããããã«ããŠããŸãã
- ã³ãŒãé·ãèšé²ããããã®ã³ãŒãè¡šã䜿çšããã³ãŒãè¡šã®äœ¿çšããã¹ãã¬ãŒãžã¹ããŒã¹ãããã«å§çž®ããŸããããã«ããã1 ãã€ã㧠1 ãã 256 ã®ã³ãŒãé·ãè¡šãããšãã§ããŸãã
- æ ŒçŽããå¿ èŠã®ãã Huffman ã³ãŒãè¡šãäºæ¬¡çã«å§çž®ããŸããDEFLATE ã¢ã«ãŽãªãºã ã§ã¯ãæçµçã« 3 ã€ã® Huffman ã³ãŒãè¡šã䜿çšããHuffman ã³ãŒãè¡šã®æ ŒçŽãå®çŸããŠããŸãã
æ¹è¯ããã Huffman 笊å·åã¢ã«ãŽãªãºã ã¯ãæŒç®é床ãèæ ®ããªãããå§çž®ããŒã¿ã®ã¹ãã¬ãŒãžã¹ããŒã¹ãå¹æçã«æžãããŠããŸãã
DEFLATE åŠçãããŒ#
DEFLATE ã¯ãå§çž®ãããã¹ãŠã®ããŒã¿ããã€ããªããŒã¿ã¹ããªãŒã ãšããŠæ±ããåºæ¬çãªåŠçèŠçŽ ã¯ãã€ãã§ããHuffman 笊å·åã¢ã«ãŽãªãºã ã¯ãDEFLATE ã¢ã«ãŽãªãºã ã«ãã£ãŠå§çž®æ¯ã«å¿ããŠèªåçã«åçãŸãã¯éçãªç¬Šå·åãéžæãããŸããåç Huffman 笊å·åã䜿çšãã DEFLATE ã¢ã«ãŽãªãºã ã®å ·äœçãªåŠçãããŒã¯ã以äžã®å³ 1 ã«ç€ºãããŠããŸãããŸããå ã®ããŒã¿ã LZ77 å§çž®åŠçãã察å¿ããè¡šã®ããŒã¿ãæ§æãããèå¥å + ããŒã¿ããšããªãã»ãããã® 2 ã€ã®ããŒã¿ãåŸãŸãã次ã«ãHuffman 笊å·åã¢ã«ãŽãªãºã ã䜿çšããŠã2 ã€ã®ããŒã¿ãããããå§çž®ãããã³ãŒãè¡š 1ããšãã³ãŒãè¡š 2ããããã³ 2 ã€ã®ã³ãŒãè¡šã§ç¬Šå·åãããå§çž®ããŒã¿ãå§çž®ããŒã¿ 1ããšãå§çž®ããŒã¿ 2ããåŸãŸããæåŸã«ããã³ãŒãè¡š 1ããšãã³ãŒãè¡š 2ããåŒãç¶ã Huffman 笊å·åããŠããã³ãŒãè¡š 3ããšãå§çž®ããŒã¿ 3ããåŸãŸãã
äžèšã®åŠçãçµãŠãå ã®ããŒã¿ã¯å§çž®ãããéç Huffman 笊å·åã䜿çšãã DEFLATE ã¢ã«ãŽãªãºã ã§ã¯ããå§çž®ããŒã¿ 1ããšãå§çž®ããŒã¿ 2ããæ ŒçŽããå¿ èŠããããŸããåç Huffman 笊å·åã䜿çšãã DEFLATE ã¢ã«ãŽãªãºã ã§ã¯ããå§çž®ããŒã¿ 1ãããå§çž®ããŒã¿ 2ãããå§çž®ããŒã¿ 3ããããã³ãã³ãŒãè¡š 3ããæ ŒçŽããå¿ èŠããããŸããããã¯å§çž®ããã»ã¹ã®éæäœã§ãã解åã«ãªããŸãã