home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume29 / jpeg / part03 < prev    next >
Text File  |  1992-03-24  |  55KB  |  1,442 lines

  1. Newsgroups: comp.sources.misc
  2. From: jpeg-info@uunet.uu.net (Independent JPEG Group)
  3. Subject:  v29i003:  jpeg - JPEG image compression, Part03/18
  4. Message-ID: <1992Mar24.072645.19578@sparky.imd.sterling.com>
  5. X-Md4-Signature: d51e614d771008e271e5711a2b601c62
  6. Date: Tue, 24 Mar 1992 07:26:45 GMT
  7. Approved: kent@sparky.imd.sterling.com
  8.  
  9. Submitted-by: jpeg-info@uunet.uu.net (Independent JPEG Group)
  10. Posting-number: Volume 29, Issue 3
  11. Archive-name: jpeg/part03
  12. Environment: UNIX, VMS, MS-DOS, Mac, Amiga, Cray
  13.  
  14. #! /bin/sh
  15. # into a shell via "sh file" or similar.  To overwrite existing files,
  16. # type "sh file -c".
  17. # The tool that generated this appeared in the comp.sources.unix newsgroup;
  18. # send mail to comp-sources-unix@uunet.uu.net if you want that tool.
  19. # Contents:  jcdeflts.c jdpipe.c
  20. # Wrapped by kent@sparky on Mon Mar 23 16:02:41 1992
  21. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  22. echo If this archive is complete, you will see the following message:
  23. echo '          "shar: End of archive 3 (of 18)."'
  24. if test -f 'jcdeflts.c' -a "${1}" != "-c" ; then 
  25.   echo shar: Will not clobber existing file \"'jcdeflts.c'\"
  26. else
  27.   echo shar: Extracting \"'jcdeflts.c'\" \(14213 characters\)
  28.   sed "s/^X//" >'jcdeflts.c' <<'END_OF_FILE'
  29. X/*
  30. X * jcdeflts.c
  31. X *
  32. X * Copyright (C) 1991, 1992, Thomas G. Lane.
  33. X * This file is part of the Independent JPEG Group's software.
  34. X * For conditions of distribution and use, see the accompanying README file.
  35. X *
  36. X * This file contains optional default-setting code for the JPEG compressor.
  37. X * User interfaces do not have to use this file, but those that don't use it
  38. X * must know a lot more about the innards of the JPEG code.
  39. X */
  40. X
  41. X#include "jinclude.h"
  42. X
  43. X
  44. X/* Default do-nothing progress monitoring routine.
  45. X * This can be overridden by a user interface that wishes to
  46. X * provide progress monitoring; just set methods->progress_monitor
  47. X * after j_c_defaults is done.  The routine will be called periodically
  48. X * during the compression process.
  49. X *
  50. X * During any one pass, loopcounter increases from 0 up to (not including)
  51. X * looplimit; the step size is not necessarily 1.  Both the step size and
  52. X * the limit may differ between passes.  The expected total number of passes
  53. X * is in cinfo->total_passes, and the number of passes already completed is
  54. X * in cinfo->completed_passes.  Thus the fraction of work completed may be
  55. X * estimated as
  56. X *        completed_passes + (loopcounter/looplimit)
  57. X *        ------------------------------------------
  58. X *                total_passes
  59. X * ignoring the fact that the passes may not be equal amounts of work.
  60. X */
  61. X
  62. XMETHODDEF void
  63. Xprogress_monitor (compress_info_ptr cinfo, long loopcounter, long looplimit)
  64. X{
  65. X  /* do nothing */
  66. X}
  67. X
  68. X
  69. X/*
  70. X * Table setup routines
  71. X */
  72. X
  73. XLOCAL void
  74. Xadd_huff_table (compress_info_ptr cinfo,
  75. X        HUFF_TBL **htblptr, const UINT8 *bits, const UINT8 *val)
  76. X/* Define a Huffman table */
  77. X{
  78. X  if (*htblptr == NULL)
  79. X    *htblptr = (HUFF_TBL *) (*cinfo->emethods->alloc_small) (SIZEOF(HUFF_TBL));
  80. X  
  81. X  memcpy((void *) (*htblptr)->bits, (const void *) bits,
  82. X     SIZEOF((*htblptr)->bits));
  83. X  memcpy((void *) (*htblptr)->huffval, (const void *) val,
  84. X     SIZEOF((*htblptr)->huffval));
  85. X
  86. X  /* Initialize sent_table FALSE so table will be written to JPEG file.
  87. X   * In an application where we are writing non-interchange JPEG files,
  88. X   * it might be desirable to save space by leaving default Huffman tables
  89. X   * out of the file.  To do that, just initialize sent_table = TRUE...
  90. X   */
  91. X
  92. X  (*htblptr)->sent_table = FALSE;
  93. X}
  94. X
  95. X
  96. XLOCAL void
  97. Xstd_huff_tables (compress_info_ptr cinfo)
  98. X/* Set up the standard Huffman tables (cf. JPEG standard section K.3) */
  99. X/* IMPORTANT: these are only valid for 8-bit data precision! */
  100. X{
  101. X  static const UINT8 dc_luminance_bits[17] =
  102. X    { /* 0-base */ 0, 0, 1, 5, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0 };
  103. X  static const UINT8 dc_luminance_val[] =
  104. X    { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
  105. X  
  106. X  static const UINT8 dc_chrominance_bits[17] =
  107. X    { /* 0-base */ 0, 0, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 };
  108. X  static const UINT8 dc_chrominance_val[] =
  109. X    { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
  110. X  
  111. X  static const UINT8 ac_luminance_bits[17] =
  112. X    { /* 0-base */ 0, 0, 2, 1, 3, 3, 2, 4, 3, 5, 5, 4, 4, 0, 0, 1, 0x7d };
  113. X  static const UINT8 ac_luminance_val[] =
  114. X    { 0x01, 0x02, 0x03, 0x00, 0x04, 0x11, 0x05, 0x12,
  115. X      0x21, 0x31, 0x41, 0x06, 0x13, 0x51, 0x61, 0x07,
  116. X      0x22, 0x71, 0x14, 0x32, 0x81, 0x91, 0xa1, 0x08,
  117. X      0x23, 0x42, 0xb1, 0xc1, 0x15, 0x52, 0xd1, 0xf0,
  118. X      0x24, 0x33, 0x62, 0x72, 0x82, 0x09, 0x0a, 0x16,
  119. X      0x17, 0x18, 0x19, 0x1a, 0x25, 0x26, 0x27, 0x28,
  120. X      0x29, 0x2a, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39,
  121. X      0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49,
  122. X      0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59,
  123. X      0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69,
  124. X      0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79,
  125. X      0x7a, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89,
  126. X      0x8a, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98,
  127. X      0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
  128. X      0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6,
  129. X      0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3, 0xc4, 0xc5,
  130. X      0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2, 0xd3, 0xd4,
  131. X      0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xe1, 0xe2,
  132. X      0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea,
  133. X      0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8,
  134. X      0xf9, 0xfa };
  135. X  
  136. X  static const UINT8 ac_chrominance_bits[17] =
  137. X    { /* 0-base */ 0, 0, 2, 1, 2, 4, 4, 3, 4, 7, 5, 4, 4, 0, 1, 2, 0x77 };
  138. X  static const UINT8 ac_chrominance_val[] =
  139. X    { 0x00, 0x01, 0x02, 0x03, 0x11, 0x04, 0x05, 0x21,
  140. X      0x31, 0x06, 0x12, 0x41, 0x51, 0x07, 0x61, 0x71,
  141. X      0x13, 0x22, 0x32, 0x81, 0x08, 0x14, 0x42, 0x91,
  142. X      0xa1, 0xb1, 0xc1, 0x09, 0x23, 0x33, 0x52, 0xf0,
  143. X      0x15, 0x62, 0x72, 0xd1, 0x0a, 0x16, 0x24, 0x34,
  144. X      0xe1, 0x25, 0xf1, 0x17, 0x18, 0x19, 0x1a, 0x26,
  145. X      0x27, 0x28, 0x29, 0x2a, 0x35, 0x36, 0x37, 0x38,
  146. X      0x39, 0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48,
  147. X      0x49, 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58,
  148. X      0x59, 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68,
  149. X      0x69, 0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78,
  150. X      0x79, 0x7a, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
  151. X      0x88, 0x89, 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96,
  152. X      0x97, 0x98, 0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5,
  153. X      0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4,
  154. X      0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3,
  155. X      0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2,
  156. X      0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda,
  157. X      0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9,
  158. X      0xea, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8,
  159. X      0xf9, 0xfa };
  160. X  
  161. X  add_huff_table(cinfo, &cinfo->dc_huff_tbl_ptrs[0],
  162. X         dc_luminance_bits, dc_luminance_val);
  163. X  add_huff_table(cinfo, &cinfo->ac_huff_tbl_ptrs[0],
  164. X         ac_luminance_bits, ac_luminance_val);
  165. X  add_huff_table(cinfo, &cinfo->dc_huff_tbl_ptrs[1],
  166. X         dc_chrominance_bits, dc_chrominance_val);
  167. X  add_huff_table(cinfo, &cinfo->ac_huff_tbl_ptrs[1],
  168. X         ac_chrominance_bits, ac_chrominance_val);
  169. X}
  170. X
  171. X
  172. X/* This is the sample quantization table given in the JPEG spec section K.1,
  173. X * but expressed in zigzag order (as are all of our quant. tables).
  174. X * The spec says that the values given produce "good" quality, and
  175. X * when divided by 2, "very good" quality.  (These two settings are
  176. X * selected by quality=50 and quality=75 in j_set_quality, below.)
  177. X */
  178. X
  179. X
  180. Xstatic const QUANT_VAL std_luminance_quant_tbl[DCTSIZE2] = {
  181. X  16,  11,  12,  14,  12,  10,  16,  14,
  182. X  13,  14,  18,  17,  16,  19,  24,  40,
  183. X  26,  24,  22,  22,  24,  49,  35,  37,
  184. X  29,  40,  58,  51,  61,  60,  57,  51,
  185. X  56,  55,  64,  72,  92,  78,  64,  68,
  186. X  87,  69,  55,  56,  80, 109,  81,  87,
  187. X  95,  98, 103, 104, 103,  62,  77, 113,
  188. X 121, 112, 100, 120,  92, 101, 103,  99
  189. X};
  190. X
  191. Xstatic const QUANT_VAL std_chrominance_quant_tbl[DCTSIZE2] = {
  192. X  17,  18,  18,  24,  21,  24,  47,  26,
  193. X  26,  47,  99,  66,  56,  66,  99,  99,
  194. X  99,  99,  99,  99,  99,  99,  99,  99,
  195. X  99,  99,  99,  99,  99,  99,  99,  99,
  196. X  99,  99,  99,  99,  99,  99,  99,  99,
  197. X  99,  99,  99,  99,  99,  99,  99,  99,
  198. X  99,  99,  99,  99,  99,  99,  99,  99,
  199. X  99,  99,  99,  99,  99,  99,  99,  99
  200. X};
  201. X
  202. X
  203. XLOCAL void
  204. Xadd_quant_table (compress_info_ptr cinfo, int which_tbl,
  205. X         const QUANT_VAL *basic_table, int scale_factor,
  206. X         boolean force_baseline)
  207. X/* Define a quantization table equal to the basic_table times */
  208. X/* a scale factor (given as a percentage) */
  209. X{
  210. X  QUANT_TBL_PTR * qtblptr = & cinfo->quant_tbl_ptrs[which_tbl];
  211. X  int i;
  212. X  long temp;
  213. X
  214. X  if (*qtblptr == NULL)
  215. X    *qtblptr = (QUANT_TBL_PTR) (*cinfo->emethods->alloc_small) (SIZEOF(QUANT_TBL));
  216. X
  217. X  for (i = 0; i < DCTSIZE2; i++) {
  218. X    temp = ((long) basic_table[i] * scale_factor + 50L) / 100L;
  219. X    /* limit the values to the valid range */
  220. X    if (temp <= 0L) temp = 1L;
  221. X#ifdef EIGHT_BIT_SAMPLES
  222. X    if (temp > 32767L) temp = 32767L; /* QUANT_VALs are 'short' */
  223. X#else
  224. X    if (temp > 65535L) temp = 65535L; /* QUANT_VALs are 'UINT16' */
  225. X#endif
  226. X    if (force_baseline && temp > 255L)
  227. X      temp = 255L;        /* limit to baseline range if requested */
  228. X    (*qtblptr)[i] = (QUANT_VAL) temp;
  229. X  }
  230. X}
  231. X
  232. X
  233. XGLOBAL void
  234. Xj_set_quality (compress_info_ptr cinfo, int quality, boolean force_baseline)
  235. X/* Set or change the 'quality' (quantization) setting. */
  236. X/* The 'quality' factor should be 0 (terrible) to 100 (very good). */
  237. X/* Quality 50 corresponds to the JPEG basic tables given above; */
  238. X/* quality 100 results in no quantization scaling at all. */
  239. X/* If force_baseline is TRUE, quantization table entries are limited */
  240. X/* to 0..255 for JPEG baseline compatibility; this is only an issue */
  241. X/* for quality settings below 24. */
  242. X{
  243. X  /* Safety limit on quality factor.  Convert 0 to 1 to avoid zero divide. */
  244. X  if (quality <= 0) quality = 1;
  245. X  if (quality > 100) quality = 100;
  246. X
  247. X  /* Convert quality rating to a percentage scaling of the basic tables.
  248. X   * The basic table is used as-is (scaling 100) for a quality of 50.
  249. X   * Qualities 50..100 are converted to scaling percentage 200 - 2*Q;
  250. X   * note that at Q=100 the scaling is 0, which will cause add_quant_table
  251. X   * to make all the table entries 1 (hence, no quantization loss).
  252. X   * Qualities 1..50 are converted to scaling percentage 5000/Q.
  253. X   */
  254. X  if (quality < 50)
  255. X    quality = 5000 / quality;
  256. X  else
  257. X    quality = 200 - quality*2;
  258. X
  259. X  /* Set up two quantization tables using the specified quality scaling */
  260. X  add_quant_table(cinfo, 0, std_luminance_quant_tbl, quality, force_baseline);
  261. X  add_quant_table(cinfo, 1, std_chrominance_quant_tbl, quality, force_baseline);
  262. X}
  263. X
  264. X
  265. X
  266. X/* Default parameter setup for compression.
  267. X *
  268. X * User interfaces that don't choose to use this routine must do their
  269. X * own setup of all these parameters.  Alternately, you can call this
  270. X * to establish defaults and then alter parameters selectively.  This
  271. X * is the recommended approach since, if we add any new parameters,
  272. X * your code will still work (they'll be set to reasonable defaults).
  273. X *
  274. X * See above for the meaning of the 'quality' and 'force_baseline' parameters.
  275. X * Typically, the application's default quality setting will be passed to this
  276. X * routine.  A later call on j_set_quality() can be used to change to a
  277. X * user-specified quality setting.
  278. X *
  279. X * This routine sets up for a color image; to output a grayscale image,
  280. X * do this first and call j_monochrome_default() afterwards.
  281. X * (The latter can be called within c_ui_method_selection, so the
  282. X * choice can depend on the input file header.)
  283. X * Note that if you want a JPEG colorspace other than GRAYSCALE or YCbCr,
  284. X * you should also change the component ID codes, and you should NOT emit
  285. X * a JFIF header (set write_JFIF_header = FALSE).
  286. X *
  287. X * CAUTION: if you want to compress multiple images per run, it's necessary
  288. X * to call j_c_defaults before *each* call to jpeg_compress, since subsidiary
  289. X * structures like the Huffman tables are automatically freed during cleanup.
  290. X */
  291. X
  292. XGLOBAL void
  293. Xj_c_defaults (compress_info_ptr cinfo, int quality, boolean force_baseline)
  294. X/* NB: the external methods must already be set up. */
  295. X{
  296. X  short i;
  297. X  jpeg_component_info * compptr;
  298. X
  299. X  /* Initialize pointers as needed to mark stuff unallocated. */
  300. X  cinfo->comp_info = NULL;
  301. X  for (i = 0; i < NUM_QUANT_TBLS; i++)
  302. X    cinfo->quant_tbl_ptrs[i] = NULL;
  303. X  for (i = 0; i < NUM_HUFF_TBLS; i++) {
  304. X    cinfo->dc_huff_tbl_ptrs[i] = NULL;
  305. X    cinfo->ac_huff_tbl_ptrs[i] = NULL;
  306. X  }
  307. X
  308. X  cinfo->data_precision = BITS_IN_JSAMPLE; /* default; can be overridden by input_init */
  309. X  cinfo->density_unit = 0;    /* Pixel size is unknown by default */
  310. X  cinfo->X_density = 1;        /* Pixel aspect ratio is square by default */
  311. X  cinfo->Y_density = 1;
  312. X
  313. X  cinfo->input_gamma = 1.0;    /* no gamma correction by default */
  314. X
  315. X  /* Prepare three color components; first is luminance which is also usable */
  316. X  /* for grayscale.  The others are assumed to be UV or similar chrominance. */
  317. X  cinfo->write_JFIF_header = TRUE;
  318. X  cinfo->jpeg_color_space = CS_YCbCr;
  319. X  cinfo->num_components = 3;
  320. X  cinfo->comp_info = (jpeg_component_info *)
  321. X    (*cinfo->emethods->alloc_small) (4 * SIZEOF(jpeg_component_info));
  322. X  /* Note: we allocate a 4-entry comp_info array so that user interface can
  323. X   * easily change over to CMYK color space if desired.
  324. X   */
  325. X
  326. X  compptr = &cinfo->comp_info[0];
  327. X  compptr->component_index = 0;
  328. X  compptr->component_id = 1;    /* JFIF specifies IDs 1,2,3 */
  329. X  compptr->h_samp_factor = 2;    /* default to 2x2 subsamples of chrominance */
  330. X  compptr->v_samp_factor = 2;
  331. X  compptr->quant_tbl_no = 0;    /* use tables 0 for luminance */
  332. X  compptr->dc_tbl_no = 0;
  333. X  compptr->ac_tbl_no = 0;
  334. X
  335. X  compptr = &cinfo->comp_info[1];
  336. X  compptr->component_index = 1;
  337. X  compptr->component_id = 2;
  338. X  compptr->h_samp_factor = 1;
  339. X  compptr->v_samp_factor = 1;
  340. X  compptr->quant_tbl_no = 1;    /* use tables 1 for chrominance */
  341. X  compptr->dc_tbl_no = 1;
  342. X  compptr->ac_tbl_no = 1;
  343. X
  344. X  compptr = &cinfo->comp_info[2];
  345. X  compptr->component_index = 2;
  346. X  compptr->component_id = 3;
  347. X  compptr->h_samp_factor = 1;
  348. X  compptr->v_samp_factor = 1;
  349. X  compptr->quant_tbl_no = 1;    /* use tables 1 for chrominance */
  350. X  compptr->dc_tbl_no = 1;
  351. X  compptr->ac_tbl_no = 1;
  352. X
  353. X  /* Set up two quantization tables using the specified quality scaling */
  354. X  j_set_quality(cinfo, quality, force_baseline);
  355. X
  356. X  /* Set up two Huffman tables in case user interface wants Huffman coding */
  357. X  std_huff_tables(cinfo);
  358. X
  359. X  /* Initialize default arithmetic coding conditioning */
  360. X  for (i = 0; i < NUM_ARITH_TBLS; i++) {
  361. X    cinfo->arith_dc_L[i] = 0;
  362. X    cinfo->arith_dc_U[i] = 1;
  363. X    cinfo->arith_ac_K[i] = 5;
  364. X  }
  365. X
  366. X  /* Use Huffman coding, not arithmetic coding, by default */
  367. X  cinfo->arith_code = FALSE;
  368. X
  369. X  /* Color images are interleaved by default */
  370. X  cinfo->interleave = TRUE;
  371. X
  372. X  /* By default, don't do extra passes to optimize entropy coding */
  373. X  cinfo->optimize_coding = FALSE;
  374. X
  375. X  /* By default, use the simpler non-cosited sampling alignment */
  376. X  cinfo->CCIR601_sampling = FALSE;
  377. X
  378. X  /* No restart markers */
  379. X  cinfo->restart_interval = 0;
  380. X
  381. X  /* Install default do-nothing progress monitoring method. */
  382. X  cinfo->methods->progress_monitor = progress_monitor;
  383. X}
  384. X
  385. X
  386. X
  387. XGLOBAL void
  388. Xj_monochrome_default (compress_info_ptr cinfo)
  389. X/* Change the j_c_defaults() values to emit a monochrome JPEG file. */
  390. X{
  391. X  jpeg_component_info * compptr;
  392. X
  393. X  cinfo->jpeg_color_space = CS_GRAYSCALE;
  394. X  cinfo->num_components = 1;
  395. X  /* Set single component to 1x1 subsampling */
  396. X  compptr = &cinfo->comp_info[0];
  397. X  compptr->h_samp_factor = 1;
  398. X  compptr->v_samp_factor = 1;
  399. X}
  400. END_OF_FILE
  401.   if test 14213 -ne `wc -c <'jcdeflts.c'`; then
  402.     echo shar: \"'jcdeflts.c'\" unpacked with wrong size!
  403.   fi
  404.   # end of 'jcdeflts.c'
  405. fi
  406. if test -f 'jdpipe.c' -a "${1}" != "-c" ; then 
  407.   echo shar: Will not clobber existing file \"'jdpipe.c'\"
  408. else
  409.   echo shar: Extracting \"'jdpipe.c'\" \(36733 characters\)
  410.   sed "s/^X//" >'jdpipe.c' <<'END_OF_FILE'
  411. X/*
  412. X * jdpipe.c
  413. X *
  414. X * Copyright (C) 1991, 1992, Thomas G. Lane.
  415. X * This file is part of the Independent JPEG Group's software.
  416. X * For conditions of distribution and use, see the accompanying README file.
  417. X *
  418. X * This file contains decompression pipeline controllers.
  419. X * These routines are invoked via the d_pipeline_controller method.
  420. X *
  421. X * There are two basic pipeline controllers.  The simpler one handles a
  422. X * single-scan JPEG file (single component or fully interleaved) with no
  423. X * color quantization or 1-pass quantization.  In this case, the file can
  424. X * be processed in one top-to-bottom pass.  The more complex controller is
  425. X * used when 2-pass color quantization is requested and/or the JPEG file
  426. X * has multiple scans (noninterleaved or partially interleaved).  In this
  427. X * case, the entire image must be buffered up in a "big" array.
  428. X *
  429. X * If you need to make a minimal implementation, the more complex controller
  430. X * can be compiled out by disabling the appropriate configuration options.
  431. X * We don't recommend this, since then you can't handle all legal JPEG files.
  432. X */
  433. X
  434. X#include "jinclude.h"
  435. X
  436. X
  437. X#ifdef MULTISCAN_FILES_SUPPORTED /* wish we could assume ANSI's defined() */
  438. X#define NEED_COMPLEX_CONTROLLER
  439. X#else
  440. X#ifdef QUANT_2PASS_SUPPORTED
  441. X#define NEED_COMPLEX_CONTROLLER
  442. X#endif
  443. X#endif
  444. X
  445. X
  446. X/*
  447. X * About the data structures:
  448. X *
  449. X * The processing chunk size for unsubsampling is referred to in this file as
  450. X * a "row group": a row group is defined as Vk (v_samp_factor) sample rows of
  451. X * any component while subsampled, or Vmax (max_v_samp_factor) unsubsampled
  452. X * rows.  In an interleaved scan each MCU row contains exactly DCTSIZE row
  453. X * groups of each component in the scan.  In a noninterleaved scan an MCU row
  454. X * is one row of blocks, which might not be an integral number of row groups;
  455. X * therefore, we read in Vk MCU rows to obtain the same amount of data as we'd
  456. X * have in an interleaved scan.
  457. X * To provide context for the unsubsampling step, we have to retain the last
  458. X * two row groups of the previous MCU row while reading in the next MCU row
  459. X * (or set of Vk MCU rows).  To do this without copying data about, we create
  460. X * a rather strange data structure.  Exactly DCTSIZE+2 row groups of samples
  461. X * are allocated, but we create two different sets of pointers to this array.
  462. X * The second set swaps the last two pairs of row groups.  By working
  463. X * alternately with the two sets of pointers, we can access the data in the
  464. X * desired order.
  465. X *
  466. X * Cross-block smoothing also needs context above and below the "current" row.
  467. X * Since this is an optional feature, I've implemented it in a way that is
  468. X * much simpler but requires more than the minimum amount of memory.  We
  469. X * simply allocate three extra MCU rows worth of coefficient blocks and use
  470. X * them to "read ahead" one MCU row in the file.  For a typical 1000-pixel-wide
  471. X * image with 2x2,1x1,1x1 sampling, each MCU row is about 50Kb; an 80x86
  472. X * machine may be unable to apply cross-block smoothing to wider images.
  473. X */
  474. X
  475. X
  476. X/*
  477. X * These variables are logically local to the pipeline controller,
  478. X * but we make them static so that scan_big_image can use them
  479. X * without having to pass them through the quantization routines.
  480. X */
  481. X
  482. Xstatic int rows_in_mem;        /* # of sample rows in full-size buffers */
  483. X/* Work buffer for data being passed to output module. */
  484. X/* This has color_out_comps components if not quantizing, */
  485. X/* but only one component when quantizing. */
  486. Xstatic JSAMPIMAGE output_workspace;
  487. X
  488. X#ifdef NEED_COMPLEX_CONTROLLER
  489. X/* Full-size image array holding desubsampled, but not color-processed data. */
  490. Xstatic big_sarray_ptr *fullsize_image;
  491. Xstatic JSAMPIMAGE fullsize_ptrs; /* workspace for access_big_sarray() result */
  492. X#endif
  493. X
  494. X
  495. X/*
  496. X * Utility routines: common code for pipeline controllers
  497. X */
  498. X
  499. XLOCAL void
  500. Xinterleaved_scan_setup (decompress_info_ptr cinfo)
  501. X/* Compute all derived info for an interleaved (multi-component) scan */
  502. X/* On entry, cinfo->comps_in_scan and cinfo->cur_comp_info[] are set up */
  503. X{
  504. X  short ci, mcublks;
  505. X  jpeg_component_info *compptr;
  506. X
  507. X  if (cinfo->comps_in_scan > MAX_COMPS_IN_SCAN)
  508. X    ERREXIT(cinfo->emethods, "Too many components for interleaved scan");
  509. X
  510. X  cinfo->MCUs_per_row = (cinfo->image_width
  511. X             + cinfo->max_h_samp_factor*DCTSIZE - 1)
  512. X            / (cinfo->max_h_samp_factor*DCTSIZE);
  513. X
  514. X  cinfo->MCU_rows_in_scan = (cinfo->image_height
  515. X                 + cinfo->max_v_samp_factor*DCTSIZE - 1)
  516. X                / (cinfo->max_v_samp_factor*DCTSIZE);
  517. X  
  518. X  cinfo->blocks_in_MCU = 0;
  519. X
  520. X  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  521. X    compptr = cinfo->cur_comp_info[ci];
  522. X    /* for interleaved scan, sampling factors give # of blocks per component */
  523. X    compptr->MCU_width = compptr->h_samp_factor;
  524. X    compptr->MCU_height = compptr->v_samp_factor;
  525. X    compptr->MCU_blocks = compptr->MCU_width * compptr->MCU_height;
  526. X    /* compute physical dimensions of component */
  527. X    compptr->subsampled_width = jround_up(compptr->true_comp_width,
  528. X                      (long) (compptr->MCU_width*DCTSIZE));
  529. X    compptr->subsampled_height = jround_up(compptr->true_comp_height,
  530. X                       (long) (compptr->MCU_height*DCTSIZE));
  531. X    /* Sanity check */
  532. X    if (compptr->subsampled_width !=
  533. X    (cinfo->MCUs_per_row * (compptr->MCU_width*DCTSIZE)))
  534. X      ERREXIT(cinfo->emethods, "I'm confused about the image width");
  535. X    /* Prepare array describing MCU composition */
  536. X    mcublks = compptr->MCU_blocks;
  537. X    if (cinfo->blocks_in_MCU + mcublks > MAX_BLOCKS_IN_MCU)
  538. X      ERREXIT(cinfo->emethods, "Sampling factors too large for interleaved scan");
  539. X    while (mcublks-- > 0) {
  540. X      cinfo->MCU_membership[cinfo->blocks_in_MCU++] = ci;
  541. X    }
  542. X  }
  543. X
  544. X  (*cinfo->methods->d_per_scan_method_selection) (cinfo);
  545. X}
  546. X
  547. X
  548. XLOCAL void
  549. Xnoninterleaved_scan_setup (decompress_info_ptr cinfo)
  550. X/* Compute all derived info for a noninterleaved (single-component) scan */
  551. X/* On entry, cinfo->comps_in_scan = 1 and cinfo->cur_comp_info[0] is set up */
  552. X{
  553. X  jpeg_component_info *compptr = cinfo->cur_comp_info[0];
  554. X
  555. X  /* for noninterleaved scan, always one block per MCU */
  556. X  compptr->MCU_width = 1;
  557. X  compptr->MCU_height = 1;
  558. X  compptr->MCU_blocks = 1;
  559. X  /* compute physical dimensions of component */
  560. X  compptr->subsampled_width = jround_up(compptr->true_comp_width,
  561. X                    (long) DCTSIZE);
  562. X  compptr->subsampled_height = jround_up(compptr->true_comp_height,
  563. X                     (long) DCTSIZE);
  564. X
  565. X  cinfo->MCUs_per_row = compptr->subsampled_width / DCTSIZE;
  566. X  cinfo->MCU_rows_in_scan = compptr->subsampled_height / DCTSIZE;
  567. X
  568. X  /* Prepare array describing MCU composition */
  569. X  cinfo->blocks_in_MCU = 1;
  570. X  cinfo->MCU_membership[0] = 0;
  571. X
  572. X  (*cinfo->methods->d_per_scan_method_selection) (cinfo);
  573. X}
  574. X
  575. X
  576. X
  577. XLOCAL JSAMPIMAGE
  578. Xalloc_sampimage (decompress_info_ptr cinfo,
  579. X         int num_comps, long num_rows, long num_cols)
  580. X/* Allocate an in-memory sample image (all components same size) */
  581. X{
  582. X  JSAMPIMAGE image;
  583. X  int ci;
  584. X
  585. X  image = (JSAMPIMAGE) (*cinfo->emethods->alloc_small)
  586. X                (num_comps * SIZEOF(JSAMPARRAY));
  587. X  for (ci = 0; ci < num_comps; ci++) {
  588. X    image[ci] = (*cinfo->emethods->alloc_small_sarray) (num_cols, num_rows);
  589. X  }
  590. X  return image;
  591. X}
  592. X
  593. X
  594. X#if 0                /* this routine not currently needed */
  595. X
  596. XLOCAL void
  597. Xfree_sampimage (decompress_info_ptr cinfo, JSAMPIMAGE image, int num_comps)
  598. X/* Release a sample image created by alloc_sampimage */
  599. X{
  600. X  int ci;
  601. X
  602. X  for (ci = 0; ci < num_comps; ci++) {
  603. X      (*cinfo->emethods->free_small_sarray) (image[ci]);
  604. X  }
  605. X  (*cinfo->emethods->free_small) ((void *) image);
  606. X}
  607. X
  608. X#endif
  609. X
  610. X
  611. XLOCAL JBLOCKIMAGE
  612. Xalloc_MCU_row (decompress_info_ptr cinfo)
  613. X/* Allocate one MCU row's worth of coefficient blocks */
  614. X{
  615. X  JBLOCKIMAGE image;
  616. X  int ci;
  617. X
  618. X  image = (JBLOCKIMAGE) (*cinfo->emethods->alloc_small)
  619. X                (cinfo->comps_in_scan * SIZEOF(JBLOCKARRAY));
  620. X  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  621. X    image[ci] = (*cinfo->emethods->alloc_small_barray)
  622. X            (cinfo->cur_comp_info[ci]->subsampled_width / DCTSIZE,
  623. X             (long) cinfo->cur_comp_info[ci]->MCU_height);
  624. X  }
  625. X  return image;
  626. X}
  627. X
  628. X
  629. X#ifdef NEED_COMPLEX_CONTROLLER    /* not used by simple controller */
  630. X
  631. XLOCAL void
  632. Xfree_MCU_row (decompress_info_ptr cinfo, JBLOCKIMAGE image)
  633. X/* Release a coefficient block array created by alloc_MCU_row */
  634. X{
  635. X  int ci;
  636. X
  637. X  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  638. X    (*cinfo->emethods->free_small_barray) (image[ci]);
  639. X  }
  640. X  (*cinfo->emethods->free_small) ((void *) image);
  641. X}
  642. X
  643. X#endif
  644. X
  645. X
  646. XLOCAL void
  647. Xalloc_sampling_buffer (decompress_info_ptr cinfo, JSAMPIMAGE subsampled_data[2])
  648. X/* Create a subsampled-data buffer having the desired structure */
  649. X/* (see comments at head of file) */
  650. X{
  651. X  short ci, vs, i;
  652. X
  653. X  /* Get top-level space for array pointers */
  654. X  subsampled_data[0] = (JSAMPIMAGE) (*cinfo->emethods->alloc_small)
  655. X                (cinfo->comps_in_scan * SIZEOF(JSAMPARRAY));
  656. X  subsampled_data[1] = (JSAMPIMAGE) (*cinfo->emethods->alloc_small)
  657. X                (cinfo->comps_in_scan * SIZEOF(JSAMPARRAY));
  658. X
  659. X  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  660. X    vs = cinfo->cur_comp_info[ci]->v_samp_factor; /* row group height */
  661. X    /* Allocate the real storage */
  662. X    subsampled_data[0][ci] = (*cinfo->emethods->alloc_small_sarray)
  663. X                (cinfo->cur_comp_info[ci]->subsampled_width,
  664. X                (long) (vs * (DCTSIZE+2)));
  665. X    /* Create space for the scrambled-order pointers */
  666. X    subsampled_data[1][ci] = (JSAMPARRAY) (*cinfo->emethods->alloc_small)
  667. X                (vs * (DCTSIZE+2) * SIZEOF(JSAMPROW));
  668. X    /* Duplicate the first DCTSIZE-2 row groups */
  669. X    for (i = 0; i < vs * (DCTSIZE-2); i++) {
  670. X      subsampled_data[1][ci][i] = subsampled_data[0][ci][i];
  671. X    }
  672. X    /* Copy the last four row groups in swapped order */
  673. X    for (i = 0; i < vs * 2; i++) {
  674. X      subsampled_data[1][ci][vs*DCTSIZE + i] = subsampled_data[0][ci][vs*(DCTSIZE-2) + i];
  675. X      subsampled_data[1][ci][vs*(DCTSIZE-2) + i] = subsampled_data[0][ci][vs*DCTSIZE + i];
  676. X    }
  677. X  }
  678. X}
  679. X
  680. X
  681. X#ifdef NEED_COMPLEX_CONTROLLER    /* not used by simple controller */
  682. X
  683. XLOCAL void
  684. Xfree_sampling_buffer (decompress_info_ptr cinfo, JSAMPIMAGE subsampled_data[2])
  685. X/* Release a sampling buffer created by alloc_sampling_buffer */
  686. X{
  687. X  short ci;
  688. X
  689. X  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  690. X    /* Free the real storage */
  691. X    (*cinfo->emethods->free_small_sarray) (subsampled_data[0][ci]);
  692. X    /* Free the scrambled-order pointers */
  693. X    (*cinfo->emethods->free_small) ((void *) subsampled_data[1][ci]);
  694. X  }
  695. X
  696. X  /* Free the top-level space */
  697. X  (*cinfo->emethods->free_small) ((void *) subsampled_data[0]);
  698. X  (*cinfo->emethods->free_small) ((void *) subsampled_data[1]);
  699. X}
  700. X
  701. X#endif
  702. X
  703. X
  704. XLOCAL void
  705. Xduplicate_row (JSAMPARRAY image_data,
  706. X           long num_cols, int source_row, int num_rows)
  707. X/* Duplicate the source_row at source_row+1 .. source_row+num_rows */
  708. X/* This happens only at the bottom of the image, */
  709. X/* so it needn't be super-efficient */
  710. X{
  711. X  register int row;
  712. X
  713. X  for (row = 1; row <= num_rows; row++) {
  714. X    jcopy_sample_rows(image_data, source_row, image_data, source_row + row,
  715. X              1, num_cols);
  716. X  }
  717. X}
  718. X
  719. X
  720. XLOCAL void
  721. Xexpand (decompress_info_ptr cinfo,
  722. X    JSAMPIMAGE subsampled_data, JSAMPIMAGE fullsize_data,
  723. X    long fullsize_width,
  724. X    short above, short current, short below, short out)
  725. X/* Do unsubsampling expansion of a single row group (of each component).  */
  726. X/* above, current, below are indexes of row groups in subsampled_data;    */
  727. X/* out is the index of the target row group in fullsize_data.             */
  728. X/* Special case: above, below can be -1 to indicate top, bottom of image. */
  729. X{
  730. X  jpeg_component_info *compptr;
  731. X  JSAMPARRAY above_ptr, below_ptr;
  732. X  JSAMPROW dummy[MAX_SAMP_FACTOR]; /* for subsample expansion at top/bottom */
  733. X  short ci, vs, i;
  734. X
  735. X  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  736. X    compptr = cinfo->cur_comp_info[ci];
  737. X    vs = compptr->v_samp_factor; /* row group height */
  738. X
  739. X    if (above >= 0)
  740. X      above_ptr = subsampled_data[ci] + above * vs;
  741. X    else {
  742. X      /* Top of image: make a dummy above-context with copies of 1st row */
  743. X      /* We assume current=0 in this case */
  744. X      for (i = 0; i < vs; i++)
  745. X    dummy[i] = subsampled_data[ci][0];
  746. X      above_ptr = (JSAMPARRAY) dummy; /* possible near->far pointer conv */
  747. X    }
  748. X
  749. X    if (below >= 0)
  750. X      below_ptr = subsampled_data[ci] + below * vs;
  751. X    else {
  752. X      /* Bot of image: make a dummy below-context with copies of last row */
  753. X      for (i = 0; i < vs; i++)
  754. X    dummy[i] = subsampled_data[ci][(current+1)*vs-1];
  755. X      below_ptr = (JSAMPARRAY) dummy; /* possible near->far pointer conv */
  756. X    }
  757. X
  758. X    (*cinfo->methods->unsubsample[ci])
  759. X        (cinfo, (int) ci,
  760. X         compptr->subsampled_width, (int) vs,
  761. X         fullsize_width, (int) cinfo->max_v_samp_factor,
  762. X         above_ptr,
  763. X         subsampled_data[ci] + current * vs,
  764. X         below_ptr,
  765. X         fullsize_data[ci] + out * cinfo->max_v_samp_factor);
  766. X  }
  767. X}
  768. X
  769. X
  770. XLOCAL void
  771. Xemit_1pass (decompress_info_ptr cinfo, int num_rows, JSAMPIMAGE fullsize_data,
  772. X        JSAMPARRAY dummy)
  773. X/* Do color processing and output of num_rows full-size rows. */
  774. X/* This is not used when doing 2-pass color quantization. */
  775. X/* The dummy argument simply lets this be called via scan_big_image. */
  776. X{
  777. X  if (cinfo->quantize_colors) {
  778. X    (*cinfo->methods->color_quantize) (cinfo, num_rows, fullsize_data,
  779. X                       output_workspace[0]);
  780. X  } else {
  781. X    (*cinfo->methods->color_convert) (cinfo, num_rows, cinfo->image_width,
  782. X                      fullsize_data, output_workspace);
  783. X  }
  784. X    
  785. X  (*cinfo->methods->put_pixel_rows) (cinfo, num_rows, output_workspace);
  786. X}
  787. X
  788. X
  789. X/*
  790. X * Support routines for complex controller.
  791. X */
  792. X
  793. X#ifdef NEED_COMPLEX_CONTROLLER
  794. X
  795. XMETHODDEF void
  796. Xscan_big_image (decompress_info_ptr cinfo, quantize_method_ptr quantize_method)
  797. X/* Apply quantize_method to entire image stored in fullsize_image[]. */
  798. X/* This is the "iterator" routine used by the 2-pass color quantizer. */
  799. X/* We also use it directly in some cases. */
  800. X{
  801. X  long pixel_rows_output;
  802. X  short ci;
  803. X
  804. X  for (pixel_rows_output = 0; pixel_rows_output < cinfo->image_height;
  805. X       pixel_rows_output += rows_in_mem) {
  806. X    (*cinfo->methods->progress_monitor) (cinfo, pixel_rows_output,
  807. X                     cinfo->image_height);
  808. X    /* Realign the big buffers */
  809. X    for (ci = 0; ci < cinfo->num_components; ci++) {
  810. X      fullsize_ptrs[ci] = (*cinfo->emethods->access_big_sarray)
  811. X    (fullsize_image[ci], pixel_rows_output, FALSE);
  812. X    }
  813. X    /* Let the quantizer have its way with the data.
  814. X     * Note that output_workspace is simply workspace for the quantizer;
  815. X     * when it's ready to output, it must call put_pixel_rows itself.
  816. X     */
  817. X    (*quantize_method) (cinfo,
  818. X            (int) MIN((long) rows_in_mem,
  819. X                  cinfo->image_height - pixel_rows_output),
  820. X            fullsize_ptrs, output_workspace[0]);
  821. X  }
  822. X
  823. X  cinfo->completed_passes++;
  824. X}
  825. X
  826. X#endif /* NEED_COMPLEX_CONTROLLER */
  827. X
  828. X
  829. X/*
  830. X * Support routines for cross-block smoothing.
  831. X */
  832. X
  833. X#ifdef BLOCK_SMOOTHING_SUPPORTED
  834. X
  835. X
  836. XLOCAL void
  837. Xsmooth_mcu_row (decompress_info_ptr cinfo,
  838. X        JBLOCKIMAGE above, JBLOCKIMAGE input, JBLOCKIMAGE below,
  839. X        JBLOCKIMAGE output)
  840. X/* Apply cross-block smoothing to one MCU row's worth of coefficient blocks. */
  841. X/* above,below are NULL if at top/bottom of image. */
  842. X{
  843. X  jpeg_component_info *compptr;
  844. X  short ci, ri, last;
  845. X  JBLOCKROW prev;
  846. X
  847. X  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  848. X    compptr = cinfo->cur_comp_info[ci];
  849. X    last = compptr->MCU_height - 1;
  850. X
  851. X    if (above == NULL)
  852. X      prev = NULL;
  853. X    else
  854. X      prev = above[ci][last];
  855. X
  856. X    for (ri = 0; ri < last; ri++) {
  857. X      (*cinfo->methods->smooth_coefficients) (cinfo, compptr,
  858. X                prev, input[ci][ri], input[ci][ri+1],
  859. X                output[ci][ri]);
  860. X      prev = input[ci][ri];
  861. X    }
  862. X
  863. X    if (below == NULL)
  864. X      (*cinfo->methods->smooth_coefficients) (cinfo, compptr,
  865. X                prev, input[ci][last], (JBLOCKROW) NULL,
  866. X                output[ci][last]);
  867. X    else
  868. X      (*cinfo->methods->smooth_coefficients) (cinfo, compptr,
  869. X                prev, input[ci][last], below[ci][0],
  870. X                output[ci][last]);
  871. X  }
  872. X}
  873. X
  874. X
  875. XLOCAL void
  876. Xget_smoothed_row (decompress_info_ptr cinfo, JBLOCKIMAGE coeff_data,
  877. X          JBLOCKIMAGE bsmooth[3], int * whichb, long cur_mcu_row)
  878. X/* Get an MCU row of coefficients, applying cross-block smoothing. */
  879. X/* The output row is placed in coeff_data.  bsmooth and whichb hold */
  880. X/* working state, and cur_row is needed to check for image top/bottom. */
  881. X/* This routine just takes care of the buffering logic. */
  882. X{
  883. X  int prev, cur, next;
  884. X  
  885. X  /* Special case for top of image: need to pre-fetch a row & init whichb */
  886. X  if (cur_mcu_row == 0) {
  887. X    (*cinfo->methods->disassemble_MCU) (cinfo, bsmooth[0]);
  888. X    if (cinfo->MCU_rows_in_scan > 1) {
  889. X      (*cinfo->methods->disassemble_MCU) (cinfo, bsmooth[1]);
  890. X      smooth_mcu_row(cinfo, (JBLOCKIMAGE) NULL, bsmooth[0], bsmooth[1],
  891. X             coeff_data);
  892. X    } else {
  893. X      smooth_mcu_row(cinfo, (JBLOCKIMAGE) NULL, bsmooth[0], (JBLOCKIMAGE) NULL,
  894. X             coeff_data);
  895. X    }
  896. X    *whichb = 1;        /* points to next bsmooth[] element to use */
  897. X    return;
  898. X  }
  899. X  
  900. X  cur = *whichb;        /* set up references */
  901. X  prev = (cur == 0 ? 2 : cur - 1);
  902. X  next = (cur == 2 ? 0 : cur + 1);
  903. X  *whichb = next;        /* advance whichb for next time */
  904. X  
  905. X  /* Special case for bottom of image: don't read another row */
  906. X  if (cur_mcu_row >= cinfo->MCU_rows_in_scan - 1) {
  907. X    smooth_mcu_row(cinfo, bsmooth[prev], bsmooth[cur], (JBLOCKIMAGE) NULL,
  908. X           coeff_data);
  909. X    return;
  910. X  }
  911. X  
  912. X  /* Normal case: read ahead a new row, smooth the one I got before */
  913. X  (*cinfo->methods->disassemble_MCU) (cinfo, bsmooth[next]);
  914. X  smooth_mcu_row(cinfo, bsmooth[prev], bsmooth[cur], bsmooth[next],
  915. X         coeff_data);
  916. X}
  917. X
  918. X
  919. X#endif /* BLOCK_SMOOTHING_SUPPORTED */
  920. X
  921. X
  922. X
  923. X/*
  924. X * Decompression pipeline controller used for single-scan files
  925. X * without 2-pass color quantization.
  926. X */
  927. X
  928. XMETHODDEF void
  929. Xsimple_dcontroller (decompress_info_ptr cinfo)
  930. X{
  931. X  long fullsize_width;        /* # of samples per row in full-size buffers */
  932. X  long cur_mcu_row;        /* counts # of MCU rows processed */
  933. X  long pixel_rows_output;    /* # of pixel rows actually emitted */
  934. X  int mcu_rows_per_loop;    /* # of MCU rows processed per outer loop */
  935. X  /* Work buffer for dequantized coefficients (IDCT input) */
  936. X  JBLOCKIMAGE coeff_data;
  937. X  /* Work buffer for cross-block smoothing input */
  938. X#ifdef BLOCK_SMOOTHING_SUPPORTED
  939. X  JBLOCKIMAGE bsmooth[3];    /* this is optional */
  940. X  int whichb;
  941. X#endif
  942. X  /* Work buffer for subsampled image data (see comments at head of file) */
  943. X  JSAMPIMAGE subsampled_data[2];
  944. X  /* Work buffer for desubsampled data */
  945. X  JSAMPIMAGE fullsize_data;
  946. X  int whichss, ri;
  947. X  short i;
  948. X
  949. X  /* Compute dimensions of full-size pixel buffers */
  950. X  /* Note these are the same whether interleaved or not. */
  951. X  rows_in_mem = cinfo->max_v_samp_factor * DCTSIZE;
  952. X  fullsize_width = jround_up(cinfo->image_width,
  953. X                 (long) (cinfo->max_h_samp_factor * DCTSIZE));
  954. X
  955. X  /* Prepare for single scan containing all components */
  956. X  if (cinfo->comps_in_scan == 1) {
  957. X    noninterleaved_scan_setup(cinfo);
  958. X    /* Need to read Vk MCU rows to obtain Vk block rows */
  959. X    mcu_rows_per_loop = cinfo->cur_comp_info[0]->v_samp_factor;
  960. X  } else {
  961. X    interleaved_scan_setup(cinfo);
  962. X    /* in an interleaved scan, one MCU row provides Vk block rows */
  963. X    mcu_rows_per_loop = 1;
  964. X  }
  965. X  cinfo->total_passes++;
  966. X
  967. X  /* Allocate working memory: */
  968. X  /* coeff_data holds a single MCU row of coefficient blocks */
  969. X  coeff_data = alloc_MCU_row(cinfo);
  970. X  /* if doing cross-block smoothing, need extra space for its input */
  971. X#ifdef BLOCK_SMOOTHING_SUPPORTED
  972. X  if (cinfo->do_block_smoothing) {
  973. X    bsmooth[0] = alloc_MCU_row(cinfo);
  974. X    bsmooth[1] = alloc_MCU_row(cinfo);
  975. X    bsmooth[2] = alloc_MCU_row(cinfo);
  976. X  }
  977. X#endif
  978. X  /* subsampled_data is sample data before unsubsampling */
  979. X  alloc_sampling_buffer(cinfo, subsampled_data);
  980. X  /* fullsize_data is sample data after unsubsampling */
  981. X  fullsize_data = alloc_sampimage(cinfo, (int) cinfo->num_components,
  982. X                  (long) rows_in_mem, fullsize_width);
  983. X  /* output_workspace is the color-processed data */
  984. X  output_workspace = alloc_sampimage(cinfo, (int) cinfo->final_out_comps,
  985. X                     (long) rows_in_mem, fullsize_width);
  986. X
  987. X  /* Tell the memory manager to instantiate big arrays.
  988. X   * We don't need any big arrays in this controller,
  989. X   * but some other module (like the output file writer) may need one.
  990. X   */
  991. X  (*cinfo->emethods->alloc_big_arrays)
  992. X    ((long) 0,                /* no more small sarrays */
  993. X     (long) 0,                /* no more small barrays */
  994. X     (long) 0);                /* no more "medium" objects */
  995. X  /* NB: if quantizer needs any "medium" size objects, it must get them */
  996. X  /* at color_quant_init time */
  997. X
  998. X  /* Initialize to read scan data */
  999. X
  1000. X  (*cinfo->methods->entropy_decoder_init) (cinfo);
  1001. X  (*cinfo->methods->unsubsample_init) (cinfo);
  1002. X  (*cinfo->methods->disassemble_init) (cinfo);
  1003. X
  1004. X  /* Loop over scan's data: rows_in_mem pixel rows are processed per loop */
  1005. X
  1006. X  pixel_rows_output = 0;
  1007. X  whichss = 1;            /* arrange to start with subsampled_data[0] */
  1008. X
  1009. X  for (cur_mcu_row = 0; cur_mcu_row < cinfo->MCU_rows_in_scan;
  1010. X       cur_mcu_row += mcu_rows_per_loop) {
  1011. X    (*cinfo->methods->progress_monitor) (cinfo, cur_mcu_row,
  1012. X                     cinfo->MCU_rows_in_scan);
  1013. X
  1014. X    whichss ^= 1;        /* switch to other subsample buffer */
  1015. X
  1016. X    /* Obtain v_samp_factor block rows of each component in the scan. */
  1017. X    /* This is a single MCU row if interleaved, multiple MCU rows if not. */
  1018. X    /* In the noninterleaved case there might be fewer than v_samp_factor */
  1019. X    /* block rows remaining; if so, pad with copies of the last pixel row */
  1020. X    /* so that unsubsampling doesn't have to treat it as a special case. */
  1021. X
  1022. X    for (ri = 0; ri < mcu_rows_per_loop; ri++) {
  1023. X      if (cur_mcu_row + ri < cinfo->MCU_rows_in_scan) {
  1024. X    /* OK to actually read an MCU row. */
  1025. X#ifdef BLOCK_SMOOTHING_SUPPORTED
  1026. X    if (cinfo->do_block_smoothing)
  1027. X      get_smoothed_row(cinfo, coeff_data,
  1028. X               bsmooth, &whichb, cur_mcu_row + ri);
  1029. X    else
  1030. X#endif
  1031. X      (*cinfo->methods->disassemble_MCU) (cinfo, coeff_data);
  1032. X      
  1033. X    (*cinfo->methods->reverse_DCT) (cinfo, coeff_data,
  1034. X                    subsampled_data[whichss],
  1035. X                    ri * DCTSIZE);
  1036. X      } else {
  1037. X    /* Need to pad out with copies of the last subsampled row. */
  1038. X    /* This can only happen if there is just one component. */
  1039. X    duplicate_row(subsampled_data[whichss][0],
  1040. X              cinfo->cur_comp_info[0]->subsampled_width,
  1041. X              ri * DCTSIZE - 1, DCTSIZE);
  1042. X      }
  1043. X    }
  1044. X
  1045. X    /* Unsubsample the data */
  1046. X    /* First time through is a special case */
  1047. X
  1048. X    if (cur_mcu_row) {
  1049. X      /* Expand last row group of previous set */
  1050. X      expand(cinfo, subsampled_data[whichss], fullsize_data, fullsize_width,
  1051. X         (short) DCTSIZE, (short) (DCTSIZE+1), (short) 0,
  1052. X         (short) (DCTSIZE-1));
  1053. X      /* and dump the previous set's expanded data */
  1054. X      emit_1pass (cinfo, rows_in_mem, fullsize_data, NULL);
  1055. X      pixel_rows_output += rows_in_mem;
  1056. X      /* Expand first row group of this set */
  1057. X      expand(cinfo, subsampled_data[whichss], fullsize_data, fullsize_width,
  1058. X         (short) (DCTSIZE+1), (short) 0, (short) 1,
  1059. X         (short) 0);
  1060. X    } else {
  1061. X      /* Expand first row group with dummy above-context */
  1062. X      expand(cinfo, subsampled_data[whichss], fullsize_data, fullsize_width,
  1063. X         (short) (-1), (short) 0, (short) 1,
  1064. X         (short) 0);
  1065. X    }
  1066. X    /* Expand second through next-to-last row groups of this set */
  1067. X    for (i = 1; i <= DCTSIZE-2; i++) {
  1068. X      expand(cinfo, subsampled_data[whichss], fullsize_data, fullsize_width,
  1069. X         (short) (i-1), (short) i, (short) (i+1),
  1070. X         (short) i);
  1071. X    }
  1072. X  } /* end of outer loop */
  1073. X
  1074. X  /* Expand the last row group with dummy below-context */
  1075. X  /* Note whichss points to last buffer side used */
  1076. X  expand(cinfo, subsampled_data[whichss], fullsize_data, fullsize_width,
  1077. X     (short) (DCTSIZE-2), (short) (DCTSIZE-1), (short) (-1),
  1078. X     (short) (DCTSIZE-1));
  1079. X  /* and dump the remaining data (may be less than full height) */
  1080. X  emit_1pass (cinfo, (int) (cinfo->image_height - pixel_rows_output),
  1081. X          fullsize_data, NULL);
  1082. X
  1083. X  /* Clean up after the scan */
  1084. X  (*cinfo->methods->disassemble_term) (cinfo);
  1085. X  (*cinfo->methods->unsubsample_term) (cinfo);
  1086. X  (*cinfo->methods->entropy_decoder_term) (cinfo);
  1087. X  (*cinfo->methods->read_scan_trailer) (cinfo);
  1088. X  cinfo->completed_passes++;
  1089. X
  1090. X  /* Verify that we've seen the whole input file */
  1091. X  if ((*cinfo->methods->read_scan_header) (cinfo))
  1092. X    ERREXIT(cinfo->emethods, "Didn't expect more than one scan");
  1093. X
  1094. X  /* Release working memory */
  1095. X  /* (no work -- we let free_all release what's needful) */
  1096. X}
  1097. X
  1098. X
  1099. X/*
  1100. X * Decompression pipeline controller used for multiple-scan files
  1101. X * and/or 2-pass color quantization.
  1102. X *
  1103. X * The current implementation places the "big" buffer at the stage of
  1104. X * desubsampled, non-color-processed data.  This is the only place that
  1105. X * makes sense when doing 2-pass quantization.  For processing multiple-scan
  1106. X * files without 2-pass quantization, it would be possible to develop another
  1107. X * controller that buffers the subsampled data instead, thus reducing the size
  1108. X * of the temp files (by about a factor of 2 in typical cases).  However,
  1109. X * our present unsubsampling logic is dependent on the assumption that
  1110. X * unsubsampling occurs during a scan, so it's much easier to do the
  1111. X * enlargement as the JPEG file is read.  This also simplifies life for the
  1112. X * memory manager, which would otherwise have to deal with overlapping
  1113. X * access_big_sarray() requests.
  1114. X * At present it appears that most JPEG files will be single-scan,
  1115. X * so it doesn't seem worthwhile to worry about this optimization.
  1116. X */
  1117. X
  1118. X#ifdef NEED_COMPLEX_CONTROLLER
  1119. X
  1120. XMETHODDEF void
  1121. Xcomplex_dcontroller (decompress_info_ptr cinfo)
  1122. X{
  1123. X  long fullsize_width;        /* # of samples per row in full-size buffers */
  1124. X  long cur_mcu_row;        /* counts # of MCU rows processed */
  1125. X  long pixel_rows_output;    /* # of pixel rows actually emitted */
  1126. X  int mcu_rows_per_loop;    /* # of MCU rows processed per outer loop */
  1127. X  /* Work buffer for dequantized coefficients (IDCT input) */
  1128. X  JBLOCKIMAGE coeff_data;
  1129. X  /* Work buffer for cross-block smoothing input */
  1130. X#ifdef BLOCK_SMOOTHING_SUPPORTED
  1131. X  JBLOCKIMAGE bsmooth[3];    /* this is optional */
  1132. X  int whichb;
  1133. X#endif
  1134. X  /* Work buffer for subsampled image data (see comments at head of file) */
  1135. X  JSAMPIMAGE subsampled_data[2];
  1136. X  int whichss, ri;
  1137. X  short ci, i;
  1138. X  boolean single_scan;
  1139. X
  1140. X  /* Compute dimensions of full-size pixel buffers */
  1141. X  /* Note these are the same whether interleaved or not. */
  1142. X  rows_in_mem = cinfo->max_v_samp_factor * DCTSIZE;
  1143. X  fullsize_width = jround_up(cinfo->image_width,
  1144. X                 (long) (cinfo->max_h_samp_factor * DCTSIZE));
  1145. X
  1146. X  /* Allocate all working memory that doesn't depend on scan info */
  1147. X  /* output_workspace is the color-processed data */
  1148. X  output_workspace = alloc_sampimage(cinfo, (int) cinfo->final_out_comps,
  1149. X                     (long) rows_in_mem, fullsize_width);
  1150. X
  1151. X  /* Get a big image: fullsize_image is sample data after unsubsampling. */
  1152. X  fullsize_image = (big_sarray_ptr *) (*cinfo->emethods->alloc_small)
  1153. X            (cinfo->num_components * SIZEOF(big_sarray_ptr));
  1154. X  for (ci = 0; ci < cinfo->num_components; ci++) {
  1155. X    fullsize_image[ci] = (*cinfo->emethods->request_big_sarray)
  1156. X            (fullsize_width,
  1157. X             jround_up(cinfo->image_height, (long) rows_in_mem),
  1158. X             (long) rows_in_mem);
  1159. X  }
  1160. X  /* Also get an area for pointers to currently accessible chunks */
  1161. X  fullsize_ptrs = (JSAMPIMAGE) (*cinfo->emethods->alloc_small)
  1162. X                (cinfo->num_components * SIZEOF(JSAMPARRAY));
  1163. X
  1164. X  /* Tell the memory manager to instantiate big arrays */
  1165. X  (*cinfo->emethods->alloc_big_arrays)
  1166. X     /* extra sarray space is for subsampled-data buffers: */
  1167. X    ((long) (fullsize_width            /* max width in samples */
  1168. X     * cinfo->max_v_samp_factor*(DCTSIZE+2)    /* max height */
  1169. X     * cinfo->num_components),        /* max components per scan */
  1170. X     /* extra barray space is for MCU-row buffers: */
  1171. X     (long) ((fullsize_width / DCTSIZE)    /* max width in blocks */
  1172. X     * cinfo->max_v_samp_factor        /* max height */
  1173. X     * cinfo->num_components        /* max components per scan */
  1174. X     * (cinfo->do_block_smoothing ? 4 : 1)),/* how many of these we need */
  1175. X     /* no extra "medium"-object space */
  1176. X     (long) 0);
  1177. X  /* NB: if quantizer needs any "medium" size objects, it must get them */
  1178. X  /* at color_quant_init time */
  1179. X
  1180. X  /* If file is single-scan, we can do color quantization prescan on-the-fly
  1181. X   * during the scan (we must be doing 2-pass quantization, else this method
  1182. X   * would not have been selected).  If it is multiple scans, we have to make
  1183. X   * a separate pass after we've collected all the components.  (We could save
  1184. X   * some I/O by doing CQ prescan during the last scan, but the extra logic
  1185. X   * doesn't seem worth the trouble.)
  1186. X   */
  1187. X
  1188. X  single_scan = (cinfo->comps_in_scan == cinfo->num_components);
  1189. X
  1190. X  /* Account for passes needed (color quantizer adds its passes separately).
  1191. X   * If multiscan file, we guess that each component has its own scan,
  1192. X   * and increment completed_passes by the number of components in the scan.
  1193. X   */
  1194. X
  1195. X  if (single_scan)
  1196. X    cinfo->total_passes++;    /* the single scan */
  1197. X  else {
  1198. X    cinfo->total_passes += cinfo->num_components; /* guessed # of scans */
  1199. X    if (cinfo->two_pass_quantize)
  1200. X      cinfo->total_passes++;    /* account for separate CQ prescan pass */
  1201. X  }
  1202. X  if (! cinfo->two_pass_quantize)
  1203. X    cinfo->total_passes++;    /* count output pass unless quantizer does it */
  1204. X
  1205. X  /* Loop over scans in file */
  1206. X
  1207. X  do {
  1208. X    
  1209. X    /* Prepare for this scan */
  1210. X    if (cinfo->comps_in_scan == 1) {
  1211. X      noninterleaved_scan_setup(cinfo);
  1212. X      /* Need to read Vk MCU rows to obtain Vk block rows */
  1213. X      mcu_rows_per_loop = cinfo->cur_comp_info[0]->v_samp_factor;
  1214. X    } else {
  1215. X      interleaved_scan_setup(cinfo);
  1216. X      /* in an interleaved scan, one MCU row provides Vk block rows */
  1217. X      mcu_rows_per_loop = 1;
  1218. X    }
  1219. X    
  1220. X    /* Allocate scan-local working memory */
  1221. X    /* coeff_data holds a single MCU row of coefficient blocks */
  1222. X    coeff_data = alloc_MCU_row(cinfo);
  1223. X    /* if doing cross-block smoothing, need extra space for its input */
  1224. X#ifdef BLOCK_SMOOTHING_SUPPORTED
  1225. X    if (cinfo->do_block_smoothing) {
  1226. X      bsmooth[0] = alloc_MCU_row(cinfo);
  1227. X      bsmooth[1] = alloc_MCU_row(cinfo);
  1228. X      bsmooth[2] = alloc_MCU_row(cinfo);
  1229. X    }
  1230. X#endif
  1231. X    /* subsampled_data is sample data before unsubsampling */
  1232. X    alloc_sampling_buffer(cinfo, subsampled_data);
  1233. X
  1234. X    /* line up the big buffers for components in this scan */
  1235. X    for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  1236. X      fullsize_ptrs[ci] = (*cinfo->emethods->access_big_sarray)
  1237. X    (fullsize_image[cinfo->cur_comp_info[ci]->component_index],
  1238. X     (long) 0, TRUE);
  1239. X    }
  1240. X    
  1241. X    /* Initialize to read scan data */
  1242. X    
  1243. X    (*cinfo->methods->entropy_decoder_init) (cinfo);
  1244. X    (*cinfo->methods->unsubsample_init) (cinfo);
  1245. X    (*cinfo->methods->disassemble_init) (cinfo);
  1246. X    
  1247. X    /* Loop over scan's data: rows_in_mem pixel rows are processed per loop */
  1248. X    
  1249. X    pixel_rows_output = 0;
  1250. X    whichss = 1;        /* arrange to start with subsampled_data[0] */
  1251. X    
  1252. X    for (cur_mcu_row = 0; cur_mcu_row < cinfo->MCU_rows_in_scan;
  1253. X     cur_mcu_row += mcu_rows_per_loop) {
  1254. X      (*cinfo->methods->progress_monitor) (cinfo, cur_mcu_row,
  1255. X                       cinfo->MCU_rows_in_scan);
  1256. X
  1257. X      whichss ^= 1;        /* switch to other subsample buffer */
  1258. X
  1259. X      /* Obtain v_samp_factor block rows of each component in the scan. */
  1260. X      /* This is a single MCU row if interleaved, multiple MCU rows if not. */
  1261. X      /* In the noninterleaved case there might be fewer than v_samp_factor */
  1262. X      /* block rows remaining; if so, pad with copies of the last pixel row */
  1263. X      /* so that unsubsampling doesn't have to treat it as a special case. */
  1264. X      
  1265. X      for (ri = 0; ri < mcu_rows_per_loop; ri++) {
  1266. X    if (cur_mcu_row + ri < cinfo->MCU_rows_in_scan) {
  1267. X      /* OK to actually read an MCU row. */
  1268. X#ifdef BLOCK_SMOOTHING_SUPPORTED
  1269. X      if (cinfo->do_block_smoothing)
  1270. X        get_smoothed_row(cinfo, coeff_data,
  1271. X                 bsmooth, &whichb, cur_mcu_row + ri);
  1272. X      else
  1273. X#endif
  1274. X        (*cinfo->methods->disassemble_MCU) (cinfo, coeff_data);
  1275. X      
  1276. X      (*cinfo->methods->reverse_DCT) (cinfo, coeff_data,
  1277. X                      subsampled_data[whichss],
  1278. X                      ri * DCTSIZE);
  1279. X    } else {
  1280. X      /* Need to pad out with copies of the last subsampled row. */
  1281. X      /* This can only happen if there is just one component. */
  1282. X      duplicate_row(subsampled_data[whichss][0],
  1283. X            cinfo->cur_comp_info[0]->subsampled_width,
  1284. X            ri * DCTSIZE - 1, DCTSIZE);
  1285. X    }
  1286. X      }
  1287. X      
  1288. X      /* Unsubsample the data */
  1289. X      /* First time through is a special case */
  1290. X      
  1291. X      if (cur_mcu_row) {
  1292. X    /* Expand last row group of previous set */
  1293. X    expand(cinfo, subsampled_data[whichss], fullsize_ptrs, fullsize_width,
  1294. X           (short) DCTSIZE, (short) (DCTSIZE+1), (short) 0,
  1295. X           (short) (DCTSIZE-1));
  1296. X    /* If single scan, can do color quantization prescan on-the-fly */
  1297. X    if (single_scan)
  1298. X      (*cinfo->methods->color_quant_prescan) (cinfo, rows_in_mem,
  1299. X                          fullsize_ptrs,
  1300. X                          output_workspace[0]);
  1301. X    /* Realign the big buffers */
  1302. X    pixel_rows_output += rows_in_mem;
  1303. X    for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  1304. X      fullsize_ptrs[ci] = (*cinfo->emethods->access_big_sarray)
  1305. X        (fullsize_image[cinfo->cur_comp_info[ci]->component_index],
  1306. X         pixel_rows_output, TRUE);
  1307. X    }
  1308. X    /* Expand first row group of this set */
  1309. X    expand(cinfo, subsampled_data[whichss], fullsize_ptrs, fullsize_width,
  1310. X           (short) (DCTSIZE+1), (short) 0, (short) 1,
  1311. X           (short) 0);
  1312. X      } else {
  1313. X    /* Expand first row group with dummy above-context */
  1314. X    expand(cinfo, subsampled_data[whichss], fullsize_ptrs, fullsize_width,
  1315. X           (short) (-1), (short) 0, (short) 1,
  1316. X           (short) 0);
  1317. X      }
  1318. X      /* Expand second through next-to-last row groups of this set */
  1319. X      for (i = 1; i <= DCTSIZE-2; i++) {
  1320. X    expand(cinfo, subsampled_data[whichss], fullsize_ptrs, fullsize_width,
  1321. X           (short) (i-1), (short) i, (short) (i+1),
  1322. X           (short) i);
  1323. X      }
  1324. X    } /* end of loop over scan's data */
  1325. X    
  1326. X    /* Expand the last row group with dummy below-context */
  1327. X    /* Note whichss points to last buffer side used */
  1328. X    expand(cinfo, subsampled_data[whichss], fullsize_ptrs, fullsize_width,
  1329. X       (short) (DCTSIZE-2), (short) (DCTSIZE-1), (short) (-1),
  1330. X       (short) (DCTSIZE-1));
  1331. X    /* If single scan, finish on-the-fly color quantization prescan */
  1332. X    if (single_scan)
  1333. X      (*cinfo->methods->color_quant_prescan) (cinfo,
  1334. X            (int) (cinfo->image_height - pixel_rows_output),
  1335. X            fullsize_ptrs, output_workspace[0]);
  1336. X    
  1337. X    /* Clean up after the scan */
  1338. X    (*cinfo->methods->disassemble_term) (cinfo);
  1339. X    (*cinfo->methods->unsubsample_term) (cinfo);
  1340. X    (*cinfo->methods->entropy_decoder_term) (cinfo);
  1341. X    (*cinfo->methods->read_scan_trailer) (cinfo);
  1342. X    if (single_scan)
  1343. X      cinfo->completed_passes++;
  1344. X    else
  1345. X      cinfo->completed_passes += cinfo->comps_in_scan;
  1346. X
  1347. X    /* Release scan-local working memory */
  1348. X    free_MCU_row(cinfo, coeff_data);
  1349. X#ifdef BLOCK_SMOOTHING_SUPPORTED
  1350. X    if (cinfo->do_block_smoothing) {
  1351. X      free_MCU_row(cinfo, bsmooth[0]);
  1352. X      free_MCU_row(cinfo, bsmooth[1]);
  1353. X      free_MCU_row(cinfo, bsmooth[2]);
  1354. X    }
  1355. X#endif
  1356. X    free_sampling_buffer(cinfo, subsampled_data);
  1357. X    
  1358. X    /* Repeat if there is another scan */
  1359. X  } while ((!single_scan) && (*cinfo->methods->read_scan_header) (cinfo));
  1360. X
  1361. X  if (single_scan) {
  1362. X    /* If we expected just one scan, make SURE there's just one */
  1363. X    if ((*cinfo->methods->read_scan_header) (cinfo))
  1364. X      ERREXIT(cinfo->emethods, "Didn't expect more than one scan");
  1365. X    /* We did the CQ prescan on-the-fly, so we are all set. */
  1366. X  } else {
  1367. X    /* For multiple-scan file, do the CQ prescan as a separate pass. */
  1368. X    /* The main reason why prescan is passed the output_workspace is */
  1369. X    /* so that we can use scan_big_image to call it... */
  1370. X    if (cinfo->two_pass_quantize)
  1371. X      scan_big_image(cinfo, cinfo->methods->color_quant_prescan);
  1372. X  }
  1373. X
  1374. X  /* Now that we've collected the data, do color processing and output */
  1375. X  if (cinfo->two_pass_quantize)
  1376. X    (*cinfo->methods->color_quant_doit) (cinfo, scan_big_image);
  1377. X  else
  1378. X    scan_big_image(cinfo, emit_1pass);
  1379. X
  1380. X  /* Release working memory */
  1381. X  /* (no work -- we let free_all release what's needful) */
  1382. X}
  1383. X
  1384. X#endif /* NEED_COMPLEX_CONTROLLER */
  1385. X
  1386. X
  1387. X/*
  1388. X * The method selection routine for decompression pipeline controllers.
  1389. X * Note that at this point we've already read the JPEG header and first SOS,
  1390. X * so we can tell whether the input is one scan or not.
  1391. X */
  1392. X
  1393. XGLOBAL void
  1394. Xjseldpipeline (decompress_info_ptr cinfo)
  1395. X{
  1396. X  /* simplify subsequent tests on color quantization */
  1397. X  if (! cinfo->quantize_colors)
  1398. X    cinfo->two_pass_quantize = FALSE;
  1399. X  
  1400. X  if (cinfo->comps_in_scan == cinfo->num_components) {
  1401. X    /* It's a single-scan file */
  1402. X    if (cinfo->two_pass_quantize) {
  1403. X#ifdef NEED_COMPLEX_CONTROLLER
  1404. X      cinfo->methods->d_pipeline_controller = complex_dcontroller;
  1405. X#else
  1406. X      ERREXIT(cinfo->emethods, "2-pass quantization support was not compiled");
  1407. X#endif
  1408. X    } else
  1409. X      cinfo->methods->d_pipeline_controller = simple_dcontroller;
  1410. X  } else {
  1411. X    /* It's a multiple-scan file */
  1412. X#ifdef NEED_COMPLEX_CONTROLLER
  1413. X    cinfo->methods->d_pipeline_controller = complex_dcontroller;
  1414. X#else
  1415. X    ERREXIT(cinfo->emethods, "Multiple-scan support was not compiled");
  1416. X#endif
  1417. X  }
  1418. X}
  1419. END_OF_FILE
  1420.   if test 36733 -ne `wc -c <'jdpipe.c'`; then
  1421.     echo shar: \"'jdpipe.c'\" unpacked with wrong size!
  1422.   fi
  1423.   # end of 'jdpipe.c'
  1424. fi
  1425. echo shar: End of archive 3 \(of 18\).
  1426. cp /dev/null ark3isdone
  1427. MISSING=""
  1428. for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 ; do
  1429.     if test ! -f ark${I}isdone ; then
  1430.     MISSING="${MISSING} ${I}"
  1431.     fi
  1432. done
  1433. if test "${MISSING}" = "" ; then
  1434.     echo You have unpacked all 18 archives.
  1435.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  1436. else
  1437.     echo You still must unpack the following archives:
  1438.     echo "        " ${MISSING}
  1439. fi
  1440. exit 0
  1441. exit 0 # Just in case...
  1442.