rev |
line source |
nuclear@2
|
1 /*
|
nuclear@2
|
2 * jdsample.c
|
nuclear@2
|
3 *
|
nuclear@2
|
4 * Copyright (C) 1991-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 upsampling routines.
|
nuclear@2
|
9 *
|
nuclear@2
|
10 * Upsampling input data is counted in "row groups". A row group
|
nuclear@2
|
11 * is defined to be (v_samp_factor * DCT_scaled_size / min_DCT_scaled_size)
|
nuclear@2
|
12 * sample rows of each component. Upsampling will normally produce
|
nuclear@2
|
13 * max_v_samp_factor pixel rows from each row group (but this could vary
|
nuclear@2
|
14 * if the upsampler is applying a scale factor of its own).
|
nuclear@2
|
15 *
|
nuclear@2
|
16 * An excellent reference for image resampling is
|
nuclear@2
|
17 * Digital Image Warping, George Wolberg, 1990.
|
nuclear@2
|
18 * Pub. by IEEE Computer Society Press, Los Alamitos, CA. ISBN 0-8186-8944-7.
|
nuclear@2
|
19 */
|
nuclear@2
|
20
|
nuclear@2
|
21 #define JPEG_INTERNALS
|
nuclear@2
|
22 #include "jinclude.h"
|
nuclear@2
|
23 #include "jpeglib.h"
|
nuclear@2
|
24
|
nuclear@2
|
25
|
nuclear@2
|
26 /* Pointer to routine to upsample a single component */
|
nuclear@2
|
27 typedef JMETHOD(void, upsample1_ptr,
|
nuclear@2
|
28 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
nuclear@2
|
29 JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr));
|
nuclear@2
|
30
|
nuclear@2
|
31 /* Private subobject */
|
nuclear@2
|
32
|
nuclear@2
|
33 typedef struct {
|
nuclear@2
|
34 struct jpeg_upsampler pub; /* public fields */
|
nuclear@2
|
35
|
nuclear@2
|
36 /* Color conversion buffer. When using separate upsampling and color
|
nuclear@2
|
37 * conversion steps, this buffer holds one upsampled row group until it
|
nuclear@2
|
38 * has been color converted and output.
|
nuclear@2
|
39 * Note: we do not allocate any storage for component(s) which are full-size,
|
nuclear@2
|
40 * ie do not need rescaling. The corresponding entry of color_buf[] is
|
nuclear@2
|
41 * simply set to point to the input data array, thereby avoiding copying.
|
nuclear@2
|
42 */
|
nuclear@2
|
43 JSAMPARRAY color_buf[MAX_COMPONENTS];
|
nuclear@2
|
44
|
nuclear@2
|
45 /* Per-component upsampling method pointers */
|
nuclear@2
|
46 upsample1_ptr methods[MAX_COMPONENTS];
|
nuclear@2
|
47
|
nuclear@2
|
48 int next_row_out; /* counts rows emitted from color_buf */
|
nuclear@2
|
49 JDIMENSION rows_to_go; /* counts rows remaining in image */
|
nuclear@2
|
50
|
nuclear@2
|
51 /* Height of an input row group for each component. */
|
nuclear@2
|
52 int rowgroup_height[MAX_COMPONENTS];
|
nuclear@2
|
53
|
nuclear@2
|
54 /* These arrays save pixel expansion factors so that int_expand need not
|
nuclear@2
|
55 * recompute them each time. They are unused for other upsampling methods.
|
nuclear@2
|
56 */
|
nuclear@2
|
57 UINT8 h_expand[MAX_COMPONENTS];
|
nuclear@2
|
58 UINT8 v_expand[MAX_COMPONENTS];
|
nuclear@2
|
59 } my_upsampler;
|
nuclear@2
|
60
|
nuclear@2
|
61 typedef my_upsampler * my_upsample_ptr;
|
nuclear@2
|
62
|
nuclear@2
|
63
|
nuclear@2
|
64 /*
|
nuclear@2
|
65 * Initialize for an upsampling pass.
|
nuclear@2
|
66 */
|
nuclear@2
|
67
|
nuclear@2
|
68 METHODDEF(void)
|
nuclear@2
|
69 start_pass_upsample (j_decompress_ptr cinfo)
|
nuclear@2
|
70 {
|
nuclear@2
|
71 my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
|
nuclear@2
|
72
|
nuclear@2
|
73 /* Mark the conversion buffer empty */
|
nuclear@2
|
74 upsample->next_row_out = cinfo->max_v_samp_factor;
|
nuclear@2
|
75 /* Initialize total-height counter for detecting bottom of image */
|
nuclear@2
|
76 upsample->rows_to_go = cinfo->output_height;
|
nuclear@2
|
77 }
|
nuclear@2
|
78
|
nuclear@2
|
79
|
nuclear@2
|
80 /*
|
nuclear@2
|
81 * Control routine to do upsampling (and color conversion).
|
nuclear@2
|
82 *
|
nuclear@2
|
83 * In this version we upsample each component independently.
|
nuclear@2
|
84 * We upsample one row group into the conversion buffer, then apply
|
nuclear@2
|
85 * color conversion a row at a time.
|
nuclear@2
|
86 */
|
nuclear@2
|
87
|
nuclear@2
|
88 METHODDEF(void)
|
nuclear@2
|
89 sep_upsample (j_decompress_ptr cinfo,
|
nuclear@2
|
90 JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
|
nuclear@2
|
91 JDIMENSION in_row_groups_avail,
|
nuclear@2
|
92 JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
|
nuclear@2
|
93 JDIMENSION out_rows_avail)
|
nuclear@2
|
94 {
|
nuclear@2
|
95 my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
|
nuclear@2
|
96 int ci;
|
nuclear@2
|
97 jpeg_component_info * compptr;
|
nuclear@2
|
98 JDIMENSION num_rows;
|
nuclear@2
|
99
|
nuclear@2
|
100 /* Fill the conversion buffer, if it's empty */
|
nuclear@2
|
101 if (upsample->next_row_out >= cinfo->max_v_samp_factor) {
|
nuclear@2
|
102 for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
|
nuclear@2
|
103 ci++, compptr++) {
|
nuclear@2
|
104 /* Invoke per-component upsample method. Notice we pass a POINTER
|
nuclear@2
|
105 * to color_buf[ci], so that fullsize_upsample can change it.
|
nuclear@2
|
106 */
|
nuclear@2
|
107 (*upsample->methods[ci]) (cinfo, compptr,
|
nuclear@2
|
108 input_buf[ci] + (*in_row_group_ctr * upsample->rowgroup_height[ci]),
|
nuclear@2
|
109 upsample->color_buf + ci);
|
nuclear@2
|
110 }
|
nuclear@2
|
111 upsample->next_row_out = 0;
|
nuclear@2
|
112 }
|
nuclear@2
|
113
|
nuclear@2
|
114 /* Color-convert and emit rows */
|
nuclear@2
|
115
|
nuclear@2
|
116 /* How many we have in the buffer: */
|
nuclear@2
|
117 num_rows = (JDIMENSION) (cinfo->max_v_samp_factor - upsample->next_row_out);
|
nuclear@2
|
118 /* Not more than the distance to the end of the image. Need this test
|
nuclear@2
|
119 * in case the image height is not a multiple of max_v_samp_factor:
|
nuclear@2
|
120 */
|
nuclear@2
|
121 if (num_rows > upsample->rows_to_go)
|
nuclear@2
|
122 num_rows = upsample->rows_to_go;
|
nuclear@2
|
123 /* And not more than what the client can accept: */
|
nuclear@2
|
124 out_rows_avail -= *out_row_ctr;
|
nuclear@2
|
125 if (num_rows > out_rows_avail)
|
nuclear@2
|
126 num_rows = out_rows_avail;
|
nuclear@2
|
127
|
nuclear@2
|
128 (*cinfo->cconvert->color_convert) (cinfo, upsample->color_buf,
|
nuclear@2
|
129 (JDIMENSION) upsample->next_row_out,
|
nuclear@2
|
130 output_buf + *out_row_ctr,
|
nuclear@2
|
131 (int) num_rows);
|
nuclear@2
|
132
|
nuclear@2
|
133 /* Adjust counts */
|
nuclear@2
|
134 *out_row_ctr += num_rows;
|
nuclear@2
|
135 upsample->rows_to_go -= num_rows;
|
nuclear@2
|
136 upsample->next_row_out += num_rows;
|
nuclear@2
|
137 /* When the buffer is emptied, declare this input row group consumed */
|
nuclear@2
|
138 if (upsample->next_row_out >= cinfo->max_v_samp_factor)
|
nuclear@2
|
139 (*in_row_group_ctr)++;
|
nuclear@2
|
140 }
|
nuclear@2
|
141
|
nuclear@2
|
142
|
nuclear@2
|
143 /*
|
nuclear@2
|
144 * These are the routines invoked by sep_upsample to upsample pixel values
|
nuclear@2
|
145 * of a single component. One row group is processed per call.
|
nuclear@2
|
146 */
|
nuclear@2
|
147
|
nuclear@2
|
148
|
nuclear@2
|
149 /*
|
nuclear@2
|
150 * For full-size components, we just make color_buf[ci] point at the
|
nuclear@2
|
151 * input buffer, and thus avoid copying any data. Note that this is
|
nuclear@2
|
152 * safe only because sep_upsample doesn't declare the input row group
|
nuclear@2
|
153 * "consumed" until we are done color converting and emitting it.
|
nuclear@2
|
154 */
|
nuclear@2
|
155
|
nuclear@2
|
156 METHODDEF(void)
|
nuclear@2
|
157 fullsize_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
nuclear@2
|
158 JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
|
nuclear@2
|
159 {
|
nuclear@2
|
160 *output_data_ptr = input_data;
|
nuclear@2
|
161 }
|
nuclear@2
|
162
|
nuclear@2
|
163
|
nuclear@2
|
164 /*
|
nuclear@2
|
165 * This is a no-op version used for "uninteresting" components.
|
nuclear@2
|
166 * These components will not be referenced by color conversion.
|
nuclear@2
|
167 */
|
nuclear@2
|
168
|
nuclear@2
|
169 METHODDEF(void)
|
nuclear@2
|
170 noop_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
nuclear@2
|
171 JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
|
nuclear@2
|
172 {
|
nuclear@2
|
173 *output_data_ptr = NULL; /* safety check */
|
nuclear@2
|
174 }
|
nuclear@2
|
175
|
nuclear@2
|
176
|
nuclear@2
|
177 /*
|
nuclear@2
|
178 * This version handles any integral sampling ratios.
|
nuclear@2
|
179 * This is not used for typical JPEG files, so it need not be fast.
|
nuclear@2
|
180 * Nor, for that matter, is it particularly accurate: the algorithm is
|
nuclear@2
|
181 * simple replication of the input pixel onto the corresponding output
|
nuclear@2
|
182 * pixels. The hi-falutin sampling literature refers to this as a
|
nuclear@2
|
183 * "box filter". A box filter tends to introduce visible artifacts,
|
nuclear@2
|
184 * so if you are actually going to use 3:1 or 4:1 sampling ratios
|
nuclear@2
|
185 * you would be well advised to improve this code.
|
nuclear@2
|
186 */
|
nuclear@2
|
187
|
nuclear@2
|
188 METHODDEF(void)
|
nuclear@2
|
189 int_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
nuclear@2
|
190 JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
|
nuclear@2
|
191 {
|
nuclear@2
|
192 my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
|
nuclear@2
|
193 JSAMPARRAY output_data = *output_data_ptr;
|
nuclear@2
|
194 register JSAMPROW inptr, outptr;
|
nuclear@2
|
195 register JSAMPLE invalue;
|
nuclear@2
|
196 register int h;
|
nuclear@2
|
197 JSAMPROW outend;
|
nuclear@2
|
198 int h_expand, v_expand;
|
nuclear@2
|
199 int inrow, outrow;
|
nuclear@2
|
200
|
nuclear@2
|
201 h_expand = upsample->h_expand[compptr->component_index];
|
nuclear@2
|
202 v_expand = upsample->v_expand[compptr->component_index];
|
nuclear@2
|
203
|
nuclear@2
|
204 inrow = outrow = 0;
|
nuclear@2
|
205 while (outrow < cinfo->max_v_samp_factor) {
|
nuclear@2
|
206 /* Generate one output row with proper horizontal expansion */
|
nuclear@2
|
207 inptr = input_data[inrow];
|
nuclear@2
|
208 outptr = output_data[outrow];
|
nuclear@2
|
209 outend = outptr + cinfo->output_width;
|
nuclear@2
|
210 while (outptr < outend) {
|
nuclear@2
|
211 invalue = *inptr++; /* don't need GETJSAMPLE() here */
|
nuclear@2
|
212 for (h = h_expand; h > 0; h--) {
|
nuclear@2
|
213 *outptr++ = invalue;
|
nuclear@2
|
214 }
|
nuclear@2
|
215 }
|
nuclear@2
|
216 /* Generate any additional output rows by duplicating the first one */
|
nuclear@2
|
217 if (v_expand > 1) {
|
nuclear@2
|
218 jcopy_sample_rows(output_data, outrow, output_data, outrow+1,
|
nuclear@2
|
219 v_expand-1, cinfo->output_width);
|
nuclear@2
|
220 }
|
nuclear@2
|
221 inrow++;
|
nuclear@2
|
222 outrow += v_expand;
|
nuclear@2
|
223 }
|
nuclear@2
|
224 }
|
nuclear@2
|
225
|
nuclear@2
|
226
|
nuclear@2
|
227 /*
|
nuclear@2
|
228 * Fast processing for the common case of 2:1 horizontal and 1:1 vertical.
|
nuclear@2
|
229 * It's still a box filter.
|
nuclear@2
|
230 */
|
nuclear@2
|
231
|
nuclear@2
|
232 METHODDEF(void)
|
nuclear@2
|
233 h2v1_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
nuclear@2
|
234 JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
|
nuclear@2
|
235 {
|
nuclear@2
|
236 JSAMPARRAY output_data = *output_data_ptr;
|
nuclear@2
|
237 register JSAMPROW inptr, outptr;
|
nuclear@2
|
238 register JSAMPLE invalue;
|
nuclear@2
|
239 JSAMPROW outend;
|
nuclear@2
|
240 int inrow;
|
nuclear@2
|
241
|
nuclear@2
|
242 for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) {
|
nuclear@2
|
243 inptr = input_data[inrow];
|
nuclear@2
|
244 outptr = output_data[inrow];
|
nuclear@2
|
245 outend = outptr + cinfo->output_width;
|
nuclear@2
|
246 while (outptr < outend) {
|
nuclear@2
|
247 invalue = *inptr++; /* don't need GETJSAMPLE() here */
|
nuclear@2
|
248 *outptr++ = invalue;
|
nuclear@2
|
249 *outptr++ = invalue;
|
nuclear@2
|
250 }
|
nuclear@2
|
251 }
|
nuclear@2
|
252 }
|
nuclear@2
|
253
|
nuclear@2
|
254
|
nuclear@2
|
255 /*
|
nuclear@2
|
256 * Fast processing for the common case of 2:1 horizontal and 2:1 vertical.
|
nuclear@2
|
257 * It's still a box filter.
|
nuclear@2
|
258 */
|
nuclear@2
|
259
|
nuclear@2
|
260 METHODDEF(void)
|
nuclear@2
|
261 h2v2_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
nuclear@2
|
262 JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
|
nuclear@2
|
263 {
|
nuclear@2
|
264 JSAMPARRAY output_data = *output_data_ptr;
|
nuclear@2
|
265 register JSAMPROW inptr, outptr;
|
nuclear@2
|
266 register JSAMPLE invalue;
|
nuclear@2
|
267 JSAMPROW outend;
|
nuclear@2
|
268 int inrow, outrow;
|
nuclear@2
|
269
|
nuclear@2
|
270 inrow = outrow = 0;
|
nuclear@2
|
271 while (outrow < cinfo->max_v_samp_factor) {
|
nuclear@2
|
272 inptr = input_data[inrow];
|
nuclear@2
|
273 outptr = output_data[outrow];
|
nuclear@2
|
274 outend = outptr + cinfo->output_width;
|
nuclear@2
|
275 while (outptr < outend) {
|
nuclear@2
|
276 invalue = *inptr++; /* don't need GETJSAMPLE() here */
|
nuclear@2
|
277 *outptr++ = invalue;
|
nuclear@2
|
278 *outptr++ = invalue;
|
nuclear@2
|
279 }
|
nuclear@2
|
280 jcopy_sample_rows(output_data, outrow, output_data, outrow+1,
|
nuclear@2
|
281 1, cinfo->output_width);
|
nuclear@2
|
282 inrow++;
|
nuclear@2
|
283 outrow += 2;
|
nuclear@2
|
284 }
|
nuclear@2
|
285 }
|
nuclear@2
|
286
|
nuclear@2
|
287
|
nuclear@2
|
288 /*
|
nuclear@2
|
289 * Fancy processing for the common case of 2:1 horizontal and 1:1 vertical.
|
nuclear@2
|
290 *
|
nuclear@2
|
291 * The upsampling algorithm is linear interpolation between pixel centers,
|
nuclear@2
|
292 * also known as a "triangle filter". This is a good compromise between
|
nuclear@2
|
293 * speed and visual quality. The centers of the output pixels are 1/4 and 3/4
|
nuclear@2
|
294 * of the way between input pixel centers.
|
nuclear@2
|
295 *
|
nuclear@2
|
296 * A note about the "bias" calculations: when rounding fractional values to
|
nuclear@2
|
297 * integer, we do not want to always round 0.5 up to the next integer.
|
nuclear@2
|
298 * If we did that, we'd introduce a noticeable bias towards larger values.
|
nuclear@2
|
299 * Instead, this code is arranged so that 0.5 will be rounded up or down at
|
nuclear@2
|
300 * alternate pixel locations (a simple ordered dither pattern).
|
nuclear@2
|
301 */
|
nuclear@2
|
302
|
nuclear@2
|
303 METHODDEF(void)
|
nuclear@2
|
304 h2v1_fancy_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
nuclear@2
|
305 JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
|
nuclear@2
|
306 {
|
nuclear@2
|
307 JSAMPARRAY output_data = *output_data_ptr;
|
nuclear@2
|
308 register JSAMPROW inptr, outptr;
|
nuclear@2
|
309 register int invalue;
|
nuclear@2
|
310 register JDIMENSION colctr;
|
nuclear@2
|
311 int inrow;
|
nuclear@2
|
312
|
nuclear@2
|
313 for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) {
|
nuclear@2
|
314 inptr = input_data[inrow];
|
nuclear@2
|
315 outptr = output_data[inrow];
|
nuclear@2
|
316 /* Special case for first column */
|
nuclear@2
|
317 invalue = GETJSAMPLE(*inptr++);
|
nuclear@2
|
318 *outptr++ = (JSAMPLE) invalue;
|
nuclear@2
|
319 *outptr++ = (JSAMPLE) ((invalue * 3 + GETJSAMPLE(*inptr) + 2) >> 2);
|
nuclear@2
|
320
|
nuclear@2
|
321 for (colctr = compptr->downsampled_width - 2; colctr > 0; colctr--) {
|
nuclear@2
|
322 /* General case: 3/4 * nearer pixel + 1/4 * further pixel */
|
nuclear@2
|
323 invalue = GETJSAMPLE(*inptr++) * 3;
|
nuclear@2
|
324 *outptr++ = (JSAMPLE) ((invalue + GETJSAMPLE(inptr[-2]) + 1) >> 2);
|
nuclear@2
|
325 *outptr++ = (JSAMPLE) ((invalue + GETJSAMPLE(*inptr) + 2) >> 2);
|
nuclear@2
|
326 }
|
nuclear@2
|
327
|
nuclear@2
|
328 /* Special case for last column */
|
nuclear@2
|
329 invalue = GETJSAMPLE(*inptr);
|
nuclear@2
|
330 *outptr++ = (JSAMPLE) ((invalue * 3 + GETJSAMPLE(inptr[-1]) + 1) >> 2);
|
nuclear@2
|
331 *outptr++ = (JSAMPLE) invalue;
|
nuclear@2
|
332 }
|
nuclear@2
|
333 }
|
nuclear@2
|
334
|
nuclear@2
|
335
|
nuclear@2
|
336 /*
|
nuclear@2
|
337 * Fancy processing for the common case of 2:1 horizontal and 2:1 vertical.
|
nuclear@2
|
338 * Again a triangle filter; see comments for h2v1 case, above.
|
nuclear@2
|
339 *
|
nuclear@2
|
340 * It is OK for us to reference the adjacent input rows because we demanded
|
nuclear@2
|
341 * context from the main buffer controller (see initialization code).
|
nuclear@2
|
342 */
|
nuclear@2
|
343
|
nuclear@2
|
344 METHODDEF(void)
|
nuclear@2
|
345 h2v2_fancy_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
nuclear@2
|
346 JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
|
nuclear@2
|
347 {
|
nuclear@2
|
348 JSAMPARRAY output_data = *output_data_ptr;
|
nuclear@2
|
349 register JSAMPROW inptr0, inptr1, outptr;
|
nuclear@2
|
350 #if BITS_IN_JSAMPLE == 8
|
nuclear@2
|
351 register int thiscolsum, lastcolsum, nextcolsum;
|
nuclear@2
|
352 #else
|
nuclear@2
|
353 register INT32 thiscolsum, lastcolsum, nextcolsum;
|
nuclear@2
|
354 #endif
|
nuclear@2
|
355 register JDIMENSION colctr;
|
nuclear@2
|
356 int inrow, outrow, v;
|
nuclear@2
|
357
|
nuclear@2
|
358 inrow = outrow = 0;
|
nuclear@2
|
359 while (outrow < cinfo->max_v_samp_factor) {
|
nuclear@2
|
360 for (v = 0; v < 2; v++) {
|
nuclear@2
|
361 /* inptr0 points to nearest input row, inptr1 points to next nearest */
|
nuclear@2
|
362 inptr0 = input_data[inrow];
|
nuclear@2
|
363 if (v == 0) /* next nearest is row above */
|
nuclear@2
|
364 inptr1 = input_data[inrow-1];
|
nuclear@2
|
365 else /* next nearest is row below */
|
nuclear@2
|
366 inptr1 = input_data[inrow+1];
|
nuclear@2
|
367 outptr = output_data[outrow++];
|
nuclear@2
|
368
|
nuclear@2
|
369 /* Special case for first column */
|
nuclear@2
|
370 thiscolsum = GETJSAMPLE(*inptr0++) * 3 + GETJSAMPLE(*inptr1++);
|
nuclear@2
|
371 nextcolsum = GETJSAMPLE(*inptr0++) * 3 + GETJSAMPLE(*inptr1++);
|
nuclear@2
|
372 *outptr++ = (JSAMPLE) ((thiscolsum * 4 + 8) >> 4);
|
nuclear@2
|
373 *outptr++ = (JSAMPLE) ((thiscolsum * 3 + nextcolsum + 7) >> 4);
|
nuclear@2
|
374 lastcolsum = thiscolsum; thiscolsum = nextcolsum;
|
nuclear@2
|
375
|
nuclear@2
|
376 for (colctr = compptr->downsampled_width - 2; colctr > 0; colctr--) {
|
nuclear@2
|
377 /* General case: 3/4 * nearer pixel + 1/4 * further pixel in each */
|
nuclear@2
|
378 /* dimension, thus 9/16, 3/16, 3/16, 1/16 overall */
|
nuclear@2
|
379 nextcolsum = GETJSAMPLE(*inptr0++) * 3 + GETJSAMPLE(*inptr1++);
|
nuclear@2
|
380 *outptr++ = (JSAMPLE) ((thiscolsum * 3 + lastcolsum + 8) >> 4);
|
nuclear@2
|
381 *outptr++ = (JSAMPLE) ((thiscolsum * 3 + nextcolsum + 7) >> 4);
|
nuclear@2
|
382 lastcolsum = thiscolsum; thiscolsum = nextcolsum;
|
nuclear@2
|
383 }
|
nuclear@2
|
384
|
nuclear@2
|
385 /* Special case for last column */
|
nuclear@2
|
386 *outptr++ = (JSAMPLE) ((thiscolsum * 3 + lastcolsum + 8) >> 4);
|
nuclear@2
|
387 *outptr++ = (JSAMPLE) ((thiscolsum * 4 + 7) >> 4);
|
nuclear@2
|
388 }
|
nuclear@2
|
389 inrow++;
|
nuclear@2
|
390 }
|
nuclear@2
|
391 }
|
nuclear@2
|
392
|
nuclear@2
|
393
|
nuclear@2
|
394 /*
|
nuclear@2
|
395 * Module initialization routine for upsampling.
|
nuclear@2
|
396 */
|
nuclear@2
|
397
|
nuclear@2
|
398 GLOBAL(void)
|
nuclear@2
|
399 jinit_upsampler (j_decompress_ptr cinfo)
|
nuclear@2
|
400 {
|
nuclear@2
|
401 my_upsample_ptr upsample;
|
nuclear@2
|
402 int ci;
|
nuclear@2
|
403 jpeg_component_info * compptr;
|
nuclear@2
|
404 boolean need_buffer, do_fancy;
|
nuclear@2
|
405 int h_in_group, v_in_group, h_out_group, v_out_group;
|
nuclear@2
|
406
|
nuclear@2
|
407 upsample = (my_upsample_ptr)
|
nuclear@2
|
408 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
nuclear@2
|
409 SIZEOF(my_upsampler));
|
nuclear@2
|
410 cinfo->upsample = (struct jpeg_upsampler *) upsample;
|
nuclear@2
|
411 upsample->pub.start_pass = start_pass_upsample;
|
nuclear@2
|
412 upsample->pub.upsample = sep_upsample;
|
nuclear@2
|
413 upsample->pub.need_context_rows = FALSE; /* until we find out differently */
|
nuclear@2
|
414
|
nuclear@2
|
415 if (cinfo->CCIR601_sampling) /* this isn't supported */
|
nuclear@2
|
416 ERREXIT(cinfo, JERR_CCIR601_NOTIMPL);
|
nuclear@2
|
417
|
nuclear@2
|
418 /* jdmainct.c doesn't support context rows when min_DCT_scaled_size = 1,
|
nuclear@2
|
419 * so don't ask for it.
|
nuclear@2
|
420 */
|
nuclear@2
|
421 do_fancy = cinfo->do_fancy_upsampling && cinfo->min_DCT_scaled_size > 1;
|
nuclear@2
|
422
|
nuclear@2
|
423 /* Verify we can handle the sampling factors, select per-component methods,
|
nuclear@2
|
424 * and create storage as needed.
|
nuclear@2
|
425 */
|
nuclear@2
|
426 for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
|
nuclear@2
|
427 ci++, compptr++) {
|
nuclear@2
|
428 /* Compute size of an "input group" after IDCT scaling. This many samples
|
nuclear@2
|
429 * are to be converted to max_h_samp_factor * max_v_samp_factor pixels.
|
nuclear@2
|
430 */
|
nuclear@2
|
431 h_in_group = (compptr->h_samp_factor * compptr->DCT_scaled_size) /
|
nuclear@2
|
432 cinfo->min_DCT_scaled_size;
|
nuclear@2
|
433 v_in_group = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
|
nuclear@2
|
434 cinfo->min_DCT_scaled_size;
|
nuclear@2
|
435 h_out_group = cinfo->max_h_samp_factor;
|
nuclear@2
|
436 v_out_group = cinfo->max_v_samp_factor;
|
nuclear@2
|
437 upsample->rowgroup_height[ci] = v_in_group; /* save for use later */
|
nuclear@2
|
438 need_buffer = TRUE;
|
nuclear@2
|
439 if (! compptr->component_needed) {
|
nuclear@2
|
440 /* Don't bother to upsample an uninteresting component. */
|
nuclear@2
|
441 upsample->methods[ci] = noop_upsample;
|
nuclear@2
|
442 need_buffer = FALSE;
|
nuclear@2
|
443 } else if (h_in_group == h_out_group && v_in_group == v_out_group) {
|
nuclear@2
|
444 /* Fullsize components can be processed without any work. */
|
nuclear@2
|
445 upsample->methods[ci] = fullsize_upsample;
|
nuclear@2
|
446 need_buffer = FALSE;
|
nuclear@2
|
447 } else if (h_in_group * 2 == h_out_group &&
|
nuclear@2
|
448 v_in_group == v_out_group) {
|
nuclear@2
|
449 /* Special cases for 2h1v upsampling */
|
nuclear@2
|
450 if (do_fancy && compptr->downsampled_width > 2)
|
nuclear@2
|
451 upsample->methods[ci] = h2v1_fancy_upsample;
|
nuclear@2
|
452 else
|
nuclear@2
|
453 upsample->methods[ci] = h2v1_upsample;
|
nuclear@2
|
454 } else if (h_in_group * 2 == h_out_group &&
|
nuclear@2
|
455 v_in_group * 2 == v_out_group) {
|
nuclear@2
|
456 /* Special cases for 2h2v upsampling */
|
nuclear@2
|
457 if (do_fancy && compptr->downsampled_width > 2) {
|
nuclear@2
|
458 upsample->methods[ci] = h2v2_fancy_upsample;
|
nuclear@2
|
459 upsample->pub.need_context_rows = TRUE;
|
nuclear@2
|
460 } else
|
nuclear@2
|
461 upsample->methods[ci] = h2v2_upsample;
|
nuclear@2
|
462 } else if ((h_out_group % h_in_group) == 0 &&
|
nuclear@2
|
463 (v_out_group % v_in_group) == 0) {
|
nuclear@2
|
464 /* Generic integral-factors upsampling method */
|
nuclear@2
|
465 upsample->methods[ci] = int_upsample;
|
nuclear@2
|
466 upsample->h_expand[ci] = (UINT8) (h_out_group / h_in_group);
|
nuclear@2
|
467 upsample->v_expand[ci] = (UINT8) (v_out_group / v_in_group);
|
nuclear@2
|
468 } else
|
nuclear@2
|
469 ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL);
|
nuclear@2
|
470 if (need_buffer) {
|
nuclear@2
|
471 upsample->color_buf[ci] = (*cinfo->mem->alloc_sarray)
|
nuclear@2
|
472 ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
nuclear@2
|
473 (JDIMENSION) jround_up((long) cinfo->output_width,
|
nuclear@2
|
474 (long) cinfo->max_h_samp_factor),
|
nuclear@2
|
475 (JDIMENSION) cinfo->max_v_samp_factor);
|
nuclear@2
|
476 }
|
nuclear@2
|
477 }
|
nuclear@2
|
478 }
|