- i += r;
- zz[unzigzag[i]] = extend(read_bits(&bits, s), s);
- }
-
- for (unsigned i = 0; i < 63; ++i) {
- putchar(zz[i]);
- //printf("%d ", zz[i]);
+ // decode AC components
+ for (unsigned i = 1; i < DCTSIZE2; ++i) {
+ unsigned rs = read_huffman_symbol(ac_table, &bits);
+ unsigned r = rs >> 4;
+ unsigned s = rs & 0xf;
+
+ if (rs == 0x00) {
+ /* end of block */
+ break;
+ }
+ if (rs == 0xf0) {
+ /* 16 zero coefficients */
+ i += 15;
+ continue;
+ }
+ i += r;
+
+ possibly_refill(&bits, s);
+ coeff[unzigzag[i]] = extend(read_bits(&bits, s), s);
+ }
+
+ uint8_t pixdata[DCTSIZE2];
+ idct_choice(coeff, image->idct_data[image->qtable[cn]], pixdata);
+
+ for (unsigned y = 0; y < DCTSIZE; ++y) {
+ unsigned real_x = (mcu_x * image->hsample[cn] + local_xb) * DCTSIZE;
+ unsigned real_y = (mcu_y * image->vsample[cn] + local_yb) * DCTSIZE + y;
+
+ memcpy(image->pixel_data[cn] + real_y * stride + real_x,
+ pixdata + y * DCTSIZE,
+ DCTSIZE);
+ }