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