Thomas G. Lane | 2cbeb8a | 1991-10-07 00:00:00 +0000 | [diff] [blame] | 1 | /* |
| 2 | * jccolor.c |
| 3 | * |
Thomas G. Lane | 489583f | 1996-02-07 00:00:00 +0000 | [diff] [blame] | 4 | * Copyright (C) 1991-1996, Thomas G. Lane. |
Pierre Ossman | 59a3938 | 2009-03-09 13:15:56 +0000 | [diff] [blame] | 5 | * Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB |
DRC | a9b646c | 2012-03-11 22:06:54 +0000 | [diff] [blame^] | 6 | * Copyright (C) 2009-2012, D. R. Commander. |
Thomas G. Lane | 2cbeb8a | 1991-10-07 00:00:00 +0000 | [diff] [blame] | 7 | * This file is part of the Independent JPEG Group's software. |
| 8 | * For conditions of distribution and use, see the accompanying README file. |
| 9 | * |
| 10 | * This file contains input colorspace conversion routines. |
Thomas G. Lane | 2cbeb8a | 1991-10-07 00:00:00 +0000 | [diff] [blame] | 11 | */ |
| 12 | |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 13 | #define JPEG_INTERNALS |
Thomas G. Lane | 2cbeb8a | 1991-10-07 00:00:00 +0000 | [diff] [blame] | 14 | #include "jinclude.h" |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 15 | #include "jpeglib.h" |
Pierre Ossman | 59a3938 | 2009-03-09 13:15:56 +0000 | [diff] [blame] | 16 | #include "jsimd.h" |
DRC | a7466c9 | 2012-01-26 22:20:31 +0000 | [diff] [blame] | 17 | #include "config.h" |
Thomas G. Lane | 2cbeb8a | 1991-10-07 00:00:00 +0000 | [diff] [blame] | 18 | |
| 19 | |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 20 | /* Private subobject */ |
| 21 | |
| 22 | typedef struct { |
| 23 | struct jpeg_color_converter pub; /* public fields */ |
| 24 | |
| 25 | /* Private state for RGB->YCC conversion */ |
| 26 | INT32 * rgb_ycc_tab; /* => table for RGB to YCbCr conversion */ |
| 27 | } my_color_converter; |
| 28 | |
| 29 | typedef my_color_converter * my_cconvert_ptr; |
Thomas G. Lane | 2cbeb8a | 1991-10-07 00:00:00 +0000 | [diff] [blame] | 30 | |
| 31 | |
Thomas G. Lane | 88aeed4 | 1992-12-10 00:00:00 +0000 | [diff] [blame] | 32 | /**************** RGB -> YCbCr conversion: most common case **************/ |
| 33 | |
| 34 | /* |
| 35 | * YCbCr is defined per CCIR 601-1, except that Cb and Cr are |
| 36 | * normalized to the range 0..MAXJSAMPLE rather than -0.5 .. 0.5. |
| 37 | * The conversion equations to be implemented are therefore |
| 38 | * Y = 0.29900 * R + 0.58700 * G + 0.11400 * B |
Thomas G. Lane | 9ba2f5e | 1994-12-07 00:00:00 +0000 | [diff] [blame] | 39 | * Cb = -0.16874 * R - 0.33126 * G + 0.50000 * B + CENTERJSAMPLE |
| 40 | * Cr = 0.50000 * R - 0.41869 * G - 0.08131 * B + CENTERJSAMPLE |
Thomas G. Lane | 88aeed4 | 1992-12-10 00:00:00 +0000 | [diff] [blame] | 41 | * (These numbers are derived from TIFF 6.0 section 21, dated 3-June-92.) |
Thomas G. Lane | 9ba2f5e | 1994-12-07 00:00:00 +0000 | [diff] [blame] | 42 | * Note: older versions of the IJG code used a zero offset of MAXJSAMPLE/2, |
| 43 | * rather than CENTERJSAMPLE, for Cb and Cr. This gave equal positive and |
| 44 | * negative swings for Cb/Cr, but meant that grayscale values (Cb=Cr=0) |
| 45 | * were not represented exactly. Now we sacrifice exact representation of |
| 46 | * maximum red and maximum blue in order to get exact grayscales. |
Thomas G. Lane | 88aeed4 | 1992-12-10 00:00:00 +0000 | [diff] [blame] | 47 | * |
| 48 | * To avoid floating-point arithmetic, we represent the fractional constants |
| 49 | * as integers scaled up by 2^16 (about 4 digits precision); we have to divide |
| 50 | * the products by 2^16, with appropriate rounding, to get the correct answer. |
| 51 | * |
| 52 | * For even more speed, we avoid doing any multiplications in the inner loop |
| 53 | * by precalculating the constants times R,G,B for all possible values. |
| 54 | * For 8-bit JSAMPLEs this is very reasonable (only 256 entries per table); |
| 55 | * for 12-bit samples it is still acceptable. It's not very reasonable for |
| 56 | * 16-bit samples, but if you want lossless storage you shouldn't be changing |
| 57 | * colorspace anyway. |
Thomas G. Lane | 9ba2f5e | 1994-12-07 00:00:00 +0000 | [diff] [blame] | 58 | * The CENTERJSAMPLE offsets and the rounding fudge-factor of 0.5 are included |
Thomas G. Lane | 88aeed4 | 1992-12-10 00:00:00 +0000 | [diff] [blame] | 59 | * in the tables to save adding them separately in the inner loop. |
| 60 | */ |
| 61 | |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 62 | #define SCALEBITS 16 /* speediest right-shift on some machines */ |
Thomas G. Lane | 9ba2f5e | 1994-12-07 00:00:00 +0000 | [diff] [blame] | 63 | #define CBCR_OFFSET ((INT32) CENTERJSAMPLE << SCALEBITS) |
Thomas G. Lane | 88aeed4 | 1992-12-10 00:00:00 +0000 | [diff] [blame] | 64 | #define ONE_HALF ((INT32) 1 << (SCALEBITS-1)) |
| 65 | #define FIX(x) ((INT32) ((x) * (1L<<SCALEBITS) + 0.5)) |
| 66 | |
| 67 | /* We allocate one big table and divide it up into eight parts, instead of |
| 68 | * doing eight alloc_small requests. This lets us use a single table base |
| 69 | * address, which can be held in a register in the inner loops on many |
| 70 | * machines (more than can hold all eight addresses, anyway). |
| 71 | */ |
| 72 | |
Thomas G. Lane | 88aeed4 | 1992-12-10 00:00:00 +0000 | [diff] [blame] | 73 | #define R_Y_OFF 0 /* offset to R => Y section */ |
| 74 | #define G_Y_OFF (1*(MAXJSAMPLE+1)) /* offset to G => Y section */ |
| 75 | #define B_Y_OFF (2*(MAXJSAMPLE+1)) /* etc. */ |
| 76 | #define R_CB_OFF (3*(MAXJSAMPLE+1)) |
| 77 | #define G_CB_OFF (4*(MAXJSAMPLE+1)) |
| 78 | #define B_CB_OFF (5*(MAXJSAMPLE+1)) |
| 79 | #define R_CR_OFF B_CB_OFF /* B=>Cb, R=>Cr are the same */ |
| 80 | #define G_CR_OFF (6*(MAXJSAMPLE+1)) |
| 81 | #define B_CR_OFF (7*(MAXJSAMPLE+1)) |
| 82 | #define TABLE_SIZE (8*(MAXJSAMPLE+1)) |
| 83 | |
| 84 | |
DRC | b4570bb | 2011-09-07 06:31:00 +0000 | [diff] [blame] | 85 | /* Include inline routines for colorspace extensions */ |
| 86 | |
| 87 | #include "jccolext.c" |
| 88 | #undef RGB_RED |
| 89 | #undef RGB_GREEN |
| 90 | #undef RGB_BLUE |
| 91 | #undef RGB_PIXELSIZE |
| 92 | |
| 93 | #define RGB_RED EXT_RGB_RED |
| 94 | #define RGB_GREEN EXT_RGB_GREEN |
| 95 | #define RGB_BLUE EXT_RGB_BLUE |
| 96 | #define RGB_PIXELSIZE EXT_RGB_PIXELSIZE |
| 97 | #define rgb_ycc_convert_internal extrgb_ycc_convert_internal |
| 98 | #define rgb_gray_convert_internal extrgb_gray_convert_internal |
DRC | a9b646c | 2012-03-11 22:06:54 +0000 | [diff] [blame^] | 99 | #define rgb_rgb_convert_internal extrgb_rgb_convert_internal |
DRC | b4570bb | 2011-09-07 06:31:00 +0000 | [diff] [blame] | 100 | #include "jccolext.c" |
| 101 | #undef RGB_RED |
| 102 | #undef RGB_GREEN |
| 103 | #undef RGB_BLUE |
| 104 | #undef RGB_PIXELSIZE |
| 105 | #undef rgb_ycc_convert_internal |
| 106 | #undef rgb_gray_convert_internal |
DRC | a9b646c | 2012-03-11 22:06:54 +0000 | [diff] [blame^] | 107 | #undef rgb_rgb_convert_internal |
DRC | b4570bb | 2011-09-07 06:31:00 +0000 | [diff] [blame] | 108 | |
| 109 | #define RGB_RED EXT_RGBX_RED |
| 110 | #define RGB_GREEN EXT_RGBX_GREEN |
| 111 | #define RGB_BLUE EXT_RGBX_BLUE |
| 112 | #define RGB_PIXELSIZE EXT_RGBX_PIXELSIZE |
| 113 | #define rgb_ycc_convert_internal extrgbx_ycc_convert_internal |
| 114 | #define rgb_gray_convert_internal extrgbx_gray_convert_internal |
DRC | a9b646c | 2012-03-11 22:06:54 +0000 | [diff] [blame^] | 115 | #define rgb_rgb_convert_internal extrgbx_rgb_convert_internal |
DRC | b4570bb | 2011-09-07 06:31:00 +0000 | [diff] [blame] | 116 | #include "jccolext.c" |
| 117 | #undef RGB_RED |
| 118 | #undef RGB_GREEN |
| 119 | #undef RGB_BLUE |
| 120 | #undef RGB_PIXELSIZE |
| 121 | #undef rgb_ycc_convert_internal |
| 122 | #undef rgb_gray_convert_internal |
DRC | a9b646c | 2012-03-11 22:06:54 +0000 | [diff] [blame^] | 123 | #undef rgb_rgb_convert_internal |
DRC | b4570bb | 2011-09-07 06:31:00 +0000 | [diff] [blame] | 124 | |
| 125 | #define RGB_RED EXT_BGR_RED |
| 126 | #define RGB_GREEN EXT_BGR_GREEN |
| 127 | #define RGB_BLUE EXT_BGR_BLUE |
| 128 | #define RGB_PIXELSIZE EXT_BGR_PIXELSIZE |
| 129 | #define rgb_ycc_convert_internal extbgr_ycc_convert_internal |
| 130 | #define rgb_gray_convert_internal extbgr_gray_convert_internal |
DRC | a9b646c | 2012-03-11 22:06:54 +0000 | [diff] [blame^] | 131 | #define rgb_rgb_convert_internal extbgr_rgb_convert_internal |
DRC | b4570bb | 2011-09-07 06:31:00 +0000 | [diff] [blame] | 132 | #include "jccolext.c" |
| 133 | #undef RGB_RED |
| 134 | #undef RGB_GREEN |
| 135 | #undef RGB_BLUE |
| 136 | #undef RGB_PIXELSIZE |
| 137 | #undef rgb_ycc_convert_internal |
| 138 | #undef rgb_gray_convert_internal |
DRC | a9b646c | 2012-03-11 22:06:54 +0000 | [diff] [blame^] | 139 | #undef rgb_rgb_convert_internal |
DRC | b4570bb | 2011-09-07 06:31:00 +0000 | [diff] [blame] | 140 | |
| 141 | #define RGB_RED EXT_BGRX_RED |
| 142 | #define RGB_GREEN EXT_BGRX_GREEN |
| 143 | #define RGB_BLUE EXT_BGRX_BLUE |
| 144 | #define RGB_PIXELSIZE EXT_BGRX_PIXELSIZE |
| 145 | #define rgb_ycc_convert_internal extbgrx_ycc_convert_internal |
| 146 | #define rgb_gray_convert_internal extbgrx_gray_convert_internal |
DRC | a9b646c | 2012-03-11 22:06:54 +0000 | [diff] [blame^] | 147 | #define rgb_rgb_convert_internal extbgrx_rgb_convert_internal |
DRC | b4570bb | 2011-09-07 06:31:00 +0000 | [diff] [blame] | 148 | #include "jccolext.c" |
| 149 | #undef RGB_RED |
| 150 | #undef RGB_GREEN |
| 151 | #undef RGB_BLUE |
| 152 | #undef RGB_PIXELSIZE |
| 153 | #undef rgb_ycc_convert_internal |
| 154 | #undef rgb_gray_convert_internal |
DRC | a9b646c | 2012-03-11 22:06:54 +0000 | [diff] [blame^] | 155 | #undef rgb_rgb_convert_internal |
DRC | b4570bb | 2011-09-07 06:31:00 +0000 | [diff] [blame] | 156 | |
| 157 | #define RGB_RED EXT_XBGR_RED |
| 158 | #define RGB_GREEN EXT_XBGR_GREEN |
| 159 | #define RGB_BLUE EXT_XBGR_BLUE |
| 160 | #define RGB_PIXELSIZE EXT_XBGR_PIXELSIZE |
| 161 | #define rgb_ycc_convert_internal extxbgr_ycc_convert_internal |
| 162 | #define rgb_gray_convert_internal extxbgr_gray_convert_internal |
DRC | a9b646c | 2012-03-11 22:06:54 +0000 | [diff] [blame^] | 163 | #define rgb_rgb_convert_internal extxbgr_rgb_convert_internal |
DRC | b4570bb | 2011-09-07 06:31:00 +0000 | [diff] [blame] | 164 | #include "jccolext.c" |
| 165 | #undef RGB_RED |
| 166 | #undef RGB_GREEN |
| 167 | #undef RGB_BLUE |
| 168 | #undef RGB_PIXELSIZE |
| 169 | #undef rgb_ycc_convert_internal |
| 170 | #undef rgb_gray_convert_internal |
DRC | a9b646c | 2012-03-11 22:06:54 +0000 | [diff] [blame^] | 171 | #undef rgb_rgb_convert_internal |
DRC | b4570bb | 2011-09-07 06:31:00 +0000 | [diff] [blame] | 172 | |
| 173 | #define RGB_RED EXT_XRGB_RED |
| 174 | #define RGB_GREEN EXT_XRGB_GREEN |
| 175 | #define RGB_BLUE EXT_XRGB_BLUE |
| 176 | #define RGB_PIXELSIZE EXT_XRGB_PIXELSIZE |
| 177 | #define rgb_ycc_convert_internal extxrgb_ycc_convert_internal |
| 178 | #define rgb_gray_convert_internal extxrgb_gray_convert_internal |
DRC | a9b646c | 2012-03-11 22:06:54 +0000 | [diff] [blame^] | 179 | #define rgb_rgb_convert_internal extxrgb_rgb_convert_internal |
DRC | b4570bb | 2011-09-07 06:31:00 +0000 | [diff] [blame] | 180 | #include "jccolext.c" |
| 181 | #undef RGB_RED |
| 182 | #undef RGB_GREEN |
| 183 | #undef RGB_BLUE |
| 184 | #undef RGB_PIXELSIZE |
| 185 | #undef rgb_ycc_convert_internal |
| 186 | #undef rgb_gray_convert_internal |
DRC | a9b646c | 2012-03-11 22:06:54 +0000 | [diff] [blame^] | 187 | #undef rgb_rgb_convert_internal |
DRC | b4570bb | 2011-09-07 06:31:00 +0000 | [diff] [blame] | 188 | |
| 189 | |
Thomas G. Lane | 2cbeb8a | 1991-10-07 00:00:00 +0000 | [diff] [blame] | 190 | /* |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 191 | * Initialize for RGB->YCC colorspace conversion. |
Thomas G. Lane | 2cbeb8a | 1991-10-07 00:00:00 +0000 | [diff] [blame] | 192 | */ |
| 193 | |
Thomas G. Lane | 489583f | 1996-02-07 00:00:00 +0000 | [diff] [blame] | 194 | METHODDEF(void) |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 195 | rgb_ycc_start (j_compress_ptr cinfo) |
Thomas G. Lane | 2cbeb8a | 1991-10-07 00:00:00 +0000 | [diff] [blame] | 196 | { |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 197 | my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert; |
| 198 | INT32 * rgb_ycc_tab; |
Thomas G. Lane | 88aeed4 | 1992-12-10 00:00:00 +0000 | [diff] [blame] | 199 | INT32 i; |
| 200 | |
Thomas G. Lane | 88aeed4 | 1992-12-10 00:00:00 +0000 | [diff] [blame] | 201 | /* Allocate and fill in the conversion tables. */ |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 202 | cconvert->rgb_ycc_tab = rgb_ycc_tab = (INT32 *) |
| 203 | (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, |
| 204 | (TABLE_SIZE * SIZEOF(INT32))); |
Thomas G. Lane | 88aeed4 | 1992-12-10 00:00:00 +0000 | [diff] [blame] | 205 | |
| 206 | for (i = 0; i <= MAXJSAMPLE; i++) { |
| 207 | rgb_ycc_tab[i+R_Y_OFF] = FIX(0.29900) * i; |
| 208 | rgb_ycc_tab[i+G_Y_OFF] = FIX(0.58700) * i; |
| 209 | rgb_ycc_tab[i+B_Y_OFF] = FIX(0.11400) * i + ONE_HALF; |
| 210 | rgb_ycc_tab[i+R_CB_OFF] = (-FIX(0.16874)) * i; |
| 211 | rgb_ycc_tab[i+G_CB_OFF] = (-FIX(0.33126)) * i; |
Thomas G. Lane | 9ba2f5e | 1994-12-07 00:00:00 +0000 | [diff] [blame] | 212 | /* We use a rounding fudge-factor of 0.5-epsilon for Cb and Cr. |
| 213 | * This ensures that the maximum output will round to MAXJSAMPLE |
| 214 | * not MAXJSAMPLE+1, and thus that we don't have to range-limit. |
| 215 | */ |
| 216 | rgb_ycc_tab[i+B_CB_OFF] = FIX(0.50000) * i + CBCR_OFFSET + ONE_HALF-1; |
Thomas G. Lane | 88aeed4 | 1992-12-10 00:00:00 +0000 | [diff] [blame] | 217 | /* B=>Cb and R=>Cr tables are the same |
Thomas G. Lane | 9ba2f5e | 1994-12-07 00:00:00 +0000 | [diff] [blame] | 218 | rgb_ycc_tab[i+R_CR_OFF] = FIX(0.50000) * i + CBCR_OFFSET + ONE_HALF-1; |
Thomas G. Lane | 88aeed4 | 1992-12-10 00:00:00 +0000 | [diff] [blame] | 219 | */ |
| 220 | rgb_ycc_tab[i+G_CR_OFF] = (-FIX(0.41869)) * i; |
| 221 | rgb_ycc_tab[i+B_CR_OFF] = (-FIX(0.08131)) * i; |
| 222 | } |
Thomas G. Lane | 2cbeb8a | 1991-10-07 00:00:00 +0000 | [diff] [blame] | 223 | } |
| 224 | |
| 225 | |
| 226 | /* |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 227 | * Convert some rows of samples to the JPEG colorspace. |
Thomas G. Lane | 4a6b730 | 1992-03-17 00:00:00 +0000 | [diff] [blame] | 228 | */ |
| 229 | |
Thomas G. Lane | 489583f | 1996-02-07 00:00:00 +0000 | [diff] [blame] | 230 | METHODDEF(void) |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 231 | rgb_ycc_convert (j_compress_ptr cinfo, |
| 232 | JSAMPARRAY input_buf, JSAMPIMAGE output_buf, |
| 233 | JDIMENSION output_row, int num_rows) |
Thomas G. Lane | 2cbeb8a | 1991-10-07 00:00:00 +0000 | [diff] [blame] | 234 | { |
DRC | b4570bb | 2011-09-07 06:31:00 +0000 | [diff] [blame] | 235 | switch (cinfo->in_color_space) { |
| 236 | case JCS_EXT_RGB: |
| 237 | extrgb_ycc_convert_internal(cinfo, input_buf, output_buf, output_row, |
| 238 | num_rows); |
| 239 | break; |
| 240 | case JCS_EXT_RGBX: |
DRC | 67ce3b2 | 2011-12-19 02:21:03 +0000 | [diff] [blame] | 241 | case JCS_EXT_RGBA: |
DRC | b4570bb | 2011-09-07 06:31:00 +0000 | [diff] [blame] | 242 | extrgbx_ycc_convert_internal(cinfo, input_buf, output_buf, output_row, |
| 243 | num_rows); |
| 244 | break; |
| 245 | case JCS_EXT_BGR: |
| 246 | extbgr_ycc_convert_internal(cinfo, input_buf, output_buf, output_row, |
| 247 | num_rows); |
| 248 | break; |
| 249 | case JCS_EXT_BGRX: |
DRC | 67ce3b2 | 2011-12-19 02:21:03 +0000 | [diff] [blame] | 250 | case JCS_EXT_BGRA: |
DRC | b4570bb | 2011-09-07 06:31:00 +0000 | [diff] [blame] | 251 | extbgrx_ycc_convert_internal(cinfo, input_buf, output_buf, output_row, |
| 252 | num_rows); |
| 253 | break; |
| 254 | case JCS_EXT_XBGR: |
DRC | 67ce3b2 | 2011-12-19 02:21:03 +0000 | [diff] [blame] | 255 | case JCS_EXT_ABGR: |
DRC | b4570bb | 2011-09-07 06:31:00 +0000 | [diff] [blame] | 256 | extxbgr_ycc_convert_internal(cinfo, input_buf, output_buf, output_row, |
| 257 | num_rows); |
| 258 | break; |
| 259 | case JCS_EXT_XRGB: |
DRC | 67ce3b2 | 2011-12-19 02:21:03 +0000 | [diff] [blame] | 260 | case JCS_EXT_ARGB: |
DRC | b4570bb | 2011-09-07 06:31:00 +0000 | [diff] [blame] | 261 | extxrgb_ycc_convert_internal(cinfo, input_buf, output_buf, output_row, |
| 262 | num_rows); |
| 263 | break; |
| 264 | default: |
| 265 | rgb_ycc_convert_internal(cinfo, input_buf, output_buf, output_row, |
| 266 | num_rows); |
| 267 | break; |
Thomas G. Lane | 88aeed4 | 1992-12-10 00:00:00 +0000 | [diff] [blame] | 268 | } |
| 269 | } |
| 270 | |
| 271 | |
| 272 | /**************** Cases other than RGB -> YCbCr **************/ |
| 273 | |
| 274 | |
| 275 | /* |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 276 | * Convert some rows of samples to the JPEG colorspace. |
Thomas G. Lane | 88aeed4 | 1992-12-10 00:00:00 +0000 | [diff] [blame] | 277 | */ |
| 278 | |
Thomas G. Lane | 489583f | 1996-02-07 00:00:00 +0000 | [diff] [blame] | 279 | METHODDEF(void) |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 280 | rgb_gray_convert (j_compress_ptr cinfo, |
| 281 | JSAMPARRAY input_buf, JSAMPIMAGE output_buf, |
| 282 | JDIMENSION output_row, int num_rows) |
Thomas G. Lane | 88aeed4 | 1992-12-10 00:00:00 +0000 | [diff] [blame] | 283 | { |
DRC | b4570bb | 2011-09-07 06:31:00 +0000 | [diff] [blame] | 284 | switch (cinfo->in_color_space) { |
| 285 | case JCS_EXT_RGB: |
| 286 | extrgb_gray_convert_internal(cinfo, input_buf, output_buf, output_row, |
| 287 | num_rows); |
| 288 | break; |
| 289 | case JCS_EXT_RGBX: |
DRC | 67ce3b2 | 2011-12-19 02:21:03 +0000 | [diff] [blame] | 290 | case JCS_EXT_RGBA: |
DRC | b4570bb | 2011-09-07 06:31:00 +0000 | [diff] [blame] | 291 | extrgbx_gray_convert_internal(cinfo, input_buf, output_buf, output_row, |
| 292 | num_rows); |
| 293 | break; |
| 294 | case JCS_EXT_BGR: |
| 295 | extbgr_gray_convert_internal(cinfo, input_buf, output_buf, output_row, |
| 296 | num_rows); |
| 297 | break; |
| 298 | case JCS_EXT_BGRX: |
DRC | 67ce3b2 | 2011-12-19 02:21:03 +0000 | [diff] [blame] | 299 | case JCS_EXT_BGRA: |
DRC | b4570bb | 2011-09-07 06:31:00 +0000 | [diff] [blame] | 300 | extbgrx_gray_convert_internal(cinfo, input_buf, output_buf, output_row, |
| 301 | num_rows); |
| 302 | break; |
| 303 | case JCS_EXT_XBGR: |
DRC | 67ce3b2 | 2011-12-19 02:21:03 +0000 | [diff] [blame] | 304 | case JCS_EXT_ABGR: |
DRC | b4570bb | 2011-09-07 06:31:00 +0000 | [diff] [blame] | 305 | extxbgr_gray_convert_internal(cinfo, input_buf, output_buf, output_row, |
| 306 | num_rows); |
| 307 | break; |
| 308 | case JCS_EXT_XRGB: |
DRC | 67ce3b2 | 2011-12-19 02:21:03 +0000 | [diff] [blame] | 309 | case JCS_EXT_ARGB: |
DRC | b4570bb | 2011-09-07 06:31:00 +0000 | [diff] [blame] | 310 | extxrgb_gray_convert_internal(cinfo, input_buf, output_buf, output_row, |
| 311 | num_rows); |
| 312 | break; |
| 313 | default: |
| 314 | rgb_gray_convert_internal(cinfo, input_buf, output_buf, output_row, |
| 315 | num_rows); |
| 316 | break; |
Thomas G. Lane | 2cbeb8a | 1991-10-07 00:00:00 +0000 | [diff] [blame] | 317 | } |
| 318 | } |
| 319 | |
| 320 | |
| 321 | /* |
DRC | a9b646c | 2012-03-11 22:06:54 +0000 | [diff] [blame^] | 322 | * Extended RGB to plain RGB conversion |
| 323 | */ |
| 324 | |
| 325 | METHODDEF(void) |
| 326 | rgb_rgb_convert (j_compress_ptr cinfo, |
| 327 | JSAMPARRAY input_buf, JSAMPIMAGE output_buf, |
| 328 | JDIMENSION output_row, int num_rows) |
| 329 | { |
| 330 | switch (cinfo->in_color_space) { |
| 331 | case JCS_EXT_RGB: |
| 332 | extrgb_rgb_convert_internal(cinfo, input_buf, output_buf, output_row, |
| 333 | num_rows); |
| 334 | break; |
| 335 | case JCS_EXT_RGBX: |
| 336 | case JCS_EXT_RGBA: |
| 337 | extrgbx_rgb_convert_internal(cinfo, input_buf, output_buf, output_row, |
| 338 | num_rows); |
| 339 | break; |
| 340 | case JCS_EXT_BGR: |
| 341 | extbgr_rgb_convert_internal(cinfo, input_buf, output_buf, output_row, |
| 342 | num_rows); |
| 343 | break; |
| 344 | case JCS_EXT_BGRX: |
| 345 | case JCS_EXT_BGRA: |
| 346 | extbgrx_rgb_convert_internal(cinfo, input_buf, output_buf, output_row, |
| 347 | num_rows); |
| 348 | break; |
| 349 | case JCS_EXT_XBGR: |
| 350 | case JCS_EXT_ABGR: |
| 351 | extxbgr_rgb_convert_internal(cinfo, input_buf, output_buf, output_row, |
| 352 | num_rows); |
| 353 | break; |
| 354 | case JCS_EXT_XRGB: |
| 355 | case JCS_EXT_ARGB: |
| 356 | extxrgb_rgb_convert_internal(cinfo, input_buf, output_buf, output_row, |
| 357 | num_rows); |
| 358 | break; |
| 359 | default: |
| 360 | rgb_rgb_convert_internal(cinfo, input_buf, output_buf, output_row, |
| 361 | num_rows); |
| 362 | break; |
| 363 | } |
| 364 | } |
| 365 | |
| 366 | |
| 367 | /* |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 368 | * Convert some rows of samples to the JPEG colorspace. |
| 369 | * This version handles Adobe-style CMYK->YCCK conversion, |
| 370 | * where we convert R=1-C, G=1-M, and B=1-Y to YCbCr using the same |
| 371 | * conversion as above, while passing K (black) unchanged. |
| 372 | * We assume rgb_ycc_start has been called. |
Thomas G. Lane | 88aeed4 | 1992-12-10 00:00:00 +0000 | [diff] [blame] | 373 | */ |
| 374 | |
Thomas G. Lane | 489583f | 1996-02-07 00:00:00 +0000 | [diff] [blame] | 375 | METHODDEF(void) |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 376 | cmyk_ycck_convert (j_compress_ptr cinfo, |
| 377 | JSAMPARRAY input_buf, JSAMPIMAGE output_buf, |
| 378 | JDIMENSION output_row, int num_rows) |
Thomas G. Lane | 88aeed4 | 1992-12-10 00:00:00 +0000 | [diff] [blame] | 379 | { |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 380 | my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert; |
| 381 | register int r, g, b; |
| 382 | register INT32 * ctab = cconvert->rgb_ycc_tab; |
| 383 | register JSAMPROW inptr; |
| 384 | register JSAMPROW outptr0, outptr1, outptr2, outptr3; |
| 385 | register JDIMENSION col; |
| 386 | JDIMENSION num_cols = cinfo->image_width; |
Thomas G. Lane | 88aeed4 | 1992-12-10 00:00:00 +0000 | [diff] [blame] | 387 | |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 388 | while (--num_rows >= 0) { |
| 389 | inptr = *input_buf++; |
| 390 | outptr0 = output_buf[0][output_row]; |
| 391 | outptr1 = output_buf[1][output_row]; |
| 392 | outptr2 = output_buf[2][output_row]; |
| 393 | outptr3 = output_buf[3][output_row]; |
| 394 | output_row++; |
| 395 | for (col = 0; col < num_cols; col++) { |
| 396 | r = MAXJSAMPLE - GETJSAMPLE(inptr[0]); |
| 397 | g = MAXJSAMPLE - GETJSAMPLE(inptr[1]); |
| 398 | b = MAXJSAMPLE - GETJSAMPLE(inptr[2]); |
| 399 | /* K passes through as-is */ |
| 400 | outptr3[col] = inptr[3]; /* don't need GETJSAMPLE here */ |
| 401 | inptr += 4; |
| 402 | /* If the inputs are 0..MAXJSAMPLE, the outputs of these equations |
| 403 | * must be too; we do not need an explicit range-limiting operation. |
| 404 | * Hence the value being shifted is never negative, and we don't |
| 405 | * need the general RIGHT_SHIFT macro. |
| 406 | */ |
| 407 | /* Y */ |
| 408 | outptr0[col] = (JSAMPLE) |
| 409 | ((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF]) |
| 410 | >> SCALEBITS); |
| 411 | /* Cb */ |
| 412 | outptr1[col] = (JSAMPLE) |
| 413 | ((ctab[r+R_CB_OFF] + ctab[g+G_CB_OFF] + ctab[b+B_CB_OFF]) |
| 414 | >> SCALEBITS); |
| 415 | /* Cr */ |
| 416 | outptr2[col] = (JSAMPLE) |
| 417 | ((ctab[r+R_CR_OFF] + ctab[g+G_CR_OFF] + ctab[b+B_CR_OFF]) |
| 418 | >> SCALEBITS); |
Thomas G. Lane | 2cbeb8a | 1991-10-07 00:00:00 +0000 | [diff] [blame] | 419 | } |
| 420 | } |
| 421 | } |
| 422 | |
| 423 | |
| 424 | /* |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 425 | * Convert some rows of samples to the JPEG colorspace. |
| 426 | * This version handles grayscale output with no conversion. |
| 427 | * The source can be either plain grayscale or YCbCr (since Y == gray). |
Thomas G. Lane | 2cbeb8a | 1991-10-07 00:00:00 +0000 | [diff] [blame] | 428 | */ |
| 429 | |
Thomas G. Lane | 489583f | 1996-02-07 00:00:00 +0000 | [diff] [blame] | 430 | METHODDEF(void) |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 431 | grayscale_convert (j_compress_ptr cinfo, |
| 432 | JSAMPARRAY input_buf, JSAMPIMAGE output_buf, |
| 433 | JDIMENSION output_row, int num_rows) |
Thomas G. Lane | 2cbeb8a | 1991-10-07 00:00:00 +0000 | [diff] [blame] | 434 | { |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 435 | register JSAMPROW inptr; |
| 436 | register JSAMPROW outptr; |
| 437 | register JDIMENSION col; |
| 438 | JDIMENSION num_cols = cinfo->image_width; |
| 439 | int instride = cinfo->input_components; |
| 440 | |
| 441 | while (--num_rows >= 0) { |
| 442 | inptr = *input_buf++; |
| 443 | outptr = output_buf[0][output_row]; |
| 444 | output_row++; |
| 445 | for (col = 0; col < num_cols; col++) { |
| 446 | outptr[col] = inptr[0]; /* don't need GETJSAMPLE() here */ |
| 447 | inptr += instride; |
| 448 | } |
| 449 | } |
Thomas G. Lane | 2cbeb8a | 1991-10-07 00:00:00 +0000 | [diff] [blame] | 450 | } |
| 451 | |
| 452 | |
| 453 | /* |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 454 | * Convert some rows of samples to the JPEG colorspace. |
| 455 | * This version handles multi-component colorspaces without conversion. |
| 456 | * We assume input_components == num_components. |
| 457 | */ |
| 458 | |
Thomas G. Lane | 489583f | 1996-02-07 00:00:00 +0000 | [diff] [blame] | 459 | METHODDEF(void) |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 460 | null_convert (j_compress_ptr cinfo, |
| 461 | JSAMPARRAY input_buf, JSAMPIMAGE output_buf, |
| 462 | JDIMENSION output_row, int num_rows) |
| 463 | { |
| 464 | register JSAMPROW inptr; |
| 465 | register JSAMPROW outptr; |
| 466 | register JDIMENSION col; |
| 467 | register int ci; |
| 468 | int nc = cinfo->num_components; |
| 469 | JDIMENSION num_cols = cinfo->image_width; |
| 470 | |
| 471 | while (--num_rows >= 0) { |
| 472 | /* It seems fastest to make a separate pass for each component. */ |
| 473 | for (ci = 0; ci < nc; ci++) { |
| 474 | inptr = *input_buf; |
| 475 | outptr = output_buf[ci][output_row]; |
| 476 | for (col = 0; col < num_cols; col++) { |
| 477 | outptr[col] = inptr[ci]; /* don't need GETJSAMPLE() here */ |
| 478 | inptr += nc; |
| 479 | } |
| 480 | } |
| 481 | input_buf++; |
| 482 | output_row++; |
| 483 | } |
| 484 | } |
| 485 | |
| 486 | |
| 487 | /* |
| 488 | * Empty method for start_pass. |
| 489 | */ |
| 490 | |
Thomas G. Lane | 489583f | 1996-02-07 00:00:00 +0000 | [diff] [blame] | 491 | METHODDEF(void) |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 492 | null_method (j_compress_ptr cinfo) |
| 493 | { |
| 494 | /* no work needed */ |
| 495 | } |
| 496 | |
| 497 | |
| 498 | /* |
| 499 | * Module initialization routine for input colorspace conversion. |
Thomas G. Lane | 2cbeb8a | 1991-10-07 00:00:00 +0000 | [diff] [blame] | 500 | */ |
| 501 | |
Thomas G. Lane | 489583f | 1996-02-07 00:00:00 +0000 | [diff] [blame] | 502 | GLOBAL(void) |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 503 | jinit_color_converter (j_compress_ptr cinfo) |
Thomas G. Lane | 2cbeb8a | 1991-10-07 00:00:00 +0000 | [diff] [blame] | 504 | { |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 505 | my_cconvert_ptr cconvert; |
| 506 | |
| 507 | cconvert = (my_cconvert_ptr) |
| 508 | (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, |
| 509 | SIZEOF(my_color_converter)); |
| 510 | cinfo->cconvert = (struct jpeg_color_converter *) cconvert; |
| 511 | /* set start_pass to null method until we find out differently */ |
| 512 | cconvert->pub.start_pass = null_method; |
| 513 | |
Thomas G. Lane | 2cbeb8a | 1991-10-07 00:00:00 +0000 | [diff] [blame] | 514 | /* Make sure input_components agrees with in_color_space */ |
| 515 | switch (cinfo->in_color_space) { |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 516 | case JCS_GRAYSCALE: |
Thomas G. Lane | 2cbeb8a | 1991-10-07 00:00:00 +0000 | [diff] [blame] | 517 | if (cinfo->input_components != 1) |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 518 | ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); |
Thomas G. Lane | 2cbeb8a | 1991-10-07 00:00:00 +0000 | [diff] [blame] | 519 | break; |
| 520 | |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 521 | case JCS_RGB: |
DRC | f25c071 | 2009-04-03 12:00:51 +0000 | [diff] [blame] | 522 | case JCS_EXT_RGB: |
| 523 | case JCS_EXT_RGBX: |
| 524 | case JCS_EXT_BGR: |
| 525 | case JCS_EXT_BGRX: |
| 526 | case JCS_EXT_XBGR: |
| 527 | case JCS_EXT_XRGB: |
DRC | 67ce3b2 | 2011-12-19 02:21:03 +0000 | [diff] [blame] | 528 | case JCS_EXT_RGBA: |
| 529 | case JCS_EXT_BGRA: |
| 530 | case JCS_EXT_ABGR: |
| 531 | case JCS_EXT_ARGB: |
DRC | f25c071 | 2009-04-03 12:00:51 +0000 | [diff] [blame] | 532 | if (cinfo->input_components != rgb_pixelsize[cinfo->in_color_space]) |
| 533 | ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); |
| 534 | break; |
| 535 | |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 536 | case JCS_YCbCr: |
Thomas G. Lane | 2cbeb8a | 1991-10-07 00:00:00 +0000 | [diff] [blame] | 537 | if (cinfo->input_components != 3) |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 538 | ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); |
Thomas G. Lane | 2cbeb8a | 1991-10-07 00:00:00 +0000 | [diff] [blame] | 539 | break; |
| 540 | |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 541 | case JCS_CMYK: |
| 542 | case JCS_YCCK: |
Thomas G. Lane | 2cbeb8a | 1991-10-07 00:00:00 +0000 | [diff] [blame] | 543 | if (cinfo->input_components != 4) |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 544 | ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); |
Thomas G. Lane | 2cbeb8a | 1991-10-07 00:00:00 +0000 | [diff] [blame] | 545 | break; |
| 546 | |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 547 | default: /* JCS_UNKNOWN can be anything */ |
| 548 | if (cinfo->input_components < 1) |
| 549 | ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); |
Thomas G. Lane | 2cbeb8a | 1991-10-07 00:00:00 +0000 | [diff] [blame] | 550 | break; |
| 551 | } |
| 552 | |
| 553 | /* Check num_components, set conversion method based on requested space */ |
| 554 | switch (cinfo->jpeg_color_space) { |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 555 | case JCS_GRAYSCALE: |
Thomas G. Lane | 2cbeb8a | 1991-10-07 00:00:00 +0000 | [diff] [blame] | 556 | if (cinfo->num_components != 1) |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 557 | ERREXIT(cinfo, JERR_BAD_J_COLORSPACE); |
| 558 | if (cinfo->in_color_space == JCS_GRAYSCALE) |
| 559 | cconvert->pub.color_convert = grayscale_convert; |
DRC | f25c071 | 2009-04-03 12:00:51 +0000 | [diff] [blame] | 560 | else if (cinfo->in_color_space == JCS_RGB || |
| 561 | cinfo->in_color_space == JCS_EXT_RGB || |
| 562 | cinfo->in_color_space == JCS_EXT_RGBX || |
| 563 | cinfo->in_color_space == JCS_EXT_BGR || |
| 564 | cinfo->in_color_space == JCS_EXT_BGRX || |
| 565 | cinfo->in_color_space == JCS_EXT_XBGR || |
DRC | 67ce3b2 | 2011-12-19 02:21:03 +0000 | [diff] [blame] | 566 | cinfo->in_color_space == JCS_EXT_XRGB || |
| 567 | cinfo->in_color_space == JCS_EXT_RGBA || |
| 568 | cinfo->in_color_space == JCS_EXT_BGRA || |
| 569 | cinfo->in_color_space == JCS_EXT_ABGR || |
| 570 | cinfo->in_color_space == JCS_EXT_ARGB) { |
DRC | c866633 | 2011-02-18 11:23:45 +0000 | [diff] [blame] | 571 | if (jsimd_can_rgb_gray()) |
| 572 | cconvert->pub.color_convert = jsimd_rgb_gray_convert; |
| 573 | else { |
| 574 | cconvert->pub.start_pass = rgb_ycc_start; |
| 575 | cconvert->pub.color_convert = rgb_gray_convert; |
| 576 | } |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 577 | } else if (cinfo->in_color_space == JCS_YCbCr) |
| 578 | cconvert->pub.color_convert = grayscale_convert; |
Thomas G. Lane | 2cbeb8a | 1991-10-07 00:00:00 +0000 | [diff] [blame] | 579 | else |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 580 | ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL); |
Thomas G. Lane | 2cbeb8a | 1991-10-07 00:00:00 +0000 | [diff] [blame] | 581 | break; |
| 582 | |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 583 | case JCS_RGB: |
Thomas G. Lane | 2cbeb8a | 1991-10-07 00:00:00 +0000 | [diff] [blame] | 584 | if (cinfo->num_components != 3) |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 585 | ERREXIT(cinfo, JERR_BAD_J_COLORSPACE); |
DRC | a9b646c | 2012-03-11 22:06:54 +0000 | [diff] [blame^] | 586 | if (rgb_red[cinfo->in_color_space] == 0 && |
| 587 | rgb_green[cinfo->in_color_space] == 1 && |
| 588 | rgb_blue[cinfo->in_color_space] == 2 && |
| 589 | rgb_pixelsize[cinfo->in_color_space] == 3) |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 590 | cconvert->pub.color_convert = null_convert; |
DRC | a9b646c | 2012-03-11 22:06:54 +0000 | [diff] [blame^] | 591 | else if (cinfo->in_color_space == JCS_RGB || |
| 592 | cinfo->in_color_space == JCS_EXT_RGB || |
| 593 | cinfo->in_color_space == JCS_EXT_RGBX || |
| 594 | cinfo->in_color_space == JCS_EXT_BGR || |
| 595 | cinfo->in_color_space == JCS_EXT_BGRX || |
| 596 | cinfo->in_color_space == JCS_EXT_XBGR || |
| 597 | cinfo->in_color_space == JCS_EXT_XRGB || |
| 598 | cinfo->in_color_space == JCS_EXT_RGBA || |
| 599 | cinfo->in_color_space == JCS_EXT_BGRA || |
| 600 | cinfo->in_color_space == JCS_EXT_ABGR || |
| 601 | cinfo->in_color_space == JCS_EXT_ARGB) |
| 602 | cconvert->pub.color_convert = rgb_rgb_convert; |
Thomas G. Lane | 2cbeb8a | 1991-10-07 00:00:00 +0000 | [diff] [blame] | 603 | else |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 604 | ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL); |
Thomas G. Lane | 2cbeb8a | 1991-10-07 00:00:00 +0000 | [diff] [blame] | 605 | break; |
| 606 | |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 607 | case JCS_YCbCr: |
| 608 | if (cinfo->num_components != 3) |
| 609 | ERREXIT(cinfo, JERR_BAD_J_COLORSPACE); |
DRC | f25c071 | 2009-04-03 12:00:51 +0000 | [diff] [blame] | 610 | if (cinfo->in_color_space == JCS_RGB || |
| 611 | cinfo->in_color_space == JCS_EXT_RGB || |
| 612 | cinfo->in_color_space == JCS_EXT_RGBX || |
| 613 | cinfo->in_color_space == JCS_EXT_BGR || |
| 614 | cinfo->in_color_space == JCS_EXT_BGRX || |
| 615 | cinfo->in_color_space == JCS_EXT_XBGR || |
DRC | 67ce3b2 | 2011-12-19 02:21:03 +0000 | [diff] [blame] | 616 | cinfo->in_color_space == JCS_EXT_XRGB || |
| 617 | cinfo->in_color_space == JCS_EXT_RGBA || |
| 618 | cinfo->in_color_space == JCS_EXT_BGRA || |
| 619 | cinfo->in_color_space == JCS_EXT_ABGR || |
| 620 | cinfo->in_color_space == JCS_EXT_ARGB) { |
Pierre Ossman | 59a3938 | 2009-03-09 13:15:56 +0000 | [diff] [blame] | 621 | if (jsimd_can_rgb_ycc()) |
| 622 | cconvert->pub.color_convert = jsimd_rgb_ycc_convert; |
| 623 | else { |
| 624 | cconvert->pub.start_pass = rgb_ycc_start; |
| 625 | cconvert->pub.color_convert = rgb_ycc_convert; |
| 626 | } |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 627 | } else if (cinfo->in_color_space == JCS_YCbCr) |
| 628 | cconvert->pub.color_convert = null_convert; |
| 629 | else |
| 630 | ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL); |
| 631 | break; |
| 632 | |
| 633 | case JCS_CMYK: |
Thomas G. Lane | 2cbeb8a | 1991-10-07 00:00:00 +0000 | [diff] [blame] | 634 | if (cinfo->num_components != 4) |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 635 | ERREXIT(cinfo, JERR_BAD_J_COLORSPACE); |
| 636 | if (cinfo->in_color_space == JCS_CMYK) |
| 637 | cconvert->pub.color_convert = null_convert; |
Thomas G. Lane | 2cbeb8a | 1991-10-07 00:00:00 +0000 | [diff] [blame] | 638 | else |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 639 | ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL); |
Thomas G. Lane | 2cbeb8a | 1991-10-07 00:00:00 +0000 | [diff] [blame] | 640 | break; |
| 641 | |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 642 | case JCS_YCCK: |
| 643 | if (cinfo->num_components != 4) |
| 644 | ERREXIT(cinfo, JERR_BAD_J_COLORSPACE); |
| 645 | if (cinfo->in_color_space == JCS_CMYK) { |
| 646 | cconvert->pub.start_pass = rgb_ycc_start; |
| 647 | cconvert->pub.color_convert = cmyk_ycck_convert; |
| 648 | } else if (cinfo->in_color_space == JCS_YCCK) |
| 649 | cconvert->pub.color_convert = null_convert; |
| 650 | else |
| 651 | ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL); |
| 652 | break; |
| 653 | |
| 654 | default: /* allow null conversion of JCS_UNKNOWN */ |
| 655 | if (cinfo->jpeg_color_space != cinfo->in_color_space || |
| 656 | cinfo->num_components != cinfo->input_components) |
| 657 | ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL); |
| 658 | cconvert->pub.color_convert = null_convert; |
Thomas G. Lane | 2cbeb8a | 1991-10-07 00:00:00 +0000 | [diff] [blame] | 659 | break; |
| 660 | } |
Thomas G. Lane | 2cbeb8a | 1991-10-07 00:00:00 +0000 | [diff] [blame] | 661 | } |