jdmainct.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514
  1. /*
  2. * jdmainct.c
  3. *
  4. * Copyright (C) 1994-1996, Thomas G. Lane.
  5. * Modified 2002-2012 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 the main buffer controller for decompression.
  10. * The main buffer lies between the JPEG decompressor proper and the
  11. * post-processor; it holds downsampled data in the JPEG colorspace.
  12. *
  13. * Note that this code is bypassed in raw-data mode, since the application
  14. * supplies the equivalent of the main buffer in that case.
  15. */
  16. #define JPEG_INTERNALS
  17. #include "jinclude.h"
  18. #include "jpeglib.h"
  19. /*
  20. * In the current system design, the main buffer need never be a full-image
  21. * buffer; any full-height buffers will be found inside the coefficient or
  22. * postprocessing controllers. Nonetheless, the main controller is not
  23. * trivial. Its responsibility is to provide context rows for upsampling/
  24. * rescaling, and doing this in an efficient fashion is a bit tricky.
  25. *
  26. * Postprocessor input data is counted in "row groups". A row group
  27. * is defined to be (v_samp_factor * DCT_scaled_size / min_DCT_scaled_size)
  28. * sample rows of each component. (We require DCT_scaled_size values to be
  29. * chosen such that these numbers are integers. In practice DCT_scaled_size
  30. * values will likely be powers of two, so we actually have the stronger
  31. * condition that DCT_scaled_size / min_DCT_scaled_size is an integer.)
  32. * Upsampling will typically produce max_v_samp_factor pixel rows from each
  33. * row group (times any additional scale factor that the upsampler is
  34. * applying).
  35. *
  36. * The coefficient controller will deliver data to us one iMCU row at a time;
  37. * each iMCU row contains v_samp_factor * DCT_scaled_size sample rows, or
  38. * exactly min_DCT_scaled_size row groups. (This amount of data corresponds
  39. * to one row of MCUs when the image is fully interleaved.) Note that the
  40. * number of sample rows varies across components, but the number of row
  41. * groups does not. Some garbage sample rows may be included in the last iMCU
  42. * row at the bottom of the image.
  43. *
  44. * Depending on the vertical scaling algorithm used, the upsampler may need
  45. * access to the sample row(s) above and below its current input row group.
  46. * The upsampler is required to set need_context_rows TRUE at global selection
  47. * time if so. When need_context_rows is FALSE, this controller can simply
  48. * obtain one iMCU row at a time from the coefficient controller and dole it
  49. * out as row groups to the postprocessor.
  50. *
  51. * When need_context_rows is TRUE, this controller guarantees that the buffer
  52. * passed to postprocessing contains at least one row group's worth of samples
  53. * above and below the row group(s) being processed. Note that the context
  54. * rows "above" the first passed row group appear at negative row offsets in
  55. * the passed buffer. At the top and bottom of the image, the required
  56. * context rows are manufactured by duplicating the first or last real sample
  57. * row; this avoids having special cases in the upsampling inner loops.
  58. *
  59. * The amount of context is fixed at one row group just because that's a
  60. * convenient number for this controller to work with. The existing
  61. * upsamplers really only need one sample row of context. An upsampler
  62. * supporting arbitrary output rescaling might wish for more than one row
  63. * group of context when shrinking the image; tough, we don't handle that.
  64. * (This is justified by the assumption that downsizing will be handled mostly
  65. * by adjusting the DCT_scaled_size values, so that the actual scale factor at
  66. * the upsample step needn't be much less than one.)
  67. *
  68. * To provide the desired context, we have to retain the last two row groups
  69. * of one iMCU row while reading in the next iMCU row. (The last row group
  70. * can't be processed until we have another row group for its below-context,
  71. * and so we have to save the next-to-last group too for its above-context.)
  72. * We could do this most simply by copying data around in our buffer, but
  73. * that'd be very slow. We can avoid copying any data by creating a rather
  74. * strange pointer structure. Here's how it works. We allocate a workspace
  75. * consisting of M+2 row groups (where M = min_DCT_scaled_size is the number
  76. * of row groups per iMCU row). We create two sets of redundant pointers to
  77. * the workspace. Labeling the physical row groups 0 to M+1, the synthesized
  78. * pointer lists look like this:
  79. * M+1 M-1
  80. * master pointer --> 0 master pointer --> 0
  81. * 1 1
  82. * ... ...
  83. * M-3 M-3
  84. * M-2 M
  85. * M-1 M+1
  86. * M M-2
  87. * M+1 M-1
  88. * 0 0
  89. * We read alternate iMCU rows using each master pointer; thus the last two
  90. * row groups of the previous iMCU row remain un-overwritten in the workspace.
  91. * The pointer lists are set up so that the required context rows appear to
  92. * be adjacent to the proper places when we pass the pointer lists to the
  93. * upsampler.
  94. *
  95. * The above pictures describe the normal state of the pointer lists.
  96. * At top and bottom of the image, we diddle the pointer lists to duplicate
  97. * the first or last sample row as necessary (this is cheaper than copying
  98. * sample rows around).
  99. *
  100. * This scheme breaks down if M < 2, ie, min_DCT_scaled_size is 1. In that
  101. * situation each iMCU row provides only one row group so the buffering logic
  102. * must be different (eg, we must read two iMCU rows before we can emit the
  103. * first row group). For now, we simply do not support providing context
  104. * rows when min_DCT_scaled_size is 1. That combination seems unlikely to
  105. * be worth providing --- if someone wants a 1/8th-size preview, they probably
  106. * want it quick and dirty, so a context-free upsampler is sufficient.
  107. */
  108. /* Private buffer controller object */
  109. typedef struct {
  110. struct jpeg_d_main_controller pub; /* public fields */
  111. /* Pointer to allocated workspace (M or M+2 row groups). */
  112. JSAMPARRAY buffer[MAX_COMPONENTS];
  113. boolean buffer_full; /* Have we gotten an iMCU row from decoder? */
  114. JDIMENSION rowgroup_ctr; /* counts row groups output to postprocessor */
  115. /* Remaining fields are only used in the context case. */
  116. /* These are the master pointers to the funny-order pointer lists. */
  117. JSAMPIMAGE xbuffer[2]; /* pointers to weird pointer lists */
  118. int whichptr; /* indicates which pointer set is now in use */
  119. int context_state; /* process_data state machine status */
  120. JDIMENSION rowgroups_avail; /* row groups available to postprocessor */
  121. JDIMENSION iMCU_row_ctr; /* counts iMCU rows to detect image top/bot */
  122. } my_main_controller;
  123. typedef my_main_controller * my_main_ptr;
  124. /* context_state values: */
  125. #define CTX_PREPARE_FOR_IMCU 0 /* need to prepare for MCU row */
  126. #define CTX_PROCESS_IMCU 1 /* feeding iMCU to postprocessor */
  127. #define CTX_POSTPONED_ROW 2 /* feeding postponed row group */
  128. /* Forward declarations */
  129. METHODDEF(void) process_data_simple_main
  130. JPP((j_decompress_ptr cinfo, JSAMPARRAY output_buf,
  131. JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail));
  132. METHODDEF(void) process_data_context_main
  133. JPP((j_decompress_ptr cinfo, JSAMPARRAY output_buf,
  134. JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail));
  135. #ifdef QUANT_2PASS_SUPPORTED
  136. METHODDEF(void) process_data_crank_post
  137. JPP((j_decompress_ptr cinfo, JSAMPARRAY output_buf,
  138. JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail));
  139. #endif
  140. LOCAL(void)
  141. alloc_funny_pointers (j_decompress_ptr cinfo)
  142. /* Allocate space for the funny pointer lists.
  143. * This is done only once, not once per pass.
  144. */
  145. {
  146. my_main_ptr mainp = (my_main_ptr) cinfo->main;
  147. int ci, rgroup;
  148. int M = cinfo->min_DCT_v_scaled_size;
  149. jpeg_component_info *compptr;
  150. JSAMPARRAY xbuf;
  151. /* Get top-level space for component array pointers.
  152. * We alloc both arrays with one call to save a few cycles.
  153. */
  154. mainp->xbuffer[0] = (JSAMPIMAGE)
  155. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  156. cinfo->num_components * 2 * SIZEOF(JSAMPARRAY));
  157. mainp->xbuffer[1] = mainp->xbuffer[0] + cinfo->num_components;
  158. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  159. ci++, compptr++) {
  160. rgroup = (compptr->v_samp_factor * compptr->DCT_v_scaled_size) /
  161. cinfo->min_DCT_v_scaled_size; /* height of a row group of component */
  162. /* Get space for pointer lists --- M+4 row groups in each list.
  163. * We alloc both pointer lists with one call to save a few cycles.
  164. */
  165. xbuf = (JSAMPARRAY)
  166. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  167. 2 * (rgroup * (M + 4)) * SIZEOF(JSAMPROW));
  168. xbuf += rgroup; /* want one row group at negative offsets */
  169. mainp->xbuffer[0][ci] = xbuf;
  170. xbuf += rgroup * (M + 4);
  171. mainp->xbuffer[1][ci] = xbuf;
  172. }
  173. }
  174. LOCAL(void)
  175. make_funny_pointers (j_decompress_ptr cinfo)
  176. /* Create the funny pointer lists discussed in the comments above.
  177. * The actual workspace is already allocated (in main->buffer),
  178. * and the space for the pointer lists is allocated too.
  179. * This routine just fills in the curiously ordered lists.
  180. * This will be repeated at the beginning of each pass.
  181. */
  182. {
  183. my_main_ptr mainp = (my_main_ptr) cinfo->main;
  184. int ci, i, rgroup;
  185. int M = cinfo->min_DCT_v_scaled_size;
  186. jpeg_component_info *compptr;
  187. JSAMPARRAY buf, xbuf0, xbuf1;
  188. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  189. ci++, compptr++) {
  190. rgroup = (compptr->v_samp_factor * compptr->DCT_v_scaled_size) /
  191. cinfo->min_DCT_v_scaled_size; /* height of a row group of component */
  192. xbuf0 = mainp->xbuffer[0][ci];
  193. xbuf1 = mainp->xbuffer[1][ci];
  194. /* First copy the workspace pointers as-is */
  195. buf = mainp->buffer[ci];
  196. for (i = 0; i < rgroup * (M + 2); i++) {
  197. xbuf0[i] = xbuf1[i] = buf[i];
  198. }
  199. /* In the second list, put the last four row groups in swapped order */
  200. for (i = 0; i < rgroup * 2; i++) {
  201. xbuf1[rgroup*(M-2) + i] = buf[rgroup*M + i];
  202. xbuf1[rgroup*M + i] = buf[rgroup*(M-2) + i];
  203. }
  204. /* The wraparound pointers at top and bottom will be filled later
  205. * (see set_wraparound_pointers, below). Initially we want the "above"
  206. * pointers to duplicate the first actual data line. This only needs
  207. * to happen in xbuffer[0].
  208. */
  209. for (i = 0; i < rgroup; i++) {
  210. xbuf0[i - rgroup] = xbuf0[0];
  211. }
  212. }
  213. }
  214. LOCAL(void)
  215. set_wraparound_pointers (j_decompress_ptr cinfo)
  216. /* Set up the "wraparound" pointers at top and bottom of the pointer lists.
  217. * This changes the pointer list state from top-of-image to the normal state.
  218. */
  219. {
  220. my_main_ptr mainp = (my_main_ptr) cinfo->main;
  221. int ci, i, rgroup;
  222. int M = cinfo->min_DCT_v_scaled_size;
  223. jpeg_component_info *compptr;
  224. JSAMPARRAY xbuf0, xbuf1;
  225. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  226. ci++, compptr++) {
  227. rgroup = (compptr->v_samp_factor * compptr->DCT_v_scaled_size) /
  228. cinfo->min_DCT_v_scaled_size; /* height of a row group of component */
  229. xbuf0 = mainp->xbuffer[0][ci];
  230. xbuf1 = mainp->xbuffer[1][ci];
  231. for (i = 0; i < rgroup; i++) {
  232. xbuf0[i - rgroup] = xbuf0[rgroup*(M+1) + i];
  233. xbuf1[i - rgroup] = xbuf1[rgroup*(M+1) + i];
  234. xbuf0[rgroup*(M+2) + i] = xbuf0[i];
  235. xbuf1[rgroup*(M+2) + i] = xbuf1[i];
  236. }
  237. }
  238. }
  239. LOCAL(void)
  240. set_bottom_pointers (j_decompress_ptr cinfo)
  241. /* Change the pointer lists to duplicate the last sample row at the bottom
  242. * of the image. whichptr indicates which xbuffer holds the final iMCU row.
  243. * Also sets rowgroups_avail to indicate number of nondummy row groups in row.
  244. */
  245. {
  246. my_main_ptr mainp = (my_main_ptr) cinfo->main;
  247. int ci, i, rgroup, iMCUheight, rows_left;
  248. jpeg_component_info *compptr;
  249. JSAMPARRAY xbuf;
  250. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  251. ci++, compptr++) {
  252. /* Count sample rows in one iMCU row and in one row group */
  253. iMCUheight = compptr->v_samp_factor * compptr->DCT_v_scaled_size;
  254. rgroup = iMCUheight / cinfo->min_DCT_v_scaled_size;
  255. /* Count nondummy sample rows remaining for this component */
  256. rows_left = (int) (compptr->downsampled_height % (JDIMENSION) iMCUheight);
  257. if (rows_left == 0) rows_left = iMCUheight;
  258. /* Count nondummy row groups. Should get same answer for each component,
  259. * so we need only do it once.
  260. */
  261. if (ci == 0) {
  262. mainp->rowgroups_avail = (JDIMENSION) ((rows_left-1) / rgroup + 1);
  263. }
  264. /* Duplicate the last real sample row rgroup*2 times; this pads out the
  265. * last partial rowgroup and ensures at least one full rowgroup of context.
  266. */
  267. xbuf = mainp->xbuffer[mainp->whichptr][ci];
  268. for (i = 0; i < rgroup * 2; i++) {
  269. xbuf[rows_left + i] = xbuf[rows_left-1];
  270. }
  271. }
  272. }
  273. /*
  274. * Initialize for a processing pass.
  275. */
  276. METHODDEF(void)
  277. start_pass_main (j_decompress_ptr cinfo, J_BUF_MODE pass_mode)
  278. {
  279. my_main_ptr mainp = (my_main_ptr) cinfo->main;
  280. switch (pass_mode) {
  281. case JBUF_PASS_THRU:
  282. if (cinfo->upsample->need_context_rows) {
  283. mainp->pub.process_data = process_data_context_main;
  284. make_funny_pointers(cinfo); /* Create the xbuffer[] lists */
  285. mainp->whichptr = 0; /* Read first iMCU row into xbuffer[0] */
  286. mainp->context_state = CTX_PREPARE_FOR_IMCU;
  287. mainp->iMCU_row_ctr = 0;
  288. } else {
  289. /* Simple case with no context needed */
  290. mainp->pub.process_data = process_data_simple_main;
  291. }
  292. mainp->buffer_full = FALSE; /* Mark buffer empty */
  293. mainp->rowgroup_ctr = 0;
  294. break;
  295. #ifdef QUANT_2PASS_SUPPORTED
  296. case JBUF_CRANK_DEST:
  297. /* For last pass of 2-pass quantization, just crank the postprocessor */
  298. mainp->pub.process_data = process_data_crank_post;
  299. break;
  300. #endif
  301. default:
  302. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  303. break;
  304. }
  305. }
  306. /*
  307. * Process some data.
  308. * This handles the simple case where no context is required.
  309. */
  310. METHODDEF(void)
  311. process_data_simple_main (j_decompress_ptr cinfo,
  312. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  313. JDIMENSION out_rows_avail)
  314. {
  315. my_main_ptr mainp = (my_main_ptr) cinfo->main;
  316. JDIMENSION rowgroups_avail;
  317. /* Read input data if we haven't filled the main buffer yet */
  318. if (! mainp->buffer_full) {
  319. if (! (*cinfo->coef->decompress_data) (cinfo, mainp->buffer))
  320. return; /* suspension forced, can do nothing more */
  321. mainp->buffer_full = TRUE; /* OK, we have an iMCU row to work with */
  322. }
  323. /* There are always min_DCT_scaled_size row groups in an iMCU row. */
  324. rowgroups_avail = (JDIMENSION) cinfo->min_DCT_v_scaled_size;
  325. /* Note: at the bottom of the image, we may pass extra garbage row groups
  326. * to the postprocessor. The postprocessor has to check for bottom
  327. * of image anyway (at row resolution), so no point in us doing it too.
  328. */
  329. /* Feed the postprocessor */
  330. (*cinfo->post->post_process_data) (cinfo, mainp->buffer,
  331. &mainp->rowgroup_ctr, rowgroups_avail,
  332. output_buf, out_row_ctr, out_rows_avail);
  333. /* Has postprocessor consumed all the data yet? If so, mark buffer empty */
  334. if (mainp->rowgroup_ctr >= rowgroups_avail) {
  335. mainp->buffer_full = FALSE;
  336. mainp->rowgroup_ctr = 0;
  337. }
  338. }
  339. /*
  340. * Process some data.
  341. * This handles the case where context rows must be provided.
  342. */
  343. METHODDEF(void)
  344. process_data_context_main (j_decompress_ptr cinfo,
  345. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  346. JDIMENSION out_rows_avail)
  347. {
  348. my_main_ptr mainp = (my_main_ptr) cinfo->main;
  349. /* Read input data if we haven't filled the main buffer yet */
  350. if (! mainp->buffer_full) {
  351. if (! (*cinfo->coef->decompress_data) (cinfo,
  352. mainp->xbuffer[mainp->whichptr]))
  353. return; /* suspension forced, can do nothing more */
  354. mainp->buffer_full = TRUE; /* OK, we have an iMCU row to work with */
  355. mainp->iMCU_row_ctr++; /* count rows received */
  356. }
  357. /* Postprocessor typically will not swallow all the input data it is handed
  358. * in one call (due to filling the output buffer first). Must be prepared
  359. * to exit and restart. This switch lets us keep track of how far we got.
  360. * Note that each case falls through to the next on successful completion.
  361. */
  362. switch (mainp->context_state) {
  363. case CTX_POSTPONED_ROW:
  364. /* Call postprocessor using previously set pointers for postponed row */
  365. (*cinfo->post->post_process_data) (cinfo, mainp->xbuffer[mainp->whichptr],
  366. &mainp->rowgroup_ctr, mainp->rowgroups_avail,
  367. output_buf, out_row_ctr, out_rows_avail);
  368. if (mainp->rowgroup_ctr < mainp->rowgroups_avail)
  369. return; /* Need to suspend */
  370. mainp->context_state = CTX_PREPARE_FOR_IMCU;
  371. if (*out_row_ctr >= out_rows_avail)
  372. return; /* Postprocessor exactly filled output buf */
  373. /*FALLTHROUGH*/
  374. case CTX_PREPARE_FOR_IMCU:
  375. /* Prepare to process first M-1 row groups of this iMCU row */
  376. mainp->rowgroup_ctr = 0;
  377. mainp->rowgroups_avail = (JDIMENSION) (cinfo->min_DCT_v_scaled_size - 1);
  378. /* Check for bottom of image: if so, tweak pointers to "duplicate"
  379. * the last sample row, and adjust rowgroups_avail to ignore padding rows.
  380. */
  381. if (mainp->iMCU_row_ctr == cinfo->total_iMCU_rows)
  382. set_bottom_pointers(cinfo);
  383. mainp->context_state = CTX_PROCESS_IMCU;
  384. /*FALLTHROUGH*/
  385. case CTX_PROCESS_IMCU:
  386. /* Call postprocessor using previously set pointers */
  387. (*cinfo->post->post_process_data) (cinfo, mainp->xbuffer[mainp->whichptr],
  388. &mainp->rowgroup_ctr, mainp->rowgroups_avail,
  389. output_buf, out_row_ctr, out_rows_avail);
  390. if (mainp->rowgroup_ctr < mainp->rowgroups_avail)
  391. return; /* Need to suspend */
  392. /* After the first iMCU, change wraparound pointers to normal state */
  393. if (mainp->iMCU_row_ctr == 1)
  394. set_wraparound_pointers(cinfo);
  395. /* Prepare to load new iMCU row using other xbuffer list */
  396. mainp->whichptr ^= 1; /* 0=>1 or 1=>0 */
  397. mainp->buffer_full = FALSE;
  398. /* Still need to process last row group of this iMCU row, */
  399. /* which is saved at index M+1 of the other xbuffer */
  400. mainp->rowgroup_ctr = (JDIMENSION) (cinfo->min_DCT_v_scaled_size + 1);
  401. mainp->rowgroups_avail = (JDIMENSION) (cinfo->min_DCT_v_scaled_size + 2);
  402. mainp->context_state = CTX_POSTPONED_ROW;
  403. }
  404. }
  405. /*
  406. * Process some data.
  407. * Final pass of two-pass quantization: just call the postprocessor.
  408. * Source data will be the postprocessor controller's internal buffer.
  409. */
  410. #ifdef QUANT_2PASS_SUPPORTED
  411. METHODDEF(void)
  412. process_data_crank_post (j_decompress_ptr cinfo,
  413. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  414. JDIMENSION out_rows_avail)
  415. {
  416. (*cinfo->post->post_process_data) (cinfo, (JSAMPIMAGE) NULL,
  417. (JDIMENSION *) NULL, (JDIMENSION) 0,
  418. output_buf, out_row_ctr, out_rows_avail);
  419. }
  420. #endif /* QUANT_2PASS_SUPPORTED */
  421. /*
  422. * Initialize main buffer controller.
  423. */
  424. GLOBAL(void)
  425. jinit_d_main_controller (j_decompress_ptr cinfo, boolean need_full_buffer)
  426. {
  427. my_main_ptr mainp;
  428. int ci, rgroup, ngroups;
  429. jpeg_component_info *compptr;
  430. mainp = (my_main_ptr)
  431. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  432. SIZEOF(my_main_controller));
  433. cinfo->main = &mainp->pub;
  434. mainp->pub.start_pass = start_pass_main;
  435. if (need_full_buffer) /* shouldn't happen */
  436. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  437. /* Allocate the workspace.
  438. * ngroups is the number of row groups we need.
  439. */
  440. if (cinfo->upsample->need_context_rows) {
  441. if (cinfo->min_DCT_v_scaled_size < 2) /* unsupported, see comments above */
  442. ERREXIT(cinfo, JERR_NOTIMPL);
  443. alloc_funny_pointers(cinfo); /* Alloc space for xbuffer[] lists */
  444. ngroups = cinfo->min_DCT_v_scaled_size + 2;
  445. } else {
  446. ngroups = cinfo->min_DCT_v_scaled_size;
  447. }
  448. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  449. ci++, compptr++) {
  450. rgroup = (compptr->v_samp_factor * compptr->DCT_v_scaled_size) /
  451. cinfo->min_DCT_v_scaled_size; /* height of a row group of component */
  452. mainp->buffer[ci] = (*cinfo->mem->alloc_sarray)
  453. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  454. compptr->width_in_blocks * ((JDIMENSION) compptr->DCT_h_scaled_size),
  455. (JDIMENSION) (rgroup * ngroups));
  456. }
  457. }