63 #define JPEG_BLOCK_SIZE 64
125 0x0000, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006,
126 0x000E, 0x001E, 0x003E, 0x007E, 0x00FE, 0x01FE
130 0x0002, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003,
131 0x0004, 0x0005, 0x0006, 0x0007, 0x0008, 0x0009
135 0x0000, 0x0001, 0x0002, 0x0006, 0x000E, 0x001E,
136 0x003E, 0x007E, 0x00FE, 0x01FE, 0x03FE, 0x07FE
140 0x0002, 0x0002, 0x0002, 0x0003, 0x0004, 0x0005,
141 0x0006, 0x0007, 0x0008, 0x0009, 0x000A, 0x000B
146 0x0000, 0x0001, 0x0004, 0x000B, 0x001A, 0x0078, 0x00F8, 0x03F6, 0xFF82, 0xFF83,
147 0x000C, 0x001B, 0x0079, 0x01F6, 0x07F6, 0xFF84, 0xFF85, 0xFF86, 0xFF87, 0xFF88,
148 0x001C, 0x00F9, 0x03F7, 0x0FF4, 0xFF89, 0xFF8A, 0xFF8b, 0xFF8C, 0xFF8D, 0xFF8E,
149 0x003A, 0x01F7, 0x0FF5, 0xFF8F, 0xFF90, 0xFF91, 0xFF92, 0xFF93, 0xFF94, 0xFF95,
150 0x003B, 0x03F8, 0xFF96, 0xFF97, 0xFF98, 0xFF99, 0xFF9A, 0xFF9B, 0xFF9C, 0xFF9D,
151 0x007A, 0x07F7, 0xFF9E, 0xFF9F, 0xFFA0, 0xFFA1, 0xFFA2, 0xFFA3, 0xFFA4, 0xFFA5,
152 0x007B, 0x0FF6, 0xFFA6, 0xFFA7, 0xFFA8, 0xFFA9, 0xFFAA, 0xFFAB, 0xFFAC, 0xFFAD,
153 0x00FA, 0x0FF7, 0xFFAE, 0xFFAF, 0xFFB0, 0xFFB1, 0xFFB2, 0xFFB3, 0xFFB4, 0xFFB5,
154 0x01F8, 0x7FC0, 0xFFB6, 0xFFB7, 0xFFB8, 0xFFB9, 0xFFBA, 0xFFBB, 0xFFBC, 0xFFBD,
155 0x01F9, 0xFFBE, 0xFFBF, 0xFFC0, 0xFFC1, 0xFFC2, 0xFFC3, 0xFFC4, 0xFFC5, 0xFFC6,
156 0x01FA, 0xFFC7, 0xFFC8, 0xFFC9, 0xFFCA, 0xFFCB, 0xFFCC, 0xFFCD, 0xFFCE, 0xFFCF,
157 0x03F9, 0xFFD0, 0xFFD1, 0xFFD2, 0xFFD3, 0xFFD4, 0xFFD5, 0xFFD6, 0xFFD7, 0xFFD8,
158 0x03FA, 0xFFD9, 0xFFDA, 0xFFDB, 0xFFDC, 0xFFDD, 0xFFDE, 0xFFDF, 0xFFE0, 0xFFE1,
159 0x07F8, 0xFFE2, 0xFFE3, 0xFFE4, 0xFFE5, 0xFFE6, 0xFFE7, 0xFFE8, 0xFFE9, 0xFFEA,
160 0xFFEB, 0xFFEC, 0xFFED, 0xFFEE, 0xFFEF, 0xFFF0, 0xFFF1, 0xFFF2, 0xFFF3, 0xFFF4,
161 0xFFF5, 0xFFF6, 0xFFF7, 0xFFF8, 0xFFF9, 0xFFFA, 0xFFFB, 0xFFFC, 0xFFFD, 0xFFFE,
167 0x0002, 0x0002, 0x0003, 0x0004, 0x0005, 0x0007, 0x0008, 0x000A, 0x0010, 0x0010,
168 0x0004, 0x0005, 0x0007, 0x0009, 0x000B, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010,
169 0x0005, 0x0008, 0x000A, 0x000C, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010,
170 0x0006, 0x0009, 0x000C, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010,
171 0x0006, 0x000A, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010,
172 0x0007, 0x000B, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010,
173 0x0007, 0x000C, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010,
174 0x0008, 0x000C, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010,
175 0x0009, 0x000F, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010,
176 0x0009, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010,
177 0x0009, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010,
178 0x000A, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010,
179 0x000A, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010,
180 0x000B, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010,
181 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010,
182 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010,
188 0x0001, 0x0004, 0x000A, 0x0018, 0x0019, 0x0038, 0x0078, 0x01F4, 0x03F6, 0x0FF4,
189 0x000B, 0x0039, 0x00F6, 0x01F5, 0x07F6, 0x0FF5, 0xFF88, 0xFF89, 0xFF8A, 0xFF8B,
190 0x001A, 0x00F7, 0x03F7, 0x0FF6, 0x7FC2, 0xFF8C, 0xFF8D, 0xFF8E, 0xFF8F, 0xFF90,
191 0x001B, 0x00F8, 0x03F8, 0x0FF7, 0xFF91, 0xFF92, 0xFF93, 0xFF94, 0xFF95, 0xFF96,
192 0x003A, 0x01F6, 0xFF97, 0xFF98, 0xFF99, 0xFF9A, 0xFF9B, 0xFF9C, 0xFF9D, 0xFF9E,
193 0x003B, 0x03F9, 0xFF9F, 0xFFA0, 0xFFA1, 0xFFA2, 0xFFA3, 0xFFA4, 0xFFA5, 0xFFA6,
194 0x0079, 0x07F7, 0xFFA7, 0xFFA8, 0xFFA9, 0xFFAA, 0xFFAB, 0xFFAC, 0xFFAD, 0xFFAE,
195 0x007A, 0x07F8, 0xFFAF, 0xFFB0, 0xFFB1, 0xFFB2, 0xFFB3, 0xFFB4, 0xFFB5, 0xFFB6,
196 0x00F9, 0xFFB7, 0xFFB8, 0xFFB9, 0xFFBA, 0xFFBB, 0xFFBC, 0xFFBD, 0xFFBE, 0xFFBF,
197 0x01F7, 0xFFC0, 0xFFC1, 0xFFC2, 0xFFC3, 0xFFC4, 0xFFC5, 0xFFC6, 0xFFC7, 0xFFC8,
198 0x01F8, 0xFFC9, 0xFFCA, 0xFFCB, 0xFFCC, 0xFFCD, 0xFFCE, 0xFFCF, 0xFFD0, 0xFFD1,
199 0x01F9, 0xFFD2, 0xFFD3, 0xFFD4, 0xFFD5, 0xFFD6, 0xFFD7, 0xFFD8, 0xFFD9, 0xFFDA,
200 0x01FA, 0xFFDB, 0xFFDC, 0xFFDD, 0xFFDE, 0xFFDF, 0xFFE0, 0xFFE1, 0xFFE2, 0xFFE3,
201 0x07F9, 0xFFE4, 0xFFE5, 0xFFE6, 0xFFE7, 0xFFE8, 0xFFE9, 0xFFEA, 0xFFEb, 0xFFEC,
202 0x3FE0, 0xFFED, 0xFFEE, 0xFFEF, 0xFFF0, 0xFFF1, 0xFFF2, 0xFFF3, 0xFFF4, 0xFFF5,
203 0x7FC3, 0xFFF6, 0xFFF7, 0xFFF8, 0xFFF9, 0xFFFA, 0xFFFB, 0xFFFC, 0xFFFD, 0xFFFE,
209 0x0002, 0x0003, 0x0004, 0x0005, 0x0005, 0x0006, 0x0007, 0x0009, 0x000A, 0x000C,
210 0x0004, 0x0006, 0x0008, 0x0009, 0x000B, 0x000C, 0x0010, 0x0010, 0x0010, 0x0010,
211 0x0005, 0x0008, 0x000A, 0x000C, 0x000F, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010,
212 0x0005, 0x0008, 0x000A, 0x000C, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010,
213 0x0006, 0x0009, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010,
214 0x0006, 0x000A, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010,
215 0x0007, 0x000B, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010,
216 0x0007, 0x000B, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010,
217 0x0008, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010,
218 0x0009, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010,
219 0x0009, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010,
220 0x0009, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010,
221 0x0009, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010,
222 0x000B, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010,
223 0x000E, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010,
224 0x000F, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010,
229 0, 1, 2, 2, 3, 3, 3, 3,
230 4, 4, 4, 4, 4, 4, 4, 4,
231 5, 5, 5, 5, 5, 5, 5, 5,
232 5, 5, 5, 5, 5, 5, 5, 5,
233 6, 6, 6, 6, 6, 6, 6, 6,
234 6, 6, 6, 6, 6, 6, 6, 6,
235 6, 6, 6, 6, 6, 6, 6, 6,
236 6, 6, 6, 6, 6, 6, 6, 6,
237 7, 7, 7, 7, 7, 7, 7, 7,
238 7, 7, 7, 7, 7, 7, 7, 7,
239 7, 7, 7, 7, 7, 7, 7, 7,
240 7, 7, 7, 7, 7, 7, 7, 7,
241 7, 7, 7, 7, 7, 7, 7, 7,
242 7, 7, 7, 7, 7, 7, 7, 7,
243 7, 7, 7, 7, 7, 7, 7, 7,
244 7, 7, 7, 7, 7, 7, 7, 7,
245 8, 8, 8, 8, 8, 8, 8, 8,
246 8, 8, 8, 8, 8, 8, 8, 8,
247 8, 8, 8, 8, 8, 8, 8, 8,
248 8, 8, 8, 8, 8, 8, 8, 8,
249 8, 8, 8, 8, 8, 8, 8, 8,
250 8, 8, 8, 8, 8, 8, 8, 8,
251 8, 8, 8, 8, 8, 8, 8, 8,
252 8, 8, 8, 8, 8, 8, 8, 8,
253 8, 8, 8, 8, 8, 8, 8, 8,
254 8, 8, 8, 8, 8, 8, 8, 8,
255 8, 8, 8, 8, 8, 8, 8, 8,
256 8, 8, 8, 8, 8, 8, 8, 8,
257 8, 8, 8, 8, 8, 8, 8, 8,
258 8, 8, 8, 8, 8, 8, 8, 8,
259 8, 8, 8, 8, 8, 8, 8, 8,
260 8, 8, 8, 8, 8, 8, 8, 8
264 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,
266 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,
268 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,
270 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,
275 0, 1, 5, 6, 14, 15, 27, 28,
276 2, 4, 7, 13, 16, 26, 29, 42,
277 3, 8, 12, 17, 25, 30, 41, 43,
278 9, 11, 18, 24, 31, 40, 44, 53,
279 10, 19, 23, 32, 39, 45, 52, 54,
280 20, 22, 33, 38, 46, 51, 55, 60,
281 21, 34, 37, 47, 50, 56, 59, 61,
282 35, 36, 48, 49, 57, 58, 62, 63
290 uint16_t mcu_width, mcu_height, bytes_per_pixel;
341 16, 11, 10, 16, 24, 40, 51, 61,
342 12, 12, 14, 19, 26, 58, 60, 55,
343 14, 13, 16, 24, 40, 57, 69, 56,
344 14, 17, 22, 29, 51, 87, 80, 62,
345 18, 22, 37, 56, 68, 109, 103, 77,
346 24, 35, 55, 64, 81, 104, 113, 92,
347 49, 64, 78, 87, 103, 121, 120, 101,
348 72, 92, 95, 98, 112, 100, 103, 99
355 17, 18, 24, 47, 99, 99, 99, 99,
356 18, 21, 26, 66, 99, 99, 99, 99,
357 24, 26, 56, 99, 99, 99, 99, 99,
358 47, 66, 99, 99, 99, 99, 99, 99,
359 99, 99, 99, 99, 99, 99, 99, 99,
360 99, 99, 99, 99, 99, 99, 99, 99,
361 99, 99, 99, 99, 99, 99, 99, 99,
362 99, 99, 99, 99, 99, 99, 99, 99
374 if (q < 1) { factor = 1; }
375 if (q > 99) { factor = 99; }
379 q = 200 - factor * 2;
383 for (i = 0; i < 64; i++) {
388 if (lq < 1) { lq = 1; }
389 else if (lq > 255) { lq = 255; }
390 jpeg_encoder_structure->
Lqt [i] = (
uint8_t) lq;
391 jpeg_encoder_structure->
ILqt [i] = 0x8000 / lq;
393 if (cq < 1) { cq = 1; }
394 else if (cq > 255) { cq = 255; }
395 jpeg_encoder_structure->
Cqt [i] = (
uint8_t) cq;
397 jpeg_encoder_structure->
ICqt [i] = 0x8000 / cq;
431 MakeTables(jpeg_encoder_structure, quality_factor);
434 if (add_dri_header) {
435 output_ptr =
jpeg_write_markers(jpeg_encoder_structure, output_ptr, image_format, in->
w, in->
h);
438 for (i = 1; i <= jpeg_encoder_structure->
vertical_mcus; i++) {
439 if (i < jpeg_encoder_structure->vertical_mcus) {
440 jpeg_encoder_structure->
rows = jpeg_encoder_structure->
mcu_height;
446 if (j < jpeg_encoder_structure->horizontal_mcus) {
447 jpeg_encoder_structure->
cols = jpeg_encoder_structure->
mcu_width;
457 output_ptr =
jpeg_encodeMCU(jpeg_encoder_structure, image_format, output_ptr);
462 input_ptr += jpeg_encoder_structure->
offset;
477 output_ptr =
jpeg_huffman(jpeg_encoder_structure, 1, output_ptr);
483 output_ptr =
jpeg_huffman(jpeg_encoder_structure, 1, output_ptr);
488 output_ptr =
jpeg_huffman(jpeg_encoder_structure, 2, output_ptr);
493 output_ptr =
jpeg_huffman(jpeg_encoder_structure, 3, output_ptr);
503 for (i = 63; i >= 0; i--) {
515 int32_t x0, x1, x2, x3, x4, x5, x6, x7, x8;
528 for (i = 8; i > 0; i--) {
529 x8 = data [0] + data [7];
530 x0 = data [0] - data [7];
532 x7 = data [1] + data [6];
533 x1 = data [1] - data [6];
535 x6 = data [2] + data [5];
536 x2 = data [2] - data [5];
538 x5 = data [3] + data [4];
539 x3 = data [3] - data [4];
553 data [7] = (
int16_t)((x0 * c7 - x1 * c5 + x2 *
c3 - x3 *
c1) >>
s2);
554 data [5] = (
int16_t)((x0 * c5 - x1 *
c1 + x2 * c7 + x3 *
c3) >>
s2);
555 data [3] = (
int16_t)((x0 *
c3 - x1 * c7 - x2 *
c1 - x3 * c5) >>
s2);
556 data [1] = (
int16_t)((x0 *
c1 + x1 *
c3 + x2 * c5 + x3 * c7) >>
s2);
563 for (i = 8; i > 0; i--) {
564 x8 = data [0] + data [56];
565 x0 = data [0] - data [56];
567 x7 = data [8] + data [48];
568 x1 = data [8] - data [48];
570 x6 = data [16] + data [40];
571 x2 = data [16] - data [40];
573 x5 = data [24] + data [32];
574 x3 = data [24] - data [32];
588 data [56] = (
int16_t)((x0 * c7 - x1 * c5 + x2 *
c3 - x3 *
c1) >>
s3);
589 data [40] = (
int16_t)((x0 * c5 - x1 *
c1 + x2 * c7 + x3 *
c3) >>
s3);
590 data [24] = (
int16_t)((x0 *
c3 - x1 * c7 - x2 *
c1 - x3 * c5) >>
s3);
591 data [8] = (
int16_t)((x0 *
c1 + x1 *
c3 + x2 * c5 + x3 * c7) >>
s3);
599 bits_in_next_word = (int16_t) (jpeg_encoder_structure->bitindex + numbits - 32); \
600 if (bits_in_next_word < 0) \
602 jpeg_encoder_structure->lcode = (jpeg_encoder_structure->lcode << numbits) | data; \
603 jpeg_encoder_structure->bitindex += numbits; \
607 jpeg_encoder_structure->lcode = (jpeg_encoder_structure->lcode << (32 - jpeg_encoder_structure->bitindex)) | (data >> bits_in_next_word); \
608 if ((*output_ptr++ = (uint8_t)(jpeg_encoder_structure->lcode >> 24)) == 0xff) \
610 if ((*output_ptr++ = (uint8_t)(jpeg_encoder_structure->lcode >> 16)) == 0xff) \
612 if ((*output_ptr++ = (uint8_t)(jpeg_encoder_structure->lcode >> 8)) == 0xff) \
614 if ((*output_ptr++ = (uint8_t) jpeg_encoder_structure->lcode) == 0xff) \
616 jpeg_encoder_structure->lcode = data; \
617 jpeg_encoder_structure->bitindex = bits_in_next_word; \
624 const uint16_t *DcCodeTable, *DcSizeTable, *AcCodeTable, *AcSizeTable;
626 int16_t *Temp_Ptr, Coeff, LastDc;
627 uint16_t AbsCoeff, HuffCode, HuffSize, RunLength = 0, DataSize = 0, index;
633 Temp_Ptr = jpeg_encoder_structure->
Temp;
636 if (component == 1) {
642 LastDc = jpeg_encoder_structure->
ldc1;
643 jpeg_encoder_structure->
ldc1 = Coeff;
650 if (component == 2) {
651 LastDc = jpeg_encoder_structure->
ldc2;
652 jpeg_encoder_structure->
ldc2 = Coeff;
654 LastDc = jpeg_encoder_structure->
ldc3;
655 jpeg_encoder_structure->
ldc3 = Coeff;
661 AbsCoeff = (Coeff < 0) ? -Coeff-- : Coeff;
663 while (AbsCoeff != 0) {
668 HuffCode = DcCodeTable [DataSize];
669 HuffSize = DcSizeTable [DataSize];
671 Coeff &= (1 << DataSize) - 1;
672 data = (HuffCode << DataSize) | Coeff;
673 numbits = HuffSize + DataSize;
677 for (i = 63; i > 0; i--) {
678 if ((Coeff = *Temp_Ptr++) != 0) {
679 while (RunLength > 15) {
681 data = AcCodeTable [161];
682 numbits = AcSizeTable [161];
686 AbsCoeff = (Coeff < 0) ? -Coeff-- : Coeff;
688 if (AbsCoeff >> 8 == 0) {
691 DataSize =
bitsize [AbsCoeff >> 8] + 8;
694 index = RunLength * 10 + DataSize;
695 HuffCode = AcCodeTable [index];
696 HuffSize = AcSizeTable [index];
698 Coeff &= (1 << DataSize) - 1;
699 data = (HuffCode << DataSize) | Coeff;
700 numbits = HuffSize + DataSize;
709 if (RunLength != 0) {
710 data = AcCodeTable [0];
711 numbits = AcSizeTable [0];
723 if (jpeg_encoder_structure->
bitindex > 0) {
724 jpeg_encoder_structure->
lcode <<= (32 - jpeg_encoder_structure->
bitindex);
728 count = (jpeg_encoder_structure->
bitindex + 7) >> 3;
732 for (i = 0; i < count; i++)
733 if ((*output_ptr++ = *ptr--) == 0xff) {
739 *output_ptr++ = 0xFF;
740 *output_ptr++ = 0xD9;
750 *output_ptr++ = 0xFF;
751 *output_ptr++ = 0xD8;
754 *output_ptr++ = 0xFF;
755 *output_ptr++ = 0xDB;
758 *output_ptr++ = 0x00;
759 *output_ptr++ = 0x43;
762 *output_ptr++ = 0x00;
765 for (i = 0; i < 64; i++) {
766 *output_ptr++ = jpeg_encoder_structure->
Lqt [i];
770 *output_ptr++ = 0xFF;
771 *output_ptr++ = 0xDB;
774 *output_ptr++ = 0x00;
775 *output_ptr++ = 0x43;
778 *output_ptr++ = 0x01;
781 for (i = 0; i < 64; i++) {
782 *output_ptr++ = jpeg_encoder_structure->
Cqt [i];
786 number_of_components = 1;
788 number_of_components = 3;
794 *output_ptr++ = 0xFF;
795 *output_ptr++ = 0xC0;
797 header_length = (
uint16_t)(8 + 3 * number_of_components);
800 *output_ptr++ = (
uint8_t)(header_length >> 8);
801 *output_ptr++ = (
uint8_t) header_length;
804 *output_ptr++ = 0x08;
807 *output_ptr++ = (
uint8_t)(image_height >> 8);
808 *output_ptr++ = (
uint8_t) image_height;
811 *output_ptr++ = (
uint8_t)(image_width >> 8);
812 *output_ptr++ = (
uint8_t) image_width;
815 *output_ptr++ = number_of_components;
818 *output_ptr++ = 0x01;
819 *output_ptr++ = 0x11;
820 *output_ptr++ = 0x00;
822 *output_ptr++ = 0x01;
825 *output_ptr++ = 0x21;
827 *output_ptr++ = 0x11;
830 *output_ptr++ = 0x00;
832 *output_ptr++ = 0x02;
833 *output_ptr++ = 0x11;
834 *output_ptr++ = 0x01;
836 *output_ptr++ = 0x03;
837 *output_ptr++ = 0x11;
838 *output_ptr++ = 0x01;
851 *output_ptr++ = 0xFF;
852 *output_ptr++ = 0xDA;
854 header_length = (
uint16_t)(6 + (number_of_components << 1));
857 *output_ptr++ = (
uint8_t)(header_length >> 8);
858 *output_ptr++ = (
uint8_t) header_length;
861 *output_ptr++ = number_of_components;
864 *output_ptr++ = 0x01;
865 *output_ptr++ = 0x00;
867 *output_ptr++ = 0x01;
868 *output_ptr++ = 0x00;
870 *output_ptr++ = 0x02;
871 *output_ptr++ = 0x11;
873 *output_ptr++ = 0x03;
874 *output_ptr++ = 0x11;
877 *output_ptr++ = 0x00;
878 *output_ptr++ = 0x3F;
879 *output_ptr++ = 0x00;
937 for (i = 63; i >= 0; i--) {
938 value = data [i] * quant_table_ptr [i];
939 value = (value + 0x4000) >> 15;
948 int16_t *Y1_Ptr = jpeg_encoder_structure->
Y1;
954 for (i = rows; i > 0; i--) {
955 for (j = cols; j > 0; j--) {
956 *Y1_Ptr++ = *input_ptr++;
959 for (j = 8 - cols; j > 0; j--) {
960 *Y1_Ptr = *(Y1_Ptr - 1);
967 for (i = 8 - rows; i > 0; i--) {
968 for (j = 8; j > 0; j--) {
969 *Y1_Ptr = *(Y1_Ptr - 8);
980 int16_t *Y1_Ptr = jpeg_encoder_structure->
Y1;
981 int16_t *Y2_Ptr = jpeg_encoder_structure->
Y2;
982 int16_t *CB_Ptr = jpeg_encoder_structure->
CB;
983 int16_t *CR_Ptr = jpeg_encoder_structure->
CR;
997 for (i = rows; i > 0; i--) {
998 for (j = Y1_cols >> 1; j > 0; j--) {
999 *CB_Ptr++ = *input_ptr++;
1000 *Y1_Ptr++ = *input_ptr++;
1001 *CR_Ptr++ = *input_ptr++;
1002 *Y1_Ptr++ = *input_ptr++;
1005 for (j = Y2_cols >> 1; j > 0; j--) {
1006 *CB_Ptr++ = *input_ptr++;
1007 *Y2_Ptr++ = *input_ptr++;
1008 *CR_Ptr++ = *input_ptr++;
1009 *Y2_Ptr++ = *input_ptr++;
1013 for (j = 8 - Y1_cols; j > 0; j--) {
1014 *Y1_Ptr = *(Y1_Ptr - 1);
1018 for (j = 8 - Y2_cols; j > 0; j--) {
1019 *Y2_Ptr = *(Y1_Ptr - 1);
1023 for (j = 8 - Y2_cols; j > 0; j--) {
1024 *Y2_Ptr = *(Y2_Ptr - 1);
1029 for (j = (16 - cols) >> 1; j > 0; j--) {
1030 *CB_Ptr = *(CB_Ptr - 1); CB_Ptr++;
1031 *CR_Ptr = *(CR_Ptr - 1); CR_Ptr++;
1037 for (i = 8 - rows; i > 0; i--) {
1038 for (j = 8; j > 0; j--) {
1039 *Y1_Ptr = *(Y1_Ptr - 8); Y1_Ptr++;
1040 *Y2_Ptr = *(Y2_Ptr - 8); Y2_Ptr++;
1041 *CB_Ptr = *(CB_Ptr - 8); CB_Ptr++;
1042 *CR_Ptr = *(CR_Ptr - 8); CR_Ptr++;