jcsample.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546
  1. /*
  2. * jcsample.c
  3. *
  4. * Copyright (C) 1991-1996, 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. /* Height of an output row group for each component. */
  60. int rowgroup_height[MAX_COMPONENTS];
  61. /* These arrays save pixel expansion factors so that int_downsample need not
  62. * recompute them each time. They are unused for other downsampling methods.
  63. */
  64. UINT8 h_expand[MAX_COMPONENTS];
  65. UINT8 v_expand[MAX_COMPONENTS];
  66. } my_downsampler;
  67. typedef my_downsampler * my_downsample_ptr;
  68. /*
  69. * Initialize for a downsampling pass.
  70. */
  71. METHODDEF(void)
  72. start_pass_downsample (j_compress_ptr cinfo)
  73. {
  74. /* no work for now */
  75. }
  76. /*
  77. * Expand a component horizontally from width input_cols to width output_cols,
  78. * by duplicating the rightmost samples.
  79. */
  80. LOCAL(void)
  81. expand_right_edge (JSAMPARRAY image_data, int num_rows,
  82. JDIMENSION input_cols, JDIMENSION output_cols)
  83. {
  84. register JSAMPROW ptr;
  85. register JSAMPLE pixval;
  86. register int count;
  87. int row;
  88. int numcols = (int) (output_cols - input_cols);
  89. if (numcols > 0) {
  90. for (row = 0; row < num_rows; row++) {
  91. ptr = image_data[row] + input_cols;
  92. pixval = ptr[-1]; /* don't need GETJSAMPLE() here */
  93. for (count = numcols; count > 0; count--)
  94. *ptr++ = pixval;
  95. }
  96. }
  97. }
  98. /*
  99. * Do downsampling for a whole row group (all components).
  100. *
  101. * In this version we simply downsample each component independently.
  102. */
  103. METHODDEF(void)
  104. sep_downsample (j_compress_ptr cinfo,
  105. JSAMPIMAGE input_buf, JDIMENSION in_row_index,
  106. JSAMPIMAGE output_buf, JDIMENSION out_row_group_index)
  107. {
  108. my_downsample_ptr downsample = (my_downsample_ptr) cinfo->downsample;
  109. int ci;
  110. jpeg_component_info * compptr;
  111. JSAMPARRAY in_ptr, out_ptr;
  112. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  113. ci++, compptr++) {
  114. in_ptr = input_buf[ci] + in_row_index;
  115. out_ptr = output_buf[ci] +
  116. (out_row_group_index * downsample->rowgroup_height[ci]);
  117. (*downsample->methods[ci]) (cinfo, compptr, in_ptr, out_ptr);
  118. }
  119. }
  120. /*
  121. * Downsample pixel values of a single component.
  122. * One row group is processed per call.
  123. * This version handles arbitrary integral sampling ratios, without smoothing.
  124. * Note that this version is not actually used for customary sampling ratios.
  125. */
  126. METHODDEF(void)
  127. int_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
  128. JSAMPARRAY input_data, JSAMPARRAY output_data)
  129. {
  130. my_downsample_ptr downsample = (my_downsample_ptr) cinfo->downsample;
  131. int inrow, outrow, h_expand, v_expand, numpix, numpix2, h, v;
  132. JDIMENSION outcol, outcol_h; /* outcol_h == outcol*h_expand */
  133. JDIMENSION output_cols = compptr->width_in_blocks * compptr->DCT_h_scaled_size;
  134. JSAMPROW inptr, outptr;
  135. INT32 outvalue;
  136. h_expand = downsample->h_expand[compptr->component_index];
  137. v_expand = downsample->v_expand[compptr->component_index];
  138. numpix = h_expand * v_expand;
  139. numpix2 = numpix/2;
  140. /* Expand input data enough to let all the output samples be generated
  141. * by the standard loop. Special-casing padded output would be more
  142. * efficient.
  143. */
  144. expand_right_edge(input_data, cinfo->max_v_samp_factor,
  145. cinfo->image_width, output_cols * h_expand);
  146. inrow = outrow = 0;
  147. while (inrow < cinfo->max_v_samp_factor) {
  148. outptr = output_data[outrow];
  149. for (outcol = 0, outcol_h = 0; outcol < output_cols;
  150. outcol++, outcol_h += h_expand) {
  151. outvalue = 0;
  152. for (v = 0; v < v_expand; v++) {
  153. inptr = input_data[inrow+v] + outcol_h;
  154. for (h = 0; h < h_expand; h++) {
  155. outvalue += (INT32) GETJSAMPLE(*inptr++);
  156. }
  157. }
  158. *outptr++ = (JSAMPLE) ((outvalue + numpix2) / numpix);
  159. }
  160. inrow += v_expand;
  161. outrow++;
  162. }
  163. }
  164. /*
  165. * Downsample pixel values of a single component.
  166. * This version handles the special case of a full-size component,
  167. * without smoothing.
  168. */
  169. METHODDEF(void)
  170. fullsize_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
  171. JSAMPARRAY input_data, JSAMPARRAY output_data)
  172. {
  173. /* Copy the data */
  174. jcopy_sample_rows(input_data, 0, output_data, 0,
  175. cinfo->max_v_samp_factor, cinfo->image_width);
  176. /* Edge-expand */
  177. expand_right_edge(output_data, cinfo->max_v_samp_factor, cinfo->image_width,
  178. compptr->width_in_blocks * compptr->DCT_h_scaled_size);
  179. }
  180. /*
  181. * Downsample pixel values of a single component.
  182. * This version handles the common case of 2:1 horizontal and 1:1 vertical,
  183. * without smoothing.
  184. *
  185. * A note about the "bias" calculations: when rounding fractional values to
  186. * integer, we do not want to always round 0.5 up to the next integer.
  187. * If we did that, we'd introduce a noticeable bias towards larger values.
  188. * Instead, this code is arranged so that 0.5 will be rounded up or down at
  189. * alternate pixel locations (a simple ordered dither pattern).
  190. */
  191. METHODDEF(void)
  192. h2v1_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
  193. JSAMPARRAY input_data, JSAMPARRAY output_data)
  194. {
  195. int inrow;
  196. JDIMENSION outcol;
  197. JDIMENSION output_cols = compptr->width_in_blocks * compptr->DCT_h_scaled_size;
  198. register JSAMPROW inptr, outptr;
  199. register int bias;
  200. /* Expand input data enough to let all the output samples be generated
  201. * by the standard loop. Special-casing padded output would be more
  202. * efficient.
  203. */
  204. expand_right_edge(input_data, cinfo->max_v_samp_factor,
  205. cinfo->image_width, output_cols * 2);
  206. for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) {
  207. outptr = output_data[inrow];
  208. inptr = input_data[inrow];
  209. bias = 0; /* bias = 0,1,0,1,... for successive samples */
  210. for (outcol = 0; outcol < output_cols; outcol++) {
  211. *outptr++ = (JSAMPLE) ((GETJSAMPLE(*inptr) + GETJSAMPLE(inptr[1])
  212. + bias) >> 1);
  213. bias ^= 1; /* 0=>1, 1=>0 */
  214. inptr += 2;
  215. }
  216. }
  217. }
  218. /*
  219. * Downsample pixel values of a single component.
  220. * This version handles the standard case of 2:1 horizontal and 2:1 vertical,
  221. * without smoothing.
  222. */
  223. METHODDEF(void)
  224. h2v2_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
  225. JSAMPARRAY input_data, JSAMPARRAY output_data)
  226. {
  227. int inrow, outrow;
  228. JDIMENSION outcol;
  229. JDIMENSION output_cols = compptr->width_in_blocks * compptr->DCT_h_scaled_size;
  230. register JSAMPROW inptr0, inptr1, outptr;
  231. register int bias;
  232. /* Expand input data enough to let all the output samples be generated
  233. * by the standard loop. Special-casing padded output would be more
  234. * efficient.
  235. */
  236. expand_right_edge(input_data, cinfo->max_v_samp_factor,
  237. cinfo->image_width, output_cols * 2);
  238. inrow = outrow = 0;
  239. while (inrow < cinfo->max_v_samp_factor) {
  240. outptr = output_data[outrow];
  241. inptr0 = input_data[inrow];
  242. inptr1 = input_data[inrow+1];
  243. bias = 1; /* bias = 1,2,1,2,... for successive samples */
  244. for (outcol = 0; outcol < output_cols; outcol++) {
  245. *outptr++ = (JSAMPLE) ((GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
  246. GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1])
  247. + bias) >> 2);
  248. bias ^= 3; /* 1=>2, 2=>1 */
  249. inptr0 += 2; inptr1 += 2;
  250. }
  251. inrow += 2;
  252. outrow++;
  253. }
  254. }
  255. #ifdef INPUT_SMOOTHING_SUPPORTED
  256. /*
  257. * Downsample pixel values of a single component.
  258. * This version handles the standard case of 2:1 horizontal and 2:1 vertical,
  259. * with smoothing. One row of context is required.
  260. */
  261. METHODDEF(void)
  262. h2v2_smooth_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
  263. JSAMPARRAY input_data, JSAMPARRAY output_data)
  264. {
  265. int inrow, outrow;
  266. JDIMENSION colctr;
  267. JDIMENSION output_cols = compptr->width_in_blocks * compptr->DCT_h_scaled_size;
  268. register JSAMPROW inptr0, inptr1, above_ptr, below_ptr, outptr;
  269. INT32 membersum, neighsum, memberscale, neighscale;
  270. /* Expand input data enough to let all the output samples be generated
  271. * by the standard loop. Special-casing padded output would be more
  272. * efficient.
  273. */
  274. expand_right_edge(input_data - 1, cinfo->max_v_samp_factor + 2,
  275. cinfo->image_width, output_cols * 2);
  276. /* We don't bother to form the individual "smoothed" input pixel values;
  277. * we can directly compute the output which is the average of the four
  278. * smoothed values. Each of the four member pixels contributes a fraction
  279. * (1-8*SF) to its own smoothed image and a fraction SF to each of the three
  280. * other smoothed pixels, therefore a total fraction (1-5*SF)/4 to the final
  281. * output. The four corner-adjacent neighbor pixels contribute a fraction
  282. * SF to just one smoothed pixel, or SF/4 to the final output; while the
  283. * eight edge-adjacent neighbors contribute SF to each of two smoothed
  284. * pixels, or SF/2 overall. In order to use integer arithmetic, these
  285. * factors are scaled by 2^16 = 65536.
  286. * Also recall that SF = smoothing_factor / 1024.
  287. */
  288. memberscale = 16384 - cinfo->smoothing_factor * 80; /* scaled (1-5*SF)/4 */
  289. neighscale = cinfo->smoothing_factor * 16; /* scaled SF/4 */
  290. inrow = outrow = 0;
  291. while (inrow < cinfo->max_v_samp_factor) {
  292. outptr = output_data[outrow];
  293. inptr0 = input_data[inrow];
  294. inptr1 = input_data[inrow+1];
  295. above_ptr = input_data[inrow-1];
  296. below_ptr = input_data[inrow+2];
  297. /* Special case for first column: pretend column -1 is same as column 0 */
  298. membersum = GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
  299. GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]);
  300. neighsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[1]) +
  301. GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[1]) +
  302. GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[2]) +
  303. GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[2]);
  304. neighsum += neighsum;
  305. neighsum += GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[2]) +
  306. GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[2]);
  307. membersum = membersum * memberscale + neighsum * neighscale;
  308. *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16);
  309. inptr0 += 2; inptr1 += 2; above_ptr += 2; below_ptr += 2;
  310. for (colctr = output_cols - 2; colctr > 0; colctr--) {
  311. /* sum of pixels directly mapped to this output element */
  312. membersum = GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
  313. GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]);
  314. /* sum of edge-neighbor pixels */
  315. neighsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[1]) +
  316. GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[1]) +
  317. GETJSAMPLE(inptr0[-1]) + GETJSAMPLE(inptr0[2]) +
  318. GETJSAMPLE(inptr1[-1]) + GETJSAMPLE(inptr1[2]);
  319. /* The edge-neighbors count twice as much as corner-neighbors */
  320. neighsum += neighsum;
  321. /* Add in the corner-neighbors */
  322. neighsum += GETJSAMPLE(above_ptr[-1]) + GETJSAMPLE(above_ptr[2]) +
  323. GETJSAMPLE(below_ptr[-1]) + GETJSAMPLE(below_ptr[2]);
  324. /* form final output scaled up by 2^16 */
  325. membersum = membersum * memberscale + neighsum * neighscale;
  326. /* round, descale and output it */
  327. *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16);
  328. inptr0 += 2; inptr1 += 2; above_ptr += 2; below_ptr += 2;
  329. }
  330. /* Special case for last column */
  331. membersum = GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
  332. GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]);
  333. neighsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[1]) +
  334. GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[1]) +
  335. GETJSAMPLE(inptr0[-1]) + GETJSAMPLE(inptr0[1]) +
  336. GETJSAMPLE(inptr1[-1]) + GETJSAMPLE(inptr1[1]);
  337. neighsum += neighsum;
  338. neighsum += GETJSAMPLE(above_ptr[-1]) + GETJSAMPLE(above_ptr[1]) +
  339. GETJSAMPLE(below_ptr[-1]) + GETJSAMPLE(below_ptr[1]);
  340. membersum = membersum * memberscale + neighsum * neighscale;
  341. *outptr = (JSAMPLE) ((membersum + 32768) >> 16);
  342. inrow += 2;
  343. outrow++;
  344. }
  345. }
  346. /*
  347. * Downsample pixel values of a single component.
  348. * This version handles the special case of a full-size component,
  349. * with smoothing. One row of context is required.
  350. */
  351. METHODDEF(void)
  352. fullsize_smooth_downsample (j_compress_ptr cinfo, jpeg_component_info *compptr,
  353. JSAMPARRAY input_data, JSAMPARRAY output_data)
  354. {
  355. int inrow;
  356. JDIMENSION colctr;
  357. JDIMENSION output_cols = compptr->width_in_blocks * compptr->DCT_h_scaled_size;
  358. register JSAMPROW inptr, above_ptr, below_ptr, outptr;
  359. INT32 membersum, neighsum, memberscale, neighscale;
  360. int colsum, lastcolsum, nextcolsum;
  361. /* Expand input data enough to let all the output samples be generated
  362. * by the standard loop. Special-casing padded output would be more
  363. * efficient.
  364. */
  365. expand_right_edge(input_data - 1, cinfo->max_v_samp_factor + 2,
  366. cinfo->image_width, output_cols);
  367. /* Each of the eight neighbor pixels contributes a fraction SF to the
  368. * smoothed pixel, while the main pixel contributes (1-8*SF). In order
  369. * to use integer arithmetic, these factors are multiplied by 2^16 = 65536.
  370. * Also recall that SF = smoothing_factor / 1024.
  371. */
  372. memberscale = 65536L - cinfo->smoothing_factor * 512L; /* scaled 1-8*SF */
  373. neighscale = cinfo->smoothing_factor * 64; /* scaled SF */
  374. for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) {
  375. outptr = output_data[inrow];
  376. inptr = input_data[inrow];
  377. above_ptr = input_data[inrow-1];
  378. below_ptr = input_data[inrow+1];
  379. /* Special case for first column */
  380. colsum = GETJSAMPLE(*above_ptr++) + GETJSAMPLE(*below_ptr++) +
  381. GETJSAMPLE(*inptr);
  382. membersum = GETJSAMPLE(*inptr++);
  383. nextcolsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(*below_ptr) +
  384. GETJSAMPLE(*inptr);
  385. neighsum = colsum + (colsum - membersum) + nextcolsum;
  386. membersum = membersum * memberscale + neighsum * neighscale;
  387. *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16);
  388. lastcolsum = colsum; colsum = nextcolsum;
  389. for (colctr = output_cols - 2; colctr > 0; colctr--) {
  390. membersum = GETJSAMPLE(*inptr++);
  391. above_ptr++; below_ptr++;
  392. nextcolsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(*below_ptr) +
  393. GETJSAMPLE(*inptr);
  394. neighsum = lastcolsum + (colsum - membersum) + nextcolsum;
  395. membersum = membersum * memberscale + neighsum * neighscale;
  396. *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16);
  397. lastcolsum = colsum; colsum = nextcolsum;
  398. }
  399. /* Special case for last column */
  400. membersum = GETJSAMPLE(*inptr);
  401. neighsum = lastcolsum + (colsum - membersum) + colsum;
  402. membersum = membersum * memberscale + neighsum * neighscale;
  403. *outptr = (JSAMPLE) ((membersum + 32768) >> 16);
  404. }
  405. }
  406. #endif /* INPUT_SMOOTHING_SUPPORTED */
  407. /*
  408. * Module initialization routine for downsampling.
  409. * Note that we must select a routine for each component.
  410. */
  411. GLOBAL(void)
  412. jinit_downsampler (j_compress_ptr cinfo)
  413. {
  414. my_downsample_ptr downsample;
  415. int ci;
  416. jpeg_component_info * compptr;
  417. boolean smoothok = TRUE;
  418. int h_in_group, v_in_group, h_out_group, v_out_group;
  419. downsample = (my_downsample_ptr)
  420. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  421. SIZEOF(my_downsampler));
  422. cinfo->downsample = (struct jpeg_downsampler *) downsample;
  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. }