{"id":755,"date":"2013-09-20T21:30:31","date_gmt":"2013-09-20T13:30:31","guid":{"rendered":"http:\/\/guoh.ai\/lifelog\/?p=755"},"modified":"2013-11-09T12:57:39","modified_gmt":"2013-11-09T04:57:39","slug":"jpeg-huffman-code-by-hand","status":"publish","type":"post","link":"https:\/\/guoh.ai\/lifelog\/2013\/09\/jpeg-huffman-code-by-hand\/","title":{"rendered":"\u624b\u5de5\u8fdb\u884c\u56fe\u7247Huffman\u7f16\u7801"},"content":{"rendered":"<p>\u8fd9\u91cc\u6709\u7bc7\u6587\u7ae0\u8bb2\u89e3\u5982\u4f55\u8fdb\u884cHuffman\u7f16\u7801\u7684<a href=\"http:\/\/www.impulseadventure.com\/photo\/jpeg-huffman-coding.html\" target=\"_blank\">JPEG Huffman Coding Tutorial<\/a>\uff0c\u5199\u7684\u8fd8\u662f\u5f88\u6e05\u6670\uff0c\u6211\u672c\u6765\u6253\u7b97\u7ffb\u8bd1\u4e00\u4e0b\u8fd9\u7bc7\u6587\u7ae0\uff0c\u4f46\u662f\u60f3\u60f3\u89c9\u5f97\u8fd8\u662f\u914d\u5408\u5b83\u7684\u601d\u8def\u4ee5\u4e0d\u540c\u7684\u89d2\u5ea6\u518d\u5199\u4e00\u7bc7\uff0c\u5b83\u662f\u89e3\u7801\u65b9\u5f0f\uff0c\u6211\u8fd9\u91cc\u662f\u4ee5\u7f16\u7801\u65b9\u5f0f\u6765\u63cf\u8ff0\uff0c\u5b83\u7684Y:Cb:Cr\u662f1:1:1\uff0c\u6211\u8fd9\u91cc\u662f4:1:1\uff0c\u5f53\u7136\u5b83\u662f\u82f1\u6587\u7684\uff0c\u6211\u662f\u4e2d\u6587\u7684 @@\u3002<\/p>\n<p>JPEG\/Huffman\u7f16\u7801\u57fa\u7840\u77e5\u8bc6\u4e0d\u4e86\u89e3\u7684\u8fd8\u662f\u8981\u5148\u5b66\u4e60\u4e0b\u57fa\u7840\u77e5\u8bc6\uff0c\u53ef\u4ee5\u53c2\u8003<a href=\"http:\/\/guoh.ai\/lifelog\/2013\/09\/memos-about-jpeg\/\" target=\"_blank\">JPEG\u5b66\u4e60\u7b14\u8bb0<\/a>\uff0c\u5426\u5219\u4f60\u53ef\u80fd\u65e0\u6cd5\u770b\u61c2\u8fd9\u91cc\u5728\u8bf4\u4ec0\u4e48\u3002<br \/>\n\u7b80\u5355\u56de\u987e\u4e0bJPEG\u7f16\u7801\u8fc7\u7a0b\uff0c\u8fd9\u91cc\u6211\u4eec\u5047\u8bbeRGB->JPEG\uff1a<\/p>\n<blockquote><p>\n\u8272\u5f69\u7a7a\u95f4\u8f6c\u6362<br \/>\n\u6b63\u5411\u79bb\u6563\u4f59\u5f26\u53d8\u6362<br \/>\n\u91cf\u5316(\u9700\u8981\u91cf\u5316\u8868)<br \/>\nHuffman\u7f16\u7801(\u9700\u8981Huffman\u7f16\u7801\u8868)<br \/>\n\u751f\u6210\u56fe\u7247\u6d41(\u6309\u7167JFIF\u683c\u5f0f)\n<\/p><\/blockquote>\n<p>\u5176\u5b83\u7684\u6211\u4eec\u90fd\u4e0d\u8bf4\u4e86\uff0c\u76f4\u63a5\u5f00\u59cb\u5427\uff0c\u5982\u679c\u4f60\u73b0\u5728\u89c9\u5f97\u4e0a\u9762\u7684\u6982\u5ff5\/\u539f\u7406\u8fd8\u4e0d\u662f\u5f88\u7406\u89e3\uff0c\u8fd8\u6765\u7684\u6025\uff0c\u8bf7\u8df3\u8f6c\u5230\u6587\u7ae0\u9876\u90e8\u4ece\u5934\u5f00\u59cb\u8bfb\u3002<br \/>\n\u6709\u4e9b\u4e2d\u95f4\u6570\u636e\u7684\u63a8\u7406\u662f\u901a\u8fc7<a href=\"http:\/\/www.impulseadventure.com\/photo\/jpeg-snoop.html\" target=\"_blank\">JPEGsnoop<\/a>\u6216\u8005\u624b\u5de5\u8fdb\u884c\u7684\uff0c\u6240\u4ee5\u4f60\u4e5f\u8981\u719f\u6089\u3002<\/p>\n<p>\u5047\u8bbe\u6211\u4eec\u6709RGB\u6570\u636e\uff0c\u8fd9\u91cc\u6211\u7528\u7684\u662f<a href=\"https:\/\/github.com\/guohai\/jpeg\/blob\/master\/test.bmp\" target=\"_blank\">test.bmp<\/a>\uff0c\u4e00\u5f2016&#215;8\u7684\u7684\u767d\u9ed1\u4f4d\u56fe(\u5de6DU\u767d\uff0c\u53f3DU\u9ed1)\uff0c\u53ef\u4ee5\u752816\u8fdb\u5236\u5de5\u5177\u6253\u5f00\u6765\u67e5\u770b\uff0c\u5b9e\u9645\u6570\u636e\u5c31\u662f\uff1a<\/p>\n<blockquote><p>\nFF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\n<\/p><\/blockquote>\n<p>\u5047\u8bbe\u6211\u4eec\u6709SOF\u6570\u636e<br \/>\n8\u4f4d\u6570\u636e\u6837\u672c(1\u5b57\u8282)<br \/>\n\u56fe\u50cf\u9ad8\u5ea6\u4e3a8(2\u5b57\u8282)<br \/>\n\u56fe\u50cf\u5bbd\u5ea6\u4e3a16(2\u5b57\u8282)<br \/>\n\u989c\u8272\u5206\u91cf\u6570\uff0cJPEG\u90fd\u662fYCrCb\uff0c\u53733(1\u5b57\u8282)<br \/>\n\u989c\u8272\u5206\u91cf\u4fe1\u606f\uff0c\u5927\u5c0f\u662f\u989c\u8272\u5206\u91cf\u6570 multiply 3<br \/>\n\u56e0\u4e3a\u5206\u91cf\u4fe1\u606f\u4e2d\u989c\u8272\u5206\u91cfID\u5360\u75281\u4e2a\u5b57\u8282\uff0c\u6c34\u5e73\/\u5782\u76f4\u56e0\u5b50\u5360\u75281\u4e2a\u5b57\u8282(\u9ad84\u4f4d\u6c34\u5e73\uff0c\u4f4e4\u4f4d\u5782\u76f4)\uff0c\u91cf\u5316\u8868\u5360\u75281\u4e2a\u5b57\u8282<br \/>\nH 2:1:1<br \/>\nV 2:1:1<br \/>\n\u6240\u4ee5\u603b\u4f53\u91c7\u6837\u56e0\u5b50\u5c31\u662f(2 * 2):(1 * 1):(1 * 1)\uff0c\u53734:1:1<\/p>\n<p>MCU\u5bbd\u662f\u6c34\u5e73\u91c7\u6837\u56e0\u5b50\u6700\u5927\u503c multiply 8(\u8bb0\u8be5\u6700\u5927\u503c\u4e3aHmax)<br \/>\nMCU\u9ad8\u662f\u5782\u76f4\u91c7\u6837\u56e0\u5b50\u6700\u5927\u503c multiply 8(\u8bb0\u8be5\u6700\u5927\u503c\u4e3aVmax)<br \/>\n\u56e0\u6b64\u8fd9\u91cc\u5c31\u662f(Hmax * 8):(Vmax * 8) = 16:16<\/p>\n<p>\u5982\u679c\u6574\u5e45\u56fe\u7247\u7684\u9ad8\u5ea6\u6216\u8005\u5bbd\u5ea6\u4e0d\u662fMCU\u7684\u6574\u6570\u500d\uff0c\u5c31\u9700\u8981padding\uff0c\u89e3\u7801\u4e4b\u540e\u4e22\u5f03\u5927\u4e8e\u5bbd\u5ea6\u6216\u8005\u9ad8\u5ea6\u90e8\u5206\u7684\u6570\u636e<br \/>\n\u5728\u6570\u636e\u6d41\u5f53\u4e2d\uff0cMCU\u662f\u6309\u4ece\u5de6\u5230\u53f3\uff0c\u4ece\u4e0a\u5230\u4e0b\u6765\u6392\u5217\u7684\u3002<br \/>\n\u56e0\u4e3a\u6bcf\u4e2aMCU\u7531\u82e5\u5e72\u6570\u636e\u5355\u5143\u7ec4\u6210\uff0c\u800c\u6570\u636e\u5355\u5143\u53c8\u5fc5\u987b\u662f8:8\u7684\uff0c\u6240\u4ee5MCU\u5f53\u4e2d\u6570\u636e\u5355\u5143\u7684\u4e2a\u6570\u5c31\u662f4(Hmax * Vmax)<\/p>\n<p>\u7ec4\u88c5\u8d77\u6765\u53ef\u80fd\u5c31\u5982\u4e0b\uff1a<\/p>\n<blockquote><p>FF C0 00 11 08 00 08 00 10 03 01 22 00 02 11 01 03 11 01<\/p><\/blockquote>\n<p>DHT(FF C4)\u5982\u4e0b(\u8fd9\u91cc\u7684Huffman\u7f16\u7801\u8868\u662f\u6807\u51c6\u7684\uff0c\u6ca1\u6709\u4f18\u5316\u8fc7\u7684)<\/p>\n<blockquote><p>\nFF C4 00 1F 00 00 01 05 01 01 01 01 01 01 00 00 00 00 00 00 00 00 01 02 03 04 05 06 07 08 09 0A 0B FF C4 00 B5 10 00 02 01 03 03 02 04 03 05 05 04 04 00 00 01 7D 01 02 03 00 04 11 05 12 21 31 41 06 13 51 61 07 22 71 14 32 81 91 A1 08 23 42 B1 C1 15 52 D1 F0 24 33 62 72 82 09 0A 16 17 18 19 1A 25 26 27 28 29 2A 34 35 36 37 38 39 3A 43 44 45 46 47 48 49 4A 53 54 55 56 57 58 59 5A 63 64 65 66 67 68 69 6A 73 74 75 76 77 78 79 7A 83 84 85 86 87 88 89 8A 92 93 94 95 96 97 98 99 9A A2 A3 A4 A5 A6 A7 A8 A9 AA B2 B3 B4 B5 B6 B7 B8 B9 BA C2 C3 C4 C5 C6 C7 C8 C9 CA D2 D3 D4 D5 D6 D7 D8 D9 DA E1 E2 E3 E4 E5 E6 E7 E8 E9 EA F1 F2 F3 F4 F5 F6 F7 F8 F9 FA FF C4 00 1F 01 00 03 01 01 01 01 01 01 01 01 01 00 00 00 00 00 00 01 02 03 04 05 06 07 08 09 0A 0B FF C4 00 B5 11 00 02 01 02 04 04 03 04 07 05 04 04 00 01 02 77 00 01 02 03 11 04 05 21 31 06 12 41 51 07 61 71 13 22 32 81 08 14 42 91 A1 B1 C1 09 23 33 52 F0 15 62 72 D1 0A 16 24 34 E1 25 F1 17 18 19 1A 26 27 28 29 2A 35 36 37 38 39 3A 43 44 45 46 47 48 49 4A 53 54 55 56 57 58 59 5A 63 64 65 66 67 68 69 6A 73 74 75 76 77 78 79 7A 82 83 84 85 86 87 88 89 8A 92 93 94 95 96 97 98 99 9A A2 A3 A4 A5 A6 A7 A8 A9 AA B2 B3 B4 B5 B6 B7 B8 B9 BA C2 C3 C4 C5 C6 C7 C8 C9 CA D2 D3 D4 D5 D6 D7 D8 D9 DA E2 E3 E4 E5 E6 E7 E8 E9 EA F2 F3 F4 F5 F6 F7 F8 F9 FA\n<\/p><\/blockquote>\n<p>\u91cd\u6784Huffman\u7f16\u7801\u8868(\u8fd9\u6837\u624d\u6bd4\u8f83\u597d\u7406\u89e3\uff0c\u7f16\u7801\u8868\u5982\u4f55\u6784\u5efa\u51fa\u6765\uff0c\u53c2\u8003[JPEG\u5b66\u4e60\u7b14\u8bb0]\uff0c\u8fd9\u91cc\u53ea\u5217\u51fa\u9700\u8981\u7528\u5230\u7684\uff0c\u90e8\u5206\u6709\u7701\u7565)\uff0c4\u5f20\u8868\u5206\u522b\u4e3a\u76f4\u6d410(\u76f4\u6d41Y)\uff0c\u4ea4\u6d410(\u4ea4\u6d41Y)\uff0c\u76f4\u6d411(\u76f4\u6d41C)\uff0c\u4ea4\u6d411(\u4ea4\u6d41C)<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\n*** Marker: DHT (Define Huffman Table) (xFFC4) ***\r\n  OFFSET: 0x000000B1\r\n  Huffman table length = 31\r\n  ----\r\n  Destination ID = 0\r\n  Class = 0 (DC \/ Lossless Table)\r\n    Codes of length 01 bits (000 total): \r\n    Codes of length 02 bits (001 total): 00 \r\n    Codes of length 03 bits (005 total): 01 02 03 04 05 \r\n    Codes of length 04 bits (001 total): 06 \r\n    Codes of length 05 bits (001 total): 07 \r\n    Codes of length 06 bits (001 total): 08 \r\n    Codes of length 07 bits (001 total): 09 \r\n    Codes of length 08 bits (001 total): 0A \r\n    Codes of length 09 bits (001 total): 0B \r\n    Codes of length 10 bits (000 total): \r\n    Codes of length 11 bits (000 total): \r\n    Codes of length 12 bits (000 total): \r\n    Codes of length 13 bits (000 total): \r\n    Codes of length 14 bits (000 total): \r\n    Codes of length 15 bits (000 total): \r\n    Codes of length 16 bits (000 total): \r\n    Total number of codes: 012\r\n\r\nLength       Codeword        Code\r\n2            00              00(End of Block)\r\n3            010             01\r\n3            011             02\r\n3            100             03\r\n3            101             04\r\n3            110             05\r\n4            1110            06\r\n5            1111 0          07\r\n6            1111 10         08\r\n7            1111 110        09\r\n8            1111 1110       0A\r\n9            1111 1111 0     0B\r\n\r\n\r\n*** Marker: DHT (Define Huffman Table) (xFFC4) ***\r\n  OFFSET: 0x000000D2\r\n  Huffman table length = 181\r\n  ----\r\n  Destination ID = 0\r\n  Class = 1 (AC Table)\r\n    Codes of length 01 bits (000 total): \r\n    Codes of length 02 bits (002 total): 01 02 \r\n    Codes of length 03 bits (001 total): 03 \r\n    Codes of length 04 bits (003 total): 00 04 11 \r\n    Codes of length 05 bits (003 total): 05 12 21 \r\n    Codes of length 06 bits (002 total): 31 41 \r\n    Codes of length 07 bits (004 total): 06 13 51 61 \r\n    Codes of length 08 bits (003 total): 07 22 71 \r\n    Codes of length 09 bits (005 total): 14 32 81 91 A1 \r\n    Codes of length 10 bits (005 total): 08 23 42 B1 C1 \r\n    Codes of length 11 bits (004 total): 15 52 D1 F0 \r\n    Codes of length 12 bits (004 total): 24 33 62 72 \r\n    Codes of length 13 bits (000 total): \r\n    Codes of length 14 bits (000 total): \r\n    Codes of length 15 bits (001 total): 82 \r\n    Codes of length 16 bits (125 total): 09 0A 16 17 18 19 1A 25 26 27 28 29 2A 34 35 36 \r\n                                         37 38 39 3A 43 44 45 46 47 48 49 4A 53 54 55 56 \r\n                                         57 58 59 5A 63 64 65 66 67 68 69 6A 73 74 75 76 \r\n                                         77 78 79 7A 83 84 85 86 87 88 89 8A 92 93 94 95 \r\n                                         96 97 98 99 9A A2 A3 A4 A5 A6 A7 A8 A9 AA B2 B3 \r\n                                         B4 B5 B6 B7 B8 B9 BA C2 C3 C4 C5 C6 C7 C8 C9 CA \r\n                                         D2 D3 D4 D5 D6 D7 D8 D9 DA E1 E2 E3 E4 E5 E6 E7 \r\n                                         E8 E9 EA F1 F2 F3 F4 F5 F6 F7 F8 F9 FA \r\n    Total number of codes: 162\r\n\r\nLength  Codeword                    Code\r\n2       00                          01\r\n2       01                          02\r\n3       100                         03\r\n4       1010                        00(End of Block)\r\n4       1011                        04\r\n4       1100                        11\r\n5       1101 0                      05\r\n5       1101 1                      12\r\n5       1110 0                      21\r\n6       1110 10                     31\r\n6       1110 11                     41\r\n7       1111 000                    06\r\n7       1111 001                    13\r\n7       1111 010                    51\r\n7       1111 011                    61\r\n......\r\n\r\n\r\n*** Marker: DHT (Define Huffman Table) (xFFC4) ***\r\n  OFFSET: 0x00000189\r\n  Huffman table length = 31\r\n  ----\r\n  Destination ID = 1\r\n  Class = 0 (DC \/ Lossless Table)\r\n    Codes of length 01 bits (000 total): \r\n    Codes of length 02 bits (003 total): 00 01 02 \r\n    Codes of length 03 bits (001 total): 03 \r\n    Codes of length 04 bits (001 total): 04 \r\n    Codes of length 05 bits (001 total): 05 \r\n    Codes of length 06 bits (001 total): 06 \r\n    Codes of length 07 bits (001 total): 07 \r\n    Codes of length 08 bits (001 total): 08 \r\n    Codes of length 09 bits (001 total): 09 \r\n    Codes of length 10 bits (001 total): 0A \r\n    Codes of length 11 bits (001 total): 0B \r\n    Codes of length 12 bits (000 total): \r\n    Codes of length 13 bits (000 total): \r\n    Codes of length 14 bits (000 total): \r\n    Codes of length 15 bits (000 total): \r\n    Codes of length 16 bits (000 total): \r\n    Total number of codes: 012\r\n\r\nLength     Codeword            Code\r\n2          00                  00(End of Block)\r\n2          01                  01\r\n2          10                  02\r\n3          110                 03\r\n4          1110                04\r\n5          1111 0              05\r\n6          1111 10             06\r\n7          1111 110            07\r\n8          1111 1110           08\r\n9          1111 1111 0         09\r\n10         1111 1111 10        0A\r\n11         1111 1111 110       0B\r\n\r\n\r\n*** Marker: DHT (Define Huffman Table) (xFFC4) ***\r\n  OFFSET: 0x000001AA\r\n  Huffman table length = 181\r\n  ----\r\n  Destination ID = 1\r\n  Class = 1 (AC Table)\r\n    Codes of length 01 bits (000 total): \r\n    Codes of length 02 bits (002 total): 00 01 \r\n    Codes of length 03 bits (001 total): 02 \r\n    Codes of length 04 bits (002 total): 03 11 \r\n    Codes of length 05 bits (004 total): 04 05 21 31 \r\n    Codes of length 06 bits (004 total): 06 12 41 51 \r\n    Codes of length 07 bits (003 total): 07 61 71 \r\n    Codes of length 08 bits (004 total): 13 22 32 81 \r\n    Codes of length 09 bits (007 total): 08 14 42 91 A1 B1 C1 \r\n    Codes of length 10 bits (005 total): 09 23 33 52 F0 \r\n    Codes of length 11 bits (004 total): 15 62 72 D1 \r\n    Codes of length 12 bits (004 total): 0A 16 24 34 \r\n    Codes of length 13 bits (000 total): \r\n    Codes of length 14 bits (001 total): E1 \r\n    Codes of length 15 bits (002 total): 25 F1 \r\n    Codes of length 16 bits (119 total): 17 18 19 1A 26 27 28 29 2A 35 36 37 38 39 3A 43 \r\n                                         44 45 46 47 48 49 4A 53 54 55 56 57 58 59 5A 63 \r\n                                         64 65 66 67 68 69 6A 73 74 75 76 77 78 79 7A 82 \r\n                                         83 84 85 86 87 88 89 8A 92 93 94 95 96 97 98 99 \r\n                                         9A A2 A3 A4 A5 A6 A7 A8 A9 AA B2 B3 B4 B5 B6 B7 \r\n                                         B8 B9 BA C2 C3 C4 C5 C6 C7 C8 C9 CA D2 D3 D4 D5 \r\n                                         D6 D7 D8 D9 DA E2 E3 E4 E5 E6 E7 E8 E9 EA F2 F3 \r\n                                         F4 F5 F6 F7 F8 F9 FA \r\n    Total number of codes: 162\r\n\r\nLength  Codeword                    Code\r\n2       00                          00(End of Block)\r\n2       01                          01\r\n3       100                         02\r\n4       1010                        03\r\n4       1011                        11\r\n5       1100 0                      04\r\n5       1100 1                      05\r\n5       1101 0                      21\r\n5       1101 1                      31\r\n6       1110 00                     06\r\n6       1110 01                     12\r\n6       1110 10                     41\r\n6       1110 11                     51\r\n......\r\n<\/pre>\n<p>DQT(FF DB)\u5982\u4e0b<\/p>\n<blockquote><p>\nFF DB 00 43 00 05 03 04 04 04 03 05 04 04 04 05 05 05 06 07 0C 08 07 07 07 07 0F 0B 0B 09 0C 11 0F 12 12 11 0F 11 11 13 16 1C 17 13 14 1A 15 11 11 18 21 18 1A 1D 1D 1F 1F 1F 13 17 22 24 22 1E 24 1C 1E 1F 1E<br \/>\nFF DB 00 43 01 05 05 05 07 06 07 0E 08 08 0E 1E 14 11 14 1E 1E 1E 1E 1E 1E 1E 1E 1E 1E 1E 1E 1E 1E 1E 1E 1E 1E 1E 1E 1E 1E 1E 1E 1E 1E 1E 1E 1E 1E 1E 1E 1E 1E 1E 1E 1E 1E 1E 1E 1E 1E 1E 1E 1E 1E 1E 1E 1E 1E\n<\/p><\/blockquote>\n<p>0x0043\u4e3a\u6240\u5360\u5927\u5c0f<br \/>\n1\u4e2a\u5b57\u8282\u4e3aQT\u4fe1\u606f\uff0c\u9ad84\u4f4d\u4e3aQT\u7cbe\u5ea6(\u5728\u8fd9\u91cc\u7cbe\u5ea6\u6570\u636e\u90fd\u662f0)\uff0c\u4f4e4\u4f4d\u4e3aQT\u53f7<br \/>\n64\u5b57\u8282\u7684QT\u6570\u636e<br \/>\n\u8fd8\u539f\u6210\u77e9\u9635\u5f62\u5f0f(Zigzag)<br \/>\nQT 0<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\n5   3   3   5   7   12  15  18\r\n\r\n4   4   4   6   8   17  18  17\r\n\r\n4   4   5   7   12  17  21  17\r\n\r\n4   5   7   9   15  16  24  19\r\n\r\n5   7   11  17  20  33  31  23\r\n\r\n7   11  17  19  24  31  34  28\r\n\r\n15  19  23  26  31  36  36  30\r\n\r\n22  28  29  29  34  30  31  30\r\n<\/pre>\n<p>QT 1<br \/>\n\u7565<\/p>\n<p>\u524d\u63d0\u6761\u4ef6\u90fd\u6709\u4e86\uff0c\u5f00\u59cb\u505a\u53d8\u6362\u4e86\u3002<br \/>\n\u901a\u8fc7SOF\u6570\u636e\u6211\u4eec\u77e5\u9053\u67091\u4e2aMCU\uff0cY\u67094\u4e2aDU(2\u4e2a\u662f\u771f\u5b9e\u7684\u6570\u636e\uff0c2\u4e2a\u662f\u586b\u5145)\uff0cCb\u6709\u4e00\u4e2aDU\uff0cCr\u6709\u4e00\u4e2aDU\u3002<\/p>\n<p>RGB<br \/>\n\u7565<\/p>\n<p>DU 1(Y)<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\n255  255  255  255  255  255  255  255\r\n\r\n255  255  255  255  255  255  255  255\r\n\r\n255  255  255  255  255  255  255  255\r\n\r\n255  255  255  255  255  255  255  255\r\n\r\n255  255  255  255  255  255  255  255\r\n\r\n255  255  255  255  255  255  255  255\r\n\r\n255  255  255  255  255  255  255  255\r\n\r\n255  255  255  255  255  255  255  255\r\n<\/pre>\n<p>DU 1(-128)<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\n127  127  127  127  127  127  127  127\r\n\r\n127  127  127  127  127  127  127  127\r\n\r\n127  127  127  127  127  127  127  127\r\n\r\n127  127  127  127  127  127  127  127\r\n\r\n127  127  127  127  127  127  127  127\r\n\r\n127  127  127  127  127  127  127  127\r\n\r\n127  127  127  127  127  127  127  127\r\n\r\n127  127  127  127  127  127  127  127\r\n<\/pre>\n<p>DU 1(FDCT)<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\n1016 0    0    0    0    0    0    0\r\n\r\n0    0    0    0    0    0    0    0\r\n\r\n0    0    0    0    0    0    0    0\r\n\r\n0    0    0    0    0    0    0    0\r\n\r\n0    0    0    0    0    0    0    0\r\n\r\n0    0    0    0    0    0    0    0\r\n\r\n0    0    0    0    0    0    0    0\r\n\r\n0    0    0    0    0    0    0    0\r\n<\/pre>\n<p>DU 1(Quantization)<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\n203  0    0    0    0    0    0    0\r\n\r\n0    0    0    0    0    0    0    0\r\n\r\n0    0    0    0    0    0    0    0\r\n\r\n0    0    0    0    0    0    0    0\r\n\r\n0    0    0    0    0    0    0    0\r\n\r\n0    0    0    0    0    0    0    0\r\n\r\n0    0    0    0    0    0    0    0\r\n\r\n0    0    0    0    0    0    0    0\r\n<\/pre>\n<p>DU 2(Y)<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\n0    0    0    0    0    0    0    0\r\n\r\n0    0    0    0    0    0    0    0\r\n\r\n0    0    0    0    0    0    0    0\r\n\r\n0    0    0    0    0    0    0    0\r\n\r\n0    0    0    0    0    0    0    0\r\n\r\n0    0    0    0    0    0    0    0\r\n\r\n0    0    0    0    0    0    0    0\r\n\r\n0    0    0    0    0    0    0    0\r\n<\/pre>\n<p>DU 2(-128)<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\n-128 -128 -128 -128 -128 -128 -128 -128\r\n\r\n-128 -128 -128 -128 -128 -128 -128 -128\r\n\r\n-128 -128 -128 -128 -128 -128 -128 -128\r\n\r\n-128 -128 -128 -128 -128 -128 -128 -128\r\n\r\n-128 -128 -128 -128 -128 -128 -128 -128\r\n\r\n-128 -128 -128 -128 -128 -128 -128 -128\r\n\r\n-128 -128 -128 -128 -128 -128 -128 -128\r\n\r\n-128 -128 -128 -128 -128 -128 -128 -128\r\n<\/pre>\n<p>DU 2(FDCT)<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\n-1024 0    0    0    0    0    0    0\r\n\r\n0    0    0    0    0    0    0    0\r\n\r\n0    0    0    0    0    0    0    0\r\n\r\n0    0    0    0    0    0    0    0\r\n\r\n0    0    0    0    0    0    0    0\r\n\r\n0    0    0    0    0    0    0    0\r\n\r\n0    0    0    0    0    0    0    0\r\n\r\n0    0    0    0    0    0    0    0\r\n<\/pre>\n<p>DU 2(Quantization)<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\n-205 0    0    0    0    0    0    0\r\n\r\n0    0    0    0    0    0    0    0\r\n\r\n0    0    0    0    0    0    0    0\r\n\r\n0    0    0    0    0    0    0    0\r\n\r\n0    0    0    0    0    0    0    0\r\n\r\n0    0    0    0    0    0    0    0\r\n\r\n0    0    0    0    0    0    0    0\r\n\r\n0    0    0    0    0    0    0    0\r\n<\/pre>\n<p>\u4e8e\u662f\u5f97\u5230<br \/>\nDC\u5206\u522b\u4e3a203\u548c-205(\u7edd\u5bf9)\uff0c\u8f6c\u6362\u4e3a\u76f8\u5bf9\u5219\u662f203\u548c-408<br \/>\nAC\u90fd\u4e3a0<\/p>\n<p>\u5176\u5b83\u4e3a0\u6216\u8005\u586b\u5145\u6570\u636e\u6682\u65f6\u5c31\u4e0d\u7528\u7ba1\u4e86\u3002<\/p>\n<p>\u73b0\u5728\u8fdb\u884cHuffman\u7f16\u7801<br \/>\n203 = 1100 1011(\u67e5\u8868\u6216\u8005\u8ba1\u7b97\u90fd\u53ef\u4ee5\u5f97\u51fa\uff0c\u6700\u9ad8\u4f4d\u4e3a1\u8868\u793a\u6b63\u6570\uff0c\u6700\u9ad8\u4f4d\u4e3a0\u8868\u793a\u8d1f\u6570\uff0c\u53d6\u53cd\u5f97\u51fa\u5176\u503c)\uff0c\u7ee7\u800cDC\u7f16\u7801\u524d\u7f00\u4e3a1111 10(\u6839\u636eY\u7684DC\u8868\u53ef\u4ee5\u5f97\u51fa\uff0c\u6570\u636e\u53608\u4f4d)<br \/>\n-408 = 0011 0011 1<br \/>\n\u5219<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\n1111 10 1100 1011 \/\/ \u76f4\u6d41Y\r\n1111 10 1100 1011 1010 \/\/ \u76f4\u6d41Y + \u4ea4\u6d41Y\r\n1111 10 1100 1011 1010 1111 110 0011 0011 1 1010 \/\/ \u76f4\u6d41Y + \u4ea4\u6d41Y + \u76f4\u6d41Y + \u4ea4\u6d41Y\r\n1111 10 1100 1011 1010 1111 110 0011 0011 1 1010 00 1010 00 1010 \/\/ \u76f4\u6d41Y + \u4ea4\u6d41Y + \u76f4\u6d41Y + \u4ea4\u6d41Y + 2\u4e2a\u586b\u5145DU(\u56e0\u4e3aMCU\u4e3a4\u4e2aDU)\r\n1111 10 1100 1011 1010 1111 110 0011 0011 1 1010 00 1010 00 1010 00 00 \/\/ \u76f4\u6d41Y + \u4ea4\u6d41Y + \u76f4\u6d41Y + \u4ea4\u6d41Y + 2\u4e2a\u586b\u5145DU(\u56e0\u4e3aMCU\u4e3a4\u4e2aDU + \u76f4\u6d41Cb + \u4ea4\u6d41Cb\r\n1111 10 1100 1011 1010 1111 110 0011 0011 1 1010 00 1010 00 1010 00 00 00 00 \/\/ \u76f4\u6d41Y + \u4ea4\u6d41Y + \u76f4\u6d41Y + \u4ea4\u6d41Y + 2\u4e2a\u586b\u5145DU(\u56e0\u4e3aMCU\u4e3a4\u4e2aDU + \u76f4\u6d41Cb + \u4ea4\u6d41Cb + \u76f4\u6d41Cr + \u4ea4\u6d41Cr\r\n1111 10 1100 1011 1010 1111 110 0011 0011 1 1010 00 1010 00 1010 00 00 00 00 111111 \/\/ \u76f4\u6d41Y + \u4ea4\u6d41Y + \u76f4\u6d41Y + \u4ea4\u6d41Y + 2\u4e2a\u586b\u5145DU(\u56e0\u4e3aMCU\u4e3a4\u4e2aDU + \u76f4\u6d41Cb + \u4ea4\u6d41Cb + \u76f4\u6d41Cr + \u4ea4\u6d41Cr + \u586b\u5145\u4f4d\r\n<\/pre>\n<p>\u53bb\u6389\u7a7a\u683c<br \/>\n1111101100101110101111110001100111101000101000101000000000111111<br \/>\n\u4e5f\u5c31\u662f\u8bf4\u6570\u636e\u5176\u5b9e\u53ea\u670958\u4f4d\uff0c\u8865\u9f50\u5230\u5b57\u8282\u5bf9\u9f50\uff0c\u5171\u536064\u4f4d\uff0c\u5c31\u5f97\u5230\u4e86\u6211\u4eec\u6700\u7ec8\u8981\u7684\u6570\u636e\u3002<br \/>\n16\u8fdb\u5236\u8868\u793a<br \/>\nFB 2E BF 19 E8 A2 80 3F<\/p>\n<p>\u8fd9\u4e0b\u4f60\u6216\u8bb8\u5bf9\u8fd9\u590d\u6742\u7684JPEG\u539f\u7406\u6709\u6240\u4e86\u89e3\u4e86\u5427\uff0c\u4f46\u662f\u8bb0\u4f4f\u8fd9\u624d\u662f\u5f00\u59cb(\u5f53\u7136\u4f60\u65e0\u6cd5\u5168\u624b\u5de5\u7684\u4e3a\u4e00\u5f20\u590d\u6742\u7684\u56fe\u7247\u6765\u7f16\u7801\uff0c\u8fd9\u7bc7\u6587\u7ae0\u53ea\u662f\u5e2e\u52a9\u7406\u89e3\u539f\u7406)\uff0cJPEG\u6b63\u771f\u590d\u6742\u7684\u662f\u5b83\u5bf9\u5404\u79cd\u7b97\u6cd5\u7684\u4f18\u5316\uff0c\u90a3\u624d\u662f\u91cd\u70b9\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8fd9\u91cc\u6709\u7bc7\u6587\u7ae0\u8bb2\u89e3\u5982\u4f55\u8fdb\u884cHuffman\u7f16\u7801\u7684JPEG Huffman Coding Tutorial\uff0c\u5199\u7684\u8fd8\u662f\u5f88\u6e05\u6670\uff0c\u6211\u672c\u6765\u6253\u7b97\u7ffb\u8bd1\u4e00\u4e0b\u8fd9\u7bc7\u6587\u7ae0\uff0c\u4f46\u662f\u60f3\u60f3\u89c9\u5f97\u8fd8\u662f\u914d\u5408\u5b83\u7684\u601d\u8def\u4ee5\u4e0d\u540c\u7684\u89d2\u5ea6\u518d\u5199\u4e00\u7bc7\uff0c\u5b83\u662f\u89e3\u7801\u65b9\u5f0f\uff0c\u6211\u8fd9\u91cc\u662f\u4ee5\u7f16\u7801\u65b9\u5f0f\u6765\u63cf\u8ff0\uff0c\u5b83\u7684Y:Cb:Cr\u662f1:1:1\uff0c\u6211\u8fd9\u91cc\u662f4:1:1\uff0c\u5f53\u7136\u5b83\u662f\u82f1\u6587\u7684\uff0c\u6211\u662f\u4e2d\u6587\u7684 @@\u3002 JPEG\/Huffman\u7f16\u7801\u57fa\u7840\u77e5\u8bc6\u4e0d\u4e86\u89e3\u7684\u8fd8\u662f\u8981\u5148\u5b66\u4e60\u4e0b\u57fa\u7840\u77e5\u8bc6\uff0c\u53ef\u4ee5\u53c2\u8003JPEG\u5b66\u4e60\u7b14\u8bb0\uff0c\u5426\u5219\u4f60\u53ef\u80fd\u65e0\u6cd5\u770b\u61c2\u8fd9\u91cc\u5728\u8bf4\u4ec0\u4e48\u3002 \u7b80\u5355\u56de\u987e\u4e0bJPEG\u7f16\u7801\u8fc7\u7a0b\uff0c\u8fd9\u91cc\u6211\u4eec\u5047\u8bbeRGB->JPEG\uff1a \u8272\u5f69\u7a7a\u95f4\u8f6c\u6362 \u6b63\u5411\u79bb\u6563\u4f59\u5f26\u53d8\u6362 \u91cf\u5316(\u9700\u8981\u91cf\u5316\u8868) Huffman\u7f16\u7801(\u9700\u8981Huffman\u7f16\u7801\u8868) \u751f\u6210\u56fe\u7247\u6d41(\u6309\u7167JFIF\u683c\u5f0f) \u5176\u5b83\u7684\u6211\u4eec\u90fd\u4e0d\u8bf4\u4e86\uff0c\u76f4\u63a5\u5f00\u59cb\u5427\uff0c\u5982\u679c\u4f60\u73b0\u5728\u89c9\u5f97\u4e0a\u9762\u7684\u6982\u5ff5\/\u539f\u7406\u8fd8\u4e0d\u662f\u5f88\u7406\u89e3\uff0c\u8fd8\u6765\u7684\u6025\uff0c\u8bf7\u8df3\u8f6c\u5230\u6587\u7ae0\u9876\u90e8\u4ece\u5934\u5f00\u59cb\u8bfb\u3002 \u6709\u4e9b\u4e2d\u95f4\u6570\u636e\u7684\u63a8\u7406\u662f\u901a\u8fc7JPEGsnoop\u6216\u8005\u624b\u5de5\u8fdb\u884c\u7684\uff0c\u6240\u4ee5\u4f60\u4e5f\u8981\u719f\u6089\u3002 \u5047\u8bbe\u6211\u4eec\u6709RGB\u6570\u636e\uff0c\u8fd9\u91cc\u6211\u7528\u7684\u662ftest.bmp\uff0c\u4e00\u5f2016&#215;8\u7684\u7684\u767d\u9ed1\u4f4d\u56fe(\u5de6DU\u767d\uff0c\u53f3DU\u9ed1)\uff0c\u53ef\u4ee5\u752816\u8fdb\u5236\u5de5\u5177\u6253\u5f00\u6765\u67e5\u770b\uff0c\u5b9e\u9645\u6570\u636e\u5c31\u662f\uff1a FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 &hellip; <a href=\"https:\/\/guoh.ai\/lifelog\/2013\/09\/jpeg-huffman-code-by-hand\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">\u624b\u5de5\u8fdb\u884c\u56fe\u7247Huffman\u7f16\u7801<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_gfmr_meta_descriptions":[],"_gfmr_multilingual_taxonomy_terms":[],"footnotes":""},"categories":[34],"tags":[],"class_list":["post-755","post","type-post","status-publish","format-standard","hentry","category-multimedia"],"_links":{"self":[{"href":"https:\/\/guoh.ai\/lifelog\/wp-json\/wp\/v2\/posts\/755","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/guoh.ai\/lifelog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/guoh.ai\/lifelog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/guoh.ai\/lifelog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/guoh.ai\/lifelog\/wp-json\/wp\/v2\/comments?post=755"}],"version-history":[{"count":14,"href":"https:\/\/guoh.ai\/lifelog\/wp-json\/wp\/v2\/posts\/755\/revisions"}],"predecessor-version":[{"id":841,"href":"https:\/\/guoh.ai\/lifelog\/wp-json\/wp\/v2\/posts\/755\/revisions\/841"}],"wp:attachment":[{"href":"https:\/\/guoh.ai\/lifelog\/wp-json\/wp\/v2\/media?parent=755"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/guoh.ai\/lifelog\/wp-json\/wp\/v2\/categories?post=755"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/guoh.ai\/lifelog\/wp-json\/wp\/v2\/tags?post=755"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}