aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/irrlicht-1.8/source/Irrlicht/jpeglib/jdmaster.c
diff options
context:
space:
mode:
authorDavid Walter Seikel2013-01-13 18:54:10 +1000
committerDavid Walter Seikel2013-01-13 18:54:10 +1000
commit959831f4ef5a3e797f576c3de08cd65032c997ad (patch)
treee7351908be5995f0b325b2ebeaa02d5a34b82583 /libraries/irrlicht-1.8/source/Irrlicht/jpeglib/jdmaster.c
parentAdd info about changes to Irrlicht. (diff)
downloadSledjHamr-959831f4ef5a3e797f576c3de08cd65032c997ad.zip
SledjHamr-959831f4ef5a3e797f576c3de08cd65032c997ad.tar.gz
SledjHamr-959831f4ef5a3e797f576c3de08cd65032c997ad.tar.bz2
SledjHamr-959831f4ef5a3e797f576c3de08cd65032c997ad.tar.xz
Remove damned ancient DOS line endings from Irrlicht. Hopefully I did not go overboard.
Diffstat (limited to 'libraries/irrlicht-1.8/source/Irrlicht/jpeglib/jdmaster.c')
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/jpeglib/jdmaster.c1062
1 files changed, 531 insertions, 531 deletions
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/jpeglib/jdmaster.c b/libraries/irrlicht-1.8/source/Irrlicht/jpeglib/jdmaster.c
index 03d4dd0..fef72a2 100644
--- a/libraries/irrlicht-1.8/source/Irrlicht/jpeglib/jdmaster.c
+++ b/libraries/irrlicht-1.8/source/Irrlicht/jpeglib/jdmaster.c
@@ -1,531 +1,531 @@
1/* 1/*
2 * jdmaster.c 2 * jdmaster.c
3 * 3 *
4 * Copyright (C) 1991-1997, Thomas G. Lane. 4 * Copyright (C) 1991-1997, Thomas G. Lane.
5 * Modified 2002-2011 by Guido Vollbeding. 5 * Modified 2002-2011 by Guido Vollbeding.
6 * This file is part of the Independent JPEG Group's software. 6 * This file is part of the Independent JPEG Group's software.
7 * For conditions of distribution and use, see the accompanying README file. 7 * For conditions of distribution and use, see the accompanying README file.
8 * 8 *
9 * This file contains master control logic for the JPEG decompressor. 9 * This file contains master control logic for the JPEG decompressor.
10 * These routines are concerned with selecting the modules to be executed 10 * These routines are concerned with selecting the modules to be executed
11 * and with determining the number of passes and the work to be done in each 11 * and with determining the number of passes and the work to be done in each
12 * pass. 12 * pass.
13 */ 13 */
14 14
15#define JPEG_INTERNALS 15#define JPEG_INTERNALS
16#include "jinclude.h" 16#include "jinclude.h"
17#include "jpeglib.h" 17#include "jpeglib.h"
18 18
19 19
20/* Private state */ 20/* Private state */
21 21
22typedef struct { 22typedef struct {
23 struct jpeg_decomp_master pub; /* public fields */ 23 struct jpeg_decomp_master pub; /* public fields */
24 24
25 int pass_number; /* # of passes completed */ 25 int pass_number; /* # of passes completed */
26 26
27 boolean using_merged_upsample; /* TRUE if using merged upsample/cconvert */ 27 boolean using_merged_upsample; /* TRUE if using merged upsample/cconvert */
28 28
29 /* Saved references to initialized quantizer modules, 29 /* Saved references to initialized quantizer modules,
30 * in case we need to switch modes. 30 * in case we need to switch modes.
31 */ 31 */
32 struct jpeg_color_quantizer * quantizer_1pass; 32 struct jpeg_color_quantizer * quantizer_1pass;
33 struct jpeg_color_quantizer * quantizer_2pass; 33 struct jpeg_color_quantizer * quantizer_2pass;
34} my_decomp_master; 34} my_decomp_master;
35 35
36typedef my_decomp_master * my_master_ptr; 36typedef my_decomp_master * my_master_ptr;
37 37
38 38
39/* 39/*
40 * Determine whether merged upsample/color conversion should be used. 40 * Determine whether merged upsample/color conversion should be used.
41 * CRUCIAL: this must match the actual capabilities of jdmerge.c! 41 * CRUCIAL: this must match the actual capabilities of jdmerge.c!
42 */ 42 */
43 43
44LOCAL(boolean) 44LOCAL(boolean)
45use_merged_upsample (j_decompress_ptr cinfo) 45use_merged_upsample (j_decompress_ptr cinfo)
46{ 46{
47#ifdef UPSAMPLE_MERGING_SUPPORTED 47#ifdef UPSAMPLE_MERGING_SUPPORTED
48 /* Merging is the equivalent of plain box-filter upsampling */ 48 /* Merging is the equivalent of plain box-filter upsampling */
49 if (cinfo->do_fancy_upsampling || cinfo->CCIR601_sampling) 49 if (cinfo->do_fancy_upsampling || cinfo->CCIR601_sampling)
50 return FALSE; 50 return FALSE;
51 /* jdmerge.c only supports YCC=>RGB color conversion */ 51 /* jdmerge.c only supports YCC=>RGB color conversion */
52 if (cinfo->jpeg_color_space != JCS_YCbCr || cinfo->num_components != 3 || 52 if (cinfo->jpeg_color_space != JCS_YCbCr || cinfo->num_components != 3 ||
53 cinfo->out_color_space != JCS_RGB || 53 cinfo->out_color_space != JCS_RGB ||
54 cinfo->out_color_components != RGB_PIXELSIZE) 54 cinfo->out_color_components != RGB_PIXELSIZE)
55 return FALSE; 55 return FALSE;
56 /* and it only handles 2h1v or 2h2v sampling ratios */ 56 /* and it only handles 2h1v or 2h2v sampling ratios */
57 if (cinfo->comp_info[0].h_samp_factor != 2 || 57 if (cinfo->comp_info[0].h_samp_factor != 2 ||
58 cinfo->comp_info[1].h_samp_factor != 1 || 58 cinfo->comp_info[1].h_samp_factor != 1 ||
59 cinfo->comp_info[2].h_samp_factor != 1 || 59 cinfo->comp_info[2].h_samp_factor != 1 ||
60 cinfo->comp_info[0].v_samp_factor > 2 || 60 cinfo->comp_info[0].v_samp_factor > 2 ||
61 cinfo->comp_info[1].v_samp_factor != 1 || 61 cinfo->comp_info[1].v_samp_factor != 1 ||
62 cinfo->comp_info[2].v_samp_factor != 1) 62 cinfo->comp_info[2].v_samp_factor != 1)
63 return FALSE; 63 return FALSE;
64 /* furthermore, it doesn't work if we've scaled the IDCTs differently */ 64 /* furthermore, it doesn't work if we've scaled the IDCTs differently */
65 if (cinfo->comp_info[0].DCT_h_scaled_size != cinfo->min_DCT_h_scaled_size || 65 if (cinfo->comp_info[0].DCT_h_scaled_size != cinfo->min_DCT_h_scaled_size ||
66 cinfo->comp_info[1].DCT_h_scaled_size != cinfo->min_DCT_h_scaled_size || 66 cinfo->comp_info[1].DCT_h_scaled_size != cinfo->min_DCT_h_scaled_size ||
67 cinfo->comp_info[2].DCT_h_scaled_size != cinfo->min_DCT_h_scaled_size || 67 cinfo->comp_info[2].DCT_h_scaled_size != cinfo->min_DCT_h_scaled_size ||
68 cinfo->comp_info[0].DCT_v_scaled_size != cinfo->min_DCT_v_scaled_size || 68 cinfo->comp_info[0].DCT_v_scaled_size != cinfo->min_DCT_v_scaled_size ||
69 cinfo->comp_info[1].DCT_v_scaled_size != cinfo->min_DCT_v_scaled_size || 69 cinfo->comp_info[1].DCT_v_scaled_size != cinfo->min_DCT_v_scaled_size ||
70 cinfo->comp_info[2].DCT_v_scaled_size != cinfo->min_DCT_v_scaled_size) 70 cinfo->comp_info[2].DCT_v_scaled_size != cinfo->min_DCT_v_scaled_size)
71 return FALSE; 71 return FALSE;
72 /* ??? also need to test for upsample-time rescaling, when & if supported */ 72 /* ??? also need to test for upsample-time rescaling, when & if supported */
73 return TRUE; /* by golly, it'll work... */ 73 return TRUE; /* by golly, it'll work... */
74#else 74#else
75 return FALSE; 75 return FALSE;
76#endif 76#endif
77} 77}
78 78
79 79
80/* 80/*
81 * Compute output image dimensions and related values. 81 * Compute output image dimensions and related values.
82 * NOTE: this is exported for possible use by application. 82 * NOTE: this is exported for possible use by application.
83 * Hence it mustn't do anything that can't be done twice. 83 * Hence it mustn't do anything that can't be done twice.
84 * Also note that it may be called before the master module is initialized! 84 * Also note that it may be called before the master module is initialized!
85 */ 85 */
86 86
87GLOBAL(void) 87GLOBAL(void)
88jpeg_calc_output_dimensions (j_decompress_ptr cinfo) 88jpeg_calc_output_dimensions (j_decompress_ptr cinfo)
89/* Do computations that are needed before master selection phase. 89/* Do computations that are needed before master selection phase.
90 * This function is used for full decompression. 90 * This function is used for full decompression.
91 */ 91 */
92{ 92{
93#ifdef IDCT_SCALING_SUPPORTED 93#ifdef IDCT_SCALING_SUPPORTED
94 int ci; 94 int ci;
95 jpeg_component_info *compptr; 95 jpeg_component_info *compptr;
96#endif 96#endif
97 97
98 /* Prevent application from calling me at wrong times */ 98 /* Prevent application from calling me at wrong times */
99 if (cinfo->global_state != DSTATE_READY) 99 if (cinfo->global_state != DSTATE_READY)
100 ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); 100 ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
101 101
102 /* Compute core output image dimensions and DCT scaling choices. */ 102 /* Compute core output image dimensions and DCT scaling choices. */
103 jpeg_core_output_dimensions(cinfo); 103 jpeg_core_output_dimensions(cinfo);
104 104
105#ifdef IDCT_SCALING_SUPPORTED 105#ifdef IDCT_SCALING_SUPPORTED
106 106
107 /* In selecting the actual DCT scaling for each component, we try to 107 /* In selecting the actual DCT scaling for each component, we try to
108 * scale up the chroma components via IDCT scaling rather than upsampling. 108 * scale up the chroma components via IDCT scaling rather than upsampling.
109 * This saves time if the upsampler gets to use 1:1 scaling. 109 * This saves time if the upsampler gets to use 1:1 scaling.
110 * Note this code adapts subsampling ratios which are powers of 2. 110 * Note this code adapts subsampling ratios which are powers of 2.
111 */ 111 */
112 for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; 112 for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
113 ci++, compptr++) { 113 ci++, compptr++) {
114 int ssize = 1; 114 int ssize = 1;
115 while (cinfo->min_DCT_h_scaled_size * ssize <= 115 while (cinfo->min_DCT_h_scaled_size * ssize <=
116 (cinfo->do_fancy_upsampling ? DCTSIZE : DCTSIZE / 2) && 116 (cinfo->do_fancy_upsampling ? DCTSIZE : DCTSIZE / 2) &&
117 (cinfo->max_h_samp_factor % (compptr->h_samp_factor * ssize * 2)) == 0) { 117 (cinfo->max_h_samp_factor % (compptr->h_samp_factor * ssize * 2)) == 0) {
118 ssize = ssize * 2; 118 ssize = ssize * 2;
119 } 119 }
120 compptr->DCT_h_scaled_size = cinfo->min_DCT_h_scaled_size * ssize; 120 compptr->DCT_h_scaled_size = cinfo->min_DCT_h_scaled_size * ssize;
121 ssize = 1; 121 ssize = 1;
122 while (cinfo->min_DCT_v_scaled_size * ssize <= 122 while (cinfo->min_DCT_v_scaled_size * ssize <=
123 (cinfo->do_fancy_upsampling ? DCTSIZE : DCTSIZE / 2) && 123 (cinfo->do_fancy_upsampling ? DCTSIZE : DCTSIZE / 2) &&
124 (cinfo->max_v_samp_factor % (compptr->v_samp_factor * ssize * 2)) == 0) { 124 (cinfo->max_v_samp_factor % (compptr->v_samp_factor * ssize * 2)) == 0) {
125 ssize = ssize * 2; 125 ssize = ssize * 2;
126 } 126 }
127 compptr->DCT_v_scaled_size = cinfo->min_DCT_v_scaled_size * ssize; 127 compptr->DCT_v_scaled_size = cinfo->min_DCT_v_scaled_size * ssize;
128 128
129 /* We don't support IDCT ratios larger than 2. */ 129 /* We don't support IDCT ratios larger than 2. */
130 if (compptr->DCT_h_scaled_size > compptr->DCT_v_scaled_size * 2) 130 if (compptr->DCT_h_scaled_size > compptr->DCT_v_scaled_size * 2)
131 compptr->DCT_h_scaled_size = compptr->DCT_v_scaled_size * 2; 131 compptr->DCT_h_scaled_size = compptr->DCT_v_scaled_size * 2;
132 else if (compptr->DCT_v_scaled_size > compptr->DCT_h_scaled_size * 2) 132 else if (compptr->DCT_v_scaled_size > compptr->DCT_h_scaled_size * 2)
133 compptr->DCT_v_scaled_size = compptr->DCT_h_scaled_size * 2; 133 compptr->DCT_v_scaled_size = compptr->DCT_h_scaled_size * 2;
134 } 134 }
135 135
136 /* Recompute downsampled dimensions of components; 136 /* Recompute downsampled dimensions of components;
137 * application needs to know these if using raw downsampled data. 137 * application needs to know these if using raw downsampled data.
138 */ 138 */
139 for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; 139 for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
140 ci++, compptr++) { 140 ci++, compptr++) {
141 /* Size in samples, after IDCT scaling */ 141 /* Size in samples, after IDCT scaling */
142 compptr->downsampled_width = (JDIMENSION) 142 compptr->downsampled_width = (JDIMENSION)
143 jdiv_round_up((long) cinfo->image_width * 143 jdiv_round_up((long) cinfo->image_width *
144 (long) (compptr->h_samp_factor * compptr->DCT_h_scaled_size), 144 (long) (compptr->h_samp_factor * compptr->DCT_h_scaled_size),
145 (long) (cinfo->max_h_samp_factor * cinfo->block_size)); 145 (long) (cinfo->max_h_samp_factor * cinfo->block_size));
146 compptr->downsampled_height = (JDIMENSION) 146 compptr->downsampled_height = (JDIMENSION)
147 jdiv_round_up((long) cinfo->image_height * 147 jdiv_round_up((long) cinfo->image_height *
148 (long) (compptr->v_samp_factor * compptr->DCT_v_scaled_size), 148 (long) (compptr->v_samp_factor * compptr->DCT_v_scaled_size),
149 (long) (cinfo->max_v_samp_factor * cinfo->block_size)); 149 (long) (cinfo->max_v_samp_factor * cinfo->block_size));
150 } 150 }
151 151
152#endif /* IDCT_SCALING_SUPPORTED */ 152#endif /* IDCT_SCALING_SUPPORTED */
153 153
154 /* Report number of components in selected colorspace. */ 154 /* Report number of components in selected colorspace. */
155 /* Probably this should be in the color conversion module... */ 155 /* Probably this should be in the color conversion module... */
156 switch (cinfo->out_color_space) { 156 switch (cinfo->out_color_space) {
157 case JCS_GRAYSCALE: 157 case JCS_GRAYSCALE:
158 cinfo->out_color_components = 1; 158 cinfo->out_color_components = 1;
159 break; 159 break;
160 case JCS_RGB: 160 case JCS_RGB:
161 cinfo->out_color_components = RGB_PIXELSIZE; 161 cinfo->out_color_components = RGB_PIXELSIZE;
162 break; 162 break;
163 case JCS_YCbCr: 163 case JCS_YCbCr:
164 cinfo->out_color_components = 3; 164 cinfo->out_color_components = 3;
165 break; 165 break;
166 case JCS_CMYK: 166 case JCS_CMYK:
167 case JCS_YCCK: 167 case JCS_YCCK:
168 cinfo->out_color_components = 4; 168 cinfo->out_color_components = 4;
169 break; 169 break;
170 default: /* else must be same colorspace as in file */ 170 default: /* else must be same colorspace as in file */
171 cinfo->out_color_components = cinfo->num_components; 171 cinfo->out_color_components = cinfo->num_components;
172 break; 172 break;
173 } 173 }
174 cinfo->output_components = (cinfo->quantize_colors ? 1 : 174 cinfo->output_components = (cinfo->quantize_colors ? 1 :
175 cinfo->out_color_components); 175 cinfo->out_color_components);
176 176
177 /* See if upsampler will want to emit more than one row at a time */ 177 /* See if upsampler will want to emit more than one row at a time */
178 if (use_merged_upsample(cinfo)) 178 if (use_merged_upsample(cinfo))
179 cinfo->rec_outbuf_height = cinfo->max_v_samp_factor; 179 cinfo->rec_outbuf_height = cinfo->max_v_samp_factor;
180 else 180 else
181 cinfo->rec_outbuf_height = 1; 181 cinfo->rec_outbuf_height = 1;
182} 182}
183 183
184 184
185/* 185/*
186 * Several decompression processes need to range-limit values to the range 186 * Several decompression processes need to range-limit values to the range
187 * 0..MAXJSAMPLE; the input value may fall somewhat outside this range 187 * 0..MAXJSAMPLE; the input value may fall somewhat outside this range
188 * due to noise introduced by quantization, roundoff error, etc. These 188 * due to noise introduced by quantization, roundoff error, etc. These
189 * processes are inner loops and need to be as fast as possible. On most 189 * processes are inner loops and need to be as fast as possible. On most
190 * machines, particularly CPUs with pipelines or instruction prefetch, 190 * machines, particularly CPUs with pipelines or instruction prefetch,
191 * a (subscript-check-less) C table lookup 191 * a (subscript-check-less) C table lookup
192 * x = sample_range_limit[x]; 192 * x = sample_range_limit[x];
193 * is faster than explicit tests 193 * is faster than explicit tests
194 * if (x < 0) x = 0; 194 * if (x < 0) x = 0;
195 * else if (x > MAXJSAMPLE) x = MAXJSAMPLE; 195 * else if (x > MAXJSAMPLE) x = MAXJSAMPLE;
196 * These processes all use a common table prepared by the routine below. 196 * These processes all use a common table prepared by the routine below.
197 * 197 *
198 * For most steps we can mathematically guarantee that the initial value 198 * For most steps we can mathematically guarantee that the initial value
199 * of x is within MAXJSAMPLE+1 of the legal range, so a table running from 199 * of x is within MAXJSAMPLE+1 of the legal range, so a table running from
200 * -(MAXJSAMPLE+1) to 2*MAXJSAMPLE+1 is sufficient. But for the initial 200 * -(MAXJSAMPLE+1) to 2*MAXJSAMPLE+1 is sufficient. But for the initial
201 * limiting step (just after the IDCT), a wildly out-of-range value is 201 * limiting step (just after the IDCT), a wildly out-of-range value is
202 * possible if the input data is corrupt. To avoid any chance of indexing 202 * possible if the input data is corrupt. To avoid any chance of indexing
203 * off the end of memory and getting a bad-pointer trap, we perform the 203 * off the end of memory and getting a bad-pointer trap, we perform the
204 * post-IDCT limiting thus: 204 * post-IDCT limiting thus:
205 * x = range_limit[x & MASK]; 205 * x = range_limit[x & MASK];
206 * where MASK is 2 bits wider than legal sample data, ie 10 bits for 8-bit 206 * where MASK is 2 bits wider than legal sample data, ie 10 bits for 8-bit
207 * samples. Under normal circumstances this is more than enough range and 207 * samples. Under normal circumstances this is more than enough range and
208 * a correct output will be generated; with bogus input data the mask will 208 * a correct output will be generated; with bogus input data the mask will
209 * cause wraparound, and we will safely generate a bogus-but-in-range output. 209 * cause wraparound, and we will safely generate a bogus-but-in-range output.
210 * For the post-IDCT step, we want to convert the data from signed to unsigned 210 * For the post-IDCT step, we want to convert the data from signed to unsigned
211 * representation by adding CENTERJSAMPLE at the same time that we limit it. 211 * representation by adding CENTERJSAMPLE at the same time that we limit it.
212 * So the post-IDCT limiting table ends up looking like this: 212 * So the post-IDCT limiting table ends up looking like this:
213 * CENTERJSAMPLE,CENTERJSAMPLE+1,...,MAXJSAMPLE, 213 * CENTERJSAMPLE,CENTERJSAMPLE+1,...,MAXJSAMPLE,
214 * MAXJSAMPLE (repeat 2*(MAXJSAMPLE+1)-CENTERJSAMPLE times), 214 * MAXJSAMPLE (repeat 2*(MAXJSAMPLE+1)-CENTERJSAMPLE times),
215 * 0 (repeat 2*(MAXJSAMPLE+1)-CENTERJSAMPLE times), 215 * 0 (repeat 2*(MAXJSAMPLE+1)-CENTERJSAMPLE times),
216 * 0,1,...,CENTERJSAMPLE-1 216 * 0,1,...,CENTERJSAMPLE-1
217 * Negative inputs select values from the upper half of the table after 217 * Negative inputs select values from the upper half of the table after
218 * masking. 218 * masking.
219 * 219 *
220 * We can save some space by overlapping the start of the post-IDCT table 220 * We can save some space by overlapping the start of the post-IDCT table
221 * with the simpler range limiting table. The post-IDCT table begins at 221 * with the simpler range limiting table. The post-IDCT table begins at
222 * sample_range_limit + CENTERJSAMPLE. 222 * sample_range_limit + CENTERJSAMPLE.
223 * 223 *
224 * Note that the table is allocated in near data space on PCs; it's small 224 * Note that the table is allocated in near data space on PCs; it's small
225 * enough and used often enough to justify this. 225 * enough and used often enough to justify this.
226 */ 226 */
227 227
228LOCAL(void) 228LOCAL(void)
229prepare_range_limit_table (j_decompress_ptr cinfo) 229prepare_range_limit_table (j_decompress_ptr cinfo)
230/* Allocate and fill in the sample_range_limit table */ 230/* Allocate and fill in the sample_range_limit table */
231{ 231{
232 JSAMPLE * table; 232 JSAMPLE * table;
233 int i; 233 int i;
234 234
235 table = (JSAMPLE *) 235 table = (JSAMPLE *)
236 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, 236 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
237 (5 * (MAXJSAMPLE+1) + CENTERJSAMPLE) * SIZEOF(JSAMPLE)); 237 (5 * (MAXJSAMPLE+1) + CENTERJSAMPLE) * SIZEOF(JSAMPLE));
238 table += (MAXJSAMPLE+1); /* allow negative subscripts of simple table */ 238 table += (MAXJSAMPLE+1); /* allow negative subscripts of simple table */
239 cinfo->sample_range_limit = table; 239 cinfo->sample_range_limit = table;
240 /* First segment of "simple" table: limit[x] = 0 for x < 0 */ 240 /* First segment of "simple" table: limit[x] = 0 for x < 0 */
241 MEMZERO(table - (MAXJSAMPLE+1), (MAXJSAMPLE+1) * SIZEOF(JSAMPLE)); 241 MEMZERO(table - (MAXJSAMPLE+1), (MAXJSAMPLE+1) * SIZEOF(JSAMPLE));
242 /* Main part of "simple" table: limit[x] = x */ 242 /* Main part of "simple" table: limit[x] = x */
243 for (i = 0; i <= MAXJSAMPLE; i++) 243 for (i = 0; i <= MAXJSAMPLE; i++)
244 table[i] = (JSAMPLE) i; 244 table[i] = (JSAMPLE) i;
245 table += CENTERJSAMPLE; /* Point to where post-IDCT table starts */ 245 table += CENTERJSAMPLE; /* Point to where post-IDCT table starts */
246 /* End of simple table, rest of first half of post-IDCT table */ 246 /* End of simple table, rest of first half of post-IDCT table */
247 for (i = CENTERJSAMPLE; i < 2*(MAXJSAMPLE+1); i++) 247 for (i = CENTERJSAMPLE; i < 2*(MAXJSAMPLE+1); i++)
248 table[i] = MAXJSAMPLE; 248 table[i] = MAXJSAMPLE;
249 /* Second half of post-IDCT table */ 249 /* Second half of post-IDCT table */
250 MEMZERO(table + (2 * (MAXJSAMPLE+1)), 250 MEMZERO(table + (2 * (MAXJSAMPLE+1)),
251 (2 * (MAXJSAMPLE+1) - CENTERJSAMPLE) * SIZEOF(JSAMPLE)); 251 (2 * (MAXJSAMPLE+1) - CENTERJSAMPLE) * SIZEOF(JSAMPLE));
252 MEMCOPY(table + (4 * (MAXJSAMPLE+1) - CENTERJSAMPLE), 252 MEMCOPY(table + (4 * (MAXJSAMPLE+1) - CENTERJSAMPLE),
253 cinfo->sample_range_limit, CENTERJSAMPLE * SIZEOF(JSAMPLE)); 253 cinfo->sample_range_limit, CENTERJSAMPLE * SIZEOF(JSAMPLE));
254} 254}
255 255
256 256
257/* 257/*
258 * Master selection of decompression modules. 258 * Master selection of decompression modules.
259 * This is done once at jpeg_start_decompress time. We determine 259 * This is done once at jpeg_start_decompress time. We determine
260 * which modules will be used and give them appropriate initialization calls. 260 * which modules will be used and give them appropriate initialization calls.
261 * We also initialize the decompressor input side to begin consuming data. 261 * We also initialize the decompressor input side to begin consuming data.
262 * 262 *
263 * Since jpeg_read_header has finished, we know what is in the SOF 263 * Since jpeg_read_header has finished, we know what is in the SOF
264 * and (first) SOS markers. We also have all the application parameter 264 * and (first) SOS markers. We also have all the application parameter
265 * settings. 265 * settings.
266 */ 266 */
267 267
268LOCAL(void) 268LOCAL(void)
269master_selection (j_decompress_ptr cinfo) 269master_selection (j_decompress_ptr cinfo)
270{ 270{
271 my_master_ptr master = (my_master_ptr) cinfo->master; 271 my_master_ptr master = (my_master_ptr) cinfo->master;
272 boolean use_c_buffer; 272 boolean use_c_buffer;
273 long samplesperrow; 273 long samplesperrow;
274 JDIMENSION jd_samplesperrow; 274 JDIMENSION jd_samplesperrow;
275 275
276 /* Initialize dimensions and other stuff */ 276 /* Initialize dimensions and other stuff */
277 jpeg_calc_output_dimensions(cinfo); 277 jpeg_calc_output_dimensions(cinfo);
278 prepare_range_limit_table(cinfo); 278 prepare_range_limit_table(cinfo);
279 279
280 /* Width of an output scanline must be representable as JDIMENSION. */ 280 /* Width of an output scanline must be representable as JDIMENSION. */
281 samplesperrow = (long) cinfo->output_width * (long) cinfo->out_color_components; 281 samplesperrow = (long) cinfo->output_width * (long) cinfo->out_color_components;
282 jd_samplesperrow = (JDIMENSION) samplesperrow; 282 jd_samplesperrow = (JDIMENSION) samplesperrow;
283 if ((long) jd_samplesperrow != samplesperrow) 283 if ((long) jd_samplesperrow != samplesperrow)
284 ERREXIT(cinfo, JERR_WIDTH_OVERFLOW); 284 ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
285 285
286 /* Initialize my private state */ 286 /* Initialize my private state */
287 master->pass_number = 0; 287 master->pass_number = 0;
288 master->using_merged_upsample = use_merged_upsample(cinfo); 288 master->using_merged_upsample = use_merged_upsample(cinfo);
289 289
290 /* Color quantizer selection */ 290 /* Color quantizer selection */
291 master->quantizer_1pass = NULL; 291 master->quantizer_1pass = NULL;
292 master->quantizer_2pass = NULL; 292 master->quantizer_2pass = NULL;
293 /* No mode changes if not using buffered-image mode. */ 293 /* No mode changes if not using buffered-image mode. */
294 if (! cinfo->quantize_colors || ! cinfo->buffered_image) { 294 if (! cinfo->quantize_colors || ! cinfo->buffered_image) {
295 cinfo->enable_1pass_quant = FALSE; 295 cinfo->enable_1pass_quant = FALSE;
296 cinfo->enable_external_quant = FALSE; 296 cinfo->enable_external_quant = FALSE;
297 cinfo->enable_2pass_quant = FALSE; 297 cinfo->enable_2pass_quant = FALSE;
298 } 298 }
299 if (cinfo->quantize_colors) { 299 if (cinfo->quantize_colors) {
300 if (cinfo->raw_data_out) 300 if (cinfo->raw_data_out)
301 ERREXIT(cinfo, JERR_NOTIMPL); 301 ERREXIT(cinfo, JERR_NOTIMPL);
302 /* 2-pass quantizer only works in 3-component color space. */ 302 /* 2-pass quantizer only works in 3-component color space. */
303 if (cinfo->out_color_components != 3) { 303 if (cinfo->out_color_components != 3) {
304 cinfo->enable_1pass_quant = TRUE; 304 cinfo->enable_1pass_quant = TRUE;
305 cinfo->enable_external_quant = FALSE; 305 cinfo->enable_external_quant = FALSE;
306 cinfo->enable_2pass_quant = FALSE; 306 cinfo->enable_2pass_quant = FALSE;
307 cinfo->colormap = NULL; 307 cinfo->colormap = NULL;
308 } else if (cinfo->colormap != NULL) { 308 } else if (cinfo->colormap != NULL) {
309 cinfo->enable_external_quant = TRUE; 309 cinfo->enable_external_quant = TRUE;
310 } else if (cinfo->two_pass_quantize) { 310 } else if (cinfo->two_pass_quantize) {
311 cinfo->enable_2pass_quant = TRUE; 311 cinfo->enable_2pass_quant = TRUE;
312 } else { 312 } else {
313 cinfo->enable_1pass_quant = TRUE; 313 cinfo->enable_1pass_quant = TRUE;
314 } 314 }
315 315
316 if (cinfo->enable_1pass_quant) { 316 if (cinfo->enable_1pass_quant) {
317#ifdef QUANT_1PASS_SUPPORTED 317#ifdef QUANT_1PASS_SUPPORTED
318 jinit_1pass_quantizer(cinfo); 318 jinit_1pass_quantizer(cinfo);
319 master->quantizer_1pass = cinfo->cquantize; 319 master->quantizer_1pass = cinfo->cquantize;
320#else 320#else
321 ERREXIT(cinfo, JERR_NOT_COMPILED); 321 ERREXIT(cinfo, JERR_NOT_COMPILED);
322#endif 322#endif
323 } 323 }
324 324
325 /* We use the 2-pass code to map to external colormaps. */ 325 /* We use the 2-pass code to map to external colormaps. */
326 if (cinfo->enable_2pass_quant || cinfo->enable_external_quant) { 326 if (cinfo->enable_2pass_quant || cinfo->enable_external_quant) {
327#ifdef QUANT_2PASS_SUPPORTED 327#ifdef QUANT_2PASS_SUPPORTED
328 jinit_2pass_quantizer(cinfo); 328 jinit_2pass_quantizer(cinfo);
329 master->quantizer_2pass = cinfo->cquantize; 329 master->quantizer_2pass = cinfo->cquantize;
330#else 330#else
331 ERREXIT(cinfo, JERR_NOT_COMPILED); 331 ERREXIT(cinfo, JERR_NOT_COMPILED);
332#endif 332#endif
333 } 333 }
334 /* If both quantizers are initialized, the 2-pass one is left active; 334 /* If both quantizers are initialized, the 2-pass one is left active;
335 * this is necessary for starting with quantization to an external map. 335 * this is necessary for starting with quantization to an external map.
336 */ 336 */
337 } 337 }
338 338
339 /* Post-processing: in particular, color conversion first */ 339 /* Post-processing: in particular, color conversion first */
340 if (! cinfo->raw_data_out) { 340 if (! cinfo->raw_data_out) {
341 if (master->using_merged_upsample) { 341 if (master->using_merged_upsample) {
342#ifdef UPSAMPLE_MERGING_SUPPORTED 342#ifdef UPSAMPLE_MERGING_SUPPORTED
343 jinit_merged_upsampler(cinfo); /* does color conversion too */ 343 jinit_merged_upsampler(cinfo); /* does color conversion too */
344#else 344#else
345 ERREXIT(cinfo, JERR_NOT_COMPILED); 345 ERREXIT(cinfo, JERR_NOT_COMPILED);
346#endif 346#endif
347 } else { 347 } else {
348 jinit_color_deconverter(cinfo); 348 jinit_color_deconverter(cinfo);
349 jinit_upsampler(cinfo); 349 jinit_upsampler(cinfo);
350 } 350 }
351 jinit_d_post_controller(cinfo, cinfo->enable_2pass_quant); 351 jinit_d_post_controller(cinfo, cinfo->enable_2pass_quant);
352 } 352 }
353 /* Inverse DCT */ 353 /* Inverse DCT */
354 jinit_inverse_dct(cinfo); 354 jinit_inverse_dct(cinfo);
355 /* Entropy decoding: either Huffman or arithmetic coding. */ 355 /* Entropy decoding: either Huffman or arithmetic coding. */
356 if (cinfo->arith_code) 356 if (cinfo->arith_code)
357 jinit_arith_decoder(cinfo); 357 jinit_arith_decoder(cinfo);
358 else { 358 else {
359 jinit_huff_decoder(cinfo); 359 jinit_huff_decoder(cinfo);
360 } 360 }
361 361
362 /* Initialize principal buffer controllers. */ 362 /* Initialize principal buffer controllers. */
363 use_c_buffer = cinfo->inputctl->has_multiple_scans || cinfo->buffered_image; 363 use_c_buffer = cinfo->inputctl->has_multiple_scans || cinfo->buffered_image;
364 jinit_d_coef_controller(cinfo, use_c_buffer); 364 jinit_d_coef_controller(cinfo, use_c_buffer);
365 365
366 if (! cinfo->raw_data_out) 366 if (! cinfo->raw_data_out)
367 jinit_d_main_controller(cinfo, FALSE /* never need full buffer here */); 367 jinit_d_main_controller(cinfo, FALSE /* never need full buffer here */);
368 368
369 /* We can now tell the memory manager to allocate virtual arrays. */ 369 /* We can now tell the memory manager to allocate virtual arrays. */
370 (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo); 370 (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo);
371 371
372 /* Initialize input side of decompressor to consume first scan. */ 372 /* Initialize input side of decompressor to consume first scan. */
373 (*cinfo->inputctl->start_input_pass) (cinfo); 373 (*cinfo->inputctl->start_input_pass) (cinfo);
374 374
375#ifdef D_MULTISCAN_FILES_SUPPORTED 375#ifdef D_MULTISCAN_FILES_SUPPORTED
376 /* If jpeg_start_decompress will read the whole file, initialize 376 /* If jpeg_start_decompress will read the whole file, initialize
377 * progress monitoring appropriately. The input step is counted 377 * progress monitoring appropriately. The input step is counted
378 * as one pass. 378 * as one pass.
379 */ 379 */
380 if (cinfo->progress != NULL && ! cinfo->buffered_image && 380 if (cinfo->progress != NULL && ! cinfo->buffered_image &&
381 cinfo->inputctl->has_multiple_scans) { 381 cinfo->inputctl->has_multiple_scans) {
382 int nscans; 382 int nscans;
383 /* Estimate number of scans to set pass_limit. */ 383 /* Estimate number of scans to set pass_limit. */
384 if (cinfo->progressive_mode) { 384 if (cinfo->progressive_mode) {
385 /* Arbitrarily estimate 2 interleaved DC scans + 3 AC scans/component. */ 385 /* Arbitrarily estimate 2 interleaved DC scans + 3 AC scans/component. */
386 nscans = 2 + 3 * cinfo->num_components; 386 nscans = 2 + 3 * cinfo->num_components;
387 } else { 387 } else {
388 /* For a nonprogressive multiscan file, estimate 1 scan per component. */ 388 /* For a nonprogressive multiscan file, estimate 1 scan per component. */
389 nscans = cinfo->num_components; 389 nscans = cinfo->num_components;
390 } 390 }
391 cinfo->progress->pass_counter = 0L; 391 cinfo->progress->pass_counter = 0L;
392 cinfo->progress->pass_limit = (long) cinfo->total_iMCU_rows * nscans; 392 cinfo->progress->pass_limit = (long) cinfo->total_iMCU_rows * nscans;
393 cinfo->progress->completed_passes = 0; 393 cinfo->progress->completed_passes = 0;
394 cinfo->progress->total_passes = (cinfo->enable_2pass_quant ? 3 : 2); 394 cinfo->progress->total_passes = (cinfo->enable_2pass_quant ? 3 : 2);
395 /* Count the input pass as done */ 395 /* Count the input pass as done */
396 master->pass_number++; 396 master->pass_number++;
397 } 397 }
398#endif /* D_MULTISCAN_FILES_SUPPORTED */ 398#endif /* D_MULTISCAN_FILES_SUPPORTED */
399} 399}
400 400
401 401
402/* 402/*
403 * Per-pass setup. 403 * Per-pass setup.
404 * This is called at the beginning of each output pass. We determine which 404 * This is called at the beginning of each output pass. We determine which
405 * modules will be active during this pass and give them appropriate 405 * modules will be active during this pass and give them appropriate
406 * start_pass calls. We also set is_dummy_pass to indicate whether this 406 * start_pass calls. We also set is_dummy_pass to indicate whether this
407 * is a "real" output pass or a dummy pass for color quantization. 407 * is a "real" output pass or a dummy pass for color quantization.
408 * (In the latter case, jdapistd.c will crank the pass to completion.) 408 * (In the latter case, jdapistd.c will crank the pass to completion.)
409 */ 409 */
410 410
411METHODDEF(void) 411METHODDEF(void)
412prepare_for_output_pass (j_decompress_ptr cinfo) 412prepare_for_output_pass (j_decompress_ptr cinfo)
413{ 413{
414 my_master_ptr master = (my_master_ptr) cinfo->master; 414 my_master_ptr master = (my_master_ptr) cinfo->master;
415 415
416 if (master->pub.is_dummy_pass) { 416 if (master->pub.is_dummy_pass) {
417#ifdef QUANT_2PASS_SUPPORTED 417#ifdef QUANT_2PASS_SUPPORTED
418 /* Final pass of 2-pass quantization */ 418 /* Final pass of 2-pass quantization */
419 master->pub.is_dummy_pass = FALSE; 419 master->pub.is_dummy_pass = FALSE;
420 (*cinfo->cquantize->start_pass) (cinfo, FALSE); 420 (*cinfo->cquantize->start_pass) (cinfo, FALSE);
421 (*cinfo->post->start_pass) (cinfo, JBUF_CRANK_DEST); 421 (*cinfo->post->start_pass) (cinfo, JBUF_CRANK_DEST);
422 (*cinfo->main->start_pass) (cinfo, JBUF_CRANK_DEST); 422 (*cinfo->main->start_pass) (cinfo, JBUF_CRANK_DEST);
423#else 423#else
424 ERREXIT(cinfo, JERR_NOT_COMPILED); 424 ERREXIT(cinfo, JERR_NOT_COMPILED);
425#endif /* QUANT_2PASS_SUPPORTED */ 425#endif /* QUANT_2PASS_SUPPORTED */
426 } else { 426 } else {
427 if (cinfo->quantize_colors && cinfo->colormap == NULL) { 427 if (cinfo->quantize_colors && cinfo->colormap == NULL) {
428 /* Select new quantization method */ 428 /* Select new quantization method */
429 if (cinfo->two_pass_quantize && cinfo->enable_2pass_quant) { 429 if (cinfo->two_pass_quantize && cinfo->enable_2pass_quant) {
430 cinfo->cquantize = master->quantizer_2pass; 430 cinfo->cquantize = master->quantizer_2pass;
431 master->pub.is_dummy_pass = TRUE; 431 master->pub.is_dummy_pass = TRUE;
432 } else if (cinfo->enable_1pass_quant) { 432 } else if (cinfo->enable_1pass_quant) {
433 cinfo->cquantize = master->quantizer_1pass; 433 cinfo->cquantize = master->quantizer_1pass;
434 } else { 434 } else {
435 ERREXIT(cinfo, JERR_MODE_CHANGE); 435 ERREXIT(cinfo, JERR_MODE_CHANGE);
436 } 436 }
437 } 437 }
438 (*cinfo->idct->start_pass) (cinfo); 438 (*cinfo->idct->start_pass) (cinfo);
439 (*cinfo->coef->start_output_pass) (cinfo); 439 (*cinfo->coef->start_output_pass) (cinfo);
440 if (! cinfo->raw_data_out) { 440 if (! cinfo->raw_data_out) {
441 if (! master->using_merged_upsample) 441 if (! master->using_merged_upsample)
442 (*cinfo->cconvert->start_pass) (cinfo); 442 (*cinfo->cconvert->start_pass) (cinfo);
443 (*cinfo->upsample->start_pass) (cinfo); 443 (*cinfo->upsample->start_pass) (cinfo);
444 if (cinfo->quantize_colors) 444 if (cinfo->quantize_colors)
445 (*cinfo->cquantize->start_pass) (cinfo, master->pub.is_dummy_pass); 445 (*cinfo->cquantize->start_pass) (cinfo, master->pub.is_dummy_pass);
446 (*cinfo->post->start_pass) (cinfo, 446 (*cinfo->post->start_pass) (cinfo,
447 (master->pub.is_dummy_pass ? JBUF_SAVE_AND_PASS : JBUF_PASS_THRU)); 447 (master->pub.is_dummy_pass ? JBUF_SAVE_AND_PASS : JBUF_PASS_THRU));
448 (*cinfo->main->start_pass) (cinfo, JBUF_PASS_THRU); 448 (*cinfo->main->start_pass) (cinfo, JBUF_PASS_THRU);
449 } 449 }
450 } 450 }
451 451
452 /* Set up progress monitor's pass info if present */ 452 /* Set up progress monitor's pass info if present */
453 if (cinfo->progress != NULL) { 453 if (cinfo->progress != NULL) {
454 cinfo->progress->completed_passes = master->pass_number; 454 cinfo->progress->completed_passes = master->pass_number;
455 cinfo->progress->total_passes = master->pass_number + 455 cinfo->progress->total_passes = master->pass_number +
456 (master->pub.is_dummy_pass ? 2 : 1); 456 (master->pub.is_dummy_pass ? 2 : 1);
457 /* In buffered-image mode, we assume one more output pass if EOI not 457 /* In buffered-image mode, we assume one more output pass if EOI not
458 * yet reached, but no more passes if EOI has been reached. 458 * yet reached, but no more passes if EOI has been reached.
459 */ 459 */
460 if (cinfo->buffered_image && ! cinfo->inputctl->eoi_reached) { 460 if (cinfo->buffered_image && ! cinfo->inputctl->eoi_reached) {
461 cinfo->progress->total_passes += (cinfo->enable_2pass_quant ? 2 : 1); 461 cinfo->progress->total_passes += (cinfo->enable_2pass_quant ? 2 : 1);
462 } 462 }
463 } 463 }
464} 464}
465 465
466 466
467/* 467/*
468 * Finish up at end of an output pass. 468 * Finish up at end of an output pass.
469 */ 469 */
470 470
471METHODDEF(void) 471METHODDEF(void)
472finish_output_pass (j_decompress_ptr cinfo) 472finish_output_pass (j_decompress_ptr cinfo)
473{ 473{
474 my_master_ptr master = (my_master_ptr) cinfo->master; 474 my_master_ptr master = (my_master_ptr) cinfo->master;
475 475
476 if (cinfo->quantize_colors) 476 if (cinfo->quantize_colors)
477 (*cinfo->cquantize->finish_pass) (cinfo); 477 (*cinfo->cquantize->finish_pass) (cinfo);
478 master->pass_number++; 478 master->pass_number++;
479} 479}
480 480
481 481
482#ifdef D_MULTISCAN_FILES_SUPPORTED 482#ifdef D_MULTISCAN_FILES_SUPPORTED
483 483
484/* 484/*
485 * Switch to a new external colormap between output passes. 485 * Switch to a new external colormap between output passes.
486 */ 486 */
487 487
488GLOBAL(void) 488GLOBAL(void)
489jpeg_new_colormap (j_decompress_ptr cinfo) 489jpeg_new_colormap (j_decompress_ptr cinfo)
490{ 490{
491 my_master_ptr master = (my_master_ptr) cinfo->master; 491 my_master_ptr master = (my_master_ptr) cinfo->master;
492 492
493 /* Prevent application from calling me at wrong times */ 493 /* Prevent application from calling me at wrong times */
494 if (cinfo->global_state != DSTATE_BUFIMAGE) 494 if (cinfo->global_state != DSTATE_BUFIMAGE)
495 ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); 495 ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
496 496
497 if (cinfo->quantize_colors && cinfo->enable_external_quant && 497 if (cinfo->quantize_colors && cinfo->enable_external_quant &&
498 cinfo->colormap != NULL) { 498 cinfo->colormap != NULL) {
499 /* Select 2-pass quantizer for external colormap use */ 499 /* Select 2-pass quantizer for external colormap use */
500 cinfo->cquantize = master->quantizer_2pass; 500 cinfo->cquantize = master->quantizer_2pass;
501 /* Notify quantizer of colormap change */ 501 /* Notify quantizer of colormap change */
502 (*cinfo->cquantize->new_color_map) (cinfo); 502 (*cinfo->cquantize->new_color_map) (cinfo);
503 master->pub.is_dummy_pass = FALSE; /* just in case */ 503 master->pub.is_dummy_pass = FALSE; /* just in case */
504 } else 504 } else
505 ERREXIT(cinfo, JERR_MODE_CHANGE); 505 ERREXIT(cinfo, JERR_MODE_CHANGE);
506} 506}
507 507
508#endif /* D_MULTISCAN_FILES_SUPPORTED */ 508#endif /* D_MULTISCAN_FILES_SUPPORTED */
509 509
510 510
511/* 511/*
512 * Initialize master decompression control and select active modules. 512 * Initialize master decompression control and select active modules.
513 * This is performed at the start of jpeg_start_decompress. 513 * This is performed at the start of jpeg_start_decompress.
514 */ 514 */
515 515
516GLOBAL(void) 516GLOBAL(void)
517jinit_master_decompress (j_decompress_ptr cinfo) 517jinit_master_decompress (j_decompress_ptr cinfo)
518{ 518{
519 my_master_ptr master; 519 my_master_ptr master;
520 520
521 master = (my_master_ptr) 521 master = (my_master_ptr)
522 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, 522 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
523 SIZEOF(my_decomp_master)); 523 SIZEOF(my_decomp_master));
524 cinfo->master = (struct jpeg_decomp_master *) master; 524 cinfo->master = (struct jpeg_decomp_master *) master;
525 master->pub.prepare_for_output_pass = prepare_for_output_pass; 525 master->pub.prepare_for_output_pass = prepare_for_output_pass;
526 master->pub.finish_output_pass = finish_output_pass; 526 master->pub.finish_output_pass = finish_output_pass;
527 527
528 master->pub.is_dummy_pass = FALSE; 528 master->pub.is_dummy_pass = FALSE;
529 529
530 master_selection(cinfo); 530 master_selection(cinfo);
531} 531}