blob: e8bdddbf59de57183dade34dbecdb952df0f4e42 [file] [log] [blame]
Ed Tanous93f987d2017-04-17 17:52:36 -07001#pragma once
2
Ed Tanous55c7b7a2018-05-22 15:27:24 -07003#include <aspeed/JTABLES.H>
Ed Tanous1abe55e2018-09-05 08:30:59 -07004
Ed Tanous93f987d2017-04-17 17:52:36 -07005#include <array>
Ed Tanous1abe55e2018-09-05 08:30:59 -07006#include <ast_video_types.hpp>
Ed Tanous1ff48782017-04-18 12:45:08 -07007#include <cassert>
8#include <cstdint>
Ed Tanous911ac312017-08-15 09:37:42 -07009#include <cstring>
Ed Tanousb078cf32017-04-18 14:51:21 -070010#include <iostream>
11#include <vector>
Ed Tanous93f987d2017-04-17 17:52:36 -070012
Ed Tanous1abe55e2018-09-05 08:30:59 -070013namespace ast_video
14{
Ed Tanous93f987d2017-04-17 17:52:36 -070015
Ed Tanous1abe55e2018-09-05 08:30:59 -070016struct ColorCache
17{
18 ColorCache() :
19 color{0x008080, 0xFF8080, 0x808080, 0xC08080}, index{0, 1, 2, 3}
20 {
21 }
Ed Tanousd5f39992017-04-18 13:41:22 -070022
Ed Tanous1abe55e2018-09-05 08:30:59 -070023 unsigned long color[4];
24 unsigned char index[4];
25 unsigned char bitMapBits{};
Ed Tanous93f987d2017-04-17 17:52:36 -070026};
27
Ed Tanous1abe55e2018-09-05 08:30:59 -070028struct RGB
29{
30 unsigned char b;
31 unsigned char g;
32 unsigned char r;
33 unsigned char reserved;
Ed Tanous93f987d2017-04-17 17:52:36 -070034};
35
Ed Tanous1abe55e2018-09-05 08:30:59 -070036enum class JpgBlock
37{
38 JPEG_NO_SKIP_CODE = 0x00,
39 JPEG_SKIP_CODE = 0x08,
Ed Tanous93f987d2017-04-17 17:52:36 -070040
Ed Tanous1abe55e2018-09-05 08:30:59 -070041 JPEG_PASS2_CODE = 0x02,
42 JPEG_SKIP_PASS2_CODE = 0x0A,
Ed Tanous93f987d2017-04-17 17:52:36 -070043
Ed Tanous1abe55e2018-09-05 08:30:59 -070044 LOW_JPEG_NO_SKIP_CODE = 0x04,
45 LOW_JPEG_SKIP_CODE = 0x0C,
Ed Tanous93f987d2017-04-17 17:52:36 -070046
Ed Tanous1abe55e2018-09-05 08:30:59 -070047 VQ_NO_SKIP_1_COLOR_CODE = 0x05,
48 VQ_SKIP_1_COLOR_CODE = 0x0D,
Ed Tanous93f987d2017-04-17 17:52:36 -070049
Ed Tanous1abe55e2018-09-05 08:30:59 -070050 VQ_NO_SKIP_2_COLOR_CODE = 0x06,
51 VQ_SKIP_2_COLOR_CODE = 0x0E,
Ed Tanous93f987d2017-04-17 17:52:36 -070052
Ed Tanous1abe55e2018-09-05 08:30:59 -070053 VQ_NO_SKIP_4_COLOR_CODE = 0x07,
54 VQ_SKIP_4_COLOR_CODE = 0x0F,
Ed Tanous93f987d2017-04-17 17:52:36 -070055
Ed Tanous1abe55e2018-09-05 08:30:59 -070056 FRAME_END_CODE = 0x09,
Ed Tanous93f987d2017-04-17 17:52:36 -070057
58};
59
Ed Tanous1abe55e2018-09-05 08:30:59 -070060class AstJpegDecoder
61{
62 public:
63 AstJpegDecoder()
64 {
65 // TODO(ed) figure out how to init this in the constructor
66 yuvBuffer.resize(1920 * 1200);
67 outBuffer.resize(1920 * 1200);
68 for (auto &r : outBuffer)
69 {
70 r.r = 0x00;
71 r.g = 0x00;
72 r.b = 0x00;
73 r.reserved = 0xAA;
74 }
75
76 int qfactor = 16;
77
78 scalefactor = qfactor;
79 scalefactoruv = qfactor;
80 advancescalefactor = 16;
81 advancescalefactoruv = 16;
82 initJpgTable();
Ed Tanous93f987d2017-04-17 17:52:36 -070083 }
Ed Tanousd5f39992017-04-18 13:41:22 -070084
Ed Tanous1abe55e2018-09-05 08:30:59 -070085 void loadQuantTable(std::array<long, 64> &quant_table)
86 {
87 float scalefactorF[8] = {1.0f, 1.387039845f, 1.306562965f,
88 1.175875602f, 1.0f, 0.785694958f,
89 0.541196100f, 0.275899379f};
90 uint8_t j, row, col;
91 std::array<uint8_t, 64> tempQT{};
Ed Tanousd5f39992017-04-18 13:41:22 -070092
Ed Tanous1abe55e2018-09-05 08:30:59 -070093 // Load quantization coefficients from JPG file, scale them for DCT and
94 // reorder
95 // from zig-zag order
96 switch (ySelector)
97 {
98 case 0:
99 stdLuminanceQt = tbl000Y;
100 break;
101 case 1:
102 stdLuminanceQt = tbl014Y;
103 break;
104 case 2:
105 stdLuminanceQt = tbl029Y;
106 break;
107 case 3:
108 stdLuminanceQt = tbl043Y;
109 break;
110 case 4:
111 stdLuminanceQt = tbl057Y;
112 break;
113 case 5:
114 stdLuminanceQt = tbl071Y;
115 break;
116 case 6:
117 stdLuminanceQt = tbl086Y;
118 break;
119 case 7:
120 stdLuminanceQt = tbl100Y;
121 break;
122 }
123 setQuantTable(stdLuminanceQt, static_cast<uint8_t>(scalefactor),
124 tempQT);
Ed Tanous93f987d2017-04-17 17:52:36 -0700125
Ed Tanous1abe55e2018-09-05 08:30:59 -0700126 for (j = 0; j <= 63; j++)
127 {
128 quant_table[j] = tempQT[zigzag[j]];
129 }
130 j = 0;
131 for (row = 0; row <= 7; row++)
132 {
133 for (col = 0; col <= 7; col++)
134 {
135 quant_table[j] = static_cast<long>(
136 (quant_table[j] * scalefactorF[row] * scalefactorF[col]) *
137 65536);
138 j++;
139 }
140 }
141 bytePos += 64;
Ed Tanous93f987d2017-04-17 17:52:36 -0700142 }
Ed Tanous93f987d2017-04-17 17:52:36 -0700143
Ed Tanous1abe55e2018-09-05 08:30:59 -0700144 void loadQuantTableCb(std::array<long, 64> &quant_table)
145 {
146 float scalefactor[8] = {1.0f, 1.387039845f, 1.306562965f, 1.175875602f,
147 1.0f, 0.785694958f, 0.541196100f, 0.275899379f};
148 uint8_t j, row, col;
149 std::array<uint8_t, 64> tempQT{};
Ed Tanous93f987d2017-04-17 17:52:36 -0700150
Ed Tanous1abe55e2018-09-05 08:30:59 -0700151 // Load quantization coefficients from JPG file, scale them for DCT and
152 // reorder from zig-zag order
153 if (mapping == 0)
154 {
155 switch (uvSelector)
156 {
157 case 0:
158 stdChrominanceQt = tbl000Y;
159 break;
160 case 1:
161 stdChrominanceQt = tbl014Y;
162 break;
163 case 2:
164 stdChrominanceQt = tbl029Y;
165 break;
166 case 3:
167 stdChrominanceQt = tbl043Y;
168 break;
169 case 4:
170 stdChrominanceQt = tbl057Y;
171 break;
172 case 5:
173 stdChrominanceQt = tbl071Y;
174 break;
175 case 6:
176 stdChrominanceQt = tbl086Y;
177 break;
178 case 7:
179 stdChrominanceQt = tbl100Y;
180 break;
181 }
182 }
183 else
184 {
185 switch (uvSelector)
186 {
187 case 0:
188 stdChrominanceQt = tbl000Uv;
189 break;
190 case 1:
191 stdChrominanceQt = tbl014Uv;
192 break;
193 case 2:
194 stdChrominanceQt = tbl029Uv;
195 break;
196 case 3:
197 stdChrominanceQt = tbl043Uv;
198 break;
199 case 4:
200 stdChrominanceQt = tbl057Uv;
201 break;
202 case 5:
203 stdChrominanceQt = tbl071Uv;
204 break;
205 case 6:
206 stdChrominanceQt = tbl086Uv;
207 break;
208 case 7:
209 stdChrominanceQt = tbl100Uv;
210 break;
211 }
212 }
213 setQuantTable(stdChrominanceQt, static_cast<uint8_t>(scalefactoruv),
214 tempQT);
Ed Tanous93f987d2017-04-17 17:52:36 -0700215
Ed Tanous1abe55e2018-09-05 08:30:59 -0700216 for (j = 0; j <= 63; j++)
217 {
218 quant_table[j] = tempQT[zigzag[j]];
219 }
220 j = 0;
221 for (row = 0; row <= 7; row++)
222 {
223 for (col = 0; col <= 7; col++)
224 {
225 quant_table[j] = static_cast<long>(
226 (quant_table[j] * scalefactor[row] * scalefactor[col]) *
227 65536);
228 j++;
229 }
230 }
231 bytePos += 64;
Ed Tanous93f987d2017-04-17 17:52:36 -0700232 }
Ed Tanous1abe55e2018-09-05 08:30:59 -0700233 // Note: Added for Dual_JPEG
234 void loadAdvanceQuantTable(std::array<long, 64> &quant_table)
235 {
236 float scalefactor[8] = {1.0f, 1.387039845f, 1.306562965f, 1.175875602f,
237 1.0f, 0.785694958f, 0.541196100f, 0.275899379f};
238 uint8_t j, row, col;
239 std::array<uint8_t, 64> tempQT{};
Ed Tanous93f987d2017-04-17 17:52:36 -0700240
Ed Tanous1abe55e2018-09-05 08:30:59 -0700241 // Load quantization coefficients from JPG file, scale them for DCT and
242 // reorder
243 // from zig-zag order
244 switch (advanceSelector)
245 {
246 case 0:
247 stdLuminanceQt = tbl000Y;
248 break;
249 case 1:
250 stdLuminanceQt = tbl014Y;
251 break;
252 case 2:
253 stdLuminanceQt = tbl029Y;
254 break;
255 case 3:
256 stdLuminanceQt = tbl043Y;
257 break;
258 case 4:
259 stdLuminanceQt = tbl057Y;
260 break;
261 case 5:
262 stdLuminanceQt = tbl071Y;
263 break;
264 case 6:
265 stdLuminanceQt = tbl086Y;
266 break;
267 case 7:
268 stdLuminanceQt = tbl100Y;
269 break;
270 }
271 // Note: pass ADVANCE SCALE FACTOR to sub-function in Dual-JPEG
272 setQuantTable(stdLuminanceQt, static_cast<uint8_t>(advancescalefactor),
273 tempQT);
Ed Tanous93f987d2017-04-17 17:52:36 -0700274
Ed Tanous1abe55e2018-09-05 08:30:59 -0700275 for (j = 0; j <= 63; j++)
276 {
277 quant_table[j] = tempQT[zigzag[j]];
278 }
279 j = 0;
280 for (row = 0; row <= 7; row++)
281 {
282 for (col = 0; col <= 7; col++)
283 {
284 quant_table[j] = static_cast<long>(
285 (quant_table[j] * scalefactor[row] * scalefactor[col]) *
286 65536);
287 j++;
288 }
289 }
290 bytePos += 64;
Ed Tanous93f987d2017-04-17 17:52:36 -0700291 }
Ed Tanous93f987d2017-04-17 17:52:36 -0700292
Ed Tanous1abe55e2018-09-05 08:30:59 -0700293 // Note: Added for Dual-JPEG
294 void loadAdvanceQuantTableCb(std::array<long, 64> &quant_table)
295 {
296 float scalefactor[8] = {1.0f, 1.387039845f, 1.306562965f, 1.175875602f,
297 1.0f, 0.785694958f, 0.541196100f, 0.275899379f};
298 uint8_t j, row, col;
299 std::array<uint8_t, 64> tempQT{};
Ed Tanous93f987d2017-04-17 17:52:36 -0700300
Ed Tanous1abe55e2018-09-05 08:30:59 -0700301 // Load quantization coefficients from JPG file, scale them for DCT and
302 // reorder
303 // from zig-zag order
304 if (mapping == 1)
305 {
306 switch (advanceSelector)
307 {
308 case 0:
309 stdChrominanceQt = tbl000Y;
310 break;
311 case 1:
312 stdChrominanceQt = tbl014Y;
313 break;
314 case 2:
315 stdChrominanceQt = tbl029Y;
316 break;
317 case 3:
318 stdChrominanceQt = tbl043Y;
319 break;
320 case 4:
321 stdChrominanceQt = tbl057Y;
322 break;
323 case 5:
324 stdChrominanceQt = tbl071Y;
325 break;
326 case 6:
327 stdChrominanceQt = tbl086Y;
328 break;
329 case 7:
330 stdChrominanceQt = tbl100Y;
331 break;
332 }
333 }
334 else
335 {
336 switch (advanceSelector)
337 {
338 case 0:
339 stdChrominanceQt = tbl000Uv;
340 break;
341 case 1:
342 stdChrominanceQt = tbl014Uv;
343 break;
344 case 2:
345 stdChrominanceQt = tbl029Uv;
346 break;
347 case 3:
348 stdChrominanceQt = tbl043Uv;
349 break;
350 case 4:
351 stdChrominanceQt = tbl057Uv;
352 break;
353 case 5:
354 stdChrominanceQt = tbl071Uv;
355 break;
356 case 6:
357 stdChrominanceQt = tbl086Uv;
358 break;
359 case 7:
360 stdChrominanceQt = tbl100Uv;
361 break;
362 }
363 }
364 // Note: pass ADVANCE SCALE FACTOR to sub-function in Dual-JPEG
365 setQuantTable(stdChrominanceQt,
366 static_cast<uint8_t>(advancescalefactoruv), tempQT);
Ed Tanous93f987d2017-04-17 17:52:36 -0700367
Ed Tanous1abe55e2018-09-05 08:30:59 -0700368 for (j = 0; j <= 63; j++)
369 {
370 quant_table[j] = tempQT[zigzag[j]];
371 }
372 j = 0;
373 for (row = 0; row <= 7; row++)
374 {
375 for (col = 0; col <= 7; col++)
376 {
377 quant_table[j] = static_cast<long>(
378 (quant_table[j] * scalefactor[row] * scalefactor[col]) *
379 65536);
380 j++;
381 }
382 }
383 bytePos += 64;
Ed Tanous93f987d2017-04-17 17:52:36 -0700384 }
Ed Tanous93f987d2017-04-17 17:52:36 -0700385
Ed Tanous1abe55e2018-09-05 08:30:59 -0700386 void idctTransform(short *coef, uint8_t *data, uint8_t nBlock)
387 {
Ed Tanous93f987d2017-04-17 17:52:36 -0700388#define FIX_1_082392200 ((int)277) /* FIX(1.082392200) */
389#define FIX_1_414213562 ((int)362) /* FIX(1.414213562) */
390#define FIX_1_847759065 ((int)473) /* FIX(1.847759065) */
391#define FIX_2_613125930 ((int)669) /* FIX(2.613125930) */
392
393#define MULTIPLY(var, cons) ((int)((var) * (cons)) >> 8)
394
Ed Tanous1abe55e2018-09-05 08:30:59 -0700395 int tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
396 int tmp10, tmp11, tmp12, tmp13;
397 int z5, z10, z11, z12, z13;
398 int workspace[64]; /* buffers data between passes */
Ed Tanous93f987d2017-04-17 17:52:36 -0700399
Ed Tanous1abe55e2018-09-05 08:30:59 -0700400 short *inptr = coef;
401 long *quantptr;
402 int *wsptr = workspace;
403 unsigned char *outptr;
404 unsigned char *rLimit = rlimitTable + 128;
405 int ctr, dcval, dctsize = 8;
Ed Tanous93f987d2017-04-17 17:52:36 -0700406
Ed Tanous1abe55e2018-09-05 08:30:59 -0700407 quantptr = &qt[nBlock][0];
Ed Tanous93f987d2017-04-17 17:52:36 -0700408
Ed Tanous1abe55e2018-09-05 08:30:59 -0700409 // Pass 1: process columns from input (inptr), store into work
410 // array(wsptr)
Ed Tanous93f987d2017-04-17 17:52:36 -0700411
Ed Tanous1abe55e2018-09-05 08:30:59 -0700412 for (ctr = 8; ctr > 0; ctr--)
413 {
414 /* Due to quantization, we will usually find that many of the input
415 * coefficients are zero, especially the AC terms. We can exploit
416 * this by short-circuiting the IDCT calculation for any column in
417 * which all the AC terms are zero. In that case each output is
418 * equal to the DC coefficient (with scale factor as needed). With
419 * typical images and quantization tables, half or more of the
420 * column DCT calculations can be simplified this way.
421 */
Ed Tanous93f987d2017-04-17 17:52:36 -0700422
Ed Tanous1abe55e2018-09-05 08:30:59 -0700423 if ((inptr[dctsize * 1] | inptr[dctsize * 2] | inptr[dctsize * 3] |
424 inptr[dctsize * 4] | inptr[dctsize * 5] | inptr[dctsize * 6] |
425 inptr[dctsize * 7]) == 0)
426 {
427 /* AC terms all zero */
428 dcval = static_cast<int>(
429 (inptr[dctsize * 0] * quantptr[dctsize * 0]) >> 16);
Ed Tanous93f987d2017-04-17 17:52:36 -0700430
Ed Tanous1abe55e2018-09-05 08:30:59 -0700431 wsptr[dctsize * 0] = dcval;
432 wsptr[dctsize * 1] = dcval;
433 wsptr[dctsize * 2] = dcval;
434 wsptr[dctsize * 3] = dcval;
435 wsptr[dctsize * 4] = dcval;
436 wsptr[dctsize * 5] = dcval;
437 wsptr[dctsize * 6] = dcval;
438 wsptr[dctsize * 7] = dcval;
Ed Tanous93f987d2017-04-17 17:52:36 -0700439
Ed Tanous1abe55e2018-09-05 08:30:59 -0700440 inptr++; /* advance pointers to next column */
441 quantptr++;
442 wsptr++;
443 continue;
444 }
Ed Tanous93f987d2017-04-17 17:52:36 -0700445
Ed Tanous1abe55e2018-09-05 08:30:59 -0700446 /* Even part */
Ed Tanous93f987d2017-04-17 17:52:36 -0700447
Ed Tanous1abe55e2018-09-05 08:30:59 -0700448 tmp0 = (inptr[dctsize * 0] * quantptr[dctsize * 0]) >> 16;
449 tmp1 = (inptr[dctsize * 2] * quantptr[dctsize * 2]) >> 16;
450 tmp2 = (inptr[dctsize * 4] * quantptr[dctsize * 4]) >> 16;
451 tmp3 = (inptr[dctsize * 6] * quantptr[dctsize * 6]) >> 16;
Ed Tanous93f987d2017-04-17 17:52:36 -0700452
Ed Tanous1abe55e2018-09-05 08:30:59 -0700453 tmp10 = tmp0 + tmp2; /* phase 3 */
454 tmp11 = tmp0 - tmp2;
Ed Tanous93f987d2017-04-17 17:52:36 -0700455
Ed Tanous1abe55e2018-09-05 08:30:59 -0700456 tmp13 = tmp1 + tmp3; /* phases 5-3 */
457 tmp12 = MULTIPLY(tmp1 - tmp3, FIX_1_414213562) - tmp13; /* 2*c4 */
Ed Tanous93f987d2017-04-17 17:52:36 -0700458
Ed Tanous1abe55e2018-09-05 08:30:59 -0700459 tmp0 = tmp10 + tmp13; /* phase 2 */
460 tmp3 = tmp10 - tmp13;
461 tmp1 = tmp11 + tmp12;
462 tmp2 = tmp11 - tmp12;
Ed Tanous93f987d2017-04-17 17:52:36 -0700463
Ed Tanous1abe55e2018-09-05 08:30:59 -0700464 /* Odd part */
Ed Tanous93f987d2017-04-17 17:52:36 -0700465
Ed Tanous1abe55e2018-09-05 08:30:59 -0700466 tmp4 = (inptr[dctsize * 1] * quantptr[dctsize * 1]) >> 16;
467 tmp5 = (inptr[dctsize * 3] * quantptr[dctsize * 3]) >> 16;
468 tmp6 = (inptr[dctsize * 5] * quantptr[dctsize * 5]) >> 16;
469 tmp7 = (inptr[dctsize * 7] * quantptr[dctsize * 7]) >> 16;
Ed Tanous93f987d2017-04-17 17:52:36 -0700470
Ed Tanous1abe55e2018-09-05 08:30:59 -0700471 z13 = tmp6 + tmp5; /* phase 6 */
472 z10 = tmp6 - tmp5;
473 z11 = tmp4 + tmp7;
474 z12 = tmp4 - tmp7;
Ed Tanous93f987d2017-04-17 17:52:36 -0700475
Ed Tanous1abe55e2018-09-05 08:30:59 -0700476 tmp7 = z11 + z13; /* phase 5 */
477 tmp11 = MULTIPLY(z11 - z13, FIX_1_414213562); /* 2*c4 */
Ed Tanous93f987d2017-04-17 17:52:36 -0700478
Ed Tanous1abe55e2018-09-05 08:30:59 -0700479 z5 = MULTIPLY(z10 + z12, FIX_1_847759065); /* 2*c2 */
480 tmp10 = MULTIPLY(z12, FIX_1_082392200) - z5; /* 2*(c2-c6) */
481 tmp12 = MULTIPLY(z10, -FIX_2_613125930) + z5; /* -2*(c2+c6) */
Ed Tanous93f987d2017-04-17 17:52:36 -0700482
Ed Tanous1abe55e2018-09-05 08:30:59 -0700483 tmp6 = tmp12 - tmp7; /* phase 2 */
484 tmp5 = tmp11 - tmp6;
485 tmp4 = tmp10 + tmp5;
Ed Tanous93f987d2017-04-17 17:52:36 -0700486
Ed Tanous1abe55e2018-09-05 08:30:59 -0700487 wsptr[dctsize * 0] = (tmp0 + tmp7);
488 wsptr[dctsize * 7] = (tmp0 - tmp7);
489 wsptr[dctsize * 1] = (tmp1 + tmp6);
490 wsptr[dctsize * 6] = (tmp1 - tmp6);
491 wsptr[dctsize * 2] = (tmp2 + tmp5);
492 wsptr[dctsize * 5] = (tmp2 - tmp5);
493 wsptr[dctsize * 4] = (tmp3 + tmp4);
494 wsptr[dctsize * 3] = (tmp3 - tmp4);
Ed Tanous93f987d2017-04-17 17:52:36 -0700495
Ed Tanous1abe55e2018-09-05 08:30:59 -0700496 inptr++; /* advance pointers to next column */
497 quantptr++;
498 wsptr++;
499 }
Ed Tanous93f987d2017-04-17 17:52:36 -0700500
501/* Pass 2: process rows from work array, store into output array. */
502/* Note that we must descale the results by a factor of 8 == 2**3, */
503/* and also undo the PASS1_BITS scaling. */
504
505//#define RANGE_MASK 1023; //2 bits wider than legal samples
506#define PASS1_BITS 0
Ed Tanous911ac312017-08-15 09:37:42 -0700507#define IDESCALE(x, n) ((int)((x) >> (n)))
Ed Tanous93f987d2017-04-17 17:52:36 -0700508
Ed Tanous1abe55e2018-09-05 08:30:59 -0700509 wsptr = workspace;
510 for (ctr = 0; ctr < dctsize; ctr++)
511 {
512 outptr = data + ctr * 8;
Ed Tanous93f987d2017-04-17 17:52:36 -0700513
Ed Tanous1abe55e2018-09-05 08:30:59 -0700514 /* Rows of zeroes can be exploited in the same way as we did with
515 * columns. However, the column calculation has created many nonzero
516 * AC terms, so the simplification applies less often (typically 5%
517 * to 10% of the time). On machines with very fast multiplication,
518 * it's possible that the test takes more time than it's worth. In
519 * that case this section may be commented out.
520 */
521 /* Even part */
Ed Tanous93f987d2017-04-17 17:52:36 -0700522
Ed Tanous1abe55e2018-09-05 08:30:59 -0700523 tmp10 = (wsptr[0] + wsptr[4]);
524 tmp11 = (wsptr[0] - wsptr[4]);
Ed Tanous93f987d2017-04-17 17:52:36 -0700525
Ed Tanous1abe55e2018-09-05 08:30:59 -0700526 tmp13 = (wsptr[2] + wsptr[6]);
527 tmp12 = MULTIPLY((int)wsptr[2] - (int)wsptr[6], FIX_1_414213562) -
528 tmp13;
Ed Tanous93f987d2017-04-17 17:52:36 -0700529
Ed Tanous1abe55e2018-09-05 08:30:59 -0700530 tmp0 = tmp10 + tmp13;
531 tmp3 = tmp10 - tmp13;
532 tmp1 = tmp11 + tmp12;
533 tmp2 = tmp11 - tmp12;
Ed Tanous93f987d2017-04-17 17:52:36 -0700534
Ed Tanous1abe55e2018-09-05 08:30:59 -0700535 /* Odd part */
Ed Tanous93f987d2017-04-17 17:52:36 -0700536
Ed Tanous1abe55e2018-09-05 08:30:59 -0700537 z13 = wsptr[5] + wsptr[3];
538 z10 = wsptr[5] - wsptr[3];
539 z11 = wsptr[1] + wsptr[7];
540 z12 = wsptr[1] - wsptr[7];
Ed Tanous93f987d2017-04-17 17:52:36 -0700541
Ed Tanous1abe55e2018-09-05 08:30:59 -0700542 tmp7 = z11 + z13; /* phase 5 */
543 tmp11 = MULTIPLY(z11 - z13, FIX_1_414213562); /* 2*c4 */
Ed Tanous93f987d2017-04-17 17:52:36 -0700544
Ed Tanous1abe55e2018-09-05 08:30:59 -0700545 z5 = MULTIPLY(z10 + z12, FIX_1_847759065); /* 2*c2 */
546 tmp10 = MULTIPLY(z12, FIX_1_082392200) - z5; /* 2*(c2-c6) */
547 tmp12 = MULTIPLY(z10, -FIX_2_613125930) + z5; /* -2*(c2+c6) */
Ed Tanous93f987d2017-04-17 17:52:36 -0700548
Ed Tanous1abe55e2018-09-05 08:30:59 -0700549 tmp6 = tmp12 - tmp7; /* phase 2 */
550 tmp5 = tmp11 - tmp6;
551 tmp4 = tmp10 + tmp5;
Ed Tanous93f987d2017-04-17 17:52:36 -0700552
Ed Tanous1abe55e2018-09-05 08:30:59 -0700553 /* Final output stage: scale down by a factor of 8 and range-limit
554 */
Ed Tanous93f987d2017-04-17 17:52:36 -0700555
Ed Tanous1abe55e2018-09-05 08:30:59 -0700556 outptr[0] =
557 rLimit[IDESCALE((tmp0 + tmp7), (PASS1_BITS + 3)) & 1023L];
558 outptr[7] =
559 rLimit[IDESCALE((tmp0 - tmp7), (PASS1_BITS + 3)) & 1023L];
560 outptr[1] =
561 rLimit[IDESCALE((tmp1 + tmp6), (PASS1_BITS + 3)) & 1023L];
562 outptr[6] =
563 rLimit[IDESCALE((tmp1 - tmp6), (PASS1_BITS + 3)) & 1023L];
564 outptr[2] =
565 rLimit[IDESCALE((tmp2 + tmp5), (PASS1_BITS + 3)) & 1023L];
566 outptr[5] =
567 rLimit[IDESCALE((tmp2 - tmp5), (PASS1_BITS + 3)) & 1023L];
568 outptr[4] =
569 rLimit[IDESCALE((tmp3 + tmp4), (PASS1_BITS + 3)) & 1023L];
570 outptr[3] =
571 rLimit[IDESCALE((tmp3 - tmp4), (PASS1_BITS + 3)) & 1023L];
Ed Tanous93f987d2017-04-17 17:52:36 -0700572
Ed Tanous1abe55e2018-09-05 08:30:59 -0700573 wsptr += dctsize; /* advance pointer to next row */
574 }
Ed Tanous93f987d2017-04-17 17:52:36 -0700575 }
Ed Tanous1abe55e2018-09-05 08:30:59 -0700576 void yuvToRgb(
577 int txb, int tyb,
578 unsigned char
579 *pYCbCr, // in, Y: 256 or 64 bytes; Cb: 64 bytes; Cr: 64 bytes
580 struct RGB *pYUV, // in, Y: 256 or 64 bytes; Cb: 64 bytes; Cr: 64 bytes
581 unsigned char
582 *pBgr // out, BGR format, 16*16*3 = 768 bytes; or 8*8*3=192 bytes
583 )
584 {
585 int i, j, pos, m, n;
586 unsigned char cb, cr, *py, *pcb, *pcr, *py420[4];
587 int y;
588 struct RGB *pByte;
589 int nBlocksInMcu = 6;
590 unsigned int pixelX, pixelY;
Ed Tanous93f987d2017-04-17 17:52:36 -0700591
Ed Tanous1abe55e2018-09-05 08:30:59 -0700592 pByte = reinterpret_cast<struct RGB *>(pBgr);
593 if (yuvmode == YuvMode::YUV444)
594 {
595 py = pYCbCr;
596 pcb = pYCbCr + 64;
597 pcr = pcb + 64;
Ed Tanous93f987d2017-04-17 17:52:36 -0700598
Ed Tanous1abe55e2018-09-05 08:30:59 -0700599 pixelX = txb * 8;
600 pixelY = tyb * 8;
601 pos = (pixelY * width) + pixelX;
Ed Tanous93f987d2017-04-17 17:52:36 -0700602
Ed Tanous1abe55e2018-09-05 08:30:59 -0700603 for (j = 0; j < 8; j++)
604 {
605 for (i = 0; i < 8; i++)
606 {
607 m = ((j << 3) + i);
608 y = py[m];
609 cb = pcb[m];
610 cr = pcr[m];
611 n = pos + i;
612 // For 2Pass. Save the YUV value
613 pYUV[n].b = cb;
614 pYUV[n].g = y;
615 pYUV[n].r = cr;
616 pByte[n].b = rlimitTable[mY[y] + mCbToB[cb]];
617 pByte[n].g = rlimitTable[mY[y] + mCbToG[cb] + mCrToG[cr]];
618 pByte[n].r = rlimitTable[mY[y] + mCrToR[cr]];
619 }
620 pos += width;
621 }
Ed Tanous93f987d2017-04-17 17:52:36 -0700622 }
Ed Tanous1abe55e2018-09-05 08:30:59 -0700623 else
624 {
625 for (i = 0; i < nBlocksInMcu - 2; i++)
626 {
627 py420[i] = pYCbCr + i * 64;
628 }
629 pcb = pYCbCr + (nBlocksInMcu - 2) * 64;
630 pcr = pcb + 64;
Ed Tanous93f987d2017-04-17 17:52:36 -0700631
Ed Tanous1abe55e2018-09-05 08:30:59 -0700632 pixelX = txb * 16;
633 pixelY = tyb * 16;
634 pos = (pixelY * width) + pixelX;
Ed Tanous93f987d2017-04-17 17:52:36 -0700635
Ed Tanous1abe55e2018-09-05 08:30:59 -0700636 for (j = 0; j < 16; j++)
637 {
638 for (i = 0; i < 16; i++)
639 {
640 // block number is ((j/8) * 2 + i/8)={0, 1, 2, 3}
641 y = *(py420[(j >> 3) * 2 + (i >> 3)]++);
642 m = ((j >> 1) << 3) + (i >> 1);
643 cb = pcb[m];
644 cr = pcr[m];
645 n = pos + i;
646 pByte[n].b = rlimitTable[mY[y] + mCbToB[cb]];
647 pByte[n].g = rlimitTable[mY[y] + mCbToG[cb] + mCrToG[cr]];
648 pByte[n].r = rlimitTable[mY[y] + mCrToR[cr]];
649 }
650 pos += width;
651 }
Ed Tanous93f987d2017-04-17 17:52:36 -0700652 }
Ed Tanous93f987d2017-04-17 17:52:36 -0700653 }
Ed Tanous1abe55e2018-09-05 08:30:59 -0700654 void yuvToBuffer(
655 int txb, int tyb,
656 unsigned char
657 *pYCbCr, // in, Y: 256 or 64 bytes; Cb: 64 bytes; Cr: 64 bytes
658 struct RGB
659 *pYUV, // out, BGR format, 16*16*3 = 768 bytes; or 8*8*3=192 bytes
660 unsigned char
661 *pBgr // out, BGR format, 16*16*3 = 768 bytes; or 8*8*3=192 bytes
662 )
663 {
664 int i, j, pos, m, n;
665 unsigned char cb, cr, *py, *pcb, *pcr, *py420[4];
666 int y;
667 struct RGB *pByte;
668 int nBlocksInMcu = 6;
669 unsigned int pixelX, pixelY;
Ed Tanous93f987d2017-04-17 17:52:36 -0700670
Ed Tanous1abe55e2018-09-05 08:30:59 -0700671 pByte = reinterpret_cast<struct RGB *>(pBgr);
672 if (yuvmode == YuvMode::YUV444)
673 {
674 py = pYCbCr;
675 pcb = pYCbCr + 64;
676 pcr = pcb + 64;
Ed Tanous93f987d2017-04-17 17:52:36 -0700677
Ed Tanous1abe55e2018-09-05 08:30:59 -0700678 pixelX = txb * 8;
679 pixelY = tyb * 8;
680 pos = (pixelY * width) + pixelX;
Ed Tanous93f987d2017-04-17 17:52:36 -0700681
Ed Tanous1abe55e2018-09-05 08:30:59 -0700682 for (j = 0; j < 8; j++)
683 {
684 for (i = 0; i < 8; i++)
685 {
686 m = ((j << 3) + i);
687 n = pos + i;
688 y = pYUV[n].g + (py[m] - 128);
689 cb = pYUV[n].b + (pcb[m] - 128);
690 cr = pYUV[n].r + (pcr[m] - 128);
691 pYUV[n].b = cb;
692 pYUV[n].g = y;
693 pYUV[n].r = cr;
694 pByte[n].b = rlimitTable[mY[y] + mCbToB[cb]];
695 pByte[n].g = rlimitTable[mY[y] + mCbToG[cb] + mCrToG[cr]];
696 pByte[n].r = rlimitTable[mY[y] + mCrToR[cr]];
697 }
698 pos += width;
699 }
Ed Tanous93f987d2017-04-17 17:52:36 -0700700 }
Ed Tanous1abe55e2018-09-05 08:30:59 -0700701 else
702 {
703 for (i = 0; i < nBlocksInMcu - 2; i++)
704 {
705 py420[i] = pYCbCr + i * 64;
706 }
707 pcb = pYCbCr + (nBlocksInMcu - 2) * 64;
708 pcr = pcb + 64;
Ed Tanous93f987d2017-04-17 17:52:36 -0700709
Ed Tanous1abe55e2018-09-05 08:30:59 -0700710 pixelX = txb * 16;
711 pixelY = tyb * 16;
712 pos = (pixelY * width) + pixelX;
Ed Tanous93f987d2017-04-17 17:52:36 -0700713
Ed Tanous1abe55e2018-09-05 08:30:59 -0700714 for (j = 0; j < 16; j++)
715 {
716 for (i = 0; i < 16; i++)
717 {
718 // block number is ((j/8) * 2 + i/8)={0, 1, 2, 3}
719 y = *(py420[(j >> 3) * 2 + (i >> 3)]++);
720 m = ((j >> 1) << 3) + (i >> 1);
721 cb = pcb[m];
722 cr = pcr[m];
723 n = pos + i;
724 pByte[n].b = rlimitTable[mY[y] + mCbToB[cb]];
725 pByte[n].g = rlimitTable[mY[y] + mCbToG[cb] + mCrToG[cr]];
726 pByte[n].r = rlimitTable[mY[y] + mCrToR[cr]];
727 }
728 pos += width;
729 }
Ed Tanous93f987d2017-04-17 17:52:36 -0700730 }
Ed Tanous93f987d2017-04-17 17:52:36 -0700731 }
Ed Tanous1abe55e2018-09-05 08:30:59 -0700732 void decompress(int txb, int tyb, char *outBuf, uint8_t QT_TableSelection)
733 {
734 unsigned char *ptr;
735 unsigned char byTileYuv[768] = {};
Ed Tanous93f987d2017-04-17 17:52:36 -0700736
Ed Tanous1abe55e2018-09-05 08:30:59 -0700737 memset(dctCoeff, 0, 384 * 2);
738 ptr = byTileYuv;
739 processHuffmanDataUnit(ydcNr, yacNr, &dcy, 0);
740 idctTransform(dctCoeff, ptr, QT_TableSelection);
741 ptr += 64;
Ed Tanous93f987d2017-04-17 17:52:36 -0700742
Ed Tanous1abe55e2018-09-05 08:30:59 -0700743 if (yuvmode == YuvMode::YUV420)
744 {
745 processHuffmanDataUnit(ydcNr, yacNr, &dcy, 64);
746 idctTransform(dctCoeff + 64, ptr, QT_TableSelection);
747 ptr += 64;
Ed Tanous93f987d2017-04-17 17:52:36 -0700748
Ed Tanous1abe55e2018-09-05 08:30:59 -0700749 processHuffmanDataUnit(ydcNr, yacNr, &dcy, 128);
750 idctTransform(dctCoeff + 128, ptr, QT_TableSelection);
751 ptr += 64;
Ed Tanous93f987d2017-04-17 17:52:36 -0700752
Ed Tanous1abe55e2018-09-05 08:30:59 -0700753 processHuffmanDataUnit(ydcNr, yacNr, &dcy, 192);
754 idctTransform(dctCoeff + 192, ptr, QT_TableSelection);
755 ptr += 64;
Ed Tanous93f987d2017-04-17 17:52:36 -0700756
Ed Tanous1abe55e2018-09-05 08:30:59 -0700757 processHuffmanDataUnit(cbDcNr, cbAcNr, &dcCb, 256);
758 idctTransform(dctCoeff + 256, ptr, QT_TableSelection + 1);
759 ptr += 64;
Ed Tanous93f987d2017-04-17 17:52:36 -0700760
Ed Tanous1abe55e2018-09-05 08:30:59 -0700761 processHuffmanDataUnit(crDcNr, crAcNr, &dcCr, 320);
762 idctTransform(dctCoeff + 320, ptr, QT_TableSelection + 1);
763 }
764 else
765 {
766 processHuffmanDataUnit(cbDcNr, cbAcNr, &dcCb, 64);
767 idctTransform(dctCoeff + 64, ptr, QT_TableSelection + 1);
768 ptr += 64;
Ed Tanous93f987d2017-04-17 17:52:36 -0700769
Ed Tanous1abe55e2018-09-05 08:30:59 -0700770 processHuffmanDataUnit(crDcNr, crAcNr, &dcCr, 128);
771 idctTransform(dctCoeff + 128, ptr, QT_TableSelection + 1);
772 }
773
774 // yuvToRgb (txb, tyb, byTileYuv, (unsigned char *)outBuf);
775 // yuvBuffer for YUV record
776 yuvToRgb(txb, tyb, byTileYuv, yuvBuffer.data(),
777 reinterpret_cast<unsigned char *>(outBuf));
Ed Tanous93f987d2017-04-17 17:52:36 -0700778 }
779
Ed Tanous1abe55e2018-09-05 08:30:59 -0700780 void decompress2Pass(int txb, int tyb, char *outBuf,
781 uint8_t QT_TableSelection)
782 {
783 unsigned char *ptr;
784 unsigned char byTileYuv[768];
785 memset(dctCoeff, 0, 384 * 2);
Ed Tanous93f987d2017-04-17 17:52:36 -0700786
Ed Tanous1abe55e2018-09-05 08:30:59 -0700787 ptr = byTileYuv;
788 processHuffmanDataUnit(ydcNr, yacNr, &dcy, 0);
789 idctTransform(dctCoeff, ptr, QT_TableSelection);
790 ptr += 64;
Ed Tanous93f987d2017-04-17 17:52:36 -0700791
Ed Tanous1abe55e2018-09-05 08:30:59 -0700792 processHuffmanDataUnit(cbDcNr, cbAcNr, &dcCb, 64);
793 idctTransform(dctCoeff + 64, ptr, QT_TableSelection + 1);
794 ptr += 64;
Ed Tanous93f987d2017-04-17 17:52:36 -0700795
Ed Tanous1abe55e2018-09-05 08:30:59 -0700796 processHuffmanDataUnit(crDcNr, crAcNr, &dcCr, 128);
797 idctTransform(dctCoeff + 128, ptr, QT_TableSelection + 1);
Ed Tanous93f987d2017-04-17 17:52:36 -0700798
Ed Tanous1abe55e2018-09-05 08:30:59 -0700799 yuvToBuffer(txb, tyb, byTileYuv, yuvBuffer.data(),
800 reinterpret_cast<unsigned char *>(outBuf));
801 // yuvToRgb (txb, tyb, byTileYuv, (unsigned char *)outBuf);
Ed Tanous93f987d2017-04-17 17:52:36 -0700802 }
Ed Tanous93f987d2017-04-17 17:52:36 -0700803
Ed Tanous1abe55e2018-09-05 08:30:59 -0700804 void vqDecompress(int txb, int tyb, char *outBuf, uint8_t QT_TableSelection,
805 struct ColorCache *VQ)
806 {
807 unsigned char *ptr, i;
808 unsigned char byTileYuv[192];
809 int data;
810
811 ptr = byTileYuv;
812 if (VQ->bitMapBits == 0)
813 {
814 for (i = 0; i < 64; i++)
815 {
816 ptr[0] = (VQ->color[VQ->index[0]] & 0xFF0000) >> 16;
817 ptr[64] = (VQ->color[VQ->index[0]] & 0x00FF00) >> 8;
818 ptr[128] = VQ->color[VQ->index[0]] & 0x0000FF;
819 ptr += 1;
820 }
Ed Tanous911ac312017-08-15 09:37:42 -0700821 }
Ed Tanous1abe55e2018-09-05 08:30:59 -0700822 else
823 {
824 for (i = 0; i < 64; i++)
825 {
826 data = static_cast<int>(lookKbits(VQ->bitMapBits));
827 ptr[0] = (VQ->color[VQ->index[data]] & 0xFF0000) >> 16;
828 ptr[64] = (VQ->color[VQ->index[data]] & 0x00FF00) >> 8;
829 ptr[128] = VQ->color[VQ->index[data]] & 0x0000FF;
830 ptr += 1;
831 skipKbits(VQ->bitMapBits);
832 }
Ed Tanous911ac312017-08-15 09:37:42 -0700833 }
Ed Tanous1abe55e2018-09-05 08:30:59 -0700834 // yuvToRgb (txb, tyb, byTileYuv, (unsigned char *)outBuf);
835 yuvToRgb(txb, tyb, byTileYuv, yuvBuffer.data(),
836 reinterpret_cast<unsigned char *>(outBuf));
Ed Tanous93f987d2017-04-17 17:52:36 -0700837 }
Ed Tanous93f987d2017-04-17 17:52:36 -0700838
Ed Tanous1abe55e2018-09-05 08:30:59 -0700839 void moveBlockIndex()
840 {
841 if (yuvmode == YuvMode::YUV444)
842 {
843 txb++;
844 if (txb >= static_cast<int>(width / 8))
845 {
846 tyb++;
847 if (tyb >= static_cast<int>(height / 8))
848 {
849 tyb = 0;
850 }
851 txb = 0;
852 }
853 }
854 else
855 {
856 txb++;
857 if (txb >= static_cast<int>(width / 16))
858 {
859 tyb++;
860 if (tyb >= static_cast<int>(height / 16))
861 {
862 tyb = 0;
863 }
864 txb = 0;
865 }
866 }
867 }
868
869 void initColorTable()
870 {
871 int i, x;
872 int nScale = 1L << 16; // equal to power(2,16)
873 int nHalf = nScale >> 1;
Ed Tanous93f987d2017-04-17 17:52:36 -0700874
875#define FIX(x) ((int)((x)*nScale + 0.5))
876
Ed Tanous1abe55e2018-09-05 08:30:59 -0700877 /* i is the actual input pixel value, in the range 0..MAXJSAMPLE */
878 /* The Cb or Cr value we are thinking of is x = i - CENTERJSAMPLE */
879 /* Cr=>r value is nearest int to 1.597656 * x */
880 /* Cb=>b value is nearest int to 2.015625 * x */
881 /* Cr=>g value is scaled-up -0.8125 * x */
882 /* Cb=>g value is scaled-up -0.390625 * x */
883 for (i = 0, x = -128; i < 256; i++, x++)
884 {
885 mCrToR[i] = (FIX(1.597656) * x + nHalf) >> 16;
886 mCbToB[i] = (FIX(2.015625) * x + nHalf) >> 16;
887 mCrToG[i] = (-FIX(0.8125) * x + nHalf) >> 16;
888 mCbToG[i] = (-FIX(0.390625) * x + nHalf) >> 16;
Ed Tanous93f987d2017-04-17 17:52:36 -0700889 }
Ed Tanous1abe55e2018-09-05 08:30:59 -0700890 for (i = 0, x = -16; i < 256; i++, x++)
891 {
892 mY[i] = (FIX(1.164) * x + nHalf) >> 16;
893 }
894 // For color Text Enchance Y Re-map. Recommend to disable in default
895 /*
896 for (i = 0; i <
897 (VideoEngineInfo->INFData.Gamma1_Gamma2_Seperate); i++) { temp =
898 (double)i / VideoEngineInfo->INFData.Gamma1_Gamma2_Seperate; temp1
899 = 1.0 / VideoEngineInfo->INFData.Gamma1Parameter; mY[i] =
900 (BYTE)(VideoEngineInfo->INFData.Gamma1_Gamma2_Seperate * pow (temp,
901 temp1));
902 if (mY[i] > 255) mY[i] = 255;
903 }
904 for (i = (VideoEngineInfo->INFData.Gamma1_Gamma2_Seperate); i <
905 256; i++) { mY[i] =
906 (BYTE)((VideoEngineInfo->INFData.Gamma1_Gamma2_Seperate) + (256 -
907 VideoEngineInfo->INFData.Gamma1_Gamma2_Seperate) * ( pow((double)((i
908 - VideoEngineInfo->INFData.Gamma1_Gamma2_Seperate) / (256 -
909 (VideoEngineInfo->INFData.Gamma1_Gamma2_Seperate))), (1.0 /
910 VideoEngineInfo->INFData.Gamma2Parameter)) ));
911 if (mY[i] > 255) mY[i] = 255;
912 }
913 */
Ed Tanous93f987d2017-04-17 17:52:36 -0700914 }
Ed Tanous1abe55e2018-09-05 08:30:59 -0700915 void loadHuffmanTable(HuffmanTable *HT, const unsigned char *nrcode,
916 const unsigned char *value,
917 const unsigned short int *Huff_code)
918 {
919 unsigned char k, j, i;
920 unsigned int code, codeIndex;
Ed Tanous93f987d2017-04-17 17:52:36 -0700921
Ed Tanous1abe55e2018-09-05 08:30:59 -0700922 for (j = 1; j <= 16; j++)
923 {
924 HT->length[j] = nrcode[j];
925 }
926 for (i = 0, k = 1; k <= 16; k++)
927 {
928 for (j = 0; j < HT->length[k]; j++)
929 {
930 HT->v[wordHiLo(k, j)] = value[i];
931 i++;
932 }
933 }
934
935 code = 0;
936 for (k = 1; k <= 16; k++)
937 {
938 HT->minorCode[k] = static_cast<unsigned short int>(code);
939 for (j = 1; j <= HT->length[k]; j++)
940 {
941 code++;
942 }
943 HT->majorCode[k] = static_cast<unsigned short int>(code - 1);
944 code *= 2;
945 if (HT->length[k] == 0)
946 {
947 HT->minorCode[k] = 0xFFFF;
948 HT->majorCode[k] = 0;
949 }
950 }
951
952 HT->len[0] = 2;
953 i = 2;
954
955 for (codeIndex = 1; codeIndex < 65535; codeIndex++)
956 {
957 if (codeIndex < Huff_code[i])
958 {
959 HT->len[codeIndex] =
960 static_cast<unsigned char>(Huff_code[i + 1]);
961 }
962 else
963 {
964 i = i + 2;
965 HT->len[codeIndex] =
966 static_cast<unsigned char>(Huff_code[i + 1]);
967 }
968 }
969 }
970 void initJpgTable()
971 {
972 initColorTable();
973 prepareRangeLimitTable();
974 loadHuffmanTable(&htdc[0], stdDcLuminanceNrcodes, stdDcLuminanceValues,
975 dcLuminanceHuffmancode);
976 loadHuffmanTable(&htac[0], stdAcLuminanceNrcodes, stdAcLuminanceValues,
977 acLuminanceHuffmancode);
978 loadHuffmanTable(&htdc[1], stdDcChrominanceNrcodes,
979 stdDcChrominanceValues, dcChrominanceHuffmancode);
980 loadHuffmanTable(&htac[1], stdAcChrominanceNrcodes,
981 stdAcChrominanceValues, acChrominanceHuffmancode);
982 }
983
984 void prepareRangeLimitTable()
985 /* Allocate and fill in the sample_range_limit table */
986 {
987 int j;
988 rlimitTable = reinterpret_cast<unsigned char *>(malloc(5 * 256L + 128));
989 /* First segment of "simple" table: limit[x] = 0 for x < 0 */
990 memset((void *)rlimitTable, 0, 256);
991 rlimitTable += 256; /* allow negative subscripts of simple table */
992 /* Main part of "simple" table: limit[x] = x */
993 for (j = 0; j < 256; j++)
994 {
995 rlimitTable[j] = j;
996 }
997 /* End of simple table, rest of first half of post-IDCT table */
998 for (j = 256; j < 640; j++)
999 {
1000 rlimitTable[j] = 255;
1001 }
1002
1003 /* Second half of post-IDCT table */
1004 memset((void *)(rlimitTable + 640), 0, 384);
1005 for (j = 0; j < 128; j++)
1006 {
1007 rlimitTable[j + 1024] = j;
1008 }
1009 }
1010
1011 inline unsigned short int wordHiLo(uint8_t byte_high, uint8_t byte_low)
1012 {
1013 return (byte_high << 8) + byte_low;
1014 }
Ed Tanous93f987d2017-04-17 17:52:36 -07001015
1016 // river
Ed Tanous1abe55e2018-09-05 08:30:59 -07001017 void processHuffmanDataUnit(uint8_t DC_nr, uint8_t AC_nr,
1018 signed short int *previous_DC,
1019 unsigned short int position)
1020 {
1021 uint8_t nr = 0;
1022 uint8_t k;
1023 unsigned short int tmpHcode;
1024 uint8_t sizeVal, count0;
1025 unsigned short int *minCode;
1026 uint8_t *huffValues;
1027 uint8_t byteTemp;
Ed Tanous93f987d2017-04-17 17:52:36 -07001028
Ed Tanous1abe55e2018-09-05 08:30:59 -07001029 minCode = htdc[DC_nr].minorCode;
1030 // maj_code=htdc[DC_nr].majorCode;
1031 huffValues = htdc[DC_nr].v;
Ed Tanous93f987d2017-04-17 17:52:36 -07001032
Ed Tanous1abe55e2018-09-05 08:30:59 -07001033 // DC
1034 k = htdc[DC_nr].len[static_cast<unsigned short int>(codebuf >> 16)];
1035 // river
1036 // tmp_Hcode=lookKbits(k);
1037 tmpHcode = static_cast<unsigned short int>(codebuf >> (32 - k));
1038 skipKbits(k);
1039 sizeVal = huffValues[wordHiLo(
1040 k, static_cast<uint8_t>(tmpHcode - minCode[k]))];
1041 if (sizeVal == 0)
1042 {
1043 dctCoeff[position + 0] = *previous_DC;
Ed Tanousb078cf32017-04-18 14:51:21 -07001044 }
Ed Tanous1abe55e2018-09-05 08:30:59 -07001045 else
1046 {
1047 dctCoeff[position + 0] = *previous_DC + getKbits(sizeVal);
1048 *previous_DC = dctCoeff[position + 0];
Ed Tanousb078cf32017-04-18 14:51:21 -07001049 }
Ed Tanous93f987d2017-04-17 17:52:36 -07001050
Ed Tanous1abe55e2018-09-05 08:30:59 -07001051 // Second, AC coefficient decoding
1052 minCode = htac[AC_nr].minorCode;
1053 // maj_code=htac[AC_nr].majorCode;
1054 huffValues = htac[AC_nr].v;
1055
1056 nr = 1; // AC coefficient
1057 do
1058 {
1059 k = htac[AC_nr].len[static_cast<unsigned short int>(codebuf >> 16)];
1060 tmpHcode = static_cast<unsigned short int>(codebuf >> (32 - k));
1061 skipKbits(k);
1062
1063 byteTemp = huffValues[wordHiLo(
1064 k, static_cast<uint8_t>(tmpHcode - minCode[k]))];
1065 sizeVal = byteTemp & 0xF;
1066 count0 = byteTemp >> 4;
1067 if (sizeVal == 0)
1068 {
1069 if (count0 != 0xF)
1070 {
1071 break;
1072 }
1073 nr += 16;
1074 }
1075 else
1076 {
1077 nr += count0; // skip count_0 zeroes
1078 dctCoeff[position + dezigzag[nr++]] = getKbits(sizeVal);
1079 }
1080 } while (nr < 64);
Ed Tanouscc9e2c22017-04-18 14:32:02 -07001081 }
Ed Tanous93f987d2017-04-17 17:52:36 -07001082
Ed Tanous1abe55e2018-09-05 08:30:59 -07001083 unsigned short int lookKbits(uint8_t k)
1084 {
1085 unsigned short int revcode;
Ed Tanous93f987d2017-04-17 17:52:36 -07001086
Ed Tanous1abe55e2018-09-05 08:30:59 -07001087 revcode = static_cast<unsigned short int>(codebuf >> (32 - k));
Ed Tanous93f987d2017-04-17 17:52:36 -07001088
Ed Tanous1abe55e2018-09-05 08:30:59 -07001089 return (revcode);
1090 }
Ed Tanous1ff48782017-04-18 12:45:08 -07001091
Ed Tanous1abe55e2018-09-05 08:30:59 -07001092 void skipKbits(uint8_t k)
1093 {
1094 unsigned long readbuf;
Ed Tanous1ff48782017-04-18 12:45:08 -07001095
Ed Tanous1abe55e2018-09-05 08:30:59 -07001096 if ((newbits - k) <= 0)
1097 {
1098 readbuf = buffer[bufferIndex];
1099 bufferIndex++;
1100 codebuf = (codebuf << k) |
1101 ((newbuf | (readbuf >> (newbits))) >> (32 - k));
1102 newbuf = readbuf << (k - newbits);
1103 newbits = 32 + newbits - k;
1104 }
1105 else
1106 {
1107 codebuf = (codebuf << k) | (newbuf >> (32 - k));
1108 newbuf = newbuf << k;
1109 newbits -= k;
1110 }
1111 }
Ed Tanous93f987d2017-04-17 17:52:36 -07001112
Ed Tanous1abe55e2018-09-05 08:30:59 -07001113 signed short int getKbits(uint8_t k)
1114 {
1115 signed short int signedWordvalue;
Ed Tanous93f987d2017-04-17 17:52:36 -07001116
Ed Tanous1abe55e2018-09-05 08:30:59 -07001117 // river
1118 // signed_wordvalue=lookKbits(k);
1119 signedWordvalue = static_cast<unsigned short int>(codebuf >> (32 - k));
1120 if (((1L << (k - 1)) & signedWordvalue) == 0)
1121 {
1122 // neg_pow2 was previously defined as the below. It seemed silly to
1123 // keep a table of values around for something THat's relatively
1124 // easy to compute, so it was replaced with the appropriate math
1125 // signed_wordvalue = signed_wordvalue - (0xFFFF >> (16 - k));
1126 std::array<signed short int, 17> negPow2 = {
1127 0, -1, -3, -7, -15, -31, -63, -127,
1128 -255, -511, -1023, -2047, -4095, -8191, -16383, -32767};
Ed Tanous93f987d2017-04-17 17:52:36 -07001129
Ed Tanous1abe55e2018-09-05 08:30:59 -07001130 signedWordvalue = signedWordvalue + negPow2[k];
1131 }
1132 skipKbits(k);
1133 return signedWordvalue;
1134 }
1135 int initJpgDecoding()
1136 {
1137 bytePos = 0;
1138 loadQuantTable(qt[0]);
1139 loadQuantTableCb(qt[1]);
1140 // Note: Added for Dual-JPEG
1141 loadAdvanceQuantTable(qt[2]);
1142 loadAdvanceQuantTableCb(qt[3]);
1143 return 1;
1144 }
1145
1146 void setQuantTable(const uint8_t *basic_table, uint8_t scale_factor,
1147 std::array<uint8_t, 64> &newtable)
1148 // Set quantization table and zigzag reorder it
1149 {
1150 uint8_t i;
1151 long temp;
1152 for (i = 0; i < 64; i++)
1153 {
1154 temp = (static_cast<long>(basic_table[i] * 16) / scale_factor);
1155 /* limit the values to the valid range */
1156 if (temp <= 0L)
1157 {
1158 temp = 1L;
Ed Tanous93f987d2017-04-17 17:52:36 -07001159 }
Ed Tanous1abe55e2018-09-05 08:30:59 -07001160 if (temp > 255L)
1161 {
1162 temp = 255L; /* limit to baseline range if requested */
Ed Tanous93f987d2017-04-17 17:52:36 -07001163 }
Ed Tanous1abe55e2018-09-05 08:30:59 -07001164 newtable[zigzag[i]] = static_cast<uint8_t>(temp);
1165 }
1166 }
Ed Tanous93f987d2017-04-17 17:52:36 -07001167
Ed Tanous1abe55e2018-09-05 08:30:59 -07001168 void updatereadbuf(uint32_t *codebuf, uint32_t *newbuf, int walks,
1169 int *newbits, std::vector<uint32_t> &buffer)
1170 {
1171 unsigned long readbuf;
Ed Tanous93f987d2017-04-17 17:52:36 -07001172
Ed Tanous1abe55e2018-09-05 08:30:59 -07001173 if ((*newbits - walks) <= 0)
1174 {
1175 readbuf = buffer[bufferIndex];
1176 bufferIndex++;
1177 *codebuf = (*codebuf << walks) |
1178 ((*newbuf | (readbuf >> (*newbits))) >> (32 - walks));
1179 *newbuf = readbuf << (walks - *newbits);
1180 *newbits = 32 + *newbits - walks;
1181 }
1182 else
1183 {
1184 *codebuf = (*codebuf << walks) | (*newbuf >> (32 - walks));
1185 *newbuf = *newbuf << walks;
1186 *newbits -= walks;
1187 }
1188 }
1189
1190 uint32_t decode(std::vector<uint32_t> &bufferVector, unsigned long width,
1191 unsigned long height, YuvMode yuvmode_in, int ySelector,
1192 int uvSelector)
1193 {
1194 ColorCache decodeColor;
1195 if (width != userWidth || height != userHeight ||
1196 yuvmode_in != yuvmode || ySelector != ySelector ||
1197 uvSelector != uvSelector)
1198 {
1199 yuvmode = yuvmode_in;
1200 ySelector = ySelector; // 0-7
1201 uvSelector = uvSelector; // 0-7
1202 userHeight = height;
1203 userWidth = width;
1204 width = width;
1205 height = height;
1206
1207 // TODO(ed) Magic number section. Document appropriately
1208 advanceSelector = 0; // 0-7
1209 mapping = 0; // 0 or 1
1210
1211 if (yuvmode == YuvMode::YUV420)
1212 {
1213 if ((width % 16) != 0u)
1214 {
1215 width = width + 16 - (width % 16);
1216 }
1217 if ((height % 16) != 0u)
1218 {
1219 height = height + 16 - (height % 16);
1220 }
Ed Tanous93f987d2017-04-17 17:52:36 -07001221 }
Ed Tanous1abe55e2018-09-05 08:30:59 -07001222 else
1223 {
1224 if ((width % 8) != 0u)
1225 {
1226 width = width + 8 - (width % 8);
1227 }
1228 if ((height % 8) != 0u)
1229 {
1230 height = height + 8 - (height % 8);
1231 }
Ed Tanous93f987d2017-04-17 17:52:36 -07001232 }
Ed Tanous93f987d2017-04-17 17:52:36 -07001233
Ed Tanous1abe55e2018-09-05 08:30:59 -07001234 initJpgDecoding();
1235 }
1236 // TODO(ed) cleanup cruft
1237 buffer = bufferVector.data();
Ed Tanous93f987d2017-04-17 17:52:36 -07001238
Ed Tanous1abe55e2018-09-05 08:30:59 -07001239 codebuf = bufferVector[0];
1240 newbuf = bufferVector[1];
1241 bufferIndex = 2;
1242
1243 txb = tyb = 0;
1244 newbits = 32;
1245 dcy = dcCb = dcCr = 0;
1246
1247 static const uint32_t vqHeaderMask = 0x01;
1248 static const uint32_t vqNoUpdateHeader = 0x00;
1249 static const uint32_t vqUpdateHeader = 0x01;
1250 static const int vqNoUpdateLength = 0x03;
1251 static const int vqUpdateLength = 0x1B;
1252 static const uint32_t vqIndexMask = 0x03;
1253 static const uint32_t vqColorMask = 0xFFFFFF;
1254
1255 static const int blockAsT2100StartLength = 0x04;
1256 static const int blockAsT2100SkipLength = 20; // S:1 H:3 X:8 Y:8
1257
1258 do
1259 {
1260 auto blockHeader = static_cast<JpgBlock>((codebuf >> 28) & 0xFF);
1261 switch (blockHeader)
1262 {
1263 case JpgBlock::JPEG_NO_SKIP_CODE:
1264 updatereadbuf(&codebuf, &newbuf, blockAsT2100StartLength,
1265 &newbits, bufferVector);
1266 decompress(txb, tyb,
1267 reinterpret_cast<char *>(outBuffer.data()), 0);
1268 break;
1269 case JpgBlock::FRAME_END_CODE:
1270 return 0;
1271 break;
1272 case JpgBlock::JPEG_SKIP_CODE:
1273
1274 txb = (codebuf & 0x0FF00000) >> 20;
1275 tyb = (codebuf & 0x0FF000) >> 12;
1276
1277 updatereadbuf(&codebuf, &newbuf, blockAsT2100SkipLength,
1278 &newbits, bufferVector);
1279 decompress(txb, tyb,
1280 reinterpret_cast<char *>(outBuffer.data()), 0);
1281 break;
1282 case JpgBlock::VQ_NO_SKIP_1_COLOR_CODE:
1283 updatereadbuf(&codebuf, &newbuf, blockAsT2100StartLength,
1284 &newbits, bufferVector);
1285 decodeColor.bitMapBits = 0;
1286
1287 for (int i = 0; i < 1; i++)
1288 {
1289 decodeColor.index[i] = ((codebuf >> 29) & vqIndexMask);
1290 if (((codebuf >> 31) & vqHeaderMask) ==
1291 vqNoUpdateHeader)
1292 {
1293 updatereadbuf(&codebuf, &newbuf, vqNoUpdateLength,
1294 &newbits, bufferVector);
1295 }
1296 else
1297 {
1298 decodeColor.color[decodeColor.index[i]] =
1299 ((codebuf >> 5) & vqColorMask);
1300 updatereadbuf(&codebuf, &newbuf, vqUpdateLength,
1301 &newbits, bufferVector);
1302 }
1303 }
1304 vqDecompress(txb, tyb,
1305 reinterpret_cast<char *>(outBuffer.data()), 0,
1306 &decodeColor);
1307 break;
1308 case JpgBlock::VQ_SKIP_1_COLOR_CODE:
1309 txb = (codebuf & 0x0FF00000) >> 20;
1310 tyb = (codebuf & 0x0FF000) >> 12;
1311
1312 updatereadbuf(&codebuf, &newbuf, blockAsT2100SkipLength,
1313 &newbits, bufferVector);
1314 decodeColor.bitMapBits = 0;
1315
1316 for (int i = 0; i < 1; i++)
1317 {
1318 decodeColor.index[i] = ((codebuf >> 29) & vqIndexMask);
1319 if (((codebuf >> 31) & vqHeaderMask) ==
1320 vqNoUpdateHeader)
1321 {
1322 updatereadbuf(&codebuf, &newbuf, vqNoUpdateLength,
1323 &newbits, bufferVector);
1324 }
1325 else
1326 {
1327 decodeColor.color[decodeColor.index[i]] =
1328 ((codebuf >> 5) & vqColorMask);
1329 updatereadbuf(&codebuf, &newbuf, vqUpdateLength,
1330 &newbits, bufferVector);
1331 }
1332 }
1333 vqDecompress(txb, tyb,
1334 reinterpret_cast<char *>(outBuffer.data()), 0,
1335 &decodeColor);
1336 break;
1337
1338 case JpgBlock::VQ_NO_SKIP_2_COLOR_CODE:
1339 updatereadbuf(&codebuf, &newbuf, blockAsT2100StartLength,
1340 &newbits, bufferVector);
1341 decodeColor.bitMapBits = 1;
1342
1343 for (int i = 0; i < 2; i++)
1344 {
1345 decodeColor.index[i] = ((codebuf >> 29) & vqIndexMask);
1346 if (((codebuf >> 31) & vqHeaderMask) ==
1347 vqNoUpdateHeader)
1348 {
1349 updatereadbuf(&codebuf, &newbuf, vqNoUpdateLength,
1350 &newbits, bufferVector);
1351 }
1352 else
1353 {
1354 decodeColor.color[decodeColor.index[i]] =
1355 ((codebuf >> 5) & vqColorMask);
1356 updatereadbuf(&codebuf, &newbuf, vqUpdateLength,
1357 &newbits, bufferVector);
1358 }
1359 }
1360 vqDecompress(txb, tyb,
1361 reinterpret_cast<char *>(outBuffer.data()), 0,
1362 &decodeColor);
1363 break;
1364 case JpgBlock::VQ_SKIP_2_COLOR_CODE:
1365 txb = (codebuf & 0x0FF00000) >> 20;
1366 tyb = (codebuf & 0x0FF000) >> 12;
1367
1368 updatereadbuf(&codebuf, &newbuf, blockAsT2100SkipLength,
1369 &newbits, bufferVector);
1370 decodeColor.bitMapBits = 1;
1371
1372 for (int i = 0; i < 2; i++)
1373 {
1374 decodeColor.index[i] = ((codebuf >> 29) & vqIndexMask);
1375 if (((codebuf >> 31) & vqHeaderMask) ==
1376 vqNoUpdateHeader)
1377 {
1378 updatereadbuf(&codebuf, &newbuf, vqNoUpdateLength,
1379 &newbits, bufferVector);
1380 }
1381 else
1382 {
1383 decodeColor.color[decodeColor.index[i]] =
1384 ((codebuf >> 5) & vqColorMask);
1385 updatereadbuf(&codebuf, &newbuf, vqUpdateLength,
1386 &newbits, bufferVector);
1387 }
1388 }
1389 vqDecompress(txb, tyb,
1390 reinterpret_cast<char *>(outBuffer.data()), 0,
1391 &decodeColor);
1392
1393 break;
1394 case JpgBlock::VQ_NO_SKIP_4_COLOR_CODE:
1395 updatereadbuf(&codebuf, &newbuf, blockAsT2100StartLength,
1396 &newbits, bufferVector);
1397 decodeColor.bitMapBits = 2;
1398
1399 for (unsigned char &i : decodeColor.index)
1400 {
1401 i = ((codebuf >> 29) & vqIndexMask);
1402 if (((codebuf >> 31) & vqHeaderMask) ==
1403 vqNoUpdateHeader)
1404 {
1405 updatereadbuf(&codebuf, &newbuf, vqNoUpdateLength,
1406 &newbits, bufferVector);
1407 }
1408 else
1409 {
1410 decodeColor.color[i] =
1411 ((codebuf >> 5) & vqColorMask);
1412 updatereadbuf(&codebuf, &newbuf, vqUpdateLength,
1413 &newbits, bufferVector);
1414 }
1415 }
1416 vqDecompress(txb, tyb,
1417 reinterpret_cast<char *>(outBuffer.data()), 0,
1418 &decodeColor);
1419
1420 break;
1421
1422 case JpgBlock::VQ_SKIP_4_COLOR_CODE:
1423 txb = (codebuf & 0x0FF00000) >> 20;
1424 tyb = (codebuf & 0x0FF000) >> 12;
1425
1426 updatereadbuf(&codebuf, &newbuf, blockAsT2100SkipLength,
1427 &newbits, bufferVector);
1428 decodeColor.bitMapBits = 2;
1429
1430 for (unsigned char &i : decodeColor.index)
1431 {
1432 i = ((codebuf >> 29) & vqIndexMask);
1433 if (((codebuf >> 31) & vqHeaderMask) ==
1434 vqNoUpdateHeader)
1435 {
1436 updatereadbuf(&codebuf, &newbuf, vqNoUpdateLength,
1437 &newbits, bufferVector);
1438 }
1439 else
1440 {
1441 decodeColor.color[i] =
1442 ((codebuf >> 5) & vqColorMask);
1443 updatereadbuf(&codebuf, &newbuf, vqUpdateLength,
1444 &newbits, bufferVector);
1445 }
1446 }
1447 vqDecompress(txb, tyb,
1448 reinterpret_cast<char *>(outBuffer.data()), 0,
1449 &decodeColor);
1450
1451 break;
1452 case JpgBlock::JPEG_SKIP_PASS2_CODE:
1453 txb = (codebuf & 0x0FF00000) >> 20;
1454 tyb = (codebuf & 0x0FF000) >> 12;
1455
1456 updatereadbuf(&codebuf, &newbuf, blockAsT2100SkipLength,
1457 &newbits, bufferVector);
1458 decompress2Pass(txb, tyb,
1459 reinterpret_cast<char *>(outBuffer.data()),
1460 2);
1461
1462 break;
1463 default:
1464 // TODO(ed) propogate errors upstream
1465 return -1;
1466 break;
Ed Tanous93f987d2017-04-17 17:52:36 -07001467 }
Ed Tanous1abe55e2018-09-05 08:30:59 -07001468 moveBlockIndex();
Ed Tanous93f987d2017-04-17 17:52:36 -07001469
Ed Tanous1abe55e2018-09-05 08:30:59 -07001470 } while (bufferIndex <= bufferVector.size());
Ed Tanous93f987d2017-04-17 17:52:36 -07001471
Ed Tanous1abe55e2018-09-05 08:30:59 -07001472 return -1;
1473 }
Ed Tanous93f987d2017-04-17 17:52:36 -07001474
1475#ifdef cimg_version
Ed Tanous1abe55e2018-09-05 08:30:59 -07001476 void dump_to_bitmap_file()
1477 {
1478 cimg_library::CImg<unsigned char> image(width, height, 1, 3);
1479 for (int y = 0; y < width; y++)
1480 {
1481 for (int x = 0; x < height; x++)
1482 {
1483 auto pixel = outBuffer[x + (y * width)];
1484 image(x, y, 0) = pixel.r;
1485 image(x, y, 1) = pixel.g;
1486 image(x, y, 2) = pixel.b;
1487 }
1488 }
1489 image.save("/tmp/file2.bmp");
Ed Tanous93f987d2017-04-17 17:52:36 -07001490 }
Ed Tanous93f987d2017-04-17 17:52:36 -07001491#endif
1492
Ed Tanous1abe55e2018-09-05 08:30:59 -07001493 private:
1494 YuvMode yuvmode{};
1495 // width and height are the modes your display used
1496 unsigned long width{};
1497 unsigned long height{};
1498 unsigned long userWidth{};
1499 unsigned long userHeight{};
1500 unsigned char ySelector{};
1501 int scalefactor;
1502 int scalefactoruv;
1503 int advancescalefactor;
1504 int advancescalefactoruv;
1505 int mapping{};
1506 unsigned char uvSelector{};
1507 unsigned char advanceSelector{};
1508 int bytePos{}; // current byte position
Ed Tanous93f987d2017-04-17 17:52:36 -07001509
Ed Tanous1abe55e2018-09-05 08:30:59 -07001510 // quantization tables, no more than 4 quantization tables
1511 std::array<std::array<long, 64>, 4> qt{};
Ed Tanous93f987d2017-04-17 17:52:36 -07001512
Ed Tanous1abe55e2018-09-05 08:30:59 -07001513 // DC huffman tables , no more than 4 (0..3)
1514 std::array<HuffmanTable, 4> htdc{};
1515 // AC huffman tables (0..3)
1516 std::array<HuffmanTable, 4> htac{};
1517 std::array<int, 256> mCrToR{};
1518 std::array<int, 256> mCbToB{};
1519 std::array<int, 256> mCrToG{};
1520 std::array<int, 256> mCbToG{};
1521 std::array<int, 256> mY{};
1522 unsigned long bufferIndex{};
1523 uint32_t codebuf{}, newbuf{}, readbuf{};
1524 const unsigned char *stdLuminanceQt{};
1525 const uint8_t *stdChrominanceQt{};
Ed Tanous93f987d2017-04-17 17:52:36 -07001526
Ed Tanous1abe55e2018-09-05 08:30:59 -07001527 signed short int dcy{}, dcCb{}, dcCr{}; // Coeficientii DC pentru Y,Cb,Cr
1528 signed short int dctCoeff[384]{};
1529 // std::vector<signed short int> dctCoeff; // Current DCT_coefficients
1530 // quantization table number for Y, Cb, Cr
1531 uint8_t yqNr = 0, cbQNr = 1, crQNr = 1;
1532 // DC Huffman table number for Y,Cb, Cr
1533 uint8_t ydcNr = 0, cbDcNr = 1, crDcNr = 1;
1534 // AC Huffman table number for Y,Cb, Cr
1535 uint8_t yacNr = 0, cbAcNr = 1, crAcNr = 1;
1536 int txb = 0;
1537 int tyb = 0;
1538 int newbits{};
1539 uint8_t *rlimitTable{};
1540 std::vector<RGB> yuvBuffer;
1541 // TODO(ed) this shouldn't exist. It is cruft that needs cleaning up
1542 uint32_t *buffer{};
Ed Tanous93f987d2017-04-17 17:52:36 -07001543
Ed Tanous1abe55e2018-09-05 08:30:59 -07001544 public:
1545 std::vector<RGB> outBuffer;
Ed Tanous93f987d2017-04-17 17:52:36 -07001546};
Ed Tanous1abe55e2018-09-05 08:30:59 -07001547} // namespace ast_video