< prev index next >

modules/javafx.graphics/src/main/native-iio/libjpeg7/jdsample.c

Print this page


   1 /*
   2  * jdsample.c
   3  *
   4  * Copyright (C) 1991-1996, Thomas G. Lane.
   5  * Modified 2002-2008 by Guido Vollbeding.
   6  * This file is part of the Independent JPEG Group's software.
   7  * For conditions of distribution and use, see the accompanying README file.
   8  *
   9  * This file contains upsampling routines.
  10  *
  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)
  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
  15  * if the upsampler is applying a scale factor of its own).
  16  *
  17  * An excellent reference for image resampling is
  18  *   Digital Image Warping, George Wolberg, 1990.
  19  *   Pub. by IEEE Computer Society Press, Los Alamitos, CA. ISBN 0-8186-8944-7.
  20  */
  21 
  22 #define JPEG_INTERNALS
  23 #include "jinclude.h"
  24 #include "jpeglib.h"
  25 


 279       *outptr++ = invalue;
 280     }
 281     jcopy_sample_rows(output_data, outrow, output_data, outrow+1,
 282                       1, cinfo->output_width);
 283     inrow++;
 284     outrow += 2;
 285   }
 286 }
 287 
 288 
 289 /*
 290  * Module initialization routine for upsampling.
 291  */
 292 
 293 GLOBAL(void)
 294 jinit_upsampler (j_decompress_ptr cinfo)
 295 {
 296   my_upsample_ptr upsample;
 297   int ci;
 298   jpeg_component_info * compptr;
 299   boolean need_buffer;
 300   int h_in_group, v_in_group, h_out_group, v_out_group;
 301 
 302   upsample = (my_upsample_ptr)
 303     (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
 304                                 SIZEOF(my_upsampler));
 305   cinfo->upsample = (struct jpeg_upsampler *) upsample;
 306   upsample->pub.start_pass = start_pass_upsample;
 307   upsample->pub.upsample = sep_upsample;
 308   upsample->pub.need_context_rows = FALSE; /* until we find out differently */
 309 
 310   if (cinfo->CCIR601_sampling)  /* this isn't supported */
 311     ERREXIT(cinfo, JERR_CCIR601_NOTIMPL);
 312 
 313   /* Verify we can handle the sampling factors, select per-component methods,
 314    * and create storage as needed.
 315    */
 316   for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
 317        ci++, compptr++) {
 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.
 320      */
 321     h_in_group = (compptr->h_samp_factor * compptr->DCT_h_scaled_size) /
 322                  cinfo->min_DCT_h_scaled_size;
 323     v_in_group = (compptr->v_samp_factor * compptr->DCT_v_scaled_size) /
 324                  cinfo->min_DCT_v_scaled_size;
 325     h_out_group = cinfo->max_h_samp_factor;
 326     v_out_group = cinfo->max_v_samp_factor;
 327     upsample->rowgroup_height[ci] = v_in_group; /* save for use later */
 328     need_buffer = TRUE;
 329     if (! compptr->component_needed) {
 330       /* Don't bother to upsample an uninteresting component. */
 331       upsample->methods[ci] = noop_upsample;
 332       need_buffer = FALSE;
 333     } else if (h_in_group == h_out_group && v_in_group == v_out_group) {

 334       /* Fullsize components can be processed without any work. */
 335       upsample->methods[ci] = fullsize_upsample;
 336       need_buffer = FALSE;
 337     } else if (h_in_group * 2 == h_out_group &&
 338                v_in_group == v_out_group) {
 339       /* Special case for 2h1v upsampling */
 340       upsample->methods[ci] = h2v1_upsample;
 341     } else if (h_in_group * 2 == h_out_group &&
 342                v_in_group * 2 == v_out_group) {
 343       /* Special case for 2h2v upsampling */
 344       upsample->methods[ci] = h2v2_upsample;
 345     } else if ((h_out_group % h_in_group) == 0 &&
 346                (v_out_group % v_in_group) == 0) {
 347       /* Generic integral-factors upsampling method */
 348       upsample->methods[ci] = int_upsample;
 349       upsample->h_expand[ci] = (UINT8) (h_out_group / h_in_group);
 350       upsample->v_expand[ci] = (UINT8) (v_out_group / v_in_group);
 351     } else
 352       ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL);
 353     if (need_buffer) {
 354       upsample->color_buf[ci] = (*cinfo->mem->alloc_sarray)
 355         ((j_common_ptr) cinfo, JPOOL_IMAGE,
 356          (JDIMENSION) jround_up((long) cinfo->output_width,
 357                                 (long) cinfo->max_h_samp_factor),
 358          (JDIMENSION) cinfo->max_v_samp_factor);
 359     }
 360   }
 361 }
   1 /*
   2  * jdsample.c
   3  *
   4  * Copyright (C) 1991-1996, Thomas G. Lane.
   5  * Modified 2002-2015 by Guido Vollbeding.
   6  * This file is part of the Independent JPEG Group's software.
   7  * For conditions of distribution and use, see the accompanying README file.
   8  *
   9  * This file contains upsampling routines.
  10  *
  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)
  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
  15  * if the upsampler is applying a scale factor of its own).
  16  *
  17  * An excellent reference for image resampling is
  18  *   Digital Image Warping, George Wolberg, 1990.
  19  *   Pub. by IEEE Computer Society Press, Los Alamitos, CA. ISBN 0-8186-8944-7.
  20  */
  21 
  22 #define JPEG_INTERNALS
  23 #include "jinclude.h"
  24 #include "jpeglib.h"
  25 


 279       *outptr++ = invalue;
 280     }
 281     jcopy_sample_rows(output_data, outrow, output_data, outrow+1,
 282                       1, cinfo->output_width);
 283     inrow++;
 284     outrow += 2;
 285   }
 286 }
 287 
 288 
 289 /*
 290  * Module initialization routine for upsampling.
 291  */
 292 
 293 GLOBAL(void)
 294 jinit_upsampler (j_decompress_ptr cinfo)
 295 {
 296   my_upsample_ptr upsample;
 297   int ci;
 298   jpeg_component_info * compptr;

 299   int h_in_group, v_in_group, h_out_group, v_out_group;
 300 
 301   upsample = (my_upsample_ptr)
 302     (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
 303                                 SIZEOF(my_upsampler));
 304   cinfo->upsample = &upsample->pub;
 305   upsample->pub.start_pass = start_pass_upsample;
 306   upsample->pub.upsample = sep_upsample;
 307   upsample->pub.need_context_rows = FALSE; /* until we find out differently */
 308 
 309   if (cinfo->CCIR601_sampling)       /* this isn't supported */
 310     ERREXIT(cinfo, JERR_CCIR601_NOTIMPL);
 311 
 312   /* Verify we can handle the sampling factors, select per-component methods,
 313    * and create storage as needed.
 314    */
 315   for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
 316        ci++, compptr++) {
 317     /* Compute size of an "input group" after IDCT scaling.  This many samples
 318      * are to be converted to max_h_samp_factor * max_v_samp_factor pixels.
 319      */
 320     h_in_group = (compptr->h_samp_factor * compptr->DCT_h_scaled_size) /
 321                  cinfo->min_DCT_h_scaled_size;
 322     v_in_group = (compptr->v_samp_factor * compptr->DCT_v_scaled_size) /
 323                  cinfo->min_DCT_v_scaled_size;
 324     h_out_group = cinfo->max_h_samp_factor;
 325     v_out_group = cinfo->max_v_samp_factor;
 326     upsample->rowgroup_height[ci] = v_in_group; /* save for use later */

 327     if (! compptr->component_needed) {
 328       /* Don't bother to upsample an uninteresting component. */
 329       upsample->methods[ci] = noop_upsample;
 330       continue;         /* don't need to allocate buffer */
 331     }
 332     if (h_in_group == h_out_group && v_in_group == v_out_group) {
 333       /* Fullsize components can be processed without any work. */
 334       upsample->methods[ci] = fullsize_upsample;
 335       continue;         /* don't need to allocate buffer */
 336     }
 337     if (h_in_group * 2 == h_out_group && v_in_group == v_out_group) {
 338       /* Special case for 2h1v upsampling */
 339       upsample->methods[ci] = h2v1_upsample;
 340     } else if (h_in_group * 2 == h_out_group &&
 341                v_in_group * 2 == v_out_group) {
 342       /* Special case for 2h2v upsampling */
 343       upsample->methods[ci] = h2v2_upsample;
 344     } else if ((h_out_group % h_in_group) == 0 &&
 345                (v_out_group % v_in_group) == 0) {
 346       /* Generic integral-factors upsampling method */
 347       upsample->methods[ci] = int_upsample;
 348       upsample->h_expand[ci] = (UINT8) (h_out_group / h_in_group);
 349       upsample->v_expand[ci] = (UINT8) (v_out_group / v_in_group);
 350     } else
 351       ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL);

 352     upsample->color_buf[ci] = (*cinfo->mem->alloc_sarray)
 353       ((j_common_ptr) cinfo, JPOOL_IMAGE,
 354        (JDIMENSION) jround_up((long) cinfo->output_width,
 355                               (long) cinfo->max_h_samp_factor),
 356        (JDIMENSION) cinfo->max_v_samp_factor);

 357   }
 358 }
< prev index next >