aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Hawthorn <jhawthor@uvic.ca>2009-05-18 11:52:25 -0700
committerJohn Hawthorn <jhawthor@uvic.ca>2009-05-18 11:52:25 -0700
commit5a10961e935c152cbbd12df6adf9e5b6ec426248 (patch)
treea15116961dc5a13f45b7dac84d8b844d1c40c04b
parentc43cbcacad6d4085996f29a6c1701e64eae97b71 (diff)
downloadmirror-meh-5a10961e935c152cbbd12df6adf9e5b6ec426248.tar.gz
mirror-meh-5a10961e935c152cbbd12df6adf9e5b6ec426248.tar.bz2
mirror-meh-5a10961e935c152cbbd12df6adf9e5b6ec426248.zip
support for rendering jpegs with 4 output components. Thanks to tarpman.
-rw-r--r--src/jpeg.c23
1 files changed, 20 insertions, 3 deletions
diff --git a/src/jpeg.c b/src/jpeg.c
index ea8188c..26e60d1 100644
--- a/src/jpeg.c
+++ b/src/jpeg.c
@@ -28,9 +28,9 @@ static void error_exit(j_common_ptr cinfo){
}
static void error_longjmp(j_common_ptr cinfo){
- struct error_mgr *myerr = (struct error_mgr *)cinfo->err;
- (*cinfo->err->output_message)(cinfo);
- longjmp(myerr->jmp_buffer, 1);
+ struct error_mgr *myerr = (struct error_mgr *)cinfo->err;
+ (*cinfo->err->output_message)(cinfo);
+ longjmp(myerr->jmp_buffer, 1);
}
/* TODO progressive */
@@ -115,6 +115,23 @@ static int jpeg_read(struct image *img){
}
y += n;
}
+ }else if(j->cinfo.output_components == 4){
+ JSAMPARRAY buffer = (*j->cinfo.mem->alloc_sarray)((j_common_ptr)&j->cinfo, JPOOL_IMAGE, row_stride, 4);
+ for(y = 0; y < j->cinfo.output_height; ){
+ int n = jpeg_read_scanlines(&j->cinfo, buffer, 4);
+ for(b = 0; b < n; b++){
+ for(x = 0; x < j->cinfo.output_width; x++){
+ int tmp = buffer[b][x*4 + 3];
+ img->buf[a++] = buffer[b][x*4] * tmp / 255;
+ img->buf[a++] = buffer[b][x*4 + 1] * tmp / 255;
+ img->buf[a++] = buffer[b][x*4 + 2] * tmp / 255;
+ }
+ }
+ y += n;
+ }
+ }else{
+ fprintf(stderr, "Unsupported number of output components: %u\n", j->cinfo.output_components);
+ return 1;
}
jpeg_finish_decompress(&j->cinfo);