X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;ds=sidebyside;f=driver.c;h=04e236912ca45d56bc4f1a34f16b3c04185112d9;hb=9d977ffbb1bc9cfe41d5e074de51bb9d7bed96d7;hp=35934da1d72d711efafdb588b62dae22cdcd8e54;hpb=bed2510078b46c35b95941e59327b1008e4bd176;p=fjl diff --git a/driver.c b/driver.c index 35934da..04e2369 100644 --- a/driver.c +++ b/driver.c @@ -194,13 +194,11 @@ void read_scan(struct byte_source* source, struct jpeg_image* image, huffman_tab 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); + unsigned real_x = (mcu_x * image->hsample[cn] + local_xb) * DCTSIZE; + unsigned real_y = (mcu_y * image->vsample[cn] + local_yb) * DCTSIZE; + uint8_t* dest_pixdata = image->pixel_data[cn] + real_y * stride + real_x; + for (unsigned y = 0; y < DCTSIZE; ++y, dest_pixdata += stride) { + memcpy(dest_pixdata, pixdata + y * DCTSIZE, DCTSIZE); } } } @@ -214,8 +212,9 @@ void read_scan(struct byte_source* source, struct jpeg_image* image, huffman_tab const int c = 1; if (mcu_y == image->num_blocks_vertical) { unsigned stride = image->num_blocks_horizontal * image->hsample[c] * DCTSIZE; - printf("P5\n%u %u\n255\n", stride, image->height); - fwrite(image->pixel_data[c], stride * image->height, 1, stdout); + unsigned height = image->num_blocks_vertical * image->vsample[c] * DCTSIZE; + printf("P5\n%u %u\n255\n", stride, height); + fwrite(image->pixel_data[c], stride * height, 1, stdout); } } } @@ -293,6 +292,9 @@ int main(void) case 0xd8: /* SOI */ break; + case 0xd9: + /* EOI */ + exit(0); case 0xc4: /* DHT (define Huffman tables) */ read_huffman_tables(&tables, byte_source_input_func, &source);