test
Dependencies: Nanopb iSerial mbed BaseJpegDecode FatFileSystem SDFileSystem RingBuffer Camera_LS_Y201
extlib/BaseJpegDecode/HuffmanDecode.cpp@0:d69efd0ee139, 2014-09-18 (annotated)
- Committer:
- cgraham
- Date:
- Thu Sep 18 15:21:47 2014 +0000
- Revision:
- 0:d69efd0ee139
test
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
cgraham | 0:d69efd0ee139 | 1 | #include "mbed.h" |
cgraham | 0:d69efd0ee139 | 2 | #include "HuffmanDecode.h" |
cgraham | 0:d69efd0ee139 | 3 | #include "HuffmanCodeTable.h" |
cgraham | 0:d69efd0ee139 | 4 | #if 1 |
cgraham | 0:d69efd0ee139 | 5 | #define DBG(...) do{fprintf(stderr,"[%s@%d] ",__PRETTY_FUNCTION__,__LINE__);fprintf(stderr,__VA_ARGS__);} while(0); |
cgraham | 0:d69efd0ee139 | 6 | #define DBG_ASSERT(A) while(!(A)){fprintf(stderr,"\n\n%s@%d %s ASSERT!\n\n",__PRETTY_FUNCTION__,__LINE__,#A);exit(1);}; |
cgraham | 0:d69efd0ee139 | 7 | #else |
cgraham | 0:d69efd0ee139 | 8 | #define DBG(...) |
cgraham | 0:d69efd0ee139 | 9 | #define DBG_ASSERT(A) |
cgraham | 0:d69efd0ee139 | 10 | #endif |
cgraham | 0:d69efd0ee139 | 11 | |
cgraham | 0:d69efd0ee139 | 12 | const Huff HT_DC_0[] = { |
cgraham | 0:d69efd0ee139 | 13 | /* 0 */ {0,0,2,0x0}, |
cgraham | 0:d69efd0ee139 | 14 | /* 1 */ {0,1,3,0x2}, |
cgraham | 0:d69efd0ee139 | 15 | /* 2 */ {0,2,3,0x3}, |
cgraham | 0:d69efd0ee139 | 16 | /* 3 */ {0,3,3,0x4}, |
cgraham | 0:d69efd0ee139 | 17 | /* 4 */ {0,4,3,0x5}, |
cgraham | 0:d69efd0ee139 | 18 | /* 5 */ {0,5,3,0x6}, |
cgraham | 0:d69efd0ee139 | 19 | /* 6 */ {0,6,4,0xe}, |
cgraham | 0:d69efd0ee139 | 20 | /* 7 */ {0,7,5,0x1e}, |
cgraham | 0:d69efd0ee139 | 21 | /* 8 */ {0,8,6,0x3e}, |
cgraham | 0:d69efd0ee139 | 22 | /* 9 */ {0,9,7,0x7e}, |
cgraham | 0:d69efd0ee139 | 23 | /* 10 */ {0,10,8,0xfe}, |
cgraham | 0:d69efd0ee139 | 24 | /* 11 */ {0,11,9,0x1fe}, |
cgraham | 0:d69efd0ee139 | 25 | }; |
cgraham | 0:d69efd0ee139 | 26 | const Huff HT_AC_0[] = { |
cgraham | 0:d69efd0ee139 | 27 | /* 0 */ {0,1,2,0x0}, |
cgraham | 0:d69efd0ee139 | 28 | /* 1 */ {0,2,2,0x1}, |
cgraham | 0:d69efd0ee139 | 29 | /* 2 */ {0,3,3,0x4}, |
cgraham | 0:d69efd0ee139 | 30 | /* 3 */ {0,0,4,0xa}, |
cgraham | 0:d69efd0ee139 | 31 | /* 4 */ {0,4,4,0xb}, |
cgraham | 0:d69efd0ee139 | 32 | /* 5 */ {1,1,4,0xc}, |
cgraham | 0:d69efd0ee139 | 33 | /* 6 */ {0,5,5,0x1a}, |
cgraham | 0:d69efd0ee139 | 34 | /* 7 */ {1,2,5,0x1b}, |
cgraham | 0:d69efd0ee139 | 35 | /* 8 */ {2,1,5,0x1c}, |
cgraham | 0:d69efd0ee139 | 36 | /* 9 */ {3,1,6,0x3a}, |
cgraham | 0:d69efd0ee139 | 37 | /* 10 */ {4,1,6,0x3b}, |
cgraham | 0:d69efd0ee139 | 38 | /* 11 */ {0,6,7,0x78}, |
cgraham | 0:d69efd0ee139 | 39 | /* 12 */ {1,3,7,0x79}, |
cgraham | 0:d69efd0ee139 | 40 | /* 13 */ {5,1,7,0x7a}, |
cgraham | 0:d69efd0ee139 | 41 | /* 14 */ {6,1,7,0x7b}, |
cgraham | 0:d69efd0ee139 | 42 | /* 15 */ {0,7,8,0xf8}, |
cgraham | 0:d69efd0ee139 | 43 | /* 16 */ {2,2,8,0xf9}, |
cgraham | 0:d69efd0ee139 | 44 | /* 17 */ {7,1,8,0xfa}, |
cgraham | 0:d69efd0ee139 | 45 | /* 18 */ {1,4,9,0x1f6}, |
cgraham | 0:d69efd0ee139 | 46 | /* 19 */ {3,2,9,0x1f7}, |
cgraham | 0:d69efd0ee139 | 47 | /* 20 */ {8,1,9,0x1f8}, |
cgraham | 0:d69efd0ee139 | 48 | /* 21 */ {9,1,9,0x1f9}, |
cgraham | 0:d69efd0ee139 | 49 | /* 22 */ {10,1,9,0x1fa}, |
cgraham | 0:d69efd0ee139 | 50 | /* 23 */ {0,8,10,0x3f6}, |
cgraham | 0:d69efd0ee139 | 51 | /* 24 */ {2,3,10,0x3f7}, |
cgraham | 0:d69efd0ee139 | 52 | /* 25 */ {4,2,10,0x3f8}, |
cgraham | 0:d69efd0ee139 | 53 | /* 26 */ {11,1,10,0x3f9}, |
cgraham | 0:d69efd0ee139 | 54 | /* 27 */ {12,1,10,0x3fa}, |
cgraham | 0:d69efd0ee139 | 55 | /* 28 */ {1,5,11,0x7f6}, |
cgraham | 0:d69efd0ee139 | 56 | /* 29 */ {5,2,11,0x7f7}, |
cgraham | 0:d69efd0ee139 | 57 | /* 30 */ {13,1,11,0x7f8}, |
cgraham | 0:d69efd0ee139 | 58 | /* 31 */ {15,0,11,0x7f9}, |
cgraham | 0:d69efd0ee139 | 59 | /* 32 */ {2,4,12,0xff4}, |
cgraham | 0:d69efd0ee139 | 60 | /* 33 */ {3,3,12,0xff5}, |
cgraham | 0:d69efd0ee139 | 61 | /* 34 */ {6,2,12,0xff6}, |
cgraham | 0:d69efd0ee139 | 62 | /* 35 */ {7,2,12,0xff7}, |
cgraham | 0:d69efd0ee139 | 63 | /* 36 */ {8,2,15,0x7fc0}, |
cgraham | 0:d69efd0ee139 | 64 | /* 37 */ {0,9,16,0xff82}, |
cgraham | 0:d69efd0ee139 | 65 | /* 38 */ {0,10,16,0xff83}, |
cgraham | 0:d69efd0ee139 | 66 | /* 39 */ {1,6,16,0xff84}, |
cgraham | 0:d69efd0ee139 | 67 | /* 40 */ {1,7,16,0xff85}, |
cgraham | 0:d69efd0ee139 | 68 | /* 41 */ {1,8,16,0xff86}, |
cgraham | 0:d69efd0ee139 | 69 | /* 42 */ {1,9,16,0xff87}, |
cgraham | 0:d69efd0ee139 | 70 | /* 43 */ {1,10,16,0xff88}, |
cgraham | 0:d69efd0ee139 | 71 | /* 44 */ {2,5,16,0xff89}, |
cgraham | 0:d69efd0ee139 | 72 | /* 45 */ {2,6,16,0xff8a}, |
cgraham | 0:d69efd0ee139 | 73 | /* 46 */ {2,7,16,0xff8b}, |
cgraham | 0:d69efd0ee139 | 74 | /* 47 */ {2,8,16,0xff8c}, |
cgraham | 0:d69efd0ee139 | 75 | /* 48 */ {2,9,16,0xff8d}, |
cgraham | 0:d69efd0ee139 | 76 | /* 49 */ {2,10,16,0xff8e}, |
cgraham | 0:d69efd0ee139 | 77 | /* 50 */ {3,4,16,0xff8f}, |
cgraham | 0:d69efd0ee139 | 78 | /* 51 */ {3,5,16,0xff90}, |
cgraham | 0:d69efd0ee139 | 79 | /* 52 */ {3,6,16,0xff91}, |
cgraham | 0:d69efd0ee139 | 80 | /* 53 */ {3,7,16,0xff92}, |
cgraham | 0:d69efd0ee139 | 81 | /* 54 */ {3,8,16,0xff93}, |
cgraham | 0:d69efd0ee139 | 82 | /* 55 */ {3,9,16,0xff94}, |
cgraham | 0:d69efd0ee139 | 83 | /* 56 */ {3,10,16,0xff95}, |
cgraham | 0:d69efd0ee139 | 84 | /* 57 */ {4,3,16,0xff96}, |
cgraham | 0:d69efd0ee139 | 85 | /* 58 */ {4,4,16,0xff97}, |
cgraham | 0:d69efd0ee139 | 86 | /* 59 */ {4,5,16,0xff98}, |
cgraham | 0:d69efd0ee139 | 87 | /* 60 */ {4,6,16,0xff99}, |
cgraham | 0:d69efd0ee139 | 88 | /* 61 */ {4,7,16,0xff9a}, |
cgraham | 0:d69efd0ee139 | 89 | /* 62 */ {4,8,16,0xff9b}, |
cgraham | 0:d69efd0ee139 | 90 | /* 63 */ {4,9,16,0xff9c}, |
cgraham | 0:d69efd0ee139 | 91 | /* 64 */ {4,10,16,0xff9d}, |
cgraham | 0:d69efd0ee139 | 92 | /* 65 */ {5,3,16,0xff9e}, |
cgraham | 0:d69efd0ee139 | 93 | /* 66 */ {5,4,16,0xff9f}, |
cgraham | 0:d69efd0ee139 | 94 | /* 67 */ {5,5,16,0xffa0}, |
cgraham | 0:d69efd0ee139 | 95 | /* 68 */ {5,6,16,0xffa1}, |
cgraham | 0:d69efd0ee139 | 96 | /* 69 */ {5,7,16,0xffa2}, |
cgraham | 0:d69efd0ee139 | 97 | /* 70 */ {5,8,16,0xffa3}, |
cgraham | 0:d69efd0ee139 | 98 | /* 71 */ {5,9,16,0xffa4}, |
cgraham | 0:d69efd0ee139 | 99 | /* 72 */ {5,10,16,0xffa5}, |
cgraham | 0:d69efd0ee139 | 100 | /* 73 */ {6,3,16,0xffa6}, |
cgraham | 0:d69efd0ee139 | 101 | /* 74 */ {6,4,16,0xffa7}, |
cgraham | 0:d69efd0ee139 | 102 | /* 75 */ {6,5,16,0xffa8}, |
cgraham | 0:d69efd0ee139 | 103 | /* 76 */ {6,6,16,0xffa9}, |
cgraham | 0:d69efd0ee139 | 104 | /* 77 */ {6,7,16,0xffaa}, |
cgraham | 0:d69efd0ee139 | 105 | /* 78 */ {6,8,16,0xffab}, |
cgraham | 0:d69efd0ee139 | 106 | /* 79 */ {6,9,16,0xffac}, |
cgraham | 0:d69efd0ee139 | 107 | /* 80 */ {6,10,16,0xffad}, |
cgraham | 0:d69efd0ee139 | 108 | /* 81 */ {7,3,16,0xffae}, |
cgraham | 0:d69efd0ee139 | 109 | /* 82 */ {7,4,16,0xffaf}, |
cgraham | 0:d69efd0ee139 | 110 | /* 83 */ {7,5,16,0xffb0}, |
cgraham | 0:d69efd0ee139 | 111 | /* 84 */ {7,6,16,0xffb1}, |
cgraham | 0:d69efd0ee139 | 112 | /* 85 */ {7,7,16,0xffb2}, |
cgraham | 0:d69efd0ee139 | 113 | /* 86 */ {7,8,16,0xffb3}, |
cgraham | 0:d69efd0ee139 | 114 | /* 87 */ {7,9,16,0xffb4}, |
cgraham | 0:d69efd0ee139 | 115 | /* 88 */ {7,10,16,0xffb5}, |
cgraham | 0:d69efd0ee139 | 116 | /* 89 */ {8,3,16,0xffb6}, |
cgraham | 0:d69efd0ee139 | 117 | /* 90 */ {8,4,16,0xffb7}, |
cgraham | 0:d69efd0ee139 | 118 | /* 91 */ {8,5,16,0xffb8}, |
cgraham | 0:d69efd0ee139 | 119 | /* 92 */ {8,6,16,0xffb9}, |
cgraham | 0:d69efd0ee139 | 120 | /* 93 */ {8,7,16,0xffba}, |
cgraham | 0:d69efd0ee139 | 121 | /* 94 */ {8,8,16,0xffbb}, |
cgraham | 0:d69efd0ee139 | 122 | /* 95 */ {8,9,16,0xffbc}, |
cgraham | 0:d69efd0ee139 | 123 | /* 96 */ {8,10,16,0xffbd}, |
cgraham | 0:d69efd0ee139 | 124 | /* 97 */ {9,2,16,0xffbe}, |
cgraham | 0:d69efd0ee139 | 125 | /* 98 */ {9,3,16,0xffbf}, |
cgraham | 0:d69efd0ee139 | 126 | /* 99 */ {9,4,16,0xffc0}, |
cgraham | 0:d69efd0ee139 | 127 | /* 100 */ {9,5,16,0xffc1}, |
cgraham | 0:d69efd0ee139 | 128 | /* 101 */ {9,6,16,0xffc2}, |
cgraham | 0:d69efd0ee139 | 129 | /* 102 */ {9,7,16,0xffc3}, |
cgraham | 0:d69efd0ee139 | 130 | /* 103 */ {9,8,16,0xffc4}, |
cgraham | 0:d69efd0ee139 | 131 | /* 104 */ {9,9,16,0xffc5}, |
cgraham | 0:d69efd0ee139 | 132 | /* 105 */ {9,10,16,0xffc6}, |
cgraham | 0:d69efd0ee139 | 133 | /* 106 */ {10,2,16,0xffc7}, |
cgraham | 0:d69efd0ee139 | 134 | /* 107 */ {10,3,16,0xffc8}, |
cgraham | 0:d69efd0ee139 | 135 | /* 108 */ {10,4,16,0xffc9}, |
cgraham | 0:d69efd0ee139 | 136 | /* 109 */ {10,5,16,0xffca}, |
cgraham | 0:d69efd0ee139 | 137 | /* 110 */ {10,6,16,0xffcb}, |
cgraham | 0:d69efd0ee139 | 138 | /* 111 */ {10,7,16,0xffcc}, |
cgraham | 0:d69efd0ee139 | 139 | /* 112 */ {10,8,16,0xffcd}, |
cgraham | 0:d69efd0ee139 | 140 | /* 113 */ {10,9,16,0xffce}, |
cgraham | 0:d69efd0ee139 | 141 | /* 114 */ {10,10,16,0xffcf}, |
cgraham | 0:d69efd0ee139 | 142 | /* 115 */ {11,2,16,0xffd0}, |
cgraham | 0:d69efd0ee139 | 143 | /* 116 */ {11,3,16,0xffd1}, |
cgraham | 0:d69efd0ee139 | 144 | /* 117 */ {11,4,16,0xffd2}, |
cgraham | 0:d69efd0ee139 | 145 | /* 118 */ {11,5,16,0xffd3}, |
cgraham | 0:d69efd0ee139 | 146 | /* 119 */ {11,6,16,0xffd4}, |
cgraham | 0:d69efd0ee139 | 147 | /* 120 */ {11,7,16,0xffd5}, |
cgraham | 0:d69efd0ee139 | 148 | /* 121 */ {11,8,16,0xffd6}, |
cgraham | 0:d69efd0ee139 | 149 | /* 122 */ {11,9,16,0xffd7}, |
cgraham | 0:d69efd0ee139 | 150 | /* 123 */ {11,10,16,0xffd8}, |
cgraham | 0:d69efd0ee139 | 151 | /* 124 */ {12,2,16,0xffd9}, |
cgraham | 0:d69efd0ee139 | 152 | /* 125 */ {12,3,16,0xffda}, |
cgraham | 0:d69efd0ee139 | 153 | /* 126 */ {12,4,16,0xffdb}, |
cgraham | 0:d69efd0ee139 | 154 | /* 127 */ {12,5,16,0xffdc}, |
cgraham | 0:d69efd0ee139 | 155 | /* 128 */ {12,6,16,0xffdd}, |
cgraham | 0:d69efd0ee139 | 156 | /* 129 */ {12,7,16,0xffde}, |
cgraham | 0:d69efd0ee139 | 157 | /* 130 */ {12,8,16,0xffdf}, |
cgraham | 0:d69efd0ee139 | 158 | /* 131 */ {12,9,16,0xffe0}, |
cgraham | 0:d69efd0ee139 | 159 | /* 132 */ {12,10,16,0xffe1}, |
cgraham | 0:d69efd0ee139 | 160 | /* 133 */ {13,2,16,0xffe2}, |
cgraham | 0:d69efd0ee139 | 161 | /* 134 */ {13,3,16,0xffe3}, |
cgraham | 0:d69efd0ee139 | 162 | /* 135 */ {13,4,16,0xffe4}, |
cgraham | 0:d69efd0ee139 | 163 | /* 136 */ {13,5,16,0xffe5}, |
cgraham | 0:d69efd0ee139 | 164 | /* 137 */ {13,6,16,0xffe6}, |
cgraham | 0:d69efd0ee139 | 165 | /* 138 */ {13,7,16,0xffe7}, |
cgraham | 0:d69efd0ee139 | 166 | /* 139 */ {13,8,16,0xffe8}, |
cgraham | 0:d69efd0ee139 | 167 | /* 140 */ {13,9,16,0xffe9}, |
cgraham | 0:d69efd0ee139 | 168 | /* 141 */ {13,10,16,0xffea}, |
cgraham | 0:d69efd0ee139 | 169 | /* 142 */ {14,1,16,0xffeb}, |
cgraham | 0:d69efd0ee139 | 170 | /* 143 */ {14,2,16,0xffec}, |
cgraham | 0:d69efd0ee139 | 171 | /* 144 */ {14,3,16,0xffed}, |
cgraham | 0:d69efd0ee139 | 172 | /* 145 */ {14,4,16,0xffee}, |
cgraham | 0:d69efd0ee139 | 173 | /* 146 */ {14,5,16,0xffef}, |
cgraham | 0:d69efd0ee139 | 174 | /* 147 */ {14,6,16,0xfff0}, |
cgraham | 0:d69efd0ee139 | 175 | /* 148 */ {14,7,16,0xfff1}, |
cgraham | 0:d69efd0ee139 | 176 | /* 149 */ {14,8,16,0xfff2}, |
cgraham | 0:d69efd0ee139 | 177 | /* 150 */ {14,9,16,0xfff3}, |
cgraham | 0:d69efd0ee139 | 178 | /* 151 */ {14,10,16,0xfff4}, |
cgraham | 0:d69efd0ee139 | 179 | /* 152 */ {15,1,16,0xfff5}, |
cgraham | 0:d69efd0ee139 | 180 | /* 153 */ {15,2,16,0xfff6}, |
cgraham | 0:d69efd0ee139 | 181 | /* 154 */ {15,3,16,0xfff7}, |
cgraham | 0:d69efd0ee139 | 182 | /* 155 */ {15,4,16,0xfff8}, |
cgraham | 0:d69efd0ee139 | 183 | /* 156 */ {15,5,16,0xfff9}, |
cgraham | 0:d69efd0ee139 | 184 | /* 157 */ {15,6,16,0xfffa}, |
cgraham | 0:d69efd0ee139 | 185 | /* 158 */ {15,7,16,0xfffb}, |
cgraham | 0:d69efd0ee139 | 186 | /* 159 */ {15,8,16,0xfffc}, |
cgraham | 0:d69efd0ee139 | 187 | /* 160 */ {15,9,16,0xfffd}, |
cgraham | 0:d69efd0ee139 | 188 | /* 161 */ {15,10,16,0xfffe}, |
cgraham | 0:d69efd0ee139 | 189 | }; |
cgraham | 0:d69efd0ee139 | 190 | const Huff HT_DC_1[] = { |
cgraham | 0:d69efd0ee139 | 191 | /* 0 */ {0,0,2,0x0}, |
cgraham | 0:d69efd0ee139 | 192 | /* 1 */ {0,1,2,0x1}, |
cgraham | 0:d69efd0ee139 | 193 | /* 2 */ {0,2,2,0x2}, |
cgraham | 0:d69efd0ee139 | 194 | /* 3 */ {0,3,3,0x6}, |
cgraham | 0:d69efd0ee139 | 195 | /* 4 */ {0,4,4,0xe}, |
cgraham | 0:d69efd0ee139 | 196 | /* 5 */ {0,5,5,0x1e}, |
cgraham | 0:d69efd0ee139 | 197 | /* 6 */ {0,6,6,0x3e}, |
cgraham | 0:d69efd0ee139 | 198 | /* 7 */ {0,7,7,0x7e}, |
cgraham | 0:d69efd0ee139 | 199 | /* 8 */ {0,8,8,0xfe}, |
cgraham | 0:d69efd0ee139 | 200 | /* 9 */ {0,9,9,0x1fe}, |
cgraham | 0:d69efd0ee139 | 201 | /* 10 */ {0,10,10,0x3fe}, |
cgraham | 0:d69efd0ee139 | 202 | /* 11 */ {0,11,11,0x7fe}, |
cgraham | 0:d69efd0ee139 | 203 | }; |
cgraham | 0:d69efd0ee139 | 204 | const Huff HT_AC_1[] = { |
cgraham | 0:d69efd0ee139 | 205 | /* 0 */ {0,0,2,0x0}, |
cgraham | 0:d69efd0ee139 | 206 | /* 1 */ {0,1,2,0x1}, |
cgraham | 0:d69efd0ee139 | 207 | /* 2 */ {0,2,3,0x4}, |
cgraham | 0:d69efd0ee139 | 208 | /* 3 */ {0,3,4,0xa}, |
cgraham | 0:d69efd0ee139 | 209 | /* 4 */ {1,1,4,0xb}, |
cgraham | 0:d69efd0ee139 | 210 | /* 5 */ {0,4,5,0x18}, |
cgraham | 0:d69efd0ee139 | 211 | /* 6 */ {0,5,5,0x19}, |
cgraham | 0:d69efd0ee139 | 212 | /* 7 */ {2,1,5,0x1a}, |
cgraham | 0:d69efd0ee139 | 213 | /* 8 */ {3,1,5,0x1b}, |
cgraham | 0:d69efd0ee139 | 214 | /* 9 */ {0,6,6,0x38}, |
cgraham | 0:d69efd0ee139 | 215 | /* 10 */ {1,2,6,0x39}, |
cgraham | 0:d69efd0ee139 | 216 | /* 11 */ {4,1,6,0x3a}, |
cgraham | 0:d69efd0ee139 | 217 | /* 12 */ {5,1,6,0x3b}, |
cgraham | 0:d69efd0ee139 | 218 | /* 13 */ {0,7,7,0x78}, |
cgraham | 0:d69efd0ee139 | 219 | /* 14 */ {6,1,7,0x79}, |
cgraham | 0:d69efd0ee139 | 220 | /* 15 */ {7,1,7,0x7a}, |
cgraham | 0:d69efd0ee139 | 221 | /* 16 */ {1,3,8,0xf6}, |
cgraham | 0:d69efd0ee139 | 222 | /* 17 */ {2,2,8,0xf7}, |
cgraham | 0:d69efd0ee139 | 223 | /* 18 */ {3,2,8,0xf8}, |
cgraham | 0:d69efd0ee139 | 224 | /* 19 */ {8,1,8,0xf9}, |
cgraham | 0:d69efd0ee139 | 225 | /* 20 */ {0,8,9,0x1f4}, |
cgraham | 0:d69efd0ee139 | 226 | /* 21 */ {1,4,9,0x1f5}, |
cgraham | 0:d69efd0ee139 | 227 | /* 22 */ {4,2,9,0x1f6}, |
cgraham | 0:d69efd0ee139 | 228 | /* 23 */ {9,1,9,0x1f7}, |
cgraham | 0:d69efd0ee139 | 229 | /* 24 */ {10,1,9,0x1f8}, |
cgraham | 0:d69efd0ee139 | 230 | /* 25 */ {11,1,9,0x1f9}, |
cgraham | 0:d69efd0ee139 | 231 | /* 26 */ {12,1,9,0x1fa}, |
cgraham | 0:d69efd0ee139 | 232 | /* 27 */ {0,9,10,0x3f6}, |
cgraham | 0:d69efd0ee139 | 233 | /* 28 */ {2,3,10,0x3f7}, |
cgraham | 0:d69efd0ee139 | 234 | /* 29 */ {3,3,10,0x3f8}, |
cgraham | 0:d69efd0ee139 | 235 | /* 30 */ {5,2,10,0x3f9}, |
cgraham | 0:d69efd0ee139 | 236 | /* 31 */ {15,0,10,0x3fa}, |
cgraham | 0:d69efd0ee139 | 237 | /* 32 */ {1,5,11,0x7f6}, |
cgraham | 0:d69efd0ee139 | 238 | /* 33 */ {6,2,11,0x7f7}, |
cgraham | 0:d69efd0ee139 | 239 | /* 34 */ {7,2,11,0x7f8}, |
cgraham | 0:d69efd0ee139 | 240 | /* 35 */ {13,1,11,0x7f9}, |
cgraham | 0:d69efd0ee139 | 241 | /* 36 */ {0,10,12,0xff4}, |
cgraham | 0:d69efd0ee139 | 242 | /* 37 */ {1,6,12,0xff5}, |
cgraham | 0:d69efd0ee139 | 243 | /* 38 */ {2,4,12,0xff6}, |
cgraham | 0:d69efd0ee139 | 244 | /* 39 */ {3,4,12,0xff7}, |
cgraham | 0:d69efd0ee139 | 245 | /* 40 */ {14,1,14,0x3fe0}, |
cgraham | 0:d69efd0ee139 | 246 | /* 41 */ {2,5,15,0x7fc2}, |
cgraham | 0:d69efd0ee139 | 247 | /* 42 */ {15,1,15,0x7fc3}, |
cgraham | 0:d69efd0ee139 | 248 | /* 43 */ {1,7,16,0xff88}, |
cgraham | 0:d69efd0ee139 | 249 | /* 44 */ {1,8,16,0xff89}, |
cgraham | 0:d69efd0ee139 | 250 | /* 45 */ {1,9,16,0xff8a}, |
cgraham | 0:d69efd0ee139 | 251 | /* 46 */ {1,10,16,0xff8b}, |
cgraham | 0:d69efd0ee139 | 252 | /* 47 */ {2,6,16,0xff8c}, |
cgraham | 0:d69efd0ee139 | 253 | /* 48 */ {2,7,16,0xff8d}, |
cgraham | 0:d69efd0ee139 | 254 | /* 49 */ {2,8,16,0xff8e}, |
cgraham | 0:d69efd0ee139 | 255 | /* 50 */ {2,9,16,0xff8f}, |
cgraham | 0:d69efd0ee139 | 256 | /* 51 */ {2,10,16,0xff90}, |
cgraham | 0:d69efd0ee139 | 257 | /* 52 */ {3,5,16,0xff91}, |
cgraham | 0:d69efd0ee139 | 258 | /* 53 */ {3,6,16,0xff92}, |
cgraham | 0:d69efd0ee139 | 259 | /* 54 */ {3,7,16,0xff93}, |
cgraham | 0:d69efd0ee139 | 260 | /* 55 */ {3,8,16,0xff94}, |
cgraham | 0:d69efd0ee139 | 261 | /* 56 */ {3,9,16,0xff95}, |
cgraham | 0:d69efd0ee139 | 262 | /* 57 */ {3,10,16,0xff96}, |
cgraham | 0:d69efd0ee139 | 263 | /* 58 */ {4,3,16,0xff97}, |
cgraham | 0:d69efd0ee139 | 264 | /* 59 */ {4,4,16,0xff98}, |
cgraham | 0:d69efd0ee139 | 265 | /* 60 */ {4,5,16,0xff99}, |
cgraham | 0:d69efd0ee139 | 266 | /* 61 */ {4,6,16,0xff9a}, |
cgraham | 0:d69efd0ee139 | 267 | /* 62 */ {4,7,16,0xff9b}, |
cgraham | 0:d69efd0ee139 | 268 | /* 63 */ {4,8,16,0xff9c}, |
cgraham | 0:d69efd0ee139 | 269 | /* 64 */ {4,9,16,0xff9d}, |
cgraham | 0:d69efd0ee139 | 270 | /* 65 */ {4,10,16,0xff9e}, |
cgraham | 0:d69efd0ee139 | 271 | /* 66 */ {5,3,16,0xff9f}, |
cgraham | 0:d69efd0ee139 | 272 | /* 67 */ {5,4,16,0xffa0}, |
cgraham | 0:d69efd0ee139 | 273 | /* 68 */ {5,5,16,0xffa1}, |
cgraham | 0:d69efd0ee139 | 274 | /* 69 */ {5,6,16,0xffa2}, |
cgraham | 0:d69efd0ee139 | 275 | /* 70 */ {5,7,16,0xffa3}, |
cgraham | 0:d69efd0ee139 | 276 | /* 71 */ {5,8,16,0xffa4}, |
cgraham | 0:d69efd0ee139 | 277 | /* 72 */ {5,9,16,0xffa5}, |
cgraham | 0:d69efd0ee139 | 278 | /* 73 */ {5,10,16,0xffa6}, |
cgraham | 0:d69efd0ee139 | 279 | /* 74 */ {6,3,16,0xffa7}, |
cgraham | 0:d69efd0ee139 | 280 | /* 75 */ {6,4,16,0xffa8}, |
cgraham | 0:d69efd0ee139 | 281 | /* 76 */ {6,5,16,0xffa9}, |
cgraham | 0:d69efd0ee139 | 282 | /* 77 */ {6,6,16,0xffaa}, |
cgraham | 0:d69efd0ee139 | 283 | /* 78 */ {6,7,16,0xffab}, |
cgraham | 0:d69efd0ee139 | 284 | /* 79 */ {6,8,16,0xffac}, |
cgraham | 0:d69efd0ee139 | 285 | /* 80 */ {6,9,16,0xffad}, |
cgraham | 0:d69efd0ee139 | 286 | /* 81 */ {6,10,16,0xffae}, |
cgraham | 0:d69efd0ee139 | 287 | /* 82 */ {7,3,16,0xffaf}, |
cgraham | 0:d69efd0ee139 | 288 | /* 83 */ {7,4,16,0xffb0}, |
cgraham | 0:d69efd0ee139 | 289 | /* 84 */ {7,5,16,0xffb1}, |
cgraham | 0:d69efd0ee139 | 290 | /* 85 */ {7,6,16,0xffb2}, |
cgraham | 0:d69efd0ee139 | 291 | /* 86 */ {7,7,16,0xffb3}, |
cgraham | 0:d69efd0ee139 | 292 | /* 87 */ {7,8,16,0xffb4}, |
cgraham | 0:d69efd0ee139 | 293 | /* 88 */ {7,9,16,0xffb5}, |
cgraham | 0:d69efd0ee139 | 294 | /* 89 */ {7,10,16,0xffb6}, |
cgraham | 0:d69efd0ee139 | 295 | /* 90 */ {8,2,16,0xffb7}, |
cgraham | 0:d69efd0ee139 | 296 | /* 91 */ {8,3,16,0xffb8}, |
cgraham | 0:d69efd0ee139 | 297 | /* 92 */ {8,4,16,0xffb9}, |
cgraham | 0:d69efd0ee139 | 298 | /* 93 */ {8,5,16,0xffba}, |
cgraham | 0:d69efd0ee139 | 299 | /* 94 */ {8,6,16,0xffbb}, |
cgraham | 0:d69efd0ee139 | 300 | /* 95 */ {8,7,16,0xffbc}, |
cgraham | 0:d69efd0ee139 | 301 | /* 96 */ {8,8,16,0xffbd}, |
cgraham | 0:d69efd0ee139 | 302 | /* 97 */ {8,9,16,0xffbe}, |
cgraham | 0:d69efd0ee139 | 303 | /* 98 */ {8,10,16,0xffbf}, |
cgraham | 0:d69efd0ee139 | 304 | /* 99 */ {9,2,16,0xffc0}, |
cgraham | 0:d69efd0ee139 | 305 | /* 100 */ {9,3,16,0xffc1}, |
cgraham | 0:d69efd0ee139 | 306 | /* 101 */ {9,4,16,0xffc2}, |
cgraham | 0:d69efd0ee139 | 307 | /* 102 */ {9,5,16,0xffc3}, |
cgraham | 0:d69efd0ee139 | 308 | /* 103 */ {9,6,16,0xffc4}, |
cgraham | 0:d69efd0ee139 | 309 | /* 104 */ {9,7,16,0xffc5}, |
cgraham | 0:d69efd0ee139 | 310 | /* 105 */ {9,8,16,0xffc6}, |
cgraham | 0:d69efd0ee139 | 311 | /* 106 */ {9,9,16,0xffc7}, |
cgraham | 0:d69efd0ee139 | 312 | /* 107 */ {9,10,16,0xffc8}, |
cgraham | 0:d69efd0ee139 | 313 | /* 108 */ {10,2,16,0xffc9}, |
cgraham | 0:d69efd0ee139 | 314 | /* 109 */ {10,3,16,0xffca}, |
cgraham | 0:d69efd0ee139 | 315 | /* 110 */ {10,4,16,0xffcb}, |
cgraham | 0:d69efd0ee139 | 316 | /* 111 */ {10,5,16,0xffcc}, |
cgraham | 0:d69efd0ee139 | 317 | /* 112 */ {10,6,16,0xffcd}, |
cgraham | 0:d69efd0ee139 | 318 | /* 113 */ {10,7,16,0xffce}, |
cgraham | 0:d69efd0ee139 | 319 | /* 114 */ {10,8,16,0xffcf}, |
cgraham | 0:d69efd0ee139 | 320 | /* 115 */ {10,9,16,0xffd0}, |
cgraham | 0:d69efd0ee139 | 321 | /* 116 */ {10,10,16,0xffd1}, |
cgraham | 0:d69efd0ee139 | 322 | /* 117 */ {11,2,16,0xffd2}, |
cgraham | 0:d69efd0ee139 | 323 | /* 118 */ {11,3,16,0xffd3}, |
cgraham | 0:d69efd0ee139 | 324 | /* 119 */ {11,4,16,0xffd4}, |
cgraham | 0:d69efd0ee139 | 325 | /* 120 */ {11,5,16,0xffd5}, |
cgraham | 0:d69efd0ee139 | 326 | /* 121 */ {11,6,16,0xffd6}, |
cgraham | 0:d69efd0ee139 | 327 | /* 122 */ {11,7,16,0xffd7}, |
cgraham | 0:d69efd0ee139 | 328 | /* 123 */ {11,8,16,0xffd8}, |
cgraham | 0:d69efd0ee139 | 329 | /* 124 */ {11,9,16,0xffd9}, |
cgraham | 0:d69efd0ee139 | 330 | /* 125 */ {11,10,16,0xffda}, |
cgraham | 0:d69efd0ee139 | 331 | /* 126 */ {12,2,16,0xffdb}, |
cgraham | 0:d69efd0ee139 | 332 | /* 127 */ {12,3,16,0xffdc}, |
cgraham | 0:d69efd0ee139 | 333 | /* 128 */ {12,4,16,0xffdd}, |
cgraham | 0:d69efd0ee139 | 334 | /* 129 */ {12,5,16,0xffde}, |
cgraham | 0:d69efd0ee139 | 335 | /* 130 */ {12,6,16,0xffdf}, |
cgraham | 0:d69efd0ee139 | 336 | /* 131 */ {12,7,16,0xffe0}, |
cgraham | 0:d69efd0ee139 | 337 | /* 132 */ {12,8,16,0xffe1}, |
cgraham | 0:d69efd0ee139 | 338 | /* 133 */ {12,9,16,0xffe2}, |
cgraham | 0:d69efd0ee139 | 339 | /* 134 */ {12,10,16,0xffe3}, |
cgraham | 0:d69efd0ee139 | 340 | /* 135 */ {13,2,16,0xffe4}, |
cgraham | 0:d69efd0ee139 | 341 | /* 136 */ {13,3,16,0xffe5}, |
cgraham | 0:d69efd0ee139 | 342 | /* 137 */ {13,4,16,0xffe6}, |
cgraham | 0:d69efd0ee139 | 343 | /* 138 */ {13,5,16,0xffe7}, |
cgraham | 0:d69efd0ee139 | 344 | /* 139 */ {13,6,16,0xffe8}, |
cgraham | 0:d69efd0ee139 | 345 | /* 140 */ {13,7,16,0xffe9}, |
cgraham | 0:d69efd0ee139 | 346 | /* 141 */ {13,8,16,0xffea}, |
cgraham | 0:d69efd0ee139 | 347 | /* 142 */ {13,9,16,0xffeb}, |
cgraham | 0:d69efd0ee139 | 348 | /* 143 */ {13,10,16,0xffec}, |
cgraham | 0:d69efd0ee139 | 349 | /* 144 */ {14,2,16,0xffed}, |
cgraham | 0:d69efd0ee139 | 350 | /* 145 */ {14,3,16,0xffee}, |
cgraham | 0:d69efd0ee139 | 351 | /* 146 */ {14,4,16,0xffef}, |
cgraham | 0:d69efd0ee139 | 352 | /* 147 */ {14,5,16,0xfff0}, |
cgraham | 0:d69efd0ee139 | 353 | /* 148 */ {14,6,16,0xfff1}, |
cgraham | 0:d69efd0ee139 | 354 | /* 149 */ {14,7,16,0xfff2}, |
cgraham | 0:d69efd0ee139 | 355 | /* 150 */ {14,8,16,0xfff3}, |
cgraham | 0:d69efd0ee139 | 356 | /* 151 */ {14,9,16,0xfff4}, |
cgraham | 0:d69efd0ee139 | 357 | /* 152 */ {14,10,16,0xfff5}, |
cgraham | 0:d69efd0ee139 | 358 | /* 153 */ {15,2,16,0xfff6}, |
cgraham | 0:d69efd0ee139 | 359 | /* 154 */ {15,3,16,0xfff7}, |
cgraham | 0:d69efd0ee139 | 360 | /* 155 */ {15,4,16,0xfff8}, |
cgraham | 0:d69efd0ee139 | 361 | /* 156 */ {15,5,16,0xfff9}, |
cgraham | 0:d69efd0ee139 | 362 | /* 157 */ {15,6,16,0xfffa}, |
cgraham | 0:d69efd0ee139 | 363 | /* 158 */ {15,7,16,0xfffb}, |
cgraham | 0:d69efd0ee139 | 364 | /* 159 */ {15,8,16,0xfffc}, |
cgraham | 0:d69efd0ee139 | 365 | /* 160 */ {15,9,16,0xfffd}, |
cgraham | 0:d69efd0ee139 | 366 | /* 161 */ {15,10,16,0xfffe}, |
cgraham | 0:d69efd0ee139 | 367 | }; |
cgraham | 0:d69efd0ee139 | 368 | |
cgraham | 0:d69efd0ee139 | 369 | #ifndef JPEG_USE_HUFFMAN_TABLE |
cgraham | 0:d69efd0ee139 | 370 | Huff* HuffmanDecode::Lookup(int tc, int th, BitPattern* bitpat) |
cgraham | 0:d69efd0ee139 | 371 | { |
cgraham | 0:d69efd0ee139 | 372 | Huff* huff; |
cgraham | 0:d69efd0ee139 | 373 | int size; |
cgraham | 0:d69efd0ee139 | 374 | |
cgraham | 0:d69efd0ee139 | 375 | if (tc == 0) { |
cgraham | 0:d69efd0ee139 | 376 | if (th == 0) { |
cgraham | 0:d69efd0ee139 | 377 | huff = (Huff*)HT_DC_0; |
cgraham | 0:d69efd0ee139 | 378 | size = sizeof(HT_DC_0) / sizeof(Huff); |
cgraham | 0:d69efd0ee139 | 379 | } else { |
cgraham | 0:d69efd0ee139 | 380 | huff = (Huff*)HT_DC_1; |
cgraham | 0:d69efd0ee139 | 381 | size = sizeof(HT_DC_1) / sizeof(Huff); |
cgraham | 0:d69efd0ee139 | 382 | } |
cgraham | 0:d69efd0ee139 | 383 | } else { |
cgraham | 0:d69efd0ee139 | 384 | if (th == 0) { |
cgraham | 0:d69efd0ee139 | 385 | huff = (Huff*)HT_AC_0; |
cgraham | 0:d69efd0ee139 | 386 | size = sizeof(HT_AC_0) / sizeof(Huff); |
cgraham | 0:d69efd0ee139 | 387 | } else { |
cgraham | 0:d69efd0ee139 | 388 | huff = (Huff*)HT_AC_1; |
cgraham | 0:d69efd0ee139 | 389 | size = sizeof(HT_AC_1) / sizeof(Huff); |
cgraham | 0:d69efd0ee139 | 390 | } |
cgraham | 0:d69efd0ee139 | 391 | } |
cgraham | 0:d69efd0ee139 | 392 | |
cgraham | 0:d69efd0ee139 | 393 | for(int i = 0; i < size; i++) { |
cgraham | 0:d69efd0ee139 | 394 | //DBG("%d %p\n", i, huff); |
cgraham | 0:d69efd0ee139 | 395 | if (huff->code_size > bitpat->size()) { |
cgraham | 0:d69efd0ee139 | 396 | return NULL; |
cgraham | 0:d69efd0ee139 | 397 | } |
cgraham | 0:d69efd0ee139 | 398 | BitPattern tmp(huff->code, huff->code_size); |
cgraham | 0:d69efd0ee139 | 399 | if (bitpat->match(tmp)) { |
cgraham | 0:d69efd0ee139 | 400 | return huff; |
cgraham | 0:d69efd0ee139 | 401 | } |
cgraham | 0:d69efd0ee139 | 402 | huff++; |
cgraham | 0:d69efd0ee139 | 403 | } |
cgraham | 0:d69efd0ee139 | 404 | return NULL; |
cgraham | 0:d69efd0ee139 | 405 | } |
cgraham | 0:d69efd0ee139 | 406 | |
cgraham | 0:d69efd0ee139 | 407 | #else // JPEG_USE_HUFFMAN_TABLE |
cgraham | 0:d69efd0ee139 | 408 | |
cgraham | 0:d69efd0ee139 | 409 | struct sthtinfo { |
cgraham | 0:d69efd0ee139 | 410 | const Huff* huff_table; |
cgraham | 0:d69efd0ee139 | 411 | const uint8_t* index_table; |
cgraham | 0:d69efd0ee139 | 412 | int max_code_size; |
cgraham | 0:d69efd0ee139 | 413 | }; |
cgraham | 0:d69efd0ee139 | 414 | |
cgraham | 0:d69efd0ee139 | 415 | const struct sthtinfo htinfo[2][2] = { |
cgraham | 0:d69efd0ee139 | 416 | {{HT_DC_0, HT_DC_0_index, 9}, {HT_DC_1, HT_DC_1_index, 11}}, |
cgraham | 0:d69efd0ee139 | 417 | {{HT_AC_0, HT_AC_0_index, 16}, {HT_AC_1, HT_AC_1_index, 16}}, |
cgraham | 0:d69efd0ee139 | 418 | }; |
cgraham | 0:d69efd0ee139 | 419 | |
cgraham | 0:d69efd0ee139 | 420 | Huff* HuffmanDecode::Lookup(int tc, int th, BitPattern* bitpat) |
cgraham | 0:d69efd0ee139 | 421 | { |
cgraham | 0:d69efd0ee139 | 422 | const struct sthtinfo* info = &htinfo[tc][th]; |
cgraham | 0:d69efd0ee139 | 423 | |
cgraham | 0:d69efd0ee139 | 424 | int pat_size = bitpat->size(); |
cgraham | 0:d69efd0ee139 | 425 | uint32_t pat = bitpat->peek(pat_size); |
cgraham | 0:d69efd0ee139 | 426 | if (pat_size > info->max_code_size) { |
cgraham | 0:d69efd0ee139 | 427 | pat >>= (pat_size-info->max_code_size); |
cgraham | 0:d69efd0ee139 | 428 | } else if (pat_size < info->max_code_size) { |
cgraham | 0:d69efd0ee139 | 429 | pat <<= (info->max_code_size-pat_size); |
cgraham | 0:d69efd0ee139 | 430 | } |
cgraham | 0:d69efd0ee139 | 431 | int index = info->index_table[pat]; |
cgraham | 0:d69efd0ee139 | 432 | if (index == 0xff) { |
cgraham | 0:d69efd0ee139 | 433 | return NULL; |
cgraham | 0:d69efd0ee139 | 434 | } |
cgraham | 0:d69efd0ee139 | 435 | Huff* huff = (Huff*)&(info->huff_table[index]); |
cgraham | 0:d69efd0ee139 | 436 | if (huff->code_size > pat_size) { |
cgraham | 0:d69efd0ee139 | 437 | return NULL; |
cgraham | 0:d69efd0ee139 | 438 | } |
cgraham | 0:d69efd0ee139 | 439 | return huff; |
cgraham | 0:d69efd0ee139 | 440 | } |
cgraham | 0:d69efd0ee139 | 441 | #endif // JPEG_USE_HUFFMAN_TABLE |
cgraham | 0:d69efd0ee139 | 442 | |
cgraham | 0:d69efd0ee139 | 443 | int HuffmanDecode::getValue(Huff* huff, BitPattern* bitpat) |
cgraham | 0:d69efd0ee139 | 444 | { |
cgraham | 0:d69efd0ee139 | 445 | int value = bitpat->get(huff->value_size); |
cgraham | 0:d69efd0ee139 | 446 | if (huff->value_size == 0) { |
cgraham | 0:d69efd0ee139 | 447 | return 0; |
cgraham | 0:d69efd0ee139 | 448 | } |
cgraham | 0:d69efd0ee139 | 449 | if (value & (1<<(huff->value_size-1))) { |
cgraham | 0:d69efd0ee139 | 450 | return value; |
cgraham | 0:d69efd0ee139 | 451 | } |
cgraham | 0:d69efd0ee139 | 452 | value -= (1<<huff->value_size)-1; |
cgraham | 0:d69efd0ee139 | 453 | return value; |
cgraham | 0:d69efd0ee139 | 454 | } |