From fb0138d517d723f43221e95bd8ece7419dac70b7 Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Mon, 1 Jun 2009 01:37:07 +0200 Subject: [PATCH 1/1] More manual strength reduction. --- driver.c | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/driver.c b/driver.c index 6db737f..616b613 100644 --- a/driver.c +++ b/driver.c @@ -15,10 +15,12 @@ struct jpeg_image { unsigned num_components; unsigned hsample[256], vsample[256], qtable[256]; unsigned max_hsample, max_vsample; + unsigned stride[256]; unsigned num_blocks_horizontal, num_blocks_vertical; uint32_t qvalues[256][DCTSIZE2]; void* idct_data[256]; uint8_t* pixel_data[256]; + uint8_t* pixel_write_pointer[256]; }; ssize_t stdio_read(void* userdata, uint8_t* buf, size_t count) @@ -103,8 +105,10 @@ void read_sof(struct byte_source* source, struct jpeg_image* image) unsigned width = image->num_blocks_horizontal * image->hsample[c] * DCTSIZE; unsigned height = image->num_blocks_vertical * image->vsample[c] * DCTSIZE; + image->stride[c] = width; image->pixel_data[c] = (uint8_t*)malloc(width * height); assert(image->pixel_data[c] != NULL); + image->pixel_write_pointer[c] = image->pixel_data[c]; fprintf(stderr, "Component %u: allocating %d x %d\n", c, width, height); } @@ -154,11 +158,12 @@ void read_scan(struct byte_source* source, struct jpeg_image* image, huffman_tab while (!bits.source_eof) { for (unsigned c = 0; c < num_components; ++c) { unsigned cn = component_num[c]; - unsigned stride = image->num_blocks_horizontal * image->hsample[cn] * DCTSIZE; assert(image->idct_data[image->qtable[cn]] != NULL); - - for (unsigned local_yb = 0; local_yb < image->vsample[cn]; ++local_yb) { - for (unsigned local_xb = 0; local_xb < image->hsample[cn]; ++local_xb) { + + uint8_t* pixel_write_pointer_y = image->pixel_write_pointer[cn]; + for (unsigned local_yb = 0; local_yb < image->vsample[cn]; ++local_yb, pixel_write_pointer_y += image->stride[cn] * DCTSIZE) { + uint8_t* pixel_write_pointer = pixel_write_pointer_y; + for (unsigned local_xb = 0; local_xb < image->hsample[cn]; ++local_xb, pixel_write_pointer += DCTSIZE) { const struct huffman_table* dc_table = &((*tables)[DC_CLASS][dc_huffman_table[c]]); const struct huffman_table* ac_table = &((*tables)[AC_CLASS][ac_huffman_table[c]]); @@ -195,19 +200,23 @@ 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); - 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) { + uint8_t* dest_pixdata = pixel_write_pointer; + for (unsigned y = 0; y < DCTSIZE; ++y, dest_pixdata += image->stride[cn]) { memcpy(dest_pixdata, pixdata + y * DCTSIZE, DCTSIZE); } } } + image->pixel_write_pointer[cn] += DCTSIZE * image->hsample[cn]; } - + if (++mcu_x == image->num_blocks_horizontal) { ++mcu_y; mcu_x = 0; + + for (unsigned c = 0; c < num_components; ++c) { + unsigned cn = component_num[c]; + image->pixel_write_pointer[cn] += (image->vsample[cn] * DCTSIZE - 1) * image->stride[cn]; + } // Some debug code. const int c = 1; -- 2.39.2