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