3dphotoshoot

annotate libs/libjpeg/jdsample.c @ 19:94b8ef9b8caa

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