diff options
Diffstat (limited to 'libraries/irrlicht-1.8/source/Irrlicht/jpeglib/jdsample.c')
-rw-r--r-- | libraries/irrlicht-1.8/source/Irrlicht/jpeglib/jdsample.c | 722 |
1 files changed, 361 insertions, 361 deletions
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/jpeglib/jdsample.c b/libraries/irrlicht-1.8/source/Irrlicht/jpeglib/jdsample.c index 94f9599..7bc8885 100644 --- a/libraries/irrlicht-1.8/source/Irrlicht/jpeglib/jdsample.c +++ b/libraries/irrlicht-1.8/source/Irrlicht/jpeglib/jdsample.c | |||
@@ -1,361 +1,361 @@ | |||
1 | /* | 1 | /* |
2 | * jdsample.c | 2 | * jdsample.c |
3 | * | 3 | * |
4 | * Copyright (C) 1991-1996, Thomas G. Lane. | 4 | * Copyright (C) 1991-1996, Thomas G. Lane. |
5 | * Modified 2002-2008 by Guido Vollbeding. | 5 | * Modified 2002-2008 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 upsampling routines. | 9 | * This file contains upsampling routines. |
10 | * | 10 | * |
11 | * Upsampling input data is counted in "row groups". A row group | 11 | * Upsampling input data is counted in "row groups". A row group |
12 | * is defined to be (v_samp_factor * DCT_v_scaled_size / min_DCT_v_scaled_size) | 12 | * is defined to be (v_samp_factor * DCT_v_scaled_size / min_DCT_v_scaled_size) |
13 | * sample rows of each component. Upsampling will normally produce | 13 | * sample rows of each component. Upsampling will normally produce |
14 | * max_v_samp_factor pixel rows from each row group (but this could vary | 14 | * max_v_samp_factor pixel rows from each row group (but this could vary |
15 | * if the upsampler is applying a scale factor of its own). | 15 | * if the upsampler is applying a scale factor of its own). |
16 | * | 16 | * |
17 | * An excellent reference for image resampling is | 17 | * An excellent reference for image resampling is |
18 | * Digital Image Warping, George Wolberg, 1990. | 18 | * Digital Image Warping, George Wolberg, 1990. |
19 | * Pub. by IEEE Computer Society Press, Los Alamitos, CA. ISBN 0-8186-8944-7. | 19 | * Pub. by IEEE Computer Society Press, Los Alamitos, CA. ISBN 0-8186-8944-7. |
20 | */ | 20 | */ |
21 | 21 | ||
22 | #define JPEG_INTERNALS | 22 | #define JPEG_INTERNALS |
23 | #include "jinclude.h" | 23 | #include "jinclude.h" |
24 | #include "jpeglib.h" | 24 | #include "jpeglib.h" |
25 | 25 | ||
26 | 26 | ||
27 | /* Pointer to routine to upsample a single component */ | 27 | /* Pointer to routine to upsample a single component */ |
28 | typedef JMETHOD(void, upsample1_ptr, | 28 | typedef JMETHOD(void, upsample1_ptr, |
29 | (j_decompress_ptr cinfo, jpeg_component_info * compptr, | 29 | (j_decompress_ptr cinfo, jpeg_component_info * compptr, |
30 | JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)); | 30 | JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)); |
31 | 31 | ||
32 | /* Private subobject */ | 32 | /* Private subobject */ |
33 | 33 | ||
34 | typedef struct { | 34 | typedef struct { |
35 | struct jpeg_upsampler pub; /* public fields */ | 35 | struct jpeg_upsampler pub; /* public fields */ |
36 | 36 | ||
37 | /* Color conversion buffer. When using separate upsampling and color | 37 | /* Color conversion buffer. When using separate upsampling and color |
38 | * conversion steps, this buffer holds one upsampled row group until it | 38 | * conversion steps, this buffer holds one upsampled row group until it |
39 | * has been color converted and output. | 39 | * has been color converted and output. |
40 | * Note: we do not allocate any storage for component(s) which are full-size, | 40 | * Note: we do not allocate any storage for component(s) which are full-size, |
41 | * ie do not need rescaling. The corresponding entry of color_buf[] is | 41 | * ie do not need rescaling. The corresponding entry of color_buf[] is |
42 | * simply set to point to the input data array, thereby avoiding copying. | 42 | * simply set to point to the input data array, thereby avoiding copying. |
43 | */ | 43 | */ |
44 | JSAMPARRAY color_buf[MAX_COMPONENTS]; | 44 | JSAMPARRAY color_buf[MAX_COMPONENTS]; |
45 | 45 | ||
46 | /* Per-component upsampling method pointers */ | 46 | /* Per-component upsampling method pointers */ |
47 | upsample1_ptr methods[MAX_COMPONENTS]; | 47 | upsample1_ptr methods[MAX_COMPONENTS]; |
48 | 48 | ||
49 | int next_row_out; /* counts rows emitted from color_buf */ | 49 | int next_row_out; /* counts rows emitted from color_buf */ |
50 | JDIMENSION rows_to_go; /* counts rows remaining in image */ | 50 | JDIMENSION rows_to_go; /* counts rows remaining in image */ |
51 | 51 | ||
52 | /* Height of an input row group for each component. */ | 52 | /* Height of an input row group for each component. */ |
53 | int rowgroup_height[MAX_COMPONENTS]; | 53 | int rowgroup_height[MAX_COMPONENTS]; |
54 | 54 | ||
55 | /* These arrays save pixel expansion factors so that int_expand need not | 55 | /* These arrays save pixel expansion factors so that int_expand need not |
56 | * recompute them each time. They are unused for other upsampling methods. | 56 | * recompute them each time. They are unused for other upsampling methods. |
57 | */ | 57 | */ |
58 | UINT8 h_expand[MAX_COMPONENTS]; | 58 | UINT8 h_expand[MAX_COMPONENTS]; |
59 | UINT8 v_expand[MAX_COMPONENTS]; | 59 | UINT8 v_expand[MAX_COMPONENTS]; |
60 | } my_upsampler; | 60 | } my_upsampler; |
61 | 61 | ||
62 | typedef my_upsampler * my_upsample_ptr; | 62 | typedef my_upsampler * my_upsample_ptr; |
63 | 63 | ||
64 | 64 | ||
65 | /* | 65 | /* |
66 | * Initialize for an upsampling pass. | 66 | * Initialize for an upsampling pass. |
67 | */ | 67 | */ |
68 | 68 | ||
69 | METHODDEF(void) | 69 | METHODDEF(void) |
70 | start_pass_upsample (j_decompress_ptr cinfo) | 70 | start_pass_upsample (j_decompress_ptr cinfo) |
71 | { | 71 | { |
72 | my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample; | 72 | my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample; |
73 | 73 | ||
74 | /* Mark the conversion buffer empty */ | 74 | /* Mark the conversion buffer empty */ |
75 | upsample->next_row_out = cinfo->max_v_samp_factor; | 75 | upsample->next_row_out = cinfo->max_v_samp_factor; |
76 | /* Initialize total-height counter for detecting bottom of image */ | 76 | /* Initialize total-height counter for detecting bottom of image */ |
77 | upsample->rows_to_go = cinfo->output_height; | 77 | upsample->rows_to_go = cinfo->output_height; |
78 | } | 78 | } |
79 | 79 | ||
80 | 80 | ||
81 | /* | 81 | /* |
82 | * Control routine to do upsampling (and color conversion). | 82 | * Control routine to do upsampling (and color conversion). |
83 | * | 83 | * |
84 | * In this version we upsample each component independently. | 84 | * In this version we upsample each component independently. |
85 | * We upsample one row group into the conversion buffer, then apply | 85 | * We upsample one row group into the conversion buffer, then apply |
86 | * color conversion a row at a time. | 86 | * color conversion a row at a time. |
87 | */ | 87 | */ |
88 | 88 | ||
89 | METHODDEF(void) | 89 | METHODDEF(void) |
90 | sep_upsample (j_decompress_ptr cinfo, | 90 | sep_upsample (j_decompress_ptr cinfo, |
91 | JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr, | 91 | JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr, |
92 | JDIMENSION in_row_groups_avail, | 92 | JDIMENSION in_row_groups_avail, |
93 | JSAMPARRAY output_buf, JDIMENSION *out_row_ctr, | 93 | JSAMPARRAY output_buf, JDIMENSION *out_row_ctr, |
94 | JDIMENSION out_rows_avail) | 94 | JDIMENSION out_rows_avail) |
95 | { | 95 | { |
96 | my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample; | 96 | my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample; |
97 | int ci; | 97 | int ci; |
98 | jpeg_component_info * compptr; | 98 | jpeg_component_info * compptr; |
99 | JDIMENSION num_rows; | 99 | JDIMENSION num_rows; |
100 | 100 | ||
101 | /* Fill the conversion buffer, if it's empty */ | 101 | /* Fill the conversion buffer, if it's empty */ |
102 | if (upsample->next_row_out >= cinfo->max_v_samp_factor) { | 102 | if (upsample->next_row_out >= cinfo->max_v_samp_factor) { |
103 | for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; | 103 | for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; |
104 | ci++, compptr++) { | 104 | ci++, compptr++) { |
105 | /* Invoke per-component upsample method. Notice we pass a POINTER | 105 | /* Invoke per-component upsample method. Notice we pass a POINTER |
106 | * to color_buf[ci], so that fullsize_upsample can change it. | 106 | * to color_buf[ci], so that fullsize_upsample can change it. |
107 | */ | 107 | */ |
108 | (*upsample->methods[ci]) (cinfo, compptr, | 108 | (*upsample->methods[ci]) (cinfo, compptr, |
109 | input_buf[ci] + (*in_row_group_ctr * upsample->rowgroup_height[ci]), | 109 | input_buf[ci] + (*in_row_group_ctr * upsample->rowgroup_height[ci]), |
110 | upsample->color_buf + ci); | 110 | upsample->color_buf + ci); |
111 | } | 111 | } |
112 | upsample->next_row_out = 0; | 112 | upsample->next_row_out = 0; |
113 | } | 113 | } |
114 | 114 | ||
115 | /* Color-convert and emit rows */ | 115 | /* Color-convert and emit rows */ |
116 | 116 | ||
117 | /* How many we have in the buffer: */ | 117 | /* How many we have in the buffer: */ |
118 | num_rows = (JDIMENSION) (cinfo->max_v_samp_factor - upsample->next_row_out); | 118 | num_rows = (JDIMENSION) (cinfo->max_v_samp_factor - upsample->next_row_out); |
119 | /* Not more than the distance to the end of the image. Need this test | 119 | /* Not more than the distance to the end of the image. Need this test |
120 | * in case the image height is not a multiple of max_v_samp_factor: | 120 | * in case the image height is not a multiple of max_v_samp_factor: |
121 | */ | 121 | */ |
122 | if (num_rows > upsample->rows_to_go) | 122 | if (num_rows > upsample->rows_to_go) |
123 | num_rows = upsample->rows_to_go; | 123 | num_rows = upsample->rows_to_go; |
124 | /* And not more than what the client can accept: */ | 124 | /* And not more than what the client can accept: */ |
125 | out_rows_avail -= *out_row_ctr; | 125 | out_rows_avail -= *out_row_ctr; |
126 | if (num_rows > out_rows_avail) | 126 | if (num_rows > out_rows_avail) |
127 | num_rows = out_rows_avail; | 127 | num_rows = out_rows_avail; |
128 | 128 | ||
129 | (*cinfo->cconvert->color_convert) (cinfo, upsample->color_buf, | 129 | (*cinfo->cconvert->color_convert) (cinfo, upsample->color_buf, |
130 | (JDIMENSION) upsample->next_row_out, | 130 | (JDIMENSION) upsample->next_row_out, |
131 | output_buf + *out_row_ctr, | 131 | output_buf + *out_row_ctr, |
132 | (int) num_rows); | 132 | (int) num_rows); |
133 | 133 | ||
134 | /* Adjust counts */ | 134 | /* Adjust counts */ |
135 | *out_row_ctr += num_rows; | 135 | *out_row_ctr += num_rows; |
136 | upsample->rows_to_go -= num_rows; | 136 | upsample->rows_to_go -= num_rows; |
137 | upsample->next_row_out += num_rows; | 137 | upsample->next_row_out += num_rows; |
138 | /* When the buffer is emptied, declare this input row group consumed */ | 138 | /* When the buffer is emptied, declare this input row group consumed */ |
139 | if (upsample->next_row_out >= cinfo->max_v_samp_factor) | 139 | if (upsample->next_row_out >= cinfo->max_v_samp_factor) |
140 | (*in_row_group_ctr)++; | 140 | (*in_row_group_ctr)++; |
141 | } | 141 | } |
142 | 142 | ||
143 | 143 | ||
144 | /* | 144 | /* |
145 | * These are the routines invoked by sep_upsample to upsample pixel values | 145 | * These are the routines invoked by sep_upsample to upsample pixel values |
146 | * of a single component. One row group is processed per call. | 146 | * of a single component. One row group is processed per call. |
147 | */ | 147 | */ |
148 | 148 | ||
149 | 149 | ||
150 | /* | 150 | /* |
151 | * For full-size components, we just make color_buf[ci] point at the | 151 | * For full-size components, we just make color_buf[ci] point at the |
152 | * input buffer, and thus avoid copying any data. Note that this is | 152 | * input buffer, and thus avoid copying any data. Note that this is |
153 | * safe only because sep_upsample doesn't declare the input row group | 153 | * safe only because sep_upsample doesn't declare the input row group |
154 | * "consumed" until we are done color converting and emitting it. | 154 | * "consumed" until we are done color converting and emitting it. |
155 | */ | 155 | */ |
156 | 156 | ||
157 | METHODDEF(void) | 157 | METHODDEF(void) |
158 | fullsize_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr, | 158 | fullsize_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr, |
159 | JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr) | 159 | JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr) |
160 | { | 160 | { |
161 | *output_data_ptr = input_data; | 161 | *output_data_ptr = input_data; |
162 | } | 162 | } |
163 | 163 | ||
164 | 164 | ||
165 | /* | 165 | /* |
166 | * This is a no-op version used for "uninteresting" components. | 166 | * This is a no-op version used for "uninteresting" components. |
167 | * These components will not be referenced by color conversion. | 167 | * These components will not be referenced by color conversion. |
168 | */ | 168 | */ |
169 | 169 | ||
170 | METHODDEF(void) | 170 | METHODDEF(void) |
171 | noop_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr, | 171 | noop_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr, |
172 | JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr) | 172 | JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr) |
173 | { | 173 | { |
174 | *output_data_ptr = NULL; /* safety check */ | 174 | *output_data_ptr = NULL; /* safety check */ |
175 | } | 175 | } |
176 | 176 | ||
177 | 177 | ||
178 | /* | 178 | /* |
179 | * This version handles any integral sampling ratios. | 179 | * This version handles any integral sampling ratios. |
180 | * This is not used for typical JPEG files, so it need not be fast. | 180 | * This is not used for typical JPEG files, so it need not be fast. |
181 | * Nor, for that matter, is it particularly accurate: the algorithm is | 181 | * Nor, for that matter, is it particularly accurate: the algorithm is |
182 | * simple replication of the input pixel onto the corresponding output | 182 | * simple replication of the input pixel onto the corresponding output |
183 | * pixels. The hi-falutin sampling literature refers to this as a | 183 | * pixels. The hi-falutin sampling literature refers to this as a |
184 | * "box filter". A box filter tends to introduce visible artifacts, | 184 | * "box filter". A box filter tends to introduce visible artifacts, |
185 | * so if you are actually going to use 3:1 or 4:1 sampling ratios | 185 | * so if you are actually going to use 3:1 or 4:1 sampling ratios |
186 | * you would be well advised to improve this code. | 186 | * you would be well advised to improve this code. |
187 | */ | 187 | */ |
188 | 188 | ||
189 | METHODDEF(void) | 189 | METHODDEF(void) |
190 | int_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr, | 190 | int_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr, |
191 | JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr) | 191 | JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr) |
192 | { | 192 | { |
193 | my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample; | 193 | my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample; |
194 | JSAMPARRAY output_data = *output_data_ptr; | 194 | JSAMPARRAY output_data = *output_data_ptr; |
195 | register JSAMPROW inptr, outptr; | 195 | register JSAMPROW inptr, outptr; |
196 | register JSAMPLE invalue; | 196 | register JSAMPLE invalue; |
197 | register int h; | 197 | register int h; |
198 | JSAMPROW outend; | 198 | JSAMPROW outend; |
199 | int h_expand, v_expand; | 199 | int h_expand, v_expand; |
200 | int inrow, outrow; | 200 | int inrow, outrow; |
201 | 201 | ||
202 | h_expand = upsample->h_expand[compptr->component_index]; | 202 | h_expand = upsample->h_expand[compptr->component_index]; |
203 | v_expand = upsample->v_expand[compptr->component_index]; | 203 | v_expand = upsample->v_expand[compptr->component_index]; |
204 | 204 | ||
205 | inrow = outrow = 0; | 205 | inrow = outrow = 0; |
206 | while (outrow < cinfo->max_v_samp_factor) { | 206 | while (outrow < cinfo->max_v_samp_factor) { |
207 | /* Generate one output row with proper horizontal expansion */ | 207 | /* Generate one output row with proper horizontal expansion */ |
208 | inptr = input_data[inrow]; | 208 | inptr = input_data[inrow]; |
209 | outptr = output_data[outrow]; | 209 | outptr = output_data[outrow]; |
210 | outend = outptr + cinfo->output_width; | 210 | outend = outptr + cinfo->output_width; |
211 | while (outptr < outend) { | 211 | while (outptr < outend) { |
212 | invalue = *inptr++; /* don't need GETJSAMPLE() here */ | 212 | invalue = *inptr++; /* don't need GETJSAMPLE() here */ |
213 | for (h = h_expand; h > 0; h--) { | 213 | for (h = h_expand; h > 0; h--) { |
214 | *outptr++ = invalue; | 214 | *outptr++ = invalue; |
215 | } | 215 | } |
216 | } | 216 | } |
217 | /* Generate any additional output rows by duplicating the first one */ | 217 | /* Generate any additional output rows by duplicating the first one */ |
218 | if (v_expand > 1) { | 218 | if (v_expand > 1) { |
219 | jcopy_sample_rows(output_data, outrow, output_data, outrow+1, | 219 | jcopy_sample_rows(output_data, outrow, output_data, outrow+1, |
220 | v_expand-1, cinfo->output_width); | 220 | v_expand-1, cinfo->output_width); |
221 | } | 221 | } |
222 | inrow++; | 222 | inrow++; |
223 | outrow += v_expand; | 223 | outrow += v_expand; |
224 | } | 224 | } |
225 | } | 225 | } |
226 | 226 | ||
227 | 227 | ||
228 | /* | 228 | /* |
229 | * Fast processing for the common case of 2:1 horizontal and 1:1 vertical. | 229 | * Fast processing for the common case of 2:1 horizontal and 1:1 vertical. |
230 | * It's still a box filter. | 230 | * It's still a box filter. |
231 | */ | 231 | */ |
232 | 232 | ||
233 | METHODDEF(void) | 233 | METHODDEF(void) |
234 | h2v1_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr, | 234 | h2v1_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr, |
235 | JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr) | 235 | JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr) |
236 | { | 236 | { |
237 | JSAMPARRAY output_data = *output_data_ptr; | 237 | JSAMPARRAY output_data = *output_data_ptr; |
238 | register JSAMPROW inptr, outptr; | 238 | register JSAMPROW inptr, outptr; |
239 | register JSAMPLE invalue; | 239 | register JSAMPLE invalue; |
240 | JSAMPROW outend; | 240 | JSAMPROW outend; |
241 | int outrow; | 241 | int outrow; |
242 | 242 | ||
243 | for (outrow = 0; outrow < cinfo->max_v_samp_factor; outrow++) { | 243 | for (outrow = 0; outrow < cinfo->max_v_samp_factor; outrow++) { |
244 | inptr = input_data[outrow]; | 244 | inptr = input_data[outrow]; |
245 | outptr = output_data[outrow]; | 245 | outptr = output_data[outrow]; |
246 | outend = outptr + cinfo->output_width; | 246 | outend = outptr + cinfo->output_width; |
247 | while (outptr < outend) { | 247 | while (outptr < outend) { |
248 | invalue = *inptr++; /* don't need GETJSAMPLE() here */ | 248 | invalue = *inptr++; /* don't need GETJSAMPLE() here */ |
249 | *outptr++ = invalue; | 249 | *outptr++ = invalue; |
250 | *outptr++ = invalue; | 250 | *outptr++ = invalue; |
251 | } | 251 | } |
252 | } | 252 | } |
253 | } | 253 | } |
254 | 254 | ||
255 | 255 | ||
256 | /* | 256 | /* |
257 | * Fast processing for the common case of 2:1 horizontal and 2:1 vertical. | 257 | * Fast processing for the common case of 2:1 horizontal and 2:1 vertical. |
258 | * It's still a box filter. | 258 | * It's still a box filter. |
259 | */ | 259 | */ |
260 | 260 | ||
261 | METHODDEF(void) | 261 | METHODDEF(void) |
262 | h2v2_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr, | 262 | h2v2_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr, |
263 | JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr) | 263 | JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr) |
264 | { | 264 | { |
265 | JSAMPARRAY output_data = *output_data_ptr; | 265 | JSAMPARRAY output_data = *output_data_ptr; |
266 | register JSAMPROW inptr, outptr; | 266 | register JSAMPROW inptr, outptr; |
267 | register JSAMPLE invalue; | 267 | register JSAMPLE invalue; |
268 | JSAMPROW outend; | 268 | JSAMPROW outend; |
269 | int inrow, outrow; | 269 | int inrow, outrow; |
270 | 270 | ||
271 | inrow = outrow = 0; | 271 | inrow = outrow = 0; |
272 | while (outrow < cinfo->max_v_samp_factor) { | 272 | while (outrow < cinfo->max_v_samp_factor) { |
273 | inptr = input_data[inrow]; | 273 | inptr = input_data[inrow]; |
274 | outptr = output_data[outrow]; | 274 | outptr = output_data[outrow]; |
275 | outend = outptr + cinfo->output_width; | 275 | outend = outptr + cinfo->output_width; |
276 | while (outptr < outend) { | 276 | while (outptr < outend) { |
277 | invalue = *inptr++; /* don't need GETJSAMPLE() here */ | 277 | invalue = *inptr++; /* don't need GETJSAMPLE() here */ |
278 | *outptr++ = invalue; | 278 | *outptr++ = invalue; |
279 | *outptr++ = invalue; | 279 | *outptr++ = invalue; |
280 | } | 280 | } |
281 | jcopy_sample_rows(output_data, outrow, output_data, outrow+1, | 281 | jcopy_sample_rows(output_data, outrow, output_data, outrow+1, |
282 | 1, cinfo->output_width); | 282 | 1, cinfo->output_width); |
283 | inrow++; | 283 | inrow++; |
284 | outrow += 2; | 284 | outrow += 2; |
285 | } | 285 | } |
286 | } | 286 | } |
287 | 287 | ||
288 | 288 | ||
289 | /* | 289 | /* |
290 | * Module initialization routine for upsampling. | 290 | * Module initialization routine for upsampling. |
291 | */ | 291 | */ |
292 | 292 | ||
293 | GLOBAL(void) | 293 | GLOBAL(void) |
294 | jinit_upsampler (j_decompress_ptr cinfo) | 294 | jinit_upsampler (j_decompress_ptr cinfo) |
295 | { | 295 | { |
296 | my_upsample_ptr upsample; | 296 | my_upsample_ptr upsample; |
297 | int ci; | 297 | int ci; |
298 | jpeg_component_info * compptr; | 298 | jpeg_component_info * compptr; |
299 | boolean need_buffer; | 299 | boolean need_buffer; |
300 | int h_in_group, v_in_group, h_out_group, v_out_group; | 300 | int h_in_group, v_in_group, h_out_group, v_out_group; |
301 | 301 | ||
302 | upsample = (my_upsample_ptr) | 302 | upsample = (my_upsample_ptr) |
303 | (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, | 303 | (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, |
304 | SIZEOF(my_upsampler)); | 304 | SIZEOF(my_upsampler)); |
305 | cinfo->upsample = (struct jpeg_upsampler *) upsample; | 305 | cinfo->upsample = (struct jpeg_upsampler *) upsample; |
306 | upsample->pub.start_pass = start_pass_upsample; | 306 | upsample->pub.start_pass = start_pass_upsample; |
307 | upsample->pub.upsample = sep_upsample; | 307 | upsample->pub.upsample = sep_upsample; |
308 | upsample->pub.need_context_rows = FALSE; /* until we find out differently */ | 308 | upsample->pub.need_context_rows = FALSE; /* until we find out differently */ |
309 | 309 | ||
310 | if (cinfo->CCIR601_sampling) /* this isn't supported */ | 310 | if (cinfo->CCIR601_sampling) /* this isn't supported */ |
311 | ERREXIT(cinfo, JERR_CCIR601_NOTIMPL); | 311 | ERREXIT(cinfo, JERR_CCIR601_NOTIMPL); |
312 | 312 | ||
313 | /* Verify we can handle the sampling factors, select per-component methods, | 313 | /* Verify we can handle the sampling factors, select per-component methods, |
314 | * and create storage as needed. | 314 | * and create storage as needed. |
315 | */ | 315 | */ |
316 | for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; | 316 | for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; |
317 | ci++, compptr++) { | 317 | ci++, compptr++) { |
318 | /* Compute size of an "input group" after IDCT scaling. This many samples | 318 | /* Compute size of an "input group" after IDCT scaling. This many samples |
319 | * are to be converted to max_h_samp_factor * max_v_samp_factor pixels. | 319 | * are to be converted to max_h_samp_factor * max_v_samp_factor pixels. |
320 | */ | 320 | */ |
321 | h_in_group = (compptr->h_samp_factor * compptr->DCT_h_scaled_size) / | 321 | h_in_group = (compptr->h_samp_factor * compptr->DCT_h_scaled_size) / |
322 | cinfo->min_DCT_h_scaled_size; | 322 | cinfo->min_DCT_h_scaled_size; |
323 | v_in_group = (compptr->v_samp_factor * compptr->DCT_v_scaled_size) / | 323 | v_in_group = (compptr->v_samp_factor * compptr->DCT_v_scaled_size) / |
324 | cinfo->min_DCT_v_scaled_size; | 324 | cinfo->min_DCT_v_scaled_size; |
325 | h_out_group = cinfo->max_h_samp_factor; | 325 | h_out_group = cinfo->max_h_samp_factor; |
326 | v_out_group = cinfo->max_v_samp_factor; | 326 | v_out_group = cinfo->max_v_samp_factor; |
327 | upsample->rowgroup_height[ci] = v_in_group; /* save for use later */ | 327 | upsample->rowgroup_height[ci] = v_in_group; /* save for use later */ |
328 | need_buffer = TRUE; | 328 | need_buffer = TRUE; |
329 | if (! compptr->component_needed) { | 329 | if (! compptr->component_needed) { |
330 | /* Don't bother to upsample an uninteresting component. */ | 330 | /* Don't bother to upsample an uninteresting component. */ |
331 | upsample->methods[ci] = noop_upsample; | 331 | upsample->methods[ci] = noop_upsample; |
332 | need_buffer = FALSE; | 332 | need_buffer = FALSE; |
333 | } else if (h_in_group == h_out_group && v_in_group == v_out_group) { | 333 | } else if (h_in_group == h_out_group && v_in_group == v_out_group) { |
334 | /* Fullsize components can be processed without any work. */ | 334 | /* Fullsize components can be processed without any work. */ |
335 | upsample->methods[ci] = fullsize_upsample; | 335 | upsample->methods[ci] = fullsize_upsample; |
336 | need_buffer = FALSE; | 336 | need_buffer = FALSE; |
337 | } else if (h_in_group * 2 == h_out_group && | 337 | } else if (h_in_group * 2 == h_out_group && |
338 | v_in_group == v_out_group) { | 338 | v_in_group == v_out_group) { |
339 | /* Special case for 2h1v upsampling */ | 339 | /* Special case for 2h1v upsampling */ |
340 | upsample->methods[ci] = h2v1_upsample; | 340 | upsample->methods[ci] = h2v1_upsample; |
341 | } else if (h_in_group * 2 == h_out_group && | 341 | } else if (h_in_group * 2 == h_out_group && |
342 | v_in_group * 2 == v_out_group) { | 342 | v_in_group * 2 == v_out_group) { |
343 | /* Special case for 2h2v upsampling */ | 343 | /* Special case for 2h2v upsampling */ |
344 | upsample->methods[ci] = h2v2_upsample; | 344 | upsample->methods[ci] = h2v2_upsample; |
345 | } else if ((h_out_group % h_in_group) == 0 && | 345 | } else if ((h_out_group % h_in_group) == 0 && |
346 | (v_out_group % v_in_group) == 0) { | 346 | (v_out_group % v_in_group) == 0) { |
347 | /* Generic integral-factors upsampling method */ | 347 | /* Generic integral-factors upsampling method */ |
348 | upsample->methods[ci] = int_upsample; | 348 | upsample->methods[ci] = int_upsample; |
349 | upsample->h_expand[ci] = (UINT8) (h_out_group / h_in_group); | 349 | upsample->h_expand[ci] = (UINT8) (h_out_group / h_in_group); |
350 | upsample->v_expand[ci] = (UINT8) (v_out_group / v_in_group); | 350 | upsample->v_expand[ci] = (UINT8) (v_out_group / v_in_group); |
351 | } else | 351 | } else |
352 | ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL); | 352 | ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL); |
353 | if (need_buffer) { | 353 | if (need_buffer) { |
354 | upsample->color_buf[ci] = (*cinfo->mem->alloc_sarray) | 354 | upsample->color_buf[ci] = (*cinfo->mem->alloc_sarray) |
355 | ((j_common_ptr) cinfo, JPOOL_IMAGE, | 355 | ((j_common_ptr) cinfo, JPOOL_IMAGE, |
356 | (JDIMENSION) jround_up((long) cinfo->output_width, | 356 | (JDIMENSION) jround_up((long) cinfo->output_width, |
357 | (long) cinfo->max_h_samp_factor), | 357 | (long) cinfo->max_h_samp_factor), |
358 | (JDIMENSION) cinfo->max_v_samp_factor); | 358 | (JDIMENSION) cinfo->max_v_samp_factor); |
359 | } | 359 | } |
360 | } | 360 | } |
361 | } | 361 | } |