From 5a10961e935c152cbbd12df6adf9e5b6ec426248 Mon Sep 17 00:00:00 2001 From: John Hawthorn Date: Mon, 18 May 2009 11:52:25 -0700 Subject: support for rendering jpegs with 4 output components. Thanks to tarpman. --- src/jpeg.c | 23 ++++++++++++++++++++--- 1 file 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); -- cgit v1.2.3