aboutsummaryrefslogtreecommitdiffstats
path: root/src/jpeg.c
diff options
context:
space:
mode:
authorJohn Hawthorn <jhawthor@uvic.ca>2008-05-15 01:07:11 -0700
committerJohn Hawthorn <jhawthor@uvic.ca>2008-05-15 01:07:11 -0700
commit74339219b352723980dcd4d87cafa166a8e27203 (patch)
treef7cf895e3949fba87b840550fa2a44076165abd8 /src/jpeg.c
parenta85e1645a3e44851251548d37c137ff4beadce3b (diff)
downloadmirror-meh-74339219b352723980dcd4d87cafa166a8e27203.tar.gz
mirror-meh-74339219b352723980dcd4d87cafa166a8e27203.tar.bz2
mirror-meh-74339219b352723980dcd4d87cafa166a8e27203.zip
various optimizations
Diffstat (limited to 'src/jpeg.c')
-rw-r--r--src/jpeg.c23
1 files changed, 16 insertions, 7 deletions
diff --git a/src/jpeg.c b/src/jpeg.c
index 6d3b40c..dde41ce 100644
--- a/src/jpeg.c
+++ b/src/jpeg.c
@@ -15,6 +15,7 @@ unsigned char *loadjpeg(char *filename, int *width, int *height){
JSAMPARRAY buffer;
int row_stride;
int i = 0;
+ int j;
int x, y;
unsigned char *retbuf;
@@ -27,23 +28,31 @@ unsigned char *loadjpeg(char *filename, int *width, int *height){
jpeg_create_decompress(&cinfo);
jpeg_stdio_src(&cinfo, infile);
jpeg_read_header(&cinfo, TRUE);
+ cinfo.do_fancy_upsampling = 0;
+ cinfo.do_block_smoothing = 0;
+ cinfo.quantize_colors = 0;
+ cinfo.dct_method = JDCT_IFAST;
jpeg_start_decompress(&cinfo);
*width = cinfo.output_width;
*height = cinfo.output_height;
- retbuf = malloc(cinfo.output_components * (cinfo.output_width * cinfo.output_height));
+ retbuf = malloc(4 * cinfo.output_components * (cinfo.output_width * cinfo.output_height));
if(cinfo.output_components != 3){
fprintf(stderr, "TODO: greyscale images are not supported\n");
exit(1);
}
row_stride = cinfo.output_width * cinfo.output_components;
- buffer = (*cinfo.mem->alloc_sarray)((j_common_ptr) &cinfo, JPOOL_IMAGE, row_stride, 1);
- for(y = 0; y < cinfo.output_height; y++){
- jpeg_read_scanlines(&cinfo, buffer, 1);
- for(x = 0; x < row_stride; x++){
- retbuf[i++] = buffer[0][x];
+ buffer = (*cinfo.mem->alloc_sarray)((j_common_ptr)&cinfo, JPOOL_IMAGE, row_stride, 16);
+ for(y = 0; y < cinfo.output_height; ){
+ int n = jpeg_read_scanlines(&cinfo, buffer, 16);
+ for(j = 0; j < n; j++){
+ for(x = 0; x < row_stride;){
+ retbuf[i++] = buffer[j][x++];
+ retbuf[i++] = buffer[j][x++];
+ retbuf[i++] = buffer[j][x++];
+ }
}
- assert(i % *width == 0);
+ y += n;
}
jpeg_finish_decompress(&cinfo);
jpeg_destroy_decompress(&cinfo);