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