jcsample.cpp 21 KB

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