aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/irrlicht-1.8/source/Irrlicht/jpeglib/jccolor.c
diff options
context:
space:
mode:
authorDavid Walter Seikel2013-01-13 18:54:10 +1000
committerDavid Walter Seikel2013-01-13 18:54:10 +1000
commit959831f4ef5a3e797f576c3de08cd65032c997ad (patch)
treee7351908be5995f0b325b2ebeaa02d5a34b82583 /libraries/irrlicht-1.8/source/Irrlicht/jpeglib/jccolor.c
parentAdd info about changes to Irrlicht. (diff)
downloadSledjHamr-959831f4ef5a3e797f576c3de08cd65032c997ad.zip
SledjHamr-959831f4ef5a3e797f576c3de08cd65032c997ad.tar.gz
SledjHamr-959831f4ef5a3e797f576c3de08cd65032c997ad.tar.bz2
SledjHamr-959831f4ef5a3e797f576c3de08cd65032c997ad.tar.xz
Remove damned ancient DOS line endings from Irrlicht. Hopefully I did not go overboard.
Diffstat (limited to 'libraries/irrlicht-1.8/source/Irrlicht/jpeglib/jccolor.c')
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/jpeglib/jccolor.c980
1 files changed, 490 insertions, 490 deletions
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/jpeglib/jccolor.c b/libraries/irrlicht-1.8/source/Irrlicht/jpeglib/jccolor.c
index 12d35f4..3e2d0e9 100644
--- a/libraries/irrlicht-1.8/source/Irrlicht/jpeglib/jccolor.c
+++ b/libraries/irrlicht-1.8/source/Irrlicht/jpeglib/jccolor.c
@@ -1,490 +1,490 @@
1/* 1/*
2 * jccolor.c 2 * jccolor.c
3 * 3 *
4 * Copyright (C) 1991-1996, Thomas G. Lane. 4 * Copyright (C) 1991-1996, Thomas G. Lane.
5 * Modified 2011 by Guido Vollbeding. 5 * Modified 2011 by Guido Vollbeding.
6 * This file is part of the Independent JPEG Group's software. 6 * This file is part of the Independent JPEG Group's software.
7 * For conditions of distribution and use, see the accompanying README file. 7 * For conditions of distribution and use, see the accompanying README file.
8 * 8 *
9 * This file contains input colorspace conversion routines. 9 * This file contains input colorspace conversion routines.
10 */ 10 */
11 11
12#define JPEG_INTERNALS 12#define JPEG_INTERNALS
13#include "jinclude.h" 13#include "jinclude.h"
14#include "jpeglib.h" 14#include "jpeglib.h"
15 15
16 16
17/* Private subobject */ 17/* Private subobject */
18 18
19typedef struct { 19typedef struct {
20 struct jpeg_color_converter pub; /* public fields */ 20 struct jpeg_color_converter pub; /* public fields */
21 21
22 /* Private state for RGB->YCC conversion */ 22 /* Private state for RGB->YCC conversion */
23 INT32 * rgb_ycc_tab; /* => table for RGB to YCbCr conversion */ 23 INT32 * rgb_ycc_tab; /* => table for RGB to YCbCr conversion */
24} my_color_converter; 24} my_color_converter;
25 25
26typedef my_color_converter * my_cconvert_ptr; 26typedef my_color_converter * my_cconvert_ptr;
27 27
28 28
29/**************** RGB -> YCbCr conversion: most common case **************/ 29/**************** RGB -> YCbCr conversion: most common case **************/
30 30
31/* 31/*
32 * YCbCr is defined per CCIR 601-1, except that Cb and Cr are 32 * YCbCr is defined per CCIR 601-1, except that Cb and Cr are
33 * normalized to the range 0..MAXJSAMPLE rather than -0.5 .. 0.5. 33 * normalized to the range 0..MAXJSAMPLE rather than -0.5 .. 0.5.
34 * The conversion equations to be implemented are therefore 34 * The conversion equations to be implemented are therefore
35 * Y = 0.29900 * R + 0.58700 * G + 0.11400 * B 35 * Y = 0.29900 * R + 0.58700 * G + 0.11400 * B
36 * Cb = -0.16874 * R - 0.33126 * G + 0.50000 * B + CENTERJSAMPLE 36 * Cb = -0.16874 * R - 0.33126 * G + 0.50000 * B + CENTERJSAMPLE
37 * Cr = 0.50000 * R - 0.41869 * G - 0.08131 * B + CENTERJSAMPLE 37 * Cr = 0.50000 * R - 0.41869 * G - 0.08131 * B + CENTERJSAMPLE
38 * (These numbers are derived from TIFF 6.0 section 21, dated 3-June-92.) 38 * (These numbers are derived from TIFF 6.0 section 21, dated 3-June-92.)
39 * Note: older versions of the IJG code used a zero offset of MAXJSAMPLE/2, 39 * Note: older versions of the IJG code used a zero offset of MAXJSAMPLE/2,
40 * rather than CENTERJSAMPLE, for Cb and Cr. This gave equal positive and 40 * rather than CENTERJSAMPLE, for Cb and Cr. This gave equal positive and
41 * negative swings for Cb/Cr, but meant that grayscale values (Cb=Cr=0) 41 * negative swings for Cb/Cr, but meant that grayscale values (Cb=Cr=0)
42 * were not represented exactly. Now we sacrifice exact representation of 42 * were not represented exactly. Now we sacrifice exact representation of
43 * maximum red and maximum blue in order to get exact grayscales. 43 * maximum red and maximum blue in order to get exact grayscales.
44 * 44 *
45 * To avoid floating-point arithmetic, we represent the fractional constants 45 * To avoid floating-point arithmetic, we represent the fractional constants
46 * as integers scaled up by 2^16 (about 4 digits precision); we have to divide 46 * as integers scaled up by 2^16 (about 4 digits precision); we have to divide
47 * the products by 2^16, with appropriate rounding, to get the correct answer. 47 * the products by 2^16, with appropriate rounding, to get the correct answer.
48 * 48 *
49 * For even more speed, we avoid doing any multiplications in the inner loop 49 * For even more speed, we avoid doing any multiplications in the inner loop
50 * by precalculating the constants times R,G,B for all possible values. 50 * by precalculating the constants times R,G,B for all possible values.
51 * For 8-bit JSAMPLEs this is very reasonable (only 256 entries per table); 51 * For 8-bit JSAMPLEs this is very reasonable (only 256 entries per table);
52 * for 12-bit samples it is still acceptable. It's not very reasonable for 52 * for 12-bit samples it is still acceptable. It's not very reasonable for
53 * 16-bit samples, but if you want lossless storage you shouldn't be changing 53 * 16-bit samples, but if you want lossless storage you shouldn't be changing
54 * colorspace anyway. 54 * colorspace anyway.
55 * The CENTERJSAMPLE offsets and the rounding fudge-factor of 0.5 are included 55 * The CENTERJSAMPLE offsets and the rounding fudge-factor of 0.5 are included
56 * in the tables to save adding them separately in the inner loop. 56 * in the tables to save adding them separately in the inner loop.
57 */ 57 */
58 58
59#define SCALEBITS 16 /* speediest right-shift on some machines */ 59#define SCALEBITS 16 /* speediest right-shift on some machines */
60#define CBCR_OFFSET ((INT32) CENTERJSAMPLE << SCALEBITS) 60#define CBCR_OFFSET ((INT32) CENTERJSAMPLE << SCALEBITS)
61#define ONE_HALF ((INT32) 1 << (SCALEBITS-1)) 61#define ONE_HALF ((INT32) 1 << (SCALEBITS-1))
62#define FIX(x) ((INT32) ((x) * (1L<<SCALEBITS) + 0.5)) 62#define FIX(x) ((INT32) ((x) * (1L<<SCALEBITS) + 0.5))
63 63
64/* We allocate one big table and divide it up into eight parts, instead of 64/* We allocate one big table and divide it up into eight parts, instead of
65 * doing eight alloc_small requests. This lets us use a single table base 65 * doing eight alloc_small requests. This lets us use a single table base
66 * address, which can be held in a register in the inner loops on many 66 * address, which can be held in a register in the inner loops on many
67 * machines (more than can hold all eight addresses, anyway). 67 * machines (more than can hold all eight addresses, anyway).
68 */ 68 */
69 69
70#define R_Y_OFF 0 /* offset to R => Y section */ 70#define R_Y_OFF 0 /* offset to R => Y section */
71#define G_Y_OFF (1*(MAXJSAMPLE+1)) /* offset to G => Y section */ 71#define G_Y_OFF (1*(MAXJSAMPLE+1)) /* offset to G => Y section */
72#define B_Y_OFF (2*(MAXJSAMPLE+1)) /* etc. */ 72#define B_Y_OFF (2*(MAXJSAMPLE+1)) /* etc. */
73#define R_CB_OFF (3*(MAXJSAMPLE+1)) 73#define R_CB_OFF (3*(MAXJSAMPLE+1))
74#define G_CB_OFF (4*(MAXJSAMPLE+1)) 74#define G_CB_OFF (4*(MAXJSAMPLE+1))
75#define B_CB_OFF (5*(MAXJSAMPLE+1)) 75#define B_CB_OFF (5*(MAXJSAMPLE+1))
76#define R_CR_OFF B_CB_OFF /* B=>Cb, R=>Cr are the same */ 76#define R_CR_OFF B_CB_OFF /* B=>Cb, R=>Cr are the same */
77#define G_CR_OFF (6*(MAXJSAMPLE+1)) 77#define G_CR_OFF (6*(MAXJSAMPLE+1))
78#define B_CR_OFF (7*(MAXJSAMPLE+1)) 78#define B_CR_OFF (7*(MAXJSAMPLE+1))
79#define TABLE_SIZE (8*(MAXJSAMPLE+1)) 79#define TABLE_SIZE (8*(MAXJSAMPLE+1))
80 80
81 81
82/* 82/*
83 * Initialize for RGB->YCC colorspace conversion. 83 * Initialize for RGB->YCC colorspace conversion.
84 */ 84 */
85 85
86METHODDEF(void) 86METHODDEF(void)
87rgb_ycc_start (j_compress_ptr cinfo) 87rgb_ycc_start (j_compress_ptr cinfo)
88{ 88{
89 my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert; 89 my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
90 INT32 * rgb_ycc_tab; 90 INT32 * rgb_ycc_tab;
91 INT32 i; 91 INT32 i;
92 92
93 /* Allocate and fill in the conversion tables. */ 93 /* Allocate and fill in the conversion tables. */
94 cconvert->rgb_ycc_tab = rgb_ycc_tab = (INT32 *) 94 cconvert->rgb_ycc_tab = rgb_ycc_tab = (INT32 *)
95 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, 95 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
96 (TABLE_SIZE * SIZEOF(INT32))); 96 (TABLE_SIZE * SIZEOF(INT32)));
97 97
98 for (i = 0; i <= MAXJSAMPLE; i++) { 98 for (i = 0; i <= MAXJSAMPLE; i++) {
99 rgb_ycc_tab[i+R_Y_OFF] = FIX(0.29900) * i; 99 rgb_ycc_tab[i+R_Y_OFF] = FIX(0.29900) * i;
100 rgb_ycc_tab[i+G_Y_OFF] = FIX(0.58700) * i; 100 rgb_ycc_tab[i+G_Y_OFF] = FIX(0.58700) * i;
101 rgb_ycc_tab[i+B_Y_OFF] = FIX(0.11400) * i + ONE_HALF; 101 rgb_ycc_tab[i+B_Y_OFF] = FIX(0.11400) * i + ONE_HALF;
102 rgb_ycc_tab[i+R_CB_OFF] = (-FIX(0.16874)) * i; 102 rgb_ycc_tab[i+R_CB_OFF] = (-FIX(0.16874)) * i;
103 rgb_ycc_tab[i+G_CB_OFF] = (-FIX(0.33126)) * i; 103 rgb_ycc_tab[i+G_CB_OFF] = (-FIX(0.33126)) * i;
104 /* We use a rounding fudge-factor of 0.5-epsilon for Cb and Cr. 104 /* We use a rounding fudge-factor of 0.5-epsilon for Cb and Cr.
105 * This ensures that the maximum output will round to MAXJSAMPLE 105 * This ensures that the maximum output will round to MAXJSAMPLE
106 * not MAXJSAMPLE+1, and thus that we don't have to range-limit. 106 * not MAXJSAMPLE+1, and thus that we don't have to range-limit.
107 */ 107 */
108 rgb_ycc_tab[i+B_CB_OFF] = FIX(0.50000) * i + CBCR_OFFSET + ONE_HALF-1; 108 rgb_ycc_tab[i+B_CB_OFF] = FIX(0.50000) * i + CBCR_OFFSET + ONE_HALF-1;
109/* B=>Cb and R=>Cr tables are the same 109/* B=>Cb and R=>Cr tables are the same
110 rgb_ycc_tab[i+R_CR_OFF] = FIX(0.50000) * i + CBCR_OFFSET + ONE_HALF-1; 110 rgb_ycc_tab[i+R_CR_OFF] = FIX(0.50000) * i + CBCR_OFFSET + ONE_HALF-1;
111*/ 111*/
112 rgb_ycc_tab[i+G_CR_OFF] = (-FIX(0.41869)) * i; 112 rgb_ycc_tab[i+G_CR_OFF] = (-FIX(0.41869)) * i;
113 rgb_ycc_tab[i+B_CR_OFF] = (-FIX(0.08131)) * i; 113 rgb_ycc_tab[i+B_CR_OFF] = (-FIX(0.08131)) * i;
114 } 114 }
115} 115}
116 116
117 117
118/* 118/*
119 * Convert some rows of samples to the JPEG colorspace. 119 * Convert some rows of samples to the JPEG colorspace.
120 * 120 *
121 * Note that we change from the application's interleaved-pixel format 121 * Note that we change from the application's interleaved-pixel format
122 * to our internal noninterleaved, one-plane-per-component format. 122 * to our internal noninterleaved, one-plane-per-component format.
123 * The input buffer is therefore three times as wide as the output buffer. 123 * The input buffer is therefore three times as wide as the output buffer.
124 * 124 *
125 * A starting row offset is provided only for the output buffer. The caller 125 * A starting row offset is provided only for the output buffer. The caller
126 * can easily adjust the passed input_buf value to accommodate any row 126 * can easily adjust the passed input_buf value to accommodate any row
127 * offset required on that side. 127 * offset required on that side.
128 */ 128 */
129 129
130METHODDEF(void) 130METHODDEF(void)
131rgb_ycc_convert (j_compress_ptr cinfo, 131rgb_ycc_convert (j_compress_ptr cinfo,
132 JSAMPARRAY input_buf, JSAMPIMAGE output_buf, 132 JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
133 JDIMENSION output_row, int num_rows) 133 JDIMENSION output_row, int num_rows)
134{ 134{
135 my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert; 135 my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
136 register int r, g, b; 136 register int r, g, b;
137 register INT32 * ctab = cconvert->rgb_ycc_tab; 137 register INT32 * ctab = cconvert->rgb_ycc_tab;
138 register JSAMPROW inptr; 138 register JSAMPROW inptr;
139 register JSAMPROW outptr0, outptr1, outptr2; 139 register JSAMPROW outptr0, outptr1, outptr2;
140 register JDIMENSION col; 140 register JDIMENSION col;
141 JDIMENSION num_cols = cinfo->image_width; 141 JDIMENSION num_cols = cinfo->image_width;
142 142
143 while (--num_rows >= 0) { 143 while (--num_rows >= 0) {
144 inptr = *input_buf++; 144 inptr = *input_buf++;
145 outptr0 = output_buf[0][output_row]; 145 outptr0 = output_buf[0][output_row];
146 outptr1 = output_buf[1][output_row]; 146 outptr1 = output_buf[1][output_row];
147 outptr2 = output_buf[2][output_row]; 147 outptr2 = output_buf[2][output_row];
148 output_row++; 148 output_row++;
149 for (col = 0; col < num_cols; col++) { 149 for (col = 0; col < num_cols; col++) {
150 r = GETJSAMPLE(inptr[RGB_RED]); 150 r = GETJSAMPLE(inptr[RGB_RED]);
151 g = GETJSAMPLE(inptr[RGB_GREEN]); 151 g = GETJSAMPLE(inptr[RGB_GREEN]);
152 b = GETJSAMPLE(inptr[RGB_BLUE]); 152 b = GETJSAMPLE(inptr[RGB_BLUE]);
153 inptr += RGB_PIXELSIZE; 153 inptr += RGB_PIXELSIZE;
154 /* If the inputs are 0..MAXJSAMPLE, the outputs of these equations 154 /* If the inputs are 0..MAXJSAMPLE, the outputs of these equations
155 * must be too; we do not need an explicit range-limiting operation. 155 * must be too; we do not need an explicit range-limiting operation.
156 * Hence the value being shifted is never negative, and we don't 156 * Hence the value being shifted is never negative, and we don't
157 * need the general RIGHT_SHIFT macro. 157 * need the general RIGHT_SHIFT macro.
158 */ 158 */
159 /* Y */ 159 /* Y */
160 outptr0[col] = (JSAMPLE) 160 outptr0[col] = (JSAMPLE)
161 ((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF]) 161 ((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])
162 >> SCALEBITS); 162 >> SCALEBITS);
163 /* Cb */ 163 /* Cb */
164 outptr1[col] = (JSAMPLE) 164 outptr1[col] = (JSAMPLE)
165 ((ctab[r+R_CB_OFF] + ctab[g+G_CB_OFF] + ctab[b+B_CB_OFF]) 165 ((ctab[r+R_CB_OFF] + ctab[g+G_CB_OFF] + ctab[b+B_CB_OFF])
166 >> SCALEBITS); 166 >> SCALEBITS);
167 /* Cr */ 167 /* Cr */
168 outptr2[col] = (JSAMPLE) 168 outptr2[col] = (JSAMPLE)
169 ((ctab[r+R_CR_OFF] + ctab[g+G_CR_OFF] + ctab[b+B_CR_OFF]) 169 ((ctab[r+R_CR_OFF] + ctab[g+G_CR_OFF] + ctab[b+B_CR_OFF])
170 >> SCALEBITS); 170 >> SCALEBITS);
171 } 171 }
172 } 172 }
173} 173}
174 174
175 175
176/**************** Cases other than RGB -> YCbCr **************/ 176/**************** Cases other than RGB -> YCbCr **************/
177 177
178 178
179/* 179/*
180 * Convert some rows of samples to the JPEG colorspace. 180 * Convert some rows of samples to the JPEG colorspace.
181 * This version handles RGB->grayscale conversion, which is the same 181 * This version handles RGB->grayscale conversion, which is the same
182 * as the RGB->Y portion of RGB->YCbCr. 182 * as the RGB->Y portion of RGB->YCbCr.
183 * We assume rgb_ycc_start has been called (we only use the Y tables). 183 * We assume rgb_ycc_start has been called (we only use the Y tables).
184 */ 184 */
185 185
186METHODDEF(void) 186METHODDEF(void)
187rgb_gray_convert (j_compress_ptr cinfo, 187rgb_gray_convert (j_compress_ptr cinfo,
188 JSAMPARRAY input_buf, JSAMPIMAGE output_buf, 188 JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
189 JDIMENSION output_row, int num_rows) 189 JDIMENSION output_row, int num_rows)
190{ 190{
191 my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert; 191 my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
192 register int r, g, b; 192 register int r, g, b;
193 register INT32 * ctab = cconvert->rgb_ycc_tab; 193 register INT32 * ctab = cconvert->rgb_ycc_tab;
194 register JSAMPROW inptr; 194 register JSAMPROW inptr;
195 register JSAMPROW outptr; 195 register JSAMPROW outptr;
196 register JDIMENSION col; 196 register JDIMENSION col;
197 JDIMENSION num_cols = cinfo->image_width; 197 JDIMENSION num_cols = cinfo->image_width;
198 198
199 while (--num_rows >= 0) { 199 while (--num_rows >= 0) {
200 inptr = *input_buf++; 200 inptr = *input_buf++;
201 outptr = output_buf[0][output_row]; 201 outptr = output_buf[0][output_row];
202 output_row++; 202 output_row++;
203 for (col = 0; col < num_cols; col++) { 203 for (col = 0; col < num_cols; col++) {
204 r = GETJSAMPLE(inptr[RGB_RED]); 204 r = GETJSAMPLE(inptr[RGB_RED]);
205 g = GETJSAMPLE(inptr[RGB_GREEN]); 205 g = GETJSAMPLE(inptr[RGB_GREEN]);
206 b = GETJSAMPLE(inptr[RGB_BLUE]); 206 b = GETJSAMPLE(inptr[RGB_BLUE]);
207 inptr += RGB_PIXELSIZE; 207 inptr += RGB_PIXELSIZE;
208 /* Y */ 208 /* Y */
209 outptr[col] = (JSAMPLE) 209 outptr[col] = (JSAMPLE)
210 ((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF]) 210 ((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])
211 >> SCALEBITS); 211 >> SCALEBITS);
212 } 212 }
213 } 213 }
214} 214}
215 215
216 216
217/* 217/*
218 * Convert some rows of samples to the JPEG colorspace. 218 * Convert some rows of samples to the JPEG colorspace.
219 * This version handles Adobe-style CMYK->YCCK conversion, 219 * This version handles Adobe-style CMYK->YCCK conversion,
220 * where we convert R=1-C, G=1-M, and B=1-Y to YCbCr using the same 220 * where we convert R=1-C, G=1-M, and B=1-Y to YCbCr using the same
221 * conversion as above, while passing K (black) unchanged. 221 * conversion as above, while passing K (black) unchanged.
222 * We assume rgb_ycc_start has been called. 222 * We assume rgb_ycc_start has been called.
223 */ 223 */
224 224
225METHODDEF(void) 225METHODDEF(void)
226cmyk_ycck_convert (j_compress_ptr cinfo, 226cmyk_ycck_convert (j_compress_ptr cinfo,
227 JSAMPARRAY input_buf, JSAMPIMAGE output_buf, 227 JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
228 JDIMENSION output_row, int num_rows) 228 JDIMENSION output_row, int num_rows)
229{ 229{
230 my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert; 230 my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
231 register int r, g, b; 231 register int r, g, b;
232 register INT32 * ctab = cconvert->rgb_ycc_tab; 232 register INT32 * ctab = cconvert->rgb_ycc_tab;
233 register JSAMPROW inptr; 233 register JSAMPROW inptr;
234 register JSAMPROW outptr0, outptr1, outptr2, outptr3; 234 register JSAMPROW outptr0, outptr1, outptr2, outptr3;
235 register JDIMENSION col; 235 register JDIMENSION col;
236 JDIMENSION num_cols = cinfo->image_width; 236 JDIMENSION num_cols = cinfo->image_width;
237 237
238 while (--num_rows >= 0) { 238 while (--num_rows >= 0) {
239 inptr = *input_buf++; 239 inptr = *input_buf++;
240 outptr0 = output_buf[0][output_row]; 240 outptr0 = output_buf[0][output_row];
241 outptr1 = output_buf[1][output_row]; 241 outptr1 = output_buf[1][output_row];
242 outptr2 = output_buf[2][output_row]; 242 outptr2 = output_buf[2][output_row];
243 outptr3 = output_buf[3][output_row]; 243 outptr3 = output_buf[3][output_row];
244 output_row++; 244 output_row++;
245 for (col = 0; col < num_cols; col++) { 245 for (col = 0; col < num_cols; col++) {
246 r = MAXJSAMPLE - GETJSAMPLE(inptr[0]); 246 r = MAXJSAMPLE - GETJSAMPLE(inptr[0]);
247 g = MAXJSAMPLE - GETJSAMPLE(inptr[1]); 247 g = MAXJSAMPLE - GETJSAMPLE(inptr[1]);
248 b = MAXJSAMPLE - GETJSAMPLE(inptr[2]); 248 b = MAXJSAMPLE - GETJSAMPLE(inptr[2]);
249 /* K passes through as-is */ 249 /* K passes through as-is */
250 outptr3[col] = inptr[3]; /* don't need GETJSAMPLE here */ 250 outptr3[col] = inptr[3]; /* don't need GETJSAMPLE here */
251 inptr += 4; 251 inptr += 4;
252 /* If the inputs are 0..MAXJSAMPLE, the outputs of these equations 252 /* If the inputs are 0..MAXJSAMPLE, the outputs of these equations
253 * must be too; we do not need an explicit range-limiting operation. 253 * must be too; we do not need an explicit range-limiting operation.
254 * Hence the value being shifted is never negative, and we don't 254 * Hence the value being shifted is never negative, and we don't
255 * need the general RIGHT_SHIFT macro. 255 * need the general RIGHT_SHIFT macro.
256 */ 256 */
257 /* Y */ 257 /* Y */
258 outptr0[col] = (JSAMPLE) 258 outptr0[col] = (JSAMPLE)
259 ((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF]) 259 ((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])
260 >> SCALEBITS); 260 >> SCALEBITS);
261 /* Cb */ 261 /* Cb */
262 outptr1[col] = (JSAMPLE) 262 outptr1[col] = (JSAMPLE)
263 ((ctab[r+R_CB_OFF] + ctab[g+G_CB_OFF] + ctab[b+B_CB_OFF]) 263 ((ctab[r+R_CB_OFF] + ctab[g+G_CB_OFF] + ctab[b+B_CB_OFF])
264 >> SCALEBITS); 264 >> SCALEBITS);
265 /* Cr */ 265 /* Cr */
266 outptr2[col] = (JSAMPLE) 266 outptr2[col] = (JSAMPLE)
267 ((ctab[r+R_CR_OFF] + ctab[g+G_CR_OFF] + ctab[b+B_CR_OFF]) 267 ((ctab[r+R_CR_OFF] + ctab[g+G_CR_OFF] + ctab[b+B_CR_OFF])
268 >> SCALEBITS); 268 >> SCALEBITS);
269 } 269 }
270 } 270 }
271} 271}
272 272
273 273
274/* 274/*
275 * Convert some rows of samples to the JPEG colorspace. 275 * Convert some rows of samples to the JPEG colorspace.
276 * This version handles grayscale output with no conversion. 276 * This version handles grayscale output with no conversion.
277 * The source can be either plain grayscale or YCbCr (since Y == gray). 277 * The source can be either plain grayscale or YCbCr (since Y == gray).
278 */ 278 */
279 279
280METHODDEF(void) 280METHODDEF(void)
281grayscale_convert (j_compress_ptr cinfo, 281grayscale_convert (j_compress_ptr cinfo,
282 JSAMPARRAY input_buf, JSAMPIMAGE output_buf, 282 JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
283 JDIMENSION output_row, int num_rows) 283 JDIMENSION output_row, int num_rows)
284{ 284{
285 register JSAMPROW inptr; 285 register JSAMPROW inptr;
286 register JSAMPROW outptr; 286 register JSAMPROW outptr;
287 register JDIMENSION col; 287 register JDIMENSION col;
288 JDIMENSION num_cols = cinfo->image_width; 288 JDIMENSION num_cols = cinfo->image_width;
289 int instride = cinfo->input_components; 289 int instride = cinfo->input_components;
290 290
291 while (--num_rows >= 0) { 291 while (--num_rows >= 0) {
292 inptr = *input_buf++; 292 inptr = *input_buf++;
293 outptr = output_buf[0][output_row]; 293 outptr = output_buf[0][output_row];
294 output_row++; 294 output_row++;
295 for (col = 0; col < num_cols; col++) { 295 for (col = 0; col < num_cols; col++) {
296 outptr[col] = inptr[0]; /* don't need GETJSAMPLE() here */ 296 outptr[col] = inptr[0]; /* don't need GETJSAMPLE() here */
297 inptr += instride; 297 inptr += instride;
298 } 298 }
299 } 299 }
300} 300}
301 301
302 302
303/* 303/*
304 * Convert some rows of samples to the JPEG colorspace. 304 * Convert some rows of samples to the JPEG colorspace.
305 * No colorspace conversion, but change from interleaved 305 * No colorspace conversion, but change from interleaved
306 * to separate-planes representation. 306 * to separate-planes representation.
307 */ 307 */
308 308
309METHODDEF(void) 309METHODDEF(void)
310rgb_convert (j_compress_ptr cinfo, 310rgb_convert (j_compress_ptr cinfo,
311 JSAMPARRAY input_buf, JSAMPIMAGE output_buf, 311 JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
312 JDIMENSION output_row, int num_rows) 312 JDIMENSION output_row, int num_rows)
313{ 313{
314 register JSAMPROW inptr; 314 register JSAMPROW inptr;
315 register JSAMPROW outptr0, outptr1, outptr2; 315 register JSAMPROW outptr0, outptr1, outptr2;
316 register JDIMENSION col; 316 register JDIMENSION col;
317 JDIMENSION num_cols = cinfo->image_width; 317 JDIMENSION num_cols = cinfo->image_width;
318 318
319 while (--num_rows >= 0) { 319 while (--num_rows >= 0) {
320 inptr = *input_buf++; 320 inptr = *input_buf++;
321 outptr0 = output_buf[0][output_row]; 321 outptr0 = output_buf[0][output_row];
322 outptr1 = output_buf[1][output_row]; 322 outptr1 = output_buf[1][output_row];
323 outptr2 = output_buf[2][output_row]; 323 outptr2 = output_buf[2][output_row];
324 output_row++; 324 output_row++;
325 for (col = 0; col < num_cols; col++) { 325 for (col = 0; col < num_cols; col++) {
326 /* We can dispense with GETJSAMPLE() here */ 326 /* We can dispense with GETJSAMPLE() here */
327 outptr0[col] = inptr[RGB_RED]; 327 outptr0[col] = inptr[RGB_RED];
328 outptr1[col] = inptr[RGB_GREEN]; 328 outptr1[col] = inptr[RGB_GREEN];
329 outptr2[col] = inptr[RGB_BLUE]; 329 outptr2[col] = inptr[RGB_BLUE];
330 inptr += RGB_PIXELSIZE; 330 inptr += RGB_PIXELSIZE;
331 } 331 }
332 } 332 }
333} 333}
334 334
335 335
336/* 336/*
337 * Convert some rows of samples to the JPEG colorspace. 337 * Convert some rows of samples to the JPEG colorspace.
338 * This version handles multi-component colorspaces without conversion. 338 * This version handles multi-component colorspaces without conversion.
339 * We assume input_components == num_components. 339 * We assume input_components == num_components.
340 */ 340 */
341 341
342METHODDEF(void) 342METHODDEF(void)
343null_convert (j_compress_ptr cinfo, 343null_convert (j_compress_ptr cinfo,
344 JSAMPARRAY input_buf, JSAMPIMAGE output_buf, 344 JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
345 JDIMENSION output_row, int num_rows) 345 JDIMENSION output_row, int num_rows)
346{ 346{
347 register JSAMPROW inptr; 347 register JSAMPROW inptr;
348 register JSAMPROW outptr; 348 register JSAMPROW outptr;
349 register JDIMENSION col; 349 register JDIMENSION col;
350 register int ci; 350 register int ci;
351 int nc = cinfo->num_components; 351 int nc = cinfo->num_components;
352 JDIMENSION num_cols = cinfo->image_width; 352 JDIMENSION num_cols = cinfo->image_width;
353 353
354 while (--num_rows >= 0) { 354 while (--num_rows >= 0) {
355 /* It seems fastest to make a separate pass for each component. */ 355 /* It seems fastest to make a separate pass for each component. */
356 for (ci = 0; ci < nc; ci++) { 356 for (ci = 0; ci < nc; ci++) {
357 inptr = *input_buf; 357 inptr = *input_buf;
358 outptr = output_buf[ci][output_row]; 358 outptr = output_buf[ci][output_row];
359 for (col = 0; col < num_cols; col++) { 359 for (col = 0; col < num_cols; col++) {
360 outptr[col] = inptr[ci]; /* don't need GETJSAMPLE() here */ 360 outptr[col] = inptr[ci]; /* don't need GETJSAMPLE() here */
361 inptr += nc; 361 inptr += nc;
362 } 362 }
363 } 363 }
364 input_buf++; 364 input_buf++;
365 output_row++; 365 output_row++;
366 } 366 }
367} 367}
368 368
369 369
370/* 370/*
371 * Empty method for start_pass. 371 * Empty method for start_pass.
372 */ 372 */
373 373
374METHODDEF(void) 374METHODDEF(void)
375null_method (j_compress_ptr cinfo) 375null_method (j_compress_ptr cinfo)
376{ 376{
377 /* no work needed */ 377 /* no work needed */
378} 378}
379 379
380 380
381/* 381/*
382 * Module initialization routine for input colorspace conversion. 382 * Module initialization routine for input colorspace conversion.
383 */ 383 */
384 384
385GLOBAL(void) 385GLOBAL(void)
386jinit_color_converter (j_compress_ptr cinfo) 386jinit_color_converter (j_compress_ptr cinfo)
387{ 387{
388 my_cconvert_ptr cconvert; 388 my_cconvert_ptr cconvert;
389 389
390 cconvert = (my_cconvert_ptr) 390 cconvert = (my_cconvert_ptr)
391 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, 391 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
392 SIZEOF(my_color_converter)); 392 SIZEOF(my_color_converter));
393 cinfo->cconvert = (struct jpeg_color_converter *) cconvert; 393 cinfo->cconvert = (struct jpeg_color_converter *) cconvert;
394 /* set start_pass to null method until we find out differently */ 394 /* set start_pass to null method until we find out differently */
395 cconvert->pub.start_pass = null_method; 395 cconvert->pub.start_pass = null_method;
396 396
397 /* Make sure input_components agrees with in_color_space */ 397 /* Make sure input_components agrees with in_color_space */
398 switch (cinfo->in_color_space) { 398 switch (cinfo->in_color_space) {
399 case JCS_GRAYSCALE: 399 case JCS_GRAYSCALE:
400 if (cinfo->input_components != 1) 400 if (cinfo->input_components != 1)
401 ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); 401 ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
402 break; 402 break;
403 403
404 case JCS_RGB: 404 case JCS_RGB:
405 if (cinfo->input_components != RGB_PIXELSIZE) 405 if (cinfo->input_components != RGB_PIXELSIZE)
406 ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); 406 ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
407 break; 407 break;
408 408
409 case JCS_YCbCr: 409 case JCS_YCbCr:
410 if (cinfo->input_components != 3) 410 if (cinfo->input_components != 3)
411 ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); 411 ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
412 break; 412 break;
413 413
414 case JCS_CMYK: 414 case JCS_CMYK:
415 case JCS_YCCK: 415 case JCS_YCCK:
416 if (cinfo->input_components != 4) 416 if (cinfo->input_components != 4)
417 ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); 417 ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
418 break; 418 break;
419 419
420 default: /* JCS_UNKNOWN can be anything */ 420 default: /* JCS_UNKNOWN can be anything */
421 if (cinfo->input_components < 1) 421 if (cinfo->input_components < 1)
422 ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); 422 ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
423 break; 423 break;
424 } 424 }
425 425
426 /* Check num_components, set conversion method based on requested space */ 426 /* Check num_components, set conversion method based on requested space */
427 switch (cinfo->jpeg_color_space) { 427 switch (cinfo->jpeg_color_space) {
428 case JCS_GRAYSCALE: 428 case JCS_GRAYSCALE:
429 if (cinfo->num_components != 1) 429 if (cinfo->num_components != 1)
430 ERREXIT(cinfo, JERR_BAD_J_COLORSPACE); 430 ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
431 if (cinfo->in_color_space == JCS_GRAYSCALE || 431 if (cinfo->in_color_space == JCS_GRAYSCALE ||
432 cinfo->in_color_space == JCS_YCbCr) 432 cinfo->in_color_space == JCS_YCbCr)
433 cconvert->pub.color_convert = grayscale_convert; 433 cconvert->pub.color_convert = grayscale_convert;
434 else if (cinfo->in_color_space == JCS_RGB) { 434 else if (cinfo->in_color_space == JCS_RGB) {
435 cconvert->pub.start_pass = rgb_ycc_start; 435 cconvert->pub.start_pass = rgb_ycc_start;
436 cconvert->pub.color_convert = rgb_gray_convert; 436 cconvert->pub.color_convert = rgb_gray_convert;
437 } else 437 } else
438 ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL); 438 ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
439 break; 439 break;
440 440
441 case JCS_RGB: 441 case JCS_RGB:
442 if (cinfo->num_components != 3) 442 if (cinfo->num_components != 3)
443 ERREXIT(cinfo, JERR_BAD_J_COLORSPACE); 443 ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
444 if (cinfo->in_color_space == JCS_RGB) 444 if (cinfo->in_color_space == JCS_RGB)
445 cconvert->pub.color_convert = rgb_convert; 445 cconvert->pub.color_convert = rgb_convert;
446 else 446 else
447 ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL); 447 ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
448 break; 448 break;
449 449
450 case JCS_YCbCr: 450 case JCS_YCbCr:
451 if (cinfo->num_components != 3) 451 if (cinfo->num_components != 3)
452 ERREXIT(cinfo, JERR_BAD_J_COLORSPACE); 452 ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
453 if (cinfo->in_color_space == JCS_RGB) { 453 if (cinfo->in_color_space == JCS_RGB) {
454 cconvert->pub.start_pass = rgb_ycc_start; 454 cconvert->pub.start_pass = rgb_ycc_start;
455 cconvert->pub.color_convert = rgb_ycc_convert; 455 cconvert->pub.color_convert = rgb_ycc_convert;
456 } else if (cinfo->in_color_space == JCS_YCbCr) 456 } else if (cinfo->in_color_space == JCS_YCbCr)
457 cconvert->pub.color_convert = null_convert; 457 cconvert->pub.color_convert = null_convert;
458 else 458 else
459 ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL); 459 ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
460 break; 460 break;
461 461
462 case JCS_CMYK: 462 case JCS_CMYK:
463 if (cinfo->num_components != 4) 463 if (cinfo->num_components != 4)
464 ERREXIT(cinfo, JERR_BAD_J_COLORSPACE); 464 ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
465 if (cinfo->in_color_space == JCS_CMYK) 465 if (cinfo->in_color_space == JCS_CMYK)
466 cconvert->pub.color_convert = null_convert; 466 cconvert->pub.color_convert = null_convert;
467 else 467 else
468 ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL); 468 ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
469 break; 469 break;
470 470
471 case JCS_YCCK: 471 case JCS_YCCK:
472 if (cinfo->num_components != 4) 472 if (cinfo->num_components != 4)
473 ERREXIT(cinfo, JERR_BAD_J_COLORSPACE); 473 ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
474 if (cinfo->in_color_space == JCS_CMYK) { 474 if (cinfo->in_color_space == JCS_CMYK) {
475 cconvert->pub.start_pass = rgb_ycc_start; 475 cconvert->pub.start_pass = rgb_ycc_start;
476 cconvert->pub.color_convert = cmyk_ycck_convert; 476 cconvert->pub.color_convert = cmyk_ycck_convert;
477 } else if (cinfo->in_color_space == JCS_YCCK) 477 } else if (cinfo->in_color_space == JCS_YCCK)
478 cconvert->pub.color_convert = null_convert; 478 cconvert->pub.color_convert = null_convert;
479 else 479 else
480 ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL); 480 ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
481 break; 481 break;
482 482
483 default: /* allow null conversion of JCS_UNKNOWN */ 483 default: /* allow null conversion of JCS_UNKNOWN */
484 if (cinfo->jpeg_color_space != cinfo->in_color_space || 484 if (cinfo->jpeg_color_space != cinfo->in_color_space ||
485 cinfo->num_components != cinfo->input_components) 485 cinfo->num_components != cinfo->input_components)
486 ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL); 486 ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
487 cconvert->pub.color_convert = null_convert; 487 cconvert->pub.color_convert = null_convert;
488 break; 488 break;
489 } 489 }
490} 490}