From: DRC Date: Tue, 16 Aug 2011 01:39:05 +0000 (+0000) Subject: Use integer arithmetic for CMYK-to-RGB conversions X-Git-Tag: 1.1.90~30 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a2fdd0c9ab94662903b682eb2dae37abddcedb35;p=libjpeg-turbo Use integer arithmetic for CMYK-to-RGB conversions git-svn-id: svn+ssh://svn.code.sf.net/p/libjpeg-turbo/code/trunk@687 632fc199-4ca6-4c93-a231-07263d6284db --- diff --git a/jdcolor.c b/jdcolor.c index 5d5c377..f8b176e 100644 --- a/jdcolor.c +++ b/jdcolor.c @@ -115,7 +115,7 @@ cmyk_rgb_convert (j_decompress_ptr cinfo, JSAMPIMAGE input_buf, JDIMENSION input_row, JSAMPARRAY output_buf, int num_rows) { - double cyan, magenta, yellow, black; + JSAMPLE cyan, magenta, yellow, black; register JSAMPROW outptr; register JSAMPROW inptr0, inptr1, inptr2, inptr3; register JDIMENSION col; @@ -133,14 +133,14 @@ cmyk_rgb_convert (j_decompress_ptr cinfo, input_row++; outptr = *output_buf++; for (col = 0; col < num_cols; col++) { - cyan = (double) GETJSAMPLE(inptr0[col]); - magenta = (double) GETJSAMPLE(inptr1[col]); - yellow = (double) GETJSAMPLE(inptr2[col]); - black = (double) GETJSAMPLE(inptr3[col]); - - outptr[rindex] = (JSAMPLE)(cyan * black / (double)MAXJSAMPLE); - outptr[gindex] = (JSAMPLE)(magenta * black / (double)MAXJSAMPLE); - outptr[bindex] = (JSAMPLE)(yellow * black / (double)MAXJSAMPLE); + cyan = GETJSAMPLE(inptr0[col]); + magenta = GETJSAMPLE(inptr1[col]); + yellow = GETJSAMPLE(inptr2[col]); + black = GETJSAMPLE(inptr3[col]); + + outptr[rindex] = (JSAMPLE)((int)cyan * (int)black / MAXJSAMPLE); + outptr[gindex] = (JSAMPLE)((int)magenta * (int)black / MAXJSAMPLE); + outptr[bindex] = (JSAMPLE)((int)yellow * (int)black / MAXJSAMPLE); outptr += rgbstride; } } @@ -155,7 +155,7 @@ ycck_rgb_convert (j_decompress_ptr cinfo, JSAMPARRAY output_buf, int num_rows) { my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert; - double cyan, magenta, yellow, black; + JSAMPLE cyan, magenta, yellow, black; register int y, cb, cr; register JSAMPROW outptr; register JSAMPROW inptr0, inptr1, inptr2, inptr3; @@ -187,19 +187,20 @@ ycck_rgb_convert (j_decompress_ptr cinfo, y = GETJSAMPLE(inptr0[col]); cb = GETJSAMPLE(inptr1[col]); cr = GETJSAMPLE(inptr2[col]); - black = (double)GETJSAMPLE(inptr3[col]); + black = GETJSAMPLE(inptr3[col]); /********* Convert YCCK to CMYK **********/ /* Range-limiting is essential due to noise introduced by DCT losses. */ - cyan = (double)range_limit[MAXJSAMPLE - (y + Crrtab[cr])]; - magenta = (double)range_limit[MAXJSAMPLE - - (y + ((int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS)))]; - yellow = (double)range_limit[MAXJSAMPLE - (y + Cbbtab[cb])]; + cyan = range_limit[MAXJSAMPLE - (y + Crrtab[cr])]; + magenta = range_limit[MAXJSAMPLE - (y + + ((int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], + SCALEBITS)))]; + yellow = range_limit[MAXJSAMPLE - (y + Cbbtab[cb])]; /********* Convert CMYK to RGB **********/ - outptr[rindex] = (JSAMPLE)(cyan * black / (double)MAXJSAMPLE); - outptr[gindex] = (JSAMPLE)(magenta * black / (double)MAXJSAMPLE); - outptr[bindex] = (JSAMPLE)(yellow * black / (double)MAXJSAMPLE); + outptr[rindex] = (JSAMPLE)((int)cyan * (int)black / MAXJSAMPLE); + outptr[gindex] = (JSAMPLE)((int)magenta * (int)black / MAXJSAMPLE); + outptr[bindex] = (JSAMPLE)((int)yellow * (int)black / MAXJSAMPLE); outptr += rgbstride; } }