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