102
106
jdiv_round_up((long) cinfo->image_width, 8L);
103
107
cinfo->output_height = (JDIMENSION)
104
108
jdiv_round_up((long) cinfo->image_height, 8L);
105
cinfo->min_DCT_scaled_size = 1;
109
cinfo->min_DCT_h_scaled_size = 1;
110
cinfo->min_DCT_v_scaled_size = 1;
106
111
} else if (cinfo->scale_num * 4 <= cinfo->scale_denom) {
107
112
/* Provide 1/4 scaling */
108
113
cinfo->output_width = (JDIMENSION)
109
114
jdiv_round_up((long) cinfo->image_width, 4L);
110
115
cinfo->output_height = (JDIMENSION)
111
116
jdiv_round_up((long) cinfo->image_height, 4L);
112
cinfo->min_DCT_scaled_size = 2;
117
cinfo->min_DCT_h_scaled_size = 2;
118
cinfo->min_DCT_v_scaled_size = 2;
119
} else if (cinfo->scale_num * 8 <= cinfo->scale_denom * 3) {
120
/* Provide 3/8 scaling */
121
cinfo->output_width = (JDIMENSION)
122
jdiv_round_up((long) cinfo->image_width * 3L, 8L);
123
cinfo->output_height = (JDIMENSION)
124
jdiv_round_up((long) cinfo->image_height * 3L, 8L);
125
cinfo->min_DCT_h_scaled_size = 3;
126
cinfo->min_DCT_v_scaled_size = 3;
113
127
} else if (cinfo->scale_num * 2 <= cinfo->scale_denom) {
114
128
/* Provide 1/2 scaling */
115
129
cinfo->output_width = (JDIMENSION)
116
130
jdiv_round_up((long) cinfo->image_width, 2L);
117
131
cinfo->output_height = (JDIMENSION)
118
132
jdiv_round_up((long) cinfo->image_height, 2L);
119
cinfo->min_DCT_scaled_size = 4;
133
cinfo->min_DCT_h_scaled_size = 4;
134
cinfo->min_DCT_v_scaled_size = 4;
135
} else if (cinfo->scale_num * 8 <= cinfo->scale_denom * 5) {
136
/* Provide 5/8 scaling */
137
cinfo->output_width = (JDIMENSION)
138
jdiv_round_up((long) cinfo->image_width * 5L, 8L);
139
cinfo->output_height = (JDIMENSION)
140
jdiv_round_up((long) cinfo->image_height * 5L, 8L);
141
cinfo->min_DCT_h_scaled_size = 5;
142
cinfo->min_DCT_v_scaled_size = 5;
143
} else if (cinfo->scale_num * 4 <= cinfo->scale_denom * 3) {
144
/* Provide 3/4 scaling */
145
cinfo->output_width = (JDIMENSION)
146
jdiv_round_up((long) cinfo->image_width * 3L, 4L);
147
cinfo->output_height = (JDIMENSION)
148
jdiv_round_up((long) cinfo->image_height * 3L, 4L);
149
cinfo->min_DCT_h_scaled_size = 6;
150
cinfo->min_DCT_v_scaled_size = 6;
151
} else if (cinfo->scale_num * 8 <= cinfo->scale_denom * 7) {
152
/* Provide 7/8 scaling */
153
cinfo->output_width = (JDIMENSION)
154
jdiv_round_up((long) cinfo->image_width * 7L, 8L);
155
cinfo->output_height = (JDIMENSION)
156
jdiv_round_up((long) cinfo->image_height * 7L, 8L);
157
cinfo->min_DCT_h_scaled_size = 7;
158
cinfo->min_DCT_v_scaled_size = 7;
159
} else if (cinfo->scale_num <= cinfo->scale_denom) {
121
160
/* Provide 1/1 scaling */
122
161
cinfo->output_width = cinfo->image_width;
123
162
cinfo->output_height = cinfo->image_height;
124
cinfo->min_DCT_scaled_size = DCTSIZE;
163
cinfo->min_DCT_h_scaled_size = DCTSIZE;
164
cinfo->min_DCT_v_scaled_size = DCTSIZE;
165
} else if (cinfo->scale_num * 8 <= cinfo->scale_denom * 9) {
166
/* Provide 9/8 scaling */
167
cinfo->output_width = cinfo->image_width + (JDIMENSION)
168
jdiv_round_up((long) cinfo->image_width, 8L);
169
cinfo->output_height = cinfo->image_height + (JDIMENSION)
170
jdiv_round_up((long) cinfo->image_height, 8L);
171
cinfo->min_DCT_h_scaled_size = 9;
172
cinfo->min_DCT_v_scaled_size = 9;
173
} else if (cinfo->scale_num * 4 <= cinfo->scale_denom * 5) {
174
/* Provide 5/4 scaling */
175
cinfo->output_width = cinfo->image_width + (JDIMENSION)
176
jdiv_round_up((long) cinfo->image_width, 4L);
177
cinfo->output_height = cinfo->image_height + (JDIMENSION)
178
jdiv_round_up((long) cinfo->image_height, 4L);
179
cinfo->min_DCT_h_scaled_size = 10;
180
cinfo->min_DCT_v_scaled_size = 10;
181
} else if (cinfo->scale_num * 8 <= cinfo->scale_denom * 11) {
182
/* Provide 11/8 scaling */
183
cinfo->output_width = cinfo->image_width + (JDIMENSION)
184
jdiv_round_up((long) cinfo->image_width * 3L, 8L);
185
cinfo->output_height = cinfo->image_height + (JDIMENSION)
186
jdiv_round_up((long) cinfo->image_height * 3L, 8L);
187
cinfo->min_DCT_h_scaled_size = 11;
188
cinfo->min_DCT_v_scaled_size = 11;
189
} else if (cinfo->scale_num * 2 <= cinfo->scale_denom * 3) {
190
/* Provide 3/2 scaling */
191
cinfo->output_width = cinfo->image_width + (JDIMENSION)
192
jdiv_round_up((long) cinfo->image_width, 2L);
193
cinfo->output_height = cinfo->image_height + (JDIMENSION)
194
jdiv_round_up((long) cinfo->image_height, 2L);
195
cinfo->min_DCT_h_scaled_size = 12;
196
cinfo->min_DCT_v_scaled_size = 12;
197
} else if (cinfo->scale_num * 8 <= cinfo->scale_denom * 13) {
198
/* Provide 13/8 scaling */
199
cinfo->output_width = cinfo->image_width + (JDIMENSION)
200
jdiv_round_up((long) cinfo->image_width * 5L, 8L);
201
cinfo->output_height = cinfo->image_height + (JDIMENSION)
202
jdiv_round_up((long) cinfo->image_height * 5L, 8L);
203
cinfo->min_DCT_h_scaled_size = 13;
204
cinfo->min_DCT_v_scaled_size = 13;
205
} else if (cinfo->scale_num * 4 <= cinfo->scale_denom * 7) {
206
/* Provide 7/4 scaling */
207
cinfo->output_width = cinfo->image_width + (JDIMENSION)
208
jdiv_round_up((long) cinfo->image_width * 3L, 4L);
209
cinfo->output_height = cinfo->image_height + (JDIMENSION)
210
jdiv_round_up((long) cinfo->image_height * 3L, 4L);
211
cinfo->min_DCT_h_scaled_size = 14;
212
cinfo->min_DCT_v_scaled_size = 14;
213
} else if (cinfo->scale_num * 8 <= cinfo->scale_denom * 15) {
214
/* Provide 15/8 scaling */
215
cinfo->output_width = cinfo->image_width + (JDIMENSION)
216
jdiv_round_up((long) cinfo->image_width * 7L, 8L);
217
cinfo->output_height = cinfo->image_height + (JDIMENSION)
218
jdiv_round_up((long) cinfo->image_height * 7L, 8L);
219
cinfo->min_DCT_h_scaled_size = 15;
220
cinfo->min_DCT_v_scaled_size = 15;
222
/* Provide 2/1 scaling */
223
cinfo->output_width = cinfo->image_width << 1;
224
cinfo->output_height = cinfo->image_height << 1;
225
cinfo->min_DCT_h_scaled_size = 16;
226
cinfo->min_DCT_v_scaled_size = 16;
126
228
/* In selecting the actual DCT scaling for each component, we try to
127
229
* scale up the chroma components via IDCT scaling rather than upsampling.
128
230
* This saves time if the upsampler gets to use 1:1 scaling.
129
* Note this code assumes that the supported DCT scalings are powers of 2.
231
* Note this code adapts subsampling ratios which are powers of 2.
131
233
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
132
234
ci++, compptr++) {
133
int ssize = cinfo->min_DCT_scaled_size;
134
while (ssize < DCTSIZE &&
135
(compptr->h_samp_factor * ssize * 2 <=
136
cinfo->max_h_samp_factor * cinfo->min_DCT_scaled_size) &&
137
(compptr->v_samp_factor * ssize * 2 <=
138
cinfo->max_v_samp_factor * cinfo->min_DCT_scaled_size)) {
141
compptr->DCT_scaled_size = ssize;
236
while (cinfo->min_DCT_h_scaled_size * ssize <=
237
(cinfo->do_fancy_upsampling ? DCTSIZE : DCTSIZE / 2) &&
238
(cinfo->max_h_samp_factor % (compptr->h_samp_factor * ssize * 2)) == 0) {
241
compptr->DCT_h_scaled_size = cinfo->min_DCT_h_scaled_size * ssize;
243
while (cinfo->min_DCT_v_scaled_size * ssize <=
244
(cinfo->do_fancy_upsampling ? DCTSIZE : DCTSIZE / 2) &&
245
(cinfo->max_v_samp_factor % (compptr->v_samp_factor * ssize * 2)) == 0) {
248
compptr->DCT_v_scaled_size = cinfo->min_DCT_v_scaled_size * ssize;
250
/* We don't support IDCT ratios larger than 2. */
251
if (compptr->DCT_h_scaled_size > compptr->DCT_v_scaled_size * 2)
252
compptr->DCT_h_scaled_size = compptr->DCT_v_scaled_size * 2;
253
else if (compptr->DCT_v_scaled_size > compptr->DCT_h_scaled_size * 2)
254
compptr->DCT_v_scaled_size = compptr->DCT_h_scaled_size * 2;
144
257
/* Recompute downsampled dimensions of components;