1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/media/libjpeg/jcparam.c Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,541 @@ 1.4 +/* 1.5 + * jcparam.c 1.6 + * 1.7 + * This file was part of the Independent JPEG Group's software: 1.8 + * Copyright (C) 1991-1998, Thomas G. Lane. 1.9 + * Modified 2003-2008 by Guido Vollbeding. 1.10 + * libjpeg-turbo Modifications: 1.11 + * Copyright (C) 2009-2011, D. R. Commander. 1.12 + * For conditions of distribution and use, see the accompanying README file. 1.13 + * 1.14 + * This file contains optional default-setting code for the JPEG compressor. 1.15 + * Applications do not have to use this file, but those that don't use it 1.16 + * must know a lot more about the innards of the JPEG code. 1.17 + */ 1.18 + 1.19 +#define JPEG_INTERNALS 1.20 +#include "jinclude.h" 1.21 +#include "jpeglib.h" 1.22 +#include "jstdhuff.c" 1.23 + 1.24 + 1.25 +/* 1.26 + * Quantization table setup routines 1.27 + */ 1.28 + 1.29 +GLOBAL(void) 1.30 +jpeg_add_quant_table (j_compress_ptr cinfo, int which_tbl, 1.31 + const unsigned int *basic_table, 1.32 + int scale_factor, boolean force_baseline) 1.33 +/* Define a quantization table equal to the basic_table times 1.34 + * a scale factor (given as a percentage). 1.35 + * If force_baseline is TRUE, the computed quantization table entries 1.36 + * are limited to 1..255 for JPEG baseline compatibility. 1.37 + */ 1.38 +{ 1.39 + JQUANT_TBL ** qtblptr; 1.40 + int i; 1.41 + long temp; 1.42 + 1.43 + /* Safety check to ensure start_compress not called yet. */ 1.44 + if (cinfo->global_state != CSTATE_START) 1.45 + ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); 1.46 + 1.47 + if (which_tbl < 0 || which_tbl >= NUM_QUANT_TBLS) 1.48 + ERREXIT1(cinfo, JERR_DQT_INDEX, which_tbl); 1.49 + 1.50 + qtblptr = & cinfo->quant_tbl_ptrs[which_tbl]; 1.51 + 1.52 + if (*qtblptr == NULL) 1.53 + *qtblptr = jpeg_alloc_quant_table((j_common_ptr) cinfo); 1.54 + 1.55 + for (i = 0; i < DCTSIZE2; i++) { 1.56 + temp = ((long) basic_table[i] * scale_factor + 50L) / 100L; 1.57 + /* limit the values to the valid range */ 1.58 + if (temp <= 0L) temp = 1L; 1.59 + if (temp > 32767L) temp = 32767L; /* max quantizer needed for 12 bits */ 1.60 + if (force_baseline && temp > 255L) 1.61 + temp = 255L; /* limit to baseline range if requested */ 1.62 + (*qtblptr)->quantval[i] = (UINT16) temp; 1.63 + } 1.64 + 1.65 + /* Initialize sent_table FALSE so table will be written to JPEG file. */ 1.66 + (*qtblptr)->sent_table = FALSE; 1.67 +} 1.68 + 1.69 + 1.70 +/* These are the sample quantization tables given in JPEG spec section K.1. 1.71 + * The spec says that the values given produce "good" quality, and 1.72 + * when divided by 2, "very good" quality. 1.73 + */ 1.74 +static const unsigned int std_luminance_quant_tbl[DCTSIZE2] = { 1.75 + 16, 11, 10, 16, 24, 40, 51, 61, 1.76 + 12, 12, 14, 19, 26, 58, 60, 55, 1.77 + 14, 13, 16, 24, 40, 57, 69, 56, 1.78 + 14, 17, 22, 29, 51, 87, 80, 62, 1.79 + 18, 22, 37, 56, 68, 109, 103, 77, 1.80 + 24, 35, 55, 64, 81, 104, 113, 92, 1.81 + 49, 64, 78, 87, 103, 121, 120, 101, 1.82 + 72, 92, 95, 98, 112, 100, 103, 99 1.83 +}; 1.84 +static const unsigned int std_chrominance_quant_tbl[DCTSIZE2] = { 1.85 + 17, 18, 24, 47, 99, 99, 99, 99, 1.86 + 18, 21, 26, 66, 99, 99, 99, 99, 1.87 + 24, 26, 56, 99, 99, 99, 99, 99, 1.88 + 47, 66, 99, 99, 99, 99, 99, 99, 1.89 + 99, 99, 99, 99, 99, 99, 99, 99, 1.90 + 99, 99, 99, 99, 99, 99, 99, 99, 1.91 + 99, 99, 99, 99, 99, 99, 99, 99, 1.92 + 99, 99, 99, 99, 99, 99, 99, 99 1.93 +}; 1.94 + 1.95 + 1.96 +#if JPEG_LIB_VERSION >= 70 1.97 +GLOBAL(void) 1.98 +jpeg_default_qtables (j_compress_ptr cinfo, boolean force_baseline) 1.99 +/* Set or change the 'quality' (quantization) setting, using default tables 1.100 + * and straight percentage-scaling quality scales. 1.101 + * This entry point allows different scalings for luminance and chrominance. 1.102 + */ 1.103 +{ 1.104 + /* Set up two quantization tables using the specified scaling */ 1.105 + jpeg_add_quant_table(cinfo, 0, std_luminance_quant_tbl, 1.106 + cinfo->q_scale_factor[0], force_baseline); 1.107 + jpeg_add_quant_table(cinfo, 1, std_chrominance_quant_tbl, 1.108 + cinfo->q_scale_factor[1], force_baseline); 1.109 +} 1.110 +#endif 1.111 + 1.112 + 1.113 +GLOBAL(void) 1.114 +jpeg_set_linear_quality (j_compress_ptr cinfo, int scale_factor, 1.115 + boolean force_baseline) 1.116 +/* Set or change the 'quality' (quantization) setting, using default tables 1.117 + * and a straight percentage-scaling quality scale. In most cases it's better 1.118 + * to use jpeg_set_quality (below); this entry point is provided for 1.119 + * applications that insist on a linear percentage scaling. 1.120 + */ 1.121 +{ 1.122 + /* Set up two quantization tables using the specified scaling */ 1.123 + jpeg_add_quant_table(cinfo, 0, std_luminance_quant_tbl, 1.124 + scale_factor, force_baseline); 1.125 + jpeg_add_quant_table(cinfo, 1, std_chrominance_quant_tbl, 1.126 + scale_factor, force_baseline); 1.127 +} 1.128 + 1.129 + 1.130 +GLOBAL(int) 1.131 +jpeg_quality_scaling (int quality) 1.132 +/* Convert a user-specified quality rating to a percentage scaling factor 1.133 + * for an underlying quantization table, using our recommended scaling curve. 1.134 + * The input 'quality' factor should be 0 (terrible) to 100 (very good). 1.135 + */ 1.136 +{ 1.137 + /* Safety limit on quality factor. Convert 0 to 1 to avoid zero divide. */ 1.138 + if (quality <= 0) quality = 1; 1.139 + if (quality > 100) quality = 100; 1.140 + 1.141 + /* The basic table is used as-is (scaling 100) for a quality of 50. 1.142 + * Qualities 50..100 are converted to scaling percentage 200 - 2*Q; 1.143 + * note that at Q=100 the scaling is 0, which will cause jpeg_add_quant_table 1.144 + * to make all the table entries 1 (hence, minimum quantization loss). 1.145 + * Qualities 1..50 are converted to scaling percentage 5000/Q. 1.146 + */ 1.147 + if (quality < 50) 1.148 + quality = 5000 / quality; 1.149 + else 1.150 + quality = 200 - quality*2; 1.151 + 1.152 + return quality; 1.153 +} 1.154 + 1.155 + 1.156 +GLOBAL(void) 1.157 +jpeg_set_quality (j_compress_ptr cinfo, int quality, boolean force_baseline) 1.158 +/* Set or change the 'quality' (quantization) setting, using default tables. 1.159 + * This is the standard quality-adjusting entry point for typical user 1.160 + * interfaces; only those who want detailed control over quantization tables 1.161 + * would use the preceding three routines directly. 1.162 + */ 1.163 +{ 1.164 + /* Convert user 0-100 rating to percentage scaling */ 1.165 + quality = jpeg_quality_scaling(quality); 1.166 + 1.167 + /* Set up standard quality tables */ 1.168 + jpeg_set_linear_quality(cinfo, quality, force_baseline); 1.169 +} 1.170 + 1.171 + 1.172 +/* 1.173 + * Default parameter setup for compression. 1.174 + * 1.175 + * Applications that don't choose to use this routine must do their 1.176 + * own setup of all these parameters. Alternately, you can call this 1.177 + * to establish defaults and then alter parameters selectively. This 1.178 + * is the recommended approach since, if we add any new parameters, 1.179 + * your code will still work (they'll be set to reasonable defaults). 1.180 + */ 1.181 + 1.182 +GLOBAL(void) 1.183 +jpeg_set_defaults (j_compress_ptr cinfo) 1.184 +{ 1.185 + int i; 1.186 + 1.187 + /* Safety check to ensure start_compress not called yet. */ 1.188 + if (cinfo->global_state != CSTATE_START) 1.189 + ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); 1.190 + 1.191 + /* Allocate comp_info array large enough for maximum component count. 1.192 + * Array is made permanent in case application wants to compress 1.193 + * multiple images at same param settings. 1.194 + */ 1.195 + if (cinfo->comp_info == NULL) 1.196 + cinfo->comp_info = (jpeg_component_info *) 1.197 + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT, 1.198 + MAX_COMPONENTS * SIZEOF(jpeg_component_info)); 1.199 + 1.200 + /* Initialize everything not dependent on the color space */ 1.201 + 1.202 +#if JPEG_LIB_VERSION >= 70 1.203 + cinfo->scale_num = 1; /* 1:1 scaling */ 1.204 + cinfo->scale_denom = 1; 1.205 +#endif 1.206 + cinfo->data_precision = BITS_IN_JSAMPLE; 1.207 + /* Set up two quantization tables using default quality of 75 */ 1.208 + jpeg_set_quality(cinfo, 75, TRUE); 1.209 + /* Set up two Huffman tables */ 1.210 + std_huff_tables((j_common_ptr) cinfo); 1.211 + 1.212 + /* Initialize default arithmetic coding conditioning */ 1.213 + for (i = 0; i < NUM_ARITH_TBLS; i++) { 1.214 + cinfo->arith_dc_L[i] = 0; 1.215 + cinfo->arith_dc_U[i] = 1; 1.216 + cinfo->arith_ac_K[i] = 5; 1.217 + } 1.218 + 1.219 + /* Default is no multiple-scan output */ 1.220 + cinfo->scan_info = NULL; 1.221 + cinfo->num_scans = 0; 1.222 + 1.223 + /* Expect normal source image, not raw downsampled data */ 1.224 + cinfo->raw_data_in = FALSE; 1.225 + 1.226 + /* Use Huffman coding, not arithmetic coding, by default */ 1.227 + cinfo->arith_code = FALSE; 1.228 + 1.229 + /* By default, don't do extra passes to optimize entropy coding */ 1.230 + cinfo->optimize_coding = FALSE; 1.231 + /* The standard Huffman tables are only valid for 8-bit data precision. 1.232 + * If the precision is higher, force optimization on so that usable 1.233 + * tables will be computed. This test can be removed if default tables 1.234 + * are supplied that are valid for the desired precision. 1.235 + */ 1.236 + if (cinfo->data_precision > 8) 1.237 + cinfo->optimize_coding = TRUE; 1.238 + 1.239 + /* By default, use the simpler non-cosited sampling alignment */ 1.240 + cinfo->CCIR601_sampling = FALSE; 1.241 + 1.242 +#if JPEG_LIB_VERSION >= 70 1.243 + /* By default, apply fancy downsampling */ 1.244 + cinfo->do_fancy_downsampling = TRUE; 1.245 +#endif 1.246 + 1.247 + /* No input smoothing */ 1.248 + cinfo->smoothing_factor = 0; 1.249 + 1.250 + /* DCT algorithm preference */ 1.251 + cinfo->dct_method = JDCT_DEFAULT; 1.252 + 1.253 + /* No restart markers */ 1.254 + cinfo->restart_interval = 0; 1.255 + cinfo->restart_in_rows = 0; 1.256 + 1.257 + /* Fill in default JFIF marker parameters. Note that whether the marker 1.258 + * will actually be written is determined by jpeg_set_colorspace. 1.259 + * 1.260 + * By default, the library emits JFIF version code 1.01. 1.261 + * An application that wants to emit JFIF 1.02 extension markers should set 1.262 + * JFIF_minor_version to 2. We could probably get away with just defaulting 1.263 + * to 1.02, but there may still be some decoders in use that will complain 1.264 + * about that; saying 1.01 should minimize compatibility problems. 1.265 + */ 1.266 + cinfo->JFIF_major_version = 1; /* Default JFIF version = 1.01 */ 1.267 + cinfo->JFIF_minor_version = 1; 1.268 + cinfo->density_unit = 0; /* Pixel size is unknown by default */ 1.269 + cinfo->X_density = 1; /* Pixel aspect ratio is square by default */ 1.270 + cinfo->Y_density = 1; 1.271 + 1.272 + /* Choose JPEG colorspace based on input space, set defaults accordingly */ 1.273 + 1.274 + jpeg_default_colorspace(cinfo); 1.275 +} 1.276 + 1.277 + 1.278 +/* 1.279 + * Select an appropriate JPEG colorspace for in_color_space. 1.280 + */ 1.281 + 1.282 +GLOBAL(void) 1.283 +jpeg_default_colorspace (j_compress_ptr cinfo) 1.284 +{ 1.285 + switch (cinfo->in_color_space) { 1.286 + case JCS_GRAYSCALE: 1.287 + jpeg_set_colorspace(cinfo, JCS_GRAYSCALE); 1.288 + break; 1.289 + case JCS_RGB: 1.290 + case JCS_EXT_RGB: 1.291 + case JCS_EXT_RGBX: 1.292 + case JCS_EXT_BGR: 1.293 + case JCS_EXT_BGRX: 1.294 + case JCS_EXT_XBGR: 1.295 + case JCS_EXT_XRGB: 1.296 + case JCS_EXT_RGBA: 1.297 + case JCS_EXT_BGRA: 1.298 + case JCS_EXT_ABGR: 1.299 + case JCS_EXT_ARGB: 1.300 + jpeg_set_colorspace(cinfo, JCS_YCbCr); 1.301 + break; 1.302 + case JCS_YCbCr: 1.303 + jpeg_set_colorspace(cinfo, JCS_YCbCr); 1.304 + break; 1.305 + case JCS_CMYK: 1.306 + jpeg_set_colorspace(cinfo, JCS_CMYK); /* By default, no translation */ 1.307 + break; 1.308 + case JCS_YCCK: 1.309 + jpeg_set_colorspace(cinfo, JCS_YCCK); 1.310 + break; 1.311 + case JCS_UNKNOWN: 1.312 + jpeg_set_colorspace(cinfo, JCS_UNKNOWN); 1.313 + break; 1.314 + default: 1.315 + ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); 1.316 + } 1.317 +} 1.318 + 1.319 + 1.320 +/* 1.321 + * Set the JPEG colorspace, and choose colorspace-dependent default values. 1.322 + */ 1.323 + 1.324 +GLOBAL(void) 1.325 +jpeg_set_colorspace (j_compress_ptr cinfo, J_COLOR_SPACE colorspace) 1.326 +{ 1.327 + jpeg_component_info * compptr; 1.328 + int ci; 1.329 + 1.330 +#define SET_COMP(index,id,hsamp,vsamp,quant,dctbl,actbl) \ 1.331 + (compptr = &cinfo->comp_info[index], \ 1.332 + compptr->component_id = (id), \ 1.333 + compptr->h_samp_factor = (hsamp), \ 1.334 + compptr->v_samp_factor = (vsamp), \ 1.335 + compptr->quant_tbl_no = (quant), \ 1.336 + compptr->dc_tbl_no = (dctbl), \ 1.337 + compptr->ac_tbl_no = (actbl) ) 1.338 + 1.339 + /* Safety check to ensure start_compress not called yet. */ 1.340 + if (cinfo->global_state != CSTATE_START) 1.341 + ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); 1.342 + 1.343 + /* For all colorspaces, we use Q and Huff tables 0 for luminance components, 1.344 + * tables 1 for chrominance components. 1.345 + */ 1.346 + 1.347 + cinfo->jpeg_color_space = colorspace; 1.348 + 1.349 + cinfo->write_JFIF_header = FALSE; /* No marker for non-JFIF colorspaces */ 1.350 + cinfo->write_Adobe_marker = FALSE; /* write no Adobe marker by default */ 1.351 + 1.352 + switch (colorspace) { 1.353 + case JCS_GRAYSCALE: 1.354 + cinfo->write_JFIF_header = TRUE; /* Write a JFIF marker */ 1.355 + cinfo->num_components = 1; 1.356 + /* JFIF specifies component ID 1 */ 1.357 + SET_COMP(0, 1, 1,1, 0, 0,0); 1.358 + break; 1.359 + case JCS_RGB: 1.360 + cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag RGB */ 1.361 + cinfo->num_components = 3; 1.362 + SET_COMP(0, 0x52 /* 'R' */, 1,1, 0, 0,0); 1.363 + SET_COMP(1, 0x47 /* 'G' */, 1,1, 0, 0,0); 1.364 + SET_COMP(2, 0x42 /* 'B' */, 1,1, 0, 0,0); 1.365 + break; 1.366 + case JCS_YCbCr: 1.367 + cinfo->write_JFIF_header = TRUE; /* Write a JFIF marker */ 1.368 + cinfo->num_components = 3; 1.369 + /* JFIF specifies component IDs 1,2,3 */ 1.370 + /* We default to 2x2 subsamples of chrominance */ 1.371 + SET_COMP(0, 1, 2,2, 0, 0,0); 1.372 + SET_COMP(1, 2, 1,1, 1, 1,1); 1.373 + SET_COMP(2, 3, 1,1, 1, 1,1); 1.374 + break; 1.375 + case JCS_CMYK: 1.376 + cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag CMYK */ 1.377 + cinfo->num_components = 4; 1.378 + SET_COMP(0, 0x43 /* 'C' */, 1,1, 0, 0,0); 1.379 + SET_COMP(1, 0x4D /* 'M' */, 1,1, 0, 0,0); 1.380 + SET_COMP(2, 0x59 /* 'Y' */, 1,1, 0, 0,0); 1.381 + SET_COMP(3, 0x4B /* 'K' */, 1,1, 0, 0,0); 1.382 + break; 1.383 + case JCS_YCCK: 1.384 + cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag YCCK */ 1.385 + cinfo->num_components = 4; 1.386 + SET_COMP(0, 1, 2,2, 0, 0,0); 1.387 + SET_COMP(1, 2, 1,1, 1, 1,1); 1.388 + SET_COMP(2, 3, 1,1, 1, 1,1); 1.389 + SET_COMP(3, 4, 2,2, 0, 0,0); 1.390 + break; 1.391 + case JCS_UNKNOWN: 1.392 + cinfo->num_components = cinfo->input_components; 1.393 + if (cinfo->num_components < 1 || cinfo->num_components > MAX_COMPONENTS) 1.394 + ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components, 1.395 + MAX_COMPONENTS); 1.396 + for (ci = 0; ci < cinfo->num_components; ci++) { 1.397 + SET_COMP(ci, ci, 1,1, 0, 0,0); 1.398 + } 1.399 + break; 1.400 + default: 1.401 + ERREXIT(cinfo, JERR_BAD_J_COLORSPACE); 1.402 + } 1.403 +} 1.404 + 1.405 + 1.406 +#ifdef C_PROGRESSIVE_SUPPORTED 1.407 + 1.408 +LOCAL(jpeg_scan_info *) 1.409 +fill_a_scan (jpeg_scan_info * scanptr, int ci, 1.410 + int Ss, int Se, int Ah, int Al) 1.411 +/* Support routine: generate one scan for specified component */ 1.412 +{ 1.413 + scanptr->comps_in_scan = 1; 1.414 + scanptr->component_index[0] = ci; 1.415 + scanptr->Ss = Ss; 1.416 + scanptr->Se = Se; 1.417 + scanptr->Ah = Ah; 1.418 + scanptr->Al = Al; 1.419 + scanptr++; 1.420 + return scanptr; 1.421 +} 1.422 + 1.423 +LOCAL(jpeg_scan_info *) 1.424 +fill_scans (jpeg_scan_info * scanptr, int ncomps, 1.425 + int Ss, int Se, int Ah, int Al) 1.426 +/* Support routine: generate one scan for each component */ 1.427 +{ 1.428 + int ci; 1.429 + 1.430 + for (ci = 0; ci < ncomps; ci++) { 1.431 + scanptr->comps_in_scan = 1; 1.432 + scanptr->component_index[0] = ci; 1.433 + scanptr->Ss = Ss; 1.434 + scanptr->Se = Se; 1.435 + scanptr->Ah = Ah; 1.436 + scanptr->Al = Al; 1.437 + scanptr++; 1.438 + } 1.439 + return scanptr; 1.440 +} 1.441 + 1.442 +LOCAL(jpeg_scan_info *) 1.443 +fill_dc_scans (jpeg_scan_info * scanptr, int ncomps, int Ah, int Al) 1.444 +/* Support routine: generate interleaved DC scan if possible, else N scans */ 1.445 +{ 1.446 + int ci; 1.447 + 1.448 + if (ncomps <= MAX_COMPS_IN_SCAN) { 1.449 + /* Single interleaved DC scan */ 1.450 + scanptr->comps_in_scan = ncomps; 1.451 + for (ci = 0; ci < ncomps; ci++) 1.452 + scanptr->component_index[ci] = ci; 1.453 + scanptr->Ss = scanptr->Se = 0; 1.454 + scanptr->Ah = Ah; 1.455 + scanptr->Al = Al; 1.456 + scanptr++; 1.457 + } else { 1.458 + /* Noninterleaved DC scan for each component */ 1.459 + scanptr = fill_scans(scanptr, ncomps, 0, 0, Ah, Al); 1.460 + } 1.461 + return scanptr; 1.462 +} 1.463 + 1.464 + 1.465 +/* 1.466 + * Create a recommended progressive-JPEG script. 1.467 + * cinfo->num_components and cinfo->jpeg_color_space must be correct. 1.468 + */ 1.469 + 1.470 +GLOBAL(void) 1.471 +jpeg_simple_progression (j_compress_ptr cinfo) 1.472 +{ 1.473 + int ncomps = cinfo->num_components; 1.474 + int nscans; 1.475 + jpeg_scan_info * scanptr; 1.476 + 1.477 + /* Safety check to ensure start_compress not called yet. */ 1.478 + if (cinfo->global_state != CSTATE_START) 1.479 + ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); 1.480 + 1.481 + /* Figure space needed for script. Calculation must match code below! */ 1.482 + if (ncomps == 3 && cinfo->jpeg_color_space == JCS_YCbCr) { 1.483 + /* Custom script for YCbCr color images. */ 1.484 + nscans = 10; 1.485 + } else { 1.486 + /* All-purpose script for other color spaces. */ 1.487 + if (ncomps > MAX_COMPS_IN_SCAN) 1.488 + nscans = 6 * ncomps; /* 2 DC + 4 AC scans per component */ 1.489 + else 1.490 + nscans = 2 + 4 * ncomps; /* 2 DC scans; 4 AC scans per component */ 1.491 + } 1.492 + 1.493 + /* Allocate space for script. 1.494 + * We need to put it in the permanent pool in case the application performs 1.495 + * multiple compressions without changing the settings. To avoid a memory 1.496 + * leak if jpeg_simple_progression is called repeatedly for the same JPEG 1.497 + * object, we try to re-use previously allocated space, and we allocate 1.498 + * enough space to handle YCbCr even if initially asked for grayscale. 1.499 + */ 1.500 + if (cinfo->script_space == NULL || cinfo->script_space_size < nscans) { 1.501 + cinfo->script_space_size = MAX(nscans, 10); 1.502 + cinfo->script_space = (jpeg_scan_info *) 1.503 + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT, 1.504 + cinfo->script_space_size * SIZEOF(jpeg_scan_info)); 1.505 + } 1.506 + scanptr = cinfo->script_space; 1.507 + cinfo->scan_info = scanptr; 1.508 + cinfo->num_scans = nscans; 1.509 + 1.510 + if (ncomps == 3 && cinfo->jpeg_color_space == JCS_YCbCr) { 1.511 + /* Custom script for YCbCr color images. */ 1.512 + /* Initial DC scan */ 1.513 + scanptr = fill_dc_scans(scanptr, ncomps, 0, 1); 1.514 + /* Initial AC scan: get some luma data out in a hurry */ 1.515 + scanptr = fill_a_scan(scanptr, 0, 1, 5, 0, 2); 1.516 + /* Chroma data is too small to be worth expending many scans on */ 1.517 + scanptr = fill_a_scan(scanptr, 2, 1, 63, 0, 1); 1.518 + scanptr = fill_a_scan(scanptr, 1, 1, 63, 0, 1); 1.519 + /* Complete spectral selection for luma AC */ 1.520 + scanptr = fill_a_scan(scanptr, 0, 6, 63, 0, 2); 1.521 + /* Refine next bit of luma AC */ 1.522 + scanptr = fill_a_scan(scanptr, 0, 1, 63, 2, 1); 1.523 + /* Finish DC successive approximation */ 1.524 + scanptr = fill_dc_scans(scanptr, ncomps, 1, 0); 1.525 + /* Finish AC successive approximation */ 1.526 + scanptr = fill_a_scan(scanptr, 2, 1, 63, 1, 0); 1.527 + scanptr = fill_a_scan(scanptr, 1, 1, 63, 1, 0); 1.528 + /* Luma bottom bit comes last since it's usually largest scan */ 1.529 + scanptr = fill_a_scan(scanptr, 0, 1, 63, 1, 0); 1.530 + } else { 1.531 + /* All-purpose script for other color spaces. */ 1.532 + /* Successive approximation first pass */ 1.533 + scanptr = fill_dc_scans(scanptr, ncomps, 0, 1); 1.534 + scanptr = fill_scans(scanptr, ncomps, 1, 5, 0, 2); 1.535 + scanptr = fill_scans(scanptr, ncomps, 6, 63, 0, 2); 1.536 + /* Successive approximation second pass */ 1.537 + scanptr = fill_scans(scanptr, ncomps, 1, 63, 2, 1); 1.538 + /* Successive approximation final pass */ 1.539 + scanptr = fill_dc_scans(scanptr, ncomps, 1, 0); 1.540 + scanptr = fill_scans(scanptr, ncomps, 1, 63, 1, 0); 1.541 + } 1.542 +} 1.543 + 1.544 +#endif /* C_PROGRESSIVE_SUPPORTED */