109 0x0000, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006,
110 0x000E, 0x001E, 0x003E, 0x007E, 0x00FE, 0x01FE
114 0x0002, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003,
115 0x0004, 0x0005, 0x0006, 0x0007, 0x0008, 0x0009
119 0x0000, 0x0001, 0x0002, 0x0006, 0x000E, 0x001E,
120 0x003E, 0x007E, 0x00FE, 0x01FE, 0x03FE, 0x07FE
124 0x0002, 0x0002, 0x0002, 0x0003, 0x0004, 0x0005,
125 0x0006, 0x0007, 0x0008, 0x0009, 0x000A, 0x000B
130 0x0000, 0x0001, 0x0004, 0x000B, 0x001A, 0x0078, 0x00F8, 0x03F6, 0xFF82, 0xFF83,
131 0x000C, 0x001B, 0x0079, 0x01F6, 0x07F6, 0xFF84, 0xFF85, 0xFF86, 0xFF87, 0xFF88,
132 0x001C, 0x00F9, 0x03F7, 0x0FF4, 0xFF89, 0xFF8A, 0xFF8b, 0xFF8C, 0xFF8D, 0xFF8E,
133 0x003A, 0x01F7, 0x0FF5, 0xFF8F, 0xFF90, 0xFF91, 0xFF92, 0xFF93, 0xFF94, 0xFF95,
134 0x003B, 0x03F8, 0xFF96, 0xFF97, 0xFF98, 0xFF99, 0xFF9A, 0xFF9B, 0xFF9C, 0xFF9D,
135 0x007A, 0x07F7, 0xFF9E, 0xFF9F, 0xFFA0, 0xFFA1, 0xFFA2, 0xFFA3, 0xFFA4, 0xFFA5,
136 0x007B, 0x0FF6, 0xFFA6, 0xFFA7, 0xFFA8, 0xFFA9, 0xFFAA, 0xFFAB, 0xFFAC, 0xFFAD,
137 0x00FA, 0x0FF7, 0xFFAE, 0xFFAF, 0xFFB0, 0xFFB1, 0xFFB2, 0xFFB3, 0xFFB4, 0xFFB5,
138 0x01F8, 0x7FC0, 0xFFB6, 0xFFB7, 0xFFB8, 0xFFB9, 0xFFBA, 0xFFBB, 0xFFBC, 0xFFBD,
139 0x01F9, 0xFFBE, 0xFFBF, 0xFFC0, 0xFFC1, 0xFFC2, 0xFFC3, 0xFFC4, 0xFFC5, 0xFFC6,
140 0x01FA, 0xFFC7, 0xFFC8, 0xFFC9, 0xFFCA, 0xFFCB, 0xFFCC, 0xFFCD, 0xFFCE, 0xFFCF,
141 0x03F9, 0xFFD0, 0xFFD1, 0xFFD2, 0xFFD3, 0xFFD4, 0xFFD5, 0xFFD6, 0xFFD7, 0xFFD8,
142 0x03FA, 0xFFD9, 0xFFDA, 0xFFDB, 0xFFDC, 0xFFDD, 0xFFDE, 0xFFDF, 0xFFE0, 0xFFE1,
143 0x07F8, 0xFFE2, 0xFFE3, 0xFFE4, 0xFFE5, 0xFFE6, 0xFFE7, 0xFFE8, 0xFFE9, 0xFFEA,
144 0xFFEB, 0xFFEC, 0xFFED, 0xFFEE, 0xFFEF, 0xFFF0, 0xFFF1, 0xFFF2, 0xFFF3, 0xFFF4,
145 0xFFF5, 0xFFF6, 0xFFF7, 0xFFF8, 0xFFF9, 0xFFFA, 0xFFFB, 0xFFFC, 0xFFFD, 0xFFFE,
151 0x0002, 0x0002, 0x0003, 0x0004, 0x0005, 0x0007, 0x0008, 0x000A, 0x0010, 0x0010,
152 0x0004, 0x0005, 0x0007, 0x0009, 0x000B, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010,
153 0x0005, 0x0008, 0x000A, 0x000C, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010,
154 0x0006, 0x0009, 0x000C, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010,
155 0x0006, 0x000A, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010,
156 0x0007, 0x000B, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010,
157 0x0007, 0x000C, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010,
158 0x0008, 0x000C, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010,
159 0x0009, 0x000F, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010,
160 0x0009, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010,
161 0x0009, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010,
162 0x000A, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010,
163 0x000A, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010,
164 0x000B, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010,
165 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010,
166 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010,
172 0x0001, 0x0004, 0x000A, 0x0018, 0x0019, 0x0038, 0x0078, 0x01F4, 0x03F6, 0x0FF4,
173 0x000B, 0x0039, 0x00F6, 0x01F5, 0x07F6, 0x0FF5, 0xFF88, 0xFF89, 0xFF8A, 0xFF8B,
174 0x001A, 0x00F7, 0x03F7, 0x0FF6, 0x7FC2, 0xFF8C, 0xFF8D, 0xFF8E, 0xFF8F, 0xFF90,
175 0x001B, 0x00F8, 0x03F8, 0x0FF7, 0xFF91, 0xFF92, 0xFF93, 0xFF94, 0xFF95, 0xFF96,
176 0x003A, 0x01F6, 0xFF97, 0xFF98, 0xFF99, 0xFF9A, 0xFF9B, 0xFF9C, 0xFF9D, 0xFF9E,
177 0x003B, 0x03F9, 0xFF9F, 0xFFA0, 0xFFA1, 0xFFA2, 0xFFA3, 0xFFA4, 0xFFA5, 0xFFA6,
178 0x0079, 0x07F7, 0xFFA7, 0xFFA8, 0xFFA9, 0xFFAA, 0xFFAB, 0xFFAC, 0xFFAD, 0xFFAE,
179 0x007A, 0x07F8, 0xFFAF, 0xFFB0, 0xFFB1, 0xFFB2, 0xFFB3, 0xFFB4, 0xFFB5, 0xFFB6,
180 0x00F9, 0xFFB7, 0xFFB8, 0xFFB9, 0xFFBA, 0xFFBB, 0xFFBC, 0xFFBD, 0xFFBE, 0xFFBF,
181 0x01F7, 0xFFC0, 0xFFC1, 0xFFC2, 0xFFC3, 0xFFC4, 0xFFC5, 0xFFC6, 0xFFC7, 0xFFC8,
182 0x01F8, 0xFFC9, 0xFFCA, 0xFFCB, 0xFFCC, 0xFFCD, 0xFFCE, 0xFFCF, 0xFFD0, 0xFFD1,
183 0x01F9, 0xFFD2, 0xFFD3, 0xFFD4, 0xFFD5, 0xFFD6, 0xFFD7, 0xFFD8, 0xFFD9, 0xFFDA,
184 0x01FA, 0xFFDB, 0xFFDC, 0xFFDD, 0xFFDE, 0xFFDF, 0xFFE0, 0xFFE1, 0xFFE2, 0xFFE3,
185 0x07F9, 0xFFE4, 0xFFE5, 0xFFE6, 0xFFE7, 0xFFE8, 0xFFE9, 0xFFEA, 0xFFEb, 0xFFEC,
186 0x3FE0, 0xFFED, 0xFFEE, 0xFFEF, 0xFFF0, 0xFFF1, 0xFFF2, 0xFFF3, 0xFFF4, 0xFFF5,
187 0x7FC3, 0xFFF6, 0xFFF7, 0xFFF8, 0xFFF9, 0xFFFA, 0xFFFB, 0xFFFC, 0xFFFD, 0xFFFE,
193 0x0002, 0x0003, 0x0004, 0x0005, 0x0005, 0x0006, 0x0007, 0x0009, 0x000A, 0x000C,
194 0x0004, 0x0006, 0x0008, 0x0009, 0x000B, 0x000C, 0x0010, 0x0010, 0x0010, 0x0010,
195 0x0005, 0x0008, 0x000A, 0x000C, 0x000F, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010,
196 0x0005, 0x0008, 0x000A, 0x000C, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010,
197 0x0006, 0x0009, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010,
198 0x0006, 0x000A, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010,
199 0x0007, 0x000B, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010,
200 0x0007, 0x000B, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010,
201 0x0008, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010,
202 0x0009, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010,
203 0x0009, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010,
204 0x0009, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010,
205 0x0009, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010,
206 0x000B, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010,
207 0x000E, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010,
208 0x000F, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010,
213 0, 1, 2, 2, 3, 3, 3, 3,
214 4, 4, 4, 4, 4, 4, 4, 4,
215 5, 5, 5, 5, 5, 5, 5, 5,
216 5, 5, 5, 5, 5, 5, 5, 5,
217 6, 6, 6, 6, 6, 6, 6, 6,
218 6, 6, 6, 6, 6, 6, 6, 6,
219 6, 6, 6, 6, 6, 6, 6, 6,
220 6, 6, 6, 6, 6, 6, 6, 6,
221 7, 7, 7, 7, 7, 7, 7, 7,
222 7, 7, 7, 7, 7, 7, 7, 7,
223 7, 7, 7, 7, 7, 7, 7, 7,
224 7, 7, 7, 7, 7, 7, 7, 7,
225 7, 7, 7, 7, 7, 7, 7, 7,
226 7, 7, 7, 7, 7, 7, 7, 7,
227 7, 7, 7, 7, 7, 7, 7, 7,
228 7, 7, 7, 7, 7, 7, 7, 7,
229 8, 8, 8, 8, 8, 8, 8, 8,
230 8, 8, 8, 8, 8, 8, 8, 8,
231 8, 8, 8, 8, 8, 8, 8, 8,
232 8, 8, 8, 8, 8, 8, 8, 8,
233 8, 8, 8, 8, 8, 8, 8, 8,
234 8, 8, 8, 8, 8, 8, 8, 8,
235 8, 8, 8, 8, 8, 8, 8, 8,
236 8, 8, 8, 8, 8, 8, 8, 8,
237 8, 8, 8, 8, 8, 8, 8, 8,
238 8, 8, 8, 8, 8, 8, 8, 8,
239 8, 8, 8, 8, 8, 8, 8, 8,
240 8, 8, 8, 8, 8, 8, 8, 8,
241 8, 8, 8, 8, 8, 8, 8, 8,
242 8, 8, 8, 8, 8, 8, 8, 8,
243 8, 8, 8, 8, 8, 8, 8, 8,
244 8, 8, 8, 8, 8, 8, 8, 8
248 0xFF, 0xC4, 0x00, 0x1F, 0x00, 0x00, 0x01, 0x05, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B,
250 0xFF, 0xC4, 0x00, 0xB5, 0x10, 0x00, 0x02, 0x01, 0x03, 0x03, 0x02, 0x04, 0x03, 0x05, 0x05, 0x04, 0x04, 0x00, 0x00, 0x01, 0x7D, 0x01, 0x02, 0x03, 0x00, 0x04, 0x11, 0x05, 0x12, 0x21, 0x31, 0x41, 0x06, 0x13, 0x51, 0x61, 0x07, 0x22, 0x71, 0x14, 0x32, 0x81, 0x91, 0xA1, 0x08, 0x23, 0x42, 0xB1, 0xC1, 0x15, 0x52, 0xD1, 0xF0, 0x24, 0x33, 0x62, 0x72, 0x82, 0x09, 0x0A, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6A, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7A, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8A, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9A, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7, 0xA8, 0xA9, 0xAA, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0xB7, 0xB8, 0xB9, 0xBA, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8, 0xC9, 0xCA, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7, 0xD8, 0xD9, 0xDA, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, 0xE8, 0xE9, 0xEA, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, 0xF8, 0xF9, 0xFA,
252 0xFF, 0xC4, 0x00, 0x1F, 0x01, 0x00, 0x03, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B,
254 0xFF, 0xC4, 0x00, 0xB5, 0x11, 0x00, 0x02, 0x01, 0x02, 0x04, 0x04, 0x03, 0x04, 0x07, 0x05, 0x04, 0x04, 0x00, 0x01, 0x02, 0x77, 0x00, 0x01, 0x02, 0x03, 0x11, 0x04, 0x05, 0x21, 0x31, 0x06, 0x12, 0x41, 0x51, 0x07, 0x61, 0x71, 0x13, 0x22, 0x32, 0x81, 0x08, 0x14, 0x42, 0x91, 0xA1, 0xB1, 0xC1, 0x09, 0x23, 0x33, 0x52, 0xF0, 0x15, 0x62, 0x72, 0xD1, 0x0A, 0x16, 0x24, 0x34, 0xE1, 0x25, 0xF1, 0x17, 0x18, 0x19, 0x1A, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6A, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7A, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8A, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9A, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7, 0xA8, 0xA9, 0xAA, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0xB7, 0xB8, 0xB9, 0xBA, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8, 0xC9, 0xCA, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7, 0xD8, 0xD9, 0xDA, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, 0xE8, 0xE9, 0xEA, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, 0xF8, 0xF9, 0xFA,
259 0, 1, 5, 6, 14, 15, 27, 28,
260 2, 4, 7, 13, 16, 26, 29, 42,
261 3, 8, 12, 17, 25, 30, 41, 43,
262 9, 11, 18, 24, 31, 40, 44, 53,
263 10, 19, 23, 32, 39, 45, 52, 54,
264 20, 22, 33, 38, 46, 51, 55, 60,
265 21, 34, 37, 47, 50, 56, 59, 61,
266 35, 36, 48, 49, 57, 58, 62, 63
290 #define JPEG_BLOCK_SIZE 64
311 uint16_t mcu_width, mcu_height, bytes_per_pixel;
358 16, 11, 10, 16, 24, 40, 51, 61,
359 12, 12, 14, 19, 26, 58, 60, 55,
360 14, 13, 16, 24, 40, 57, 69, 56,
361 14, 17, 22, 29, 51, 87, 80, 62,
362 18, 22, 37, 56, 68, 109, 103, 77,
363 24, 35, 55, 64, 81, 104, 113, 92,
364 49, 64, 78, 87, 103, 121, 120, 101,
365 72, 92, 95, 98, 112, 100, 103, 99
372 17, 18, 24, 47, 99, 99, 99, 99,
373 18, 21, 26, 66, 99, 99, 99, 99,
374 24, 26, 56, 99, 99, 99, 99, 99,
375 47, 66, 99, 99, 99, 99, 99, 99,
376 99, 99, 99, 99, 99, 99, 99, 99,
377 99, 99, 99, 99, 99, 99, 99, 99,
378 99, 99, 99, 99, 99, 99, 99, 99,
379 99, 99, 99, 99, 99, 99, 99, 99
391 if (q < 1) { factor = 1; }
392 if (q > 99) { factor = 99; }
396 q = 200 - factor * 2;
400 for (i = 0; i < 64; i++) {
405 if (lq < 1) { lq = 1; }
406 else if (lq > 255) { lq = 255; }
408 ILqt [i] = 0x8000 / lq;
410 if (cq < 1) { cq = 1; }
411 else if (cq > 255) { cq = 255; }
414 ICqt [i] = 0x8000 / cq;
451 if (add_dri_header) {
455 for (i = 1; i <= jpeg_encoder_structure->
vertical_mcus; i++) {
456 if (i < jpeg_encoder_structure->vertical_mcus) {
457 jpeg_encoder_structure->
rows = jpeg_encoder_structure->
mcu_height;
463 if (j < jpeg_encoder_structure->horizontal_mcus) {
464 jpeg_encoder_structure->
cols = jpeg_encoder_structure->
mcu_width;
474 output_ptr =
jpeg_encodeMCU(jpeg_encoder_structure, image_format, output_ptr);
479 input_ptr += jpeg_encoder_structure->
offset;
494 output_ptr =
jpeg_huffman(jpeg_encoder_structure, 1, output_ptr);
500 output_ptr =
jpeg_huffman(jpeg_encoder_structure, 1, output_ptr);
505 output_ptr =
jpeg_huffman(jpeg_encoder_structure, 2, output_ptr);
510 output_ptr =
jpeg_huffman(jpeg_encoder_structure, 3, output_ptr);
520 for (i = 63; i >= 0; i--) {
532 int32_t x0, x1, x2, x3, x4, x5, x6, x7, x8;
545 for (i = 8; i > 0; i--) {
546 x8 = data [0] + data [7];
547 x0 = data [0] - data [7];
549 x7 = data [1] + data [6];
550 x1 = data [1] - data [6];
552 x6 = data [2] + data [5];
553 x2 = data [2] - data [5];
555 x5 = data [3] + data [4];
556 x3 = data [3] - data [4];
567 data [2] = (
int16_t)((x8 * c2 + x7 * c6) >> s2);
568 data [6] = (
int16_t)((x8 * c6 - x7 * c2) >> s2);
570 data [7] = (
int16_t)((x0 * c7 - x1 * c5 + x2 * c3 - x3 * c1) >> s2);
571 data [5] = (
int16_t)((x0 * c5 - x1 * c1 + x2 * c7 + x3 * c3) >> s2);
572 data [3] = (
int16_t)((x0 * c3 - x1 * c7 - x2 * c1 - x3 * c5) >> s2);
573 data [1] = (
int16_t)((x0 * c1 + x1 * c3 + x2 * c5 + x3 * c7) >> s2);
580 for (i = 8; i > 0; i--) {
581 x8 = data [0] + data [56];
582 x0 = data [0] - data [56];
584 x7 = data [8] + data [48];
585 x1 = data [8] - data [48];
587 x6 = data [16] + data [40];
588 x2 = data [16] - data [40];
590 x5 = data [24] + data [32];
591 x3 = data [24] - data [32];
599 data [0] = (
int16_t)((x4 + x5) >> s1);
600 data [32] = (
int16_t)((x4 - x5) >> s1);
602 data [16] = (
int16_t)((x8 * c2 + x7 * c6) >> s3);
603 data [48] = (
int16_t)((x8 * c6 - x7 * c2) >> s3);
605 data [56] = (
int16_t)((x0 * c7 - x1 * c5 + x2 * c3 - x3 * c1) >> s3);
606 data [40] = (
int16_t)((x0 * c5 - x1 * c1 + x2 * c7 + x3 * c3) >> s3);
607 data [24] = (
int16_t)((x0 * c3 - x1 * c7 - x2 * c1 - x3 * c5) >> s3);
608 data [8] = (
int16_t)((x0 * c1 + x1 * c3 + x2 * c5 + x3 * c7) >> s3);
616 bits_in_next_word = (int16_t) (bitindex + numbits - 32); \
617 if (bits_in_next_word < 0) \
619 lcode = (lcode << numbits) | data; \
620 bitindex += numbits; \
624 lcode = (lcode << (32 - bitindex)) | (data >> bits_in_next_word); \
625 if ((*output_ptr++ = (uint8_t)(lcode >> 24)) == 0xff) \
627 if ((*output_ptr++ = (uint8_t)(lcode >> 16)) == 0xff) \
629 if ((*output_ptr++ = (uint8_t)(lcode >> 8)) == 0xff) \
631 if ((*output_ptr++ = (uint8_t) lcode) == 0xff) \
634 bitindex = bits_in_next_word; \
641 uint16_t *DcCodeTable, *DcSizeTable, *AcCodeTable, *AcSizeTable;
643 int16_t *Temp_Ptr, Coeff, LastDc;
644 uint16_t AbsCoeff, HuffCode, HuffSize, RunLength = 0, DataSize = 0, index;
653 if (component == 1) {
659 LastDc = jpeg_encoder_structure->
ldc1;
660 jpeg_encoder_structure->
ldc1 = Coeff;
667 if (component == 2) {
668 LastDc = jpeg_encoder_structure->
ldc2;
669 jpeg_encoder_structure->
ldc2 = Coeff;
671 LastDc = jpeg_encoder_structure->
ldc3;
672 jpeg_encoder_structure->
ldc3 = Coeff;
678 AbsCoeff = (Coeff < 0) ? -Coeff-- : Coeff;
680 while (AbsCoeff != 0) {
685 HuffCode = DcCodeTable [DataSize];
686 HuffSize = DcSizeTable [DataSize];
688 Coeff &= (1 << DataSize) - 1;
689 data = (HuffCode << DataSize) | Coeff;
690 numbits = HuffSize + DataSize;
694 for (i = 63; i > 0; i--) {
695 if ((Coeff = *Temp_Ptr++) != 0) {
696 while (RunLength > 15) {
698 data = AcCodeTable [161];
699 numbits = AcSizeTable [161];
703 AbsCoeff = (Coeff < 0) ? -Coeff-- : Coeff;
705 if (AbsCoeff >> 8 == 0) {
708 DataSize =
bitsize [AbsCoeff >> 8] + 8;
711 index = RunLength * 10 + DataSize;
712 HuffCode = AcCodeTable [index];
713 HuffSize = AcSizeTable [index];
715 Coeff &= (1 << DataSize) - 1;
716 data = (HuffCode << DataSize) | Coeff;
717 numbits = HuffSize + DataSize;
726 if (RunLength != 0) {
727 data = AcCodeTable [0];
728 numbits = AcSizeTable [0];
749 for (i = 0; i < count; i++)
750 if ((*output_ptr++ = *ptr--) == 0xff) {
756 *output_ptr++ = 0xFF;
757 *output_ptr++ = 0xD9;
767 *output_ptr++ = 0xFF;
768 *output_ptr++ = 0xD8;
771 *output_ptr++ = 0xFF;
772 *output_ptr++ = 0xDB;
775 *output_ptr++ = 0x00;
776 *output_ptr++ = 0x43;
779 *output_ptr++ = 0x00;
782 for (i = 0; i < 64; i++) {
783 *output_ptr++ =
Lqt [i];
787 *output_ptr++ = 0xFF;
788 *output_ptr++ = 0xDB;
791 *output_ptr++ = 0x00;
792 *output_ptr++ = 0x43;
795 *output_ptr++ = 0x01;
798 for (i = 0; i < 64; i++) {
799 *output_ptr++ =
Cqt [i];
803 number_of_components = 1;
805 number_of_components = 3;
811 *output_ptr++ = 0xFF;
812 *output_ptr++ = 0xC0;
814 header_length = (
uint16_t)(8 + 3 * number_of_components);
817 *output_ptr++ = (
uint8_t)(header_length >> 8);
818 *output_ptr++ = (
uint8_t) header_length;
821 *output_ptr++ = 0x08;
824 *output_ptr++ = (
uint8_t)(image_height >> 8);
825 *output_ptr++ = (
uint8_t) image_height;
828 *output_ptr++ = (
uint8_t)(image_width >> 8);
829 *output_ptr++ = (
uint8_t) image_width;
832 *output_ptr++ = number_of_components;
835 *output_ptr++ = 0x01;
836 *output_ptr++ = 0x11;
837 *output_ptr++ = 0x00;
839 *output_ptr++ = 0x01;
842 *output_ptr++ = 0x21;
844 *output_ptr++ = 0x11;
847 *output_ptr++ = 0x00;
849 *output_ptr++ = 0x02;
850 *output_ptr++ = 0x11;
851 *output_ptr++ = 0x01;
853 *output_ptr++ = 0x03;
854 *output_ptr++ = 0x11;
855 *output_ptr++ = 0x01;
868 *output_ptr++ = 0xFF;
869 *output_ptr++ = 0xDA;
871 header_length = (
uint16_t)(6 + (number_of_components << 1));
874 *output_ptr++ = (
uint8_t)(header_length >> 8);
875 *output_ptr++ = (
uint8_t) header_length;
878 *output_ptr++ = number_of_components;
881 *output_ptr++ = 0x01;
882 *output_ptr++ = 0x00;
884 *output_ptr++ = 0x01;
885 *output_ptr++ = 0x00;
887 *output_ptr++ = 0x02;
888 *output_ptr++ = 0x11;
890 *output_ptr++ = 0x03;
891 *output_ptr++ = 0x11;
894 *output_ptr++ = 0x00;
895 *output_ptr++ = 0x3F;
896 *output_ptr++ = 0x00;
954 for (i = 63; i >= 0; i--) {
955 value = data [i] * quant_table_ptr [i];
956 value = (value + 0x4000) >> 15;
971 for (i = rows; i > 0; i--) {
972 for (j = cols; j > 0; j--) {
973 *Y1_Ptr++ = *input_ptr++;
976 for (j = 8 - cols; j > 0; j--) {
977 *Y1_Ptr = *(Y1_Ptr - 1);
984 for (i = 8 - rows; i > 0; i--) {
985 for (j = 8; j > 0; j--) {
986 *Y1_Ptr = *(Y1_Ptr - 8);
1014 for (i = rows; i > 0; i--) {
1015 for (j = Y1_cols >> 1; j > 0; j--) {
1016 *CB_Ptr++ = *input_ptr++;
1017 *Y1_Ptr++ = *input_ptr++;
1018 *CR_Ptr++ = *input_ptr++;
1019 *Y1_Ptr++ = *input_ptr++;
1022 for (j = Y2_cols >> 1; j > 0; j--) {
1023 *CB_Ptr++ = *input_ptr++;
1024 *Y2_Ptr++ = *input_ptr++;
1025 *CR_Ptr++ = *input_ptr++;
1026 *Y2_Ptr++ = *input_ptr++;
1030 for (j = 8 - Y1_cols; j > 0; j--) {
1031 *Y1_Ptr = *(Y1_Ptr - 1);
1035 for (j = 8 - Y2_cols; j > 0; j--) {
1036 *Y2_Ptr = *(Y1_Ptr - 1);
1040 for (j = 8 - Y2_cols; j > 0; j--) {
1041 *Y2_Ptr = *(Y2_Ptr - 1);
1046 for (j = (16 - cols) >> 1; j > 0; j--) {
1047 *CB_Ptr = *(CB_Ptr - 1); CB_Ptr++;
1048 *CR_Ptr = *(CR_Ptr - 1); CR_Ptr++;
1054 for (i = 8 - rows; i > 0; i--) {
1055 for (j = 8; j > 0; j--) {
1056 *Y1_Ptr = *(Y1_Ptr - 8); Y1_Ptr++;
1057 *Y2_Ptr = *(Y2_Ptr - 8); Y2_Ptr++;
1058 *CB_Ptr = *(CB_Ptr - 8); CB_Ptr++;
1059 *CR_Ptr = *(CR_Ptr - 8); CR_Ptr++;
static int16_t CB[JPEG_BLOCK_SIZE]
static uint8_t * jpeg_close_bitstream(uint8_t *)
static void jpeg_initialization(JPEG_ENCODER_STRUCTURE *, uint32_t, uint32_t, uint32_t)
static uint16_t luminance_dc_size_table[]
uint32_t buf_size
The buffer size.
static uint8_t markerdata[]
static uint16_t ICqt[JPEG_BLOCK_SIZE]
static uint8_t * jpeg_write_markers(uint8_t *, uint32_t, uint32_t, uint32_t)
static uint16_t chrominance_ac_size_table[]
static uint8_t Lqt[JPEG_BLOCK_SIZE]
static uint8_t * jpeg_encodeMCU(JPEG_ENCODER_STRUCTURE *, uint32_t, uint8_t *)
static uint8_t Cqt[JPEG_BLOCK_SIZE]
uint16_t length_minus_width
static unsigned char svs_size_code(int w)
static uint16_t ILqt[JPEG_BLOCK_SIZE]
static void jpeg_DCT(int16_t *)
uint16_t length_minus_mcu_width
static uint16_t luminance_ac_code_table[]
static const int jpeg_chroma_quantizer[64]
static int16_t Y1[JPEG_BLOCK_SIZE]
static void jpeg_read_422_format(JPEG_ENCODER_STRUCTURE *, uint8_t *)
void jpeg_encode_image(struct image_t *in, struct image_t *out, uint32_t quality_factor, bool_t add_dri_header)
Encode an YUV422 image.
static void jpeg_levelshift(int16_t *)
static uint16_t chrominance_ac_code_table[]
static int16_t CR[JPEG_BLOCK_SIZE]
static int16_t Y2[JPEG_BLOCK_SIZE]
void * buf
Image buffer (depending on the image_type)
static const int jpeg_luma_quantizer[64]
void(* read_format)(JPEG_ENCODER_STRUCTURE *jpeg_encoder_structure, uint8_t *input_ptr)
uint16_t cols_in_right_mcus
Encode images with the use of the JPEG encoding.
struct JPEG_ENCODER_STRUCTURE JPEG_ENCODER_STRUCTURE
static uint16_t chrominance_dc_size_table[]
static uint16_t luminance_dc_code_table[]
static int16_t Temp[JPEG_BLOCK_SIZE]
UYVY format (uint16 per pixel)
int jpeg_create_svs_header(unsigned char *jpegbuf, int32_t size, int w)
uint16_t rows_in_bottom_mcus
Grayscale image with only the Y part (uint8 per pixel)
static uint8_t zigzag_table[]
static uint16_t chrominance_dc_code_table[]
static uint16_t luminance_ac_size_table[]
static void jpeg_read_400_format(JPEG_ENCODER_STRUCTURE *, uint8_t *)
static uint8_t * jpeg_huffman(JPEG_ENCODER_STRUCTURE *, uint16_t, uint8_t *)
static void jpeg_quantization(int16_t *, uint16_t *)
enum image_type type
The image type.