jcsample.c 20 KB

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