jcparam.c 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991
  1. /*
  2. * jcparam.c
  3. *
  4. * This file was part of the Independent JPEG Group's software:
  5. * Copyright (C) 1991-1998, Thomas G. Lane.
  6. * Modified 2003-2008 by Guido Vollbeding.
  7. * libjpeg-turbo Modifications:
  8. * Copyright (C) 2009-2011, 2018, D. R. Commander.
  9. * mozjpeg Modifications:
  10. * Copyright (C) 2014, Mozilla Corporation.
  11. * For conditions of distribution and use, see the accompanying README file.
  12. *
  13. * This file contains optional default-setting code for the JPEG compressor.
  14. * Applications do not have to use this file, but those that don't use it
  15. * must know a lot more about the innards of the JPEG code.
  16. */
  17. #define JPEG_INTERNALS
  18. #include "jinclude.h"
  19. #include "jpeglib.h"
  20. #include "jstdhuff.c"
  21. /*
  22. * Quantization table setup routines
  23. */
  24. GLOBAL(void)
  25. jpeg_add_quant_table (j_compress_ptr cinfo, int which_tbl,
  26. const unsigned int *basic_table, int scale_factor,
  27. boolean force_baseline)
  28. /* Define a quantization table equal to the basic_table times
  29. * a scale factor (given as a percentage).
  30. * If force_baseline is TRUE, the computed quantization table entries
  31. * are limited to 1..255 for JPEG baseline compatibility.
  32. */
  33. {
  34. JQUANT_TBL **qtblptr;
  35. int i;
  36. long temp;
  37. /* Safety check to ensure start_compress not called yet. */
  38. if (cinfo->global_state != CSTATE_START)
  39. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  40. if (which_tbl < 0 || which_tbl >= NUM_QUANT_TBLS)
  41. ERREXIT1(cinfo, JERR_DQT_INDEX, which_tbl);
  42. qtblptr = & cinfo->quant_tbl_ptrs[which_tbl];
  43. if (*qtblptr == NULL)
  44. *qtblptr = jpeg_alloc_quant_table((j_common_ptr) cinfo);
  45. for (i = 0; i < DCTSIZE2; i++) {
  46. temp = ((long) basic_table[i] * scale_factor + 50L) / 100L;
  47. /* limit the values to the valid range */
  48. if (temp <= 0L) temp = 1L;
  49. if (temp > 32767L) temp = 32767L; /* max quantizer needed for 12 bits */
  50. if (force_baseline && temp > 255L)
  51. temp = 255L; /* limit to baseline range if requested */
  52. (*qtblptr)->quantval[i] = (UINT16) temp;
  53. }
  54. /* Initialize sent_table FALSE so table will be written to JPEG file. */
  55. (*qtblptr)->sent_table = FALSE;
  56. }
  57. /* These are the sample quantization tables given in Annex K (Clause K.1) of
  58. * Recommendation ITU-T T.81 (1992) | ISO/IEC 10918-1:1994.
  59. * The spec says that the values given produce "good" quality, and
  60. * when divided by 2, "very good" quality.
  61. */
  62. static const unsigned int std_luminance_quant_tbl[9][DCTSIZE2] = {
  63. {
  64. /* JPEG Annex K
  65. */
  66. 16, 11, 10, 16, 24, 40, 51, 61,
  67. 12, 12, 14, 19, 26, 58, 60, 55,
  68. 14, 13, 16, 24, 40, 57, 69, 56,
  69. 14, 17, 22, 29, 51, 87, 80, 62,
  70. 18, 22, 37, 56, 68, 109, 103, 77,
  71. 24, 35, 55, 64, 81, 104, 113, 92,
  72. 49, 64, 78, 87, 103, 121, 120, 101,
  73. 72, 92, 95, 98, 112, 100, 103, 99
  74. },
  75. {
  76. /* flat
  77. */
  78. 16, 16, 16, 16, 16, 16, 16, 16,
  79. 16, 16, 16, 16, 16, 16, 16, 16,
  80. 16, 16, 16, 16, 16, 16, 16, 16,
  81. 16, 16, 16, 16, 16, 16, 16, 16,
  82. 16, 16, 16, 16, 16, 16, 16, 16,
  83. 16, 16, 16, 16, 16, 16, 16, 16,
  84. 16, 16, 16, 16, 16, 16, 16, 16,
  85. 16, 16, 16, 16, 16, 16, 16, 16
  86. },
  87. {
  88. 12, 17, 20, 21, 30, 34, 56, 63,
  89. 18, 20, 20, 26, 28, 51, 61, 55,
  90. 19, 20, 21, 26, 33, 58, 69, 55,
  91. 26, 26, 26, 30, 46, 87, 86, 66,
  92. 31, 33, 36, 40, 46, 96, 100, 73,
  93. 40, 35, 46, 62, 81, 100, 111, 91,
  94. 46, 66, 76, 86, 102, 121, 120, 101,
  95. 68, 90, 90, 96, 113, 102, 105, 103
  96. },
  97. {
  98. /* From http://www.imagemagick.org/discourse-server/viewtopic.php?f=22&t=20333&p=98008#p98008
  99. */
  100. 16, 16, 16, 18, 25, 37, 56, 85,
  101. 16, 17, 20, 27, 34, 40, 53, 75,
  102. 16, 20, 24, 31, 43, 62, 91, 135,
  103. 18, 27, 31, 40, 53, 74, 106, 156,
  104. 25, 34, 43, 53, 69, 94, 131, 189,
  105. 37, 40, 62, 74, 94, 124, 169, 238,
  106. 56, 53, 91, 106, 131, 169, 226, 311,
  107. 85, 75, 135, 156, 189, 238, 311, 418
  108. },
  109. {
  110. 9, 10, 12, 14, 27, 32, 51, 62,
  111. 11, 12, 14, 19, 27, 44, 59, 73,
  112. 12, 14, 18, 25, 42, 59, 79, 78,
  113. 17, 18, 25, 42, 61, 92, 87, 92,
  114. 23, 28, 42, 75, 79, 112, 112, 99,
  115. 40, 42, 59, 84, 88, 124, 132, 111,
  116. 42, 64, 78, 95, 105, 126, 125, 99,
  117. 70, 75, 100, 102, 116, 100, 107, 98
  118. },
  119. {
  120. /* Relevance of human vision to JPEG-DCT compression (1992) Klein, Silverstein and Carney.
  121. */
  122. 10, 12, 14, 19, 26, 38, 57, 86,
  123. 12, 18, 21, 28, 35, 41, 54, 76,
  124. 14, 21, 25, 32, 44, 63, 92, 136,
  125. 19, 28, 32, 41, 54, 75, 107, 157,
  126. 26, 35, 44, 54, 70, 95, 132, 190,
  127. 38, 41, 63, 75, 95, 125, 170, 239,
  128. 57, 54, 92, 107, 132, 170, 227, 312,
  129. 86, 76, 136, 157, 190, 239, 312, 419
  130. },
  131. {
  132. /* DCTune perceptual optimization of compressed dental X-Rays (1997) Watson, Taylor, Borthwick
  133. */
  134. 7, 8, 10, 14, 23, 44, 95, 241,
  135. 8, 8, 11, 15, 25, 47, 102, 255,
  136. 10, 11, 13, 19, 31, 58, 127, 255,
  137. 14, 15, 19, 27, 44, 83, 181, 255,
  138. 23, 25, 31, 44, 72, 136, 255, 255,
  139. 44, 47, 58, 83, 136, 255, 255, 255,
  140. 95, 102, 127, 181, 255, 255, 255, 255,
  141. 241, 255, 255, 255, 255, 255, 255, 255
  142. },
  143. {
  144. /* A visual detection model for DCT coefficient quantization (12/9/93) Ahumada, Watson, Peterson
  145. */
  146. 15, 11, 11, 12, 15, 19, 25, 32,
  147. 11, 13, 10, 10, 12, 15, 19, 24,
  148. 11, 10, 14, 14, 16, 18, 22, 27,
  149. 12, 10, 14, 18, 21, 24, 28, 33,
  150. 15, 12, 16, 21, 26, 31, 36, 42,
  151. 19, 15, 18, 24, 31, 38, 45, 53,
  152. 25, 19, 22, 28, 36, 45, 55, 65,
  153. 32, 24, 27, 33, 42, 53, 65, 77
  154. },
  155. {
  156. /* An improved detection model for DCT coefficient quantization (1993) Peterson, Ahumada and Watson
  157. */
  158. 14, 10, 11, 14, 19, 25, 34, 45,
  159. 10, 11, 11, 12, 15, 20, 26, 33,
  160. 11, 11, 15, 18, 21, 25, 31, 38,
  161. 14, 12, 18, 24, 28, 33, 39, 47,
  162. 19, 15, 21, 28, 36, 43, 51, 59,
  163. 25, 20, 25, 33, 43, 54, 64, 74,
  164. 34, 26, 31, 39, 51, 64, 77, 91,
  165. 45, 33, 38, 47, 59, 74, 91, 108
  166. }
  167. };
  168. static const unsigned int std_chrominance_quant_tbl[9][DCTSIZE2] = {
  169. {
  170. /* JPEG Annex K
  171. */
  172. 17, 18, 24, 47, 99, 99, 99, 99,
  173. 18, 21, 26, 66, 99, 99, 99, 99,
  174. 24, 26, 56, 99, 99, 99, 99, 99,
  175. 47, 66, 99, 99, 99, 99, 99, 99,
  176. 99, 99, 99, 99, 99, 99, 99, 99,
  177. 99, 99, 99, 99, 99, 99, 99, 99,
  178. 99, 99, 99, 99, 99, 99, 99, 99,
  179. 99, 99, 99, 99, 99, 99, 99, 99
  180. },
  181. {
  182. /* flat
  183. */
  184. 16, 16, 16, 16, 16, 16, 16, 16,
  185. 16, 16, 16, 16, 16, 16, 16, 16,
  186. 16, 16, 16, 16, 16, 16, 16, 16,
  187. 16, 16, 16, 16, 16, 16, 16, 16,
  188. 16, 16, 16, 16, 16, 16, 16, 16,
  189. 16, 16, 16, 16, 16, 16, 16, 16,
  190. 16, 16, 16, 16, 16, 16, 16, 16,
  191. 16, 16, 16, 16, 16, 16, 16, 16
  192. },
  193. {
  194. 8, 12, 15, 15, 86, 96, 96, 98,
  195. 13, 13, 15, 26, 90, 96, 99, 98,
  196. 12, 15, 18, 96, 99, 99, 99, 99,
  197. 17, 16, 90, 96, 99, 99, 99, 99,
  198. 96, 96, 99, 99, 99, 99, 99, 99,
  199. 99, 99, 99, 99, 99, 99, 99, 99,
  200. 99, 99, 99, 99, 99, 99, 99, 99,
  201. 99, 99, 99, 99, 99, 99, 99, 99
  202. },
  203. {
  204. /* From http://www.imagemagick.org/discourse-server/viewtopic.php?f=22&t=20333&p=98008#p98008
  205. */
  206. 16, 16, 16, 18, 25, 37, 56, 85,
  207. 16, 17, 20, 27, 34, 40, 53, 75,
  208. 16, 20, 24, 31, 43, 62, 91, 135,
  209. 18, 27, 31, 40, 53, 74, 106, 156,
  210. 25, 34, 43, 53, 69, 94, 131, 189,
  211. 37, 40, 62, 74, 94, 124, 169, 238,
  212. 56, 53, 91, 106, 131, 169, 226, 311,
  213. 85, 75, 135, 156, 189, 238, 311, 418
  214. },
  215. {
  216. 9, 10, 17, 19, 62, 89, 91, 97,
  217. 12, 13, 18, 29, 84, 91, 88, 98,
  218. 14, 19, 29, 93, 95, 95, 98, 97,
  219. 20, 26, 84, 88, 95, 95, 98, 94,
  220. 26, 86, 91, 93, 97, 99, 98, 99,
  221. 99, 100, 98, 99, 99, 99, 99, 99,
  222. 99, 99, 99, 99, 99, 99, 99, 99,
  223. 97, 97, 99, 99, 99, 99, 97, 99
  224. },
  225. {
  226. /* Relevance of human vision to JPEG-DCT compression (1992) Klein, Silverstein and Carney.
  227. * Copied from luma
  228. */
  229. 10, 12, 14, 19, 26, 38, 57, 86,
  230. 12, 18, 21, 28, 35, 41, 54, 76,
  231. 14, 21, 25, 32, 44, 63, 92, 136,
  232. 19, 28, 32, 41, 54, 75, 107, 157,
  233. 26, 35, 44, 54, 70, 95, 132, 190,
  234. 38, 41, 63, 75, 95, 125, 170, 239,
  235. 57, 54, 92, 107, 132, 170, 227, 312,
  236. 86, 76, 136, 157, 190, 239, 312, 419
  237. },
  238. {
  239. /* DCTune perceptual optimization of compressed dental X-Rays (1997) Watson, Taylor, Borthwick
  240. * Copied from luma
  241. */
  242. 7, 8, 10, 14, 23, 44, 95, 241,
  243. 8, 8, 11, 15, 25, 47, 102, 255,
  244. 10, 11, 13, 19, 31, 58, 127, 255,
  245. 14, 15, 19, 27, 44, 83, 181, 255,
  246. 23, 25, 31, 44, 72, 136, 255, 255,
  247. 44, 47, 58, 83, 136, 255, 255, 255,
  248. 95, 102, 127, 181, 255, 255, 255, 255,
  249. 241, 255, 255, 255, 255, 255, 255, 255
  250. },
  251. {
  252. /* A visual detection model for DCT coefficient quantization (12/9/93) Ahumada, Watson, Peterson
  253. * Copied from luma
  254. */
  255. 15, 11, 11, 12, 15, 19, 25, 32,
  256. 11, 13, 10, 10, 12, 15, 19, 24,
  257. 11, 10, 14, 14, 16, 18, 22, 27,
  258. 12, 10, 14, 18, 21, 24, 28, 33,
  259. 15, 12, 16, 21, 26, 31, 36, 42,
  260. 19, 15, 18, 24, 31, 38, 45, 53,
  261. 25, 19, 22, 28, 36, 45, 55, 65,
  262. 32, 24, 27, 33, 42, 53, 65, 77
  263. },
  264. {
  265. /* An improved detection model for DCT coefficient quantization (1993) Peterson, Ahumada and Watson
  266. * Copied from luma
  267. */
  268. 14, 10, 11, 14, 19, 25, 34, 45,
  269. 10, 11, 11, 12, 15, 20, 26, 33,
  270. 11, 11, 15, 18, 21, 25, 31, 38,
  271. 14, 12, 18, 24, 28, 33, 39, 47,
  272. 19, 15, 21, 28, 36, 43, 51, 59,
  273. 25, 20, 25, 33, 43, 54, 64, 74,
  274. 34, 26, 31, 39, 51, 64, 77, 91,
  275. 45, 33, 38, 47, 59, 74, 91, 108
  276. }
  277. };
  278. #if JPEG_LIB_VERSION >= 70
  279. GLOBAL(void)
  280. jpeg_default_qtables (j_compress_ptr cinfo, boolean force_baseline)
  281. /* Set or change the 'quality' (quantization) setting, using default tables
  282. * and straight percentage-scaling quality scales.
  283. * This entry point allows different scalings for luminance and chrominance.
  284. */
  285. {
  286. /* Set up two quantization tables using the specified scaling */
  287. jpeg_add_quant_table(cinfo, 0, std_luminance_quant_tbl[cinfo->master->quant_tbl_master_idx],
  288. cinfo->q_scale_factor[0], force_baseline);
  289. jpeg_add_quant_table(cinfo, 1, std_chrominance_quant_tbl[cinfo->master->quant_tbl_master_idx],
  290. cinfo->q_scale_factor[1], force_baseline);
  291. }
  292. #endif
  293. GLOBAL(void)
  294. jpeg_set_linear_quality (j_compress_ptr cinfo, int scale_factor,
  295. boolean force_baseline)
  296. /* Set or change the 'quality' (quantization) setting, using default tables
  297. * and a straight percentage-scaling quality scale. In most cases it's better
  298. * to use jpeg_set_quality (below); this entry point is provided for
  299. * applications that insist on a linear percentage scaling.
  300. */
  301. {
  302. /* Set up two quantization tables using the specified scaling */
  303. jpeg_add_quant_table(cinfo, 0, std_luminance_quant_tbl[cinfo->master->quant_tbl_master_idx],
  304. scale_factor, force_baseline);
  305. jpeg_add_quant_table(cinfo, 1, std_chrominance_quant_tbl[cinfo->master->quant_tbl_master_idx],
  306. scale_factor, force_baseline);
  307. }
  308. GLOBAL(int)
  309. jpeg_quality_scaling (int quality)
  310. {
  311. return jpeg_float_quality_scaling(quality);
  312. }
  313. GLOBAL(float)
  314. jpeg_float_quality_scaling(float quality)
  315. /* Convert a user-specified quality rating to a percentage scaling factor
  316. * for an underlying quantization table, using our recommended scaling curve.
  317. * The input 'quality' factor should be 0 (terrible) to 100 (very good).
  318. */
  319. {
  320. /* Safety limit on quality factor. Convert 0 to 1 to avoid zero divide. */
  321. if (quality <= 0.f) quality = 1.f;
  322. if (quality > 100.f) quality = 100.f;
  323. /* The basic table is used as-is (scaling 100) for a quality of 50.
  324. * Qualities 50..100 are converted to scaling percentage 200 - 2*Q;
  325. * note that at Q=100 the scaling is 0, which will cause jpeg_add_quant_table
  326. * to make all the table entries 1 (hence, minimum quantization loss).
  327. * Qualities 1..50 are converted to scaling percentage 5000/Q.
  328. */
  329. if (quality < 50.f)
  330. quality = 5000.f / quality;
  331. else
  332. quality = 200.f - quality*2.f;
  333. return quality;
  334. }
  335. GLOBAL(void)
  336. jpeg_set_quality (j_compress_ptr cinfo, int quality, boolean force_baseline)
  337. /* Set or change the 'quality' (quantization) setting, using default tables.
  338. * This is the standard quality-adjusting entry point for typical user
  339. * interfaces; only those who want detailed control over quantization tables
  340. * would use the preceding three routines directly.
  341. */
  342. {
  343. /* Convert user 0-100 rating to percentage scaling */
  344. quality = jpeg_quality_scaling(quality);
  345. /* Set up standard quality tables */
  346. jpeg_set_linear_quality(cinfo, quality, force_baseline);
  347. }
  348. /*
  349. * Default parameter setup for compression.
  350. *
  351. * Applications that don't choose to use this routine must do their
  352. * own setup of all these parameters. Alternately, you can call this
  353. * to establish defaults and then alter parameters selectively. This
  354. * is the recommended approach since, if we add any new parameters,
  355. * your code will still work (they'll be set to reasonable defaults).
  356. */
  357. GLOBAL(void)
  358. jpeg_set_defaults (j_compress_ptr cinfo)
  359. {
  360. int i;
  361. /* Safety check to ensure start_compress not called yet. */
  362. if (cinfo->global_state != CSTATE_START)
  363. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  364. /* Allocate comp_info array large enough for maximum component count.
  365. * Array is made permanent in case application wants to compress
  366. * multiple images at same param settings.
  367. */
  368. if (cinfo->comp_info == NULL)
  369. cinfo->comp_info = (jpeg_component_info *)
  370. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  371. MAX_COMPONENTS * sizeof(jpeg_component_info));
  372. /* Initialize everything not dependent on the color space */
  373. #if JPEG_LIB_VERSION >= 70
  374. cinfo->scale_num = 1; /* 1:1 scaling */
  375. cinfo->scale_denom = 1;
  376. #endif
  377. cinfo->data_precision = BITS_IN_JSAMPLE;
  378. /* Set up two quantization tables using default quality of 75 */
  379. jpeg_set_quality(cinfo, 75, TRUE);
  380. /* Set up two Huffman tables */
  381. std_huff_tables((j_common_ptr) cinfo);
  382. /* Initialize default arithmetic coding conditioning */
  383. for (i = 0; i < NUM_ARITH_TBLS; i++) {
  384. cinfo->arith_dc_L[i] = 0;
  385. cinfo->arith_dc_U[i] = 1;
  386. cinfo->arith_ac_K[i] = 5;
  387. }
  388. /* Default is no multiple-scan output */
  389. cinfo->scan_info = NULL;
  390. cinfo->num_scans = 0;
  391. /* Expect normal source image, not raw downsampled data */
  392. cinfo->raw_data_in = FALSE;
  393. /* Use Huffman coding, not arithmetic coding, by default */
  394. cinfo->arith_code = FALSE;
  395. #ifdef ENTROPY_OPT_SUPPORTED
  396. if (cinfo->master->compress_profile == JCP_MAX_COMPRESSION)
  397. /* By default, do extra passes to optimize entropy coding */
  398. cinfo->optimize_coding = TRUE;
  399. else
  400. /* By default, don't do extra passes to optimize entropy coding */
  401. cinfo->optimize_coding = FALSE;
  402. #else
  403. /* By default, don't do extra passes to optimize entropy coding */
  404. cinfo->optimize_coding = FALSE;
  405. #endif
  406. /* The standard Huffman tables are only valid for 8-bit data precision.
  407. * If the precision is higher, force optimization on so that usable
  408. * tables will be computed. This test can be removed if default tables
  409. * are supplied that are valid for the desired precision.
  410. */
  411. if (cinfo->data_precision > 8)
  412. cinfo->optimize_coding = TRUE;
  413. /* By default, use the simpler non-cosited sampling alignment */
  414. cinfo->CCIR601_sampling = FALSE;
  415. #if JPEG_LIB_VERSION >= 70
  416. /* By default, apply fancy downsampling */
  417. cinfo->do_fancy_downsampling = TRUE;
  418. #endif
  419. cinfo->master->overshoot_deringing =
  420. cinfo->master->compress_profile == JCP_MAX_COMPRESSION;
  421. /* No input smoothing */
  422. cinfo->smoothing_factor = 0;
  423. /* DCT algorithm preference */
  424. cinfo->dct_method = JDCT_DEFAULT;
  425. /* No restart markers */
  426. cinfo->restart_interval = 0;
  427. cinfo->restart_in_rows = 0;
  428. /* Fill in default JFIF marker parameters. Note that whether the marker
  429. * will actually be written is determined by jpeg_set_colorspace.
  430. *
  431. * By default, the library emits JFIF version code 1.01.
  432. * An application that wants to emit JFIF 1.02 extension markers should set
  433. * JFIF_minor_version to 2. We could probably get away with just defaulting
  434. * to 1.02, but there may still be some decoders in use that will complain
  435. * about that; saying 1.01 should minimize compatibility problems.
  436. */
  437. cinfo->JFIF_major_version = 1; /* Default JFIF version = 1.01 */
  438. cinfo->JFIF_minor_version = 1;
  439. cinfo->density_unit = 0; /* Pixel size is unknown by default */
  440. cinfo->X_density = 1; /* Pixel aspect ratio is square by default */
  441. cinfo->Y_density = 1;
  442. /* Choose JPEG colorspace based on input space, set defaults accordingly */
  443. jpeg_default_colorspace(cinfo);
  444. cinfo->master->dc_scan_opt_mode = 1;
  445. #ifdef C_PROGRESSIVE_SUPPORTED
  446. if (cinfo->master->compress_profile == JCP_MAX_COMPRESSION) {
  447. cinfo->master->optimize_scans = TRUE;
  448. jpeg_simple_progression(cinfo);
  449. } else
  450. cinfo->master->optimize_scans = FALSE;
  451. #endif
  452. cinfo->master->trellis_quant =
  453. cinfo->master->compress_profile == JCP_MAX_COMPRESSION;
  454. cinfo->master->lambda_log_scale1 = 14.75;
  455. cinfo->master->lambda_log_scale2 = 16.5;
  456. cinfo->master->quant_tbl_master_idx =
  457. cinfo->master->compress_profile == JCP_MAX_COMPRESSION ? 3 : 0;
  458. cinfo->master->use_lambda_weight_tbl = TRUE;
  459. cinfo->master->use_scans_in_trellis = FALSE;
  460. cinfo->master->trellis_freq_split = 8;
  461. cinfo->master->trellis_num_loops = 1;
  462. cinfo->master->trellis_q_opt = FALSE;
  463. cinfo->master->trellis_quant_dc = TRUE;
  464. cinfo->master->trellis_delta_dc_weight = 0.0;
  465. }
  466. /*
  467. * Select an appropriate JPEG colorspace for in_color_space.
  468. */
  469. GLOBAL(void)
  470. jpeg_default_colorspace (j_compress_ptr cinfo)
  471. {
  472. switch (cinfo->in_color_space) {
  473. case JCS_GRAYSCALE:
  474. jpeg_set_colorspace(cinfo, JCS_GRAYSCALE);
  475. break;
  476. case JCS_RGB:
  477. case JCS_EXT_RGB:
  478. case JCS_EXT_RGBX:
  479. case JCS_EXT_BGR:
  480. case JCS_EXT_BGRX:
  481. case JCS_EXT_XBGR:
  482. case JCS_EXT_XRGB:
  483. case JCS_EXT_RGBA:
  484. case JCS_EXT_BGRA:
  485. case JCS_EXT_ABGR:
  486. case JCS_EXT_ARGB:
  487. jpeg_set_colorspace(cinfo, JCS_YCbCr);
  488. break;
  489. case JCS_YCbCr:
  490. jpeg_set_colorspace(cinfo, JCS_YCbCr);
  491. break;
  492. case JCS_CMYK:
  493. jpeg_set_colorspace(cinfo, JCS_CMYK); /* By default, no translation */
  494. break;
  495. case JCS_YCCK:
  496. jpeg_set_colorspace(cinfo, JCS_YCCK);
  497. break;
  498. case JCS_UNKNOWN:
  499. jpeg_set_colorspace(cinfo, JCS_UNKNOWN);
  500. break;
  501. default:
  502. ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  503. }
  504. }
  505. /*
  506. * Set the JPEG colorspace, and choose colorspace-dependent default values.
  507. */
  508. GLOBAL(void)
  509. jpeg_set_colorspace (j_compress_ptr cinfo, J_COLOR_SPACE colorspace)
  510. {
  511. jpeg_component_info *compptr;
  512. int ci;
  513. #define SET_COMP(index,id,hsamp,vsamp,quant,dctbl,actbl) \
  514. (compptr = &cinfo->comp_info[index], \
  515. compptr->component_id = (id), \
  516. compptr->h_samp_factor = (hsamp), \
  517. compptr->v_samp_factor = (vsamp), \
  518. compptr->quant_tbl_no = (quant), \
  519. compptr->dc_tbl_no = (dctbl), \
  520. compptr->ac_tbl_no = (actbl) )
  521. /* Safety check to ensure start_compress not called yet. */
  522. if (cinfo->global_state != CSTATE_START)
  523. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  524. /* For all colorspaces, we use Q and Huff tables 0 for luminance components,
  525. * tables 1 for chrominance components.
  526. */
  527. cinfo->jpeg_color_space = colorspace;
  528. cinfo->write_JFIF_header = FALSE; /* No marker for non-JFIF colorspaces */
  529. cinfo->write_Adobe_marker = FALSE; /* write no Adobe marker by default */
  530. switch (colorspace) {
  531. case JCS_GRAYSCALE:
  532. cinfo->write_JFIF_header = TRUE; /* Write a JFIF marker */
  533. cinfo->num_components = 1;
  534. /* JFIF specifies component ID 1 */
  535. SET_COMP(0, 1, 1,1, 0, 0,0);
  536. break;
  537. case JCS_RGB:
  538. cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag RGB */
  539. cinfo->num_components = 3;
  540. SET_COMP(0, 0x52 /* 'R' */, 1,1, 0, 0,0);
  541. SET_COMP(1, 0x47 /* 'G' */, 1,1, 0, 0,0);
  542. SET_COMP(2, 0x42 /* 'B' */, 1,1, 0, 0,0);
  543. break;
  544. case JCS_YCbCr:
  545. cinfo->write_JFIF_header = TRUE; /* Write a JFIF marker */
  546. cinfo->num_components = 3;
  547. /* JFIF specifies component IDs 1,2,3 */
  548. /* We default to 2x2 subsamples of chrominance */
  549. SET_COMP(0, 1, 2,2, 0, 0,0);
  550. SET_COMP(1, 2, 1,1, 1, 1,1);
  551. SET_COMP(2, 3, 1,1, 1, 1,1);
  552. break;
  553. case JCS_CMYK:
  554. cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag CMYK */
  555. cinfo->num_components = 4;
  556. SET_COMP(0, 0x43 /* 'C' */, 1,1, 0, 0,0);
  557. SET_COMP(1, 0x4D /* 'M' */, 1,1, 0, 0,0);
  558. SET_COMP(2, 0x59 /* 'Y' */, 1,1, 0, 0,0);
  559. SET_COMP(3, 0x4B /* 'K' */, 1,1, 0, 0,0);
  560. break;
  561. case JCS_YCCK:
  562. cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag YCCK */
  563. cinfo->num_components = 4;
  564. SET_COMP(0, 1, 2,2, 0, 0,0);
  565. SET_COMP(1, 2, 1,1, 1, 1,1);
  566. SET_COMP(2, 3, 1,1, 1, 1,1);
  567. SET_COMP(3, 4, 2,2, 0, 0,0);
  568. break;
  569. case JCS_UNKNOWN:
  570. cinfo->num_components = cinfo->input_components;
  571. if (cinfo->num_components < 1 || cinfo->num_components > MAX_COMPONENTS)
  572. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
  573. MAX_COMPONENTS);
  574. for (ci = 0; ci < cinfo->num_components; ci++) {
  575. SET_COMP(ci, ci, 1,1, 0, 0,0);
  576. }
  577. break;
  578. default:
  579. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  580. }
  581. }
  582. #ifdef C_PROGRESSIVE_SUPPORTED
  583. LOCAL(jpeg_scan_info *)
  584. fill_a_scan(jpeg_scan_info *scanptr, int ci, int Ss, int Se, int Ah, int Al)
  585. /* Support routine: generate one scan for specified component */
  586. {
  587. scanptr->comps_in_scan = 1;
  588. scanptr->component_index[0] = ci;
  589. scanptr->Ss = Ss;
  590. scanptr->Se = Se;
  591. scanptr->Ah = Ah;
  592. scanptr->Al = Al;
  593. scanptr++;
  594. return scanptr;
  595. }
  596. LOCAL(jpeg_scan_info *)
  597. fill_a_scan_pair (jpeg_scan_info * scanptr, int ci,
  598. int Ss, int Se, int Ah, int Al)
  599. /* Support routine: generate one scan for pair of components */
  600. {
  601. scanptr->comps_in_scan = 2;
  602. scanptr->component_index[0] = ci;
  603. scanptr->component_index[1] = ci + 1;
  604. scanptr->Ss = Ss;
  605. scanptr->Se = Se;
  606. scanptr->Ah = Ah;
  607. scanptr->Al = Al;
  608. scanptr++;
  609. return scanptr;
  610. }
  611. LOCAL(jpeg_scan_info *)
  612. fill_scans (jpeg_scan_info *scanptr, int ncomps,
  613. int Ss, int Se, int Ah, int Al)
  614. /* Support routine: generate one scan for each component */
  615. {
  616. int ci;
  617. for (ci = 0; ci < ncomps; ci++) {
  618. scanptr->comps_in_scan = 1;
  619. scanptr->component_index[0] = ci;
  620. scanptr->Ss = Ss;
  621. scanptr->Se = Se;
  622. scanptr->Ah = Ah;
  623. scanptr->Al = Al;
  624. scanptr++;
  625. }
  626. return scanptr;
  627. }
  628. LOCAL(jpeg_scan_info *)
  629. fill_dc_scans (jpeg_scan_info *scanptr, int ncomps, int Ah, int Al)
  630. /* Support routine: generate interleaved DC scan if possible, else N scans */
  631. {
  632. int ci;
  633. if (ncomps <= MAX_COMPS_IN_SCAN) {
  634. /* Single interleaved DC scan */
  635. scanptr->comps_in_scan = ncomps;
  636. for (ci = 0; ci < ncomps; ci++)
  637. scanptr->component_index[ci] = ci;
  638. scanptr->Ss = scanptr->Se = 0;
  639. scanptr->Ah = Ah;
  640. scanptr->Al = Al;
  641. scanptr++;
  642. } else {
  643. /* Noninterleaved DC scan for each component */
  644. scanptr = fill_scans(scanptr, ncomps, 0, 0, Ah, Al);
  645. }
  646. return scanptr;
  647. }
  648. /*
  649. * List of scans to be tested
  650. * cinfo->num_components and cinfo->jpeg_color_space must be correct.
  651. */
  652. LOCAL(boolean)
  653. jpeg_search_progression (j_compress_ptr cinfo)
  654. {
  655. int ncomps = cinfo->num_components;
  656. int nscans;
  657. jpeg_scan_info * scanptr;
  658. int Al;
  659. int frequency_split[] = { 2, 8, 5, 12, 18 };
  660. int i;
  661. /* Safety check to ensure start_compress not called yet. */
  662. if (cinfo->global_state != CSTATE_START)
  663. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  664. /* Figure space needed for script. Calculation must match code below! */
  665. if (ncomps == 3 && cinfo->jpeg_color_space == JCS_YCbCr) {
  666. /* Custom script for YCbCr color images. */
  667. nscans = 64;
  668. } else if (ncomps == 1) {
  669. nscans = 23;
  670. } else {
  671. cinfo->master->num_scans_luma = 0;
  672. return FALSE;
  673. }
  674. /* Allocate space for script.
  675. * We need to put it in the permanent pool in case the application performs
  676. * multiple compressions without changing the settings. To avoid a memory
  677. * leak if jpeg_simple_progression is called repeatedly for the same JPEG
  678. * object, we try to re-use previously allocated space, and we allocate
  679. * enough space to handle YCbCr even if initially asked for grayscale.
  680. */
  681. if (cinfo->script_space == NULL || cinfo->script_space_size < nscans) {
  682. cinfo->script_space_size = MAX(nscans, 64);
  683. cinfo->script_space = (jpeg_scan_info *)
  684. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  685. cinfo->script_space_size * sizeof(jpeg_scan_info));
  686. }
  687. scanptr = cinfo->script_space;
  688. cinfo->scan_info = scanptr;
  689. cinfo->num_scans = nscans;
  690. cinfo->master->Al_max_luma = 3;
  691. cinfo->master->num_scans_luma_dc = 1;
  692. cinfo->master->num_frequency_splits = 5;
  693. cinfo->master->num_scans_luma =
  694. cinfo->master->num_scans_luma_dc + (3 * cinfo->master->Al_max_luma + 2) +
  695. (2 * cinfo->master->num_frequency_splits + 1);
  696. /* 23 scans for luma */
  697. /* 1 scan for DC */
  698. /* 11 scans to determine successive approximation */
  699. /* 11 scans to determine frequency approximation */
  700. /* after 12 scans need to update following 11 */
  701. /* after 23 scans need to determine which to keep */
  702. /* last 4 done conditionally */
  703. /* luma DC by itself */
  704. if (cinfo->master->dc_scan_opt_mode == 0)
  705. scanptr = fill_dc_scans(scanptr, ncomps, 0, 0);
  706. else
  707. scanptr = fill_dc_scans(scanptr, 1, 0, 0);
  708. scanptr = fill_a_scan(scanptr, 0, 1, 8, 0, 0);
  709. scanptr = fill_a_scan(scanptr, 0, 9, 63, 0, 0);
  710. for (Al = 0; Al < cinfo->master->Al_max_luma; Al++) {
  711. scanptr = fill_a_scan(scanptr, 0, 1, 63, Al+1, Al);
  712. scanptr = fill_a_scan(scanptr, 0, 1, 8, 0, Al+1);
  713. scanptr = fill_a_scan(scanptr, 0, 9, 63, 0, Al+1);
  714. }
  715. scanptr = fill_a_scan(scanptr, 0, 1, 63, 0, 0);
  716. for (i = 0; i < cinfo->master->num_frequency_splits; i++) {
  717. scanptr = fill_a_scan(scanptr, 0, 1, frequency_split[i], 0, 0);
  718. scanptr = fill_a_scan(scanptr, 0, frequency_split[i]+1, 63, 0, 0);
  719. }
  720. if (ncomps == 1) {
  721. cinfo->master->Al_max_chroma = 0;
  722. cinfo->master->num_scans_chroma_dc = 0;
  723. } else {
  724. cinfo->master->Al_max_chroma = 2;
  725. cinfo->master->num_scans_chroma_dc = 3;
  726. /* 41 scans for chroma */
  727. /* chroma DC combined */
  728. scanptr = fill_a_scan_pair(scanptr, 1, 0, 0, 0, 0);
  729. /* chroma DC separate */
  730. scanptr = fill_a_scan(scanptr, 1, 0, 0, 0, 0);
  731. scanptr = fill_a_scan(scanptr, 2, 0, 0, 0, 0);
  732. scanptr = fill_a_scan(scanptr, 1, 1, 8, 0, 0);
  733. scanptr = fill_a_scan(scanptr, 1, 9, 63, 0, 0);
  734. scanptr = fill_a_scan(scanptr, 2, 1, 8, 0, 0);
  735. scanptr = fill_a_scan(scanptr, 2, 9, 63, 0, 0);
  736. for (Al = 0; Al < cinfo->master->Al_max_chroma; Al++) {
  737. scanptr = fill_a_scan(scanptr, 1, 1, 63, Al+1, Al);
  738. scanptr = fill_a_scan(scanptr, 2, 1, 63, Al+1, Al);
  739. scanptr = fill_a_scan(scanptr, 1, 1, 8, 0, Al+1);
  740. scanptr = fill_a_scan(scanptr, 1, 9, 63, 0, Al+1);
  741. scanptr = fill_a_scan(scanptr, 2, 1, 8, 0, Al+1);
  742. scanptr = fill_a_scan(scanptr, 2, 9, 63, 0, Al+1);
  743. }
  744. scanptr = fill_a_scan(scanptr, 1, 1, 63, 0, 0);
  745. scanptr = fill_a_scan(scanptr, 2, 1, 63, 0, 0);
  746. for (i = 0; i < cinfo->master->num_frequency_splits; i++) {
  747. scanptr = fill_a_scan(scanptr, 1, 1, frequency_split[i], 0, 0);
  748. scanptr = fill_a_scan(scanptr, 1, frequency_split[i]+1, 63, 0, 0);
  749. scanptr = fill_a_scan(scanptr, 2, 1, frequency_split[i], 0, 0);
  750. scanptr = fill_a_scan(scanptr, 2, frequency_split[i]+1, 63, 0, 0);
  751. }
  752. }
  753. return TRUE;
  754. }
  755. /*
  756. * Create a recommended progressive-JPEG script.
  757. * cinfo->num_components and cinfo->jpeg_color_space must be correct.
  758. */
  759. GLOBAL(void)
  760. jpeg_simple_progression (j_compress_ptr cinfo)
  761. {
  762. int ncomps;
  763. int nscans;
  764. jpeg_scan_info *scanptr;
  765. if (cinfo->master->optimize_scans) {
  766. if (jpeg_search_progression(cinfo) == TRUE)
  767. return;
  768. }
  769. /* Safety check to ensure start_compress not called yet. */
  770. if (cinfo->global_state != CSTATE_START)
  771. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  772. /* Figure space needed for script. Calculation must match code below! */
  773. ncomps = cinfo->num_components;
  774. if (ncomps == 3 && cinfo->jpeg_color_space == JCS_YCbCr) {
  775. /* Custom script for YCbCr color images. */
  776. if (cinfo->master->compress_profile == JCP_MAX_COMPRESSION) {
  777. if (cinfo->master->dc_scan_opt_mode == 0) {
  778. nscans = 9; /* 1 DC scan for all components */
  779. } else if (cinfo->master->dc_scan_opt_mode == 1) {
  780. nscans = 11; /* 1 DC scan for each component */
  781. } else {
  782. nscans = 10; /* 1 DC scan for luminance and 1 DC scan for chroma */
  783. }
  784. } else {
  785. nscans = 10; /* 2 DC scans and 8 AC scans */
  786. }
  787. } else {
  788. /* All-purpose script for other color spaces. */
  789. if (cinfo->master->compress_profile == JCP_MAX_COMPRESSION) {
  790. if (ncomps > MAX_COMPS_IN_SCAN)
  791. nscans = 5 * ncomps; /* 2 DC + 4 AC scans per component */
  792. else
  793. nscans = 1 + 4 * ncomps; /* 2 DC scans; 4 AC scans per component */
  794. } else {
  795. if (ncomps > MAX_COMPS_IN_SCAN)
  796. nscans = 6 * ncomps; /* 2 DC + 4 AC scans per component */
  797. else
  798. nscans = 2 + 4 * ncomps; /* 2 DC scans; 4 AC scans per component */
  799. }
  800. }
  801. /* Allocate space for script.
  802. * We need to put it in the permanent pool in case the application performs
  803. * multiple compressions without changing the settings. To avoid a memory
  804. * leak if jpeg_simple_progression is called repeatedly for the same JPEG
  805. * object, we try to re-use previously allocated space, and we allocate
  806. * enough space to handle YCbCr even if initially asked for grayscale.
  807. */
  808. if (cinfo->script_space == NULL || cinfo->script_space_size < nscans) {
  809. cinfo->script_space_size = MAX(nscans, 10);
  810. cinfo->script_space = (jpeg_scan_info *)
  811. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  812. cinfo->script_space_size * sizeof(jpeg_scan_info));
  813. }
  814. scanptr = cinfo->script_space;
  815. cinfo->scan_info = scanptr;
  816. cinfo->num_scans = nscans;
  817. if (ncomps == 3 && cinfo->jpeg_color_space == JCS_YCbCr) {
  818. /* Custom script for YCbCr color images. */
  819. if (cinfo->master->compress_profile == JCP_MAX_COMPRESSION) {
  820. /* scan defined in jpeg_scan_rgb.txt in jpgcrush */
  821. /* Initial DC scan */
  822. if (cinfo->master->dc_scan_opt_mode == 0) {
  823. /* 1 DC scan for all components */
  824. scanptr = fill_dc_scans(scanptr, ncomps, 0, 0);
  825. } else if (cinfo->master->dc_scan_opt_mode == 1) {
  826. /* 1 DC scan for each component */
  827. scanptr = fill_a_scan(scanptr, 0, 0, 0, 0, 0);
  828. scanptr = fill_a_scan(scanptr, 1, 0, 0, 0, 0);
  829. scanptr = fill_a_scan(scanptr, 2, 0, 0, 0, 0);
  830. } else {
  831. /* 1 DC scan for luminance and 1 DC scan for chroma */
  832. scanptr = fill_dc_scans(scanptr, 1, 0, 0);
  833. scanptr = fill_a_scan_pair(scanptr, 1, 0, 0, 0, 0);
  834. }
  835. /* Low frequency AC scans */
  836. scanptr = fill_a_scan(scanptr, 0, 1, 8, 0, 2);
  837. scanptr = fill_a_scan(scanptr, 1, 1, 8, 0, 0);
  838. scanptr = fill_a_scan(scanptr, 2, 1, 8, 0, 0);
  839. /* Complete spectral selection for luma AC */
  840. scanptr = fill_a_scan(scanptr, 0, 9, 63, 0, 2);
  841. /* Finish luma AC successive approximation */
  842. scanptr = fill_a_scan(scanptr, 0, 1, 63, 2, 1);
  843. scanptr = fill_a_scan(scanptr, 0, 1, 63, 1, 0);
  844. /* Complete spectral selection for chroma AC */
  845. scanptr = fill_a_scan(scanptr, 1, 9, 63, 0, 0);
  846. scanptr = fill_a_scan(scanptr, 2, 9, 63, 0, 0);
  847. } else {
  848. /* Initial DC scan */
  849. scanptr = fill_dc_scans(scanptr, ncomps, 0, 1);
  850. /* Initial AC scan: get some luma data out in a hurry */
  851. scanptr = fill_a_scan(scanptr, 0, 1, 5, 0, 2);
  852. /* Chroma data is too small to be worth expending many scans on */
  853. scanptr = fill_a_scan(scanptr, 2, 1, 63, 0, 1);
  854. scanptr = fill_a_scan(scanptr, 1, 1, 63, 0, 1);
  855. /* Complete spectral selection for luma AC */
  856. scanptr = fill_a_scan(scanptr, 0, 6, 63, 0, 2);
  857. /* Refine next bit of luma AC */
  858. scanptr = fill_a_scan(scanptr, 0, 1, 63, 2, 1);
  859. /* Finish DC successive approximation */
  860. scanptr = fill_dc_scans(scanptr, ncomps, 1, 0);
  861. /* Finish AC successive approximation */
  862. scanptr = fill_a_scan(scanptr, 2, 1, 63, 1, 0);
  863. scanptr = fill_a_scan(scanptr, 1, 1, 63, 1, 0);
  864. /* Luma bottom bit comes last since it's usually largest scan */
  865. scanptr = fill_a_scan(scanptr, 0, 1, 63, 1, 0);
  866. }
  867. } else {
  868. /* All-purpose script for other color spaces. */
  869. if (cinfo->master->compress_profile == JCP_MAX_COMPRESSION) {
  870. /* scan defined in jpeg_scan_bw.txt in jpgcrush */
  871. /* DC component, no successive approximation */
  872. scanptr = fill_dc_scans(scanptr, ncomps, 0, 0);
  873. /* Successive approximation first pass */
  874. scanptr = fill_scans(scanptr, ncomps, 1, 8, 0, 2);
  875. scanptr = fill_scans(scanptr, ncomps, 9, 63, 0, 2);
  876. /* Successive approximation second pass */
  877. scanptr = fill_scans(scanptr, ncomps, 1, 63, 2, 1);
  878. /* Successive approximation final pass */
  879. scanptr = fill_scans(scanptr, ncomps, 1, 63, 1, 0);
  880. } else {
  881. /* Successive approximation first pass */
  882. scanptr = fill_dc_scans(scanptr, ncomps, 0, 1);
  883. scanptr = fill_scans(scanptr, ncomps, 1, 5, 0, 2);
  884. scanptr = fill_scans(scanptr, ncomps, 6, 63, 0, 2);
  885. /* Successive approximation second pass */
  886. scanptr = fill_scans(scanptr, ncomps, 1, 63, 2, 1);
  887. /* Successive approximation final pass */
  888. scanptr = fill_dc_scans(scanptr, ncomps, 1, 0);
  889. scanptr = fill_scans(scanptr, ncomps, 1, 63, 1, 0);
  890. }
  891. }
  892. }
  893. #endif /* C_PROGRESSIVE_SUPPORTED */