home *** CD-ROM | disk | FTP | other *** search
/ Windows Graphics Programming / Feng_Yuan_Win32_GDI_DirectX.iso / Samples / include / jlib / jcsample.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-16  |  19.4 KB  |  520 lines

  1. //-------------------------------------------------------------------------//
  2. //          Windows Graphics Programming: Win32 GDI and DirectDraw         //
  3. //                        ISBN  0-13-086985-6                              //
  4. //                                                                         //
  5. //  Modified by: Yuan, Feng                             www.fengyuan.com   //
  6. //  Changes    : C++, exception, in-memory source, BGR byte order          //
  7. //  Version    : 1.00.000, May 31, 2000                                    //
  8. //-------------------------------------------------------------------------//
  9.  
  10. /*
  11.  * jcsample.c
  12.  *
  13.  * Copyright (C) 1991-1996, Thomas G. Lane.
  14.  * This file is part of the Independent JPEG Group's software.
  15.  * For conditions of distribution and use, see the accompanying README file.
  16.  *
  17.  * This file contains downsampling routines.
  18.  *
  19.  * Downsampling input data is counted in "row groups".  A row group
  20.  * is defined to be max_v_samp_factor pixel rows of each component,
  21.  * from which the downsampler produces v_samp_factor sample rows.
  22.  * A single row group is processed in each call to the downsampler module.
  23.  *
  24.  * The downsampler is responsible for edge-expansion of its output data
  25.  * to fill an integral number of DCT blocks horizontally.  The source buffer
  26.  * may be modified if it is helpful for this purpose (the source buffer is
  27.  * allocated wide enough to correspond to the desired output width).
  28.  * The caller (the prep controller) is responsible for vertical padding.
  29.  *
  30.  * The downsampler may request "context rows" by setting need_context_rows
  31.  * during startup.  In this case, the input arrays will contain at least
  32.  * one row group's worth of pixels above and below the passed-in data;
  33.  * the caller will create dummy rows at image top and bottom by replicating
  34.  * the first or last real pixel row.
  35.  *
  36.  * An excellent reference for image resampling is
  37.  *   Digital Image Warping, George Wolberg, 1990.
  38.  *   Pub. by IEEE Computer Society Press, Los Alamitos, CA. ISBN 0-8186-8944-7.
  39.  *
  40.  * The downsampling algorithm used here is a simple average of the source
  41.  * pixels covered by the output pixel.  The hi-falutin sampling literature
  42.  * refers to this as a "box filter".  In general the characteristics of a box
  43.  * filter are not very good, but for the specific cases we normally use (1:1
  44.  * and 2:1 ratios) the box is equivalent to a "triangle filter" which is not
  45.  * nearly so bad.  If you intend to use other sampling ratios, you'd be well
  46.  * advised to improve this code.
  47.  *
  48.  * A simple input-smoothing capability is provided.  This is mainly intended
  49.  * for cleaning up color-dithered GIF input files (if you find it inadequate,
  50.  * we suggest using an external filtering program such as pnmconvol).  When
  51.  * enabled, each input pixel P is replaced by a weighted sum of itself and its
  52.  * eight neighbors.  P's weight is 1-8*SF and each neighbor's weight is SF,
  53.  * where SF = (smoothing_factor / 1024).
  54.  * Currently, smoothing is only supported for 2h2v sampling factors.
  55.  */
  56.  
  57. #define JPEG_INTERNALS
  58. #include "jinclude.h"
  59. #include "jpeglib.h"
  60.  
  61.  
  62. /* Pointer to routine to downsample a single component */
  63. typedef JMETHOD(void, downsample1_ptr,
  64.         (j_compress_ptr cinfo, jpeg_component_info * compptr,
  65.          JSAMPARRAY input_data, JSAMPARRAY output_data));
  66.  
  67. /* Private subobject */
  68.  
  69. typedef struct {
  70.   struct jpeg_downsampler pub;    /* public fields */
  71.  
  72.   /* Downsampling method pointers, one per component */
  73.   downsample1_ptr methods[MAX_COMPONENTS];
  74. } my_downsampler;
  75.  
  76. typedef my_downsampler * my_downsample_ptr;
  77.  
  78.  
  79. /*
  80.  * Initialize for a downsampling pass.
  81.  */
  82.  
  83. void start_pass_downsample (j_compress_ptr cinfo)
  84. {
  85.   /* no work for now */
  86. }
  87.  
  88.  
  89. /*
  90.  * Expand a component horizontally from width input_cols to width output_cols,
  91.  * by duplicating the rightmost samples.
  92.  */
  93.  
  94. LOCAL(void)
  95. expand_right_edge (JSAMPARRAY image_data, int num_rows,
  96.            JDIMENSION input_cols, JDIMENSION output_cols)
  97. {
  98.   register JSAMPROW ptr;
  99.   register JSAMPLE pixval;
  100.   register int count;
  101.   int row;
  102.   int numcols = (int) (output_cols - input_cols);
  103.  
  104.   if (numcols > 0) {
  105.     for (row = 0; row < num_rows; row++) {
  106.       ptr = image_data[row] + input_cols;
  107.       pixval = ptr[-1];        /* don't need GETJSAMPLE() here */
  108.       for (count = numcols; count > 0; count--)
  109.     *ptr++ = pixval;
  110.     }
  111.   }
  112. }
  113.  
  114.  
  115. /*
  116.  * Do downsampling for a whole row group (all components).
  117.  *
  118.  * In this version we simply downsample each component independently.
  119.  */
  120.  
  121. void sep_downsample (j_compress_ptr cinfo,
  122.         JSAMPIMAGE input_buf, JDIMENSION in_row_index,
  123.         JSAMPIMAGE output_buf, JDIMENSION out_row_group_index)
  124. {
  125.   my_downsample_ptr downsample = (my_downsample_ptr) cinfo->downsample;
  126.   int ci;
  127.   jpeg_component_info * compptr;
  128.   JSAMPARRAY in_ptr, out_ptr;
  129.  
  130.   for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  131.        ci++, compptr++) {
  132.     in_ptr = input_buf[ci] + in_row_index;
  133.     out_ptr = output_buf[ci] + (out_row_group_index * compptr->v_samp_factor);
  134.     (*downsample->methods[ci]) (cinfo, compptr, in_ptr, out_ptr);
  135.   }
  136. }
  137.  
  138.  
  139. /*
  140.  * Downsample pixel values of a single component.
  141.  * One row group is processed per call.
  142.  * This version handles arbitrary integral sampling ratios, without smoothing.
  143.  * Note that this version is not actually used for customary sampling ratios.
  144.  */
  145.  
  146. void int_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
  147.         JSAMPARRAY input_data, JSAMPARRAY output_data)
  148. {
  149.   int inrow, outrow, h_expand, v_expand, numpix, numpix2, h, v;
  150.   JDIMENSION outcol, outcol_h;    /* outcol_h == outcol*h_expand */
  151.   JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
  152.   JSAMPROW inptr, outptr;
  153.   long outvalue;
  154.  
  155.   h_expand = cinfo->max_h_samp_factor / compptr->h_samp_factor;
  156.   v_expand = cinfo->max_v_samp_factor / compptr->v_samp_factor;
  157.   numpix = h_expand * v_expand;
  158.   numpix2 = numpix/2;
  159.  
  160.   /* Expand input data enough to let all the output samples be generated
  161.    * by the standard loop.  Special-casing padded output would be more
  162.    * efficient.
  163.    */
  164.   expand_right_edge(input_data, cinfo->max_v_samp_factor,
  165.             cinfo->image_width, output_cols * h_expand);
  166.  
  167.   inrow = 0;
  168.   for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
  169.     outptr = output_data[outrow];
  170.     for (outcol = 0, outcol_h = 0; outcol < output_cols;
  171.      outcol++, outcol_h += h_expand) {
  172.       outvalue = 0;
  173.       for (v = 0; v < v_expand; v++) {
  174.     inptr = input_data[inrow+v] + outcol_h;
  175.     for (h = 0; h < h_expand; h++) {
  176.       outvalue += (long) GETJSAMPLE(*inptr++);
  177.     }
  178.       }
  179.       *outptr++ = (JSAMPLE) ((outvalue + numpix2) / numpix);
  180.     }
  181.     inrow += v_expand;
  182.   }
  183. }
  184.  
  185.  
  186. /*
  187.  * Downsample pixel values of a single component.
  188.  * This version handles the special case of a full-size component,
  189.  * without smoothing.
  190.  */
  191.  
  192. void fullsize_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
  193.              JSAMPARRAY input_data, JSAMPARRAY output_data)
  194. {
  195.   /* Copy the data */
  196.   jcopy_sample_rows(input_data, 0, output_data, 0,
  197.             cinfo->max_v_samp_factor, cinfo->image_width);
  198.   /* Edge-expand */
  199.   expand_right_edge(output_data, cinfo->max_v_samp_factor,
  200.             cinfo->image_width, compptr->width_in_blocks * DCTSIZE);
  201. }
  202.  
  203.  
  204. /*
  205.  * Downsample pixel values of a single component.
  206.  * This version handles the common case of 2:1 horizontal and 1:1 vertical,
  207.  * without smoothing.
  208.  *
  209.  * A note about the "bias" calculations: when rounding fractional values to
  210.  * integer, we do not want to always round 0.5 up to the next integer.
  211.  * If we did that, we'd introduce a noticeable bias towards larger values.
  212.  * Instead, this code is arranged so that 0.5 will be rounded up or down at
  213.  * alternate pixel locations (a simple ordered dither pattern).
  214.  */
  215.  
  216. void h2v1_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
  217.          JSAMPARRAY input_data, JSAMPARRAY output_data)
  218. {
  219.   int outrow;
  220.   JDIMENSION outcol;
  221.   JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
  222.   register JSAMPROW inptr, outptr;
  223.   register int bias;
  224.  
  225.   /* Expand input data enough to let all the output samples be generated
  226.    * by the standard loop.  Special-casing padded output would be more
  227.    * efficient.
  228.    */
  229.   expand_right_edge(input_data, cinfo->max_v_samp_factor,
  230.             cinfo->image_width, output_cols * 2);
  231.  
  232.   for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
  233.     outptr = output_data[outrow];
  234.     inptr = input_data[outrow];
  235.     bias = 0;            /* bias = 0,1,0,1,... for successive samples */
  236.     for (outcol = 0; outcol < output_cols; outcol++) {
  237.       *outptr++ = (JSAMPLE) ((GETJSAMPLE(*inptr) + GETJSAMPLE(inptr[1])
  238.                   + bias) >> 1);
  239.       bias ^= 1;        /* 0=>1, 1=>0 */
  240.       inptr += 2;
  241.     }
  242.   }
  243. }
  244.  
  245.  
  246. /*
  247.  * Downsample pixel values of a single component.
  248.  * This version handles the standard case of 2:1 horizontal and 2:1 vertical,
  249.  * without smoothing.
  250.  */
  251.  
  252. void h2v2_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
  253.          JSAMPARRAY input_data, JSAMPARRAY output_data)
  254. {
  255.   int inrow, outrow;
  256.   JDIMENSION outcol;
  257.   JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
  258.   register JSAMPROW inptr0, inptr1, outptr;
  259.   register int bias;
  260.  
  261.   /* Expand input data enough to let all the output samples be generated
  262.    * by the standard loop.  Special-casing padded output would be more
  263.    * efficient.
  264.    */
  265.   expand_right_edge(input_data, cinfo->max_v_samp_factor,
  266.             cinfo->image_width, output_cols * 2);
  267.  
  268.   inrow = 0;
  269.   for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
  270.     outptr = output_data[outrow];
  271.     inptr0 = input_data[inrow];
  272.     inptr1 = input_data[inrow+1];
  273.     bias = 1;            /* bias = 1,2,1,2,... for successive samples */
  274.     for (outcol = 0; outcol < output_cols; outcol++) {
  275.       *outptr++ = (JSAMPLE) ((GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
  276.                   GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1])
  277.                   + bias) >> 2);
  278.       bias ^= 3;        /* 1=>2, 2=>1 */
  279.       inptr0 += 2; inptr1 += 2;
  280.     }
  281.     inrow += 2;
  282.   }
  283. }
  284.  
  285.  
  286. #ifdef INPUT_SMOOTHING_SUPPORTED
  287.  
  288. /*
  289.  * Downsample pixel values of a single component.
  290.  * This version handles the standard case of 2:1 horizontal and 2:1 vertical,
  291.  * with smoothing.  One row of context is required.
  292.  */
  293.  
  294. void h2v2_smooth_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
  295.             JSAMPARRAY input_data, JSAMPARRAY output_data)
  296. {
  297.   int inrow, outrow;
  298.   JDIMENSION colctr;
  299.   JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
  300.   register JSAMPROW inptr0, inptr1, above_ptr, below_ptr, outptr;
  301.   long membersum, neighsum, memberscale, neighscale;
  302.  
  303.   /* Expand input data enough to let all the output samples be generated
  304.    * by the standard loop.  Special-casing padded output would be more
  305.    * efficient.
  306.    */
  307.   expand_right_edge(input_data - 1, cinfo->max_v_samp_factor + 2,
  308.             cinfo->image_width, output_cols * 2);
  309.  
  310.   /* We don't bother to form the individual "smoothed" input pixel values;
  311.    * we can directly compute the output which is the average of the four
  312.    * smoothed values.  Each of the four member pixels contributes a fraction
  313.    * (1-8*SF) to its own smoothed image and a fraction SF to each of the three
  314.    * other smoothed pixels, therefore a total fraction (1-5*SF)/4 to the final
  315.    * output.  The four corner-adjacent neighbor pixels contribute a fraction
  316.    * SF to just one smoothed pixel, or SF/4 to the final output; while the
  317.    * eight edge-adjacent neighbors contribute SF to each of two smoothed
  318.    * pixels, or SF/2 overall.  In order to use integer arithmetic, these
  319.    * factors are scaled by 2^16 = 65536.
  320.    * Also recall that SF = smoothing_factor / 1024.
  321.    */
  322.  
  323.   memberscale = 16384 - cinfo->smoothing_factor * 80; /* scaled (1-5*SF)/4 */
  324.   neighscale = cinfo->smoothing_factor * 16; /* scaled SF/4 */
  325.  
  326.   inrow = 0;
  327.   for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
  328.     outptr = output_data[outrow];
  329.     inptr0 = input_data[inrow];
  330.     inptr1 = input_data[inrow+1];
  331.     above_ptr = input_data[inrow-1];
  332.     below_ptr = input_data[inrow+2];
  333.  
  334.     /* Special case for first column: pretend column -1 is same as column 0 */
  335.     membersum = GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
  336.         GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]);
  337.     neighsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[1]) +
  338.            GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[1]) +
  339.            GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[2]) +
  340.            GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[2]);
  341.     neighsum += neighsum;
  342.     neighsum += GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[2]) +
  343.         GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[2]);
  344.     membersum = membersum * memberscale + neighsum * neighscale;
  345.     *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16);
  346.     inptr0 += 2; inptr1 += 2; above_ptr += 2; below_ptr += 2;
  347.  
  348.     for (colctr = output_cols - 2; colctr > 0; colctr--) {
  349.       /* sum of pixels directly mapped to this output element */
  350.       membersum = GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
  351.           GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]);
  352.       /* sum of edge-neighbor pixels */
  353.       neighsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[1]) +
  354.          GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[1]) +
  355.          GETJSAMPLE(inptr0[-1]) + GETJSAMPLE(inptr0[2]) +
  356.          GETJSAMPLE(inptr1[-1]) + GETJSAMPLE(inptr1[2]);
  357.       /* The edge-neighbors count twice as much as corner-neighbors */
  358.       neighsum += neighsum;
  359.       /* Add in the corner-neighbors */
  360.       neighsum += GETJSAMPLE(above_ptr[-1]) + GETJSAMPLE(above_ptr[2]) +
  361.           GETJSAMPLE(below_ptr[-1]) + GETJSAMPLE(below_ptr[2]);
  362.       /* form final output scaled up by 2^16 */
  363.       membersum = membersum * memberscale + neighsum * neighscale;
  364.       /* round, descale and output it */
  365.       *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16);
  366.       inptr0 += 2; inptr1 += 2; above_ptr += 2; below_ptr += 2;
  367.     }
  368.  
  369.     /* Special case for last column */
  370.     membersum = GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
  371.         GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]);
  372.     neighsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[1]) +
  373.            GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[1]) +
  374.            GETJSAMPLE(inptr0[-1]) + GETJSAMPLE(inptr0[1]) +
  375.            GETJSAMPLE(inptr1[-1]) + GETJSAMPLE(inptr1[1]);
  376.     neighsum += neighsum;
  377.     neighsum += GETJSAMPLE(above_ptr[-1]) + GETJSAMPLE(above_ptr[1]) +
  378.         GETJSAMPLE(below_ptr[-1]) + GETJSAMPLE(below_ptr[1]);
  379.     membersum = membersum * memberscale + neighsum * neighscale;
  380.     *outptr = (JSAMPLE) ((membersum + 32768) >> 16);
  381.  
  382.     inrow += 2;
  383.   }
  384. }
  385.  
  386.  
  387. /*
  388.  * Downsample pixel values of a single component.
  389.  * This version handles the special case of a full-size component,
  390.  * with smoothing.  One row of context is required.
  391.  */
  392.  
  393. void fullsize_smooth_downsample (j_compress_ptr cinfo, jpeg_component_info *compptr,
  394.                 JSAMPARRAY input_data, JSAMPARRAY output_data)
  395. {
  396.   int outrow;
  397.   JDIMENSION colctr;
  398.   JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
  399.   register JSAMPROW inptr, above_ptr, below_ptr, outptr;
  400.   long membersum, neighsum, memberscale, neighscale;
  401.   int colsum, lastcolsum, nextcolsum;
  402.  
  403.   /* Expand input data enough to let all the output samples be generated
  404.    * by the standard loop.  Special-casing padded output would be more
  405.    * efficient.
  406.    */
  407.   expand_right_edge(input_data - 1, cinfo->max_v_samp_factor + 2,
  408.             cinfo->image_width, output_cols);
  409.  
  410.   /* Each of the eight neighbor pixels contributes a fraction SF to the
  411.    * smoothed pixel, while the main pixel contributes (1-8*SF).  In order
  412.    * to use integer arithmetic, these factors are multiplied by 2^16 = 65536.
  413.    * Also recall that SF = smoothing_factor / 1024.
  414.    */
  415.  
  416.   memberscale = 65536L - cinfo->smoothing_factor * 512L; /* scaled 1-8*SF */
  417.   neighscale = cinfo->smoothing_factor * 64; /* scaled SF */
  418.  
  419.   for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
  420.     outptr = output_data[outrow];
  421.     inptr = input_data[outrow];
  422.     above_ptr = input_data[outrow-1];
  423.     below_ptr = input_data[outrow+1];
  424.  
  425.     /* Special case for first column */
  426.     colsum = GETJSAMPLE(*above_ptr++) + GETJSAMPLE(*below_ptr++) +
  427.          GETJSAMPLE(*inptr);
  428.     membersum = GETJSAMPLE(*inptr++);
  429.     nextcolsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(*below_ptr) +
  430.          GETJSAMPLE(*inptr);
  431.     neighsum = colsum + (colsum - membersum) + nextcolsum;
  432.     membersum = membersum * memberscale + neighsum * neighscale;
  433.     *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16);
  434.     lastcolsum = colsum; colsum = nextcolsum;
  435.  
  436.     for (colctr = output_cols - 2; colctr > 0; colctr--) {
  437.       membersum = GETJSAMPLE(*inptr++);
  438.       above_ptr++; below_ptr++;
  439.       nextcolsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(*below_ptr) +
  440.            GETJSAMPLE(*inptr);
  441.       neighsum = lastcolsum + (colsum - membersum) + nextcolsum;
  442.       membersum = membersum * memberscale + neighsum * neighscale;
  443.       *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16);
  444.       lastcolsum = colsum; colsum = nextcolsum;
  445.     }
  446.  
  447.     /* Special case for last column */
  448.     membersum = GETJSAMPLE(*inptr);
  449.     neighsum = lastcolsum + (colsum - membersum) + colsum;
  450.     membersum = membersum * memberscale + neighsum * neighscale;
  451.     *outptr = (JSAMPLE) ((membersum + 32768) >> 16);
  452.  
  453.   }
  454. }
  455.  
  456. #endif /* INPUT_SMOOTHING_SUPPORTED */
  457.  
  458.  
  459. /*
  460.  * Module initialization routine for downsampling.
  461.  * Note that we must select a routine for each component.
  462.  */
  463.  
  464. GLOBAL(void)
  465. jinit_downsampler (j_compress_ptr cinfo)
  466. {
  467.   my_downsample_ptr downsample;
  468.   int ci;
  469.   jpeg_component_info * compptr;
  470.   boolean smoothok = TRUE;
  471.  
  472.   downsample = (my_downsample_ptr)
  473.     cinfo->mem->alloc_small(JPOOL_IMAGE, sizeof(my_downsampler));
  474.   cinfo->downsample = (struct jpeg_downsampler *) downsample;
  475.   downsample->pub.start_pass = start_pass_downsample;
  476.   downsample->pub.downsample = sep_downsample;
  477.   downsample->pub.need_context_rows = FALSE;
  478.  
  479.   if (cinfo->CCIR601_sampling)
  480.     cinfo->ERREXIT(JERR_CCIR601_NOTIMPL);
  481.  
  482.   /* Verify we can handle the sampling factors, and set up method pointers */
  483.   for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  484.        ci++, compptr++) {
  485.     if (compptr->h_samp_factor == cinfo->max_h_samp_factor &&
  486.     compptr->v_samp_factor == cinfo->max_v_samp_factor) {
  487. #ifdef INPUT_SMOOTHING_SUPPORTED
  488.       if (cinfo->smoothing_factor) {
  489.     downsample->methods[ci] = fullsize_smooth_downsample;
  490.     downsample->pub.need_context_rows = TRUE;
  491.       } else
  492. #endif
  493.     downsample->methods[ci] = fullsize_downsample;
  494.     } else if (compptr->h_samp_factor * 2 == cinfo->max_h_samp_factor &&
  495.            compptr->v_samp_factor == cinfo->max_v_samp_factor) {
  496.       smoothok = FALSE;
  497.       downsample->methods[ci] = h2v1_downsample;
  498.     } else if (compptr->h_samp_factor * 2 == cinfo->max_h_samp_factor &&
  499.            compptr->v_samp_factor * 2 == cinfo->max_v_samp_factor) {
  500. #ifdef INPUT_SMOOTHING_SUPPORTED
  501.       if (cinfo->smoothing_factor) {
  502.     downsample->methods[ci] = h2v2_smooth_downsample;
  503.     downsample->pub.need_context_rows = TRUE;
  504.       } else
  505. #endif
  506.     downsample->methods[ci] = h2v2_downsample;
  507.     } else if ((cinfo->max_h_samp_factor % compptr->h_samp_factor) == 0 &&
  508.            (cinfo->max_v_samp_factor % compptr->v_samp_factor) == 0) {
  509.       smoothok = FALSE;
  510.       downsample->methods[ci] = int_downsample;
  511.     } else
  512.       cinfo->ERREXIT(JERR_FRACT_SAMPLE_NOTIMPL);
  513.   }
  514.  
  515. #ifdef INPUT_SMOOTHING_SUPPORTED
  516.   if (cinfo->smoothing_factor && !smoothok)
  517.     TRACEMS(cinfo, 0, JTRC_SMOOTH_NOTIMPL);
  518. #endif
  519. }
  520.