media/libjpeg/jdsample.c

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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

mercurial