From ca178369524df9e21a93d647da50d6da6156a85c Mon Sep 17 00:00:00 2001 From: dcommander Date: Wed, 7 Sep 2011 06:31:00 +0000 Subject: Improve performance of non-SIMD color conversion routines and use global constants to define colorspace extension parameters git-svn-id: svn://svn.code.sf.net/p/libjpeg-turbo/code/trunk@698 632fc199-4ca6-4c93-a231-07263d6284db --- jdcolor.c | 216 ++++++++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 153 insertions(+), 63 deletions(-) (limited to 'jdcolor.c') diff --git a/jdcolor.c b/jdcolor.c index 0af024c..d6e5a10 100644 --- a/jdcolor.c +++ b/jdcolor.c @@ -3,7 +3,7 @@ * * Copyright (C) 1991-1997, Thomas G. Lane. * Copyright 2009 Pierre Ossman for Cendio AB - * Copyright (C) 2009, D. R. Commander. + * Copyright (C) 2009, 2011, D. R. Commander. * This file is part of the Independent JPEG Group's software. * For conditions of distribution and use, see the accompanying README file. * @@ -65,6 +65,99 @@ typedef my_color_deconverter * my_cconvert_ptr; #define FIX(x) ((INT32) ((x) * (1L<RGB colorspace conversion. */ @@ -110,13 +203,6 @@ build_ycc_rgb_table (j_decompress_ptr cinfo) /* * Convert some rows of samples to the output colorspace. - * - * Note that we change from noninterleaved, one-plane-per-component format - * to interleaved-pixel format. The output buffer is therefore three times - * as wide as the input buffer. - * A starting row offset is provided only for the input buffer. The caller - * can easily adjust the passed output_buf value to accommodate any row - * offset required on that side. */ METHODDEF(void) @@ -124,42 +210,35 @@ ycc_rgb_convert (j_decompress_ptr cinfo, JSAMPIMAGE input_buf, JDIMENSION input_row, JSAMPARRAY output_buf, int num_rows) { - my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert; - register int y, cb, cr; - register JSAMPROW outptr; - register JSAMPROW inptr0, inptr1, inptr2; - register JDIMENSION col; - JDIMENSION num_cols = cinfo->output_width; - int rindex = rgb_red[cinfo->out_color_space]; - int gindex = rgb_green[cinfo->out_color_space]; - int bindex = rgb_blue[cinfo->out_color_space]; - int rgbstride = rgb_pixelsize[cinfo->out_color_space]; - /* copy these pointers into registers if possible */ - register JSAMPLE * range_limit = cinfo->sample_range_limit; - register int * Crrtab = cconvert->Cr_r_tab; - register int * Cbbtab = cconvert->Cb_b_tab; - register INT32 * Crgtab = cconvert->Cr_g_tab; - register INT32 * Cbgtab = cconvert->Cb_g_tab; - SHIFT_TEMPS - - while (--num_rows >= 0) { - inptr0 = input_buf[0][input_row]; - inptr1 = input_buf[1][input_row]; - inptr2 = input_buf[2][input_row]; - input_row++; - outptr = *output_buf++; - for (col = 0; col < num_cols; col++) { - y = GETJSAMPLE(inptr0[col]); - cb = GETJSAMPLE(inptr1[col]); - cr = GETJSAMPLE(inptr2[col]); - /* Range-limiting is essential due to noise introduced by DCT losses. */ - outptr[rindex] = range_limit[y + Crrtab[cr]]; - outptr[gindex] = range_limit[y + - ((int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], - SCALEBITS))]; - outptr[bindex] = range_limit[y + Cbbtab[cb]]; - outptr += rgbstride; - } + switch (cinfo->out_color_space) { + case JCS_EXT_RGB: + ycc_extrgb_convert_internal(cinfo, input_buf, input_row, output_buf, + num_rows); + break; + case JCS_EXT_RGBX: + ycc_extrgbx_convert_internal(cinfo, input_buf, input_row, output_buf, + num_rows); + break; + case JCS_EXT_BGR: + ycc_extbgr_convert_internal(cinfo, input_buf, input_row, output_buf, + num_rows); + break; + case JCS_EXT_BGRX: + ycc_extbgrx_convert_internal(cinfo, input_buf, input_row, output_buf, + num_rows); + break; + case JCS_EXT_XBGR: + ycc_extxbgr_convert_internal(cinfo, input_buf, input_row, output_buf, + num_rows); + break; + case JCS_EXT_XRGB: + ycc_extxrgb_convert_internal(cinfo, input_buf, input_row, output_buf, + num_rows); + break; + default: + ycc_rgb_convert_internal(cinfo, input_buf, input_row, output_buf, + num_rows); + break; } } @@ -215,9 +294,7 @@ grayscale_convert (j_decompress_ptr cinfo, /* - * Convert grayscale to RGB: just duplicate the graylevel three times. - * This is provided to support applications that don't want to cope - * with grayscale as a separate case. + * Convert grayscale to RGB */ METHODDEF(void) @@ -225,22 +302,35 @@ gray_rgb_convert (j_decompress_ptr cinfo, JSAMPIMAGE input_buf, JDIMENSION input_row, JSAMPARRAY output_buf, int num_rows) { - register JSAMPROW inptr, outptr; - JSAMPLE *maxinptr; - JDIMENSION num_cols = cinfo->output_width; - int rindex = rgb_red[cinfo->out_color_space]; - int gindex = rgb_green[cinfo->out_color_space]; - int bindex = rgb_blue[cinfo->out_color_space]; - int rgbstride = rgb_pixelsize[cinfo->out_color_space]; - - while (--num_rows >= 0) { - inptr = input_buf[0][input_row++]; - maxinptr = &inptr[num_cols]; - outptr = *output_buf++; - for (; inptr < maxinptr; inptr++, outptr += rgbstride) { - /* We can dispense with GETJSAMPLE() here */ - outptr[rindex] = outptr[gindex] = outptr[bindex] = *inptr; - } + switch (cinfo->out_color_space) { + case JCS_EXT_RGB: + gray_extrgb_convert_internal(cinfo, input_buf, input_row, output_buf, + num_rows); + break; + case JCS_EXT_RGBX: + gray_extrgbx_convert_internal(cinfo, input_buf, input_row, output_buf, + num_rows); + break; + case JCS_EXT_BGR: + gray_extbgr_convert_internal(cinfo, input_buf, input_row, output_buf, + num_rows); + break; + case JCS_EXT_BGRX: + gray_extbgrx_convert_internal(cinfo, input_buf, input_row, output_buf, + num_rows); + break; + case JCS_EXT_XBGR: + gray_extxbgr_convert_internal(cinfo, input_buf, input_row, output_buf, + num_rows); + break; + case JCS_EXT_XRGB: + gray_extxrgb_convert_internal(cinfo, input_buf, input_row, output_buf, + num_rows); + break; + default: + gray_rgb_convert_internal(cinfo, input_buf, input_row, output_buf, + num_rows); + break; } } -- cgit v1.2.3