aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/irrlicht-1.8/source/Irrlicht/jpeglib/jdinput.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/jdinput.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/jdinput.c')
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/jpeglib/jdinput.c1322
1 files changed, 661 insertions, 661 deletions
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/jpeglib/jdinput.c b/libraries/irrlicht-1.8/source/Irrlicht/jpeglib/jdinput.c
index 85e7e8f..c8333d3 100644
--- a/libraries/irrlicht-1.8/source/Irrlicht/jpeglib/jdinput.c
+++ b/libraries/irrlicht-1.8/source/Irrlicht/jpeglib/jdinput.c
@@ -1,661 +1,661 @@
1/* 1/*
2 * jdinput.c 2 * jdinput.c
3 * 3 *
4 * Copyright (C) 1991-1997, Thomas G. Lane. 4 * Copyright (C) 1991-1997, Thomas G. Lane.
5 * Modified 2002-2009 by Guido Vollbeding. 5 * Modified 2002-2009 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 input control logic for the JPEG decompressor. 9 * This file contains input control logic for the JPEG decompressor.
10 * These routines are concerned with controlling the decompressor's input 10 * These routines are concerned with controlling the decompressor's input
11 * processing (marker reading and coefficient decoding). The actual input 11 * processing (marker reading and coefficient decoding). The actual input
12 * reading is done in jdmarker.c, jdhuff.c, and jdarith.c. 12 * reading is done in jdmarker.c, jdhuff.c, and jdarith.c.
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_input_controller pub; /* public fields */ 23 struct jpeg_input_controller pub; /* public fields */
24 24
25 int inheaders; /* Nonzero until first SOS is reached */ 25 int inheaders; /* Nonzero until first SOS is reached */
26} my_input_controller; 26} my_input_controller;
27 27
28typedef my_input_controller * my_inputctl_ptr; 28typedef my_input_controller * my_inputctl_ptr;
29 29
30 30
31/* Forward declarations */ 31/* Forward declarations */
32METHODDEF(int) consume_markers JPP((j_decompress_ptr cinfo)); 32METHODDEF(int) consume_markers JPP((j_decompress_ptr cinfo));
33 33
34 34
35/* 35/*
36 * Routines to calculate various quantities related to the size of the image. 36 * Routines to calculate various quantities related to the size of the image.
37 */ 37 */
38 38
39 39
40/* 40/*
41 * Compute output image dimensions and related values. 41 * Compute output image dimensions and related values.
42 * NOTE: this is exported for possible use by application. 42 * NOTE: this is exported for possible use by application.
43 * Hence it mustn't do anything that can't be done twice. 43 * Hence it mustn't do anything that can't be done twice.
44 */ 44 */
45 45
46GLOBAL(void) 46GLOBAL(void)
47jpeg_core_output_dimensions (j_decompress_ptr cinfo) 47jpeg_core_output_dimensions (j_decompress_ptr cinfo)
48/* Do computations that are needed before master selection phase. 48/* Do computations that are needed before master selection phase.
49 * This function is used for transcoding and full decompression. 49 * This function is used for transcoding and full decompression.
50 */ 50 */
51{ 51{
52#ifdef IDCT_SCALING_SUPPORTED 52#ifdef IDCT_SCALING_SUPPORTED
53 int ci; 53 int ci;
54 jpeg_component_info *compptr; 54 jpeg_component_info *compptr;
55 55
56 /* Compute actual output image dimensions and DCT scaling choices. */ 56 /* Compute actual output image dimensions and DCT scaling choices. */
57 if (cinfo->scale_num * cinfo->block_size <= cinfo->scale_denom) { 57 if (cinfo->scale_num * cinfo->block_size <= cinfo->scale_denom) {
58 /* Provide 1/block_size scaling */ 58 /* Provide 1/block_size scaling */
59 cinfo->output_width = (JDIMENSION) 59 cinfo->output_width = (JDIMENSION)
60 jdiv_round_up((long) cinfo->image_width, (long) cinfo->block_size); 60 jdiv_round_up((long) cinfo->image_width, (long) cinfo->block_size);
61 cinfo->output_height = (JDIMENSION) 61 cinfo->output_height = (JDIMENSION)
62 jdiv_round_up((long) cinfo->image_height, (long) cinfo->block_size); 62 jdiv_round_up((long) cinfo->image_height, (long) cinfo->block_size);
63 cinfo->min_DCT_h_scaled_size = 1; 63 cinfo->min_DCT_h_scaled_size = 1;
64 cinfo->min_DCT_v_scaled_size = 1; 64 cinfo->min_DCT_v_scaled_size = 1;
65 } else if (cinfo->scale_num * cinfo->block_size <= cinfo->scale_denom * 2) { 65 } else if (cinfo->scale_num * cinfo->block_size <= cinfo->scale_denom * 2) {
66 /* Provide 2/block_size scaling */ 66 /* Provide 2/block_size scaling */
67 cinfo->output_width = (JDIMENSION) 67 cinfo->output_width = (JDIMENSION)
68 jdiv_round_up((long) cinfo->image_width * 2L, (long) cinfo->block_size); 68 jdiv_round_up((long) cinfo->image_width * 2L, (long) cinfo->block_size);
69 cinfo->output_height = (JDIMENSION) 69 cinfo->output_height = (JDIMENSION)
70 jdiv_round_up((long) cinfo->image_height * 2L, (long) cinfo->block_size); 70 jdiv_round_up((long) cinfo->image_height * 2L, (long) cinfo->block_size);
71 cinfo->min_DCT_h_scaled_size = 2; 71 cinfo->min_DCT_h_scaled_size = 2;
72 cinfo->min_DCT_v_scaled_size = 2; 72 cinfo->min_DCT_v_scaled_size = 2;
73 } else if (cinfo->scale_num * cinfo->block_size <= cinfo->scale_denom * 3) { 73 } else if (cinfo->scale_num * cinfo->block_size <= cinfo->scale_denom * 3) {
74 /* Provide 3/block_size scaling */ 74 /* Provide 3/block_size scaling */
75 cinfo->output_width = (JDIMENSION) 75 cinfo->output_width = (JDIMENSION)
76 jdiv_round_up((long) cinfo->image_width * 3L, (long) cinfo->block_size); 76 jdiv_round_up((long) cinfo->image_width * 3L, (long) cinfo->block_size);
77 cinfo->output_height = (JDIMENSION) 77 cinfo->output_height = (JDIMENSION)
78 jdiv_round_up((long) cinfo->image_height * 3L, (long) cinfo->block_size); 78 jdiv_round_up((long) cinfo->image_height * 3L, (long) cinfo->block_size);
79 cinfo->min_DCT_h_scaled_size = 3; 79 cinfo->min_DCT_h_scaled_size = 3;
80 cinfo->min_DCT_v_scaled_size = 3; 80 cinfo->min_DCT_v_scaled_size = 3;
81 } else if (cinfo->scale_num * cinfo->block_size <= cinfo->scale_denom * 4) { 81 } else if (cinfo->scale_num * cinfo->block_size <= cinfo->scale_denom * 4) {
82 /* Provide 4/block_size scaling */ 82 /* Provide 4/block_size scaling */
83 cinfo->output_width = (JDIMENSION) 83 cinfo->output_width = (JDIMENSION)
84 jdiv_round_up((long) cinfo->image_width * 4L, (long) cinfo->block_size); 84 jdiv_round_up((long) cinfo->image_width * 4L, (long) cinfo->block_size);
85 cinfo->output_height = (JDIMENSION) 85 cinfo->output_height = (JDIMENSION)
86 jdiv_round_up((long) cinfo->image_height * 4L, (long) cinfo->block_size); 86 jdiv_round_up((long) cinfo->image_height * 4L, (long) cinfo->block_size);
87 cinfo->min_DCT_h_scaled_size = 4; 87 cinfo->min_DCT_h_scaled_size = 4;
88 cinfo->min_DCT_v_scaled_size = 4; 88 cinfo->min_DCT_v_scaled_size = 4;
89 } else if (cinfo->scale_num * cinfo->block_size <= cinfo->scale_denom * 5) { 89 } else if (cinfo->scale_num * cinfo->block_size <= cinfo->scale_denom * 5) {
90 /* Provide 5/block_size scaling */ 90 /* Provide 5/block_size scaling */
91 cinfo->output_width = (JDIMENSION) 91 cinfo->output_width = (JDIMENSION)
92 jdiv_round_up((long) cinfo->image_width * 5L, (long) cinfo->block_size); 92 jdiv_round_up((long) cinfo->image_width * 5L, (long) cinfo->block_size);
93 cinfo->output_height = (JDIMENSION) 93 cinfo->output_height = (JDIMENSION)
94 jdiv_round_up((long) cinfo->image_height * 5L, (long) cinfo->block_size); 94 jdiv_round_up((long) cinfo->image_height * 5L, (long) cinfo->block_size);
95 cinfo->min_DCT_h_scaled_size = 5; 95 cinfo->min_DCT_h_scaled_size = 5;
96 cinfo->min_DCT_v_scaled_size = 5; 96 cinfo->min_DCT_v_scaled_size = 5;
97 } else if (cinfo->scale_num * cinfo->block_size <= cinfo->scale_denom * 6) { 97 } else if (cinfo->scale_num * cinfo->block_size <= cinfo->scale_denom * 6) {
98 /* Provide 6/block_size scaling */ 98 /* Provide 6/block_size scaling */
99 cinfo->output_width = (JDIMENSION) 99 cinfo->output_width = (JDIMENSION)
100 jdiv_round_up((long) cinfo->image_width * 6L, (long) cinfo->block_size); 100 jdiv_round_up((long) cinfo->image_width * 6L, (long) cinfo->block_size);
101 cinfo->output_height = (JDIMENSION) 101 cinfo->output_height = (JDIMENSION)
102 jdiv_round_up((long) cinfo->image_height * 6L, (long) cinfo->block_size); 102 jdiv_round_up((long) cinfo->image_height * 6L, (long) cinfo->block_size);
103 cinfo->min_DCT_h_scaled_size = 6; 103 cinfo->min_DCT_h_scaled_size = 6;
104 cinfo->min_DCT_v_scaled_size = 6; 104 cinfo->min_DCT_v_scaled_size = 6;
105 } else if (cinfo->scale_num * cinfo->block_size <= cinfo->scale_denom * 7) { 105 } else if (cinfo->scale_num * cinfo->block_size <= cinfo->scale_denom * 7) {
106 /* Provide 7/block_size scaling */ 106 /* Provide 7/block_size scaling */
107 cinfo->output_width = (JDIMENSION) 107 cinfo->output_width = (JDIMENSION)
108 jdiv_round_up((long) cinfo->image_width * 7L, (long) cinfo->block_size); 108 jdiv_round_up((long) cinfo->image_width * 7L, (long) cinfo->block_size);
109 cinfo->output_height = (JDIMENSION) 109 cinfo->output_height = (JDIMENSION)
110 jdiv_round_up((long) cinfo->image_height * 7L, (long) cinfo->block_size); 110 jdiv_round_up((long) cinfo->image_height * 7L, (long) cinfo->block_size);
111 cinfo->min_DCT_h_scaled_size = 7; 111 cinfo->min_DCT_h_scaled_size = 7;
112 cinfo->min_DCT_v_scaled_size = 7; 112 cinfo->min_DCT_v_scaled_size = 7;
113 } else if (cinfo->scale_num * cinfo->block_size <= cinfo->scale_denom * 8) { 113 } else if (cinfo->scale_num * cinfo->block_size <= cinfo->scale_denom * 8) {
114 /* Provide 8/block_size scaling */ 114 /* Provide 8/block_size scaling */
115 cinfo->output_width = (JDIMENSION) 115 cinfo->output_width = (JDIMENSION)
116 jdiv_round_up((long) cinfo->image_width * 8L, (long) cinfo->block_size); 116 jdiv_round_up((long) cinfo->image_width * 8L, (long) cinfo->block_size);
117 cinfo->output_height = (JDIMENSION) 117 cinfo->output_height = (JDIMENSION)
118 jdiv_round_up((long) cinfo->image_height * 8L, (long) cinfo->block_size); 118 jdiv_round_up((long) cinfo->image_height * 8L, (long) cinfo->block_size);
119 cinfo->min_DCT_h_scaled_size = 8; 119 cinfo->min_DCT_h_scaled_size = 8;
120 cinfo->min_DCT_v_scaled_size = 8; 120 cinfo->min_DCT_v_scaled_size = 8;
121 } else if (cinfo->scale_num * cinfo->block_size <= cinfo->scale_denom * 9) { 121 } else if (cinfo->scale_num * cinfo->block_size <= cinfo->scale_denom * 9) {
122 /* Provide 9/block_size scaling */ 122 /* Provide 9/block_size scaling */
123 cinfo->output_width = (JDIMENSION) 123 cinfo->output_width = (JDIMENSION)
124 jdiv_round_up((long) cinfo->image_width * 9L, (long) cinfo->block_size); 124 jdiv_round_up((long) cinfo->image_width * 9L, (long) cinfo->block_size);
125 cinfo->output_height = (JDIMENSION) 125 cinfo->output_height = (JDIMENSION)
126 jdiv_round_up((long) cinfo->image_height * 9L, (long) cinfo->block_size); 126 jdiv_round_up((long) cinfo->image_height * 9L, (long) cinfo->block_size);
127 cinfo->min_DCT_h_scaled_size = 9; 127 cinfo->min_DCT_h_scaled_size = 9;
128 cinfo->min_DCT_v_scaled_size = 9; 128 cinfo->min_DCT_v_scaled_size = 9;
129 } else if (cinfo->scale_num * cinfo->block_size <= cinfo->scale_denom * 10) { 129 } else if (cinfo->scale_num * cinfo->block_size <= cinfo->scale_denom * 10) {
130 /* Provide 10/block_size scaling */ 130 /* Provide 10/block_size scaling */
131 cinfo->output_width = (JDIMENSION) 131 cinfo->output_width = (JDIMENSION)
132 jdiv_round_up((long) cinfo->image_width * 10L, (long) cinfo->block_size); 132 jdiv_round_up((long) cinfo->image_width * 10L, (long) cinfo->block_size);
133 cinfo->output_height = (JDIMENSION) 133 cinfo->output_height = (JDIMENSION)
134 jdiv_round_up((long) cinfo->image_height * 10L, (long) cinfo->block_size); 134 jdiv_round_up((long) cinfo->image_height * 10L, (long) cinfo->block_size);
135 cinfo->min_DCT_h_scaled_size = 10; 135 cinfo->min_DCT_h_scaled_size = 10;
136 cinfo->min_DCT_v_scaled_size = 10; 136 cinfo->min_DCT_v_scaled_size = 10;
137 } else if (cinfo->scale_num * cinfo->block_size <= cinfo->scale_denom * 11) { 137 } else if (cinfo->scale_num * cinfo->block_size <= cinfo->scale_denom * 11) {
138 /* Provide 11/block_size scaling */ 138 /* Provide 11/block_size scaling */
139 cinfo->output_width = (JDIMENSION) 139 cinfo->output_width = (JDIMENSION)
140 jdiv_round_up((long) cinfo->image_width * 11L, (long) cinfo->block_size); 140 jdiv_round_up((long) cinfo->image_width * 11L, (long) cinfo->block_size);
141 cinfo->output_height = (JDIMENSION) 141 cinfo->output_height = (JDIMENSION)
142 jdiv_round_up((long) cinfo->image_height * 11L, (long) cinfo->block_size); 142 jdiv_round_up((long) cinfo->image_height * 11L, (long) cinfo->block_size);
143 cinfo->min_DCT_h_scaled_size = 11; 143 cinfo->min_DCT_h_scaled_size = 11;
144 cinfo->min_DCT_v_scaled_size = 11; 144 cinfo->min_DCT_v_scaled_size = 11;
145 } else if (cinfo->scale_num * cinfo->block_size <= cinfo->scale_denom * 12) { 145 } else if (cinfo->scale_num * cinfo->block_size <= cinfo->scale_denom * 12) {
146 /* Provide 12/block_size scaling */ 146 /* Provide 12/block_size scaling */
147 cinfo->output_width = (JDIMENSION) 147 cinfo->output_width = (JDIMENSION)
148 jdiv_round_up((long) cinfo->image_width * 12L, (long) cinfo->block_size); 148 jdiv_round_up((long) cinfo->image_width * 12L, (long) cinfo->block_size);
149 cinfo->output_height = (JDIMENSION) 149 cinfo->output_height = (JDIMENSION)
150 jdiv_round_up((long) cinfo->image_height * 12L, (long) cinfo->block_size); 150 jdiv_round_up((long) cinfo->image_height * 12L, (long) cinfo->block_size);
151 cinfo->min_DCT_h_scaled_size = 12; 151 cinfo->min_DCT_h_scaled_size = 12;
152 cinfo->min_DCT_v_scaled_size = 12; 152 cinfo->min_DCT_v_scaled_size = 12;
153 } else if (cinfo->scale_num * cinfo->block_size <= cinfo->scale_denom * 13) { 153 } else if (cinfo->scale_num * cinfo->block_size <= cinfo->scale_denom * 13) {
154 /* Provide 13/block_size scaling */ 154 /* Provide 13/block_size scaling */
155 cinfo->output_width = (JDIMENSION) 155 cinfo->output_width = (JDIMENSION)
156 jdiv_round_up((long) cinfo->image_width * 13L, (long) cinfo->block_size); 156 jdiv_round_up((long) cinfo->image_width * 13L, (long) cinfo->block_size);
157 cinfo->output_height = (JDIMENSION) 157 cinfo->output_height = (JDIMENSION)
158 jdiv_round_up((long) cinfo->image_height * 13L, (long) cinfo->block_size); 158 jdiv_round_up((long) cinfo->image_height * 13L, (long) cinfo->block_size);
159 cinfo->min_DCT_h_scaled_size = 13; 159 cinfo->min_DCT_h_scaled_size = 13;
160 cinfo->min_DCT_v_scaled_size = 13; 160 cinfo->min_DCT_v_scaled_size = 13;
161 } else if (cinfo->scale_num * cinfo->block_size <= cinfo->scale_denom * 14) { 161 } else if (cinfo->scale_num * cinfo->block_size <= cinfo->scale_denom * 14) {
162 /* Provide 14/block_size scaling */ 162 /* Provide 14/block_size scaling */
163 cinfo->output_width = (JDIMENSION) 163 cinfo->output_width = (JDIMENSION)
164 jdiv_round_up((long) cinfo->image_width * 14L, (long) cinfo->block_size); 164 jdiv_round_up((long) cinfo->image_width * 14L, (long) cinfo->block_size);
165 cinfo->output_height = (JDIMENSION) 165 cinfo->output_height = (JDIMENSION)
166 jdiv_round_up((long) cinfo->image_height * 14L, (long) cinfo->block_size); 166 jdiv_round_up((long) cinfo->image_height * 14L, (long) cinfo->block_size);
167 cinfo->min_DCT_h_scaled_size = 14; 167 cinfo->min_DCT_h_scaled_size = 14;
168 cinfo->min_DCT_v_scaled_size = 14; 168 cinfo->min_DCT_v_scaled_size = 14;
169 } else if (cinfo->scale_num * cinfo->block_size <= cinfo->scale_denom * 15) { 169 } else if (cinfo->scale_num * cinfo->block_size <= cinfo->scale_denom * 15) {
170 /* Provide 15/block_size scaling */ 170 /* Provide 15/block_size scaling */
171 cinfo->output_width = (JDIMENSION) 171 cinfo->output_width = (JDIMENSION)
172 jdiv_round_up((long) cinfo->image_width * 15L, (long) cinfo->block_size); 172 jdiv_round_up((long) cinfo->image_width * 15L, (long) cinfo->block_size);
173 cinfo->output_height = (JDIMENSION) 173 cinfo->output_height = (JDIMENSION)
174 jdiv_round_up((long) cinfo->image_height * 15L, (long) cinfo->block_size); 174 jdiv_round_up((long) cinfo->image_height * 15L, (long) cinfo->block_size);
175 cinfo->min_DCT_h_scaled_size = 15; 175 cinfo->min_DCT_h_scaled_size = 15;
176 cinfo->min_DCT_v_scaled_size = 15; 176 cinfo->min_DCT_v_scaled_size = 15;
177 } else { 177 } else {
178 /* Provide 16/block_size scaling */ 178 /* Provide 16/block_size scaling */
179 cinfo->output_width = (JDIMENSION) 179 cinfo->output_width = (JDIMENSION)
180 jdiv_round_up((long) cinfo->image_width * 16L, (long) cinfo->block_size); 180 jdiv_round_up((long) cinfo->image_width * 16L, (long) cinfo->block_size);
181 cinfo->output_height = (JDIMENSION) 181 cinfo->output_height = (JDIMENSION)
182 jdiv_round_up((long) cinfo->image_height * 16L, (long) cinfo->block_size); 182 jdiv_round_up((long) cinfo->image_height * 16L, (long) cinfo->block_size);
183 cinfo->min_DCT_h_scaled_size = 16; 183 cinfo->min_DCT_h_scaled_size = 16;
184 cinfo->min_DCT_v_scaled_size = 16; 184 cinfo->min_DCT_v_scaled_size = 16;
185 } 185 }
186 186
187 /* Recompute dimensions of components */ 187 /* Recompute dimensions of components */
188 for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; 188 for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
189 ci++, compptr++) { 189 ci++, compptr++) {
190 compptr->DCT_h_scaled_size = cinfo->min_DCT_h_scaled_size; 190 compptr->DCT_h_scaled_size = cinfo->min_DCT_h_scaled_size;
191 compptr->DCT_v_scaled_size = cinfo->min_DCT_v_scaled_size; 191 compptr->DCT_v_scaled_size = cinfo->min_DCT_v_scaled_size;
192 } 192 }
193 193
194#else /* !IDCT_SCALING_SUPPORTED */ 194#else /* !IDCT_SCALING_SUPPORTED */
195 195
196 /* Hardwire it to "no scaling" */ 196 /* Hardwire it to "no scaling" */
197 cinfo->output_width = cinfo->image_width; 197 cinfo->output_width = cinfo->image_width;
198 cinfo->output_height = cinfo->image_height; 198 cinfo->output_height = cinfo->image_height;
199 /* jdinput.c has already initialized DCT_scaled_size, 199 /* jdinput.c has already initialized DCT_scaled_size,
200 * and has computed unscaled downsampled_width and downsampled_height. 200 * and has computed unscaled downsampled_width and downsampled_height.
201 */ 201 */
202 202
203#endif /* IDCT_SCALING_SUPPORTED */ 203#endif /* IDCT_SCALING_SUPPORTED */
204} 204}
205 205
206 206
207LOCAL(void) 207LOCAL(void)
208initial_setup (j_decompress_ptr cinfo) 208initial_setup (j_decompress_ptr cinfo)
209/* Called once, when first SOS marker is reached */ 209/* Called once, when first SOS marker is reached */
210{ 210{
211 int ci; 211 int ci;
212 jpeg_component_info *compptr; 212 jpeg_component_info *compptr;
213 213
214 /* Make sure image isn't bigger than I can handle */ 214 /* Make sure image isn't bigger than I can handle */
215 if ((long) cinfo->image_height > (long) JPEG_MAX_DIMENSION || 215 if ((long) cinfo->image_height > (long) JPEG_MAX_DIMENSION ||
216 (long) cinfo->image_width > (long) JPEG_MAX_DIMENSION) 216 (long) cinfo->image_width > (long) JPEG_MAX_DIMENSION)
217 ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) JPEG_MAX_DIMENSION); 217 ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) JPEG_MAX_DIMENSION);
218 218
219 /* For now, precision must match compiled-in value... */ 219 /* For now, precision must match compiled-in value... */
220 if (cinfo->data_precision != BITS_IN_JSAMPLE) 220 if (cinfo->data_precision != BITS_IN_JSAMPLE)
221 ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); 221 ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
222 222
223 /* Check that number of components won't exceed internal array sizes */ 223 /* Check that number of components won't exceed internal array sizes */
224 if (cinfo->num_components > MAX_COMPONENTS) 224 if (cinfo->num_components > MAX_COMPONENTS)
225 ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components, 225 ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
226 MAX_COMPONENTS); 226 MAX_COMPONENTS);
227 227
228 /* Compute maximum sampling factors; check factor validity */ 228 /* Compute maximum sampling factors; check factor validity */
229 cinfo->max_h_samp_factor = 1; 229 cinfo->max_h_samp_factor = 1;
230 cinfo->max_v_samp_factor = 1; 230 cinfo->max_v_samp_factor = 1;
231 for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; 231 for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
232 ci++, compptr++) { 232 ci++, compptr++) {
233 if (compptr->h_samp_factor<=0 || compptr->h_samp_factor>MAX_SAMP_FACTOR || 233 if (compptr->h_samp_factor<=0 || compptr->h_samp_factor>MAX_SAMP_FACTOR ||
234 compptr->v_samp_factor<=0 || compptr->v_samp_factor>MAX_SAMP_FACTOR) 234 compptr->v_samp_factor<=0 || compptr->v_samp_factor>MAX_SAMP_FACTOR)
235 ERREXIT(cinfo, JERR_BAD_SAMPLING); 235 ERREXIT(cinfo, JERR_BAD_SAMPLING);
236 cinfo->max_h_samp_factor = MAX(cinfo->max_h_samp_factor, 236 cinfo->max_h_samp_factor = MAX(cinfo->max_h_samp_factor,
237 compptr->h_samp_factor); 237 compptr->h_samp_factor);
238 cinfo->max_v_samp_factor = MAX(cinfo->max_v_samp_factor, 238 cinfo->max_v_samp_factor = MAX(cinfo->max_v_samp_factor,
239 compptr->v_samp_factor); 239 compptr->v_samp_factor);
240 } 240 }
241 241
242 /* Derive block_size, natural_order, and lim_Se */ 242 /* Derive block_size, natural_order, and lim_Se */
243 if (cinfo->is_baseline || (cinfo->progressive_mode && 243 if (cinfo->is_baseline || (cinfo->progressive_mode &&
244 cinfo->comps_in_scan)) { /* no pseudo SOS marker */ 244 cinfo->comps_in_scan)) { /* no pseudo SOS marker */
245 cinfo->block_size = DCTSIZE; 245 cinfo->block_size = DCTSIZE;
246 cinfo->natural_order = jpeg_natural_order; 246 cinfo->natural_order = jpeg_natural_order;
247 cinfo->lim_Se = DCTSIZE2-1; 247 cinfo->lim_Se = DCTSIZE2-1;
248 } else 248 } else
249 switch (cinfo->Se) { 249 switch (cinfo->Se) {
250 case (1*1-1): 250 case (1*1-1):
251 cinfo->block_size = 1; 251 cinfo->block_size = 1;
252 cinfo->natural_order = jpeg_natural_order; /* not needed */ 252 cinfo->natural_order = jpeg_natural_order; /* not needed */
253 cinfo->lim_Se = cinfo->Se; 253 cinfo->lim_Se = cinfo->Se;
254 break; 254 break;
255 case (2*2-1): 255 case (2*2-1):
256 cinfo->block_size = 2; 256 cinfo->block_size = 2;
257 cinfo->natural_order = jpeg_natural_order2; 257 cinfo->natural_order = jpeg_natural_order2;
258 cinfo->lim_Se = cinfo->Se; 258 cinfo->lim_Se = cinfo->Se;
259 break; 259 break;
260 case (3*3-1): 260 case (3*3-1):
261 cinfo->block_size = 3; 261 cinfo->block_size = 3;
262 cinfo->natural_order = jpeg_natural_order3; 262 cinfo->natural_order = jpeg_natural_order3;
263 cinfo->lim_Se = cinfo->Se; 263 cinfo->lim_Se = cinfo->Se;
264 break; 264 break;
265 case (4*4-1): 265 case (4*4-1):
266 cinfo->block_size = 4; 266 cinfo->block_size = 4;
267 cinfo->natural_order = jpeg_natural_order4; 267 cinfo->natural_order = jpeg_natural_order4;
268 cinfo->lim_Se = cinfo->Se; 268 cinfo->lim_Se = cinfo->Se;
269 break; 269 break;
270 case (5*5-1): 270 case (5*5-1):
271 cinfo->block_size = 5; 271 cinfo->block_size = 5;
272 cinfo->natural_order = jpeg_natural_order5; 272 cinfo->natural_order = jpeg_natural_order5;
273 cinfo->lim_Se = cinfo->Se; 273 cinfo->lim_Se = cinfo->Se;
274 break; 274 break;
275 case (6*6-1): 275 case (6*6-1):
276 cinfo->block_size = 6; 276 cinfo->block_size = 6;
277 cinfo->natural_order = jpeg_natural_order6; 277 cinfo->natural_order = jpeg_natural_order6;
278 cinfo->lim_Se = cinfo->Se; 278 cinfo->lim_Se = cinfo->Se;
279 break; 279 break;
280 case (7*7-1): 280 case (7*7-1):
281 cinfo->block_size = 7; 281 cinfo->block_size = 7;
282 cinfo->natural_order = jpeg_natural_order7; 282 cinfo->natural_order = jpeg_natural_order7;
283 cinfo->lim_Se = cinfo->Se; 283 cinfo->lim_Se = cinfo->Se;
284 break; 284 break;
285 case (8*8-1): 285 case (8*8-1):
286 cinfo->block_size = 8; 286 cinfo->block_size = 8;
287 cinfo->natural_order = jpeg_natural_order; 287 cinfo->natural_order = jpeg_natural_order;
288 cinfo->lim_Se = DCTSIZE2-1; 288 cinfo->lim_Se = DCTSIZE2-1;
289 break; 289 break;
290 case (9*9-1): 290 case (9*9-1):
291 cinfo->block_size = 9; 291 cinfo->block_size = 9;
292 cinfo->natural_order = jpeg_natural_order; 292 cinfo->natural_order = jpeg_natural_order;
293 cinfo->lim_Se = DCTSIZE2-1; 293 cinfo->lim_Se = DCTSIZE2-1;
294 break; 294 break;
295 case (10*10-1): 295 case (10*10-1):
296 cinfo->block_size = 10; 296 cinfo->block_size = 10;
297 cinfo->natural_order = jpeg_natural_order; 297 cinfo->natural_order = jpeg_natural_order;
298 cinfo->lim_Se = DCTSIZE2-1; 298 cinfo->lim_Se = DCTSIZE2-1;
299 break; 299 break;
300 case (11*11-1): 300 case (11*11-1):
301 cinfo->block_size = 11; 301 cinfo->block_size = 11;
302 cinfo->natural_order = jpeg_natural_order; 302 cinfo->natural_order = jpeg_natural_order;
303 cinfo->lim_Se = DCTSIZE2-1; 303 cinfo->lim_Se = DCTSIZE2-1;
304 break; 304 break;
305 case (12*12-1): 305 case (12*12-1):
306 cinfo->block_size = 12; 306 cinfo->block_size = 12;
307 cinfo->natural_order = jpeg_natural_order; 307 cinfo->natural_order = jpeg_natural_order;
308 cinfo->lim_Se = DCTSIZE2-1; 308 cinfo->lim_Se = DCTSIZE2-1;
309 break; 309 break;
310 case (13*13-1): 310 case (13*13-1):
311 cinfo->block_size = 13; 311 cinfo->block_size = 13;
312 cinfo->natural_order = jpeg_natural_order; 312 cinfo->natural_order = jpeg_natural_order;
313 cinfo->lim_Se = DCTSIZE2-1; 313 cinfo->lim_Se = DCTSIZE2-1;
314 break; 314 break;
315 case (14*14-1): 315 case (14*14-1):
316 cinfo->block_size = 14; 316 cinfo->block_size = 14;
317 cinfo->natural_order = jpeg_natural_order; 317 cinfo->natural_order = jpeg_natural_order;
318 cinfo->lim_Se = DCTSIZE2-1; 318 cinfo->lim_Se = DCTSIZE2-1;
319 break; 319 break;
320 case (15*15-1): 320 case (15*15-1):
321 cinfo->block_size = 15; 321 cinfo->block_size = 15;
322 cinfo->natural_order = jpeg_natural_order; 322 cinfo->natural_order = jpeg_natural_order;
323 cinfo->lim_Se = DCTSIZE2-1; 323 cinfo->lim_Se = DCTSIZE2-1;
324 break; 324 break;
325 case (16*16-1): 325 case (16*16-1):
326 cinfo->block_size = 16; 326 cinfo->block_size = 16;
327 cinfo->natural_order = jpeg_natural_order; 327 cinfo->natural_order = jpeg_natural_order;
328 cinfo->lim_Se = DCTSIZE2-1; 328 cinfo->lim_Se = DCTSIZE2-1;
329 break; 329 break;
330 default: 330 default:
331 ERREXIT4(cinfo, JERR_BAD_PROGRESSION, 331 ERREXIT4(cinfo, JERR_BAD_PROGRESSION,
332 cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al); 332 cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al);
333 break; 333 break;
334 } 334 }
335 335
336 /* We initialize DCT_scaled_size and min_DCT_scaled_size to block_size. 336 /* We initialize DCT_scaled_size and min_DCT_scaled_size to block_size.
337 * In the full decompressor, 337 * In the full decompressor,
338 * this will be overridden by jpeg_calc_output_dimensions in jdmaster.c; 338 * this will be overridden by jpeg_calc_output_dimensions in jdmaster.c;
339 * but in the transcoder, 339 * but in the transcoder,
340 * jpeg_calc_output_dimensions is not used, so we must do it here. 340 * jpeg_calc_output_dimensions is not used, so we must do it here.
341 */ 341 */
342 cinfo->min_DCT_h_scaled_size = cinfo->block_size; 342 cinfo->min_DCT_h_scaled_size = cinfo->block_size;
343 cinfo->min_DCT_v_scaled_size = cinfo->block_size; 343 cinfo->min_DCT_v_scaled_size = cinfo->block_size;
344 344
345 /* Compute dimensions of components */ 345 /* Compute dimensions of components */
346 for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; 346 for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
347 ci++, compptr++) { 347 ci++, compptr++) {
348 compptr->DCT_h_scaled_size = cinfo->block_size; 348 compptr->DCT_h_scaled_size = cinfo->block_size;
349 compptr->DCT_v_scaled_size = cinfo->block_size; 349 compptr->DCT_v_scaled_size = cinfo->block_size;
350 /* Size in DCT blocks */ 350 /* Size in DCT blocks */
351 compptr->width_in_blocks = (JDIMENSION) 351 compptr->width_in_blocks = (JDIMENSION)
352 jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor, 352 jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor,
353 (long) (cinfo->max_h_samp_factor * cinfo->block_size)); 353 (long) (cinfo->max_h_samp_factor * cinfo->block_size));
354 compptr->height_in_blocks = (JDIMENSION) 354 compptr->height_in_blocks = (JDIMENSION)
355 jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor, 355 jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor,
356 (long) (cinfo->max_v_samp_factor * cinfo->block_size)); 356 (long) (cinfo->max_v_samp_factor * cinfo->block_size));
357 /* downsampled_width and downsampled_height will also be overridden by 357 /* downsampled_width and downsampled_height will also be overridden by
358 * jdmaster.c if we are doing full decompression. The transcoder library 358 * jdmaster.c if we are doing full decompression. The transcoder library
359 * doesn't use these values, but the calling application might. 359 * doesn't use these values, but the calling application might.
360 */ 360 */
361 /* Size in samples */ 361 /* Size in samples */
362 compptr->downsampled_width = (JDIMENSION) 362 compptr->downsampled_width = (JDIMENSION)
363 jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor, 363 jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor,
364 (long) cinfo->max_h_samp_factor); 364 (long) cinfo->max_h_samp_factor);
365 compptr->downsampled_height = (JDIMENSION) 365 compptr->downsampled_height = (JDIMENSION)
366 jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor, 366 jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor,
367 (long) cinfo->max_v_samp_factor); 367 (long) cinfo->max_v_samp_factor);
368 /* Mark component needed, until color conversion says otherwise */ 368 /* Mark component needed, until color conversion says otherwise */
369 compptr->component_needed = TRUE; 369 compptr->component_needed = TRUE;
370 /* Mark no quantization table yet saved for component */ 370 /* Mark no quantization table yet saved for component */
371 compptr->quant_table = NULL; 371 compptr->quant_table = NULL;
372 } 372 }
373 373
374 /* Compute number of fully interleaved MCU rows. */ 374 /* Compute number of fully interleaved MCU rows. */
375 cinfo->total_iMCU_rows = (JDIMENSION) 375 cinfo->total_iMCU_rows = (JDIMENSION)
376 jdiv_round_up((long) cinfo->image_height, 376 jdiv_round_up((long) cinfo->image_height,
377 (long) (cinfo->max_v_samp_factor * cinfo->block_size)); 377 (long) (cinfo->max_v_samp_factor * cinfo->block_size));
378 378
379 /* Decide whether file contains multiple scans */ 379 /* Decide whether file contains multiple scans */
380 if (cinfo->comps_in_scan < cinfo->num_components || cinfo->progressive_mode) 380 if (cinfo->comps_in_scan < cinfo->num_components || cinfo->progressive_mode)
381 cinfo->inputctl->has_multiple_scans = TRUE; 381 cinfo->inputctl->has_multiple_scans = TRUE;
382 else 382 else
383 cinfo->inputctl->has_multiple_scans = FALSE; 383 cinfo->inputctl->has_multiple_scans = FALSE;
384} 384}
385 385
386 386
387LOCAL(void) 387LOCAL(void)
388per_scan_setup (j_decompress_ptr cinfo) 388per_scan_setup (j_decompress_ptr cinfo)
389/* Do computations that are needed before processing a JPEG scan */ 389/* Do computations that are needed before processing a JPEG scan */
390/* cinfo->comps_in_scan and cinfo->cur_comp_info[] were set from SOS marker */ 390/* cinfo->comps_in_scan and cinfo->cur_comp_info[] were set from SOS marker */
391{ 391{
392 int ci, mcublks, tmp; 392 int ci, mcublks, tmp;
393 jpeg_component_info *compptr; 393 jpeg_component_info *compptr;
394 394
395 if (cinfo->comps_in_scan == 1) { 395 if (cinfo->comps_in_scan == 1) {
396 396
397 /* Noninterleaved (single-component) scan */ 397 /* Noninterleaved (single-component) scan */
398 compptr = cinfo->cur_comp_info[0]; 398 compptr = cinfo->cur_comp_info[0];
399 399
400 /* Overall image size in MCUs */ 400 /* Overall image size in MCUs */
401 cinfo->MCUs_per_row = compptr->width_in_blocks; 401 cinfo->MCUs_per_row = compptr->width_in_blocks;
402 cinfo->MCU_rows_in_scan = compptr->height_in_blocks; 402 cinfo->MCU_rows_in_scan = compptr->height_in_blocks;
403 403
404 /* For noninterleaved scan, always one block per MCU */ 404 /* For noninterleaved scan, always one block per MCU */
405 compptr->MCU_width = 1; 405 compptr->MCU_width = 1;
406 compptr->MCU_height = 1; 406 compptr->MCU_height = 1;
407 compptr->MCU_blocks = 1; 407 compptr->MCU_blocks = 1;
408 compptr->MCU_sample_width = compptr->DCT_h_scaled_size; 408 compptr->MCU_sample_width = compptr->DCT_h_scaled_size;
409 compptr->last_col_width = 1; 409 compptr->last_col_width = 1;
410 /* For noninterleaved scans, it is convenient to define last_row_height 410 /* For noninterleaved scans, it is convenient to define last_row_height
411 * as the number of block rows present in the last iMCU row. 411 * as the number of block rows present in the last iMCU row.
412 */ 412 */
413 tmp = (int) (compptr->height_in_blocks % compptr->v_samp_factor); 413 tmp = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
414 if (tmp == 0) tmp = compptr->v_samp_factor; 414 if (tmp == 0) tmp = compptr->v_samp_factor;
415 compptr->last_row_height = tmp; 415 compptr->last_row_height = tmp;
416 416
417 /* Prepare array describing MCU composition */ 417 /* Prepare array describing MCU composition */
418 cinfo->blocks_in_MCU = 1; 418 cinfo->blocks_in_MCU = 1;
419 cinfo->MCU_membership[0] = 0; 419 cinfo->MCU_membership[0] = 0;
420 420
421 } else { 421 } else {
422 422
423 /* Interleaved (multi-component) scan */ 423 /* Interleaved (multi-component) scan */
424 if (cinfo->comps_in_scan <= 0 || cinfo->comps_in_scan > MAX_COMPS_IN_SCAN) 424 if (cinfo->comps_in_scan <= 0 || cinfo->comps_in_scan > MAX_COMPS_IN_SCAN)
425 ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->comps_in_scan, 425 ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->comps_in_scan,
426 MAX_COMPS_IN_SCAN); 426 MAX_COMPS_IN_SCAN);
427 427
428 /* Overall image size in MCUs */ 428 /* Overall image size in MCUs */
429 cinfo->MCUs_per_row = (JDIMENSION) 429 cinfo->MCUs_per_row = (JDIMENSION)
430 jdiv_round_up((long) cinfo->image_width, 430 jdiv_round_up((long) cinfo->image_width,
431 (long) (cinfo->max_h_samp_factor * cinfo->block_size)); 431 (long) (cinfo->max_h_samp_factor * cinfo->block_size));
432 cinfo->MCU_rows_in_scan = (JDIMENSION) 432 cinfo->MCU_rows_in_scan = (JDIMENSION)
433 jdiv_round_up((long) cinfo->image_height, 433 jdiv_round_up((long) cinfo->image_height,
434 (long) (cinfo->max_v_samp_factor * cinfo->block_size)); 434 (long) (cinfo->max_v_samp_factor * cinfo->block_size));
435 435
436 cinfo->blocks_in_MCU = 0; 436 cinfo->blocks_in_MCU = 0;
437 437
438 for (ci = 0; ci < cinfo->comps_in_scan; ci++) { 438 for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
439 compptr = cinfo->cur_comp_info[ci]; 439 compptr = cinfo->cur_comp_info[ci];
440 /* Sampling factors give # of blocks of component in each MCU */ 440 /* Sampling factors give # of blocks of component in each MCU */
441 compptr->MCU_width = compptr->h_samp_factor; 441 compptr->MCU_width = compptr->h_samp_factor;
442 compptr->MCU_height = compptr->v_samp_factor; 442 compptr->MCU_height = compptr->v_samp_factor;
443 compptr->MCU_blocks = compptr->MCU_width * compptr->MCU_height; 443 compptr->MCU_blocks = compptr->MCU_width * compptr->MCU_height;
444 compptr->MCU_sample_width = compptr->MCU_width * compptr->DCT_h_scaled_size; 444 compptr->MCU_sample_width = compptr->MCU_width * compptr->DCT_h_scaled_size;
445 /* Figure number of non-dummy blocks in last MCU column & row */ 445 /* Figure number of non-dummy blocks in last MCU column & row */
446 tmp = (int) (compptr->width_in_blocks % compptr->MCU_width); 446 tmp = (int) (compptr->width_in_blocks % compptr->MCU_width);
447 if (tmp == 0) tmp = compptr->MCU_width; 447 if (tmp == 0) tmp = compptr->MCU_width;
448 compptr->last_col_width = tmp; 448 compptr->last_col_width = tmp;
449 tmp = (int) (compptr->height_in_blocks % compptr->MCU_height); 449 tmp = (int) (compptr->height_in_blocks % compptr->MCU_height);
450 if (tmp == 0) tmp = compptr->MCU_height; 450 if (tmp == 0) tmp = compptr->MCU_height;
451 compptr->last_row_height = tmp; 451 compptr->last_row_height = tmp;
452 /* Prepare array describing MCU composition */ 452 /* Prepare array describing MCU composition */
453 mcublks = compptr->MCU_blocks; 453 mcublks = compptr->MCU_blocks;
454 if (cinfo->blocks_in_MCU + mcublks > D_MAX_BLOCKS_IN_MCU) 454 if (cinfo->blocks_in_MCU + mcublks > D_MAX_BLOCKS_IN_MCU)
455 ERREXIT(cinfo, JERR_BAD_MCU_SIZE); 455 ERREXIT(cinfo, JERR_BAD_MCU_SIZE);
456 while (mcublks-- > 0) { 456 while (mcublks-- > 0) {
457 cinfo->MCU_membership[cinfo->blocks_in_MCU++] = ci; 457 cinfo->MCU_membership[cinfo->blocks_in_MCU++] = ci;
458 } 458 }
459 } 459 }
460 460
461 } 461 }
462} 462}
463 463
464 464
465/* 465/*
466 * Save away a copy of the Q-table referenced by each component present 466 * Save away a copy of the Q-table referenced by each component present
467 * in the current scan, unless already saved during a prior scan. 467 * in the current scan, unless already saved during a prior scan.
468 * 468 *
469 * In a multiple-scan JPEG file, the encoder could assign different components 469 * In a multiple-scan JPEG file, the encoder could assign different components
470 * the same Q-table slot number, but change table definitions between scans 470 * the same Q-table slot number, but change table definitions between scans
471 * so that each component uses a different Q-table. (The IJG encoder is not 471 * so that each component uses a different Q-table. (The IJG encoder is not
472 * currently capable of doing this, but other encoders might.) Since we want 472 * currently capable of doing this, but other encoders might.) Since we want
473 * to be able to dequantize all the components at the end of the file, this 473 * to be able to dequantize all the components at the end of the file, this
474 * means that we have to save away the table actually used for each component. 474 * means that we have to save away the table actually used for each component.
475 * We do this by copying the table at the start of the first scan containing 475 * We do this by copying the table at the start of the first scan containing
476 * the component. 476 * the component.
477 * The JPEG spec prohibits the encoder from changing the contents of a Q-table 477 * The JPEG spec prohibits the encoder from changing the contents of a Q-table
478 * slot between scans of a component using that slot. If the encoder does so 478 * slot between scans of a component using that slot. If the encoder does so
479 * anyway, this decoder will simply use the Q-table values that were current 479 * anyway, this decoder will simply use the Q-table values that were current
480 * at the start of the first scan for the component. 480 * at the start of the first scan for the component.
481 * 481 *
482 * The decompressor output side looks only at the saved quant tables, 482 * The decompressor output side looks only at the saved quant tables,
483 * not at the current Q-table slots. 483 * not at the current Q-table slots.
484 */ 484 */
485 485
486LOCAL(void) 486LOCAL(void)
487latch_quant_tables (j_decompress_ptr cinfo) 487latch_quant_tables (j_decompress_ptr cinfo)
488{ 488{
489 int ci, qtblno; 489 int ci, qtblno;
490 jpeg_component_info *compptr; 490 jpeg_component_info *compptr;
491 JQUANT_TBL * qtbl; 491 JQUANT_TBL * qtbl;
492 492
493 for (ci = 0; ci < cinfo->comps_in_scan; ci++) { 493 for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
494 compptr = cinfo->cur_comp_info[ci]; 494 compptr = cinfo->cur_comp_info[ci];
495 /* No work if we already saved Q-table for this component */ 495 /* No work if we already saved Q-table for this component */
496 if (compptr->quant_table != NULL) 496 if (compptr->quant_table != NULL)
497 continue; 497 continue;
498 /* Make sure specified quantization table is present */ 498 /* Make sure specified quantization table is present */
499 qtblno = compptr->quant_tbl_no; 499 qtblno = compptr->quant_tbl_no;
500 if (qtblno < 0 || qtblno >= NUM_QUANT_TBLS || 500 if (qtblno < 0 || qtblno >= NUM_QUANT_TBLS ||
501 cinfo->quant_tbl_ptrs[qtblno] == NULL) 501 cinfo->quant_tbl_ptrs[qtblno] == NULL)
502 ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, qtblno); 502 ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, qtblno);
503 /* OK, save away the quantization table */ 503 /* OK, save away the quantization table */
504 qtbl = (JQUANT_TBL *) 504 qtbl = (JQUANT_TBL *)
505 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, 505 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
506 SIZEOF(JQUANT_TBL)); 506 SIZEOF(JQUANT_TBL));
507 MEMCOPY(qtbl, cinfo->quant_tbl_ptrs[qtblno], SIZEOF(JQUANT_TBL)); 507 MEMCOPY(qtbl, cinfo->quant_tbl_ptrs[qtblno], SIZEOF(JQUANT_TBL));
508 compptr->quant_table = qtbl; 508 compptr->quant_table = qtbl;
509 } 509 }
510} 510}
511 511
512 512
513/* 513/*
514 * Initialize the input modules to read a scan of compressed data. 514 * Initialize the input modules to read a scan of compressed data.
515 * The first call to this is done by jdmaster.c after initializing 515 * The first call to this is done by jdmaster.c after initializing
516 * the entire decompressor (during jpeg_start_decompress). 516 * the entire decompressor (during jpeg_start_decompress).
517 * Subsequent calls come from consume_markers, below. 517 * Subsequent calls come from consume_markers, below.
518 */ 518 */
519 519
520METHODDEF(void) 520METHODDEF(void)
521start_input_pass (j_decompress_ptr cinfo) 521start_input_pass (j_decompress_ptr cinfo)
522{ 522{
523 per_scan_setup(cinfo); 523 per_scan_setup(cinfo);
524 latch_quant_tables(cinfo); 524 latch_quant_tables(cinfo);
525 (*cinfo->entropy->start_pass) (cinfo); 525 (*cinfo->entropy->start_pass) (cinfo);
526 (*cinfo->coef->start_input_pass) (cinfo); 526 (*cinfo->coef->start_input_pass) (cinfo);
527 cinfo->inputctl->consume_input = cinfo->coef->consume_data; 527 cinfo->inputctl->consume_input = cinfo->coef->consume_data;
528} 528}
529 529
530 530
531/* 531/*
532 * Finish up after inputting a compressed-data scan. 532 * Finish up after inputting a compressed-data scan.
533 * This is called by the coefficient controller after it has read all 533 * This is called by the coefficient controller after it has read all
534 * the expected data of the scan. 534 * the expected data of the scan.
535 */ 535 */
536 536
537METHODDEF(void) 537METHODDEF(void)
538finish_input_pass (j_decompress_ptr cinfo) 538finish_input_pass (j_decompress_ptr cinfo)
539{ 539{
540 cinfo->inputctl->consume_input = consume_markers; 540 cinfo->inputctl->consume_input = consume_markers;
541} 541}
542 542
543 543
544/* 544/*
545 * Read JPEG markers before, between, or after compressed-data scans. 545 * Read JPEG markers before, between, or after compressed-data scans.
546 * Change state as necessary when a new scan is reached. 546 * Change state as necessary when a new scan is reached.
547 * Return value is JPEG_SUSPENDED, JPEG_REACHED_SOS, or JPEG_REACHED_EOI. 547 * Return value is JPEG_SUSPENDED, JPEG_REACHED_SOS, or JPEG_REACHED_EOI.
548 * 548 *
549 * The consume_input method pointer points either here or to the 549 * The consume_input method pointer points either here or to the
550 * coefficient controller's consume_data routine, depending on whether 550 * coefficient controller's consume_data routine, depending on whether
551 * we are reading a compressed data segment or inter-segment markers. 551 * we are reading a compressed data segment or inter-segment markers.
552 * 552 *
553 * Note: This function should NOT return a pseudo SOS marker (with zero 553 * Note: This function should NOT return a pseudo SOS marker (with zero
554 * component number) to the caller. A pseudo marker received by 554 * component number) to the caller. A pseudo marker received by
555 * read_markers is processed and then skipped for other markers. 555 * read_markers is processed and then skipped for other markers.
556 */ 556 */
557 557
558METHODDEF(int) 558METHODDEF(int)
559consume_markers (j_decompress_ptr cinfo) 559consume_markers (j_decompress_ptr cinfo)
560{ 560{
561 my_inputctl_ptr inputctl = (my_inputctl_ptr) cinfo->inputctl; 561 my_inputctl_ptr inputctl = (my_inputctl_ptr) cinfo->inputctl;
562 int val; 562 int val;
563 563
564 if (inputctl->pub.eoi_reached) /* After hitting EOI, read no further */ 564 if (inputctl->pub.eoi_reached) /* After hitting EOI, read no further */
565 return JPEG_REACHED_EOI; 565 return JPEG_REACHED_EOI;
566 566
567 for (;;) { /* Loop to pass pseudo SOS marker */ 567 for (;;) { /* Loop to pass pseudo SOS marker */
568 val = (*cinfo->marker->read_markers) (cinfo); 568 val = (*cinfo->marker->read_markers) (cinfo);
569 569
570 switch (val) { 570 switch (val) {
571 case JPEG_REACHED_SOS: /* Found SOS */ 571 case JPEG_REACHED_SOS: /* Found SOS */
572 if (inputctl->inheaders) { /* 1st SOS */ 572 if (inputctl->inheaders) { /* 1st SOS */
573 if (inputctl->inheaders == 1) 573 if (inputctl->inheaders == 1)
574 initial_setup(cinfo); 574 initial_setup(cinfo);
575 if (cinfo->comps_in_scan == 0) { /* pseudo SOS marker */ 575 if (cinfo->comps_in_scan == 0) { /* pseudo SOS marker */
576 inputctl->inheaders = 2; 576 inputctl->inheaders = 2;
577 break; 577 break;
578 } 578 }
579 inputctl->inheaders = 0; 579 inputctl->inheaders = 0;
580 /* Note: start_input_pass must be called by jdmaster.c 580 /* Note: start_input_pass must be called by jdmaster.c
581 * before any more input can be consumed. jdapimin.c is 581 * before any more input can be consumed. jdapimin.c is
582 * responsible for enforcing this sequencing. 582 * responsible for enforcing this sequencing.
583 */ 583 */
584 } else { /* 2nd or later SOS marker */ 584 } else { /* 2nd or later SOS marker */
585 if (! inputctl->pub.has_multiple_scans) 585 if (! inputctl->pub.has_multiple_scans)
586 ERREXIT(cinfo, JERR_EOI_EXPECTED); /* Oops, I wasn't expecting this! */ 586 ERREXIT(cinfo, JERR_EOI_EXPECTED); /* Oops, I wasn't expecting this! */
587 if (cinfo->comps_in_scan == 0) /* unexpected pseudo SOS marker */ 587 if (cinfo->comps_in_scan == 0) /* unexpected pseudo SOS marker */
588 break; 588 break;
589 start_input_pass(cinfo); 589 start_input_pass(cinfo);
590 } 590 }
591 return val; 591 return val;
592 case JPEG_REACHED_EOI: /* Found EOI */ 592 case JPEG_REACHED_EOI: /* Found EOI */
593 inputctl->pub.eoi_reached = TRUE; 593 inputctl->pub.eoi_reached = TRUE;
594 if (inputctl->inheaders) { /* Tables-only datastream, apparently */ 594 if (inputctl->inheaders) { /* Tables-only datastream, apparently */
595 if (cinfo->marker->saw_SOF) 595 if (cinfo->marker->saw_SOF)
596 ERREXIT(cinfo, JERR_SOF_NO_SOS); 596 ERREXIT(cinfo, JERR_SOF_NO_SOS);
597 } else { 597 } else {
598 /* Prevent infinite loop in coef ctlr's decompress_data routine 598 /* Prevent infinite loop in coef ctlr's decompress_data routine
599 * if user set output_scan_number larger than number of scans. 599 * if user set output_scan_number larger than number of scans.
600 */ 600 */
601 if (cinfo->output_scan_number > cinfo->input_scan_number) 601 if (cinfo->output_scan_number > cinfo->input_scan_number)
602 cinfo->output_scan_number = cinfo->input_scan_number; 602 cinfo->output_scan_number = cinfo->input_scan_number;
603 } 603 }
604 return val; 604 return val;
605 case JPEG_SUSPENDED: 605 case JPEG_SUSPENDED:
606 return val; 606 return val;
607 default: 607 default:
608 return val; 608 return val;
609 } 609 }
610 } 610 }
611} 611}
612 612
613 613
614/* 614/*
615 * Reset state to begin a fresh datastream. 615 * Reset state to begin a fresh datastream.
616 */ 616 */
617 617
618METHODDEF(void) 618METHODDEF(void)
619reset_input_controller (j_decompress_ptr cinfo) 619reset_input_controller (j_decompress_ptr cinfo)
620{ 620{
621 my_inputctl_ptr inputctl = (my_inputctl_ptr) cinfo->inputctl; 621 my_inputctl_ptr inputctl = (my_inputctl_ptr) cinfo->inputctl;
622 622
623 inputctl->pub.consume_input = consume_markers; 623 inputctl->pub.consume_input = consume_markers;
624 inputctl->pub.has_multiple_scans = FALSE; /* "unknown" would be better */ 624 inputctl->pub.has_multiple_scans = FALSE; /* "unknown" would be better */
625 inputctl->pub.eoi_reached = FALSE; 625 inputctl->pub.eoi_reached = FALSE;
626 inputctl->inheaders = 1; 626 inputctl->inheaders = 1;
627 /* Reset other modules */ 627 /* Reset other modules */
628 (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo); 628 (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);
629 (*cinfo->marker->reset_marker_reader) (cinfo); 629 (*cinfo->marker->reset_marker_reader) (cinfo);
630 /* Reset progression state -- would be cleaner if entropy decoder did this */ 630 /* Reset progression state -- would be cleaner if entropy decoder did this */
631 cinfo->coef_bits = NULL; 631 cinfo->coef_bits = NULL;
632} 632}
633 633
634 634
635/* 635/*
636 * Initialize the input controller module. 636 * Initialize the input controller module.
637 * This is called only once, when the decompression object is created. 637 * This is called only once, when the decompression object is created.
638 */ 638 */
639 639
640GLOBAL(void) 640GLOBAL(void)
641jinit_input_controller (j_decompress_ptr cinfo) 641jinit_input_controller (j_decompress_ptr cinfo)
642{ 642{
643 my_inputctl_ptr inputctl; 643 my_inputctl_ptr inputctl;
644 644
645 /* Create subobject in permanent pool */ 645 /* Create subobject in permanent pool */
646 inputctl = (my_inputctl_ptr) 646 inputctl = (my_inputctl_ptr)
647 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT, 647 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
648 SIZEOF(my_input_controller)); 648 SIZEOF(my_input_controller));
649 cinfo->inputctl = (struct jpeg_input_controller *) inputctl; 649 cinfo->inputctl = (struct jpeg_input_controller *) inputctl;
650 /* Initialize method pointers */ 650 /* Initialize method pointers */
651 inputctl->pub.consume_input = consume_markers; 651 inputctl->pub.consume_input = consume_markers;
652 inputctl->pub.reset_input_controller = reset_input_controller; 652 inputctl->pub.reset_input_controller = reset_input_controller;
653 inputctl->pub.start_input_pass = start_input_pass; 653 inputctl->pub.start_input_pass = start_input_pass;
654 inputctl->pub.finish_input_pass = finish_input_pass; 654 inputctl->pub.finish_input_pass = finish_input_pass;
655 /* Initialize state: can't use reset_input_controller since we don't 655 /* Initialize state: can't use reset_input_controller since we don't
656 * want to try to reset other modules yet. 656 * want to try to reset other modules yet.
657 */ 657 */
658 inputctl->pub.has_multiple_scans = FALSE; /* "unknown" would be better */ 658 inputctl->pub.has_multiple_scans = FALSE; /* "unknown" would be better */
659 inputctl->pub.eoi_reached = FALSE; 659 inputctl->pub.eoi_reached = FALSE;
660 inputctl->inheaders = 1; 660 inputctl->inheaders = 1;
661} 661}