| Index: jdcolor.c
|
| diff --git a/jdcolor.c b/jdcolor.c
|
| index 2c68ed83b7d7f2eff1f079296f778f1516095058..ab8fa24925e70f330e7394e43833ff7e07f72672 100644
|
| --- a/jdcolor.c
|
| +++ b/jdcolor.c
|
| @@ -6,9 +6,10 @@
|
| * Modified 2011 by Guido Vollbeding.
|
| * libjpeg-turbo Modifications:
|
| * Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
|
| - * Copyright (C) 2009, 2011-2012, 2014, D. R. Commander.
|
| + * Copyright (C) 2009, 2011-2012, 2014-2015, D. R. Commander.
|
| * Copyright (C) 2013, Linaro Limited.
|
| - * For conditions of distribution and use, see the accompanying README file.
|
| + * For conditions of distribution and use, see the accompanying README.ijg
|
| + * file.
|
| *
|
| * This file contains output colorspace conversion routines.
|
| */
|
| @@ -17,7 +18,7 @@
|
| #include "jinclude.h"
|
| #include "jpeglib.h"
|
| #include "jsimd.h"
|
| -#include "config.h"
|
| +#include "jconfigint.h"
|
|
|
|
|
| /* Private subobject */
|
| @@ -26,16 +27,16 @@ typedef struct {
|
| struct jpeg_color_deconverter pub; /* public fields */
|
|
|
| /* Private state for YCC->RGB conversion */
|
| - int * Cr_r_tab; /* => table for Cr to R conversion */
|
| - int * Cb_b_tab; /* => table for Cb to B conversion */
|
| - INT32 * Cr_g_tab; /* => table for Cr to G conversion */
|
| - INT32 * Cb_g_tab; /* => table for Cb to G conversion */
|
| + int *Cr_r_tab; /* => table for Cr to R conversion */
|
| + int *Cb_b_tab; /* => table for Cb to B conversion */
|
| + JLONG *Cr_g_tab; /* => table for Cr to G conversion */
|
| + JLONG *Cb_g_tab; /* => table for Cb to G conversion */
|
|
|
| /* Private state for RGB->Y conversion */
|
| - INT32 * rgb_y_tab; /* => table for RGB to Y conversion */
|
| + JLONG *rgb_y_tab; /* => table for RGB to Y conversion */
|
| } my_color_deconverter;
|
|
|
| -typedef my_color_deconverter * my_cconvert_ptr;
|
| +typedef my_color_deconverter *my_cconvert_ptr;
|
|
|
|
|
| /**************** YCbCr -> RGB conversion: most common case **************/
|
| @@ -46,11 +47,11 @@ typedef my_color_deconverter * my_cconvert_ptr;
|
| * normalized to the range 0..MAXJSAMPLE rather than -0.5 .. 0.5.
|
| * The conversion equations to be implemented are therefore
|
| *
|
| - * R = Y + 1.40200 * Cr
|
| - * G = Y - 0.34414 * Cb - 0.71414 * Cr
|
| - * B = Y + 1.77200 * Cb
|
| + * R = Y + 1.40200 * Cr
|
| + * G = Y - 0.34414 * Cb - 0.71414 * Cr
|
| + * B = Y + 1.77200 * Cb
|
| *
|
| - * Y = 0.29900 * R + 0.58700 * G + 0.11400 * B
|
| + * Y = 0.29900 * R + 0.58700 * G + 0.11400 * B
|
| *
|
| * where Cb and Cr represent the incoming values less CENTERJSAMPLE.
|
| * (These numbers are derived from TIFF 6.0 section 21, dated 3-June-92.)
|
| @@ -72,9 +73,9 @@ typedef my_color_deconverter * my_cconvert_ptr;
|
| * together before rounding.
|
| */
|
|
|
| -#define SCALEBITS 16 /* speediest right-shift on some machines */
|
| -#define ONE_HALF ((INT32) 1 << (SCALEBITS-1))
|
| -#define FIX(x) ((INT32) ((x) * (1L<<SCALEBITS) + 0.5))
|
| +#define SCALEBITS 16 /* speediest right-shift on some machines */
|
| +#define ONE_HALF ((JLONG) 1 << (SCALEBITS-1))
|
| +#define FIX(x) ((JLONG) ((x) * (1L<<SCALEBITS) + 0.5))
|
|
|
| /* We allocate one big table for RGB->Y conversion and divide it up into
|
| * three parts, instead of doing three alloc_small requests. This lets us
|
| @@ -83,10 +84,10 @@ typedef my_color_deconverter * my_cconvert_ptr;
|
| * anyway).
|
| */
|
|
|
| -#define R_Y_OFF 0 /* offset to R => Y section */
|
| -#define G_Y_OFF (1*(MAXJSAMPLE+1)) /* offset to G => Y section */
|
| -#define B_Y_OFF (2*(MAXJSAMPLE+1)) /* etc. */
|
| -#define TABLE_SIZE (3*(MAXJSAMPLE+1))
|
| +#define R_Y_OFF 0 /* offset to R => Y section */
|
| +#define G_Y_OFF (1*(MAXJSAMPLE+1)) /* offset to G => Y section */
|
| +#define B_Y_OFF (2*(MAXJSAMPLE+1)) /* etc. */
|
| +#define TABLE_SIZE (3*(MAXJSAMPLE+1))
|
|
|
|
|
| /* Include inline routines for colorspace extensions */
|
| @@ -211,31 +212,31 @@ build_ycc_rgb_table (j_decompress_ptr cinfo)
|
| {
|
| my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
|
| int i;
|
| - INT32 x;
|
| + JLONG x;
|
| SHIFT_TEMPS
|
|
|
| cconvert->Cr_r_tab = (int *)
|
| (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
| - (MAXJSAMPLE+1) * SIZEOF(int));
|
| + (MAXJSAMPLE+1) * sizeof(int));
|
| cconvert->Cb_b_tab = (int *)
|
| (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
| - (MAXJSAMPLE+1) * SIZEOF(int));
|
| - cconvert->Cr_g_tab = (INT32 *)
|
| + (MAXJSAMPLE+1) * sizeof(int));
|
| + cconvert->Cr_g_tab = (JLONG *)
|
| (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
| - (MAXJSAMPLE+1) * SIZEOF(INT32));
|
| - cconvert->Cb_g_tab = (INT32 *)
|
| + (MAXJSAMPLE+1) * sizeof(JLONG));
|
| + cconvert->Cb_g_tab = (JLONG *)
|
| (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
| - (MAXJSAMPLE+1) * SIZEOF(INT32));
|
| + (MAXJSAMPLE+1) * sizeof(JLONG));
|
|
|
| for (i = 0, x = -CENTERJSAMPLE; i <= MAXJSAMPLE; i++, x++) {
|
| /* i is the actual input pixel value, in the range 0..MAXJSAMPLE */
|
| /* The Cb or Cr value we are thinking of is x = i - CENTERJSAMPLE */
|
| /* Cr=>R value is nearest int to 1.40200 * x */
|
| cconvert->Cr_r_tab[i] = (int)
|
| - RIGHT_SHIFT(FIX(1.40200) * x + ONE_HALF, SCALEBITS);
|
| + RIGHT_SHIFT(FIX(1.40200) * x + ONE_HALF, SCALEBITS);
|
| /* Cb=>B value is nearest int to 1.77200 * x */
|
| cconvert->Cb_b_tab[i] = (int)
|
| - RIGHT_SHIFT(FIX(1.77200) * x + ONE_HALF, SCALEBITS);
|
| + RIGHT_SHIFT(FIX(1.77200) * x + ONE_HALF, SCALEBITS);
|
| /* Cr=>G value is scaled-up -0.71414 * x */
|
| cconvert->Cr_g_tab[i] = (- FIX(0.71414)) * x;
|
| /* Cb=>G value is scaled-up -0.34414 * x */
|
| @@ -251,8 +252,8 @@ build_ycc_rgb_table (j_decompress_ptr cinfo)
|
|
|
| METHODDEF(void)
|
| ycc_rgb_convert (j_decompress_ptr cinfo,
|
| - JSAMPIMAGE input_buf, JDIMENSION input_row,
|
| - JSAMPARRAY output_buf, int num_rows)
|
| + JSAMPIMAGE input_buf, JDIMENSION input_row,
|
| + JSAMPARRAY output_buf, int num_rows)
|
| {
|
| switch (cinfo->out_color_space) {
|
| case JCS_EXT_RGB:
|
| @@ -302,13 +303,13 @@ LOCAL(void)
|
| build_rgb_y_table (j_decompress_ptr cinfo)
|
| {
|
| my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
|
| - INT32 * rgb_y_tab;
|
| - INT32 i;
|
| + JLONG *rgb_y_tab;
|
| + JLONG i;
|
|
|
| /* Allocate and fill in the conversion tables. */
|
| - cconvert->rgb_y_tab = rgb_y_tab = (INT32 *)
|
| + cconvert->rgb_y_tab = rgb_y_tab = (JLONG *)
|
| (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
| - (TABLE_SIZE * SIZEOF(INT32)));
|
| + (TABLE_SIZE * sizeof(JLONG)));
|
|
|
| for (i = 0; i <= MAXJSAMPLE; i++) {
|
| rgb_y_tab[i+R_Y_OFF] = FIX(0.29900) * i;
|
| @@ -324,12 +325,12 @@ build_rgb_y_table (j_decompress_ptr cinfo)
|
|
|
| METHODDEF(void)
|
| rgb_gray_convert (j_decompress_ptr cinfo,
|
| - JSAMPIMAGE input_buf, JDIMENSION input_row,
|
| - JSAMPARRAY output_buf, int num_rows)
|
| + JSAMPIMAGE input_buf, JDIMENSION input_row,
|
| + JSAMPARRAY output_buf, int num_rows)
|
| {
|
| my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
|
| register int r, g, b;
|
| - register INT32 * ctab = cconvert->rgb_y_tab;
|
| + register JLONG *ctab = cconvert->rgb_y_tab;
|
| register JSAMPROW outptr;
|
| register JSAMPROW inptr0, inptr1, inptr2;
|
| register JDIMENSION col;
|
| @@ -347,8 +348,8 @@ rgb_gray_convert (j_decompress_ptr cinfo,
|
| b = GETJSAMPLE(inptr2[col]);
|
| /* Y */
|
| outptr[col] = (JSAMPLE)
|
| - ((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])
|
| - >> SCALEBITS);
|
| + ((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])
|
| + >> SCALEBITS);
|
| }
|
| }
|
| }
|
| @@ -361,26 +362,56 @@ rgb_gray_convert (j_decompress_ptr cinfo,
|
|
|
| METHODDEF(void)
|
| null_convert (j_decompress_ptr cinfo,
|
| - JSAMPIMAGE input_buf, JDIMENSION input_row,
|
| - JSAMPARRAY output_buf, int num_rows)
|
| + JSAMPIMAGE input_buf, JDIMENSION input_row,
|
| + JSAMPARRAY output_buf, int num_rows)
|
| {
|
| - register JSAMPROW inptr, outptr;
|
| - register JDIMENSION count;
|
| + register JSAMPROW inptr, inptr0, inptr1, inptr2, inptr3, outptr;
|
| + register JDIMENSION col;
|
| register int num_components = cinfo->num_components;
|
| JDIMENSION num_cols = cinfo->output_width;
|
| int ci;
|
|
|
| - while (--num_rows >= 0) {
|
| - for (ci = 0; ci < num_components; ci++) {
|
| - inptr = input_buf[ci][input_row];
|
| - outptr = output_buf[0] + ci;
|
| - for (count = num_cols; count > 0; count--) {
|
| - *outptr = *inptr++; /* needn't bother with GETJSAMPLE() here */
|
| - outptr += num_components;
|
| + if (num_components == 3) {
|
| + 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++) {
|
| + *outptr++ = inptr0[col];
|
| + *outptr++ = inptr1[col];
|
| + *outptr++ = inptr2[col];
|
| }
|
| }
|
| - input_row++;
|
| - output_buf++;
|
| + } else if (num_components == 4) {
|
| + while (--num_rows >= 0) {
|
| + inptr0 = input_buf[0][input_row];
|
| + inptr1 = input_buf[1][input_row];
|
| + inptr2 = input_buf[2][input_row];
|
| + inptr3 = input_buf[3][input_row];
|
| + input_row++;
|
| + outptr = *output_buf++;
|
| + for (col = 0; col < num_cols; col++) {
|
| + *outptr++ = inptr0[col];
|
| + *outptr++ = inptr1[col];
|
| + *outptr++ = inptr2[col];
|
| + *outptr++ = inptr3[col];
|
| + }
|
| + }
|
| + } else {
|
| + while (--num_rows >= 0) {
|
| + for (ci = 0; ci < num_components; ci++) {
|
| + inptr = input_buf[ci][input_row];
|
| + outptr = *output_buf;
|
| + for (col = 0; col < num_cols; col++) {
|
| + outptr[ci] = inptr[col];
|
| + outptr += num_components;
|
| + }
|
| + }
|
| + output_buf++;
|
| + input_row++;
|
| + }
|
| }
|
| }
|
|
|
| @@ -393,11 +424,11 @@ null_convert (j_decompress_ptr cinfo,
|
|
|
| METHODDEF(void)
|
| grayscale_convert (j_decompress_ptr cinfo,
|
| - JSAMPIMAGE input_buf, JDIMENSION input_row,
|
| - JSAMPARRAY output_buf, int num_rows)
|
| + JSAMPIMAGE input_buf, JDIMENSION input_row,
|
| + JSAMPARRAY output_buf, int num_rows)
|
| {
|
| jcopy_sample_rows(input_buf[0], (int) input_row, output_buf, 0,
|
| - num_rows, cinfo->output_width);
|
| + num_rows, cinfo->output_width);
|
| }
|
|
|
|
|
| @@ -407,8 +438,8 @@ grayscale_convert (j_decompress_ptr cinfo,
|
|
|
| METHODDEF(void)
|
| gray_rgb_convert (j_decompress_ptr cinfo,
|
| - JSAMPIMAGE input_buf, JDIMENSION input_row,
|
| - JSAMPARRAY output_buf, int num_rows)
|
| + JSAMPIMAGE input_buf, JDIMENSION input_row,
|
| + JSAMPARRAY output_buf, int num_rows)
|
| {
|
| switch (cinfo->out_color_space) {
|
| case JCS_EXT_RGB:
|
| @@ -453,8 +484,8 @@ gray_rgb_convert (j_decompress_ptr cinfo,
|
|
|
| METHODDEF(void)
|
| rgb_rgb_convert (j_decompress_ptr cinfo,
|
| - JSAMPIMAGE input_buf, JDIMENSION input_row,
|
| - JSAMPARRAY output_buf, int num_rows)
|
| + JSAMPIMAGE input_buf, JDIMENSION input_row,
|
| + JSAMPARRAY output_buf, int num_rows)
|
| {
|
| switch (cinfo->out_color_space) {
|
| case JCS_EXT_RGB:
|
| @@ -502,8 +533,8 @@ rgb_rgb_convert (j_decompress_ptr cinfo,
|
|
|
| METHODDEF(void)
|
| ycck_cmyk_convert (j_decompress_ptr cinfo,
|
| - JSAMPIMAGE input_buf, JDIMENSION input_row,
|
| - JSAMPARRAY output_buf, int num_rows)
|
| + 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;
|
| @@ -512,11 +543,11 @@ ycck_cmyk_convert (j_decompress_ptr cinfo,
|
| register JDIMENSION col;
|
| JDIMENSION num_cols = cinfo->output_width;
|
| /* 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;
|
| + register JSAMPLE *range_limit = cinfo->sample_range_limit;
|
| + register int *Crrtab = cconvert->Cr_r_tab;
|
| + register int *Cbbtab = cconvert->Cb_b_tab;
|
| + register JLONG *Crgtab = cconvert->Cr_g_tab;
|
| + register JLONG *Cbgtab = cconvert->Cb_g_tab;
|
| SHIFT_TEMPS
|
|
|
| while (--num_rows >= 0) {
|
| @@ -531,13 +562,13 @@ ycck_cmyk_convert (j_decompress_ptr cinfo,
|
| cb = GETJSAMPLE(inptr1[col]);
|
| cr = GETJSAMPLE(inptr2[col]);
|
| /* Range-limiting is essential due to noise introduced by DCT losses. */
|
| - outptr[0] = range_limit[MAXJSAMPLE - (y + Crrtab[cr])]; /* red */
|
| - outptr[1] = range_limit[MAXJSAMPLE - (y + /* green */
|
| - ((int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
|
| - SCALEBITS)))];
|
| - outptr[2] = range_limit[MAXJSAMPLE - (y + Cbbtab[cb])]; /* blue */
|
| + outptr[0] = range_limit[MAXJSAMPLE - (y + Crrtab[cr])]; /* red */
|
| + outptr[1] = range_limit[MAXJSAMPLE - (y + /* green */
|
| + ((int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
|
| + SCALEBITS)))];
|
| + outptr[2] = range_limit[MAXJSAMPLE - (y + Cbbtab[cb])]; /* blue */
|
| /* K passes through unchanged */
|
| - outptr[3] = inptr3[col]; /* don't need GETJSAMPLE here */
|
| + outptr[3] = inptr3[col]; /* don't need GETJSAMPLE here */
|
| outptr += 4;
|
| }
|
| }
|
| @@ -573,8 +604,8 @@ ycck_cmyk_convert (j_decompress_ptr cinfo,
|
| */
|
|
|
| #define DITHER_MASK 0x3
|
| -#define DITHER_ROTATE(x) (((x) << 24) | (((x) >> 8) & 0x00FFFFFF))
|
| -static const INT32 dither_matrix[4] = {
|
| +#define DITHER_ROTATE(x) ((((x) & 0xFF) << 24) | (((x) >> 8) & 0x00FFFFFF))
|
| +static const JLONG dither_matrix[4] = {
|
| 0x0008020A,
|
| 0x0C040E06,
|
| 0x030B0109,
|
| @@ -725,7 +756,7 @@ jinit_color_deconverter (j_decompress_ptr cinfo)
|
|
|
| cconvert = (my_cconvert_ptr)
|
| (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
| - SIZEOF(my_color_deconverter));
|
| + sizeof(my_color_deconverter));
|
| cinfo->cconvert = (struct jpeg_color_deconverter *) cconvert;
|
| cconvert->pub.start_pass = start_pass_dcolor;
|
|
|
| @@ -748,7 +779,7 @@ jinit_color_deconverter (j_decompress_ptr cinfo)
|
| ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
|
| break;
|
|
|
| - default: /* JCS_UNKNOWN can be anything */
|
| + default: /* JCS_UNKNOWN can be anything */
|
| if (cinfo->num_components < 1)
|
| ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
|
| break;
|
| @@ -763,11 +794,11 @@ jinit_color_deconverter (j_decompress_ptr cinfo)
|
| case JCS_GRAYSCALE:
|
| cinfo->out_color_components = 1;
|
| if (cinfo->jpeg_color_space == JCS_GRAYSCALE ||
|
| - cinfo->jpeg_color_space == JCS_YCbCr) {
|
| + cinfo->jpeg_color_space == JCS_YCbCr) {
|
| cconvert->pub.color_convert = grayscale_convert;
|
| /* For color->grayscale conversion, only the Y (0) component is needed */
|
| for (ci = 1; ci < cinfo->num_components; ci++)
|
| - cinfo->comp_info[ci].component_needed = FALSE;
|
| + cinfo->comp_info[ci].component_needed = FALSE;
|
| } else if (cinfo->jpeg_color_space == JCS_RGB) {
|
| cconvert->pub.color_convert = rgb_gray_convert;
|
| build_rgb_y_table(cinfo);
|
| @@ -812,11 +843,11 @@ jinit_color_deconverter (j_decompress_ptr cinfo)
|
| cinfo->out_color_components = 3;
|
| if (cinfo->dither_mode == JDITHER_NONE) {
|
| if (cinfo->jpeg_color_space == JCS_YCbCr) {
|
| - if (jsimd_can_ycc_rgb565())
|
| - cconvert->pub.color_convert = jsimd_ycc_rgb565_convert;
|
| - else {
|
| - cconvert->pub.color_convert = ycc_rgb565_convert;
|
| - build_ycc_rgb_table(cinfo);
|
| + if (jsimd_can_ycc_rgb565())
|
| + cconvert->pub.color_convert = jsimd_ycc_rgb565_convert;
|
| + else {
|
| + cconvert->pub.color_convert = ycc_rgb565_convert;
|
| + build_ycc_rgb_table(cinfo);
|
| }
|
| } else if (cinfo->jpeg_color_space == JCS_GRAYSCALE) {
|
| cconvert->pub.color_convert = gray_rgb565_convert;
|
| @@ -838,7 +869,7 @@ jinit_color_deconverter (j_decompress_ptr cinfo)
|
| }
|
| break;
|
|
|
| -case JCS_CMYK:
|
| + case JCS_CMYK:
|
| cinfo->out_color_components = 4;
|
| if (cinfo->jpeg_color_space == JCS_YCCK) {
|
| cconvert->pub.color_convert = ycck_cmyk_convert;
|
| @@ -854,7 +885,7 @@ case JCS_CMYK:
|
| if (cinfo->out_color_space == cinfo->jpeg_color_space) {
|
| cinfo->out_color_components = cinfo->num_components;
|
| cconvert->pub.color_convert = null_convert;
|
| - } else /* unsupported non-null conversion */
|
| + } else /* unsupported non-null conversion */
|
| ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
|
| break;
|
| }
|
|
|