jcsample.c 19 KB

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