jcsample.c 20 KB

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