Ed Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame] | 3 | #include <aspeed/JTABLES.H> |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 4 | |
Ed Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 5 | #include <array> |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 6 | #include <ast_video_types.hpp> |
Ed Tanous | 1ff4878 | 2017-04-18 12:45:08 -0700 | [diff] [blame] | 7 | #include <cassert> |
| 8 | #include <cstdint> |
Ed Tanous | 911ac31 | 2017-08-15 09:37:42 -0700 | [diff] [blame] | 9 | #include <cstring> |
Ed Tanous | b078cf3 | 2017-04-18 14:51:21 -0700 | [diff] [blame] | 10 | #include <iostream> |
| 11 | #include <vector> |
Ed Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 12 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 13 | namespace ast_video |
| 14 | { |
Ed Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 15 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 16 | struct ColorCache |
| 17 | { |
| 18 | ColorCache() : |
| 19 | color{0x008080, 0xFF8080, 0x808080, 0xC08080}, index{0, 1, 2, 3} |
| 20 | { |
| 21 | } |
Ed Tanous | d5f3999 | 2017-04-18 13:41:22 -0700 | [diff] [blame] | 22 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 23 | unsigned long color[4]; |
| 24 | unsigned char index[4]; |
| 25 | unsigned char bitMapBits{}; |
Ed Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 26 | }; |
| 27 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 28 | struct RGB |
| 29 | { |
| 30 | unsigned char b; |
| 31 | unsigned char g; |
| 32 | unsigned char r; |
| 33 | unsigned char reserved; |
Ed Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 34 | }; |
| 35 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 36 | enum class JpgBlock |
| 37 | { |
| 38 | JPEG_NO_SKIP_CODE = 0x00, |
| 39 | JPEG_SKIP_CODE = 0x08, |
Ed Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 40 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 41 | JPEG_PASS2_CODE = 0x02, |
| 42 | JPEG_SKIP_PASS2_CODE = 0x0A, |
Ed Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 43 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 44 | LOW_JPEG_NO_SKIP_CODE = 0x04, |
| 45 | LOW_JPEG_SKIP_CODE = 0x0C, |
Ed Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 46 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 47 | VQ_NO_SKIP_1_COLOR_CODE = 0x05, |
| 48 | VQ_SKIP_1_COLOR_CODE = 0x0D, |
Ed Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 49 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 50 | VQ_NO_SKIP_2_COLOR_CODE = 0x06, |
| 51 | VQ_SKIP_2_COLOR_CODE = 0x0E, |
Ed Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 52 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 53 | VQ_NO_SKIP_4_COLOR_CODE = 0x07, |
| 54 | VQ_SKIP_4_COLOR_CODE = 0x0F, |
Ed Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 55 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 56 | FRAME_END_CODE = 0x09, |
Ed Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 57 | |
| 58 | }; |
| 59 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 60 | class 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 Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 83 | } |
Ed Tanous | d5f3999 | 2017-04-18 13:41:22 -0700 | [diff] [blame] | 84 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 85 | 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 Tanous | d5f3999 | 2017-04-18 13:41:22 -0700 | [diff] [blame] | 92 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 93 | // 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 Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 125 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 126 | 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 Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 142 | } |
Ed Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 143 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 144 | 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 Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 150 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 151 | // 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 Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 215 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 216 | 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 Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 232 | } |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 233 | // 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 Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 240 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 241 | // 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 Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 274 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 275 | 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 Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 291 | } |
Ed Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 292 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 293 | // 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 Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 300 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 301 | // 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 Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 367 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 368 | 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 Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 384 | } |
Ed Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 385 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 386 | void idctTransform(short *coef, uint8_t *data, uint8_t nBlock) |
| 387 | { |
Ed Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 388 | #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 Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 395 | 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 Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 399 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 400 | 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 Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 406 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 407 | quantptr = &qt[nBlock][0]; |
Ed Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 408 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 409 | // Pass 1: process columns from input (inptr), store into work |
| 410 | // array(wsptr) |
Ed Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 411 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 412 | 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 Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 422 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 423 | 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 Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 430 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 431 | 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 Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 439 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 440 | inptr++; /* advance pointers to next column */ |
| 441 | quantptr++; |
| 442 | wsptr++; |
| 443 | continue; |
| 444 | } |
Ed Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 445 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 446 | /* Even part */ |
Ed Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 447 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 448 | 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 Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 452 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 453 | tmp10 = tmp0 + tmp2; /* phase 3 */ |
| 454 | tmp11 = tmp0 - tmp2; |
Ed Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 455 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 456 | tmp13 = tmp1 + tmp3; /* phases 5-3 */ |
| 457 | tmp12 = MULTIPLY(tmp1 - tmp3, FIX_1_414213562) - tmp13; /* 2*c4 */ |
Ed Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 458 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 459 | tmp0 = tmp10 + tmp13; /* phase 2 */ |
| 460 | tmp3 = tmp10 - tmp13; |
| 461 | tmp1 = tmp11 + tmp12; |
| 462 | tmp2 = tmp11 - tmp12; |
Ed Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 463 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 464 | /* Odd part */ |
Ed Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 465 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 466 | 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 Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 470 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 471 | z13 = tmp6 + tmp5; /* phase 6 */ |
| 472 | z10 = tmp6 - tmp5; |
| 473 | z11 = tmp4 + tmp7; |
| 474 | z12 = tmp4 - tmp7; |
Ed Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 475 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 476 | tmp7 = z11 + z13; /* phase 5 */ |
| 477 | tmp11 = MULTIPLY(z11 - z13, FIX_1_414213562); /* 2*c4 */ |
Ed Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 478 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 479 | 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 Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 482 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 483 | tmp6 = tmp12 - tmp7; /* phase 2 */ |
| 484 | tmp5 = tmp11 - tmp6; |
| 485 | tmp4 = tmp10 + tmp5; |
Ed Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 486 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 487 | 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 Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 495 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 496 | inptr++; /* advance pointers to next column */ |
| 497 | quantptr++; |
| 498 | wsptr++; |
| 499 | } |
Ed Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 500 | |
| 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 Tanous | 911ac31 | 2017-08-15 09:37:42 -0700 | [diff] [blame] | 507 | #define IDESCALE(x, n) ((int)((x) >> (n))) |
Ed Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 508 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 509 | wsptr = workspace; |
| 510 | for (ctr = 0; ctr < dctsize; ctr++) |
| 511 | { |
| 512 | outptr = data + ctr * 8; |
Ed Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 513 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 514 | /* 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 Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 522 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 523 | tmp10 = (wsptr[0] + wsptr[4]); |
| 524 | tmp11 = (wsptr[0] - wsptr[4]); |
Ed Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 525 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 526 | tmp13 = (wsptr[2] + wsptr[6]); |
| 527 | tmp12 = MULTIPLY((int)wsptr[2] - (int)wsptr[6], FIX_1_414213562) - |
| 528 | tmp13; |
Ed Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 529 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 530 | tmp0 = tmp10 + tmp13; |
| 531 | tmp3 = tmp10 - tmp13; |
| 532 | tmp1 = tmp11 + tmp12; |
| 533 | tmp2 = tmp11 - tmp12; |
Ed Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 534 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 535 | /* Odd part */ |
Ed Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 536 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 537 | z13 = wsptr[5] + wsptr[3]; |
| 538 | z10 = wsptr[5] - wsptr[3]; |
| 539 | z11 = wsptr[1] + wsptr[7]; |
| 540 | z12 = wsptr[1] - wsptr[7]; |
Ed Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 541 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 542 | tmp7 = z11 + z13; /* phase 5 */ |
| 543 | tmp11 = MULTIPLY(z11 - z13, FIX_1_414213562); /* 2*c4 */ |
Ed Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 544 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 545 | 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 Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 548 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 549 | tmp6 = tmp12 - tmp7; /* phase 2 */ |
| 550 | tmp5 = tmp11 - tmp6; |
| 551 | tmp4 = tmp10 + tmp5; |
Ed Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 552 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 553 | /* Final output stage: scale down by a factor of 8 and range-limit |
| 554 | */ |
Ed Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 555 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 556 | 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 Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 572 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 573 | wsptr += dctsize; /* advance pointer to next row */ |
| 574 | } |
Ed Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 575 | } |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 576 | 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 Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 591 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 592 | pByte = reinterpret_cast<struct RGB *>(pBgr); |
| 593 | if (yuvmode == YuvMode::YUV444) |
| 594 | { |
| 595 | py = pYCbCr; |
| 596 | pcb = pYCbCr + 64; |
| 597 | pcr = pcb + 64; |
Ed Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 598 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 599 | pixelX = txb * 8; |
| 600 | pixelY = tyb * 8; |
| 601 | pos = (pixelY * width) + pixelX; |
Ed Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 602 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 603 | 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 Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 622 | } |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 623 | 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 Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 631 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 632 | pixelX = txb * 16; |
| 633 | pixelY = tyb * 16; |
| 634 | pos = (pixelY * width) + pixelX; |
Ed Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 635 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 636 | 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 Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 652 | } |
Ed Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 653 | } |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 654 | 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 Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 670 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 671 | pByte = reinterpret_cast<struct RGB *>(pBgr); |
| 672 | if (yuvmode == YuvMode::YUV444) |
| 673 | { |
| 674 | py = pYCbCr; |
| 675 | pcb = pYCbCr + 64; |
| 676 | pcr = pcb + 64; |
Ed Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 677 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 678 | pixelX = txb * 8; |
| 679 | pixelY = tyb * 8; |
| 680 | pos = (pixelY * width) + pixelX; |
Ed Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 681 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 682 | 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 Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 700 | } |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 701 | 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 Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 709 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 710 | pixelX = txb * 16; |
| 711 | pixelY = tyb * 16; |
| 712 | pos = (pixelY * width) + pixelX; |
Ed Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 713 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 714 | 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 Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 730 | } |
Ed Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 731 | } |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 732 | void decompress(int txb, int tyb, char *outBuf, uint8_t QT_TableSelection) |
| 733 | { |
| 734 | unsigned char *ptr; |
| 735 | unsigned char byTileYuv[768] = {}; |
Ed Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 736 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 737 | memset(dctCoeff, 0, 384 * 2); |
| 738 | ptr = byTileYuv; |
| 739 | processHuffmanDataUnit(ydcNr, yacNr, &dcy, 0); |
| 740 | idctTransform(dctCoeff, ptr, QT_TableSelection); |
| 741 | ptr += 64; |
Ed Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 742 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 743 | if (yuvmode == YuvMode::YUV420) |
| 744 | { |
| 745 | processHuffmanDataUnit(ydcNr, yacNr, &dcy, 64); |
| 746 | idctTransform(dctCoeff + 64, ptr, QT_TableSelection); |
| 747 | ptr += 64; |
Ed Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 748 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 749 | processHuffmanDataUnit(ydcNr, yacNr, &dcy, 128); |
| 750 | idctTransform(dctCoeff + 128, ptr, QT_TableSelection); |
| 751 | ptr += 64; |
Ed Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 752 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 753 | processHuffmanDataUnit(ydcNr, yacNr, &dcy, 192); |
| 754 | idctTransform(dctCoeff + 192, ptr, QT_TableSelection); |
| 755 | ptr += 64; |
Ed Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 756 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 757 | processHuffmanDataUnit(cbDcNr, cbAcNr, &dcCb, 256); |
| 758 | idctTransform(dctCoeff + 256, ptr, QT_TableSelection + 1); |
| 759 | ptr += 64; |
Ed Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 760 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 761 | 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 Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 769 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 770 | 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 Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 778 | } |
| 779 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 780 | 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 Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 786 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 787 | ptr = byTileYuv; |
| 788 | processHuffmanDataUnit(ydcNr, yacNr, &dcy, 0); |
| 789 | idctTransform(dctCoeff, ptr, QT_TableSelection); |
| 790 | ptr += 64; |
Ed Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 791 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 792 | processHuffmanDataUnit(cbDcNr, cbAcNr, &dcCb, 64); |
| 793 | idctTransform(dctCoeff + 64, ptr, QT_TableSelection + 1); |
| 794 | ptr += 64; |
Ed Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 795 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 796 | processHuffmanDataUnit(crDcNr, crAcNr, &dcCr, 128); |
| 797 | idctTransform(dctCoeff + 128, ptr, QT_TableSelection + 1); |
Ed Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 798 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 799 | yuvToBuffer(txb, tyb, byTileYuv, yuvBuffer.data(), |
| 800 | reinterpret_cast<unsigned char *>(outBuf)); |
| 801 | // yuvToRgb (txb, tyb, byTileYuv, (unsigned char *)outBuf); |
Ed Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 802 | } |
Ed Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 803 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 804 | 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 Tanous | 911ac31 | 2017-08-15 09:37:42 -0700 | [diff] [blame] | 821 | } |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 822 | 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 Tanous | 911ac31 | 2017-08-15 09:37:42 -0700 | [diff] [blame] | 833 | } |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 834 | // yuvToRgb (txb, tyb, byTileYuv, (unsigned char *)outBuf); |
| 835 | yuvToRgb(txb, tyb, byTileYuv, yuvBuffer.data(), |
| 836 | reinterpret_cast<unsigned char *>(outBuf)); |
Ed Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 837 | } |
Ed Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 838 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 839 | 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 Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 874 | |
| 875 | #define FIX(x) ((int)((x)*nScale + 0.5)) |
| 876 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 877 | /* 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 Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 889 | } |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 890 | 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 Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 914 | } |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 915 | 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 Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 921 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 922 | 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 Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 1015 | |
| 1016 | // river |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 1017 | 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 Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 1028 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 1029 | minCode = htdc[DC_nr].minorCode; |
| 1030 | // maj_code=htdc[DC_nr].majorCode; |
| 1031 | huffValues = htdc[DC_nr].v; |
Ed Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 1032 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 1033 | // 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 Tanous | b078cf3 | 2017-04-18 14:51:21 -0700 | [diff] [blame] | 1044 | } |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 1045 | else |
| 1046 | { |
| 1047 | dctCoeff[position + 0] = *previous_DC + getKbits(sizeVal); |
| 1048 | *previous_DC = dctCoeff[position + 0]; |
Ed Tanous | b078cf3 | 2017-04-18 14:51:21 -0700 | [diff] [blame] | 1049 | } |
Ed Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 1050 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 1051 | // 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 Tanous | cc9e2c2 | 2017-04-18 14:32:02 -0700 | [diff] [blame] | 1081 | } |
Ed Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 1082 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 1083 | unsigned short int lookKbits(uint8_t k) |
| 1084 | { |
| 1085 | unsigned short int revcode; |
Ed Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 1086 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 1087 | revcode = static_cast<unsigned short int>(codebuf >> (32 - k)); |
Ed Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 1088 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 1089 | return (revcode); |
| 1090 | } |
Ed Tanous | 1ff4878 | 2017-04-18 12:45:08 -0700 | [diff] [blame] | 1091 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 1092 | void skipKbits(uint8_t k) |
| 1093 | { |
| 1094 | unsigned long readbuf; |
Ed Tanous | 1ff4878 | 2017-04-18 12:45:08 -0700 | [diff] [blame] | 1095 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 1096 | 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 Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 1112 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 1113 | signed short int getKbits(uint8_t k) |
| 1114 | { |
| 1115 | signed short int signedWordvalue; |
Ed Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 1116 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 1117 | // 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 Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 1129 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 1130 | 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 Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 1159 | } |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 1160 | if (temp > 255L) |
| 1161 | { |
| 1162 | temp = 255L; /* limit to baseline range if requested */ |
Ed Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 1163 | } |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 1164 | newtable[zigzag[i]] = static_cast<uint8_t>(temp); |
| 1165 | } |
| 1166 | } |
Ed Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 1167 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 1168 | void updatereadbuf(uint32_t *codebuf, uint32_t *newbuf, int walks, |
| 1169 | int *newbits, std::vector<uint32_t> &buffer) |
| 1170 | { |
| 1171 | unsigned long readbuf; |
Ed Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 1172 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 1173 | 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 Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 1221 | } |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 1222 | 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 Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 1232 | } |
Ed Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 1233 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 1234 | initJpgDecoding(); |
| 1235 | } |
| 1236 | // TODO(ed) cleanup cruft |
| 1237 | buffer = bufferVector.data(); |
Ed Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 1238 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 1239 | 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 Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 1467 | } |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 1468 | moveBlockIndex(); |
Ed Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 1469 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 1470 | } while (bufferIndex <= bufferVector.size()); |
Ed Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 1471 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 1472 | return -1; |
| 1473 | } |
Ed Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 1474 | |
| 1475 | #ifdef cimg_version |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 1476 | 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 Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 1490 | } |
Ed Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 1491 | #endif |
| 1492 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 1493 | 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 Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 1509 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 1510 | // quantization tables, no more than 4 quantization tables |
| 1511 | std::array<std::array<long, 64>, 4> qt{}; |
Ed Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 1512 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 1513 | // 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 Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 1526 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 1527 | 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 Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 1543 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 1544 | public: |
| 1545 | std::vector<RGB> outBuffer; |
Ed Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 1546 | }; |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 1547 | } // namespace ast_video |