rev |
line source |
nuclear@26
|
1 /*
|
nuclear@26
|
2 * jdmerge.c
|
nuclear@26
|
3 *
|
nuclear@26
|
4 * Copyright (C) 1994-1996, Thomas G. Lane.
|
nuclear@26
|
5 * This file is part of the Independent JPEG Group's software.
|
nuclear@26
|
6 * For conditions of distribution and use, see the accompanying README file.
|
nuclear@26
|
7 *
|
nuclear@26
|
8 * This file contains code for merged upsampling/color conversion.
|
nuclear@26
|
9 *
|
nuclear@26
|
10 * This file combines functions from jdsample.c and jdcolor.c;
|
nuclear@26
|
11 * read those files first to understand what's going on.
|
nuclear@26
|
12 *
|
nuclear@26
|
13 * When the chroma components are to be upsampled by simple replication
|
nuclear@26
|
14 * (ie, box filtering), we can save some work in color conversion by
|
nuclear@26
|
15 * calculating all the output pixels corresponding to a pair of chroma
|
nuclear@26
|
16 * samples at one time. In the conversion equations
|
nuclear@26
|
17 * R = Y + K1 * Cr
|
nuclear@26
|
18 * G = Y + K2 * Cb + K3 * Cr
|
nuclear@26
|
19 * B = Y + K4 * Cb
|
nuclear@26
|
20 * only the Y term varies among the group of pixels corresponding to a pair
|
nuclear@26
|
21 * of chroma samples, so the rest of the terms can be calculated just once.
|
nuclear@26
|
22 * At typical sampling ratios, this eliminates half or three-quarters of the
|
nuclear@26
|
23 * multiplications needed for color conversion.
|
nuclear@26
|
24 *
|
nuclear@26
|
25 * This file currently provides implementations for the following cases:
|
nuclear@26
|
26 * YCbCr => RGB color conversion only.
|
nuclear@26
|
27 * Sampling ratios of 2h1v or 2h2v.
|
nuclear@26
|
28 * No scaling needed at upsample time.
|
nuclear@26
|
29 * Corner-aligned (non-CCIR601) sampling alignment.
|
nuclear@26
|
30 * Other special cases could be added, but in most applications these are
|
nuclear@26
|
31 * the only common cases. (For uncommon cases we fall back on the more
|
nuclear@26
|
32 * general code in jdsample.c and jdcolor.c.)
|
nuclear@26
|
33 */
|
nuclear@26
|
34
|
nuclear@26
|
35 #define JPEG_INTERNALS
|
nuclear@26
|
36 #include "jinclude.h"
|
nuclear@26
|
37 #include "jpeglib.h"
|
nuclear@26
|
38
|
nuclear@26
|
39 #ifdef UPSAMPLE_MERGING_SUPPORTED
|
nuclear@26
|
40
|
nuclear@26
|
41
|
nuclear@26
|
42 /* Private subobject */
|
nuclear@26
|
43
|
nuclear@26
|
44 typedef struct {
|
nuclear@26
|
45 struct jpeg_upsampler pub; /* public fields */
|
nuclear@26
|
46
|
nuclear@26
|
47 /* Pointer to routine to do actual upsampling/conversion of one row group */
|
nuclear@26
|
48 JMETHOD(void, upmethod, (j_decompress_ptr cinfo,
|
nuclear@26
|
49 JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
|
nuclear@26
|
50 JSAMPARRAY output_buf));
|
nuclear@26
|
51
|
nuclear@26
|
52 /* Private state for YCC->RGB conversion */
|
nuclear@26
|
53 int * Cr_r_tab; /* => table for Cr to R conversion */
|
nuclear@26
|
54 int * Cb_b_tab; /* => table for Cb to B conversion */
|
nuclear@26
|
55 INT32 * Cr_g_tab; /* => table for Cr to G conversion */
|
nuclear@26
|
56 INT32 * Cb_g_tab; /* => table for Cb to G conversion */
|
nuclear@26
|
57
|
nuclear@26
|
58 /* For 2:1 vertical sampling, we produce two output rows at a time.
|
nuclear@26
|
59 * We need a "spare" row buffer to hold the second output row if the
|
nuclear@26
|
60 * application provides just a one-row buffer; we also use the spare
|
nuclear@26
|
61 * to discard the dummy last row if the image height is odd.
|
nuclear@26
|
62 */
|
nuclear@26
|
63 JSAMPROW spare_row;
|
nuclear@26
|
64 boolean spare_full; /* T if spare buffer is occupied */
|
nuclear@26
|
65
|
nuclear@26
|
66 JDIMENSION out_row_width; /* samples per output row */
|
nuclear@26
|
67 JDIMENSION rows_to_go; /* counts rows remaining in image */
|
nuclear@26
|
68 } my_upsampler;
|
nuclear@26
|
69
|
nuclear@26
|
70 typedef my_upsampler * my_upsample_ptr;
|
nuclear@26
|
71
|
nuclear@26
|
72 #define SCALEBITS 16 /* speediest right-shift on some machines */
|
nuclear@26
|
73 #define ONE_HALF ((INT32) 1 << (SCALEBITS-1))
|
nuclear@26
|
74 #define FIX(x) ((INT32) ((x) * (1L<<SCALEBITS) + 0.5))
|
nuclear@26
|
75
|
nuclear@26
|
76
|
nuclear@26
|
77 /*
|
nuclear@26
|
78 * Initialize tables for YCC->RGB colorspace conversion.
|
nuclear@26
|
79 * This is taken directly from jdcolor.c; see that file for more info.
|
nuclear@26
|
80 */
|
nuclear@26
|
81
|
nuclear@26
|
82 LOCAL(void)
|
nuclear@26
|
83 build_ycc_rgb_table (j_decompress_ptr cinfo)
|
nuclear@26
|
84 {
|
nuclear@26
|
85 my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
|
nuclear@26
|
86 int i;
|
nuclear@26
|
87 INT32 x;
|
nuclear@26
|
88 SHIFT_TEMPS
|
nuclear@26
|
89
|
nuclear@26
|
90 upsample->Cr_r_tab = (int *)
|
nuclear@26
|
91 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
nuclear@26
|
92 (MAXJSAMPLE+1) * SIZEOF(int));
|
nuclear@26
|
93 upsample->Cb_b_tab = (int *)
|
nuclear@26
|
94 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
nuclear@26
|
95 (MAXJSAMPLE+1) * SIZEOF(int));
|
nuclear@26
|
96 upsample->Cr_g_tab = (INT32 *)
|
nuclear@26
|
97 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
nuclear@26
|
98 (MAXJSAMPLE+1) * SIZEOF(INT32));
|
nuclear@26
|
99 upsample->Cb_g_tab = (INT32 *)
|
nuclear@26
|
100 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
nuclear@26
|
101 (MAXJSAMPLE+1) * SIZEOF(INT32));
|
nuclear@26
|
102
|
nuclear@26
|
103 for (i = 0, x = -CENTERJSAMPLE; i <= MAXJSAMPLE; i++, x++) {
|
nuclear@26
|
104 /* i is the actual input pixel value, in the range 0..MAXJSAMPLE */
|
nuclear@26
|
105 /* The Cb or Cr value we are thinking of is x = i - CENTERJSAMPLE */
|
nuclear@26
|
106 /* Cr=>R value is nearest int to 1.40200 * x */
|
nuclear@26
|
107 upsample->Cr_r_tab[i] = (int)
|
nuclear@26
|
108 RIGHT_SHIFT(FIX(1.40200) * x + ONE_HALF, SCALEBITS);
|
nuclear@26
|
109 /* Cb=>B value is nearest int to 1.77200 * x */
|
nuclear@26
|
110 upsample->Cb_b_tab[i] = (int)
|
nuclear@26
|
111 RIGHT_SHIFT(FIX(1.77200) * x + ONE_HALF, SCALEBITS);
|
nuclear@26
|
112 /* Cr=>G value is scaled-up -0.71414 * x */
|
nuclear@26
|
113 upsample->Cr_g_tab[i] = (- FIX(0.71414)) * x;
|
nuclear@26
|
114 /* Cb=>G value is scaled-up -0.34414 * x */
|
nuclear@26
|
115 /* We also add in ONE_HALF so that need not do it in inner loop */
|
nuclear@26
|
116 upsample->Cb_g_tab[i] = (- FIX(0.34414)) * x + ONE_HALF;
|
nuclear@26
|
117 }
|
nuclear@26
|
118 }
|
nuclear@26
|
119
|
nuclear@26
|
120
|
nuclear@26
|
121 /*
|
nuclear@26
|
122 * Initialize for an upsampling pass.
|
nuclear@26
|
123 */
|
nuclear@26
|
124
|
nuclear@26
|
125 METHODDEF(void)
|
nuclear@26
|
126 start_pass_merged_upsample (j_decompress_ptr cinfo)
|
nuclear@26
|
127 {
|
nuclear@26
|
128 my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
|
nuclear@26
|
129
|
nuclear@26
|
130 /* Mark the spare buffer empty */
|
nuclear@26
|
131 upsample->spare_full = FALSE;
|
nuclear@26
|
132 /* Initialize total-height counter for detecting bottom of image */
|
nuclear@26
|
133 upsample->rows_to_go = cinfo->output_height;
|
nuclear@26
|
134 }
|
nuclear@26
|
135
|
nuclear@26
|
136
|
nuclear@26
|
137 /*
|
nuclear@26
|
138 * Control routine to do upsampling (and color conversion).
|
nuclear@26
|
139 *
|
nuclear@26
|
140 * The control routine just handles the row buffering considerations.
|
nuclear@26
|
141 */
|
nuclear@26
|
142
|
nuclear@26
|
143 METHODDEF(void)
|
nuclear@26
|
144 merged_2v_upsample (j_decompress_ptr cinfo,
|
nuclear@26
|
145 JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
|
nuclear@26
|
146 JDIMENSION in_row_groups_avail,
|
nuclear@26
|
147 JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
|
nuclear@26
|
148 JDIMENSION out_rows_avail)
|
nuclear@26
|
149 /* 2:1 vertical sampling case: may need a spare row. */
|
nuclear@26
|
150 {
|
nuclear@26
|
151 my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
|
nuclear@26
|
152 JSAMPROW work_ptrs[2];
|
nuclear@26
|
153 JDIMENSION num_rows; /* number of rows returned to caller */
|
nuclear@26
|
154
|
nuclear@26
|
155 if (upsample->spare_full) {
|
nuclear@26
|
156 /* If we have a spare row saved from a previous cycle, just return it. */
|
nuclear@26
|
157 jcopy_sample_rows(& upsample->spare_row, 0, output_buf + *out_row_ctr, 0,
|
nuclear@26
|
158 1, upsample->out_row_width);
|
nuclear@26
|
159 num_rows = 1;
|
nuclear@26
|
160 upsample->spare_full = FALSE;
|
nuclear@26
|
161 } else {
|
nuclear@26
|
162 /* Figure number of rows to return to caller. */
|
nuclear@26
|
163 num_rows = 2;
|
nuclear@26
|
164 /* Not more than the distance to the end of the image. */
|
nuclear@26
|
165 if (num_rows > upsample->rows_to_go)
|
nuclear@26
|
166 num_rows = upsample->rows_to_go;
|
nuclear@26
|
167 /* And not more than what the client can accept: */
|
nuclear@26
|
168 out_rows_avail -= *out_row_ctr;
|
nuclear@26
|
169 if (num_rows > out_rows_avail)
|
nuclear@26
|
170 num_rows = out_rows_avail;
|
nuclear@26
|
171 /* Create output pointer array for upsampler. */
|
nuclear@26
|
172 work_ptrs[0] = output_buf[*out_row_ctr];
|
nuclear@26
|
173 if (num_rows > 1) {
|
nuclear@26
|
174 work_ptrs[1] = output_buf[*out_row_ctr + 1];
|
nuclear@26
|
175 } else {
|
nuclear@26
|
176 work_ptrs[1] = upsample->spare_row;
|
nuclear@26
|
177 upsample->spare_full = TRUE;
|
nuclear@26
|
178 }
|
nuclear@26
|
179 /* Now do the upsampling. */
|
nuclear@26
|
180 (*upsample->upmethod) (cinfo, input_buf, *in_row_group_ctr, work_ptrs);
|
nuclear@26
|
181 }
|
nuclear@26
|
182
|
nuclear@26
|
183 /* Adjust counts */
|
nuclear@26
|
184 *out_row_ctr += num_rows;
|
nuclear@26
|
185 upsample->rows_to_go -= num_rows;
|
nuclear@26
|
186 /* When the buffer is emptied, declare this input row group consumed */
|
nuclear@26
|
187 if (! upsample->spare_full)
|
nuclear@26
|
188 (*in_row_group_ctr)++;
|
nuclear@26
|
189 }
|
nuclear@26
|
190
|
nuclear@26
|
191
|
nuclear@26
|
192 METHODDEF(void)
|
nuclear@26
|
193 merged_1v_upsample (j_decompress_ptr cinfo,
|
nuclear@26
|
194 JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
|
nuclear@26
|
195 JDIMENSION in_row_groups_avail,
|
nuclear@26
|
196 JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
|
nuclear@26
|
197 JDIMENSION out_rows_avail)
|
nuclear@26
|
198 /* 1:1 vertical sampling case: much easier, never need a spare row. */
|
nuclear@26
|
199 {
|
nuclear@26
|
200 my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
|
nuclear@26
|
201
|
nuclear@26
|
202 /* Just do the upsampling. */
|
nuclear@26
|
203 (*upsample->upmethod) (cinfo, input_buf, *in_row_group_ctr,
|
nuclear@26
|
204 output_buf + *out_row_ctr);
|
nuclear@26
|
205 /* Adjust counts */
|
nuclear@26
|
206 (*out_row_ctr)++;
|
nuclear@26
|
207 (*in_row_group_ctr)++;
|
nuclear@26
|
208 }
|
nuclear@26
|
209
|
nuclear@26
|
210
|
nuclear@26
|
211 /*
|
nuclear@26
|
212 * These are the routines invoked by the control routines to do
|
nuclear@26
|
213 * the actual upsampling/conversion. One row group is processed per call.
|
nuclear@26
|
214 *
|
nuclear@26
|
215 * Note: since we may be writing directly into application-supplied buffers,
|
nuclear@26
|
216 * we have to be honest about the output width; we can't assume the buffer
|
nuclear@26
|
217 * has been rounded up to an even width.
|
nuclear@26
|
218 */
|
nuclear@26
|
219
|
nuclear@26
|
220
|
nuclear@26
|
221 /*
|
nuclear@26
|
222 * Upsample and color convert for the case of 2:1 horizontal and 1:1 vertical.
|
nuclear@26
|
223 */
|
nuclear@26
|
224
|
nuclear@26
|
225 METHODDEF(void)
|
nuclear@26
|
226 h2v1_merged_upsample (j_decompress_ptr cinfo,
|
nuclear@26
|
227 JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
|
nuclear@26
|
228 JSAMPARRAY output_buf)
|
nuclear@26
|
229 {
|
nuclear@26
|
230 my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
|
nuclear@26
|
231 register int y, cred, cgreen, cblue;
|
nuclear@26
|
232 int cb, cr;
|
nuclear@26
|
233 register JSAMPROW outptr;
|
nuclear@26
|
234 JSAMPROW inptr0, inptr1, inptr2;
|
nuclear@26
|
235 JDIMENSION col;
|
nuclear@26
|
236 /* copy these pointers into registers if possible */
|
nuclear@26
|
237 register JSAMPLE * range_limit = cinfo->sample_range_limit;
|
nuclear@26
|
238 int * Crrtab = upsample->Cr_r_tab;
|
nuclear@26
|
239 int * Cbbtab = upsample->Cb_b_tab;
|
nuclear@26
|
240 INT32 * Crgtab = upsample->Cr_g_tab;
|
nuclear@26
|
241 INT32 * Cbgtab = upsample->Cb_g_tab;
|
nuclear@26
|
242 SHIFT_TEMPS
|
nuclear@26
|
243
|
nuclear@26
|
244 inptr0 = input_buf[0][in_row_group_ctr];
|
nuclear@26
|
245 inptr1 = input_buf[1][in_row_group_ctr];
|
nuclear@26
|
246 inptr2 = input_buf[2][in_row_group_ctr];
|
nuclear@26
|
247 outptr = output_buf[0];
|
nuclear@26
|
248 /* Loop for each pair of output pixels */
|
nuclear@26
|
249 for (col = cinfo->output_width >> 1; col > 0; col--) {
|
nuclear@26
|
250 /* Do the chroma part of the calculation */
|
nuclear@26
|
251 cb = GETJSAMPLE(*inptr1++);
|
nuclear@26
|
252 cr = GETJSAMPLE(*inptr2++);
|
nuclear@26
|
253 cred = Crrtab[cr];
|
nuclear@26
|
254 cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
|
nuclear@26
|
255 cblue = Cbbtab[cb];
|
nuclear@26
|
256 /* Fetch 2 Y values and emit 2 pixels */
|
nuclear@26
|
257 y = GETJSAMPLE(*inptr0++);
|
nuclear@26
|
258 outptr[RGB_RED] = range_limit[y + cred];
|
nuclear@26
|
259 outptr[RGB_GREEN] = range_limit[y + cgreen];
|
nuclear@26
|
260 outptr[RGB_BLUE] = range_limit[y + cblue];
|
nuclear@26
|
261 outptr += RGB_PIXELSIZE;
|
nuclear@26
|
262 y = GETJSAMPLE(*inptr0++);
|
nuclear@26
|
263 outptr[RGB_RED] = range_limit[y + cred];
|
nuclear@26
|
264 outptr[RGB_GREEN] = range_limit[y + cgreen];
|
nuclear@26
|
265 outptr[RGB_BLUE] = range_limit[y + cblue];
|
nuclear@26
|
266 outptr += RGB_PIXELSIZE;
|
nuclear@26
|
267 }
|
nuclear@26
|
268 /* If image width is odd, do the last output column separately */
|
nuclear@26
|
269 if (cinfo->output_width & 1) {
|
nuclear@26
|
270 cb = GETJSAMPLE(*inptr1);
|
nuclear@26
|
271 cr = GETJSAMPLE(*inptr2);
|
nuclear@26
|
272 cred = Crrtab[cr];
|
nuclear@26
|
273 cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
|
nuclear@26
|
274 cblue = Cbbtab[cb];
|
nuclear@26
|
275 y = GETJSAMPLE(*inptr0);
|
nuclear@26
|
276 outptr[RGB_RED] = range_limit[y + cred];
|
nuclear@26
|
277 outptr[RGB_GREEN] = range_limit[y + cgreen];
|
nuclear@26
|
278 outptr[RGB_BLUE] = range_limit[y + cblue];
|
nuclear@26
|
279 }
|
nuclear@26
|
280 }
|
nuclear@26
|
281
|
nuclear@26
|
282
|
nuclear@26
|
283 /*
|
nuclear@26
|
284 * Upsample and color convert for the case of 2:1 horizontal and 2:1 vertical.
|
nuclear@26
|
285 */
|
nuclear@26
|
286
|
nuclear@26
|
287 METHODDEF(void)
|
nuclear@26
|
288 h2v2_merged_upsample (j_decompress_ptr cinfo,
|
nuclear@26
|
289 JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
|
nuclear@26
|
290 JSAMPARRAY output_buf)
|
nuclear@26
|
291 {
|
nuclear@26
|
292 my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
|
nuclear@26
|
293 register int y, cred, cgreen, cblue;
|
nuclear@26
|
294 int cb, cr;
|
nuclear@26
|
295 register JSAMPROW outptr0, outptr1;
|
nuclear@26
|
296 JSAMPROW inptr00, inptr01, inptr1, inptr2;
|
nuclear@26
|
297 JDIMENSION col;
|
nuclear@26
|
298 /* copy these pointers into registers if possible */
|
nuclear@26
|
299 register JSAMPLE * range_limit = cinfo->sample_range_limit;
|
nuclear@26
|
300 int * Crrtab = upsample->Cr_r_tab;
|
nuclear@26
|
301 int * Cbbtab = upsample->Cb_b_tab;
|
nuclear@26
|
302 INT32 * Crgtab = upsample->Cr_g_tab;
|
nuclear@26
|
303 INT32 * Cbgtab = upsample->Cb_g_tab;
|
nuclear@26
|
304 SHIFT_TEMPS
|
nuclear@26
|
305
|
nuclear@26
|
306 inptr00 = input_buf[0][in_row_group_ctr*2];
|
nuclear@26
|
307 inptr01 = input_buf[0][in_row_group_ctr*2 + 1];
|
nuclear@26
|
308 inptr1 = input_buf[1][in_row_group_ctr];
|
nuclear@26
|
309 inptr2 = input_buf[2][in_row_group_ctr];
|
nuclear@26
|
310 outptr0 = output_buf[0];
|
nuclear@26
|
311 outptr1 = output_buf[1];
|
nuclear@26
|
312 /* Loop for each group of output pixels */
|
nuclear@26
|
313 for (col = cinfo->output_width >> 1; col > 0; col--) {
|
nuclear@26
|
314 /* Do the chroma part of the calculation */
|
nuclear@26
|
315 cb = GETJSAMPLE(*inptr1++);
|
nuclear@26
|
316 cr = GETJSAMPLE(*inptr2++);
|
nuclear@26
|
317 cred = Crrtab[cr];
|
nuclear@26
|
318 cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
|
nuclear@26
|
319 cblue = Cbbtab[cb];
|
nuclear@26
|
320 /* Fetch 4 Y values and emit 4 pixels */
|
nuclear@26
|
321 y = GETJSAMPLE(*inptr00++);
|
nuclear@26
|
322 outptr0[RGB_RED] = range_limit[y + cred];
|
nuclear@26
|
323 outptr0[RGB_GREEN] = range_limit[y + cgreen];
|
nuclear@26
|
324 outptr0[RGB_BLUE] = range_limit[y + cblue];
|
nuclear@26
|
325 outptr0 += RGB_PIXELSIZE;
|
nuclear@26
|
326 y = GETJSAMPLE(*inptr00++);
|
nuclear@26
|
327 outptr0[RGB_RED] = range_limit[y + cred];
|
nuclear@26
|
328 outptr0[RGB_GREEN] = range_limit[y + cgreen];
|
nuclear@26
|
329 outptr0[RGB_BLUE] = range_limit[y + cblue];
|
nuclear@26
|
330 outptr0 += RGB_PIXELSIZE;
|
nuclear@26
|
331 y = GETJSAMPLE(*inptr01++);
|
nuclear@26
|
332 outptr1[RGB_RED] = range_limit[y + cred];
|
nuclear@26
|
333 outptr1[RGB_GREEN] = range_limit[y + cgreen];
|
nuclear@26
|
334 outptr1[RGB_BLUE] = range_limit[y + cblue];
|
nuclear@26
|
335 outptr1 += RGB_PIXELSIZE;
|
nuclear@26
|
336 y = GETJSAMPLE(*inptr01++);
|
nuclear@26
|
337 outptr1[RGB_RED] = range_limit[y + cred];
|
nuclear@26
|
338 outptr1[RGB_GREEN] = range_limit[y + cgreen];
|
nuclear@26
|
339 outptr1[RGB_BLUE] = range_limit[y + cblue];
|
nuclear@26
|
340 outptr1 += RGB_PIXELSIZE;
|
nuclear@26
|
341 }
|
nuclear@26
|
342 /* If image width is odd, do the last output column separately */
|
nuclear@26
|
343 if (cinfo->output_width & 1) {
|
nuclear@26
|
344 cb = GETJSAMPLE(*inptr1);
|
nuclear@26
|
345 cr = GETJSAMPLE(*inptr2);
|
nuclear@26
|
346 cred = Crrtab[cr];
|
nuclear@26
|
347 cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
|
nuclear@26
|
348 cblue = Cbbtab[cb];
|
nuclear@26
|
349 y = GETJSAMPLE(*inptr00);
|
nuclear@26
|
350 outptr0[RGB_RED] = range_limit[y + cred];
|
nuclear@26
|
351 outptr0[RGB_GREEN] = range_limit[y + cgreen];
|
nuclear@26
|
352 outptr0[RGB_BLUE] = range_limit[y + cblue];
|
nuclear@26
|
353 y = GETJSAMPLE(*inptr01);
|
nuclear@26
|
354 outptr1[RGB_RED] = range_limit[y + cred];
|
nuclear@26
|
355 outptr1[RGB_GREEN] = range_limit[y + cgreen];
|
nuclear@26
|
356 outptr1[RGB_BLUE] = range_limit[y + cblue];
|
nuclear@26
|
357 }
|
nuclear@26
|
358 }
|
nuclear@26
|
359
|
nuclear@26
|
360
|
nuclear@26
|
361 /*
|
nuclear@26
|
362 * Module initialization routine for merged upsampling/color conversion.
|
nuclear@26
|
363 *
|
nuclear@26
|
364 * NB: this is called under the conditions determined by use_merged_upsample()
|
nuclear@26
|
365 * in jdmaster.c. That routine MUST correspond to the actual capabilities
|
nuclear@26
|
366 * of this module; no safety checks are made here.
|
nuclear@26
|
367 */
|
nuclear@26
|
368
|
nuclear@26
|
369 GLOBAL(void)
|
nuclear@26
|
370 jinit_merged_upsampler (j_decompress_ptr cinfo)
|
nuclear@26
|
371 {
|
nuclear@26
|
372 my_upsample_ptr upsample;
|
nuclear@26
|
373
|
nuclear@26
|
374 upsample = (my_upsample_ptr)
|
nuclear@26
|
375 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
nuclear@26
|
376 SIZEOF(my_upsampler));
|
nuclear@26
|
377 cinfo->upsample = (struct jpeg_upsampler *) upsample;
|
nuclear@26
|
378 upsample->pub.start_pass = start_pass_merged_upsample;
|
nuclear@26
|
379 upsample->pub.need_context_rows = FALSE;
|
nuclear@26
|
380
|
nuclear@26
|
381 upsample->out_row_width = cinfo->output_width * cinfo->out_color_components;
|
nuclear@26
|
382
|
nuclear@26
|
383 if (cinfo->max_v_samp_factor == 2) {
|
nuclear@26
|
384 upsample->pub.upsample = merged_2v_upsample;
|
nuclear@26
|
385 upsample->upmethod = h2v2_merged_upsample;
|
nuclear@26
|
386 /* Allocate a spare row buffer */
|
nuclear@26
|
387 upsample->spare_row = (JSAMPROW)
|
nuclear@26
|
388 (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
nuclear@26
|
389 (size_t) (upsample->out_row_width * SIZEOF(JSAMPLE)));
|
nuclear@26
|
390 } else {
|
nuclear@26
|
391 upsample->pub.upsample = merged_1v_upsample;
|
nuclear@26
|
392 upsample->upmethod = h2v1_merged_upsample;
|
nuclear@26
|
393 /* No spare row needed */
|
nuclear@26
|
394 upsample->spare_row = NULL;
|
nuclear@26
|
395 }
|
nuclear@26
|
396
|
nuclear@26
|
397 build_ycc_rgb_table(cinfo);
|
nuclear@26
|
398 }
|
nuclear@26
|
399
|
nuclear@26
|
400 #endif /* UPSAMPLE_MERGING_SUPPORTED */
|