aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/irrlicht-1.8/source/Irrlicht/jpeglib/jcmaster.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/jcmaster.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/jcmaster.c')
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/jpeglib/jcmaster.c1716
1 files changed, 858 insertions, 858 deletions
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/jpeglib/jcmaster.c b/libraries/irrlicht-1.8/source/Irrlicht/jpeglib/jcmaster.c
index ef73194..caf80a5 100644
--- a/libraries/irrlicht-1.8/source/Irrlicht/jpeglib/jcmaster.c
+++ b/libraries/irrlicht-1.8/source/Irrlicht/jpeglib/jcmaster.c
@@ -1,858 +1,858 @@
1/* 1/*
2 * jcmaster.c 2 * jcmaster.c
3 * 3 *
4 * Copyright (C) 1991-1997, Thomas G. Lane. 4 * Copyright (C) 1991-1997, Thomas G. Lane.
5 * Modified 2003-2011 by Guido Vollbeding. 5 * Modified 2003-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 compressor. 9 * This file contains master control logic for the JPEG compressor.
10 * These routines are concerned with parameter validation, initial setup, 10 * These routines are concerned with parameter validation, initial setup,
11 * and inter-pass control (determining the number of passes and the work 11 * and inter-pass control (determining the number of passes and the work
12 * to be done in each pass). 12 * to be done in each 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 enum { 22typedef enum {
23 main_pass, /* input data, also do first output step */ 23 main_pass, /* input data, also do first output step */
24 huff_opt_pass, /* Huffman code optimization pass */ 24 huff_opt_pass, /* Huffman code optimization pass */
25 output_pass /* data output pass */ 25 output_pass /* data output pass */
26} c_pass_type; 26} c_pass_type;
27 27
28typedef struct { 28typedef struct {
29 struct jpeg_comp_master pub; /* public fields */ 29 struct jpeg_comp_master pub; /* public fields */
30 30
31 c_pass_type pass_type; /* the type of the current pass */ 31 c_pass_type pass_type; /* the type of the current pass */
32 32
33 int pass_number; /* # of passes completed */ 33 int pass_number; /* # of passes completed */
34 int total_passes; /* total # of passes needed */ 34 int total_passes; /* total # of passes needed */
35 35
36 int scan_number; /* current index in scan_info[] */ 36 int scan_number; /* current index in scan_info[] */
37} my_comp_master; 37} my_comp_master;
38 38
39typedef my_comp_master * my_master_ptr; 39typedef my_comp_master * my_master_ptr;
40 40
41 41
42/* 42/*
43 * Support routines that do various essential calculations. 43 * Support routines that do various essential calculations.
44 */ 44 */
45 45
46/* 46/*
47 * Compute JPEG image dimensions and related values. 47 * Compute JPEG image dimensions and related values.
48 * NOTE: this is exported for possible use by application. 48 * NOTE: this is exported for possible use by application.
49 * Hence it mustn't do anything that can't be done twice. 49 * Hence it mustn't do anything that can't be done twice.
50 */ 50 */
51 51
52GLOBAL(void) 52GLOBAL(void)
53jpeg_calc_jpeg_dimensions (j_compress_ptr cinfo) 53jpeg_calc_jpeg_dimensions (j_compress_ptr cinfo)
54/* Do computations that are needed before master selection phase */ 54/* Do computations that are needed before master selection phase */
55{ 55{
56#ifdef DCT_SCALING_SUPPORTED 56#ifdef DCT_SCALING_SUPPORTED
57 57
58 /* Sanity check on input image dimensions to prevent overflow in 58 /* Sanity check on input image dimensions to prevent overflow in
59 * following calculation. 59 * following calculation.
60 * We do check jpeg_width and jpeg_height in initial_setup below, 60 * We do check jpeg_width and jpeg_height in initial_setup below,
61 * but image_width and image_height can come from arbitrary data, 61 * but image_width and image_height can come from arbitrary data,
62 * and we need some space for multiplication by block_size. 62 * and we need some space for multiplication by block_size.
63 */ 63 */
64 if (((long) cinfo->image_width >> 24) || ((long) cinfo->image_height >> 24)) 64 if (((long) cinfo->image_width >> 24) || ((long) cinfo->image_height >> 24))
65 ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) JPEG_MAX_DIMENSION); 65 ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) JPEG_MAX_DIMENSION);
66 66
67 /* Compute actual JPEG image dimensions and DCT scaling choices. */ 67 /* Compute actual JPEG image dimensions and DCT scaling choices. */
68 if (cinfo->scale_num >= cinfo->scale_denom * cinfo->block_size) { 68 if (cinfo->scale_num >= cinfo->scale_denom * cinfo->block_size) {
69 /* Provide block_size/1 scaling */ 69 /* Provide block_size/1 scaling */
70 cinfo->jpeg_width = cinfo->image_width * cinfo->block_size; 70 cinfo->jpeg_width = cinfo->image_width * cinfo->block_size;
71 cinfo->jpeg_height = cinfo->image_height * cinfo->block_size; 71 cinfo->jpeg_height = cinfo->image_height * cinfo->block_size;
72 cinfo->min_DCT_h_scaled_size = 1; 72 cinfo->min_DCT_h_scaled_size = 1;
73 cinfo->min_DCT_v_scaled_size = 1; 73 cinfo->min_DCT_v_scaled_size = 1;
74 } else if (cinfo->scale_num * 2 >= cinfo->scale_denom * cinfo->block_size) { 74 } else if (cinfo->scale_num * 2 >= cinfo->scale_denom * cinfo->block_size) {
75 /* Provide block_size/2 scaling */ 75 /* Provide block_size/2 scaling */
76 cinfo->jpeg_width = (JDIMENSION) 76 cinfo->jpeg_width = (JDIMENSION)
77 jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 2L); 77 jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 2L);
78 cinfo->jpeg_height = (JDIMENSION) 78 cinfo->jpeg_height = (JDIMENSION)
79 jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 2L); 79 jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 2L);
80 cinfo->min_DCT_h_scaled_size = 2; 80 cinfo->min_DCT_h_scaled_size = 2;
81 cinfo->min_DCT_v_scaled_size = 2; 81 cinfo->min_DCT_v_scaled_size = 2;
82 } else if (cinfo->scale_num * 3 >= cinfo->scale_denom * cinfo->block_size) { 82 } else if (cinfo->scale_num * 3 >= cinfo->scale_denom * cinfo->block_size) {
83 /* Provide block_size/3 scaling */ 83 /* Provide block_size/3 scaling */
84 cinfo->jpeg_width = (JDIMENSION) 84 cinfo->jpeg_width = (JDIMENSION)
85 jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 3L); 85 jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 3L);
86 cinfo->jpeg_height = (JDIMENSION) 86 cinfo->jpeg_height = (JDIMENSION)
87 jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 3L); 87 jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 3L);
88 cinfo->min_DCT_h_scaled_size = 3; 88 cinfo->min_DCT_h_scaled_size = 3;
89 cinfo->min_DCT_v_scaled_size = 3; 89 cinfo->min_DCT_v_scaled_size = 3;
90 } else if (cinfo->scale_num * 4 >= cinfo->scale_denom * cinfo->block_size) { 90 } else if (cinfo->scale_num * 4 >= cinfo->scale_denom * cinfo->block_size) {
91 /* Provide block_size/4 scaling */ 91 /* Provide block_size/4 scaling */
92 cinfo->jpeg_width = (JDIMENSION) 92 cinfo->jpeg_width = (JDIMENSION)
93 jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 4L); 93 jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 4L);
94 cinfo->jpeg_height = (JDIMENSION) 94 cinfo->jpeg_height = (JDIMENSION)
95 jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 4L); 95 jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 4L);
96 cinfo->min_DCT_h_scaled_size = 4; 96 cinfo->min_DCT_h_scaled_size = 4;
97 cinfo->min_DCT_v_scaled_size = 4; 97 cinfo->min_DCT_v_scaled_size = 4;
98 } else if (cinfo->scale_num * 5 >= cinfo->scale_denom * cinfo->block_size) { 98 } else if (cinfo->scale_num * 5 >= cinfo->scale_denom * cinfo->block_size) {
99 /* Provide block_size/5 scaling */ 99 /* Provide block_size/5 scaling */
100 cinfo->jpeg_width = (JDIMENSION) 100 cinfo->jpeg_width = (JDIMENSION)
101 jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 5L); 101 jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 5L);
102 cinfo->jpeg_height = (JDIMENSION) 102 cinfo->jpeg_height = (JDIMENSION)
103 jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 5L); 103 jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 5L);
104 cinfo->min_DCT_h_scaled_size = 5; 104 cinfo->min_DCT_h_scaled_size = 5;
105 cinfo->min_DCT_v_scaled_size = 5; 105 cinfo->min_DCT_v_scaled_size = 5;
106 } else if (cinfo->scale_num * 6 >= cinfo->scale_denom * cinfo->block_size) { 106 } else if (cinfo->scale_num * 6 >= cinfo->scale_denom * cinfo->block_size) {
107 /* Provide block_size/6 scaling */ 107 /* Provide block_size/6 scaling */
108 cinfo->jpeg_width = (JDIMENSION) 108 cinfo->jpeg_width = (JDIMENSION)
109 jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 6L); 109 jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 6L);
110 cinfo->jpeg_height = (JDIMENSION) 110 cinfo->jpeg_height = (JDIMENSION)
111 jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 6L); 111 jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 6L);
112 cinfo->min_DCT_h_scaled_size = 6; 112 cinfo->min_DCT_h_scaled_size = 6;
113 cinfo->min_DCT_v_scaled_size = 6; 113 cinfo->min_DCT_v_scaled_size = 6;
114 } else if (cinfo->scale_num * 7 >= cinfo->scale_denom * cinfo->block_size) { 114 } else if (cinfo->scale_num * 7 >= cinfo->scale_denom * cinfo->block_size) {
115 /* Provide block_size/7 scaling */ 115 /* Provide block_size/7 scaling */
116 cinfo->jpeg_width = (JDIMENSION) 116 cinfo->jpeg_width = (JDIMENSION)
117 jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 7L); 117 jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 7L);
118 cinfo->jpeg_height = (JDIMENSION) 118 cinfo->jpeg_height = (JDIMENSION)
119 jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 7L); 119 jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 7L);
120 cinfo->min_DCT_h_scaled_size = 7; 120 cinfo->min_DCT_h_scaled_size = 7;
121 cinfo->min_DCT_v_scaled_size = 7; 121 cinfo->min_DCT_v_scaled_size = 7;
122 } else if (cinfo->scale_num * 8 >= cinfo->scale_denom * cinfo->block_size) { 122 } else if (cinfo->scale_num * 8 >= cinfo->scale_denom * cinfo->block_size) {
123 /* Provide block_size/8 scaling */ 123 /* Provide block_size/8 scaling */
124 cinfo->jpeg_width = (JDIMENSION) 124 cinfo->jpeg_width = (JDIMENSION)
125 jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 8L); 125 jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 8L);
126 cinfo->jpeg_height = (JDIMENSION) 126 cinfo->jpeg_height = (JDIMENSION)
127 jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 8L); 127 jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 8L);
128 cinfo->min_DCT_h_scaled_size = 8; 128 cinfo->min_DCT_h_scaled_size = 8;
129 cinfo->min_DCT_v_scaled_size = 8; 129 cinfo->min_DCT_v_scaled_size = 8;
130 } else if (cinfo->scale_num * 9 >= cinfo->scale_denom * cinfo->block_size) { 130 } else if (cinfo->scale_num * 9 >= cinfo->scale_denom * cinfo->block_size) {
131 /* Provide block_size/9 scaling */ 131 /* Provide block_size/9 scaling */
132 cinfo->jpeg_width = (JDIMENSION) 132 cinfo->jpeg_width = (JDIMENSION)
133 jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 9L); 133 jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 9L);
134 cinfo->jpeg_height = (JDIMENSION) 134 cinfo->jpeg_height = (JDIMENSION)
135 jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 9L); 135 jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 9L);
136 cinfo->min_DCT_h_scaled_size = 9; 136 cinfo->min_DCT_h_scaled_size = 9;
137 cinfo->min_DCT_v_scaled_size = 9; 137 cinfo->min_DCT_v_scaled_size = 9;
138 } else if (cinfo->scale_num * 10 >= cinfo->scale_denom * cinfo->block_size) { 138 } else if (cinfo->scale_num * 10 >= cinfo->scale_denom * cinfo->block_size) {
139 /* Provide block_size/10 scaling */ 139 /* Provide block_size/10 scaling */
140 cinfo->jpeg_width = (JDIMENSION) 140 cinfo->jpeg_width = (JDIMENSION)
141 jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 10L); 141 jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 10L);
142 cinfo->jpeg_height = (JDIMENSION) 142 cinfo->jpeg_height = (JDIMENSION)
143 jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 10L); 143 jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 10L);
144 cinfo->min_DCT_h_scaled_size = 10; 144 cinfo->min_DCT_h_scaled_size = 10;
145 cinfo->min_DCT_v_scaled_size = 10; 145 cinfo->min_DCT_v_scaled_size = 10;
146 } else if (cinfo->scale_num * 11 >= cinfo->scale_denom * cinfo->block_size) { 146 } else if (cinfo->scale_num * 11 >= cinfo->scale_denom * cinfo->block_size) {
147 /* Provide block_size/11 scaling */ 147 /* Provide block_size/11 scaling */
148 cinfo->jpeg_width = (JDIMENSION) 148 cinfo->jpeg_width = (JDIMENSION)
149 jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 11L); 149 jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 11L);
150 cinfo->jpeg_height = (JDIMENSION) 150 cinfo->jpeg_height = (JDIMENSION)
151 jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 11L); 151 jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 11L);
152 cinfo->min_DCT_h_scaled_size = 11; 152 cinfo->min_DCT_h_scaled_size = 11;
153 cinfo->min_DCT_v_scaled_size = 11; 153 cinfo->min_DCT_v_scaled_size = 11;
154 } else if (cinfo->scale_num * 12 >= cinfo->scale_denom * cinfo->block_size) { 154 } else if (cinfo->scale_num * 12 >= cinfo->scale_denom * cinfo->block_size) {
155 /* Provide block_size/12 scaling */ 155 /* Provide block_size/12 scaling */
156 cinfo->jpeg_width = (JDIMENSION) 156 cinfo->jpeg_width = (JDIMENSION)
157 jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 12L); 157 jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 12L);
158 cinfo->jpeg_height = (JDIMENSION) 158 cinfo->jpeg_height = (JDIMENSION)
159 jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 12L); 159 jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 12L);
160 cinfo->min_DCT_h_scaled_size = 12; 160 cinfo->min_DCT_h_scaled_size = 12;
161 cinfo->min_DCT_v_scaled_size = 12; 161 cinfo->min_DCT_v_scaled_size = 12;
162 } else if (cinfo->scale_num * 13 >= cinfo->scale_denom * cinfo->block_size) { 162 } else if (cinfo->scale_num * 13 >= cinfo->scale_denom * cinfo->block_size) {
163 /* Provide block_size/13 scaling */ 163 /* Provide block_size/13 scaling */
164 cinfo->jpeg_width = (JDIMENSION) 164 cinfo->jpeg_width = (JDIMENSION)
165 jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 13L); 165 jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 13L);
166 cinfo->jpeg_height = (JDIMENSION) 166 cinfo->jpeg_height = (JDIMENSION)
167 jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 13L); 167 jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 13L);
168 cinfo->min_DCT_h_scaled_size = 13; 168 cinfo->min_DCT_h_scaled_size = 13;
169 cinfo->min_DCT_v_scaled_size = 13; 169 cinfo->min_DCT_v_scaled_size = 13;
170 } else if (cinfo->scale_num * 14 >= cinfo->scale_denom * cinfo->block_size) { 170 } else if (cinfo->scale_num * 14 >= cinfo->scale_denom * cinfo->block_size) {
171 /* Provide block_size/14 scaling */ 171 /* Provide block_size/14 scaling */
172 cinfo->jpeg_width = (JDIMENSION) 172 cinfo->jpeg_width = (JDIMENSION)
173 jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 14L); 173 jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 14L);
174 cinfo->jpeg_height = (JDIMENSION) 174 cinfo->jpeg_height = (JDIMENSION)
175 jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 14L); 175 jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 14L);
176 cinfo->min_DCT_h_scaled_size = 14; 176 cinfo->min_DCT_h_scaled_size = 14;
177 cinfo->min_DCT_v_scaled_size = 14; 177 cinfo->min_DCT_v_scaled_size = 14;
178 } else if (cinfo->scale_num * 15 >= cinfo->scale_denom * cinfo->block_size) { 178 } else if (cinfo->scale_num * 15 >= cinfo->scale_denom * cinfo->block_size) {
179 /* Provide block_size/15 scaling */ 179 /* Provide block_size/15 scaling */
180 cinfo->jpeg_width = (JDIMENSION) 180 cinfo->jpeg_width = (JDIMENSION)
181 jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 15L); 181 jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 15L);
182 cinfo->jpeg_height = (JDIMENSION) 182 cinfo->jpeg_height = (JDIMENSION)
183 jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 15L); 183 jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 15L);
184 cinfo->min_DCT_h_scaled_size = 15; 184 cinfo->min_DCT_h_scaled_size = 15;
185 cinfo->min_DCT_v_scaled_size = 15; 185 cinfo->min_DCT_v_scaled_size = 15;
186 } else { 186 } else {
187 /* Provide block_size/16 scaling */ 187 /* Provide block_size/16 scaling */
188 cinfo->jpeg_width = (JDIMENSION) 188 cinfo->jpeg_width = (JDIMENSION)
189 jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 16L); 189 jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 16L);
190 cinfo->jpeg_height = (JDIMENSION) 190 cinfo->jpeg_height = (JDIMENSION)
191 jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 16L); 191 jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 16L);
192 cinfo->min_DCT_h_scaled_size = 16; 192 cinfo->min_DCT_h_scaled_size = 16;
193 cinfo->min_DCT_v_scaled_size = 16; 193 cinfo->min_DCT_v_scaled_size = 16;
194 } 194 }
195 195
196#else /* !DCT_SCALING_SUPPORTED */ 196#else /* !DCT_SCALING_SUPPORTED */
197 197
198 /* Hardwire it to "no scaling" */ 198 /* Hardwire it to "no scaling" */
199 cinfo->jpeg_width = cinfo->image_width; 199 cinfo->jpeg_width = cinfo->image_width;
200 cinfo->jpeg_height = cinfo->image_height; 200 cinfo->jpeg_height = cinfo->image_height;
201 cinfo->min_DCT_h_scaled_size = DCTSIZE; 201 cinfo->min_DCT_h_scaled_size = DCTSIZE;
202 cinfo->min_DCT_v_scaled_size = DCTSIZE; 202 cinfo->min_DCT_v_scaled_size = DCTSIZE;
203 203
204#endif /* DCT_SCALING_SUPPORTED */ 204#endif /* DCT_SCALING_SUPPORTED */
205} 205}
206 206
207 207
208LOCAL(void) 208LOCAL(void)
209jpeg_calc_trans_dimensions (j_compress_ptr cinfo) 209jpeg_calc_trans_dimensions (j_compress_ptr cinfo)
210{ 210{
211 if (cinfo->min_DCT_h_scaled_size != cinfo->min_DCT_v_scaled_size) 211 if (cinfo->min_DCT_h_scaled_size != cinfo->min_DCT_v_scaled_size)
212 ERREXIT2(cinfo, JERR_BAD_DCTSIZE, 212 ERREXIT2(cinfo, JERR_BAD_DCTSIZE,
213 cinfo->min_DCT_h_scaled_size, cinfo->min_DCT_v_scaled_size); 213 cinfo->min_DCT_h_scaled_size, cinfo->min_DCT_v_scaled_size);
214 214
215 cinfo->block_size = cinfo->min_DCT_h_scaled_size; 215 cinfo->block_size = cinfo->min_DCT_h_scaled_size;
216} 216}
217 217
218 218
219LOCAL(void) 219LOCAL(void)
220initial_setup (j_compress_ptr cinfo, boolean transcode_only) 220initial_setup (j_compress_ptr cinfo, boolean transcode_only)
221/* Do computations that are needed before master selection phase */ 221/* Do computations that are needed before master selection phase */
222{ 222{
223 int ci, ssize; 223 int ci, ssize;
224 jpeg_component_info *compptr; 224 jpeg_component_info *compptr;
225 long samplesperrow; 225 long samplesperrow;
226 JDIMENSION jd_samplesperrow; 226 JDIMENSION jd_samplesperrow;
227 227
228 if (transcode_only) 228 if (transcode_only)
229 jpeg_calc_trans_dimensions(cinfo); 229 jpeg_calc_trans_dimensions(cinfo);
230 else 230 else
231 jpeg_calc_jpeg_dimensions(cinfo); 231 jpeg_calc_jpeg_dimensions(cinfo);
232 232
233 /* Sanity check on block_size */ 233 /* Sanity check on block_size */
234 if (cinfo->block_size < 1 || cinfo->block_size > 16) 234 if (cinfo->block_size < 1 || cinfo->block_size > 16)
235 ERREXIT2(cinfo, JERR_BAD_DCTSIZE, cinfo->block_size, cinfo->block_size); 235 ERREXIT2(cinfo, JERR_BAD_DCTSIZE, cinfo->block_size, cinfo->block_size);
236 236
237 /* Derive natural_order from block_size */ 237 /* Derive natural_order from block_size */
238 switch (cinfo->block_size) { 238 switch (cinfo->block_size) {
239 case 2: cinfo->natural_order = jpeg_natural_order2; break; 239 case 2: cinfo->natural_order = jpeg_natural_order2; break;
240 case 3: cinfo->natural_order = jpeg_natural_order3; break; 240 case 3: cinfo->natural_order = jpeg_natural_order3; break;
241 case 4: cinfo->natural_order = jpeg_natural_order4; break; 241 case 4: cinfo->natural_order = jpeg_natural_order4; break;
242 case 5: cinfo->natural_order = jpeg_natural_order5; break; 242 case 5: cinfo->natural_order = jpeg_natural_order5; break;
243 case 6: cinfo->natural_order = jpeg_natural_order6; break; 243 case 6: cinfo->natural_order = jpeg_natural_order6; break;
244 case 7: cinfo->natural_order = jpeg_natural_order7; break; 244 case 7: cinfo->natural_order = jpeg_natural_order7; break;
245 default: cinfo->natural_order = jpeg_natural_order; break; 245 default: cinfo->natural_order = jpeg_natural_order; break;
246 } 246 }
247 247
248 /* Derive lim_Se from block_size */ 248 /* Derive lim_Se from block_size */
249 cinfo->lim_Se = cinfo->block_size < DCTSIZE ? 249 cinfo->lim_Se = cinfo->block_size < DCTSIZE ?
250 cinfo->block_size * cinfo->block_size - 1 : DCTSIZE2-1; 250 cinfo->block_size * cinfo->block_size - 1 : DCTSIZE2-1;
251 251
252 /* Sanity check on image dimensions */ 252 /* Sanity check on image dimensions */
253 if (cinfo->jpeg_height <= 0 || cinfo->jpeg_width <= 0 || 253 if (cinfo->jpeg_height <= 0 || cinfo->jpeg_width <= 0 ||
254 cinfo->num_components <= 0 || cinfo->input_components <= 0) 254 cinfo->num_components <= 0 || cinfo->input_components <= 0)
255 ERREXIT(cinfo, JERR_EMPTY_IMAGE); 255 ERREXIT(cinfo, JERR_EMPTY_IMAGE);
256 256
257 /* Make sure image isn't bigger than I can handle */ 257 /* Make sure image isn't bigger than I can handle */
258 if ((long) cinfo->jpeg_height > (long) JPEG_MAX_DIMENSION || 258 if ((long) cinfo->jpeg_height > (long) JPEG_MAX_DIMENSION ||
259 (long) cinfo->jpeg_width > (long) JPEG_MAX_DIMENSION) 259 (long) cinfo->jpeg_width > (long) JPEG_MAX_DIMENSION)
260 ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) JPEG_MAX_DIMENSION); 260 ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) JPEG_MAX_DIMENSION);
261 261
262 /* Width of an input scanline must be representable as JDIMENSION. */ 262 /* Width of an input scanline must be representable as JDIMENSION. */
263 samplesperrow = (long) cinfo->image_width * (long) cinfo->input_components; 263 samplesperrow = (long) cinfo->image_width * (long) cinfo->input_components;
264 jd_samplesperrow = (JDIMENSION) samplesperrow; 264 jd_samplesperrow = (JDIMENSION) samplesperrow;
265 if ((long) jd_samplesperrow != samplesperrow) 265 if ((long) jd_samplesperrow != samplesperrow)
266 ERREXIT(cinfo, JERR_WIDTH_OVERFLOW); 266 ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
267 267
268 /* For now, precision must match compiled-in value... */ 268 /* For now, precision must match compiled-in value... */
269 if (cinfo->data_precision != BITS_IN_JSAMPLE) 269 if (cinfo->data_precision != BITS_IN_JSAMPLE)
270 ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); 270 ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
271 271
272 /* Check that number of components won't exceed internal array sizes */ 272 /* Check that number of components won't exceed internal array sizes */
273 if (cinfo->num_components > MAX_COMPONENTS) 273 if (cinfo->num_components > MAX_COMPONENTS)
274 ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components, 274 ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
275 MAX_COMPONENTS); 275 MAX_COMPONENTS);
276 276
277 /* Compute maximum sampling factors; check factor validity */ 277 /* Compute maximum sampling factors; check factor validity */
278 cinfo->max_h_samp_factor = 1; 278 cinfo->max_h_samp_factor = 1;
279 cinfo->max_v_samp_factor = 1; 279 cinfo->max_v_samp_factor = 1;
280 for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; 280 for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
281 ci++, compptr++) { 281 ci++, compptr++) {
282 if (compptr->h_samp_factor<=0 || compptr->h_samp_factor>MAX_SAMP_FACTOR || 282 if (compptr->h_samp_factor<=0 || compptr->h_samp_factor>MAX_SAMP_FACTOR ||
283 compptr->v_samp_factor<=0 || compptr->v_samp_factor>MAX_SAMP_FACTOR) 283 compptr->v_samp_factor<=0 || compptr->v_samp_factor>MAX_SAMP_FACTOR)
284 ERREXIT(cinfo, JERR_BAD_SAMPLING); 284 ERREXIT(cinfo, JERR_BAD_SAMPLING);
285 cinfo->max_h_samp_factor = MAX(cinfo->max_h_samp_factor, 285 cinfo->max_h_samp_factor = MAX(cinfo->max_h_samp_factor,
286 compptr->h_samp_factor); 286 compptr->h_samp_factor);
287 cinfo->max_v_samp_factor = MAX(cinfo->max_v_samp_factor, 287 cinfo->max_v_samp_factor = MAX(cinfo->max_v_samp_factor,
288 compptr->v_samp_factor); 288 compptr->v_samp_factor);
289 } 289 }
290 290
291 /* Compute dimensions of components */ 291 /* Compute dimensions of components */
292 for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; 292 for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
293 ci++, compptr++) { 293 ci++, compptr++) {
294 /* Fill in the correct component_index value; don't rely on application */ 294 /* Fill in the correct component_index value; don't rely on application */
295 compptr->component_index = ci; 295 compptr->component_index = ci;
296 /* In selecting the actual DCT scaling for each component, we try to 296 /* In selecting the actual DCT scaling for each component, we try to
297 * scale down the chroma components via DCT scaling rather than downsampling. 297 * scale down the chroma components via DCT scaling rather than downsampling.
298 * This saves time if the downsampler gets to use 1:1 scaling. 298 * This saves time if the downsampler gets to use 1:1 scaling.
299 * Note this code adapts subsampling ratios which are powers of 2. 299 * Note this code adapts subsampling ratios which are powers of 2.
300 */ 300 */
301 ssize = 1; 301 ssize = 1;
302#ifdef DCT_SCALING_SUPPORTED 302#ifdef DCT_SCALING_SUPPORTED
303 while (cinfo->min_DCT_h_scaled_size * ssize <= 303 while (cinfo->min_DCT_h_scaled_size * ssize <=
304 (cinfo->do_fancy_downsampling ? DCTSIZE : DCTSIZE / 2) && 304 (cinfo->do_fancy_downsampling ? DCTSIZE : DCTSIZE / 2) &&
305 (cinfo->max_h_samp_factor % (compptr->h_samp_factor * ssize * 2)) == 0) { 305 (cinfo->max_h_samp_factor % (compptr->h_samp_factor * ssize * 2)) == 0) {
306 ssize = ssize * 2; 306 ssize = ssize * 2;
307 } 307 }
308#endif 308#endif
309 compptr->DCT_h_scaled_size = cinfo->min_DCT_h_scaled_size * ssize; 309 compptr->DCT_h_scaled_size = cinfo->min_DCT_h_scaled_size * ssize;
310 ssize = 1; 310 ssize = 1;
311#ifdef DCT_SCALING_SUPPORTED 311#ifdef DCT_SCALING_SUPPORTED
312 while (cinfo->min_DCT_v_scaled_size * ssize <= 312 while (cinfo->min_DCT_v_scaled_size * ssize <=
313 (cinfo->do_fancy_downsampling ? DCTSIZE : DCTSIZE / 2) && 313 (cinfo->do_fancy_downsampling ? DCTSIZE : DCTSIZE / 2) &&
314 (cinfo->max_v_samp_factor % (compptr->v_samp_factor * ssize * 2)) == 0) { 314 (cinfo->max_v_samp_factor % (compptr->v_samp_factor * ssize * 2)) == 0) {
315 ssize = ssize * 2; 315 ssize = ssize * 2;
316 } 316 }
317#endif 317#endif
318 compptr->DCT_v_scaled_size = cinfo->min_DCT_v_scaled_size * ssize; 318 compptr->DCT_v_scaled_size = cinfo->min_DCT_v_scaled_size * ssize;
319 319
320 /* We don't support DCT ratios larger than 2. */ 320 /* We don't support DCT ratios larger than 2. */
321 if (compptr->DCT_h_scaled_size > compptr->DCT_v_scaled_size * 2) 321 if (compptr->DCT_h_scaled_size > compptr->DCT_v_scaled_size * 2)
322 compptr->DCT_h_scaled_size = compptr->DCT_v_scaled_size * 2; 322 compptr->DCT_h_scaled_size = compptr->DCT_v_scaled_size * 2;
323 else if (compptr->DCT_v_scaled_size > compptr->DCT_h_scaled_size * 2) 323 else if (compptr->DCT_v_scaled_size > compptr->DCT_h_scaled_size * 2)
324 compptr->DCT_v_scaled_size = compptr->DCT_h_scaled_size * 2; 324 compptr->DCT_v_scaled_size = compptr->DCT_h_scaled_size * 2;
325 325
326 /* Size in DCT blocks */ 326 /* Size in DCT blocks */
327 compptr->width_in_blocks = (JDIMENSION) 327 compptr->width_in_blocks = (JDIMENSION)
328 jdiv_round_up((long) cinfo->jpeg_width * (long) compptr->h_samp_factor, 328 jdiv_round_up((long) cinfo->jpeg_width * (long) compptr->h_samp_factor,
329 (long) (cinfo->max_h_samp_factor * cinfo->block_size)); 329 (long) (cinfo->max_h_samp_factor * cinfo->block_size));
330 compptr->height_in_blocks = (JDIMENSION) 330 compptr->height_in_blocks = (JDIMENSION)
331 jdiv_round_up((long) cinfo->jpeg_height * (long) compptr->v_samp_factor, 331 jdiv_round_up((long) cinfo->jpeg_height * (long) compptr->v_samp_factor,
332 (long) (cinfo->max_v_samp_factor * cinfo->block_size)); 332 (long) (cinfo->max_v_samp_factor * cinfo->block_size));
333 /* Size in samples */ 333 /* Size in samples */
334 compptr->downsampled_width = (JDIMENSION) 334 compptr->downsampled_width = (JDIMENSION)
335 jdiv_round_up((long) cinfo->jpeg_width * 335 jdiv_round_up((long) cinfo->jpeg_width *
336 (long) (compptr->h_samp_factor * compptr->DCT_h_scaled_size), 336 (long) (compptr->h_samp_factor * compptr->DCT_h_scaled_size),
337 (long) (cinfo->max_h_samp_factor * cinfo->block_size)); 337 (long) (cinfo->max_h_samp_factor * cinfo->block_size));
338 compptr->downsampled_height = (JDIMENSION) 338 compptr->downsampled_height = (JDIMENSION)
339 jdiv_round_up((long) cinfo->jpeg_height * 339 jdiv_round_up((long) cinfo->jpeg_height *
340 (long) (compptr->v_samp_factor * compptr->DCT_v_scaled_size), 340 (long) (compptr->v_samp_factor * compptr->DCT_v_scaled_size),
341 (long) (cinfo->max_v_samp_factor * cinfo->block_size)); 341 (long) (cinfo->max_v_samp_factor * cinfo->block_size));
342 /* Mark component needed (this flag isn't actually used for compression) */ 342 /* Mark component needed (this flag isn't actually used for compression) */
343 compptr->component_needed = TRUE; 343 compptr->component_needed = TRUE;
344 } 344 }
345 345
346 /* Compute number of fully interleaved MCU rows (number of times that 346 /* Compute number of fully interleaved MCU rows (number of times that
347 * main controller will call coefficient controller). 347 * main controller will call coefficient controller).
348 */ 348 */
349 cinfo->total_iMCU_rows = (JDIMENSION) 349 cinfo->total_iMCU_rows = (JDIMENSION)
350 jdiv_round_up((long) cinfo->jpeg_height, 350 jdiv_round_up((long) cinfo->jpeg_height,
351 (long) (cinfo->max_v_samp_factor * cinfo->block_size)); 351 (long) (cinfo->max_v_samp_factor * cinfo->block_size));
352} 352}
353 353
354 354
355#ifdef C_MULTISCAN_FILES_SUPPORTED 355#ifdef C_MULTISCAN_FILES_SUPPORTED
356 356
357LOCAL(void) 357LOCAL(void)
358validate_script (j_compress_ptr cinfo) 358validate_script (j_compress_ptr cinfo)
359/* Verify that the scan script in cinfo->scan_info[] is valid; also 359/* Verify that the scan script in cinfo->scan_info[] is valid; also
360 * determine whether it uses progressive JPEG, and set cinfo->progressive_mode. 360 * determine whether it uses progressive JPEG, and set cinfo->progressive_mode.
361 */ 361 */
362{ 362{
363 const jpeg_scan_info * scanptr; 363 const jpeg_scan_info * scanptr;
364 int scanno, ncomps, ci, coefi, thisi; 364 int scanno, ncomps, ci, coefi, thisi;
365 int Ss, Se, Ah, Al; 365 int Ss, Se, Ah, Al;
366 boolean component_sent[MAX_COMPONENTS]; 366 boolean component_sent[MAX_COMPONENTS];
367#ifdef C_PROGRESSIVE_SUPPORTED 367#ifdef C_PROGRESSIVE_SUPPORTED
368 int * last_bitpos_ptr; 368 int * last_bitpos_ptr;
369 int last_bitpos[MAX_COMPONENTS][DCTSIZE2]; 369 int last_bitpos[MAX_COMPONENTS][DCTSIZE2];
370 /* -1 until that coefficient has been seen; then last Al for it */ 370 /* -1 until that coefficient has been seen; then last Al for it */
371#endif 371#endif
372 372
373 if (cinfo->num_scans <= 0) 373 if (cinfo->num_scans <= 0)
374 ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, 0); 374 ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, 0);
375 375
376 /* For sequential JPEG, all scans must have Ss=0, Se=DCTSIZE2-1; 376 /* For sequential JPEG, all scans must have Ss=0, Se=DCTSIZE2-1;
377 * for progressive JPEG, no scan can have this. 377 * for progressive JPEG, no scan can have this.
378 */ 378 */
379 scanptr = cinfo->scan_info; 379 scanptr = cinfo->scan_info;
380 if (scanptr->Ss != 0 || scanptr->Se != DCTSIZE2-1) { 380 if (scanptr->Ss != 0 || scanptr->Se != DCTSIZE2-1) {
381#ifdef C_PROGRESSIVE_SUPPORTED 381#ifdef C_PROGRESSIVE_SUPPORTED
382 cinfo->progressive_mode = TRUE; 382 cinfo->progressive_mode = TRUE;
383 last_bitpos_ptr = & last_bitpos[0][0]; 383 last_bitpos_ptr = & last_bitpos[0][0];
384 for (ci = 0; ci < cinfo->num_components; ci++) 384 for (ci = 0; ci < cinfo->num_components; ci++)
385 for (coefi = 0; coefi < DCTSIZE2; coefi++) 385 for (coefi = 0; coefi < DCTSIZE2; coefi++)
386 *last_bitpos_ptr++ = -1; 386 *last_bitpos_ptr++ = -1;
387#else 387#else
388 ERREXIT(cinfo, JERR_NOT_COMPILED); 388 ERREXIT(cinfo, JERR_NOT_COMPILED);
389#endif 389#endif
390 } else { 390 } else {
391 cinfo->progressive_mode = FALSE; 391 cinfo->progressive_mode = FALSE;
392 for (ci = 0; ci < cinfo->num_components; ci++) 392 for (ci = 0; ci < cinfo->num_components; ci++)
393 component_sent[ci] = FALSE; 393 component_sent[ci] = FALSE;
394 } 394 }
395 395
396 for (scanno = 1; scanno <= cinfo->num_scans; scanptr++, scanno++) { 396 for (scanno = 1; scanno <= cinfo->num_scans; scanptr++, scanno++) {
397 /* Validate component indexes */ 397 /* Validate component indexes */
398 ncomps = scanptr->comps_in_scan; 398 ncomps = scanptr->comps_in_scan;
399 if (ncomps <= 0 || ncomps > MAX_COMPS_IN_SCAN) 399 if (ncomps <= 0 || ncomps > MAX_COMPS_IN_SCAN)
400 ERREXIT2(cinfo, JERR_COMPONENT_COUNT, ncomps, MAX_COMPS_IN_SCAN); 400 ERREXIT2(cinfo, JERR_COMPONENT_COUNT, ncomps, MAX_COMPS_IN_SCAN);
401 for (ci = 0; ci < ncomps; ci++) { 401 for (ci = 0; ci < ncomps; ci++) {
402 thisi = scanptr->component_index[ci]; 402 thisi = scanptr->component_index[ci];
403 if (thisi < 0 || thisi >= cinfo->num_components) 403 if (thisi < 0 || thisi >= cinfo->num_components)
404 ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, scanno); 404 ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, scanno);
405 /* Components must appear in SOF order within each scan */ 405 /* Components must appear in SOF order within each scan */
406 if (ci > 0 && thisi <= scanptr->component_index[ci-1]) 406 if (ci > 0 && thisi <= scanptr->component_index[ci-1])
407 ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, scanno); 407 ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, scanno);
408 } 408 }
409 /* Validate progression parameters */ 409 /* Validate progression parameters */
410 Ss = scanptr->Ss; 410 Ss = scanptr->Ss;
411 Se = scanptr->Se; 411 Se = scanptr->Se;
412 Ah = scanptr->Ah; 412 Ah = scanptr->Ah;
413 Al = scanptr->Al; 413 Al = scanptr->Al;
414 if (cinfo->progressive_mode) { 414 if (cinfo->progressive_mode) {
415#ifdef C_PROGRESSIVE_SUPPORTED 415#ifdef C_PROGRESSIVE_SUPPORTED
416 /* The JPEG spec simply gives the ranges 0..13 for Ah and Al, but that 416 /* The JPEG spec simply gives the ranges 0..13 for Ah and Al, but that
417 * seems wrong: the upper bound ought to depend on data precision. 417 * seems wrong: the upper bound ought to depend on data precision.
418 * Perhaps they really meant 0..N+1 for N-bit precision. 418 * Perhaps they really meant 0..N+1 for N-bit precision.
419 * Here we allow 0..10 for 8-bit data; Al larger than 10 results in 419 * Here we allow 0..10 for 8-bit data; Al larger than 10 results in
420 * out-of-range reconstructed DC values during the first DC scan, 420 * out-of-range reconstructed DC values during the first DC scan,
421 * which might cause problems for some decoders. 421 * which might cause problems for some decoders.
422 */ 422 */
423#if BITS_IN_JSAMPLE == 8 423#if BITS_IN_JSAMPLE == 8
424#define MAX_AH_AL 10 424#define MAX_AH_AL 10
425#else 425#else
426#define MAX_AH_AL 13 426#define MAX_AH_AL 13
427#endif 427#endif
428 if (Ss < 0 || Ss >= DCTSIZE2 || Se < Ss || Se >= DCTSIZE2 || 428 if (Ss < 0 || Ss >= DCTSIZE2 || Se < Ss || Se >= DCTSIZE2 ||
429 Ah < 0 || Ah > MAX_AH_AL || Al < 0 || Al > MAX_AH_AL) 429 Ah < 0 || Ah > MAX_AH_AL || Al < 0 || Al > MAX_AH_AL)
430 ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno); 430 ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
431 if (Ss == 0) { 431 if (Ss == 0) {
432 if (Se != 0) /* DC and AC together not OK */ 432 if (Se != 0) /* DC and AC together not OK */
433 ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno); 433 ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
434 } else { 434 } else {
435 if (ncomps != 1) /* AC scans must be for only one component */ 435 if (ncomps != 1) /* AC scans must be for only one component */
436 ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno); 436 ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
437 } 437 }
438 for (ci = 0; ci < ncomps; ci++) { 438 for (ci = 0; ci < ncomps; ci++) {
439 last_bitpos_ptr = & last_bitpos[scanptr->component_index[ci]][0]; 439 last_bitpos_ptr = & last_bitpos[scanptr->component_index[ci]][0];
440 if (Ss != 0 && last_bitpos_ptr[0] < 0) /* AC without prior DC scan */ 440 if (Ss != 0 && last_bitpos_ptr[0] < 0) /* AC without prior DC scan */
441 ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno); 441 ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
442 for (coefi = Ss; coefi <= Se; coefi++) { 442 for (coefi = Ss; coefi <= Se; coefi++) {
443 if (last_bitpos_ptr[coefi] < 0) { 443 if (last_bitpos_ptr[coefi] < 0) {
444 /* first scan of this coefficient */ 444 /* first scan of this coefficient */
445 if (Ah != 0) 445 if (Ah != 0)
446 ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno); 446 ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
447 } else { 447 } else {
448 /* not first scan */ 448 /* not first scan */
449 if (Ah != last_bitpos_ptr[coefi] || Al != Ah-1) 449 if (Ah != last_bitpos_ptr[coefi] || Al != Ah-1)
450 ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno); 450 ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
451 } 451 }
452 last_bitpos_ptr[coefi] = Al; 452 last_bitpos_ptr[coefi] = Al;
453 } 453 }
454 } 454 }
455#endif 455#endif
456 } else { 456 } else {
457 /* For sequential JPEG, all progression parameters must be these: */ 457 /* For sequential JPEG, all progression parameters must be these: */
458 if (Ss != 0 || Se != DCTSIZE2-1 || Ah != 0 || Al != 0) 458 if (Ss != 0 || Se != DCTSIZE2-1 || Ah != 0 || Al != 0)
459 ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno); 459 ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
460 /* Make sure components are not sent twice */ 460 /* Make sure components are not sent twice */
461 for (ci = 0; ci < ncomps; ci++) { 461 for (ci = 0; ci < ncomps; ci++) {
462 thisi = scanptr->component_index[ci]; 462 thisi = scanptr->component_index[ci];
463 if (component_sent[thisi]) 463 if (component_sent[thisi])
464 ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, scanno); 464 ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, scanno);
465 component_sent[thisi] = TRUE; 465 component_sent[thisi] = TRUE;
466 } 466 }
467 } 467 }
468 } 468 }
469 469
470 /* Now verify that everything got sent. */ 470 /* Now verify that everything got sent. */
471 if (cinfo->progressive_mode) { 471 if (cinfo->progressive_mode) {
472#ifdef C_PROGRESSIVE_SUPPORTED 472#ifdef C_PROGRESSIVE_SUPPORTED
473 /* For progressive mode, we only check that at least some DC data 473 /* For progressive mode, we only check that at least some DC data
474 * got sent for each component; the spec does not require that all bits 474 * got sent for each component; the spec does not require that all bits
475 * of all coefficients be transmitted. Would it be wiser to enforce 475 * of all coefficients be transmitted. Would it be wiser to enforce
476 * transmission of all coefficient bits?? 476 * transmission of all coefficient bits??
477 */ 477 */
478 for (ci = 0; ci < cinfo->num_components; ci++) { 478 for (ci = 0; ci < cinfo->num_components; ci++) {
479 if (last_bitpos[ci][0] < 0) 479 if (last_bitpos[ci][0] < 0)
480 ERREXIT(cinfo, JERR_MISSING_DATA); 480 ERREXIT(cinfo, JERR_MISSING_DATA);
481 } 481 }
482#endif 482#endif
483 } else { 483 } else {
484 for (ci = 0; ci < cinfo->num_components; ci++) { 484 for (ci = 0; ci < cinfo->num_components; ci++) {
485 if (! component_sent[ci]) 485 if (! component_sent[ci])
486 ERREXIT(cinfo, JERR_MISSING_DATA); 486 ERREXIT(cinfo, JERR_MISSING_DATA);
487 } 487 }
488 } 488 }
489} 489}
490 490
491 491
492LOCAL(void) 492LOCAL(void)
493reduce_script (j_compress_ptr cinfo) 493reduce_script (j_compress_ptr cinfo)
494/* Adapt scan script for use with reduced block size; 494/* Adapt scan script for use with reduced block size;
495 * assume that script has been validated before. 495 * assume that script has been validated before.
496 */ 496 */
497{ 497{
498 jpeg_scan_info * scanptr; 498 jpeg_scan_info * scanptr;
499 int idxout, idxin; 499 int idxout, idxin;
500 500
501 /* Circumvent const declaration for this function */ 501 /* Circumvent const declaration for this function */
502 scanptr = (jpeg_scan_info *) cinfo->scan_info; 502 scanptr = (jpeg_scan_info *) cinfo->scan_info;
503 idxout = 0; 503 idxout = 0;
504 504
505 for (idxin = 0; idxin < cinfo->num_scans; idxin++) { 505 for (idxin = 0; idxin < cinfo->num_scans; idxin++) {
506 /* After skipping, idxout becomes smaller than idxin */ 506 /* After skipping, idxout becomes smaller than idxin */
507 if (idxin != idxout) 507 if (idxin != idxout)
508 /* Copy rest of data; 508 /* Copy rest of data;
509 * note we stay in given chunk of allocated memory. 509 * note we stay in given chunk of allocated memory.
510 */ 510 */
511 scanptr[idxout] = scanptr[idxin]; 511 scanptr[idxout] = scanptr[idxin];
512 if (scanptr[idxout].Ss > cinfo->lim_Se) 512 if (scanptr[idxout].Ss > cinfo->lim_Se)
513 /* Entire scan out of range - skip this entry */ 513 /* Entire scan out of range - skip this entry */
514 continue; 514 continue;
515 if (scanptr[idxout].Se > cinfo->lim_Se) 515 if (scanptr[idxout].Se > cinfo->lim_Se)
516 /* Limit scan to end of block */ 516 /* Limit scan to end of block */
517 scanptr[idxout].Se = cinfo->lim_Se; 517 scanptr[idxout].Se = cinfo->lim_Se;
518 idxout++; 518 idxout++;
519 } 519 }
520 520
521 cinfo->num_scans = idxout; 521 cinfo->num_scans = idxout;
522} 522}
523 523
524#endif /* C_MULTISCAN_FILES_SUPPORTED */ 524#endif /* C_MULTISCAN_FILES_SUPPORTED */
525 525
526 526
527LOCAL(void) 527LOCAL(void)
528select_scan_parameters (j_compress_ptr cinfo) 528select_scan_parameters (j_compress_ptr cinfo)
529/* Set up the scan parameters for the current scan */ 529/* Set up the scan parameters for the current scan */
530{ 530{
531 int ci; 531 int ci;
532 532
533#ifdef C_MULTISCAN_FILES_SUPPORTED 533#ifdef C_MULTISCAN_FILES_SUPPORTED
534 if (cinfo->scan_info != NULL) { 534 if (cinfo->scan_info != NULL) {
535 /* Prepare for current scan --- the script is already validated */ 535 /* Prepare for current scan --- the script is already validated */
536 my_master_ptr master = (my_master_ptr) cinfo->master; 536 my_master_ptr master = (my_master_ptr) cinfo->master;
537 const jpeg_scan_info * scanptr = cinfo->scan_info + master->scan_number; 537 const jpeg_scan_info * scanptr = cinfo->scan_info + master->scan_number;
538 538
539 cinfo->comps_in_scan = scanptr->comps_in_scan; 539 cinfo->comps_in_scan = scanptr->comps_in_scan;
540 for (ci = 0; ci < scanptr->comps_in_scan; ci++) { 540 for (ci = 0; ci < scanptr->comps_in_scan; ci++) {
541 cinfo->cur_comp_info[ci] = 541 cinfo->cur_comp_info[ci] =
542 &cinfo->comp_info[scanptr->component_index[ci]]; 542 &cinfo->comp_info[scanptr->component_index[ci]];
543 } 543 }
544 if (cinfo->progressive_mode) { 544 if (cinfo->progressive_mode) {
545 cinfo->Ss = scanptr->Ss; 545 cinfo->Ss = scanptr->Ss;
546 cinfo->Se = scanptr->Se; 546 cinfo->Se = scanptr->Se;
547 cinfo->Ah = scanptr->Ah; 547 cinfo->Ah = scanptr->Ah;
548 cinfo->Al = scanptr->Al; 548 cinfo->Al = scanptr->Al;
549 return; 549 return;
550 } 550 }
551 } 551 }
552 else 552 else
553#endif 553#endif
554 { 554 {
555 /* Prepare for single sequential-JPEG scan containing all components */ 555 /* Prepare for single sequential-JPEG scan containing all components */
556 if (cinfo->num_components > MAX_COMPS_IN_SCAN) 556 if (cinfo->num_components > MAX_COMPS_IN_SCAN)
557 ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components, 557 ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
558 MAX_COMPS_IN_SCAN); 558 MAX_COMPS_IN_SCAN);
559 cinfo->comps_in_scan = cinfo->num_components; 559 cinfo->comps_in_scan = cinfo->num_components;
560 for (ci = 0; ci < cinfo->num_components; ci++) { 560 for (ci = 0; ci < cinfo->num_components; ci++) {
561 cinfo->cur_comp_info[ci] = &cinfo->comp_info[ci]; 561 cinfo->cur_comp_info[ci] = &cinfo->comp_info[ci];
562 } 562 }
563 } 563 }
564 cinfo->Ss = 0; 564 cinfo->Ss = 0;
565 cinfo->Se = cinfo->block_size * cinfo->block_size - 1; 565 cinfo->Se = cinfo->block_size * cinfo->block_size - 1;
566 cinfo->Ah = 0; 566 cinfo->Ah = 0;
567 cinfo->Al = 0; 567 cinfo->Al = 0;
568} 568}
569 569
570 570
571LOCAL(void) 571LOCAL(void)
572per_scan_setup (j_compress_ptr cinfo) 572per_scan_setup (j_compress_ptr cinfo)
573/* Do computations that are needed before processing a JPEG scan */ 573/* Do computations that are needed before processing a JPEG scan */
574/* cinfo->comps_in_scan and cinfo->cur_comp_info[] are already set */ 574/* cinfo->comps_in_scan and cinfo->cur_comp_info[] are already set */
575{ 575{
576 int ci, mcublks, tmp; 576 int ci, mcublks, tmp;
577 jpeg_component_info *compptr; 577 jpeg_component_info *compptr;
578 578
579 if (cinfo->comps_in_scan == 1) { 579 if (cinfo->comps_in_scan == 1) {
580 580
581 /* Noninterleaved (single-component) scan */ 581 /* Noninterleaved (single-component) scan */
582 compptr = cinfo->cur_comp_info[0]; 582 compptr = cinfo->cur_comp_info[0];
583 583
584 /* Overall image size in MCUs */ 584 /* Overall image size in MCUs */
585 cinfo->MCUs_per_row = compptr->width_in_blocks; 585 cinfo->MCUs_per_row = compptr->width_in_blocks;
586 cinfo->MCU_rows_in_scan = compptr->height_in_blocks; 586 cinfo->MCU_rows_in_scan = compptr->height_in_blocks;
587 587
588 /* For noninterleaved scan, always one block per MCU */ 588 /* For noninterleaved scan, always one block per MCU */
589 compptr->MCU_width = 1; 589 compptr->MCU_width = 1;
590 compptr->MCU_height = 1; 590 compptr->MCU_height = 1;
591 compptr->MCU_blocks = 1; 591 compptr->MCU_blocks = 1;
592 compptr->MCU_sample_width = compptr->DCT_h_scaled_size; 592 compptr->MCU_sample_width = compptr->DCT_h_scaled_size;
593 compptr->last_col_width = 1; 593 compptr->last_col_width = 1;
594 /* For noninterleaved scans, it is convenient to define last_row_height 594 /* For noninterleaved scans, it is convenient to define last_row_height
595 * as the number of block rows present in the last iMCU row. 595 * as the number of block rows present in the last iMCU row.
596 */ 596 */
597 tmp = (int) (compptr->height_in_blocks % compptr->v_samp_factor); 597 tmp = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
598 if (tmp == 0) tmp = compptr->v_samp_factor; 598 if (tmp == 0) tmp = compptr->v_samp_factor;
599 compptr->last_row_height = tmp; 599 compptr->last_row_height = tmp;
600 600
601 /* Prepare array describing MCU composition */ 601 /* Prepare array describing MCU composition */
602 cinfo->blocks_in_MCU = 1; 602 cinfo->blocks_in_MCU = 1;
603 cinfo->MCU_membership[0] = 0; 603 cinfo->MCU_membership[0] = 0;
604 604
605 } else { 605 } else {
606 606
607 /* Interleaved (multi-component) scan */ 607 /* Interleaved (multi-component) scan */
608 if (cinfo->comps_in_scan <= 0 || cinfo->comps_in_scan > MAX_COMPS_IN_SCAN) 608 if (cinfo->comps_in_scan <= 0 || cinfo->comps_in_scan > MAX_COMPS_IN_SCAN)
609 ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->comps_in_scan, 609 ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->comps_in_scan,
610 MAX_COMPS_IN_SCAN); 610 MAX_COMPS_IN_SCAN);
611 611
612 /* Overall image size in MCUs */ 612 /* Overall image size in MCUs */
613 cinfo->MCUs_per_row = (JDIMENSION) 613 cinfo->MCUs_per_row = (JDIMENSION)
614 jdiv_round_up((long) cinfo->jpeg_width, 614 jdiv_round_up((long) cinfo->jpeg_width,
615 (long) (cinfo->max_h_samp_factor * cinfo->block_size)); 615 (long) (cinfo->max_h_samp_factor * cinfo->block_size));
616 cinfo->MCU_rows_in_scan = (JDIMENSION) 616 cinfo->MCU_rows_in_scan = (JDIMENSION)
617 jdiv_round_up((long) cinfo->jpeg_height, 617 jdiv_round_up((long) cinfo->jpeg_height,
618 (long) (cinfo->max_v_samp_factor * cinfo->block_size)); 618 (long) (cinfo->max_v_samp_factor * cinfo->block_size));
619 619
620 cinfo->blocks_in_MCU = 0; 620 cinfo->blocks_in_MCU = 0;
621 621
622 for (ci = 0; ci < cinfo->comps_in_scan; ci++) { 622 for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
623 compptr = cinfo->cur_comp_info[ci]; 623 compptr = cinfo->cur_comp_info[ci];
624 /* Sampling factors give # of blocks of component in each MCU */ 624 /* Sampling factors give # of blocks of component in each MCU */
625 compptr->MCU_width = compptr->h_samp_factor; 625 compptr->MCU_width = compptr->h_samp_factor;
626 compptr->MCU_height = compptr->v_samp_factor; 626 compptr->MCU_height = compptr->v_samp_factor;
627 compptr->MCU_blocks = compptr->MCU_width * compptr->MCU_height; 627 compptr->MCU_blocks = compptr->MCU_width * compptr->MCU_height;
628 compptr->MCU_sample_width = compptr->MCU_width * compptr->DCT_h_scaled_size; 628 compptr->MCU_sample_width = compptr->MCU_width * compptr->DCT_h_scaled_size;
629 /* Figure number of non-dummy blocks in last MCU column & row */ 629 /* Figure number of non-dummy blocks in last MCU column & row */
630 tmp = (int) (compptr->width_in_blocks % compptr->MCU_width); 630 tmp = (int) (compptr->width_in_blocks % compptr->MCU_width);
631 if (tmp == 0) tmp = compptr->MCU_width; 631 if (tmp == 0) tmp = compptr->MCU_width;
632 compptr->last_col_width = tmp; 632 compptr->last_col_width = tmp;
633 tmp = (int) (compptr->height_in_blocks % compptr->MCU_height); 633 tmp = (int) (compptr->height_in_blocks % compptr->MCU_height);
634 if (tmp == 0) tmp = compptr->MCU_height; 634 if (tmp == 0) tmp = compptr->MCU_height;
635 compptr->last_row_height = tmp; 635 compptr->last_row_height = tmp;
636 /* Prepare array describing MCU composition */ 636 /* Prepare array describing MCU composition */
637 mcublks = compptr->MCU_blocks; 637 mcublks = compptr->MCU_blocks;
638 if (cinfo->blocks_in_MCU + mcublks > C_MAX_BLOCKS_IN_MCU) 638 if (cinfo->blocks_in_MCU + mcublks > C_MAX_BLOCKS_IN_MCU)
639 ERREXIT(cinfo, JERR_BAD_MCU_SIZE); 639 ERREXIT(cinfo, JERR_BAD_MCU_SIZE);
640 while (mcublks-- > 0) { 640 while (mcublks-- > 0) {
641 cinfo->MCU_membership[cinfo->blocks_in_MCU++] = ci; 641 cinfo->MCU_membership[cinfo->blocks_in_MCU++] = ci;
642 } 642 }
643 } 643 }
644 644
645 } 645 }
646 646
647 /* Convert restart specified in rows to actual MCU count. */ 647 /* Convert restart specified in rows to actual MCU count. */
648 /* Note that count must fit in 16 bits, so we provide limiting. */ 648 /* Note that count must fit in 16 bits, so we provide limiting. */
649 if (cinfo->restart_in_rows > 0) { 649 if (cinfo->restart_in_rows > 0) {
650 long nominal = (long) cinfo->restart_in_rows * (long) cinfo->MCUs_per_row; 650 long nominal = (long) cinfo->restart_in_rows * (long) cinfo->MCUs_per_row;
651 cinfo->restart_interval = (unsigned int) MIN(nominal, 65535L); 651 cinfo->restart_interval = (unsigned int) MIN(nominal, 65535L);
652 } 652 }
653} 653}
654 654
655 655
656/* 656/*
657 * Per-pass setup. 657 * Per-pass setup.
658 * This is called at the beginning of each pass. We determine which modules 658 * This is called at the beginning of each pass. We determine which modules
659 * will be active during this pass and give them appropriate start_pass calls. 659 * will be active during this pass and give them appropriate start_pass calls.
660 * We also set is_last_pass to indicate whether any more passes will be 660 * We also set is_last_pass to indicate whether any more passes will be
661 * required. 661 * required.
662 */ 662 */
663 663
664METHODDEF(void) 664METHODDEF(void)
665prepare_for_pass (j_compress_ptr cinfo) 665prepare_for_pass (j_compress_ptr cinfo)
666{ 666{
667 my_master_ptr master = (my_master_ptr) cinfo->master; 667 my_master_ptr master = (my_master_ptr) cinfo->master;
668 668
669 switch (master->pass_type) { 669 switch (master->pass_type) {
670 case main_pass: 670 case main_pass:
671 /* Initial pass: will collect input data, and do either Huffman 671 /* Initial pass: will collect input data, and do either Huffman
672 * optimization or data output for the first scan. 672 * optimization or data output for the first scan.
673 */ 673 */
674 select_scan_parameters(cinfo); 674 select_scan_parameters(cinfo);
675 per_scan_setup(cinfo); 675 per_scan_setup(cinfo);
676 if (! cinfo->raw_data_in) { 676 if (! cinfo->raw_data_in) {
677 (*cinfo->cconvert->start_pass) (cinfo); 677 (*cinfo->cconvert->start_pass) (cinfo);
678 (*cinfo->downsample->start_pass) (cinfo); 678 (*cinfo->downsample->start_pass) (cinfo);
679 (*cinfo->prep->start_pass) (cinfo, JBUF_PASS_THRU); 679 (*cinfo->prep->start_pass) (cinfo, JBUF_PASS_THRU);
680 } 680 }
681 (*cinfo->fdct->start_pass) (cinfo); 681 (*cinfo->fdct->start_pass) (cinfo);
682 (*cinfo->entropy->start_pass) (cinfo, cinfo->optimize_coding); 682 (*cinfo->entropy->start_pass) (cinfo, cinfo->optimize_coding);
683 (*cinfo->coef->start_pass) (cinfo, 683 (*cinfo->coef->start_pass) (cinfo,
684 (master->total_passes > 1 ? 684 (master->total_passes > 1 ?
685 JBUF_SAVE_AND_PASS : JBUF_PASS_THRU)); 685 JBUF_SAVE_AND_PASS : JBUF_PASS_THRU));
686 (*cinfo->main->start_pass) (cinfo, JBUF_PASS_THRU); 686 (*cinfo->main->start_pass) (cinfo, JBUF_PASS_THRU);
687 if (cinfo->optimize_coding) { 687 if (cinfo->optimize_coding) {
688 /* No immediate data output; postpone writing frame/scan headers */ 688 /* No immediate data output; postpone writing frame/scan headers */
689 master->pub.call_pass_startup = FALSE; 689 master->pub.call_pass_startup = FALSE;
690 } else { 690 } else {
691 /* Will write frame/scan headers at first jpeg_write_scanlines call */ 691 /* Will write frame/scan headers at first jpeg_write_scanlines call */
692 master->pub.call_pass_startup = TRUE; 692 master->pub.call_pass_startup = TRUE;
693 } 693 }
694 break; 694 break;
695#ifdef ENTROPY_OPT_SUPPORTED 695#ifdef ENTROPY_OPT_SUPPORTED
696 case huff_opt_pass: 696 case huff_opt_pass:
697 /* Do Huffman optimization for a scan after the first one. */ 697 /* Do Huffman optimization for a scan after the first one. */
698 select_scan_parameters(cinfo); 698 select_scan_parameters(cinfo);
699 per_scan_setup(cinfo); 699 per_scan_setup(cinfo);
700 if (cinfo->Ss != 0 || cinfo->Ah == 0) { 700 if (cinfo->Ss != 0 || cinfo->Ah == 0) {
701 (*cinfo->entropy->start_pass) (cinfo, TRUE); 701 (*cinfo->entropy->start_pass) (cinfo, TRUE);
702 (*cinfo->coef->start_pass) (cinfo, JBUF_CRANK_DEST); 702 (*cinfo->coef->start_pass) (cinfo, JBUF_CRANK_DEST);
703 master->pub.call_pass_startup = FALSE; 703 master->pub.call_pass_startup = FALSE;
704 break; 704 break;
705 } 705 }
706 /* Special case: Huffman DC refinement scans need no Huffman table 706 /* Special case: Huffman DC refinement scans need no Huffman table
707 * and therefore we can skip the optimization pass for them. 707 * and therefore we can skip the optimization pass for them.
708 */ 708 */
709 master->pass_type = output_pass; 709 master->pass_type = output_pass;
710 master->pass_number++; 710 master->pass_number++;
711 /*FALLTHROUGH*/ 711 /*FALLTHROUGH*/
712#endif 712#endif
713 case output_pass: 713 case output_pass:
714 /* Do a data-output pass. */ 714 /* Do a data-output pass. */
715 /* We need not repeat per-scan setup if prior optimization pass did it. */ 715 /* We need not repeat per-scan setup if prior optimization pass did it. */
716 if (! cinfo->optimize_coding) { 716 if (! cinfo->optimize_coding) {
717 select_scan_parameters(cinfo); 717 select_scan_parameters(cinfo);
718 per_scan_setup(cinfo); 718 per_scan_setup(cinfo);
719 } 719 }
720 (*cinfo->entropy->start_pass) (cinfo, FALSE); 720 (*cinfo->entropy->start_pass) (cinfo, FALSE);
721 (*cinfo->coef->start_pass) (cinfo, JBUF_CRANK_DEST); 721 (*cinfo->coef->start_pass) (cinfo, JBUF_CRANK_DEST);
722 /* We emit frame/scan headers now */ 722 /* We emit frame/scan headers now */
723 if (master->scan_number == 0) 723 if (master->scan_number == 0)
724 (*cinfo->marker->write_frame_header) (cinfo); 724 (*cinfo->marker->write_frame_header) (cinfo);
725 (*cinfo->marker->write_scan_header) (cinfo); 725 (*cinfo->marker->write_scan_header) (cinfo);
726 master->pub.call_pass_startup = FALSE; 726 master->pub.call_pass_startup = FALSE;
727 break; 727 break;
728 default: 728 default:
729 ERREXIT(cinfo, JERR_NOT_COMPILED); 729 ERREXIT(cinfo, JERR_NOT_COMPILED);
730 } 730 }
731 731
732 master->pub.is_last_pass = (master->pass_number == master->total_passes-1); 732 master->pub.is_last_pass = (master->pass_number == master->total_passes-1);
733 733
734 /* Set up progress monitor's pass info if present */ 734 /* Set up progress monitor's pass info if present */
735 if (cinfo->progress != NULL) { 735 if (cinfo->progress != NULL) {
736 cinfo->progress->completed_passes = master->pass_number; 736 cinfo->progress->completed_passes = master->pass_number;
737 cinfo->progress->total_passes = master->total_passes; 737 cinfo->progress->total_passes = master->total_passes;
738 } 738 }
739} 739}
740 740
741 741
742/* 742/*
743 * Special start-of-pass hook. 743 * Special start-of-pass hook.
744 * This is called by jpeg_write_scanlines if call_pass_startup is TRUE. 744 * This is called by jpeg_write_scanlines if call_pass_startup is TRUE.
745 * In single-pass processing, we need this hook because we don't want to 745 * In single-pass processing, we need this hook because we don't want to
746 * write frame/scan headers during jpeg_start_compress; we want to let the 746 * write frame/scan headers during jpeg_start_compress; we want to let the
747 * application write COM markers etc. between jpeg_start_compress and the 747 * application write COM markers etc. between jpeg_start_compress and the
748 * jpeg_write_scanlines loop. 748 * jpeg_write_scanlines loop.
749 * In multi-pass processing, this routine is not used. 749 * In multi-pass processing, this routine is not used.
750 */ 750 */
751 751
752METHODDEF(void) 752METHODDEF(void)
753pass_startup (j_compress_ptr cinfo) 753pass_startup (j_compress_ptr cinfo)
754{ 754{
755 cinfo->master->call_pass_startup = FALSE; /* reset flag so call only once */ 755 cinfo->master->call_pass_startup = FALSE; /* reset flag so call only once */
756 756
757 (*cinfo->marker->write_frame_header) (cinfo); 757 (*cinfo->marker->write_frame_header) (cinfo);
758 (*cinfo->marker->write_scan_header) (cinfo); 758 (*cinfo->marker->write_scan_header) (cinfo);
759} 759}
760 760
761 761
762/* 762/*
763 * Finish up at end of pass. 763 * Finish up at end of pass.
764 */ 764 */
765 765
766METHODDEF(void) 766METHODDEF(void)
767finish_pass_master (j_compress_ptr cinfo) 767finish_pass_master (j_compress_ptr cinfo)
768{ 768{
769 my_master_ptr master = (my_master_ptr) cinfo->master; 769 my_master_ptr master = (my_master_ptr) cinfo->master;
770 770
771 /* The entropy coder always needs an end-of-pass call, 771 /* The entropy coder always needs an end-of-pass call,
772 * either to analyze statistics or to flush its output buffer. 772 * either to analyze statistics or to flush its output buffer.
773 */ 773 */
774 (*cinfo->entropy->finish_pass) (cinfo); 774 (*cinfo->entropy->finish_pass) (cinfo);
775 775
776 /* Update state for next pass */ 776 /* Update state for next pass */
777 switch (master->pass_type) { 777 switch (master->pass_type) {
778 case main_pass: 778 case main_pass:
779 /* next pass is either output of scan 0 (after optimization) 779 /* next pass is either output of scan 0 (after optimization)
780 * or output of scan 1 (if no optimization). 780 * or output of scan 1 (if no optimization).
781 */ 781 */
782 master->pass_type = output_pass; 782 master->pass_type = output_pass;
783 if (! cinfo->optimize_coding) 783 if (! cinfo->optimize_coding)
784 master->scan_number++; 784 master->scan_number++;
785 break; 785 break;
786 case huff_opt_pass: 786 case huff_opt_pass:
787 /* next pass is always output of current scan */ 787 /* next pass is always output of current scan */
788 master->pass_type = output_pass; 788 master->pass_type = output_pass;
789 break; 789 break;
790 case output_pass: 790 case output_pass:
791 /* next pass is either optimization or output of next scan */ 791 /* next pass is either optimization or output of next scan */
792 if (cinfo->optimize_coding) 792 if (cinfo->optimize_coding)
793 master->pass_type = huff_opt_pass; 793 master->pass_type = huff_opt_pass;
794 master->scan_number++; 794 master->scan_number++;
795 break; 795 break;
796 } 796 }
797 797
798 master->pass_number++; 798 master->pass_number++;
799} 799}
800 800
801 801
802/* 802/*
803 * Initialize master compression control. 803 * Initialize master compression control.
804 */ 804 */
805 805
806GLOBAL(void) 806GLOBAL(void)
807jinit_c_master_control (j_compress_ptr cinfo, boolean transcode_only) 807jinit_c_master_control (j_compress_ptr cinfo, boolean transcode_only)
808{ 808{
809 my_master_ptr master; 809 my_master_ptr master;
810 810
811 master = (my_master_ptr) 811 master = (my_master_ptr)
812 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, 812 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
813 SIZEOF(my_comp_master)); 813 SIZEOF(my_comp_master));
814 cinfo->master = (struct jpeg_comp_master *) master; 814 cinfo->master = (struct jpeg_comp_master *) master;
815 master->pub.prepare_for_pass = prepare_for_pass; 815 master->pub.prepare_for_pass = prepare_for_pass;
816 master->pub.pass_startup = pass_startup; 816 master->pub.pass_startup = pass_startup;
817 master->pub.finish_pass = finish_pass_master; 817 master->pub.finish_pass = finish_pass_master;
818 master->pub.is_last_pass = FALSE; 818 master->pub.is_last_pass = FALSE;
819 819
820 /* Validate parameters, determine derived values */ 820 /* Validate parameters, determine derived values */
821 initial_setup(cinfo, transcode_only); 821 initial_setup(cinfo, transcode_only);
822 822
823 if (cinfo->scan_info != NULL) { 823 if (cinfo->scan_info != NULL) {
824#ifdef C_MULTISCAN_FILES_SUPPORTED 824#ifdef C_MULTISCAN_FILES_SUPPORTED
825 validate_script(cinfo); 825 validate_script(cinfo);
826 if (cinfo->block_size < DCTSIZE) 826 if (cinfo->block_size < DCTSIZE)
827 reduce_script(cinfo); 827 reduce_script(cinfo);
828#else 828#else
829 ERREXIT(cinfo, JERR_NOT_COMPILED); 829 ERREXIT(cinfo, JERR_NOT_COMPILED);
830#endif 830#endif
831 } else { 831 } else {
832 cinfo->progressive_mode = FALSE; 832 cinfo->progressive_mode = FALSE;
833 cinfo->num_scans = 1; 833 cinfo->num_scans = 1;
834 } 834 }
835 835
836 if ((cinfo->progressive_mode || cinfo->block_size < DCTSIZE) && 836 if ((cinfo->progressive_mode || cinfo->block_size < DCTSIZE) &&
837 !cinfo->arith_code) /* TEMPORARY HACK ??? */ 837 !cinfo->arith_code) /* TEMPORARY HACK ??? */
838 /* assume default tables no good for progressive or downscale mode */ 838 /* assume default tables no good for progressive or downscale mode */
839 cinfo->optimize_coding = TRUE; 839 cinfo->optimize_coding = TRUE;
840 840
841 /* Initialize my private state */ 841 /* Initialize my private state */
842 if (transcode_only) { 842 if (transcode_only) {
843 /* no main pass in transcoding */ 843 /* no main pass in transcoding */
844 if (cinfo->optimize_coding) 844 if (cinfo->optimize_coding)
845 master->pass_type = huff_opt_pass; 845 master->pass_type = huff_opt_pass;
846 else 846 else
847 master->pass_type = output_pass; 847 master->pass_type = output_pass;
848 } else { 848 } else {
849 /* for normal compression, first pass is always this type: */ 849 /* for normal compression, first pass is always this type: */
850 master->pass_type = main_pass; 850 master->pass_type = main_pass;
851 } 851 }
852 master->scan_number = 0; 852 master->scan_number = 0;
853 master->pass_number = 0; 853 master->pass_number = 0;
854 if (cinfo->optimize_coding) 854 if (cinfo->optimize_coding)
855 master->total_passes = cinfo->num_scans * 2; 855 master->total_passes = cinfo->num_scans * 2;
856 else 856 else
857 master->total_passes = cinfo->num_scans; 857 master->total_passes = cinfo->num_scans;
858} 858}