Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(86)

Side by Side Diff: transupp.c

Issue 1953443002: Update to libjpeg_turbo 1.4.90 (Closed) Base URL: https://chromium.googlesource.com/chromium/deps/libjpeg_turbo.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « transupp.h ('k') | turbojpeg.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * transupp.c 2 * transupp.c
3 * 3 *
4 * This file was part of the Independent JPEG Group's software: 4 * This file was part of the Independent JPEG Group's software:
5 * Copyright (C) 1997-2011, Thomas G. Lane, Guido Vollbeding. 5 * Copyright (C) 1997-2011, Thomas G. Lane, Guido Vollbeding.
6 * libjpeg-turbo Modifications: 6 * libjpeg-turbo Modifications:
7 * Copyright (C) 2010, D. R. Commander. 7 * Copyright (C) 2010, D. R. Commander.
8 * For conditions of distribution and use, see the accompanying README file. 8 * For conditions of distribution and use, see the accompanying README.ijg
9 * file.
9 * 10 *
10 * This file contains image transformation routines and other utility code 11 * This file contains image transformation routines and other utility code
11 * used by the jpegtran sample application. These are NOT part of the core 12 * used by the jpegtran sample application. These are NOT part of the core
12 * JPEG library. But we keep these routines separate from jpegtran.c to 13 * JPEG library. But we keep these routines separate from jpegtran.c to
13 * ease the task of maintaining jpegtran-like programs that have other user 14 * ease the task of maintaining jpegtran-like programs that have other user
14 * interfaces. 15 * interfaces.
15 */ 16 */
16 17
17 /* Although this file really shouldn't have access to the library internals, 18 /* Although this file really shouldn't have access to the library internals,
18 * it's helpful to let it call jround_up() and jcopy_block_row(). 19 * it's helpful to let it call jround_up() and jcopy_block_row().
19 */ 20 */
20 #define JPEG_INTERNALS 21 #define JPEG_INTERNALS
21 22
22 #include "jinclude.h" 23 #include "jinclude.h"
23 #include "jpeglib.h" 24 #include "jpeglib.h"
24 #include "transupp.h"» » /* My own external interface */ 25 #include "transupp.h" /* My own external interface */
25 #include "jpegcomp.h" 26 #include "jpegcomp.h"
26 #include <ctype.h>» » /* to declare isdigit() */ 27 #include <ctype.h> /* to declare isdigit() */
27 28
28 29
29 #if JPEG_LIB_VERSION >= 70 30 #if JPEG_LIB_VERSION >= 70
30 #define dstinfo_min_DCT_h_scaled_size dstinfo->min_DCT_h_scaled_size 31 #define dstinfo_min_DCT_h_scaled_size dstinfo->min_DCT_h_scaled_size
31 #define dstinfo_min_DCT_v_scaled_size dstinfo->min_DCT_v_scaled_size 32 #define dstinfo_min_DCT_v_scaled_size dstinfo->min_DCT_v_scaled_size
32 #else 33 #else
33 #define dstinfo_min_DCT_h_scaled_size DCTSIZE 34 #define dstinfo_min_DCT_h_scaled_size DCTSIZE
34 #define dstinfo_min_DCT_v_scaled_size DCTSIZE 35 #define dstinfo_min_DCT_v_scaled_size DCTSIZE
35 #endif 36 #endif
36 37
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 * passed to the transform routines are measured in iMCU blocks of the 83 * passed to the transform routines are measured in iMCU blocks of the
83 * destination.) 84 * destination.)
84 * 6. All the routines assume that the source and destination buffers are 85 * 6. All the routines assume that the source and destination buffers are
85 * padded out to a full iMCU boundary. This is true, although for the 86 * padded out to a full iMCU boundary. This is true, although for the
86 * source buffer it is an undocumented property of jdcoefct.c. 87 * source buffer it is an undocumented property of jdcoefct.c.
87 */ 88 */
88 89
89 90
90 LOCAL(void) 91 LOCAL(void)
91 do_crop (j_decompress_ptr srcinfo, j_compress_ptr dstinfo, 92 do_crop (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
92 » JDIMENSION x_crop_offset, JDIMENSION y_crop_offset, 93 JDIMENSION x_crop_offset, JDIMENSION y_crop_offset,
93 » jvirt_barray_ptr *src_coef_arrays, 94 jvirt_barray_ptr *src_coef_arrays,
94 » jvirt_barray_ptr *dst_coef_arrays) 95 jvirt_barray_ptr *dst_coef_arrays)
95 /* Crop. This is only used when no rotate/flip is requested with the crop. */ 96 /* Crop. This is only used when no rotate/flip is requested with the crop. */
96 { 97 {
97 JDIMENSION dst_blk_y, x_crop_blocks, y_crop_blocks; 98 JDIMENSION dst_blk_y, x_crop_blocks, y_crop_blocks;
98 int ci, offset_y; 99 int ci, offset_y;
99 JBLOCKARRAY src_buffer, dst_buffer; 100 JBLOCKARRAY src_buffer, dst_buffer;
100 jpeg_component_info *compptr; 101 jpeg_component_info *compptr;
101 102
102 /* We simply have to copy the right amount of data (the destination's 103 /* We simply have to copy the right amount of data (the destination's
103 * image size) starting at the given X and Y offsets in the source. 104 * image size) starting at the given X and Y offsets in the source.
104 */ 105 */
105 for (ci = 0; ci < dstinfo->num_components; ci++) { 106 for (ci = 0; ci < dstinfo->num_components; ci++) {
106 compptr = dstinfo->comp_info + ci; 107 compptr = dstinfo->comp_info + ci;
107 x_crop_blocks = x_crop_offset * compptr->h_samp_factor; 108 x_crop_blocks = x_crop_offset * compptr->h_samp_factor;
108 y_crop_blocks = y_crop_offset * compptr->v_samp_factor; 109 y_crop_blocks = y_crop_offset * compptr->v_samp_factor;
109 for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks; 110 for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
110 » dst_blk_y += compptr->v_samp_factor) { 111 dst_blk_y += compptr->v_samp_factor) {
111 dst_buffer = (*srcinfo->mem->access_virt_barray) 112 dst_buffer = (*srcinfo->mem->access_virt_barray)
112 » ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y, 113 ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
113 » (JDIMENSION) compptr->v_samp_factor, TRUE); 114 (JDIMENSION) compptr->v_samp_factor, TRUE);
114 src_buffer = (*srcinfo->mem->access_virt_barray) 115 src_buffer = (*srcinfo->mem->access_virt_barray)
115 » ((j_common_ptr) srcinfo, src_coef_arrays[ci], 116 ((j_common_ptr) srcinfo, src_coef_arrays[ci],
116 » dst_blk_y + y_crop_blocks, 117 dst_blk_y + y_crop_blocks,
117 » (JDIMENSION) compptr->v_samp_factor, FALSE); 118 (JDIMENSION) compptr->v_samp_factor, FALSE);
118 for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) { 119 for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
119 » jcopy_block_row(src_buffer[offset_y] + x_crop_blocks, 120 jcopy_block_row(src_buffer[offset_y] + x_crop_blocks,
120 » » » dst_buffer[offset_y], 121 dst_buffer[offset_y],
121 » » » compptr->width_in_blocks); 122 compptr->width_in_blocks);
122 } 123 }
123 } 124 }
124 } 125 }
125 } 126 }
126 127
127 128
128 LOCAL(void) 129 LOCAL(void)
129 do_flip_h_no_crop (j_decompress_ptr srcinfo, j_compress_ptr dstinfo, 130 do_flip_h_no_crop (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
130 » » JDIMENSION x_crop_offset, 131 JDIMENSION x_crop_offset,
131 » » jvirt_barray_ptr *src_coef_arrays) 132 jvirt_barray_ptr *src_coef_arrays)
132 /* Horizontal flip; done in-place, so no separate dest array is required. 133 /* Horizontal flip; done in-place, so no separate dest array is required.
133 * NB: this only works when y_crop_offset is zero. 134 * NB: this only works when y_crop_offset is zero.
134 */ 135 */
135 { 136 {
136 JDIMENSION MCU_cols, comp_width, blk_x, blk_y, x_crop_blocks; 137 JDIMENSION MCU_cols, comp_width, blk_x, blk_y, x_crop_blocks;
137 int ci, k, offset_y; 138 int ci, k, offset_y;
138 JBLOCKARRAY buffer; 139 JBLOCKARRAY buffer;
139 JCOEFPTR ptr1, ptr2; 140 JCOEFPTR ptr1, ptr2;
140 JCOEF temp1, temp2; 141 JCOEF temp1, temp2;
141 jpeg_component_info *compptr; 142 jpeg_component_info *compptr;
142 143
143 /* Horizontal mirroring of DCT blocks is accomplished by swapping 144 /* Horizontal mirroring of DCT blocks is accomplished by swapping
144 * pairs of blocks in-place. Within a DCT block, we perform horizontal 145 * pairs of blocks in-place. Within a DCT block, we perform horizontal
145 * mirroring by changing the signs of odd-numbered columns. 146 * mirroring by changing the signs of odd-numbered columns.
146 * Partial iMCUs at the right edge are left untouched. 147 * Partial iMCUs at the right edge are left untouched.
147 */ 148 */
148 MCU_cols = srcinfo->output_width / 149 MCU_cols = srcinfo->output_width /
149 (dstinfo->max_h_samp_factor * dstinfo_min_DCT_h_scaled_size); 150 (dstinfo->max_h_samp_factor * dstinfo_min_DCT_h_scaled_size);
150 151
151 for (ci = 0; ci < dstinfo->num_components; ci++) { 152 for (ci = 0; ci < dstinfo->num_components; ci++) {
152 compptr = dstinfo->comp_info + ci; 153 compptr = dstinfo->comp_info + ci;
153 comp_width = MCU_cols * compptr->h_samp_factor; 154 comp_width = MCU_cols * compptr->h_samp_factor;
154 x_crop_blocks = x_crop_offset * compptr->h_samp_factor; 155 x_crop_blocks = x_crop_offset * compptr->h_samp_factor;
155 for (blk_y = 0; blk_y < compptr->height_in_blocks; 156 for (blk_y = 0; blk_y < compptr->height_in_blocks;
156 » blk_y += compptr->v_samp_factor) { 157 blk_y += compptr->v_samp_factor) {
157 buffer = (*srcinfo->mem->access_virt_barray) 158 buffer = (*srcinfo->mem->access_virt_barray)
158 » ((j_common_ptr) srcinfo, src_coef_arrays[ci], blk_y, 159 ((j_common_ptr) srcinfo, src_coef_arrays[ci], blk_y,
159 » (JDIMENSION) compptr->v_samp_factor, TRUE); 160 (JDIMENSION) compptr->v_samp_factor, TRUE);
160 for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) { 161 for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
161 » /* Do the mirroring */ 162 /* Do the mirroring */
162 » for (blk_x = 0; blk_x * 2 < comp_width; blk_x++) { 163 for (blk_x = 0; blk_x * 2 < comp_width; blk_x++) {
163 » ptr1 = buffer[offset_y][blk_x]; 164 ptr1 = buffer[offset_y][blk_x];
164 » ptr2 = buffer[offset_y][comp_width - blk_x - 1]; 165 ptr2 = buffer[offset_y][comp_width - blk_x - 1];
165 » /* this unrolled loop doesn't need to know which row it's on... */ 166 /* this unrolled loop doesn't need to know which row it's on... */
166 » for (k = 0; k < DCTSIZE2; k += 2) { 167 for (k = 0; k < DCTSIZE2; k += 2) {
167 » temp1 = *ptr1;» /* swap even column */ 168 temp1 = *ptr1; /* swap even column */
168 » temp2 = *ptr2; 169 temp2 = *ptr2;
169 » *ptr1++ = temp2; 170 *ptr1++ = temp2;
170 » *ptr2++ = temp1; 171 *ptr2++ = temp1;
171 » temp1 = *ptr1;» /* swap odd column with sign change */ 172 temp1 = *ptr1; /* swap odd column with sign change */
172 » temp2 = *ptr2; 173 temp2 = *ptr2;
173 » *ptr1++ = -temp2; 174 *ptr1++ = -temp2;
174 » *ptr2++ = -temp1; 175 *ptr2++ = -temp1;
175 » } 176 }
176 » } 177 }
177 » if (x_crop_blocks > 0) { 178 if (x_crop_blocks > 0) {
178 » /* Now left-justify the portion of the data to be kept. 179 /* Now left-justify the portion of the data to be kept.
179 » * We can't use a single jcopy_block_row() call because that routine 180 * We can't use a single jcopy_block_row() call because that routine
180 » * depends on memcpy(), whose behavior is unspecified for overlapping 181 * depends on memcpy(), whose behavior is unspecified for overlapping
181 » * source and destination areas. Sigh. 182 * source and destination areas. Sigh.
182 » */ 183 */
183 » for (blk_x = 0; blk_x < compptr->width_in_blocks; blk_x++) { 184 for (blk_x = 0; blk_x < compptr->width_in_blocks; blk_x++) {
184 » jcopy_block_row(buffer[offset_y] + blk_x + x_crop_blocks, 185 jcopy_block_row(buffer[offset_y] + blk_x + x_crop_blocks,
185 » » » buffer[offset_y] + blk_x, 186 buffer[offset_y] + blk_x,
186 » » » (JDIMENSION) 1); 187 (JDIMENSION) 1);
187 » } 188 }
188 » } 189 }
189 } 190 }
190 } 191 }
191 } 192 }
192 } 193 }
193 194
194 195
195 LOCAL(void) 196 LOCAL(void)
196 do_flip_h (j_decompress_ptr srcinfo, j_compress_ptr dstinfo, 197 do_flip_h (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
197 » JDIMENSION x_crop_offset, JDIMENSION y_crop_offset, 198 JDIMENSION x_crop_offset, JDIMENSION y_crop_offset,
198 » jvirt_barray_ptr *src_coef_arrays, 199 jvirt_barray_ptr *src_coef_arrays,
199 » jvirt_barray_ptr *dst_coef_arrays) 200 jvirt_barray_ptr *dst_coef_arrays)
200 /* Horizontal flip in general cropping case */ 201 /* Horizontal flip in general cropping case */
201 { 202 {
202 JDIMENSION MCU_cols, comp_width, dst_blk_x, dst_blk_y; 203 JDIMENSION MCU_cols, comp_width, dst_blk_x, dst_blk_y;
203 JDIMENSION x_crop_blocks, y_crop_blocks; 204 JDIMENSION x_crop_blocks, y_crop_blocks;
204 int ci, k, offset_y; 205 int ci, k, offset_y;
205 JBLOCKARRAY src_buffer, dst_buffer; 206 JBLOCKARRAY src_buffer, dst_buffer;
206 JBLOCKROW src_row_ptr, dst_row_ptr; 207 JBLOCKROW src_row_ptr, dst_row_ptr;
207 JCOEFPTR src_ptr, dst_ptr; 208 JCOEFPTR src_ptr, dst_ptr;
208 jpeg_component_info *compptr; 209 jpeg_component_info *compptr;
209 210
210 /* Here we must output into a separate array because we can't touch 211 /* Here we must output into a separate array because we can't touch
211 * different rows of a single virtual array simultaneously. Otherwise, 212 * different rows of a single virtual array simultaneously. Otherwise,
212 * this is essentially the same as the routine above. 213 * this is essentially the same as the routine above.
213 */ 214 */
214 MCU_cols = srcinfo->output_width / 215 MCU_cols = srcinfo->output_width /
215 (dstinfo->max_h_samp_factor * dstinfo_min_DCT_h_scaled_size); 216 (dstinfo->max_h_samp_factor * dstinfo_min_DCT_h_scaled_size);
216 217
217 for (ci = 0; ci < dstinfo->num_components; ci++) { 218 for (ci = 0; ci < dstinfo->num_components; ci++) {
218 compptr = dstinfo->comp_info + ci; 219 compptr = dstinfo->comp_info + ci;
219 comp_width = MCU_cols * compptr->h_samp_factor; 220 comp_width = MCU_cols * compptr->h_samp_factor;
220 x_crop_blocks = x_crop_offset * compptr->h_samp_factor; 221 x_crop_blocks = x_crop_offset * compptr->h_samp_factor;
221 y_crop_blocks = y_crop_offset * compptr->v_samp_factor; 222 y_crop_blocks = y_crop_offset * compptr->v_samp_factor;
222 for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks; 223 for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
223 » dst_blk_y += compptr->v_samp_factor) { 224 dst_blk_y += compptr->v_samp_factor) {
224 dst_buffer = (*srcinfo->mem->access_virt_barray) 225 dst_buffer = (*srcinfo->mem->access_virt_barray)
225 » ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y, 226 ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
226 » (JDIMENSION) compptr->v_samp_factor, TRUE); 227 (JDIMENSION) compptr->v_samp_factor, TRUE);
227 src_buffer = (*srcinfo->mem->access_virt_barray) 228 src_buffer = (*srcinfo->mem->access_virt_barray)
228 » ((j_common_ptr) srcinfo, src_coef_arrays[ci], 229 ((j_common_ptr) srcinfo, src_coef_arrays[ci],
229 » dst_blk_y + y_crop_blocks, 230 dst_blk_y + y_crop_blocks,
230 » (JDIMENSION) compptr->v_samp_factor, FALSE); 231 (JDIMENSION) compptr->v_samp_factor, FALSE);
231 for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) { 232 for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
232 » dst_row_ptr = dst_buffer[offset_y]; 233 dst_row_ptr = dst_buffer[offset_y];
233 » src_row_ptr = src_buffer[offset_y]; 234 src_row_ptr = src_buffer[offset_y];
234 » for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks; dst_blk_x++) { 235 for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks; dst_blk_x++) {
235 » if (x_crop_blocks + dst_blk_x < comp_width) { 236 if (x_crop_blocks + dst_blk_x < comp_width) {
236 » /* Do the mirrorable blocks */ 237 /* Do the mirrorable blocks */
237 » dst_ptr = dst_row_ptr[dst_blk_x]; 238 dst_ptr = dst_row_ptr[dst_blk_x];
238 » src_ptr = src_row_ptr[comp_width - x_crop_blocks - dst_blk_x - 1]; 239 src_ptr = src_row_ptr[comp_width - x_crop_blocks - dst_blk_x - 1];
239 » /* this unrolled loop doesn't need to know which row it's on... */ 240 /* this unrolled loop doesn't need to know which row it's on... */
240 » for (k = 0; k < DCTSIZE2; k += 2) { 241 for (k = 0; k < DCTSIZE2; k += 2) {
241 » *dst_ptr++ = *src_ptr++;» /* copy even column */ 242 *dst_ptr++ = *src_ptr++; /* copy even column */
242 » *dst_ptr++ = - *src_ptr++; /* copy odd column with sign change */ 243 *dst_ptr++ = - *src_ptr++; /* copy odd column with sign change */
243 » } 244 }
244 » } else { 245 } else {
245 » /* Copy last partial block(s) verbatim */ 246 /* Copy last partial block(s) verbatim */
246 » jcopy_block_row(src_row_ptr + dst_blk_x + x_crop_blocks, 247 jcopy_block_row(src_row_ptr + dst_blk_x + x_crop_blocks,
247 » » » dst_row_ptr + dst_blk_x, 248 dst_row_ptr + dst_blk_x,
248 » » » (JDIMENSION) 1); 249 (JDIMENSION) 1);
249 » } 250 }
250 » } 251 }
251 } 252 }
252 } 253 }
253 } 254 }
254 } 255 }
255 256
256 257
257 LOCAL(void) 258 LOCAL(void)
258 do_flip_v (j_decompress_ptr srcinfo, j_compress_ptr dstinfo, 259 do_flip_v (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
259 » JDIMENSION x_crop_offset, JDIMENSION y_crop_offset, 260 JDIMENSION x_crop_offset, JDIMENSION y_crop_offset,
260 » jvirt_barray_ptr *src_coef_arrays, 261 jvirt_barray_ptr *src_coef_arrays,
261 » jvirt_barray_ptr *dst_coef_arrays) 262 jvirt_barray_ptr *dst_coef_arrays)
262 /* Vertical flip */ 263 /* Vertical flip */
263 { 264 {
264 JDIMENSION MCU_rows, comp_height, dst_blk_x, dst_blk_y; 265 JDIMENSION MCU_rows, comp_height, dst_blk_x, dst_blk_y;
265 JDIMENSION x_crop_blocks, y_crop_blocks; 266 JDIMENSION x_crop_blocks, y_crop_blocks;
266 int ci, i, j, offset_y; 267 int ci, i, j, offset_y;
267 JBLOCKARRAY src_buffer, dst_buffer; 268 JBLOCKARRAY src_buffer, dst_buffer;
268 JBLOCKROW src_row_ptr, dst_row_ptr; 269 JBLOCKROW src_row_ptr, dst_row_ptr;
269 JCOEFPTR src_ptr, dst_ptr; 270 JCOEFPTR src_ptr, dst_ptr;
270 jpeg_component_info *compptr; 271 jpeg_component_info *compptr;
271 272
272 /* We output into a separate array because we can't touch different 273 /* We output into a separate array because we can't touch different
273 * rows of the source virtual array simultaneously. Otherwise, this 274 * rows of the source virtual array simultaneously. Otherwise, this
274 * is a pretty straightforward analog of horizontal flip. 275 * is a pretty straightforward analog of horizontal flip.
275 * Within a DCT block, vertical mirroring is done by changing the signs 276 * Within a DCT block, vertical mirroring is done by changing the signs
276 * of odd-numbered rows. 277 * of odd-numbered rows.
277 * Partial iMCUs at the bottom edge are copied verbatim. 278 * Partial iMCUs at the bottom edge are copied verbatim.
278 */ 279 */
279 MCU_rows = srcinfo->output_height / 280 MCU_rows = srcinfo->output_height /
280 (dstinfo->max_v_samp_factor * dstinfo_min_DCT_v_scaled_size); 281 (dstinfo->max_v_samp_factor * dstinfo_min_DCT_v_scaled_size);
281 282
282 for (ci = 0; ci < dstinfo->num_components; ci++) { 283 for (ci = 0; ci < dstinfo->num_components; ci++) {
283 compptr = dstinfo->comp_info + ci; 284 compptr = dstinfo->comp_info + ci;
284 comp_height = MCU_rows * compptr->v_samp_factor; 285 comp_height = MCU_rows * compptr->v_samp_factor;
285 x_crop_blocks = x_crop_offset * compptr->h_samp_factor; 286 x_crop_blocks = x_crop_offset * compptr->h_samp_factor;
286 y_crop_blocks = y_crop_offset * compptr->v_samp_factor; 287 y_crop_blocks = y_crop_offset * compptr->v_samp_factor;
287 for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks; 288 for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
288 » dst_blk_y += compptr->v_samp_factor) { 289 dst_blk_y += compptr->v_samp_factor) {
289 dst_buffer = (*srcinfo->mem->access_virt_barray) 290 dst_buffer = (*srcinfo->mem->access_virt_barray)
290 » ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y, 291 ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
291 » (JDIMENSION) compptr->v_samp_factor, TRUE); 292 (JDIMENSION) compptr->v_samp_factor, TRUE);
292 if (y_crop_blocks + dst_blk_y < comp_height) { 293 if (y_crop_blocks + dst_blk_y < comp_height) {
293 » /* Row is within the mirrorable area. */ 294 /* Row is within the mirrorable area. */
294 » src_buffer = (*srcinfo->mem->access_virt_barray) 295 src_buffer = (*srcinfo->mem->access_virt_barray)
295 » ((j_common_ptr) srcinfo, src_coef_arrays[ci], 296 ((j_common_ptr) srcinfo, src_coef_arrays[ci],
296 » comp_height - y_crop_blocks - dst_blk_y - 297 comp_height - y_crop_blocks - dst_blk_y -
297 » (JDIMENSION) compptr->v_samp_factor, 298 (JDIMENSION) compptr->v_samp_factor,
298 » (JDIMENSION) compptr->v_samp_factor, FALSE); 299 (JDIMENSION) compptr->v_samp_factor, FALSE);
299 } else { 300 } else {
300 » /* Bottom-edge blocks will be copied verbatim. */ 301 /* Bottom-edge blocks will be copied verbatim. */
301 » src_buffer = (*srcinfo->mem->access_virt_barray) 302 src_buffer = (*srcinfo->mem->access_virt_barray)
302 » ((j_common_ptr) srcinfo, src_coef_arrays[ci], 303 ((j_common_ptr) srcinfo, src_coef_arrays[ci],
303 » dst_blk_y + y_crop_blocks, 304 dst_blk_y + y_crop_blocks,
304 » (JDIMENSION) compptr->v_samp_factor, FALSE); 305 (JDIMENSION) compptr->v_samp_factor, FALSE);
305 } 306 }
306 for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) { 307 for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
307 » if (y_crop_blocks + dst_blk_y < comp_height) { 308 if (y_crop_blocks + dst_blk_y < comp_height) {
308 » /* Row is within the mirrorable area. */ 309 /* Row is within the mirrorable area. */
309 » dst_row_ptr = dst_buffer[offset_y]; 310 dst_row_ptr = dst_buffer[offset_y];
310 » src_row_ptr = src_buffer[compptr->v_samp_factor - offset_y - 1]; 311 src_row_ptr = src_buffer[compptr->v_samp_factor - offset_y - 1];
311 » src_row_ptr += x_crop_blocks; 312 src_row_ptr += x_crop_blocks;
312 » for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks; 313 for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
313 » dst_blk_x++) { 314 dst_blk_x++) {
314 » dst_ptr = dst_row_ptr[dst_blk_x]; 315 dst_ptr = dst_row_ptr[dst_blk_x];
315 » src_ptr = src_row_ptr[dst_blk_x]; 316 src_ptr = src_row_ptr[dst_blk_x];
316 » for (i = 0; i < DCTSIZE; i += 2) { 317 for (i = 0; i < DCTSIZE; i += 2) {
317 » /* copy even row */ 318 /* copy even row */
318 » for (j = 0; j < DCTSIZE; j++) 319 for (j = 0; j < DCTSIZE; j++)
319 » » *dst_ptr++ = *src_ptr++; 320 *dst_ptr++ = *src_ptr++;
320 » /* copy odd row with sign change */ 321 /* copy odd row with sign change */
321 » for (j = 0; j < DCTSIZE; j++) 322 for (j = 0; j < DCTSIZE; j++)
322 » » *dst_ptr++ = - *src_ptr++; 323 *dst_ptr++ = - *src_ptr++;
323 » } 324 }
324 » } 325 }
325 » } else { 326 } else {
326 » /* Just copy row verbatim. */ 327 /* Just copy row verbatim. */
327 » jcopy_block_row(src_buffer[offset_y] + x_crop_blocks, 328 jcopy_block_row(src_buffer[offset_y] + x_crop_blocks,
328 » » » dst_buffer[offset_y], 329 dst_buffer[offset_y],
329 » » » compptr->width_in_blocks); 330 compptr->width_in_blocks);
330 » } 331 }
331 } 332 }
332 } 333 }
333 } 334 }
334 } 335 }
335 336
336 337
337 LOCAL(void) 338 LOCAL(void)
338 do_transpose (j_decompress_ptr srcinfo, j_compress_ptr dstinfo, 339 do_transpose (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
339 » JDIMENSION x_crop_offset, JDIMENSION y_crop_offset, 340 JDIMENSION x_crop_offset, JDIMENSION y_crop_offset,
340 » jvirt_barray_ptr *src_coef_arrays, 341 jvirt_barray_ptr *src_coef_arrays,
341 » jvirt_barray_ptr *dst_coef_arrays) 342 jvirt_barray_ptr *dst_coef_arrays)
342 /* Transpose source into destination */ 343 /* Transpose source into destination */
343 { 344 {
344 JDIMENSION dst_blk_x, dst_blk_y, x_crop_blocks, y_crop_blocks; 345 JDIMENSION dst_blk_x, dst_blk_y, x_crop_blocks, y_crop_blocks;
345 int ci, i, j, offset_x, offset_y; 346 int ci, i, j, offset_x, offset_y;
346 JBLOCKARRAY src_buffer, dst_buffer; 347 JBLOCKARRAY src_buffer, dst_buffer;
347 JCOEFPTR src_ptr, dst_ptr; 348 JCOEFPTR src_ptr, dst_ptr;
348 jpeg_component_info *compptr; 349 jpeg_component_info *compptr;
349 350
350 /* Transposing pixels within a block just requires transposing the 351 /* Transposing pixels within a block just requires transposing the
351 * DCT coefficients. 352 * DCT coefficients.
352 * Partial iMCUs at the edges require no special treatment; we simply 353 * Partial iMCUs at the edges require no special treatment; we simply
353 * process all the available DCT blocks for every component. 354 * process all the available DCT blocks for every component.
354 */ 355 */
355 for (ci = 0; ci < dstinfo->num_components; ci++) { 356 for (ci = 0; ci < dstinfo->num_components; ci++) {
356 compptr = dstinfo->comp_info + ci; 357 compptr = dstinfo->comp_info + ci;
357 x_crop_blocks = x_crop_offset * compptr->h_samp_factor; 358 x_crop_blocks = x_crop_offset * compptr->h_samp_factor;
358 y_crop_blocks = y_crop_offset * compptr->v_samp_factor; 359 y_crop_blocks = y_crop_offset * compptr->v_samp_factor;
359 for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks; 360 for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
360 » dst_blk_y += compptr->v_samp_factor) { 361 dst_blk_y += compptr->v_samp_factor) {
361 dst_buffer = (*srcinfo->mem->access_virt_barray) 362 dst_buffer = (*srcinfo->mem->access_virt_barray)
362 » ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y, 363 ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
363 » (JDIMENSION) compptr->v_samp_factor, TRUE); 364 (JDIMENSION) compptr->v_samp_factor, TRUE);
364 for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) { 365 for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
365 » for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks; 366 for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
366 » dst_blk_x += compptr->h_samp_factor) { 367 dst_blk_x += compptr->h_samp_factor) {
367 » src_buffer = (*srcinfo->mem->access_virt_barray) 368 src_buffer = (*srcinfo->mem->access_virt_barray)
368 » ((j_common_ptr) srcinfo, src_coef_arrays[ci], 369 ((j_common_ptr) srcinfo, src_coef_arrays[ci],
369 » dst_blk_x + x_crop_blocks, 370 dst_blk_x + x_crop_blocks,
370 » (JDIMENSION) compptr->h_samp_factor, FALSE); 371 (JDIMENSION) compptr->h_samp_factor, FALSE);
371 » for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) { 372 for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) {
372 » dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x]; 373 dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
373 » src_ptr = src_buffer[offset_x][dst_blk_y + offset_y + y_crop_blocks] ; 374 src_ptr = src_buffer[offset_x][dst_blk_y + offset_y + y_crop_blocks] ;
374 » for (i = 0; i < DCTSIZE; i++) 375 for (i = 0; i < DCTSIZE; i++)
375 » for (j = 0; j < DCTSIZE; j++) 376 for (j = 0; j < DCTSIZE; j++)
376 » » dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j]; 377 dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
377 » } 378 }
378 » } 379 }
379 } 380 }
380 } 381 }
381 } 382 }
382 } 383 }
383 384
384 385
385 LOCAL(void) 386 LOCAL(void)
386 do_rot_90 (j_decompress_ptr srcinfo, j_compress_ptr dstinfo, 387 do_rot_90 (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
387 » JDIMENSION x_crop_offset, JDIMENSION y_crop_offset, 388 JDIMENSION x_crop_offset, JDIMENSION y_crop_offset,
388 » jvirt_barray_ptr *src_coef_arrays, 389 jvirt_barray_ptr *src_coef_arrays,
389 » jvirt_barray_ptr *dst_coef_arrays) 390 jvirt_barray_ptr *dst_coef_arrays)
390 /* 90 degree rotation is equivalent to 391 /* 90 degree rotation is equivalent to
391 * 1. Transposing the image; 392 * 1. Transposing the image;
392 * 2. Horizontal mirroring. 393 * 2. Horizontal mirroring.
393 * These two steps are merged into a single processing routine. 394 * These two steps are merged into a single processing routine.
394 */ 395 */
395 { 396 {
396 JDIMENSION MCU_cols, comp_width, dst_blk_x, dst_blk_y; 397 JDIMENSION MCU_cols, comp_width, dst_blk_x, dst_blk_y;
397 JDIMENSION x_crop_blocks, y_crop_blocks; 398 JDIMENSION x_crop_blocks, y_crop_blocks;
398 int ci, i, j, offset_x, offset_y; 399 int ci, i, j, offset_x, offset_y;
399 JBLOCKARRAY src_buffer, dst_buffer; 400 JBLOCKARRAY src_buffer, dst_buffer;
400 JCOEFPTR src_ptr, dst_ptr; 401 JCOEFPTR src_ptr, dst_ptr;
401 jpeg_component_info *compptr; 402 jpeg_component_info *compptr;
402 403
403 /* Because of the horizontal mirror step, we can't process partial iMCUs 404 /* Because of the horizontal mirror step, we can't process partial iMCUs
404 * at the (output) right edge properly. They just get transposed and 405 * at the (output) right edge properly. They just get transposed and
405 * not mirrored. 406 * not mirrored.
406 */ 407 */
407 MCU_cols = srcinfo->output_height / 408 MCU_cols = srcinfo->output_height /
408 (dstinfo->max_h_samp_factor * dstinfo_min_DCT_h_scaled_size); 409 (dstinfo->max_h_samp_factor * dstinfo_min_DCT_h_scaled_size);
409 410
410 for (ci = 0; ci < dstinfo->num_components; ci++) { 411 for (ci = 0; ci < dstinfo->num_components; ci++) {
411 compptr = dstinfo->comp_info + ci; 412 compptr = dstinfo->comp_info + ci;
412 comp_width = MCU_cols * compptr->h_samp_factor; 413 comp_width = MCU_cols * compptr->h_samp_factor;
413 x_crop_blocks = x_crop_offset * compptr->h_samp_factor; 414 x_crop_blocks = x_crop_offset * compptr->h_samp_factor;
414 y_crop_blocks = y_crop_offset * compptr->v_samp_factor; 415 y_crop_blocks = y_crop_offset * compptr->v_samp_factor;
415 for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks; 416 for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
416 » dst_blk_y += compptr->v_samp_factor) { 417 dst_blk_y += compptr->v_samp_factor) {
417 dst_buffer = (*srcinfo->mem->access_virt_barray) 418 dst_buffer = (*srcinfo->mem->access_virt_barray)
418 » ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y, 419 ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
419 » (JDIMENSION) compptr->v_samp_factor, TRUE); 420 (JDIMENSION) compptr->v_samp_factor, TRUE);
420 for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) { 421 for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
421 » for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks; 422 for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
422 » dst_blk_x += compptr->h_samp_factor) { 423 dst_blk_x += compptr->h_samp_factor) {
423 » if (x_crop_blocks + dst_blk_x < comp_width) { 424 if (x_crop_blocks + dst_blk_x < comp_width) {
424 » /* Block is within the mirrorable area. */ 425 /* Block is within the mirrorable area. */
425 » src_buffer = (*srcinfo->mem->access_virt_barray) 426 src_buffer = (*srcinfo->mem->access_virt_barray)
426 » ((j_common_ptr) srcinfo, src_coef_arrays[ci], 427 ((j_common_ptr) srcinfo, src_coef_arrays[ci],
427 » comp_width - x_crop_blocks - dst_blk_x - 428 comp_width - x_crop_blocks - dst_blk_x -
428 » (JDIMENSION) compptr->h_samp_factor, 429 (JDIMENSION) compptr->h_samp_factor,
429 » (JDIMENSION) compptr->h_samp_factor, FALSE); 430 (JDIMENSION) compptr->h_samp_factor, FALSE);
430 » } else { 431 } else {
431 » /* Edge blocks are transposed but not mirrored. */ 432 /* Edge blocks are transposed but not mirrored. */
432 » src_buffer = (*srcinfo->mem->access_virt_barray) 433 src_buffer = (*srcinfo->mem->access_virt_barray)
433 » ((j_common_ptr) srcinfo, src_coef_arrays[ci], 434 ((j_common_ptr) srcinfo, src_coef_arrays[ci],
434 » dst_blk_x + x_crop_blocks, 435 dst_blk_x + x_crop_blocks,
435 » (JDIMENSION) compptr->h_samp_factor, FALSE); 436 (JDIMENSION) compptr->h_samp_factor, FALSE);
436 » } 437 }
437 » for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) { 438 for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) {
438 » dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x]; 439 dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
439 » if (x_crop_blocks + dst_blk_x < comp_width) { 440 if (x_crop_blocks + dst_blk_x < comp_width) {
440 » /* Block is within the mirrorable area. */ 441 /* Block is within the mirrorable area. */
441 » src_ptr = src_buffer[compptr->h_samp_factor - offset_x - 1] 442 src_ptr = src_buffer[compptr->h_samp_factor - offset_x - 1]
442 » » [dst_blk_y + offset_y + y_crop_blocks]; 443 [dst_blk_y + offset_y + y_crop_blocks];
443 » for (i = 0; i < DCTSIZE; i++) { 444 for (i = 0; i < DCTSIZE; i++) {
444 » » for (j = 0; j < DCTSIZE; j++) 445 for (j = 0; j < DCTSIZE; j++)
445 » » dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j]; 446 dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
446 » » i++; 447 i++;
447 » » for (j = 0; j < DCTSIZE; j++) 448 for (j = 0; j < DCTSIZE; j++)
448 » » dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j]; 449 dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
449 » } 450 }
450 » } else { 451 } else {
451 » /* Edge blocks are transposed but not mirrored. */ 452 /* Edge blocks are transposed but not mirrored. */
452 » src_ptr = src_buffer[offset_x] 453 src_ptr = src_buffer[offset_x]
453 » » [dst_blk_y + offset_y + y_crop_blocks]; 454 [dst_blk_y + offset_y + y_crop_blocks];
454 » for (i = 0; i < DCTSIZE; i++) 455 for (i = 0; i < DCTSIZE; i++)
455 » » for (j = 0; j < DCTSIZE; j++) 456 for (j = 0; j < DCTSIZE; j++)
456 » » dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j]; 457 dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
457 » } 458 }
458 » } 459 }
459 » } 460 }
460 } 461 }
461 } 462 }
462 } 463 }
463 } 464 }
464 465
465 466
466 LOCAL(void) 467 LOCAL(void)
467 do_rot_270 (j_decompress_ptr srcinfo, j_compress_ptr dstinfo, 468 do_rot_270 (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
468 » JDIMENSION x_crop_offset, JDIMENSION y_crop_offset, 469 JDIMENSION x_crop_offset, JDIMENSION y_crop_offset,
469 » jvirt_barray_ptr *src_coef_arrays, 470 jvirt_barray_ptr *src_coef_arrays,
470 » jvirt_barray_ptr *dst_coef_arrays) 471 jvirt_barray_ptr *dst_coef_arrays)
471 /* 270 degree rotation is equivalent to 472 /* 270 degree rotation is equivalent to
472 * 1. Horizontal mirroring; 473 * 1. Horizontal mirroring;
473 * 2. Transposing the image. 474 * 2. Transposing the image.
474 * These two steps are merged into a single processing routine. 475 * These two steps are merged into a single processing routine.
475 */ 476 */
476 { 477 {
477 JDIMENSION MCU_rows, comp_height, dst_blk_x, dst_blk_y; 478 JDIMENSION MCU_rows, comp_height, dst_blk_x, dst_blk_y;
478 JDIMENSION x_crop_blocks, y_crop_blocks; 479 JDIMENSION x_crop_blocks, y_crop_blocks;
479 int ci, i, j, offset_x, offset_y; 480 int ci, i, j, offset_x, offset_y;
480 JBLOCKARRAY src_buffer, dst_buffer; 481 JBLOCKARRAY src_buffer, dst_buffer;
481 JCOEFPTR src_ptr, dst_ptr; 482 JCOEFPTR src_ptr, dst_ptr;
482 jpeg_component_info *compptr; 483 jpeg_component_info *compptr;
483 484
484 /* Because of the horizontal mirror step, we can't process partial iMCUs 485 /* Because of the horizontal mirror step, we can't process partial iMCUs
485 * at the (output) bottom edge properly. They just get transposed and 486 * at the (output) bottom edge properly. They just get transposed and
486 * not mirrored. 487 * not mirrored.
487 */ 488 */
488 MCU_rows = srcinfo->output_width / 489 MCU_rows = srcinfo->output_width /
489 (dstinfo->max_v_samp_factor * dstinfo_min_DCT_v_scaled_size); 490 (dstinfo->max_v_samp_factor * dstinfo_min_DCT_v_scaled_size);
490 491
491 for (ci = 0; ci < dstinfo->num_components; ci++) { 492 for (ci = 0; ci < dstinfo->num_components; ci++) {
492 compptr = dstinfo->comp_info + ci; 493 compptr = dstinfo->comp_info + ci;
493 comp_height = MCU_rows * compptr->v_samp_factor; 494 comp_height = MCU_rows * compptr->v_samp_factor;
494 x_crop_blocks = x_crop_offset * compptr->h_samp_factor; 495 x_crop_blocks = x_crop_offset * compptr->h_samp_factor;
495 y_crop_blocks = y_crop_offset * compptr->v_samp_factor; 496 y_crop_blocks = y_crop_offset * compptr->v_samp_factor;
496 for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks; 497 for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
497 » dst_blk_y += compptr->v_samp_factor) { 498 dst_blk_y += compptr->v_samp_factor) {
498 dst_buffer = (*srcinfo->mem->access_virt_barray) 499 dst_buffer = (*srcinfo->mem->access_virt_barray)
499 » ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y, 500 ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
500 » (JDIMENSION) compptr->v_samp_factor, TRUE); 501 (JDIMENSION) compptr->v_samp_factor, TRUE);
501 for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) { 502 for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
502 » for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks; 503 for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
503 » dst_blk_x += compptr->h_samp_factor) { 504 dst_blk_x += compptr->h_samp_factor) {
504 » src_buffer = (*srcinfo->mem->access_virt_barray) 505 src_buffer = (*srcinfo->mem->access_virt_barray)
505 » ((j_common_ptr) srcinfo, src_coef_arrays[ci], 506 ((j_common_ptr) srcinfo, src_coef_arrays[ci],
506 » dst_blk_x + x_crop_blocks, 507 dst_blk_x + x_crop_blocks,
507 » (JDIMENSION) compptr->h_samp_factor, FALSE); 508 (JDIMENSION) compptr->h_samp_factor, FALSE);
508 » for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) { 509 for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) {
509 » dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x]; 510 dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
510 » if (y_crop_blocks + dst_blk_y < comp_height) { 511 if (y_crop_blocks + dst_blk_y < comp_height) {
511 » /* Block is within the mirrorable area. */ 512 /* Block is within the mirrorable area. */
512 » src_ptr = src_buffer[offset_x] 513 src_ptr = src_buffer[offset_x]
513 » » [comp_height - y_crop_blocks - dst_blk_y - offset_y - 1]; 514 [comp_height - y_crop_blocks - dst_blk_y - offset_y - 1];
514 » for (i = 0; i < DCTSIZE; i++) { 515 for (i = 0; i < DCTSIZE; i++) {
515 » » for (j = 0; j < DCTSIZE; j++) { 516 for (j = 0; j < DCTSIZE; j++) {
516 » » dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j]; 517 dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
517 » » j++; 518 j++;
518 » » dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j]; 519 dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
519 » » } 520 }
520 » } 521 }
521 » } else { 522 } else {
522 » /* Edge blocks are transposed but not mirrored. */ 523 /* Edge blocks are transposed but not mirrored. */
523 » src_ptr = src_buffer[offset_x] 524 src_ptr = src_buffer[offset_x]
524 » » [dst_blk_y + offset_y + y_crop_blocks]; 525 [dst_blk_y + offset_y + y_crop_blocks];
525 » for (i = 0; i < DCTSIZE; i++) 526 for (i = 0; i < DCTSIZE; i++)
526 » » for (j = 0; j < DCTSIZE; j++) 527 for (j = 0; j < DCTSIZE; j++)
527 » » dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j]; 528 dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
528 » } 529 }
529 » } 530 }
530 » } 531 }
531 } 532 }
532 } 533 }
533 } 534 }
534 } 535 }
535 536
536 537
537 LOCAL(void) 538 LOCAL(void)
538 do_rot_180 (j_decompress_ptr srcinfo, j_compress_ptr dstinfo, 539 do_rot_180 (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
539 » JDIMENSION x_crop_offset, JDIMENSION y_crop_offset, 540 JDIMENSION x_crop_offset, JDIMENSION y_crop_offset,
540 » jvirt_barray_ptr *src_coef_arrays, 541 jvirt_barray_ptr *src_coef_arrays,
541 » jvirt_barray_ptr *dst_coef_arrays) 542 jvirt_barray_ptr *dst_coef_arrays)
542 /* 180 degree rotation is equivalent to 543 /* 180 degree rotation is equivalent to
543 * 1. Vertical mirroring; 544 * 1. Vertical mirroring;
544 * 2. Horizontal mirroring. 545 * 2. Horizontal mirroring.
545 * These two steps are merged into a single processing routine. 546 * These two steps are merged into a single processing routine.
546 */ 547 */
547 { 548 {
548 JDIMENSION MCU_cols, MCU_rows, comp_width, comp_height, dst_blk_x, dst_blk_y; 549 JDIMENSION MCU_cols, MCU_rows, comp_width, comp_height, dst_blk_x, dst_blk_y;
549 JDIMENSION x_crop_blocks, y_crop_blocks; 550 JDIMENSION x_crop_blocks, y_crop_blocks;
550 int ci, i, j, offset_y; 551 int ci, i, j, offset_y;
551 JBLOCKARRAY src_buffer, dst_buffer; 552 JBLOCKARRAY src_buffer, dst_buffer;
552 JBLOCKROW src_row_ptr, dst_row_ptr; 553 JBLOCKROW src_row_ptr, dst_row_ptr;
553 JCOEFPTR src_ptr, dst_ptr; 554 JCOEFPTR src_ptr, dst_ptr;
554 jpeg_component_info *compptr; 555 jpeg_component_info *compptr;
555 556
556 MCU_cols = srcinfo->output_width / 557 MCU_cols = srcinfo->output_width /
557 (dstinfo->max_h_samp_factor * dstinfo_min_DCT_h_scaled_size); 558 (dstinfo->max_h_samp_factor * dstinfo_min_DCT_h_scaled_size);
558 MCU_rows = srcinfo->output_height / 559 MCU_rows = srcinfo->output_height /
559 (dstinfo->max_v_samp_factor * dstinfo_min_DCT_v_scaled_size); 560 (dstinfo->max_v_samp_factor * dstinfo_min_DCT_v_scaled_size);
560 561
561 for (ci = 0; ci < dstinfo->num_components; ci++) { 562 for (ci = 0; ci < dstinfo->num_components; ci++) {
562 compptr = dstinfo->comp_info + ci; 563 compptr = dstinfo->comp_info + ci;
563 comp_width = MCU_cols * compptr->h_samp_factor; 564 comp_width = MCU_cols * compptr->h_samp_factor;
564 comp_height = MCU_rows * compptr->v_samp_factor; 565 comp_height = MCU_rows * compptr->v_samp_factor;
565 x_crop_blocks = x_crop_offset * compptr->h_samp_factor; 566 x_crop_blocks = x_crop_offset * compptr->h_samp_factor;
566 y_crop_blocks = y_crop_offset * compptr->v_samp_factor; 567 y_crop_blocks = y_crop_offset * compptr->v_samp_factor;
567 for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks; 568 for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
568 » dst_blk_y += compptr->v_samp_factor) { 569 dst_blk_y += compptr->v_samp_factor) {
569 dst_buffer = (*srcinfo->mem->access_virt_barray) 570 dst_buffer = (*srcinfo->mem->access_virt_barray)
570 » ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y, 571 ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
571 » (JDIMENSION) compptr->v_samp_factor, TRUE); 572 (JDIMENSION) compptr->v_samp_factor, TRUE);
572 if (y_crop_blocks + dst_blk_y < comp_height) { 573 if (y_crop_blocks + dst_blk_y < comp_height) {
573 » /* Row is within the vertically mirrorable area. */ 574 /* Row is within the vertically mirrorable area. */
574 » src_buffer = (*srcinfo->mem->access_virt_barray) 575 src_buffer = (*srcinfo->mem->access_virt_barray)
575 » ((j_common_ptr) srcinfo, src_coef_arrays[ci], 576 ((j_common_ptr) srcinfo, src_coef_arrays[ci],
576 » comp_height - y_crop_blocks - dst_blk_y - 577 comp_height - y_crop_blocks - dst_blk_y -
577 » (JDIMENSION) compptr->v_samp_factor, 578 (JDIMENSION) compptr->v_samp_factor,
578 » (JDIMENSION) compptr->v_samp_factor, FALSE); 579 (JDIMENSION) compptr->v_samp_factor, FALSE);
579 } else { 580 } else {
580 » /* Bottom-edge rows are only mirrored horizontally. */ 581 /* Bottom-edge rows are only mirrored horizontally. */
581 » src_buffer = (*srcinfo->mem->access_virt_barray) 582 src_buffer = (*srcinfo->mem->access_virt_barray)
582 » ((j_common_ptr) srcinfo, src_coef_arrays[ci], 583 ((j_common_ptr) srcinfo, src_coef_arrays[ci],
583 » dst_blk_y + y_crop_blocks, 584 dst_blk_y + y_crop_blocks,
584 » (JDIMENSION) compptr->v_samp_factor, FALSE); 585 (JDIMENSION) compptr->v_samp_factor, FALSE);
585 } 586 }
586 for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) { 587 for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
587 » dst_row_ptr = dst_buffer[offset_y]; 588 dst_row_ptr = dst_buffer[offset_y];
588 » if (y_crop_blocks + dst_blk_y < comp_height) { 589 if (y_crop_blocks + dst_blk_y < comp_height) {
589 » /* Row is within the mirrorable area. */ 590 /* Row is within the mirrorable area. */
590 » src_row_ptr = src_buffer[compptr->v_samp_factor - offset_y - 1]; 591 src_row_ptr = src_buffer[compptr->v_samp_factor - offset_y - 1];
591 » for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks; dst_blk_x++) { 592 for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks; dst_blk_x++) {
592 » dst_ptr = dst_row_ptr[dst_blk_x]; 593 dst_ptr = dst_row_ptr[dst_blk_x];
593 » if (x_crop_blocks + dst_blk_x < comp_width) { 594 if (x_crop_blocks + dst_blk_x < comp_width) {
594 » /* Process the blocks that can be mirrored both ways. */ 595 /* Process the blocks that can be mirrored both ways. */
595 » src_ptr = src_row_ptr[comp_width - x_crop_blocks - dst_blk_x - 1]; 596 src_ptr = src_row_ptr[comp_width - x_crop_blocks - dst_blk_x - 1];
596 » for (i = 0; i < DCTSIZE; i += 2) { 597 for (i = 0; i < DCTSIZE; i += 2) {
597 » » /* For even row, negate every odd column. */ 598 /* For even row, negate every odd column. */
598 » » for (j = 0; j < DCTSIZE; j += 2) { 599 for (j = 0; j < DCTSIZE; j += 2) {
599 » » *dst_ptr++ = *src_ptr++; 600 *dst_ptr++ = *src_ptr++;
600 » » *dst_ptr++ = - *src_ptr++; 601 *dst_ptr++ = - *src_ptr++;
601 » » } 602 }
602 » » /* For odd row, negate every even column. */ 603 /* For odd row, negate every even column. */
603 » » for (j = 0; j < DCTSIZE; j += 2) { 604 for (j = 0; j < DCTSIZE; j += 2) {
604 » » *dst_ptr++ = - *src_ptr++; 605 *dst_ptr++ = - *src_ptr++;
605 » » *dst_ptr++ = *src_ptr++; 606 *dst_ptr++ = *src_ptr++;
606 » » } 607 }
607 » } 608 }
608 » } else { 609 } else {
609 » /* Any remaining right-edge blocks are only mirrored vertically. * / 610 /* Any remaining right-edge blocks are only mirrored vertically. * /
610 » src_ptr = src_row_ptr[x_crop_blocks + dst_blk_x]; 611 src_ptr = src_row_ptr[x_crop_blocks + dst_blk_x];
611 » for (i = 0; i < DCTSIZE; i += 2) { 612 for (i = 0; i < DCTSIZE; i += 2) {
612 » » for (j = 0; j < DCTSIZE; j++) 613 for (j = 0; j < DCTSIZE; j++)
613 » » *dst_ptr++ = *src_ptr++; 614 *dst_ptr++ = *src_ptr++;
614 » » for (j = 0; j < DCTSIZE; j++) 615 for (j = 0; j < DCTSIZE; j++)
615 » » *dst_ptr++ = - *src_ptr++; 616 *dst_ptr++ = - *src_ptr++;
616 » } 617 }
617 » } 618 }
618 » } 619 }
619 » } else { 620 } else {
620 » /* Remaining rows are just mirrored horizontally. */ 621 /* Remaining rows are just mirrored horizontally. */
621 » src_row_ptr = src_buffer[offset_y]; 622 src_row_ptr = src_buffer[offset_y];
622 » for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks; dst_blk_x++) { 623 for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks; dst_blk_x++) {
623 » if (x_crop_blocks + dst_blk_x < comp_width) { 624 if (x_crop_blocks + dst_blk_x < comp_width) {
624 » /* Process the blocks that can be mirrored. */ 625 /* Process the blocks that can be mirrored. */
625 » dst_ptr = dst_row_ptr[dst_blk_x]; 626 dst_ptr = dst_row_ptr[dst_blk_x];
626 » src_ptr = src_row_ptr[comp_width - x_crop_blocks - dst_blk_x - 1]; 627 src_ptr = src_row_ptr[comp_width - x_crop_blocks - dst_blk_x - 1];
627 » for (i = 0; i < DCTSIZE2; i += 2) { 628 for (i = 0; i < DCTSIZE2; i += 2) {
628 » » *dst_ptr++ = *src_ptr++; 629 *dst_ptr++ = *src_ptr++;
629 » » *dst_ptr++ = - *src_ptr++; 630 *dst_ptr++ = - *src_ptr++;
630 » } 631 }
631 » } else { 632 } else {
632 » /* Any remaining right-edge blocks are only copied. */ 633 /* Any remaining right-edge blocks are only copied. */
633 » jcopy_block_row(src_row_ptr + dst_blk_x + x_crop_blocks, 634 jcopy_block_row(src_row_ptr + dst_blk_x + x_crop_blocks,
634 » » » dst_row_ptr + dst_blk_x, 635 dst_row_ptr + dst_blk_x,
635 » » » (JDIMENSION) 1); 636 (JDIMENSION) 1);
636 » } 637 }
637 » } 638 }
638 » } 639 }
639 } 640 }
640 } 641 }
641 } 642 }
642 } 643 }
643 644
644 645
645 LOCAL(void) 646 LOCAL(void)
646 do_transverse (j_decompress_ptr srcinfo, j_compress_ptr dstinfo, 647 do_transverse (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
647 » JDIMENSION x_crop_offset, JDIMENSION y_crop_offset, 648 JDIMENSION x_crop_offset, JDIMENSION y_crop_offset,
648 » jvirt_barray_ptr *src_coef_arrays, 649 jvirt_barray_ptr *src_coef_arrays,
649 » jvirt_barray_ptr *dst_coef_arrays) 650 jvirt_barray_ptr *dst_coef_arrays)
650 /* Transverse transpose is equivalent to 651 /* Transverse transpose is equivalent to
651 * 1. 180 degree rotation; 652 * 1. 180 degree rotation;
652 * 2. Transposition; 653 * 2. Transposition;
653 * or 654 * or
654 * 1. Horizontal mirroring; 655 * 1. Horizontal mirroring;
655 * 2. Transposition; 656 * 2. Transposition;
656 * 3. Horizontal mirroring. 657 * 3. Horizontal mirroring.
657 * These steps are merged into a single processing routine. 658 * These steps are merged into a single processing routine.
658 */ 659 */
659 { 660 {
660 JDIMENSION MCU_cols, MCU_rows, comp_width, comp_height, dst_blk_x, dst_blk_y; 661 JDIMENSION MCU_cols, MCU_rows, comp_width, comp_height, dst_blk_x, dst_blk_y;
661 JDIMENSION x_crop_blocks, y_crop_blocks; 662 JDIMENSION x_crop_blocks, y_crop_blocks;
662 int ci, i, j, offset_x, offset_y; 663 int ci, i, j, offset_x, offset_y;
663 JBLOCKARRAY src_buffer, dst_buffer; 664 JBLOCKARRAY src_buffer, dst_buffer;
664 JCOEFPTR src_ptr, dst_ptr; 665 JCOEFPTR src_ptr, dst_ptr;
665 jpeg_component_info *compptr; 666 jpeg_component_info *compptr;
666 667
667 MCU_cols = srcinfo->output_height / 668 MCU_cols = srcinfo->output_height /
668 (dstinfo->max_h_samp_factor * dstinfo_min_DCT_h_scaled_size); 669 (dstinfo->max_h_samp_factor * dstinfo_min_DCT_h_scaled_size);
669 MCU_rows = srcinfo->output_width / 670 MCU_rows = srcinfo->output_width /
670 (dstinfo->max_v_samp_factor * dstinfo_min_DCT_v_scaled_size); 671 (dstinfo->max_v_samp_factor * dstinfo_min_DCT_v_scaled_size);
671 672
672 for (ci = 0; ci < dstinfo->num_components; ci++) { 673 for (ci = 0; ci < dstinfo->num_components; ci++) {
673 compptr = dstinfo->comp_info + ci; 674 compptr = dstinfo->comp_info + ci;
674 comp_width = MCU_cols * compptr->h_samp_factor; 675 comp_width = MCU_cols * compptr->h_samp_factor;
675 comp_height = MCU_rows * compptr->v_samp_factor; 676 comp_height = MCU_rows * compptr->v_samp_factor;
676 x_crop_blocks = x_crop_offset * compptr->h_samp_factor; 677 x_crop_blocks = x_crop_offset * compptr->h_samp_factor;
677 y_crop_blocks = y_crop_offset * compptr->v_samp_factor; 678 y_crop_blocks = y_crop_offset * compptr->v_samp_factor;
678 for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks; 679 for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
679 » dst_blk_y += compptr->v_samp_factor) { 680 dst_blk_y += compptr->v_samp_factor) {
680 dst_buffer = (*srcinfo->mem->access_virt_barray) 681 dst_buffer = (*srcinfo->mem->access_virt_barray)
681 » ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y, 682 ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
682 » (JDIMENSION) compptr->v_samp_factor, TRUE); 683 (JDIMENSION) compptr->v_samp_factor, TRUE);
683 for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) { 684 for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
684 » for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks; 685 for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
685 » dst_blk_x += compptr->h_samp_factor) { 686 dst_blk_x += compptr->h_samp_factor) {
686 » if (x_crop_blocks + dst_blk_x < comp_width) { 687 if (x_crop_blocks + dst_blk_x < comp_width) {
687 » /* Block is within the mirrorable area. */ 688 /* Block is within the mirrorable area. */
688 » src_buffer = (*srcinfo->mem->access_virt_barray) 689 src_buffer = (*srcinfo->mem->access_virt_barray)
689 » ((j_common_ptr) srcinfo, src_coef_arrays[ci], 690 ((j_common_ptr) srcinfo, src_coef_arrays[ci],
690 » comp_width - x_crop_blocks - dst_blk_x - 691 comp_width - x_crop_blocks - dst_blk_x -
691 » (JDIMENSION) compptr->h_samp_factor, 692 (JDIMENSION) compptr->h_samp_factor,
692 » (JDIMENSION) compptr->h_samp_factor, FALSE); 693 (JDIMENSION) compptr->h_samp_factor, FALSE);
693 » } else { 694 } else {
694 » src_buffer = (*srcinfo->mem->access_virt_barray) 695 src_buffer = (*srcinfo->mem->access_virt_barray)
695 » ((j_common_ptr) srcinfo, src_coef_arrays[ci], 696 ((j_common_ptr) srcinfo, src_coef_arrays[ci],
696 » dst_blk_x + x_crop_blocks, 697 dst_blk_x + x_crop_blocks,
697 » (JDIMENSION) compptr->h_samp_factor, FALSE); 698 (JDIMENSION) compptr->h_samp_factor, FALSE);
698 » } 699 }
699 » for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) { 700 for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) {
700 » dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x]; 701 dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
701 » if (y_crop_blocks + dst_blk_y < comp_height) { 702 if (y_crop_blocks + dst_blk_y < comp_height) {
702 » if (x_crop_blocks + dst_blk_x < comp_width) { 703 if (x_crop_blocks + dst_blk_x < comp_width) {
703 » » /* Block is within the mirrorable area. */ 704 /* Block is within the mirrorable area. */
704 » » src_ptr = src_buffer[compptr->h_samp_factor - offset_x - 1] 705 src_ptr = src_buffer[compptr->h_samp_factor - offset_x - 1]
705 » » [comp_height - y_crop_blocks - dst_blk_y - offset_y - 1]; 706 [comp_height - y_crop_blocks - dst_blk_y - offset_y - 1];
706 » » for (i = 0; i < DCTSIZE; i++) { 707 for (i = 0; i < DCTSIZE; i++) {
707 » » for (j = 0; j < DCTSIZE; j++) { 708 for (j = 0; j < DCTSIZE; j++) {
708 » » dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j]; 709 dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
709 » » j++; 710 j++;
710 » » dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j]; 711 dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
711 » » } 712 }
712 » » i++; 713 i++;
713 » » for (j = 0; j < DCTSIZE; j++) { 714 for (j = 0; j < DCTSIZE; j++) {
714 » » dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j]; 715 dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
715 » » j++; 716 j++;
716 » » dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j]; 717 dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
717 » » } 718 }
718 » » } 719 }
719 » } else { 720 } else {
720 » » /* Right-edge blocks are mirrored in y only */ 721 /* Right-edge blocks are mirrored in y only */
721 » » src_ptr = src_buffer[offset_x] 722 src_ptr = src_buffer[offset_x]
722 » » [comp_height - y_crop_blocks - dst_blk_y - offset_y - 1]; 723 [comp_height - y_crop_blocks - dst_blk_y - offset_y - 1];
723 » » for (i = 0; i < DCTSIZE; i++) { 724 for (i = 0; i < DCTSIZE; i++) {
724 » » for (j = 0; j < DCTSIZE; j++) { 725 for (j = 0; j < DCTSIZE; j++) {
725 » » dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j]; 726 dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
726 » » j++; 727 j++;
727 » » dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j]; 728 dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
728 » » } 729 }
729 » » } 730 }
730 » } 731 }
731 » } else { 732 } else {
732 » if (x_crop_blocks + dst_blk_x < comp_width) { 733 if (x_crop_blocks + dst_blk_x < comp_width) {
733 » » /* Bottom-edge blocks are mirrored in x only */ 734 /* Bottom-edge blocks are mirrored in x only */
734 » » src_ptr = src_buffer[compptr->h_samp_factor - offset_x - 1] 735 src_ptr = src_buffer[compptr->h_samp_factor - offset_x - 1]
735 » » [dst_blk_y + offset_y + y_crop_blocks]; 736 [dst_blk_y + offset_y + y_crop_blocks];
736 » » for (i = 0; i < DCTSIZE; i++) { 737 for (i = 0; i < DCTSIZE; i++) {
737 » » for (j = 0; j < DCTSIZE; j++) 738 for (j = 0; j < DCTSIZE; j++)
738 » » dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j]; 739 dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
739 » » i++; 740 i++;
740 » » for (j = 0; j < DCTSIZE; j++) 741 for (j = 0; j < DCTSIZE; j++)
741 » » dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j]; 742 dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
742 » » } 743 }
743 » } else { 744 } else {
744 » » /* At lower right corner, just transpose, no mirroring */ 745 /* At lower right corner, just transpose, no mirroring */
745 » » src_ptr = src_buffer[offset_x] 746 src_ptr = src_buffer[offset_x]
746 » » [dst_blk_y + offset_y + y_crop_blocks]; 747 [dst_blk_y + offset_y + y_crop_blocks];
747 » » for (i = 0; i < DCTSIZE; i++) 748 for (i = 0; i < DCTSIZE; i++)
748 » » for (j = 0; j < DCTSIZE; j++) 749 for (j = 0; j < DCTSIZE; j++)
749 » » dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j]; 750 dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
750 » } 751 }
751 » } 752 }
752 » } 753 }
753 » } 754 }
754 } 755 }
755 } 756 }
756 } 757 }
757 } 758 }
758 759
759 760
760 /* Parse an unsigned integer: subroutine for jtransform_parse_crop_spec. 761 /* Parse an unsigned integer: subroutine for jtransform_parse_crop_spec.
761 * Returns TRUE if valid integer found, FALSE if not. 762 * Returns TRUE if valid integer found, FALSE if not.
762 * *strptr is advanced over the digit string, and *result is set to its value. 763 * *strptr is advanced over the digit string, and *result is set to its value.
763 */ 764 */
764 765
765 LOCAL(boolean) 766 LOCAL(boolean)
766 jt_read_integer (const char ** strptr, JDIMENSION * result) 767 jt_read_integer (const char **strptr, JDIMENSION *result)
767 { 768 {
768 const char * ptr = *strptr; 769 const char *ptr = *strptr;
769 JDIMENSION val = 0; 770 JDIMENSION val = 0;
770 771
771 for (; isdigit(*ptr); ptr++) { 772 for (; isdigit(*ptr); ptr++) {
772 val = val * 10 + (JDIMENSION) (*ptr - '0'); 773 val = val * 10 + (JDIMENSION) (*ptr - '0');
773 } 774 }
774 *result = val; 775 *result = val;
775 if (ptr == *strptr) 776 if (ptr == *strptr)
776 return FALSE;» » /* oops, no digits */ 777 return FALSE; /* oops, no digits */
777 *strptr = ptr; 778 *strptr = ptr;
778 return TRUE; 779 return TRUE;
779 } 780 }
780 781
781 782
782 /* Parse a crop specification (written in X11 geometry style). 783 /* Parse a crop specification (written in X11 geometry style).
783 * The routine returns TRUE if the spec string is valid, FALSE if not. 784 * The routine returns TRUE if the spec string is valid, FALSE if not.
784 * 785 *
785 * The crop spec string should have the format 786 * The crop spec string should have the format
786 *» <width>[f]x<height>[f]{+-}<xoffset>{+-}<yoffset> 787 * <width>[f]x<height>[f]{+-}<xoffset>{+-}<yoffset>
787 * where width, height, xoffset, and yoffset are unsigned integers. 788 * where width, height, xoffset, and yoffset are unsigned integers.
788 * Each of the elements can be omitted to indicate a default value. 789 * Each of the elements can be omitted to indicate a default value.
789 * (A weakness of this style is that it is not possible to omit xoffset 790 * (A weakness of this style is that it is not possible to omit xoffset
790 * while specifying yoffset, since they look alike.) 791 * while specifying yoffset, since they look alike.)
791 * 792 *
792 * This code is loosely based on XParseGeometry from the X11 distribution. 793 * This code is loosely based on XParseGeometry from the X11 distribution.
793 */ 794 */
794 795
795 GLOBAL(boolean) 796 GLOBAL(boolean)
796 jtransform_parse_crop_spec (jpeg_transform_info *info, const char *spec) 797 jtransform_parse_crop_spec (jpeg_transform_info *info, const char *spec)
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
881 * Hence, this routine must be called after jpeg_read_header (which reads 882 * Hence, this routine must be called after jpeg_read_header (which reads
882 * the image dimensions) and before jpeg_read_coefficients (which realizes 883 * the image dimensions) and before jpeg_read_coefficients (which realizes
883 * the source's virtual arrays). 884 * the source's virtual arrays).
884 * 885 *
885 * This function returns FALSE right away if -perfect is given 886 * This function returns FALSE right away if -perfect is given
886 * and transformation is not perfect. Otherwise returns TRUE. 887 * and transformation is not perfect. Otherwise returns TRUE.
887 */ 888 */
888 889
889 GLOBAL(boolean) 890 GLOBAL(boolean)
890 jtransform_request_workspace (j_decompress_ptr srcinfo, 891 jtransform_request_workspace (j_decompress_ptr srcinfo,
891 » » » jpeg_transform_info *info) 892 jpeg_transform_info *info)
892 { 893 {
893 jvirt_barray_ptr *coef_arrays; 894 jvirt_barray_ptr *coef_arrays;
894 boolean need_workspace, transpose_it; 895 boolean need_workspace, transpose_it;
895 jpeg_component_info *compptr; 896 jpeg_component_info *compptr;
896 JDIMENSION xoffset, yoffset; 897 JDIMENSION xoffset, yoffset;
897 JDIMENSION width_in_iMCUs, height_in_iMCUs; 898 JDIMENSION width_in_iMCUs, height_in_iMCUs;
898 JDIMENSION width_in_blocks, height_in_blocks; 899 JDIMENSION width_in_blocks, height_in_blocks;
899 int ci, h_samp_factor, v_samp_factor; 900 int ci, h_samp_factor, v_samp_factor;
900 901
901 /* Determine number of components in output image */ 902 /* Determine number of components in output image */
(...skipping 12 matching lines...) Expand all
914 #else 915 #else
915 srcinfo->output_width = srcinfo->image_width; 916 srcinfo->output_width = srcinfo->image_width;
916 srcinfo->output_height = srcinfo->image_height; 917 srcinfo->output_height = srcinfo->image_height;
917 #endif 918 #endif
918 919
919 /* Return right away if -perfect is given and transformation is not perfect. 920 /* Return right away if -perfect is given and transformation is not perfect.
920 */ 921 */
921 if (info->perfect) { 922 if (info->perfect) {
922 if (info->num_components == 1) { 923 if (info->num_components == 1) {
923 if (!jtransform_perfect_transform(srcinfo->output_width, 924 if (!jtransform_perfect_transform(srcinfo->output_width,
924 » srcinfo->output_height, 925 srcinfo->output_height,
925 » srcinfo->_min_DCT_h_scaled_size, 926 srcinfo->_min_DCT_h_scaled_size,
926 » srcinfo->_min_DCT_v_scaled_size, 927 srcinfo->_min_DCT_v_scaled_size,
927 » info->transform)) 928 info->transform))
928 » return FALSE; 929 return FALSE;
929 } else { 930 } else {
930 if (!jtransform_perfect_transform(srcinfo->output_width, 931 if (!jtransform_perfect_transform(srcinfo->output_width,
931 » srcinfo->output_height, 932 srcinfo->output_height,
932 » srcinfo->max_h_samp_factor * srcinfo->_min_DCT_h_scaled_size, 933 srcinfo->max_h_samp_factor * srcinfo->_min_DCT_h_scaled_size,
933 » srcinfo->max_v_samp_factor * srcinfo->_min_DCT_v_scaled_size, 934 srcinfo->max_v_samp_factor * srcinfo->_min_DCT_v_scaled_size,
934 » info->transform)) 935 info->transform))
935 » return FALSE; 936 return FALSE;
936 } 937 }
937 } 938 }
938 939
939 /* If there is only one output component, force the iMCU size to be 1; 940 /* If there is only one output component, force the iMCU size to be 1;
940 * else use the source iMCU size. (This allows us to do the right thing 941 * else use the source iMCU size. (This allows us to do the right thing
941 * when reducing color to grayscale, and also provides a handy way of 942 * when reducing color to grayscale, and also provides a handy way of
942 * cleaning up "funny" grayscale images whose sampling factors are not 1x1.) 943 * cleaning up "funny" grayscale images whose sampling factors are not 1x1.)
943 */ 944 */
944 switch (info->transform) { 945 switch (info->transform) {
945 case JXFORM_TRANSPOSE: 946 case JXFORM_TRANSPOSE:
946 case JXFORM_TRANSVERSE: 947 case JXFORM_TRANSVERSE:
947 case JXFORM_ROT_90: 948 case JXFORM_ROT_90:
948 case JXFORM_ROT_270: 949 case JXFORM_ROT_270:
949 info->output_width = srcinfo->output_height; 950 info->output_width = srcinfo->output_height;
950 info->output_height = srcinfo->output_width; 951 info->output_height = srcinfo->output_width;
951 if (info->num_components == 1) { 952 if (info->num_components == 1) {
952 info->iMCU_sample_width = srcinfo->_min_DCT_v_scaled_size; 953 info->iMCU_sample_width = srcinfo->_min_DCT_v_scaled_size;
953 info->iMCU_sample_height = srcinfo->_min_DCT_h_scaled_size; 954 info->iMCU_sample_height = srcinfo->_min_DCT_h_scaled_size;
954 } else { 955 } else {
955 info->iMCU_sample_width = 956 info->iMCU_sample_width =
956 » srcinfo->max_v_samp_factor * srcinfo->_min_DCT_v_scaled_size; 957 srcinfo->max_v_samp_factor * srcinfo->_min_DCT_v_scaled_size;
957 info->iMCU_sample_height = 958 info->iMCU_sample_height =
958 » srcinfo->max_h_samp_factor * srcinfo->_min_DCT_h_scaled_size; 959 srcinfo->max_h_samp_factor * srcinfo->_min_DCT_h_scaled_size;
959 } 960 }
960 break; 961 break;
961 default: 962 default:
962 info->output_width = srcinfo->output_width; 963 info->output_width = srcinfo->output_width;
963 info->output_height = srcinfo->output_height; 964 info->output_height = srcinfo->output_height;
964 if (info->num_components == 1) { 965 if (info->num_components == 1) {
965 info->iMCU_sample_width = srcinfo->_min_DCT_h_scaled_size; 966 info->iMCU_sample_width = srcinfo->_min_DCT_h_scaled_size;
966 info->iMCU_sample_height = srcinfo->_min_DCT_v_scaled_size; 967 info->iMCU_sample_height = srcinfo->_min_DCT_v_scaled_size;
967 } else { 968 } else {
968 info->iMCU_sample_width = 969 info->iMCU_sample_width =
969 » srcinfo->max_h_samp_factor * srcinfo->_min_DCT_h_scaled_size; 970 srcinfo->max_h_samp_factor * srcinfo->_min_DCT_h_scaled_size;
970 info->iMCU_sample_height = 971 info->iMCU_sample_height =
971 » srcinfo->max_v_samp_factor * srcinfo->_min_DCT_v_scaled_size; 972 srcinfo->max_v_samp_factor * srcinfo->_min_DCT_v_scaled_size;
972 } 973 }
973 break; 974 break;
974 } 975 }
975 976
976 /* If cropping has been requested, compute the crop area's position and 977 /* If cropping has been requested, compute the crop area's position and
977 * dimensions, ensuring that its upper left corner falls at an iMCU boundary. 978 * dimensions, ensuring that its upper left corner falls at an iMCU boundary.
978 */ 979 */
979 if (info->crop) { 980 if (info->crop) {
980 /* Insert default values for unset crop parameters */ 981 /* Insert default values for unset crop parameters */
981 if (info->crop_xoffset_set == JCROP_UNSET) 982 if (info->crop_xoffset_set == JCROP_UNSET)
982 info->crop_xoffset = 0;» /* default to +0 */ 983 info->crop_xoffset = 0; /* default to +0 */
983 if (info->crop_yoffset_set == JCROP_UNSET) 984 if (info->crop_yoffset_set == JCROP_UNSET)
984 info->crop_yoffset = 0;» /* default to +0 */ 985 info->crop_yoffset = 0; /* default to +0 */
985 if (info->crop_xoffset >= info->output_width || 986 if (info->crop_xoffset >= info->output_width ||
986 » info->crop_yoffset >= info->output_height) 987 info->crop_yoffset >= info->output_height)
987 ERREXIT(srcinfo, JERR_BAD_CROP_SPEC); 988 ERREXIT(srcinfo, JERR_BAD_CROP_SPEC);
988 if (info->crop_width_set == JCROP_UNSET) 989 if (info->crop_width_set == JCROP_UNSET)
989 info->crop_width = info->output_width - info->crop_xoffset; 990 info->crop_width = info->output_width - info->crop_xoffset;
990 if (info->crop_height_set == JCROP_UNSET) 991 if (info->crop_height_set == JCROP_UNSET)
991 info->crop_height = info->output_height - info->crop_yoffset; 992 info->crop_height = info->output_height - info->crop_yoffset;
992 /* Ensure parameters are valid */ 993 /* Ensure parameters are valid */
993 if (info->crop_width <= 0 || info->crop_width > info->output_width || 994 if (info->crop_width <= 0 || info->crop_width > info->output_width ||
994 » info->crop_height <= 0 || info->crop_height > info->output_height || 995 info->crop_height <= 0 || info->crop_height > info->output_height ||
995 » info->crop_xoffset > info->output_width - info->crop_width || 996 info->crop_xoffset > info->output_width - info->crop_width ||
996 » info->crop_yoffset > info->output_height - info->crop_height) 997 info->crop_yoffset > info->output_height - info->crop_height)
997 ERREXIT(srcinfo, JERR_BAD_CROP_SPEC); 998 ERREXIT(srcinfo, JERR_BAD_CROP_SPEC);
998 /* Convert negative crop offsets into regular offsets */ 999 /* Convert negative crop offsets into regular offsets */
999 if (info->crop_xoffset_set == JCROP_NEG) 1000 if (info->crop_xoffset_set == JCROP_NEG)
1000 xoffset = info->output_width - info->crop_width - info->crop_xoffset; 1001 xoffset = info->output_width - info->crop_width - info->crop_xoffset;
1001 else 1002 else
1002 xoffset = info->crop_xoffset; 1003 xoffset = info->crop_xoffset;
1003 if (info->crop_yoffset_set == JCROP_NEG) 1004 if (info->crop_yoffset_set == JCROP_NEG)
1004 yoffset = info->output_height - info->crop_height - info->crop_yoffset; 1005 yoffset = info->output_height - info->crop_height - info->crop_yoffset;
1005 else 1006 else
1006 yoffset = info->crop_yoffset; 1007 yoffset = info->crop_yoffset;
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
1086 break; 1087 break;
1087 } 1088 }
1088 1089
1089 /* Allocate workspace if needed. 1090 /* Allocate workspace if needed.
1090 * Note that we allocate arrays padded out to the next iMCU boundary, 1091 * Note that we allocate arrays padded out to the next iMCU boundary,
1091 * so that transform routines need not worry about missing edge blocks. 1092 * so that transform routines need not worry about missing edge blocks.
1092 */ 1093 */
1093 if (need_workspace) { 1094 if (need_workspace) {
1094 coef_arrays = (jvirt_barray_ptr *) 1095 coef_arrays = (jvirt_barray_ptr *)
1095 (*srcinfo->mem->alloc_small) ((j_common_ptr) srcinfo, JPOOL_IMAGE, 1096 (*srcinfo->mem->alloc_small) ((j_common_ptr) srcinfo, JPOOL_IMAGE,
1096 » » SIZEOF(jvirt_barray_ptr) * info->num_components); 1097 sizeof(jvirt_barray_ptr) * info->num_components);
1097 width_in_iMCUs = (JDIMENSION) 1098 width_in_iMCUs = (JDIMENSION)
1098 jdiv_round_up((long) info->output_width, 1099 jdiv_round_up((long) info->output_width,
1099 » » (long) info->iMCU_sample_width); 1100 (long) info->iMCU_sample_width);
1100 height_in_iMCUs = (JDIMENSION) 1101 height_in_iMCUs = (JDIMENSION)
1101 jdiv_round_up((long) info->output_height, 1102 jdiv_round_up((long) info->output_height,
1102 » » (long) info->iMCU_sample_height); 1103 (long) info->iMCU_sample_height);
1103 for (ci = 0; ci < info->num_components; ci++) { 1104 for (ci = 0; ci < info->num_components; ci++) {
1104 compptr = srcinfo->comp_info + ci; 1105 compptr = srcinfo->comp_info + ci;
1105 if (info->num_components == 1) { 1106 if (info->num_components == 1) {
1106 » /* we're going to force samp factors to 1x1 in this case */ 1107 /* we're going to force samp factors to 1x1 in this case */
1107 » h_samp_factor = v_samp_factor = 1; 1108 h_samp_factor = v_samp_factor = 1;
1108 } else if (transpose_it) { 1109 } else if (transpose_it) {
1109 » h_samp_factor = compptr->v_samp_factor; 1110 h_samp_factor = compptr->v_samp_factor;
1110 » v_samp_factor = compptr->h_samp_factor; 1111 v_samp_factor = compptr->h_samp_factor;
1111 } else { 1112 } else {
1112 » h_samp_factor = compptr->h_samp_factor; 1113 h_samp_factor = compptr->h_samp_factor;
1113 » v_samp_factor = compptr->v_samp_factor; 1114 v_samp_factor = compptr->v_samp_factor;
1114 } 1115 }
1115 width_in_blocks = width_in_iMCUs * h_samp_factor; 1116 width_in_blocks = width_in_iMCUs * h_samp_factor;
1116 height_in_blocks = height_in_iMCUs * v_samp_factor; 1117 height_in_blocks = height_in_iMCUs * v_samp_factor;
1117 coef_arrays[ci] = (*srcinfo->mem->request_virt_barray) 1118 coef_arrays[ci] = (*srcinfo->mem->request_virt_barray)
1118 » ((j_common_ptr) srcinfo, JPOOL_IMAGE, FALSE, 1119 ((j_common_ptr) srcinfo, JPOOL_IMAGE, FALSE,
1119 » width_in_blocks, height_in_blocks, (JDIMENSION) v_samp_factor); 1120 width_in_blocks, height_in_blocks, (JDIMENSION) v_samp_factor);
1120 } 1121 }
1121 info->workspace_coef_arrays = coef_arrays; 1122 info->workspace_coef_arrays = coef_arrays;
1122 } else 1123 } else
1123 info->workspace_coef_arrays = NULL; 1124 info->workspace_coef_arrays = NULL;
1124 1125
1125 return TRUE; 1126 return TRUE;
1126 } 1127 }
1127 1128
1128 1129
1129 /* Transpose destination image parameters */ 1130 /* Transpose destination image parameters */
(...skipping 23 matching lines...) Expand all
1153 itemp = compptr->h_samp_factor; 1154 itemp = compptr->h_samp_factor;
1154 compptr->h_samp_factor = compptr->v_samp_factor; 1155 compptr->h_samp_factor = compptr->v_samp_factor;
1155 compptr->v_samp_factor = itemp; 1156 compptr->v_samp_factor = itemp;
1156 } 1157 }
1157 1158
1158 /* Transpose quantization tables */ 1159 /* Transpose quantization tables */
1159 for (tblno = 0; tblno < NUM_QUANT_TBLS; tblno++) { 1160 for (tblno = 0; tblno < NUM_QUANT_TBLS; tblno++) {
1160 qtblptr = dstinfo->quant_tbl_ptrs[tblno]; 1161 qtblptr = dstinfo->quant_tbl_ptrs[tblno];
1161 if (qtblptr != NULL) { 1162 if (qtblptr != NULL) {
1162 for (i = 0; i < DCTSIZE; i++) { 1163 for (i = 0; i < DCTSIZE; i++) {
1163 » for (j = 0; j < i; j++) { 1164 for (j = 0; j < i; j++) {
1164 » qtemp = qtblptr->quantval[i*DCTSIZE+j]; 1165 qtemp = qtblptr->quantval[i*DCTSIZE+j];
1165 » qtblptr->quantval[i*DCTSIZE+j] = qtblptr->quantval[j*DCTSIZE+i]; 1166 qtblptr->quantval[i*DCTSIZE+j] = qtblptr->quantval[j*DCTSIZE+i];
1166 » qtblptr->quantval[j*DCTSIZE+i] = qtemp; 1167 qtblptr->quantval[j*DCTSIZE+i] = qtemp;
1167 » } 1168 }
1168 } 1169 }
1169 } 1170 }
1170 } 1171 }
1171 } 1172 }
1172 1173
1173 1174
1174 /* Adjust Exif image parameters. 1175 /* Adjust Exif image parameters.
1175 * 1176 *
1176 * We try to adjust the Tags ExifImageWidth and ExifImageHeight if possible. 1177 * We try to adjust the Tags ExifImageWidth and ExifImageHeight if possible.
1177 */ 1178 */
1178 1179
1179 #if JPEG_LIB_VERSION >= 70 1180 #if JPEG_LIB_VERSION >= 70
1180 LOCAL(void) 1181 LOCAL(void)
1181 adjust_exif_parameters (JOCTET FAR * data, unsigned int length, 1182 adjust_exif_parameters (JOCTET *data, unsigned int length,
1182 » » » JDIMENSION new_width, JDIMENSION new_height) 1183 JDIMENSION new_width, JDIMENSION new_height)
1183 { 1184 {
1184 boolean is_motorola; /* Flag for byte order */ 1185 boolean is_motorola; /* Flag for byte order */
1185 unsigned int number_of_tags, tagnum; 1186 unsigned int number_of_tags, tagnum;
1186 unsigned int firstoffset, offset; 1187 unsigned int firstoffset, offset;
1187 JDIMENSION new_value; 1188 JDIMENSION new_value;
1188 1189
1189 if (length < 12) return; /* Length of an IFD entry */ 1190 if (length < 12) return; /* Length of an IFD entry */
1190 1191
1191 /* Discover byte order */ 1192 /* Discover byte order */
1192 if (GETJOCTET(data[0]) == 0x49 && GETJOCTET(data[1]) == 0x49) 1193 if (GETJOCTET(data[0]) == 0x49 && GETJOCTET(data[1]) == 0x49)
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
1289 tagnum = GETJOCTET(data[offset]); 1290 tagnum = GETJOCTET(data[offset]);
1290 tagnum <<= 8; 1291 tagnum <<= 8;
1291 tagnum += GETJOCTET(data[offset+1]); 1292 tagnum += GETJOCTET(data[offset+1]);
1292 } else { 1293 } else {
1293 tagnum = GETJOCTET(data[offset+1]); 1294 tagnum = GETJOCTET(data[offset+1]);
1294 tagnum <<= 8; 1295 tagnum <<= 8;
1295 tagnum += GETJOCTET(data[offset]); 1296 tagnum += GETJOCTET(data[offset]);
1296 } 1297 }
1297 if (tagnum == 0xA002 || tagnum == 0xA003) { 1298 if (tagnum == 0xA002 || tagnum == 0xA003) {
1298 if (tagnum == 0xA002) 1299 if (tagnum == 0xA002)
1299 » new_value = new_width; /* ExifImageWidth Tag */ 1300 new_value = new_width; /* ExifImageWidth Tag */
1300 else 1301 else
1301 » new_value = new_height; /* ExifImageHeight Tag */ 1302 new_value = new_height; /* ExifImageHeight Tag */
1302 if (is_motorola) { 1303 if (is_motorola) {
1303 » data[offset+2] = 0; /* Format = unsigned long (4 octets) */ 1304 data[offset+2] = 0; /* Format = unsigned long (4 octets) */
1304 » data[offset+3] = 4; 1305 data[offset+3] = 4;
1305 » data[offset+4] = 0; /* Number Of Components = 1 */ 1306 data[offset+4] = 0; /* Number Of Components = 1 */
1306 » data[offset+5] = 0; 1307 data[offset+5] = 0;
1307 » data[offset+6] = 0; 1308 data[offset+6] = 0;
1308 » data[offset+7] = 1; 1309 data[offset+7] = 1;
1309 » data[offset+8] = 0; 1310 data[offset+8] = 0;
1310 » data[offset+9] = 0; 1311 data[offset+9] = 0;
1311 » data[offset+10] = (JOCTET)((new_value >> 8) & 0xFF); 1312 data[offset+10] = (JOCTET)((new_value >> 8) & 0xFF);
1312 » data[offset+11] = (JOCTET)(new_value & 0xFF); 1313 data[offset+11] = (JOCTET)(new_value & 0xFF);
1313 } else { 1314 } else {
1314 » data[offset+2] = 4; /* Format = unsigned long (4 octets) */ 1315 data[offset+2] = 4; /* Format = unsigned long (4 octets) */
1315 » data[offset+3] = 0; 1316 data[offset+3] = 0;
1316 » data[offset+4] = 1; /* Number Of Components = 1 */ 1317 data[offset+4] = 1; /* Number Of Components = 1 */
1317 » data[offset+5] = 0; 1318 data[offset+5] = 0;
1318 » data[offset+6] = 0; 1319 data[offset+6] = 0;
1319 » data[offset+7] = 0; 1320 data[offset+7] = 0;
1320 » data[offset+8] = (JOCTET)(new_value & 0xFF); 1321 data[offset+8] = (JOCTET)(new_value & 0xFF);
1321 » data[offset+9] = (JOCTET)((new_value >> 8) & 0xFF); 1322 data[offset+9] = (JOCTET)((new_value >> 8) & 0xFF);
1322 » data[offset+10] = 0; 1323 data[offset+10] = 0;
1323 » data[offset+11] = 0; 1324 data[offset+11] = 0;
1324 } 1325 }
1325 } 1326 }
1326 offset += 12; 1327 offset += 12;
1327 } while (--number_of_tags); 1328 } while (--number_of_tags);
1328 } 1329 }
1329 #endif 1330 #endif
1330 1331
1331 1332
1332 /* Adjust output image parameters as needed. 1333 /* Adjust output image parameters as needed.
1333 * 1334 *
1334 * This must be called after jpeg_copy_critical_parameters() 1335 * This must be called after jpeg_copy_critical_parameters()
1335 * and before jpeg_write_coefficients(). 1336 * and before jpeg_write_coefficients().
1336 * 1337 *
1337 * The return value is the set of virtual coefficient arrays to be written 1338 * The return value is the set of virtual coefficient arrays to be written
1338 * (either the ones allocated by jtransform_request_workspace, or the 1339 * (either the ones allocated by jtransform_request_workspace, or the
1339 * original source data arrays). The caller will need to pass this value 1340 * original source data arrays). The caller will need to pass this value
1340 * to jpeg_write_coefficients(). 1341 * to jpeg_write_coefficients().
1341 */ 1342 */
1342 1343
1343 GLOBAL(jvirt_barray_ptr *) 1344 GLOBAL(jvirt_barray_ptr *)
1344 jtransform_adjust_parameters (j_decompress_ptr srcinfo, 1345 jtransform_adjust_parameters (j_decompress_ptr srcinfo,
1345 » » » j_compress_ptr dstinfo, 1346 j_compress_ptr dstinfo,
1346 » » » jvirt_barray_ptr *src_coef_arrays, 1347 jvirt_barray_ptr *src_coef_arrays,
1347 » » » jpeg_transform_info *info) 1348 jpeg_transform_info *info)
1348 { 1349 {
1349 /* If force-to-grayscale is requested, adjust destination parameters */ 1350 /* If force-to-grayscale is requested, adjust destination parameters */
1350 if (info->force_grayscale) { 1351 if (info->force_grayscale) {
1351 /* First, ensure we have YCbCr or grayscale data, and that the source's 1352 /* First, ensure we have YCbCr or grayscale data, and that the source's
1352 * Y channel is full resolution. (No reasonable person would make Y 1353 * Y channel is full resolution. (No reasonable person would make Y
1353 * be less than full resolution, so actually coping with that case 1354 * be less than full resolution, so actually coping with that case
1354 * isn't worth extra code space. But we check it to avoid crashing.) 1355 * isn't worth extra code space. But we check it to avoid crashing.)
1355 */ 1356 */
1356 if (((dstinfo->jpeg_color_space == JCS_YCbCr && 1357 if (((dstinfo->jpeg_color_space == JCS_YCbCr &&
1357 » dstinfo->num_components == 3) || 1358 dstinfo->num_components == 3) ||
1358 » (dstinfo->jpeg_color_space == JCS_GRAYSCALE && 1359 (dstinfo->jpeg_color_space == JCS_GRAYSCALE &&
1359 » dstinfo->num_components == 1)) && 1360 dstinfo->num_components == 1)) &&
1360 » srcinfo->comp_info[0].h_samp_factor == srcinfo->max_h_samp_factor && 1361 srcinfo->comp_info[0].h_samp_factor == srcinfo->max_h_samp_factor &&
1361 » srcinfo->comp_info[0].v_samp_factor == srcinfo->max_v_samp_factor) { 1362 srcinfo->comp_info[0].v_samp_factor == srcinfo->max_v_samp_factor) {
1362 /* We use jpeg_set_colorspace to make sure subsidiary settings get fixed 1363 /* We use jpeg_set_colorspace to make sure subsidiary settings get fixed
1363 * properly. Among other things, it sets the target h_samp_factor & 1364 * properly. Among other things, it sets the target h_samp_factor &
1364 * v_samp_factor to 1, which typically won't match the source. 1365 * v_samp_factor to 1, which typically won't match the source.
1365 * We have to preserve the source's quantization table number, however. 1366 * We have to preserve the source's quantization table number, however.
1366 */ 1367 */
1367 int sv_quant_tbl_no = dstinfo->comp_info[0].quant_tbl_no; 1368 int sv_quant_tbl_no = dstinfo->comp_info[0].quant_tbl_no;
1368 jpeg_set_colorspace(dstinfo, JCS_GRAYSCALE); 1369 jpeg_set_colorspace(dstinfo, JCS_GRAYSCALE);
1369 dstinfo->comp_info[0].quant_tbl_no = sv_quant_tbl_no; 1370 dstinfo->comp_info[0].quant_tbl_no = sv_quant_tbl_no;
1370 } else { 1371 } else {
1371 /* Sorry, can't do it */ 1372 /* Sorry, can't do it */
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1416 GETJOCTET(srcinfo->marker_list->data[1]) == 0x78 && 1417 GETJOCTET(srcinfo->marker_list->data[1]) == 0x78 &&
1417 GETJOCTET(srcinfo->marker_list->data[2]) == 0x69 && 1418 GETJOCTET(srcinfo->marker_list->data[2]) == 0x69 &&
1418 GETJOCTET(srcinfo->marker_list->data[3]) == 0x66 && 1419 GETJOCTET(srcinfo->marker_list->data[3]) == 0x66 &&
1419 GETJOCTET(srcinfo->marker_list->data[4]) == 0 && 1420 GETJOCTET(srcinfo->marker_list->data[4]) == 0 &&
1420 GETJOCTET(srcinfo->marker_list->data[5]) == 0) { 1421 GETJOCTET(srcinfo->marker_list->data[5]) == 0) {
1421 /* Suppress output of JFIF marker */ 1422 /* Suppress output of JFIF marker */
1422 dstinfo->write_JFIF_header = FALSE; 1423 dstinfo->write_JFIF_header = FALSE;
1423 #if JPEG_LIB_VERSION >= 70 1424 #if JPEG_LIB_VERSION >= 70
1424 /* Adjust Exif image parameters */ 1425 /* Adjust Exif image parameters */
1425 if (dstinfo->jpeg_width != srcinfo->image_width || 1426 if (dstinfo->jpeg_width != srcinfo->image_width ||
1426 » dstinfo->jpeg_height != srcinfo->image_height) 1427 dstinfo->jpeg_height != srcinfo->image_height)
1427 /* Align data segment to start of TIFF structure for parsing */ 1428 /* Align data segment to start of TIFF structure for parsing */
1428 adjust_exif_parameters(srcinfo->marker_list->data + 6, 1429 adjust_exif_parameters(srcinfo->marker_list->data + 6,
1429 » srcinfo->marker_list->data_length - 6, 1430 srcinfo->marker_list->data_length - 6,
1430 » dstinfo->jpeg_width, dstinfo->jpeg_height); 1431 dstinfo->jpeg_width, dstinfo->jpeg_height);
1431 #endif 1432 #endif
1432 } 1433 }
1433 1434
1434 /* Return the appropriate output data set */ 1435 /* Return the appropriate output data set */
1435 if (info->workspace_coef_arrays != NULL) 1436 if (info->workspace_coef_arrays != NULL)
1436 return info->workspace_coef_arrays; 1437 return info->workspace_coef_arrays;
1437 return src_coef_arrays; 1438 return src_coef_arrays;
1438 } 1439 }
1439 1440
1440 1441
1441 /* Execute the actual transformation, if any. 1442 /* Execute the actual transformation, if any.
1442 * 1443 *
1443 * This must be called *after* jpeg_write_coefficients, because it depends 1444 * This must be called *after* jpeg_write_coefficients, because it depends
1444 * on jpeg_write_coefficients to have computed subsidiary values such as 1445 * on jpeg_write_coefficients to have computed subsidiary values such as
1445 * the per-component width and height fields in the destination object. 1446 * the per-component width and height fields in the destination object.
1446 * 1447 *
1447 * Note that some transformations will modify the source data arrays! 1448 * Note that some transformations will modify the source data arrays!
1448 */ 1449 */
1449 1450
1450 GLOBAL(void) 1451 GLOBAL(void)
1451 jtransform_execute_transform (j_decompress_ptr srcinfo, 1452 jtransform_execute_transform (j_decompress_ptr srcinfo,
1452 » » » j_compress_ptr dstinfo, 1453 j_compress_ptr dstinfo,
1453 » » » jvirt_barray_ptr *src_coef_arrays, 1454 jvirt_barray_ptr *src_coef_arrays,
1454 » » » jpeg_transform_info *info) 1455 jpeg_transform_info *info)
1455 { 1456 {
1456 jvirt_barray_ptr *dst_coef_arrays = info->workspace_coef_arrays; 1457 jvirt_barray_ptr *dst_coef_arrays = info->workspace_coef_arrays;
1457 1458
1458 /* Note: conditions tested here should match those in switch statement 1459 /* Note: conditions tested here should match those in switch statement
1459 * in jtransform_request_workspace() 1460 * in jtransform_request_workspace()
1460 */ 1461 */
1461 switch (info->transform) { 1462 switch (info->transform) {
1462 case JXFORM_NONE: 1463 case JXFORM_NONE:
1463 if (info->x_crop_offset != 0 || info->y_crop_offset != 0) 1464 if (info->x_crop_offset != 0 || info->y_crop_offset != 0)
1464 do_crop(srcinfo, dstinfo, info->x_crop_offset, info->y_crop_offset, 1465 do_crop(srcinfo, dstinfo, info->x_crop_offset, info->y_crop_offset,
1465 » src_coef_arrays, dst_coef_arrays); 1466 src_coef_arrays, dst_coef_arrays);
1466 break; 1467 break;
1467 case JXFORM_FLIP_H: 1468 case JXFORM_FLIP_H:
1468 if (info->y_crop_offset != 0 || info->slow_hflip) 1469 if (info->y_crop_offset != 0 || info->slow_hflip)
1469 do_flip_h(srcinfo, dstinfo, info->x_crop_offset, info->y_crop_offset, 1470 do_flip_h(srcinfo, dstinfo, info->x_crop_offset, info->y_crop_offset,
1470 » » src_coef_arrays, dst_coef_arrays); 1471 src_coef_arrays, dst_coef_arrays);
1471 else 1472 else
1472 do_flip_h_no_crop(srcinfo, dstinfo, info->x_crop_offset, 1473 do_flip_h_no_crop(srcinfo, dstinfo, info->x_crop_offset,
1473 » » » src_coef_arrays); 1474 src_coef_arrays);
1474 break; 1475 break;
1475 case JXFORM_FLIP_V: 1476 case JXFORM_FLIP_V:
1476 do_flip_v(srcinfo, dstinfo, info->x_crop_offset, info->y_crop_offset, 1477 do_flip_v(srcinfo, dstinfo, info->x_crop_offset, info->y_crop_offset,
1477 » src_coef_arrays, dst_coef_arrays); 1478 src_coef_arrays, dst_coef_arrays);
1478 break; 1479 break;
1479 case JXFORM_TRANSPOSE: 1480 case JXFORM_TRANSPOSE:
1480 do_transpose(srcinfo, dstinfo, info->x_crop_offset, info->y_crop_offset, 1481 do_transpose(srcinfo, dstinfo, info->x_crop_offset, info->y_crop_offset,
1481 » » src_coef_arrays, dst_coef_arrays); 1482 src_coef_arrays, dst_coef_arrays);
1482 break; 1483 break;
1483 case JXFORM_TRANSVERSE: 1484 case JXFORM_TRANSVERSE:
1484 do_transverse(srcinfo, dstinfo, info->x_crop_offset, info->y_crop_offset, 1485 do_transverse(srcinfo, dstinfo, info->x_crop_offset, info->y_crop_offset,
1485 » » src_coef_arrays, dst_coef_arrays); 1486 src_coef_arrays, dst_coef_arrays);
1486 break; 1487 break;
1487 case JXFORM_ROT_90: 1488 case JXFORM_ROT_90:
1488 do_rot_90(srcinfo, dstinfo, info->x_crop_offset, info->y_crop_offset, 1489 do_rot_90(srcinfo, dstinfo, info->x_crop_offset, info->y_crop_offset,
1489 » src_coef_arrays, dst_coef_arrays); 1490 src_coef_arrays, dst_coef_arrays);
1490 break; 1491 break;
1491 case JXFORM_ROT_180: 1492 case JXFORM_ROT_180:
1492 do_rot_180(srcinfo, dstinfo, info->x_crop_offset, info->y_crop_offset, 1493 do_rot_180(srcinfo, dstinfo, info->x_crop_offset, info->y_crop_offset,
1493 » src_coef_arrays, dst_coef_arrays); 1494 src_coef_arrays, dst_coef_arrays);
1494 break; 1495 break;
1495 case JXFORM_ROT_270: 1496 case JXFORM_ROT_270:
1496 do_rot_270(srcinfo, dstinfo, info->x_crop_offset, info->y_crop_offset, 1497 do_rot_270(srcinfo, dstinfo, info->x_crop_offset, info->y_crop_offset,
1497 » src_coef_arrays, dst_coef_arrays); 1498 src_coef_arrays, dst_coef_arrays);
1498 break; 1499 break;
1499 } 1500 }
1500 } 1501 }
1501 1502
1502 /* jtransform_perfect_transform 1503 /* jtransform_perfect_transform
1503 * 1504 *
1504 * Determine whether lossless transformation is perfectly 1505 * Determine whether lossless transformation is perfectly
1505 * possible for a specified image and transformation. 1506 * possible for a specified image and transformation.
1506 * 1507 *
1507 * Inputs: 1508 * Inputs:
1508 * image_width, image_height: source image dimensions. 1509 * image_width, image_height: source image dimensions.
1509 * MCU_width, MCU_height: pixel dimensions of MCU. 1510 * MCU_width, MCU_height: pixel dimensions of MCU.
1510 * transform: transformation identifier. 1511 * transform: transformation identifier.
1511 * Parameter sources from initialized jpeg_struct 1512 * Parameter sources from initialized jpeg_struct
1512 * (after reading source header): 1513 * (after reading source header):
1513 * image_width = cinfo.image_width 1514 * image_width = cinfo.image_width
1514 * image_height = cinfo.image_height 1515 * image_height = cinfo.image_height
1515 * MCU_width = cinfo.max_h_samp_factor * cinfo.block_size 1516 * MCU_width = cinfo.max_h_samp_factor * cinfo.block_size
1516 * MCU_height = cinfo.max_v_samp_factor * cinfo.block_size 1517 * MCU_height = cinfo.max_v_samp_factor * cinfo.block_size
1517 * Result: 1518 * Result:
1518 * TRUE = perfect transformation possible 1519 * TRUE = perfect transformation possible
1519 * FALSE = perfect transformation not possible 1520 * FALSE = perfect transformation not possible
1520 * (may use custom action then) 1521 * (may use custom action then)
1521 */ 1522 */
1522 1523
1523 GLOBAL(boolean) 1524 GLOBAL(boolean)
1524 jtransform_perfect_transform(JDIMENSION image_width, JDIMENSION image_height, 1525 jtransform_perfect_transform(JDIMENSION image_width, JDIMENSION image_height,
1525 » » » int MCU_width, int MCU_height, 1526 int MCU_width, int MCU_height,
1526 » » » JXFORM_CODE transform) 1527 JXFORM_CODE transform)
1527 { 1528 {
1528 boolean result = TRUE; /* initialize TRUE */ 1529 boolean result = TRUE; /* initialize TRUE */
1529 1530
1530 switch (transform) { 1531 switch (transform) {
1531 case JXFORM_FLIP_H: 1532 case JXFORM_FLIP_H:
1532 case JXFORM_ROT_270: 1533 case JXFORM_ROT_270:
1533 if (image_width % (JDIMENSION) MCU_width) 1534 if (image_width % (JDIMENSION) MCU_width)
1534 result = FALSE; 1535 result = FALSE;
1535 break; 1536 break;
1536 case JXFORM_FLIP_V: 1537 case JXFORM_FLIP_V:
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1579 1580
1580 /* Copy markers saved in the given source object to the destination object. 1581 /* Copy markers saved in the given source object to the destination object.
1581 * This should be called just after jpeg_start_compress() or 1582 * This should be called just after jpeg_start_compress() or
1582 * jpeg_write_coefficients(). 1583 * jpeg_write_coefficients().
1583 * Note that those routines will have written the SOI, and also the 1584 * Note that those routines will have written the SOI, and also the
1584 * JFIF APP0 or Adobe APP14 markers if selected. 1585 * JFIF APP0 or Adobe APP14 markers if selected.
1585 */ 1586 */
1586 1587
1587 GLOBAL(void) 1588 GLOBAL(void)
1588 jcopy_markers_execute (j_decompress_ptr srcinfo, j_compress_ptr dstinfo, 1589 jcopy_markers_execute (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
1589 » » JCOPY_OPTION option) 1590 JCOPY_OPTION option)
1590 { 1591 {
1591 jpeg_saved_marker_ptr marker; 1592 jpeg_saved_marker_ptr marker;
1592 1593
1593 /* In the current implementation, we don't actually need to examine the 1594 /* In the current implementation, we don't actually need to examine the
1594 * option flag here; we just copy everything that got saved. 1595 * option flag here; we just copy everything that got saved.
1595 * But to avoid confusion, we do not output JFIF and Adobe APP14 markers 1596 * But to avoid confusion, we do not output JFIF and Adobe APP14 markers
1596 * if the encoder library already wrote one. 1597 * if the encoder library already wrote one.
1597 */ 1598 */
1598 for (marker = srcinfo->marker_list; marker != NULL; marker = marker->next) { 1599 for (marker = srcinfo->marker_list; marker != NULL; marker = marker->next) {
1599 if (dstinfo->write_JFIF_header && 1600 if (dstinfo->write_JFIF_header &&
1600 » marker->marker == JPEG_APP0 && 1601 marker->marker == JPEG_APP0 &&
1601 » marker->data_length >= 5 && 1602 marker->data_length >= 5 &&
1602 » GETJOCTET(marker->data[0]) == 0x4A && 1603 GETJOCTET(marker->data[0]) == 0x4A &&
1603 » GETJOCTET(marker->data[1]) == 0x46 && 1604 GETJOCTET(marker->data[1]) == 0x46 &&
1604 » GETJOCTET(marker->data[2]) == 0x49 && 1605 GETJOCTET(marker->data[2]) == 0x49 &&
1605 » GETJOCTET(marker->data[3]) == 0x46 && 1606 GETJOCTET(marker->data[3]) == 0x46 &&
1606 » GETJOCTET(marker->data[4]) == 0) 1607 GETJOCTET(marker->data[4]) == 0)
1607 continue;»» » /* reject duplicate JFIF */ 1608 continue; /* reject duplicate JFIF */
1608 if (dstinfo->write_Adobe_marker && 1609 if (dstinfo->write_Adobe_marker &&
1609 » marker->marker == JPEG_APP0+14 && 1610 marker->marker == JPEG_APP0+14 &&
1610 » marker->data_length >= 5 && 1611 marker->data_length >= 5 &&
1611 » GETJOCTET(marker->data[0]) == 0x41 && 1612 GETJOCTET(marker->data[0]) == 0x41 &&
1612 » GETJOCTET(marker->data[1]) == 0x64 && 1613 GETJOCTET(marker->data[1]) == 0x64 &&
1613 » GETJOCTET(marker->data[2]) == 0x6F && 1614 GETJOCTET(marker->data[2]) == 0x6F &&
1614 » GETJOCTET(marker->data[3]) == 0x62 && 1615 GETJOCTET(marker->data[3]) == 0x62 &&
1615 » GETJOCTET(marker->data[4]) == 0x65) 1616 GETJOCTET(marker->data[4]) == 0x65)
1616 continue;»» » /* reject duplicate Adobe */ 1617 continue; /* reject duplicate Adobe */
1617 #ifdef NEED_FAR_POINTERS
1618 /* We could use jpeg_write_marker if the data weren't FAR... */
1619 {
1620 unsigned int i;
1621 jpeg_write_m_header(dstinfo, marker->marker, marker->data_length);
1622 for (i = 0; i < marker->data_length; i++)
1623 » jpeg_write_m_byte(dstinfo, marker->data[i]);
1624 }
1625 #else
1626 jpeg_write_marker(dstinfo, marker->marker, 1618 jpeg_write_marker(dstinfo, marker->marker,
1627 » » marker->data, marker->data_length); 1619 marker->data, marker->data_length);
1628 #endif
1629 } 1620 }
1630 } 1621 }
OLDNEW
« no previous file with comments | « transupp.h ('k') | turbojpeg.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698