aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/irrlicht-1.8/source/Irrlicht/jpeglib/jdcolor.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/jdcolor.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/jdcolor.c')
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/jpeglib/jdcolor.c1024
1 files changed, 512 insertions, 512 deletions
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/jpeglib/jdcolor.c b/libraries/irrlicht-1.8/source/Irrlicht/jpeglib/jdcolor.c
index c12d9c8..83e4d06 100644
--- a/libraries/irrlicht-1.8/source/Irrlicht/jpeglib/jdcolor.c
+++ b/libraries/irrlicht-1.8/source/Irrlicht/jpeglib/jdcolor.c
@@ -1,512 +1,512 @@
1/* 1/*
2 * jdcolor.c 2 * jdcolor.c
3 * 3 *
4 * Copyright (C) 1991-1997, Thomas G. Lane. 4 * Copyright (C) 1991-1997, 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 output colorspace conversion routines. 9 * This file contains output 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_deconverter pub; /* public fields */ 20 struct jpeg_color_deconverter pub; /* public fields */
21 21
22 /* Private state for YCC->RGB conversion */ 22 /* Private state for YCC->RGB conversion */
23 int * Cr_r_tab; /* => table for Cr to R conversion */ 23 int * Cr_r_tab; /* => table for Cr to R conversion */
24 int * Cb_b_tab; /* => table for Cb to B conversion */ 24 int * Cb_b_tab; /* => table for Cb to B conversion */
25 INT32 * Cr_g_tab; /* => table for Cr to G conversion */ 25 INT32 * Cr_g_tab; /* => table for Cr to G conversion */
26 INT32 * Cb_g_tab; /* => table for Cb to G conversion */ 26 INT32 * Cb_g_tab; /* => table for Cb to G conversion */
27 27
28 /* Private state for RGB->Y conversion */ 28 /* Private state for RGB->Y conversion */
29 INT32 * rgb_y_tab; /* => table for RGB to Y conversion */ 29 INT32 * rgb_y_tab; /* => table for RGB to Y conversion */
30} my_color_deconverter; 30} my_color_deconverter;
31 31
32typedef my_color_deconverter * my_cconvert_ptr; 32typedef my_color_deconverter * my_cconvert_ptr;
33 33
34 34
35/**************** YCbCr -> RGB conversion: most common case **************/ 35/**************** YCbCr -> RGB conversion: most common case **************/
36/**************** RGB -> Y conversion: less common case **************/ 36/**************** RGB -> Y conversion: less common case **************/
37 37
38/* 38/*
39 * YCbCr is defined per CCIR 601-1, except that Cb and Cr are 39 * YCbCr is defined per CCIR 601-1, except that Cb and Cr are
40 * normalized to the range 0..MAXJSAMPLE rather than -0.5 .. 0.5. 40 * normalized to the range 0..MAXJSAMPLE rather than -0.5 .. 0.5.
41 * The conversion equations to be implemented are therefore 41 * The conversion equations to be implemented are therefore
42 * 42 *
43 * R = Y + 1.40200 * Cr 43 * R = Y + 1.40200 * Cr
44 * G = Y - 0.34414 * Cb - 0.71414 * Cr 44 * G = Y - 0.34414 * Cb - 0.71414 * Cr
45 * B = Y + 1.77200 * Cb 45 * B = Y + 1.77200 * Cb
46 * 46 *
47 * Y = 0.29900 * R + 0.58700 * G + 0.11400 * B 47 * Y = 0.29900 * R + 0.58700 * G + 0.11400 * B
48 * 48 *
49 * where Cb and Cr represent the incoming values less CENTERJSAMPLE. 49 * where Cb and Cr represent the incoming values less CENTERJSAMPLE.
50 * (These numbers are derived from TIFF 6.0 section 21, dated 3-June-92.) 50 * (These numbers are derived from TIFF 6.0 section 21, dated 3-June-92.)
51 * 51 *
52 * To avoid floating-point arithmetic, we represent the fractional constants 52 * To avoid floating-point arithmetic, we represent the fractional constants
53 * as integers scaled up by 2^16 (about 4 digits precision); we have to divide 53 * as integers scaled up by 2^16 (about 4 digits precision); we have to divide
54 * the products by 2^16, with appropriate rounding, to get the correct answer. 54 * the products by 2^16, with appropriate rounding, to get the correct answer.
55 * Notice that Y, being an integral input, does not contribute any fraction 55 * Notice that Y, being an integral input, does not contribute any fraction
56 * so it need not participate in the rounding. 56 * so it need not participate in the rounding.
57 * 57 *
58 * For even more speed, we avoid doing any multiplications in the inner loop 58 * For even more speed, we avoid doing any multiplications in the inner loop
59 * by precalculating the constants times Cb and Cr for all possible values. 59 * by precalculating the constants times Cb and Cr for all possible values.
60 * For 8-bit JSAMPLEs this is very reasonable (only 256 entries per table); 60 * For 8-bit JSAMPLEs this is very reasonable (only 256 entries per table);
61 * for 12-bit samples it is still acceptable. It's not very reasonable for 61 * for 12-bit samples it is still acceptable. It's not very reasonable for
62 * 16-bit samples, but if you want lossless storage you shouldn't be changing 62 * 16-bit samples, but if you want lossless storage you shouldn't be changing
63 * colorspace anyway. 63 * colorspace anyway.
64 * The Cr=>R and Cb=>B values can be rounded to integers in advance; the 64 * The Cr=>R and Cb=>B values can be rounded to integers in advance; the
65 * values for the G calculation are left scaled up, since we must add them 65 * values for the G calculation are left scaled up, since we must add them
66 * together before rounding. 66 * together before rounding.
67 */ 67 */
68 68
69#define SCALEBITS 16 /* speediest right-shift on some machines */ 69#define SCALEBITS 16 /* speediest right-shift on some machines */
70#define ONE_HALF ((INT32) 1 << (SCALEBITS-1)) 70#define ONE_HALF ((INT32) 1 << (SCALEBITS-1))
71#define FIX(x) ((INT32) ((x) * (1L<<SCALEBITS) + 0.5)) 71#define FIX(x) ((INT32) ((x) * (1L<<SCALEBITS) + 0.5))
72 72
73/* We allocate one big table for RGB->Y conversion and divide it up into 73/* We allocate one big table for RGB->Y conversion and divide it up into
74 * three parts, instead of doing three alloc_small requests. This lets us 74 * three parts, instead of doing three alloc_small requests. This lets us
75 * use a single table base address, which can be held in a register in the 75 * use a single table base address, which can be held in a register in the
76 * inner loops on many machines (more than can hold all three addresses, 76 * inner loops on many machines (more than can hold all three addresses,
77 * anyway). 77 * anyway).
78 */ 78 */
79 79
80#define R_Y_OFF 0 /* offset to R => Y section */ 80#define R_Y_OFF 0 /* offset to R => Y section */
81#define G_Y_OFF (1*(MAXJSAMPLE+1)) /* offset to G => Y section */ 81#define G_Y_OFF (1*(MAXJSAMPLE+1)) /* offset to G => Y section */
82#define B_Y_OFF (2*(MAXJSAMPLE+1)) /* etc. */ 82#define B_Y_OFF (2*(MAXJSAMPLE+1)) /* etc. */
83#define TABLE_SIZE (3*(MAXJSAMPLE+1)) 83#define TABLE_SIZE (3*(MAXJSAMPLE+1))
84 84
85 85
86/* 86/*
87 * Initialize tables for YCC->RGB colorspace conversion. 87 * Initialize tables for YCC->RGB colorspace conversion.
88 */ 88 */
89 89
90LOCAL(void) 90LOCAL(void)
91build_ycc_rgb_table (j_decompress_ptr cinfo) 91build_ycc_rgb_table (j_decompress_ptr cinfo)
92{ 92{
93 my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert; 93 my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
94 int i; 94 int i;
95 INT32 x; 95 INT32 x;
96 SHIFT_TEMPS 96 SHIFT_TEMPS
97 97
98 cconvert->Cr_r_tab = (int *) 98 cconvert->Cr_r_tab = (int *)
99 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, 99 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
100 (MAXJSAMPLE+1) * SIZEOF(int)); 100 (MAXJSAMPLE+1) * SIZEOF(int));
101 cconvert->Cb_b_tab = (int *) 101 cconvert->Cb_b_tab = (int *)
102 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, 102 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
103 (MAXJSAMPLE+1) * SIZEOF(int)); 103 (MAXJSAMPLE+1) * SIZEOF(int));
104 cconvert->Cr_g_tab = (INT32 *) 104 cconvert->Cr_g_tab = (INT32 *)
105 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, 105 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
106 (MAXJSAMPLE+1) * SIZEOF(INT32)); 106 (MAXJSAMPLE+1) * SIZEOF(INT32));
107 cconvert->Cb_g_tab = (INT32 *) 107 cconvert->Cb_g_tab = (INT32 *)
108 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, 108 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
109 (MAXJSAMPLE+1) * SIZEOF(INT32)); 109 (MAXJSAMPLE+1) * SIZEOF(INT32));
110 110
111 for (i = 0, x = -CENTERJSAMPLE; i <= MAXJSAMPLE; i++, x++) { 111 for (i = 0, x = -CENTERJSAMPLE; i <= MAXJSAMPLE; i++, x++) {
112 /* i is the actual input pixel value, in the range 0..MAXJSAMPLE */ 112 /* i is the actual input pixel value, in the range 0..MAXJSAMPLE */
113 /* The Cb or Cr value we are thinking of is x = i - CENTERJSAMPLE */ 113 /* The Cb or Cr value we are thinking of is x = i - CENTERJSAMPLE */
114 /* Cr=>R value is nearest int to 1.40200 * x */ 114 /* Cr=>R value is nearest int to 1.40200 * x */
115 cconvert->Cr_r_tab[i] = (int) 115 cconvert->Cr_r_tab[i] = (int)
116 RIGHT_SHIFT(FIX(1.40200) * x + ONE_HALF, SCALEBITS); 116 RIGHT_SHIFT(FIX(1.40200) * x + ONE_HALF, SCALEBITS);
117 /* Cb=>B value is nearest int to 1.77200 * x */ 117 /* Cb=>B value is nearest int to 1.77200 * x */
118 cconvert->Cb_b_tab[i] = (int) 118 cconvert->Cb_b_tab[i] = (int)
119 RIGHT_SHIFT(FIX(1.77200) * x + ONE_HALF, SCALEBITS); 119 RIGHT_SHIFT(FIX(1.77200) * x + ONE_HALF, SCALEBITS);
120 /* Cr=>G value is scaled-up -0.71414 * x */ 120 /* Cr=>G value is scaled-up -0.71414 * x */
121 cconvert->Cr_g_tab[i] = (- FIX(0.71414)) * x; 121 cconvert->Cr_g_tab[i] = (- FIX(0.71414)) * x;
122 /* Cb=>G value is scaled-up -0.34414 * x */ 122 /* Cb=>G value is scaled-up -0.34414 * x */
123 /* We also add in ONE_HALF so that need not do it in inner loop */ 123 /* We also add in ONE_HALF so that need not do it in inner loop */
124 cconvert->Cb_g_tab[i] = (- FIX(0.34414)) * x + ONE_HALF; 124 cconvert->Cb_g_tab[i] = (- FIX(0.34414)) * x + ONE_HALF;
125 } 125 }
126} 126}
127 127
128 128
129/* 129/*
130 * Convert some rows of samples to the output colorspace. 130 * Convert some rows of samples to the output colorspace.
131 * 131 *
132 * Note that we change from noninterleaved, one-plane-per-component format 132 * Note that we change from noninterleaved, one-plane-per-component format
133 * to interleaved-pixel format. The output buffer is therefore three times 133 * to interleaved-pixel format. The output buffer is therefore three times
134 * as wide as the input buffer. 134 * as wide as the input buffer.
135 * A starting row offset is provided only for the input buffer. The caller 135 * A starting row offset is provided only for the input buffer. The caller
136 * can easily adjust the passed output_buf value to accommodate any row 136 * can easily adjust the passed output_buf value to accommodate any row
137 * offset required on that side. 137 * offset required on that side.
138 */ 138 */
139 139
140METHODDEF(void) 140METHODDEF(void)
141ycc_rgb_convert (j_decompress_ptr cinfo, 141ycc_rgb_convert (j_decompress_ptr cinfo,
142 JSAMPIMAGE input_buf, JDIMENSION input_row, 142 JSAMPIMAGE input_buf, JDIMENSION input_row,
143 JSAMPARRAY output_buf, int num_rows) 143 JSAMPARRAY output_buf, int num_rows)
144{ 144{
145 my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert; 145 my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
146 register int y, cb, cr; 146 register int y, cb, cr;
147 register JSAMPROW outptr; 147 register JSAMPROW outptr;
148 register JSAMPROW inptr0, inptr1, inptr2; 148 register JSAMPROW inptr0, inptr1, inptr2;
149 register JDIMENSION col; 149 register JDIMENSION col;
150 JDIMENSION num_cols = cinfo->output_width; 150 JDIMENSION num_cols = cinfo->output_width;
151 /* copy these pointers into registers if possible */ 151 /* copy these pointers into registers if possible */
152 register JSAMPLE * range_limit = cinfo->sample_range_limit; 152 register JSAMPLE * range_limit = cinfo->sample_range_limit;
153 register int * Crrtab = cconvert->Cr_r_tab; 153 register int * Crrtab = cconvert->Cr_r_tab;
154 register int * Cbbtab = cconvert->Cb_b_tab; 154 register int * Cbbtab = cconvert->Cb_b_tab;
155 register INT32 * Crgtab = cconvert->Cr_g_tab; 155 register INT32 * Crgtab = cconvert->Cr_g_tab;
156 register INT32 * Cbgtab = cconvert->Cb_g_tab; 156 register INT32 * Cbgtab = cconvert->Cb_g_tab;
157 SHIFT_TEMPS 157 SHIFT_TEMPS
158 158
159 while (--num_rows >= 0) { 159 while (--num_rows >= 0) {
160 inptr0 = input_buf[0][input_row]; 160 inptr0 = input_buf[0][input_row];
161 inptr1 = input_buf[1][input_row]; 161 inptr1 = input_buf[1][input_row];
162 inptr2 = input_buf[2][input_row]; 162 inptr2 = input_buf[2][input_row];
163 input_row++; 163 input_row++;
164 outptr = *output_buf++; 164 outptr = *output_buf++;
165 for (col = 0; col < num_cols; col++) { 165 for (col = 0; col < num_cols; col++) {
166 y = GETJSAMPLE(inptr0[col]); 166 y = GETJSAMPLE(inptr0[col]);
167 cb = GETJSAMPLE(inptr1[col]); 167 cb = GETJSAMPLE(inptr1[col]);
168 cr = GETJSAMPLE(inptr2[col]); 168 cr = GETJSAMPLE(inptr2[col]);
169 /* Range-limiting is essential due to noise introduced by DCT losses. */ 169 /* Range-limiting is essential due to noise introduced by DCT losses. */
170 outptr[RGB_RED] = range_limit[y + Crrtab[cr]]; 170 outptr[RGB_RED] = range_limit[y + Crrtab[cr]];
171 outptr[RGB_GREEN] = range_limit[y + 171 outptr[RGB_GREEN] = range_limit[y +
172 ((int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], 172 ((int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
173 SCALEBITS))]; 173 SCALEBITS))];
174 outptr[RGB_BLUE] = range_limit[y + Cbbtab[cb]]; 174 outptr[RGB_BLUE] = range_limit[y + Cbbtab[cb]];
175 outptr += RGB_PIXELSIZE; 175 outptr += RGB_PIXELSIZE;
176 } 176 }
177 } 177 }
178} 178}
179 179
180 180
181/**************** Cases other than YCbCr -> RGB **************/ 181/**************** Cases other than YCbCr -> RGB **************/
182 182
183 183
184/* 184/*
185 * Initialize for RGB->grayscale colorspace conversion. 185 * Initialize for RGB->grayscale colorspace conversion.
186 */ 186 */
187 187
188LOCAL(void) 188LOCAL(void)
189build_rgb_y_table (j_decompress_ptr cinfo) 189build_rgb_y_table (j_decompress_ptr cinfo)
190{ 190{
191 my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert; 191 my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
192 INT32 * rgb_y_tab; 192 INT32 * rgb_y_tab;
193 INT32 i; 193 INT32 i;
194 194
195 /* Allocate and fill in the conversion tables. */ 195 /* Allocate and fill in the conversion tables. */
196 cconvert->rgb_y_tab = rgb_y_tab = (INT32 *) 196 cconvert->rgb_y_tab = rgb_y_tab = (INT32 *)
197 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, 197 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
198 (TABLE_SIZE * SIZEOF(INT32))); 198 (TABLE_SIZE * SIZEOF(INT32)));
199 199
200 for (i = 0; i <= MAXJSAMPLE; i++) { 200 for (i = 0; i <= MAXJSAMPLE; i++) {
201 rgb_y_tab[i+R_Y_OFF] = FIX(0.29900) * i; 201 rgb_y_tab[i+R_Y_OFF] = FIX(0.29900) * i;
202 rgb_y_tab[i+G_Y_OFF] = FIX(0.58700) * i; 202 rgb_y_tab[i+G_Y_OFF] = FIX(0.58700) * i;
203 rgb_y_tab[i+B_Y_OFF] = FIX(0.11400) * i + ONE_HALF; 203 rgb_y_tab[i+B_Y_OFF] = FIX(0.11400) * i + ONE_HALF;
204 } 204 }
205} 205}
206 206
207 207
208/* 208/*
209 * Convert RGB to grayscale. 209 * Convert RGB to grayscale.
210 */ 210 */
211 211
212METHODDEF(void) 212METHODDEF(void)
213rgb_gray_convert (j_decompress_ptr cinfo, 213rgb_gray_convert (j_decompress_ptr cinfo,
214 JSAMPIMAGE input_buf, JDIMENSION input_row, 214 JSAMPIMAGE input_buf, JDIMENSION input_row,
215 JSAMPARRAY output_buf, int num_rows) 215 JSAMPARRAY output_buf, int num_rows)
216{ 216{
217 my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert; 217 my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
218 register int r, g, b; 218 register int r, g, b;
219 register INT32 * ctab = cconvert->rgb_y_tab; 219 register INT32 * ctab = cconvert->rgb_y_tab;
220 register JSAMPROW outptr; 220 register JSAMPROW outptr;
221 register JSAMPROW inptr0, inptr1, inptr2; 221 register JSAMPROW inptr0, inptr1, inptr2;
222 register JDIMENSION col; 222 register JDIMENSION col;
223 JDIMENSION num_cols = cinfo->output_width; 223 JDIMENSION num_cols = cinfo->output_width;
224 224
225 while (--num_rows >= 0) { 225 while (--num_rows >= 0) {
226 inptr0 = input_buf[0][input_row]; 226 inptr0 = input_buf[0][input_row];
227 inptr1 = input_buf[1][input_row]; 227 inptr1 = input_buf[1][input_row];
228 inptr2 = input_buf[2][input_row]; 228 inptr2 = input_buf[2][input_row];
229 input_row++; 229 input_row++;
230 outptr = *output_buf++; 230 outptr = *output_buf++;
231 for (col = 0; col < num_cols; col++) { 231 for (col = 0; col < num_cols; col++) {
232 r = GETJSAMPLE(inptr0[col]); 232 r = GETJSAMPLE(inptr0[col]);
233 g = GETJSAMPLE(inptr1[col]); 233 g = GETJSAMPLE(inptr1[col]);
234 b = GETJSAMPLE(inptr2[col]); 234 b = GETJSAMPLE(inptr2[col]);
235 /* Y */ 235 /* Y */
236 outptr[col] = (JSAMPLE) 236 outptr[col] = (JSAMPLE)
237 ((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF]) 237 ((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])
238 >> SCALEBITS); 238 >> SCALEBITS);
239 } 239 }
240 } 240 }
241} 241}
242 242
243 243
244/* 244/*
245 * No colorspace change, but conversion from separate-planes 245 * No colorspace change, but conversion from separate-planes
246 * to interleaved representation. 246 * to interleaved representation.
247 */ 247 */
248 248
249METHODDEF(void) 249METHODDEF(void)
250rgb_convert (j_decompress_ptr cinfo, 250rgb_convert (j_decompress_ptr cinfo,
251 JSAMPIMAGE input_buf, JDIMENSION input_row, 251 JSAMPIMAGE input_buf, JDIMENSION input_row,
252 JSAMPARRAY output_buf, int num_rows) 252 JSAMPARRAY output_buf, int num_rows)
253{ 253{
254 register JSAMPROW outptr; 254 register JSAMPROW outptr;
255 register JSAMPROW inptr0, inptr1, inptr2; 255 register JSAMPROW inptr0, inptr1, inptr2;
256 register JDIMENSION col; 256 register JDIMENSION col;
257 JDIMENSION num_cols = cinfo->output_width; 257 JDIMENSION num_cols = cinfo->output_width;
258 258
259 while (--num_rows >= 0) { 259 while (--num_rows >= 0) {
260 inptr0 = input_buf[0][input_row]; 260 inptr0 = input_buf[0][input_row];
261 inptr1 = input_buf[1][input_row]; 261 inptr1 = input_buf[1][input_row];
262 inptr2 = input_buf[2][input_row]; 262 inptr2 = input_buf[2][input_row];
263 input_row++; 263 input_row++;
264 outptr = *output_buf++; 264 outptr = *output_buf++;
265 for (col = 0; col < num_cols; col++) { 265 for (col = 0; col < num_cols; col++) {
266 /* We can dispense with GETJSAMPLE() here */ 266 /* We can dispense with GETJSAMPLE() here */
267 outptr[RGB_RED] = inptr0[col]; 267 outptr[RGB_RED] = inptr0[col];
268 outptr[RGB_GREEN] = inptr1[col]; 268 outptr[RGB_GREEN] = inptr1[col];
269 outptr[RGB_BLUE] = inptr2[col]; 269 outptr[RGB_BLUE] = inptr2[col];
270 outptr += RGB_PIXELSIZE; 270 outptr += RGB_PIXELSIZE;
271 } 271 }
272 } 272 }
273} 273}
274 274
275 275
276/* 276/*
277 * Color conversion for no colorspace change: just copy the data, 277 * Color conversion for no colorspace change: just copy the data,
278 * converting from separate-planes to interleaved representation. 278 * converting from separate-planes to interleaved representation.
279 */ 279 */
280 280
281METHODDEF(void) 281METHODDEF(void)
282null_convert (j_decompress_ptr cinfo, 282null_convert (j_decompress_ptr cinfo,
283 JSAMPIMAGE input_buf, JDIMENSION input_row, 283 JSAMPIMAGE input_buf, JDIMENSION input_row,
284 JSAMPARRAY output_buf, int num_rows) 284 JSAMPARRAY output_buf, int num_rows)
285{ 285{
286 register JSAMPROW inptr, outptr; 286 register JSAMPROW inptr, outptr;
287 register JDIMENSION count; 287 register JDIMENSION count;
288 register int num_components = cinfo->num_components; 288 register int num_components = cinfo->num_components;
289 JDIMENSION num_cols = cinfo->output_width; 289 JDIMENSION num_cols = cinfo->output_width;
290 int ci; 290 int ci;
291 291
292 while (--num_rows >= 0) { 292 while (--num_rows >= 0) {
293 for (ci = 0; ci < num_components; ci++) { 293 for (ci = 0; ci < num_components; ci++) {
294 inptr = input_buf[ci][input_row]; 294 inptr = input_buf[ci][input_row];
295 outptr = output_buf[0] + ci; 295 outptr = output_buf[0] + ci;
296 for (count = num_cols; count > 0; count--) { 296 for (count = num_cols; count > 0; count--) {
297 *outptr = *inptr++; /* needn't bother with GETJSAMPLE() here */ 297 *outptr = *inptr++; /* needn't bother with GETJSAMPLE() here */
298 outptr += num_components; 298 outptr += num_components;
299 } 299 }
300 } 300 }
301 input_row++; 301 input_row++;
302 output_buf++; 302 output_buf++;
303 } 303 }
304} 304}
305 305
306 306
307/* 307/*
308 * Color conversion for grayscale: just copy the data. 308 * Color conversion for grayscale: just copy the data.
309 * This also works for YCbCr -> grayscale conversion, in which 309 * This also works for YCbCr -> grayscale conversion, in which
310 * we just copy the Y (luminance) component and ignore chrominance. 310 * we just copy the Y (luminance) component and ignore chrominance.
311 */ 311 */
312 312
313METHODDEF(void) 313METHODDEF(void)
314grayscale_convert (j_decompress_ptr cinfo, 314grayscale_convert (j_decompress_ptr cinfo,
315 JSAMPIMAGE input_buf, JDIMENSION input_row, 315 JSAMPIMAGE input_buf, JDIMENSION input_row,
316 JSAMPARRAY output_buf, int num_rows) 316 JSAMPARRAY output_buf, int num_rows)
317{ 317{
318 jcopy_sample_rows(input_buf[0], (int) input_row, output_buf, 0, 318 jcopy_sample_rows(input_buf[0], (int) input_row, output_buf, 0,
319 num_rows, cinfo->output_width); 319 num_rows, cinfo->output_width);
320} 320}
321 321
322 322
323/* 323/*
324 * Convert grayscale to RGB: just duplicate the graylevel three times. 324 * Convert grayscale to RGB: just duplicate the graylevel three times.
325 * This is provided to support applications that don't want to cope 325 * This is provided to support applications that don't want to cope
326 * with grayscale as a separate case. 326 * with grayscale as a separate case.
327 */ 327 */
328 328
329METHODDEF(void) 329METHODDEF(void)
330gray_rgb_convert (j_decompress_ptr cinfo, 330gray_rgb_convert (j_decompress_ptr cinfo,
331 JSAMPIMAGE input_buf, JDIMENSION input_row, 331 JSAMPIMAGE input_buf, JDIMENSION input_row,
332 JSAMPARRAY output_buf, int num_rows) 332 JSAMPARRAY output_buf, int num_rows)
333{ 333{
334 register JSAMPROW inptr, outptr; 334 register JSAMPROW inptr, outptr;
335 register JDIMENSION col; 335 register JDIMENSION col;
336 JDIMENSION num_cols = cinfo->output_width; 336 JDIMENSION num_cols = cinfo->output_width;
337 337
338 while (--num_rows >= 0) { 338 while (--num_rows >= 0) {
339 inptr = input_buf[0][input_row++]; 339 inptr = input_buf[0][input_row++];
340 outptr = *output_buf++; 340 outptr = *output_buf++;
341 for (col = 0; col < num_cols; col++) { 341 for (col = 0; col < num_cols; col++) {
342 /* We can dispense with GETJSAMPLE() here */ 342 /* We can dispense with GETJSAMPLE() here */
343 outptr[RGB_RED] = outptr[RGB_GREEN] = outptr[RGB_BLUE] = inptr[col]; 343 outptr[RGB_RED] = outptr[RGB_GREEN] = outptr[RGB_BLUE] = inptr[col];
344 outptr += RGB_PIXELSIZE; 344 outptr += RGB_PIXELSIZE;
345 } 345 }
346 } 346 }
347} 347}
348 348
349 349
350/* 350/*
351 * Adobe-style YCCK->CMYK conversion. 351 * Adobe-style YCCK->CMYK conversion.
352 * We convert YCbCr to R=1-C, G=1-M, and B=1-Y using the same 352 * We convert YCbCr to R=1-C, G=1-M, and B=1-Y using the same
353 * conversion as above, while passing K (black) unchanged. 353 * conversion as above, while passing K (black) unchanged.
354 * We assume build_ycc_rgb_table has been called. 354 * We assume build_ycc_rgb_table has been called.
355 */ 355 */
356 356
357METHODDEF(void) 357METHODDEF(void)
358ycck_cmyk_convert (j_decompress_ptr cinfo, 358ycck_cmyk_convert (j_decompress_ptr cinfo,
359 JSAMPIMAGE input_buf, JDIMENSION input_row, 359 JSAMPIMAGE input_buf, JDIMENSION input_row,
360 JSAMPARRAY output_buf, int num_rows) 360 JSAMPARRAY output_buf, int num_rows)
361{ 361{
362 my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert; 362 my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
363 register int y, cb, cr; 363 register int y, cb, cr;
364 register JSAMPROW outptr; 364 register JSAMPROW outptr;
365 register JSAMPROW inptr0, inptr1, inptr2, inptr3; 365 register JSAMPROW inptr0, inptr1, inptr2, inptr3;
366 register JDIMENSION col; 366 register JDIMENSION col;
367 JDIMENSION num_cols = cinfo->output_width; 367 JDIMENSION num_cols = cinfo->output_width;
368 /* copy these pointers into registers if possible */ 368 /* copy these pointers into registers if possible */
369 register JSAMPLE * range_limit = cinfo->sample_range_limit; 369 register JSAMPLE * range_limit = cinfo->sample_range_limit;
370 register int * Crrtab = cconvert->Cr_r_tab; 370 register int * Crrtab = cconvert->Cr_r_tab;
371 register int * Cbbtab = cconvert->Cb_b_tab; 371 register int * Cbbtab = cconvert->Cb_b_tab;
372 register INT32 * Crgtab = cconvert->Cr_g_tab; 372 register INT32 * Crgtab = cconvert->Cr_g_tab;
373 register INT32 * Cbgtab = cconvert->Cb_g_tab; 373 register INT32 * Cbgtab = cconvert->Cb_g_tab;
374 SHIFT_TEMPS 374 SHIFT_TEMPS
375 375
376 while (--num_rows >= 0) { 376 while (--num_rows >= 0) {
377 inptr0 = input_buf[0][input_row]; 377 inptr0 = input_buf[0][input_row];
378 inptr1 = input_buf[1][input_row]; 378 inptr1 = input_buf[1][input_row];
379 inptr2 = input_buf[2][input_row]; 379 inptr2 = input_buf[2][input_row];
380 inptr3 = input_buf[3][input_row]; 380 inptr3 = input_buf[3][input_row];
381 input_row++; 381 input_row++;
382 outptr = *output_buf++; 382 outptr = *output_buf++;
383 for (col = 0; col < num_cols; col++) { 383 for (col = 0; col < num_cols; col++) {
384 y = GETJSAMPLE(inptr0[col]); 384 y = GETJSAMPLE(inptr0[col]);
385 cb = GETJSAMPLE(inptr1[col]); 385 cb = GETJSAMPLE(inptr1[col]);
386 cr = GETJSAMPLE(inptr2[col]); 386 cr = GETJSAMPLE(inptr2[col]);
387 /* Range-limiting is essential due to noise introduced by DCT losses. */ 387 /* Range-limiting is essential due to noise introduced by DCT losses. */
388 outptr[0] = range_limit[MAXJSAMPLE - (y + Crrtab[cr])]; /* red */ 388 outptr[0] = range_limit[MAXJSAMPLE - (y + Crrtab[cr])]; /* red */
389 outptr[1] = range_limit[MAXJSAMPLE - (y + /* green */ 389 outptr[1] = range_limit[MAXJSAMPLE - (y + /* green */
390 ((int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], 390 ((int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
391 SCALEBITS)))]; 391 SCALEBITS)))];
392 outptr[2] = range_limit[MAXJSAMPLE - (y + Cbbtab[cb])]; /* blue */ 392 outptr[2] = range_limit[MAXJSAMPLE - (y + Cbbtab[cb])]; /* blue */
393 /* K passes through unchanged */ 393 /* K passes through unchanged */
394 outptr[3] = inptr3[col]; /* don't need GETJSAMPLE here */ 394 outptr[3] = inptr3[col]; /* don't need GETJSAMPLE here */
395 outptr += 4; 395 outptr += 4;
396 } 396 }
397 } 397 }
398} 398}
399 399
400 400
401/* 401/*
402 * Empty method for start_pass. 402 * Empty method for start_pass.
403 */ 403 */
404 404
405METHODDEF(void) 405METHODDEF(void)
406start_pass_dcolor (j_decompress_ptr cinfo) 406start_pass_dcolor (j_decompress_ptr cinfo)
407{ 407{
408 /* no work needed */ 408 /* no work needed */
409} 409}
410 410
411 411
412/* 412/*
413 * Module initialization routine for output colorspace conversion. 413 * Module initialization routine for output colorspace conversion.
414 */ 414 */
415 415
416GLOBAL(void) 416GLOBAL(void)
417jinit_color_deconverter (j_decompress_ptr cinfo) 417jinit_color_deconverter (j_decompress_ptr cinfo)
418{ 418{
419 my_cconvert_ptr cconvert; 419 my_cconvert_ptr cconvert;
420 int ci; 420 int ci;
421 421
422 cconvert = (my_cconvert_ptr) 422 cconvert = (my_cconvert_ptr)
423 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, 423 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
424 SIZEOF(my_color_deconverter)); 424 SIZEOF(my_color_deconverter));
425 cinfo->cconvert = (struct jpeg_color_deconverter *) cconvert; 425 cinfo->cconvert = (struct jpeg_color_deconverter *) cconvert;
426 cconvert->pub.start_pass = start_pass_dcolor; 426 cconvert->pub.start_pass = start_pass_dcolor;
427 427
428 /* Make sure num_components agrees with jpeg_color_space */ 428 /* Make sure num_components agrees with jpeg_color_space */
429 switch (cinfo->jpeg_color_space) { 429 switch (cinfo->jpeg_color_space) {
430 case JCS_GRAYSCALE: 430 case JCS_GRAYSCALE:
431 if (cinfo->num_components != 1) 431 if (cinfo->num_components != 1)
432 ERREXIT(cinfo, JERR_BAD_J_COLORSPACE); 432 ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
433 break; 433 break;
434 434
435 case JCS_RGB: 435 case JCS_RGB:
436 case JCS_YCbCr: 436 case JCS_YCbCr:
437 if (cinfo->num_components != 3) 437 if (cinfo->num_components != 3)
438 ERREXIT(cinfo, JERR_BAD_J_COLORSPACE); 438 ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
439 break; 439 break;
440 440
441 case JCS_CMYK: 441 case JCS_CMYK:
442 case JCS_YCCK: 442 case JCS_YCCK:
443 if (cinfo->num_components != 4) 443 if (cinfo->num_components != 4)
444 ERREXIT(cinfo, JERR_BAD_J_COLORSPACE); 444 ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
445 break; 445 break;
446 446
447 default: /* JCS_UNKNOWN can be anything */ 447 default: /* JCS_UNKNOWN can be anything */
448 if (cinfo->num_components < 1) 448 if (cinfo->num_components < 1)
449 ERREXIT(cinfo, JERR_BAD_J_COLORSPACE); 449 ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
450 break; 450 break;
451 } 451 }
452 452
453 /* Set out_color_components and conversion method based on requested space. 453 /* Set out_color_components and conversion method based on requested space.
454 * Also clear the component_needed flags for any unused components, 454 * Also clear the component_needed flags for any unused components,
455 * so that earlier pipeline stages can avoid useless computation. 455 * so that earlier pipeline stages can avoid useless computation.
456 */ 456 */
457 457
458 switch (cinfo->out_color_space) { 458 switch (cinfo->out_color_space) {
459 case JCS_GRAYSCALE: 459 case JCS_GRAYSCALE:
460 cinfo->out_color_components = 1; 460 cinfo->out_color_components = 1;
461 if (cinfo->jpeg_color_space == JCS_GRAYSCALE || 461 if (cinfo->jpeg_color_space == JCS_GRAYSCALE ||
462 cinfo->jpeg_color_space == JCS_YCbCr) { 462 cinfo->jpeg_color_space == JCS_YCbCr) {
463 cconvert->pub.color_convert = grayscale_convert; 463 cconvert->pub.color_convert = grayscale_convert;
464 /* For color->grayscale conversion, only the Y (0) component is needed */ 464 /* For color->grayscale conversion, only the Y (0) component is needed */
465 for (ci = 1; ci < cinfo->num_components; ci++) 465 for (ci = 1; ci < cinfo->num_components; ci++)
466 cinfo->comp_info[ci].component_needed = FALSE; 466 cinfo->comp_info[ci].component_needed = FALSE;
467 } else if (cinfo->jpeg_color_space == JCS_RGB) { 467 } else if (cinfo->jpeg_color_space == JCS_RGB) {
468 cconvert->pub.color_convert = rgb_gray_convert; 468 cconvert->pub.color_convert = rgb_gray_convert;
469 build_rgb_y_table(cinfo); 469 build_rgb_y_table(cinfo);
470 } else 470 } else
471 ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL); 471 ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
472 break; 472 break;
473 473
474 case JCS_RGB: 474 case JCS_RGB:
475 cinfo->out_color_components = RGB_PIXELSIZE; 475 cinfo->out_color_components = RGB_PIXELSIZE;
476 if (cinfo->jpeg_color_space == JCS_YCbCr) { 476 if (cinfo->jpeg_color_space == JCS_YCbCr) {
477 cconvert->pub.color_convert = ycc_rgb_convert; 477 cconvert->pub.color_convert = ycc_rgb_convert;
478 build_ycc_rgb_table(cinfo); 478 build_ycc_rgb_table(cinfo);
479 } else if (cinfo->jpeg_color_space == JCS_GRAYSCALE) { 479 } else if (cinfo->jpeg_color_space == JCS_GRAYSCALE) {
480 cconvert->pub.color_convert = gray_rgb_convert; 480 cconvert->pub.color_convert = gray_rgb_convert;
481 } else if (cinfo->jpeg_color_space == JCS_RGB) { 481 } else if (cinfo->jpeg_color_space == JCS_RGB) {
482 cconvert->pub.color_convert = rgb_convert; 482 cconvert->pub.color_convert = rgb_convert;
483 } else 483 } else
484 ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL); 484 ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
485 break; 485 break;
486 486
487 case JCS_CMYK: 487 case JCS_CMYK:
488 cinfo->out_color_components = 4; 488 cinfo->out_color_components = 4;
489 if (cinfo->jpeg_color_space == JCS_YCCK) { 489 if (cinfo->jpeg_color_space == JCS_YCCK) {
490 cconvert->pub.color_convert = ycck_cmyk_convert; 490 cconvert->pub.color_convert = ycck_cmyk_convert;
491 build_ycc_rgb_table(cinfo); 491 build_ycc_rgb_table(cinfo);
492 } else if (cinfo->jpeg_color_space == JCS_CMYK) { 492 } else if (cinfo->jpeg_color_space == JCS_CMYK) {
493 cconvert->pub.color_convert = null_convert; 493 cconvert->pub.color_convert = null_convert;
494 } else 494 } else
495 ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL); 495 ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
496 break; 496 break;
497 497
498 default: 498 default:
499 /* Permit null conversion to same output space */ 499 /* Permit null conversion to same output space */
500 if (cinfo->out_color_space == cinfo->jpeg_color_space) { 500 if (cinfo->out_color_space == cinfo->jpeg_color_space) {
501 cinfo->out_color_components = cinfo->num_components; 501 cinfo->out_color_components = cinfo->num_components;
502 cconvert->pub.color_convert = null_convert; 502 cconvert->pub.color_convert = null_convert;
503 } else /* unsupported non-null conversion */ 503 } else /* unsupported non-null conversion */
504 ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL); 504 ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
505 break; 505 break;
506 } 506 }
507 507
508 if (cinfo->quantize_colors) 508 if (cinfo->quantize_colors)
509 cinfo->output_components = 1; /* single colormapped output component */ 509 cinfo->output_components = 1; /* single colormapped output component */
510 else 510 else
511 cinfo->output_components = cinfo->out_color_components; 511 cinfo->output_components = cinfo->out_color_components;
512} 512}