| OLD | NEW |
| 1 /* | 1 /* |
| 2 * transupp.c | 2 * transupp.c |
| 3 * | 3 * |
| 4 * Copyright (C) 1997, Thomas G. Lane. | 4 * Copyright (C) 1997-2009, Thomas G. Lane, Guido Vollbeding. |
| 5 * Copyright (C) 2010, D. R. Commander. |
| 5 * This file is part of the Independent JPEG Group's software. | 6 * This file is part of the Independent JPEG Group's software. |
| 6 * For conditions of distribution and use, see the accompanying README file. | 7 * For conditions of distribution and use, see the accompanying README file. |
| 7 * | 8 * |
| 8 * This file contains image transformation routines and other utility code | 9 * This file contains image transformation routines and other utility code |
| 9 * used by the jpegtran sample application. These are NOT part of the core | 10 * used by the jpegtran sample application. These are NOT part of the core |
| 10 * JPEG library. But we keep these routines separate from jpegtran.c to | 11 * JPEG library. But we keep these routines separate from jpegtran.c to |
| 11 * ease the task of maintaining jpegtran-like programs that have other user | 12 * ease the task of maintaining jpegtran-like programs that have other user |
| 12 * interfaces. | 13 * interfaces. |
| 13 */ | 14 */ |
| 14 | 15 |
| 15 /* Although this file really shouldn't have access to the library internals, | 16 /* Although this file really shouldn't have access to the library internals, |
| 16 * it's helpful to let it call jround_up() and jcopy_block_row(). | 17 * it's helpful to let it call jround_up() and jcopy_block_row(). |
| 17 */ | 18 */ |
| 18 #define JPEG_INTERNALS | 19 #define JPEG_INTERNALS |
| 19 | 20 |
| 20 #include "jinclude.h" | 21 #include "jinclude.h" |
| 21 #include "jpeglib.h" | 22 #include "jpeglib.h" |
| 22 #include "transupp.h" /* My own external interface */ | 23 #include "transupp.h" /* My own external interface */ |
| 24 #include "jpegcomp.h" |
| 25 #include <ctype.h> /* to declare isdigit() */ |
| 26 |
| 27 |
| 28 #if JPEG_LIB_VERSION >= 70 |
| 29 #define dstinfo_min_DCT_h_scaled_size dstinfo->min_DCT_h_scaled_size |
| 30 #define dstinfo_min_DCT_v_scaled_size dstinfo->min_DCT_v_scaled_size |
| 31 #else |
| 32 #define dstinfo_min_DCT_h_scaled_size DCTSIZE |
| 33 #define dstinfo_min_DCT_v_scaled_size DCTSIZE |
| 34 #endif |
| 23 | 35 |
| 24 | 36 |
| 25 #if TRANSFORMS_SUPPORTED | 37 #if TRANSFORMS_SUPPORTED |
| 26 | 38 |
| 27 /* | 39 /* |
| 28 * Lossless image transformation routines. These routines work on DCT | 40 * Lossless image transformation routines. These routines work on DCT |
| 29 * coefficient arrays and thus do not require any lossy decompression | 41 * coefficient arrays and thus do not require any lossy decompression |
| 30 * or recompression of the image. | 42 * or recompression of the image. |
| 31 * Thanks to Guido Vollbeding for the initial design and code of this feature. | 43 * Thanks to Guido Vollbeding for the initial design and code of this feature, |
| 44 * and to Ben Jackson for introducing the cropping feature. |
| 32 * | 45 * |
| 33 * Horizontal flipping is done in-place, using a single top-to-bottom | 46 * Horizontal flipping is done in-place, using a single top-to-bottom |
| 34 * pass through the virtual source array. It will thus be much the | 47 * pass through the virtual source array. It will thus be much the |
| 35 * fastest option for images larger than main memory. | 48 * fastest option for images larger than main memory. |
| 36 * | 49 * |
| 37 * The other routines require a set of destination virtual arrays, so they | 50 * The other routines require a set of destination virtual arrays, so they |
| 38 * need twice as much memory as jpegtran normally does. The destination | 51 * need twice as much memory as jpegtran normally does. The destination |
| 39 * arrays are always written in normal scan order (top to bottom) because | 52 * arrays are always written in normal scan order (top to bottom) because |
| 40 * the virtual array manager expects this. The source arrays will be scanned | 53 * the virtual array manager expects this. The source arrays will be scanned |
| 41 * in the corresponding order, which means multiple passes through the source | 54 * in the corresponding order, which means multiple passes through the source |
| 42 * arrays for most of the transforms. That could result in much thrashing | 55 * arrays for most of the transforms. That could result in much thrashing |
| 43 * if the image is larger than main memory. | 56 * if the image is larger than main memory. |
| 44 * | 57 * |
| 58 * If cropping or trimming is involved, the destination arrays may be smaller |
| 59 * than the source arrays. Note it is not possible to do horizontal flip |
| 60 * in-place when a nonzero Y crop offset is specified, since we'd have to move |
| 61 * data from one block row to another but the virtual array manager doesn't |
| 62 * guarantee we can touch more than one row at a time. So in that case, |
| 63 * we have to use a separate destination array. |
| 64 * |
| 45 * Some notes about the operating environment of the individual transform | 65 * Some notes about the operating environment of the individual transform |
| 46 * routines: | 66 * routines: |
| 47 * 1. Both the source and destination virtual arrays are allocated from the | 67 * 1. Both the source and destination virtual arrays are allocated from the |
| 48 * source JPEG object, and therefore should be manipulated by calling the | 68 * source JPEG object, and therefore should be manipulated by calling the |
| 49 * source's memory manager. | 69 * source's memory manager. |
| 50 * 2. The destination's component count should be used. It may be smaller | 70 * 2. The destination's component count should be used. It may be smaller |
| 51 * than the source's when forcing to grayscale. | 71 * than the source's when forcing to grayscale. |
| 52 * 3. Likewise the destination's sampling factors should be used. When | 72 * 3. Likewise the destination's sampling factors should be used. When |
| 53 * forcing to grayscale the destination's sampling factors will be all 1, | 73 * forcing to grayscale the destination's sampling factors will be all 1, |
| 54 * and we may as well take that as the effective iMCU size. | 74 * and we may as well take that as the effective iMCU size. |
| 55 * 4. When "trim" is in effect, the destination's dimensions will be the | 75 * 4. When "trim" is in effect, the destination's dimensions will be the |
| 56 * trimmed values but the source's will be untrimmed. | 76 * trimmed values but the source's will be untrimmed. |
| 57 * 5. All the routines assume that the source and destination buffers are | 77 * 5. When "crop" is in effect, the destination's dimensions will be the |
| 78 * cropped values but the source's will be uncropped. Each transform |
| 79 * routine is responsible for picking up source data starting at the |
| 80 * correct X and Y offset for the crop region. (The X and Y offsets |
| 81 * passed to the transform routines are measured in iMCU blocks of the |
| 82 * destination.) |
| 83 * 6. All the routines assume that the source and destination buffers are |
| 58 * padded out to a full iMCU boundary. This is true, although for the | 84 * padded out to a full iMCU boundary. This is true, although for the |
| 59 * source buffer it is an undocumented property of jdcoefct.c. | 85 * source buffer it is an undocumented property of jdcoefct.c. |
| 60 * Notes 2,3,4 boil down to this: generally we should use the destination's | |
| 61 * dimensions and ignore the source's. | |
| 62 */ | 86 */ |
| 63 | 87 |
| 64 | 88 |
| 65 LOCAL(void) | 89 LOCAL(void) |
| 66 do_flip_h (j_decompress_ptr srcinfo, j_compress_ptr dstinfo, | 90 do_crop (j_decompress_ptr srcinfo, j_compress_ptr dstinfo, |
| 67 » jvirt_barray_ptr *src_coef_arrays) | 91 » JDIMENSION x_crop_offset, JDIMENSION y_crop_offset, |
| 68 /* Horizontal flip; done in-place, so no separate dest array is required */ | 92 » jvirt_barray_ptr *src_coef_arrays, |
| 93 » jvirt_barray_ptr *dst_coef_arrays) |
| 94 /* Crop. This is only used when no rotate/flip is requested with the crop. */ |
| 69 { | 95 { |
| 70 JDIMENSION MCU_cols, comp_width, blk_x, blk_y; | 96 JDIMENSION dst_blk_y, x_crop_blocks, y_crop_blocks; |
| 97 int ci, offset_y; |
| 98 JBLOCKARRAY src_buffer, dst_buffer; |
| 99 jpeg_component_info *compptr; |
| 100 |
| 101 /* We simply have to copy the right amount of data (the destination's |
| 102 * image size) starting at the given X and Y offsets in the source. |
| 103 */ |
| 104 for (ci = 0; ci < dstinfo->num_components; ci++) { |
| 105 compptr = dstinfo->comp_info + ci; |
| 106 x_crop_blocks = x_crop_offset * compptr->h_samp_factor; |
| 107 y_crop_blocks = y_crop_offset * compptr->v_samp_factor; |
| 108 for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks; |
| 109 » dst_blk_y += compptr->v_samp_factor) { |
| 110 dst_buffer = (*srcinfo->mem->access_virt_barray) |
| 111 » ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y, |
| 112 » (JDIMENSION) compptr->v_samp_factor, TRUE); |
| 113 src_buffer = (*srcinfo->mem->access_virt_barray) |
| 114 » ((j_common_ptr) srcinfo, src_coef_arrays[ci], |
| 115 » dst_blk_y + y_crop_blocks, |
| 116 » (JDIMENSION) compptr->v_samp_factor, FALSE); |
| 117 for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) { |
| 118 » jcopy_block_row(src_buffer[offset_y] + x_crop_blocks, |
| 119 » » » dst_buffer[offset_y], |
| 120 » » » compptr->width_in_blocks); |
| 121 } |
| 122 } |
| 123 } |
| 124 } |
| 125 |
| 126 |
| 127 LOCAL(void) |
| 128 do_flip_h_no_crop (j_decompress_ptr srcinfo, j_compress_ptr dstinfo, |
| 129 » » JDIMENSION x_crop_offset, |
| 130 » » jvirt_barray_ptr *src_coef_arrays) |
| 131 /* Horizontal flip; done in-place, so no separate dest array is required. |
| 132 * NB: this only works when y_crop_offset is zero. |
| 133 */ |
| 134 { |
| 135 JDIMENSION MCU_cols, comp_width, blk_x, blk_y, x_crop_blocks; |
| 71 int ci, k, offset_y; | 136 int ci, k, offset_y; |
| 72 JBLOCKARRAY buffer; | 137 JBLOCKARRAY buffer; |
| 73 JCOEFPTR ptr1, ptr2; | 138 JCOEFPTR ptr1, ptr2; |
| 74 JCOEF temp1, temp2; | 139 JCOEF temp1, temp2; |
| 75 jpeg_component_info *compptr; | 140 jpeg_component_info *compptr; |
| 76 | 141 |
| 77 /* Horizontal mirroring of DCT blocks is accomplished by swapping | 142 /* Horizontal mirroring of DCT blocks is accomplished by swapping |
| 78 * pairs of blocks in-place. Within a DCT block, we perform horizontal | 143 * pairs of blocks in-place. Within a DCT block, we perform horizontal |
| 79 * mirroring by changing the signs of odd-numbered columns. | 144 * mirroring by changing the signs of odd-numbered columns. |
| 80 * Partial iMCUs at the right edge are left untouched. | 145 * Partial iMCUs at the right edge are left untouched. |
| 81 */ | 146 */ |
| 82 MCU_cols = dstinfo->image_width / (dstinfo->max_h_samp_factor * DCTSIZE); | 147 MCU_cols = srcinfo->output_width / |
| 148 (dstinfo->max_h_samp_factor * dstinfo_min_DCT_h_scaled_size); |
| 83 | 149 |
| 84 for (ci = 0; ci < dstinfo->num_components; ci++) { | 150 for (ci = 0; ci < dstinfo->num_components; ci++) { |
| 85 compptr = dstinfo->comp_info + ci; | 151 compptr = dstinfo->comp_info + ci; |
| 86 comp_width = MCU_cols * compptr->h_samp_factor; | 152 comp_width = MCU_cols * compptr->h_samp_factor; |
| 153 x_crop_blocks = x_crop_offset * compptr->h_samp_factor; |
| 87 for (blk_y = 0; blk_y < compptr->height_in_blocks; | 154 for (blk_y = 0; blk_y < compptr->height_in_blocks; |
| 88 blk_y += compptr->v_samp_factor) { | 155 blk_y += compptr->v_samp_factor) { |
| 89 buffer = (*srcinfo->mem->access_virt_barray) | 156 buffer = (*srcinfo->mem->access_virt_barray) |
| 90 ((j_common_ptr) srcinfo, src_coef_arrays[ci], blk_y, | 157 ((j_common_ptr) srcinfo, src_coef_arrays[ci], blk_y, |
| 91 (JDIMENSION) compptr->v_samp_factor, TRUE); | 158 (JDIMENSION) compptr->v_samp_factor, TRUE); |
| 92 for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) { | 159 for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) { |
| 160 /* Do the mirroring */ |
| 93 for (blk_x = 0; blk_x * 2 < comp_width; blk_x++) { | 161 for (blk_x = 0; blk_x * 2 < comp_width; blk_x++) { |
| 94 ptr1 = buffer[offset_y][blk_x]; | 162 ptr1 = buffer[offset_y][blk_x]; |
| 95 ptr2 = buffer[offset_y][comp_width - blk_x - 1]; | 163 ptr2 = buffer[offset_y][comp_width - blk_x - 1]; |
| 96 /* this unrolled loop doesn't need to know which row it's on... */ | 164 /* this unrolled loop doesn't need to know which row it's on... */ |
| 97 for (k = 0; k < DCTSIZE2; k += 2) { | 165 for (k = 0; k < DCTSIZE2; k += 2) { |
| 98 temp1 = *ptr1; /* swap even column */ | 166 temp1 = *ptr1; /* swap even column */ |
| 99 temp2 = *ptr2; | 167 temp2 = *ptr2; |
| 100 *ptr1++ = temp2; | 168 *ptr1++ = temp2; |
| 101 *ptr2++ = temp1; | 169 *ptr2++ = temp1; |
| 102 temp1 = *ptr1; /* swap odd column with sign change */ | 170 temp1 = *ptr1; /* swap odd column with sign change */ |
| 103 temp2 = *ptr2; | 171 temp2 = *ptr2; |
| 104 *ptr1++ = -temp2; | 172 *ptr1++ = -temp2; |
| 105 *ptr2++ = -temp1; | 173 *ptr2++ = -temp1; |
| 106 } | 174 } |
| 107 } | 175 } |
| 176 if (x_crop_blocks > 0) { |
| 177 /* Now left-justify the portion of the data to be kept. |
| 178 * We can't use a single jcopy_block_row() call because that routine |
| 179 * depends on memcpy(), whose behavior is unspecified for overlapping |
| 180 * source and destination areas. Sigh. |
| 181 */ |
| 182 for (blk_x = 0; blk_x < compptr->width_in_blocks; blk_x++) { |
| 183 jcopy_block_row(buffer[offset_y] + blk_x + x_crop_blocks, |
| 184 buffer[offset_y] + blk_x, |
| 185 (JDIMENSION) 1); |
| 186 } |
| 187 } |
| 108 } | 188 } |
| 109 } | 189 } |
| 110 } | 190 } |
| 111 } | 191 } |
| 112 | 192 |
| 113 | 193 |
| 114 LOCAL(void) | 194 LOCAL(void) |
| 195 do_flip_h (j_decompress_ptr srcinfo, j_compress_ptr dstinfo, |
| 196 JDIMENSION x_crop_offset, JDIMENSION y_crop_offset, |
| 197 jvirt_barray_ptr *src_coef_arrays, |
| 198 jvirt_barray_ptr *dst_coef_arrays) |
| 199 /* Horizontal flip in general cropping case */ |
| 200 { |
| 201 JDIMENSION MCU_cols, comp_width, dst_blk_x, dst_blk_y; |
| 202 JDIMENSION x_crop_blocks, y_crop_blocks; |
| 203 int ci, k, offset_y; |
| 204 JBLOCKARRAY src_buffer, dst_buffer; |
| 205 JBLOCKROW src_row_ptr, dst_row_ptr; |
| 206 JCOEFPTR src_ptr, dst_ptr; |
| 207 jpeg_component_info *compptr; |
| 208 |
| 209 /* Here we must output into a separate array because we can't touch |
| 210 * different rows of a single virtual array simultaneously. Otherwise, |
| 211 * this is essentially the same as the routine above. |
| 212 */ |
| 213 MCU_cols = srcinfo->output_width / |
| 214 (dstinfo->max_h_samp_factor * dstinfo_min_DCT_h_scaled_size); |
| 215 |
| 216 for (ci = 0; ci < dstinfo->num_components; ci++) { |
| 217 compptr = dstinfo->comp_info + ci; |
| 218 comp_width = MCU_cols * compptr->h_samp_factor; |
| 219 x_crop_blocks = x_crop_offset * compptr->h_samp_factor; |
| 220 y_crop_blocks = y_crop_offset * compptr->v_samp_factor; |
| 221 for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks; |
| 222 dst_blk_y += compptr->v_samp_factor) { |
| 223 dst_buffer = (*srcinfo->mem->access_virt_barray) |
| 224 ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y, |
| 225 (JDIMENSION) compptr->v_samp_factor, TRUE); |
| 226 src_buffer = (*srcinfo->mem->access_virt_barray) |
| 227 ((j_common_ptr) srcinfo, src_coef_arrays[ci], |
| 228 dst_blk_y + y_crop_blocks, |
| 229 (JDIMENSION) compptr->v_samp_factor, FALSE); |
| 230 for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) { |
| 231 dst_row_ptr = dst_buffer[offset_y]; |
| 232 src_row_ptr = src_buffer[offset_y]; |
| 233 for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks; dst_blk_x++) { |
| 234 if (x_crop_blocks + dst_blk_x < comp_width) { |
| 235 /* Do the mirrorable blocks */ |
| 236 dst_ptr = dst_row_ptr[dst_blk_x]; |
| 237 src_ptr = src_row_ptr[comp_width - x_crop_blocks - dst_blk_x - 1]; |
| 238 /* this unrolled loop doesn't need to know which row it's on... */ |
| 239 for (k = 0; k < DCTSIZE2; k += 2) { |
| 240 *dst_ptr++ = *src_ptr++; /* copy even column */ |
| 241 *dst_ptr++ = - *src_ptr++; /* copy odd column with sign change */ |
| 242 } |
| 243 } else { |
| 244 /* Copy last partial block(s) verbatim */ |
| 245 jcopy_block_row(src_row_ptr + dst_blk_x + x_crop_blocks, |
| 246 dst_row_ptr + dst_blk_x, |
| 247 (JDIMENSION) 1); |
| 248 } |
| 249 } |
| 250 } |
| 251 } |
| 252 } |
| 253 } |
| 254 |
| 255 |
| 256 LOCAL(void) |
| 115 do_flip_v (j_decompress_ptr srcinfo, j_compress_ptr dstinfo, | 257 do_flip_v (j_decompress_ptr srcinfo, j_compress_ptr dstinfo, |
| 258 JDIMENSION x_crop_offset, JDIMENSION y_crop_offset, |
| 116 jvirt_barray_ptr *src_coef_arrays, | 259 jvirt_barray_ptr *src_coef_arrays, |
| 117 jvirt_barray_ptr *dst_coef_arrays) | 260 jvirt_barray_ptr *dst_coef_arrays) |
| 118 /* Vertical flip */ | 261 /* Vertical flip */ |
| 119 { | 262 { |
| 120 JDIMENSION MCU_rows, comp_height, dst_blk_x, dst_blk_y; | 263 JDIMENSION MCU_rows, comp_height, dst_blk_x, dst_blk_y; |
| 264 JDIMENSION x_crop_blocks, y_crop_blocks; |
| 121 int ci, i, j, offset_y; | 265 int ci, i, j, offset_y; |
| 122 JBLOCKARRAY src_buffer, dst_buffer; | 266 JBLOCKARRAY src_buffer, dst_buffer; |
| 123 JBLOCKROW src_row_ptr, dst_row_ptr; | 267 JBLOCKROW src_row_ptr, dst_row_ptr; |
| 124 JCOEFPTR src_ptr, dst_ptr; | 268 JCOEFPTR src_ptr, dst_ptr; |
| 125 jpeg_component_info *compptr; | 269 jpeg_component_info *compptr; |
| 126 | 270 |
| 127 /* We output into a separate array because we can't touch different | 271 /* We output into a separate array because we can't touch different |
| 128 * rows of the source virtual array simultaneously. Otherwise, this | 272 * rows of the source virtual array simultaneously. Otherwise, this |
| 129 * is a pretty straightforward analog of horizontal flip. | 273 * is a pretty straightforward analog of horizontal flip. |
| 130 * Within a DCT block, vertical mirroring is done by changing the signs | 274 * Within a DCT block, vertical mirroring is done by changing the signs |
| 131 * of odd-numbered rows. | 275 * of odd-numbered rows. |
| 132 * Partial iMCUs at the bottom edge are copied verbatim. | 276 * Partial iMCUs at the bottom edge are copied verbatim. |
| 133 */ | 277 */ |
| 134 MCU_rows = dstinfo->image_height / (dstinfo->max_v_samp_factor * DCTSIZE); | 278 MCU_rows = srcinfo->output_height / |
| 279 (dstinfo->max_v_samp_factor * dstinfo_min_DCT_v_scaled_size); |
| 135 | 280 |
| 136 for (ci = 0; ci < dstinfo->num_components; ci++) { | 281 for (ci = 0; ci < dstinfo->num_components; ci++) { |
| 137 compptr = dstinfo->comp_info + ci; | 282 compptr = dstinfo->comp_info + ci; |
| 138 comp_height = MCU_rows * compptr->v_samp_factor; | 283 comp_height = MCU_rows * compptr->v_samp_factor; |
| 284 x_crop_blocks = x_crop_offset * compptr->h_samp_factor; |
| 285 y_crop_blocks = y_crop_offset * compptr->v_samp_factor; |
| 139 for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks; | 286 for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks; |
| 140 dst_blk_y += compptr->v_samp_factor) { | 287 dst_blk_y += compptr->v_samp_factor) { |
| 141 dst_buffer = (*srcinfo->mem->access_virt_barray) | 288 dst_buffer = (*srcinfo->mem->access_virt_barray) |
| 142 ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y, | 289 ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y, |
| 143 (JDIMENSION) compptr->v_samp_factor, TRUE); | 290 (JDIMENSION) compptr->v_samp_factor, TRUE); |
| 144 if (dst_blk_y < comp_height) { | 291 if (y_crop_blocks + dst_blk_y < comp_height) { |
| 145 /* Row is within the mirrorable area. */ | 292 /* Row is within the mirrorable area. */ |
| 146 src_buffer = (*srcinfo->mem->access_virt_barray) | 293 src_buffer = (*srcinfo->mem->access_virt_barray) |
| 147 ((j_common_ptr) srcinfo, src_coef_arrays[ci], | 294 ((j_common_ptr) srcinfo, src_coef_arrays[ci], |
| 148 » comp_height - dst_blk_y - (JDIMENSION) compptr->v_samp_factor, | 295 » comp_height - y_crop_blocks - dst_blk_y - |
| 296 » (JDIMENSION) compptr->v_samp_factor, |
| 149 (JDIMENSION) compptr->v_samp_factor, FALSE); | 297 (JDIMENSION) compptr->v_samp_factor, FALSE); |
| 150 } else { | 298 } else { |
| 151 /* Bottom-edge blocks will be copied verbatim. */ | 299 /* Bottom-edge blocks will be copied verbatim. */ |
| 152 src_buffer = (*srcinfo->mem->access_virt_barray) | 300 src_buffer = (*srcinfo->mem->access_virt_barray) |
| 153 » ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_y, | 301 » ((j_common_ptr) srcinfo, src_coef_arrays[ci], |
| 302 » dst_blk_y + y_crop_blocks, |
| 154 (JDIMENSION) compptr->v_samp_factor, FALSE); | 303 (JDIMENSION) compptr->v_samp_factor, FALSE); |
| 155 } | 304 } |
| 156 for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) { | 305 for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) { |
| 157 » if (dst_blk_y < comp_height) { | 306 » if (y_crop_blocks + dst_blk_y < comp_height) { |
| 158 /* Row is within the mirrorable area. */ | 307 /* Row is within the mirrorable area. */ |
| 159 dst_row_ptr = dst_buffer[offset_y]; | 308 dst_row_ptr = dst_buffer[offset_y]; |
| 160 src_row_ptr = src_buffer[compptr->v_samp_factor - offset_y - 1]; | 309 src_row_ptr = src_buffer[compptr->v_samp_factor - offset_y - 1]; |
| 310 src_row_ptr += x_crop_blocks; |
| 161 for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks; | 311 for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks; |
| 162 dst_blk_x++) { | 312 dst_blk_x++) { |
| 163 dst_ptr = dst_row_ptr[dst_blk_x]; | 313 dst_ptr = dst_row_ptr[dst_blk_x]; |
| 164 src_ptr = src_row_ptr[dst_blk_x]; | 314 src_ptr = src_row_ptr[dst_blk_x]; |
| 165 for (i = 0; i < DCTSIZE; i += 2) { | 315 for (i = 0; i < DCTSIZE; i += 2) { |
| 166 /* copy even row */ | 316 /* copy even row */ |
| 167 for (j = 0; j < DCTSIZE; j++) | 317 for (j = 0; j < DCTSIZE; j++) |
| 168 *dst_ptr++ = *src_ptr++; | 318 *dst_ptr++ = *src_ptr++; |
| 169 /* copy odd row with sign change */ | 319 /* copy odd row with sign change */ |
| 170 for (j = 0; j < DCTSIZE; j++) | 320 for (j = 0; j < DCTSIZE; j++) |
| 171 *dst_ptr++ = - *src_ptr++; | 321 *dst_ptr++ = - *src_ptr++; |
| 172 } | 322 } |
| 173 } | 323 } |
| 174 } else { | 324 } else { |
| 175 /* Just copy row verbatim. */ | 325 /* Just copy row verbatim. */ |
| 176 » jcopy_block_row(src_buffer[offset_y], dst_buffer[offset_y], | 326 » jcopy_block_row(src_buffer[offset_y] + x_crop_blocks, |
| 327 » » » dst_buffer[offset_y], |
| 177 compptr->width_in_blocks); | 328 compptr->width_in_blocks); |
| 178 } | 329 } |
| 179 } | 330 } |
| 180 } | 331 } |
| 181 } | 332 } |
| 182 } | 333 } |
| 183 | 334 |
| 184 | 335 |
| 185 LOCAL(void) | 336 LOCAL(void) |
| 186 do_transpose (j_decompress_ptr srcinfo, j_compress_ptr dstinfo, | 337 do_transpose (j_decompress_ptr srcinfo, j_compress_ptr dstinfo, |
| 338 JDIMENSION x_crop_offset, JDIMENSION y_crop_offset, |
| 187 jvirt_barray_ptr *src_coef_arrays, | 339 jvirt_barray_ptr *src_coef_arrays, |
| 188 jvirt_barray_ptr *dst_coef_arrays) | 340 jvirt_barray_ptr *dst_coef_arrays) |
| 189 /* Transpose source into destination */ | 341 /* Transpose source into destination */ |
| 190 { | 342 { |
| 191 JDIMENSION dst_blk_x, dst_blk_y; | 343 JDIMENSION dst_blk_x, dst_blk_y, x_crop_blocks, y_crop_blocks; |
| 192 int ci, i, j, offset_x, offset_y; | 344 int ci, i, j, offset_x, offset_y; |
| 193 JBLOCKARRAY src_buffer, dst_buffer; | 345 JBLOCKARRAY src_buffer, dst_buffer; |
| 194 JCOEFPTR src_ptr, dst_ptr; | 346 JCOEFPTR src_ptr, dst_ptr; |
| 195 jpeg_component_info *compptr; | 347 jpeg_component_info *compptr; |
| 196 | 348 |
| 197 /* Transposing pixels within a block just requires transposing the | 349 /* Transposing pixels within a block just requires transposing the |
| 198 * DCT coefficients. | 350 * DCT coefficients. |
| 199 * Partial iMCUs at the edges require no special treatment; we simply | 351 * Partial iMCUs at the edges require no special treatment; we simply |
| 200 * process all the available DCT blocks for every component. | 352 * process all the available DCT blocks for every component. |
| 201 */ | 353 */ |
| 202 for (ci = 0; ci < dstinfo->num_components; ci++) { | 354 for (ci = 0; ci < dstinfo->num_components; ci++) { |
| 203 compptr = dstinfo->comp_info + ci; | 355 compptr = dstinfo->comp_info + ci; |
| 356 x_crop_blocks = x_crop_offset * compptr->h_samp_factor; |
| 357 y_crop_blocks = y_crop_offset * compptr->v_samp_factor; |
| 204 for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks; | 358 for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks; |
| 205 dst_blk_y += compptr->v_samp_factor) { | 359 dst_blk_y += compptr->v_samp_factor) { |
| 206 dst_buffer = (*srcinfo->mem->access_virt_barray) | 360 dst_buffer = (*srcinfo->mem->access_virt_barray) |
| 207 ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y, | 361 ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y, |
| 208 (JDIMENSION) compptr->v_samp_factor, TRUE); | 362 (JDIMENSION) compptr->v_samp_factor, TRUE); |
| 209 for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) { | 363 for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) { |
| 210 for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks; | 364 for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks; |
| 211 dst_blk_x += compptr->h_samp_factor) { | 365 dst_blk_x += compptr->h_samp_factor) { |
| 212 src_buffer = (*srcinfo->mem->access_virt_barray) | 366 src_buffer = (*srcinfo->mem->access_virt_barray) |
| 213 » ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_x, | 367 » ((j_common_ptr) srcinfo, src_coef_arrays[ci], |
| 368 » dst_blk_x + x_crop_blocks, |
| 214 (JDIMENSION) compptr->h_samp_factor, FALSE); | 369 (JDIMENSION) compptr->h_samp_factor, FALSE); |
| 215 for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) { | 370 for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) { |
| 216 src_ptr = src_buffer[offset_x][dst_blk_y + offset_y]; | |
| 217 dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x]; | 371 dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x]; |
| 372 src_ptr = src_buffer[offset_x][dst_blk_y + offset_y + y_crop_blocks]
; |
| 218 for (i = 0; i < DCTSIZE; i++) | 373 for (i = 0; i < DCTSIZE; i++) |
| 219 for (j = 0; j < DCTSIZE; j++) | 374 for (j = 0; j < DCTSIZE; j++) |
| 220 dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j]; | 375 dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j]; |
| 221 } | 376 } |
| 222 } | 377 } |
| 223 } | 378 } |
| 224 } | 379 } |
| 225 } | 380 } |
| 226 } | 381 } |
| 227 | 382 |
| 228 | 383 |
| 229 LOCAL(void) | 384 LOCAL(void) |
| 230 do_rot_90 (j_decompress_ptr srcinfo, j_compress_ptr dstinfo, | 385 do_rot_90 (j_decompress_ptr srcinfo, j_compress_ptr dstinfo, |
| 386 JDIMENSION x_crop_offset, JDIMENSION y_crop_offset, |
| 231 jvirt_barray_ptr *src_coef_arrays, | 387 jvirt_barray_ptr *src_coef_arrays, |
| 232 jvirt_barray_ptr *dst_coef_arrays) | 388 jvirt_barray_ptr *dst_coef_arrays) |
| 233 /* 90 degree rotation is equivalent to | 389 /* 90 degree rotation is equivalent to |
| 234 * 1. Transposing the image; | 390 * 1. Transposing the image; |
| 235 * 2. Horizontal mirroring. | 391 * 2. Horizontal mirroring. |
| 236 * These two steps are merged into a single processing routine. | 392 * These two steps are merged into a single processing routine. |
| 237 */ | 393 */ |
| 238 { | 394 { |
| 239 JDIMENSION MCU_cols, comp_width, dst_blk_x, dst_blk_y; | 395 JDIMENSION MCU_cols, comp_width, dst_blk_x, dst_blk_y; |
| 396 JDIMENSION x_crop_blocks, y_crop_blocks; |
| 240 int ci, i, j, offset_x, offset_y; | 397 int ci, i, j, offset_x, offset_y; |
| 241 JBLOCKARRAY src_buffer, dst_buffer; | 398 JBLOCKARRAY src_buffer, dst_buffer; |
| 242 JCOEFPTR src_ptr, dst_ptr; | 399 JCOEFPTR src_ptr, dst_ptr; |
| 243 jpeg_component_info *compptr; | 400 jpeg_component_info *compptr; |
| 244 | 401 |
| 245 /* Because of the horizontal mirror step, we can't process partial iMCUs | 402 /* Because of the horizontal mirror step, we can't process partial iMCUs |
| 246 * at the (output) right edge properly. They just get transposed and | 403 * at the (output) right edge properly. They just get transposed and |
| 247 * not mirrored. | 404 * not mirrored. |
| 248 */ | 405 */ |
| 249 MCU_cols = dstinfo->image_width / (dstinfo->max_h_samp_factor * DCTSIZE); | 406 MCU_cols = srcinfo->output_height / |
| 407 (dstinfo->max_h_samp_factor * dstinfo_min_DCT_h_scaled_size); |
| 250 | 408 |
| 251 for (ci = 0; ci < dstinfo->num_components; ci++) { | 409 for (ci = 0; ci < dstinfo->num_components; ci++) { |
| 252 compptr = dstinfo->comp_info + ci; | 410 compptr = dstinfo->comp_info + ci; |
| 253 comp_width = MCU_cols * compptr->h_samp_factor; | 411 comp_width = MCU_cols * compptr->h_samp_factor; |
| 412 x_crop_blocks = x_crop_offset * compptr->h_samp_factor; |
| 413 y_crop_blocks = y_crop_offset * compptr->v_samp_factor; |
| 254 for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks; | 414 for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks; |
| 255 dst_blk_y += compptr->v_samp_factor) { | 415 dst_blk_y += compptr->v_samp_factor) { |
| 256 dst_buffer = (*srcinfo->mem->access_virt_barray) | 416 dst_buffer = (*srcinfo->mem->access_virt_barray) |
| 257 ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y, | 417 ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y, |
| 258 (JDIMENSION) compptr->v_samp_factor, TRUE); | 418 (JDIMENSION) compptr->v_samp_factor, TRUE); |
| 259 for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) { | 419 for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) { |
| 260 for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks; | 420 for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks; |
| 261 dst_blk_x += compptr->h_samp_factor) { | 421 dst_blk_x += compptr->h_samp_factor) { |
| 262 » src_buffer = (*srcinfo->mem->access_virt_barray) | 422 » if (x_crop_blocks + dst_blk_x < comp_width) { |
| 263 » ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_x, | 423 » /* Block is within the mirrorable area. */ |
| 264 » (JDIMENSION) compptr->h_samp_factor, FALSE); | 424 » src_buffer = (*srcinfo->mem->access_virt_barray) |
| 425 » ((j_common_ptr) srcinfo, src_coef_arrays[ci], |
| 426 » comp_width - x_crop_blocks - dst_blk_x - |
| 427 » (JDIMENSION) compptr->h_samp_factor, |
| 428 » (JDIMENSION) compptr->h_samp_factor, FALSE); |
| 429 » } else { |
| 430 » /* Edge blocks are transposed but not mirrored. */ |
| 431 » src_buffer = (*srcinfo->mem->access_virt_barray) |
| 432 » ((j_common_ptr) srcinfo, src_coef_arrays[ci], |
| 433 » dst_blk_x + x_crop_blocks, |
| 434 » (JDIMENSION) compptr->h_samp_factor, FALSE); |
| 435 » } |
| 265 for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) { | 436 for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) { |
| 266 » src_ptr = src_buffer[offset_x][dst_blk_y + offset_y]; | 437 » dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x]; |
| 267 » if (dst_blk_x < comp_width) { | 438 » if (x_crop_blocks + dst_blk_x < comp_width) { |
| 268 /* Block is within the mirrorable area. */ | 439 /* Block is within the mirrorable area. */ |
| 269 » dst_ptr = dst_buffer[offset_y] | 440 » src_ptr = src_buffer[compptr->h_samp_factor - offset_x - 1] |
| 270 » » [comp_width - dst_blk_x - offset_x - 1]; | 441 » » [dst_blk_y + offset_y + y_crop_blocks]; |
| 271 for (i = 0; i < DCTSIZE; i++) { | 442 for (i = 0; i < DCTSIZE; i++) { |
| 272 for (j = 0; j < DCTSIZE; j++) | 443 for (j = 0; j < DCTSIZE; j++) |
| 273 dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j]; | 444 dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j]; |
| 274 i++; | 445 i++; |
| 275 for (j = 0; j < DCTSIZE; j++) | 446 for (j = 0; j < DCTSIZE; j++) |
| 276 dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j]; | 447 dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j]; |
| 277 } | 448 } |
| 278 } else { | 449 } else { |
| 279 /* Edge blocks are transposed but not mirrored. */ | 450 /* Edge blocks are transposed but not mirrored. */ |
| 280 » dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x]; | 451 » src_ptr = src_buffer[offset_x] |
| 452 » » [dst_blk_y + offset_y + y_crop_blocks]; |
| 281 for (i = 0; i < DCTSIZE; i++) | 453 for (i = 0; i < DCTSIZE; i++) |
| 282 for (j = 0; j < DCTSIZE; j++) | 454 for (j = 0; j < DCTSIZE; j++) |
| 283 dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j]; | 455 dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j]; |
| 284 } | 456 } |
| 285 } | 457 } |
| 286 } | 458 } |
| 287 } | 459 } |
| 288 } | 460 } |
| 289 } | 461 } |
| 290 } | 462 } |
| 291 | 463 |
| 292 | 464 |
| 293 LOCAL(void) | 465 LOCAL(void) |
| 294 do_rot_270 (j_decompress_ptr srcinfo, j_compress_ptr dstinfo, | 466 do_rot_270 (j_decompress_ptr srcinfo, j_compress_ptr dstinfo, |
| 467 JDIMENSION x_crop_offset, JDIMENSION y_crop_offset, |
| 295 jvirt_barray_ptr *src_coef_arrays, | 468 jvirt_barray_ptr *src_coef_arrays, |
| 296 jvirt_barray_ptr *dst_coef_arrays) | 469 jvirt_barray_ptr *dst_coef_arrays) |
| 297 /* 270 degree rotation is equivalent to | 470 /* 270 degree rotation is equivalent to |
| 298 * 1. Horizontal mirroring; | 471 * 1. Horizontal mirroring; |
| 299 * 2. Transposing the image. | 472 * 2. Transposing the image. |
| 300 * These two steps are merged into a single processing routine. | 473 * These two steps are merged into a single processing routine. |
| 301 */ | 474 */ |
| 302 { | 475 { |
| 303 JDIMENSION MCU_rows, comp_height, dst_blk_x, dst_blk_y; | 476 JDIMENSION MCU_rows, comp_height, dst_blk_x, dst_blk_y; |
| 477 JDIMENSION x_crop_blocks, y_crop_blocks; |
| 304 int ci, i, j, offset_x, offset_y; | 478 int ci, i, j, offset_x, offset_y; |
| 305 JBLOCKARRAY src_buffer, dst_buffer; | 479 JBLOCKARRAY src_buffer, dst_buffer; |
| 306 JCOEFPTR src_ptr, dst_ptr; | 480 JCOEFPTR src_ptr, dst_ptr; |
| 307 jpeg_component_info *compptr; | 481 jpeg_component_info *compptr; |
| 308 | 482 |
| 309 /* Because of the horizontal mirror step, we can't process partial iMCUs | 483 /* Because of the horizontal mirror step, we can't process partial iMCUs |
| 310 * at the (output) bottom edge properly. They just get transposed and | 484 * at the (output) bottom edge properly. They just get transposed and |
| 311 * not mirrored. | 485 * not mirrored. |
| 312 */ | 486 */ |
| 313 MCU_rows = dstinfo->image_height / (dstinfo->max_v_samp_factor * DCTSIZE); | 487 MCU_rows = srcinfo->output_width / |
| 488 (dstinfo->max_v_samp_factor * dstinfo_min_DCT_v_scaled_size); |
| 314 | 489 |
| 315 for (ci = 0; ci < dstinfo->num_components; ci++) { | 490 for (ci = 0; ci < dstinfo->num_components; ci++) { |
| 316 compptr = dstinfo->comp_info + ci; | 491 compptr = dstinfo->comp_info + ci; |
| 317 comp_height = MCU_rows * compptr->v_samp_factor; | 492 comp_height = MCU_rows * compptr->v_samp_factor; |
| 493 x_crop_blocks = x_crop_offset * compptr->h_samp_factor; |
| 494 y_crop_blocks = y_crop_offset * compptr->v_samp_factor; |
| 318 for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks; | 495 for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks; |
| 319 dst_blk_y += compptr->v_samp_factor) { | 496 dst_blk_y += compptr->v_samp_factor) { |
| 320 dst_buffer = (*srcinfo->mem->access_virt_barray) | 497 dst_buffer = (*srcinfo->mem->access_virt_barray) |
| 321 ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y, | 498 ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y, |
| 322 (JDIMENSION) compptr->v_samp_factor, TRUE); | 499 (JDIMENSION) compptr->v_samp_factor, TRUE); |
| 323 for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) { | 500 for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) { |
| 324 for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks; | 501 for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks; |
| 325 dst_blk_x += compptr->h_samp_factor) { | 502 dst_blk_x += compptr->h_samp_factor) { |
| 326 src_buffer = (*srcinfo->mem->access_virt_barray) | 503 src_buffer = (*srcinfo->mem->access_virt_barray) |
| 327 » ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_x, | 504 » ((j_common_ptr) srcinfo, src_coef_arrays[ci], |
| 505 » dst_blk_x + x_crop_blocks, |
| 328 (JDIMENSION) compptr->h_samp_factor, FALSE); | 506 (JDIMENSION) compptr->h_samp_factor, FALSE); |
| 329 for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) { | 507 for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) { |
| 330 dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x]; | 508 dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x]; |
| 331 » if (dst_blk_y < comp_height) { | 509 » if (y_crop_blocks + dst_blk_y < comp_height) { |
| 332 /* Block is within the mirrorable area. */ | 510 /* Block is within the mirrorable area. */ |
| 333 src_ptr = src_buffer[offset_x] | 511 src_ptr = src_buffer[offset_x] |
| 334 » » [comp_height - dst_blk_y - offset_y - 1]; | 512 » » [comp_height - y_crop_blocks - dst_blk_y - offset_y - 1]; |
| 335 for (i = 0; i < DCTSIZE; i++) { | 513 for (i = 0; i < DCTSIZE; i++) { |
| 336 for (j = 0; j < DCTSIZE; j++) { | 514 for (j = 0; j < DCTSIZE; j++) { |
| 337 dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j]; | 515 dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j]; |
| 338 j++; | 516 j++; |
| 339 dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j]; | 517 dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j]; |
| 340 } | 518 } |
| 341 } | 519 } |
| 342 } else { | 520 } else { |
| 343 /* Edge blocks are transposed but not mirrored. */ | 521 /* Edge blocks are transposed but not mirrored. */ |
| 344 » src_ptr = src_buffer[offset_x][dst_blk_y + offset_y]; | 522 » src_ptr = src_buffer[offset_x] |
| 523 » » [dst_blk_y + offset_y + y_crop_blocks]; |
| 345 for (i = 0; i < DCTSIZE; i++) | 524 for (i = 0; i < DCTSIZE; i++) |
| 346 for (j = 0; j < DCTSIZE; j++) | 525 for (j = 0; j < DCTSIZE; j++) |
| 347 dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j]; | 526 dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j]; |
| 348 } | 527 } |
| 349 } | 528 } |
| 350 } | 529 } |
| 351 } | 530 } |
| 352 } | 531 } |
| 353 } | 532 } |
| 354 } | 533 } |
| 355 | 534 |
| 356 | 535 |
| 357 LOCAL(void) | 536 LOCAL(void) |
| 358 do_rot_180 (j_decompress_ptr srcinfo, j_compress_ptr dstinfo, | 537 do_rot_180 (j_decompress_ptr srcinfo, j_compress_ptr dstinfo, |
| 538 JDIMENSION x_crop_offset, JDIMENSION y_crop_offset, |
| 359 jvirt_barray_ptr *src_coef_arrays, | 539 jvirt_barray_ptr *src_coef_arrays, |
| 360 jvirt_barray_ptr *dst_coef_arrays) | 540 jvirt_barray_ptr *dst_coef_arrays) |
| 361 /* 180 degree rotation is equivalent to | 541 /* 180 degree rotation is equivalent to |
| 362 * 1. Vertical mirroring; | 542 * 1. Vertical mirroring; |
| 363 * 2. Horizontal mirroring. | 543 * 2. Horizontal mirroring. |
| 364 * These two steps are merged into a single processing routine. | 544 * These two steps are merged into a single processing routine. |
| 365 */ | 545 */ |
| 366 { | 546 { |
| 367 JDIMENSION MCU_cols, MCU_rows, comp_width, comp_height, dst_blk_x, dst_blk_y; | 547 JDIMENSION MCU_cols, MCU_rows, comp_width, comp_height, dst_blk_x, dst_blk_y; |
| 548 JDIMENSION x_crop_blocks, y_crop_blocks; |
| 368 int ci, i, j, offset_y; | 549 int ci, i, j, offset_y; |
| 369 JBLOCKARRAY src_buffer, dst_buffer; | 550 JBLOCKARRAY src_buffer, dst_buffer; |
| 370 JBLOCKROW src_row_ptr, dst_row_ptr; | 551 JBLOCKROW src_row_ptr, dst_row_ptr; |
| 371 JCOEFPTR src_ptr, dst_ptr; | 552 JCOEFPTR src_ptr, dst_ptr; |
| 372 jpeg_component_info *compptr; | 553 jpeg_component_info *compptr; |
| 373 | 554 |
| 374 MCU_cols = dstinfo->image_width / (dstinfo->max_h_samp_factor * DCTSIZE); | 555 MCU_cols = srcinfo->output_width / |
| 375 MCU_rows = dstinfo->image_height / (dstinfo->max_v_samp_factor * DCTSIZE); | 556 (dstinfo->max_h_samp_factor * dstinfo_min_DCT_h_scaled_size); |
| 557 MCU_rows = srcinfo->output_height / |
| 558 (dstinfo->max_v_samp_factor * dstinfo_min_DCT_v_scaled_size); |
| 376 | 559 |
| 377 for (ci = 0; ci < dstinfo->num_components; ci++) { | 560 for (ci = 0; ci < dstinfo->num_components; ci++) { |
| 378 compptr = dstinfo->comp_info + ci; | 561 compptr = dstinfo->comp_info + ci; |
| 379 comp_width = MCU_cols * compptr->h_samp_factor; | 562 comp_width = MCU_cols * compptr->h_samp_factor; |
| 380 comp_height = MCU_rows * compptr->v_samp_factor; | 563 comp_height = MCU_rows * compptr->v_samp_factor; |
| 564 x_crop_blocks = x_crop_offset * compptr->h_samp_factor; |
| 565 y_crop_blocks = y_crop_offset * compptr->v_samp_factor; |
| 381 for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks; | 566 for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks; |
| 382 dst_blk_y += compptr->v_samp_factor) { | 567 dst_blk_y += compptr->v_samp_factor) { |
| 383 dst_buffer = (*srcinfo->mem->access_virt_barray) | 568 dst_buffer = (*srcinfo->mem->access_virt_barray) |
| 384 ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y, | 569 ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y, |
| 385 (JDIMENSION) compptr->v_samp_factor, TRUE); | 570 (JDIMENSION) compptr->v_samp_factor, TRUE); |
| 386 if (dst_blk_y < comp_height) { | 571 if (y_crop_blocks + dst_blk_y < comp_height) { |
| 387 /* Row is within the vertically mirrorable area. */ | 572 /* Row is within the vertically mirrorable area. */ |
| 388 src_buffer = (*srcinfo->mem->access_virt_barray) | 573 src_buffer = (*srcinfo->mem->access_virt_barray) |
| 389 ((j_common_ptr) srcinfo, src_coef_arrays[ci], | 574 ((j_common_ptr) srcinfo, src_coef_arrays[ci], |
| 390 » comp_height - dst_blk_y - (JDIMENSION) compptr->v_samp_factor, | 575 » comp_height - y_crop_blocks - dst_blk_y - |
| 576 » (JDIMENSION) compptr->v_samp_factor, |
| 391 (JDIMENSION) compptr->v_samp_factor, FALSE); | 577 (JDIMENSION) compptr->v_samp_factor, FALSE); |
| 392 } else { | 578 } else { |
| 393 /* Bottom-edge rows are only mirrored horizontally. */ | 579 /* Bottom-edge rows are only mirrored horizontally. */ |
| 394 src_buffer = (*srcinfo->mem->access_virt_barray) | 580 src_buffer = (*srcinfo->mem->access_virt_barray) |
| 395 » ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_y, | 581 » ((j_common_ptr) srcinfo, src_coef_arrays[ci], |
| 582 » dst_blk_y + y_crop_blocks, |
| 396 (JDIMENSION) compptr->v_samp_factor, FALSE); | 583 (JDIMENSION) compptr->v_samp_factor, FALSE); |
| 397 } | 584 } |
| 398 for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) { | 585 for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) { |
| 399 » if (dst_blk_y < comp_height) { | 586 » dst_row_ptr = dst_buffer[offset_y]; |
| 587 » if (y_crop_blocks + dst_blk_y < comp_height) { |
| 400 /* Row is within the mirrorable area. */ | 588 /* Row is within the mirrorable area. */ |
| 401 dst_row_ptr = dst_buffer[offset_y]; | |
| 402 src_row_ptr = src_buffer[compptr->v_samp_factor - offset_y - 1]; | 589 src_row_ptr = src_buffer[compptr->v_samp_factor - offset_y - 1]; |
| 403 » /* Process the blocks that can be mirrored both ways. */ | 590 » for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks; dst_blk_x++)
{ |
| 404 » for (dst_blk_x = 0; dst_blk_x < comp_width; dst_blk_x++) { | |
| 405 dst_ptr = dst_row_ptr[dst_blk_x]; | 591 dst_ptr = dst_row_ptr[dst_blk_x]; |
| 406 » src_ptr = src_row_ptr[comp_width - dst_blk_x - 1]; | 592 » if (x_crop_blocks + dst_blk_x < comp_width) { |
| 407 » for (i = 0; i < DCTSIZE; i += 2) { | 593 » /* Process the blocks that can be mirrored both ways. */ |
| 408 » /* For even row, negate every odd column. */ | 594 » src_ptr = src_row_ptr[comp_width - x_crop_blocks - dst_blk_x - 1]; |
| 409 » for (j = 0; j < DCTSIZE; j += 2) { | 595 » for (i = 0; i < DCTSIZE; i += 2) { |
| 410 » » *dst_ptr++ = *src_ptr++; | 596 » » /* For even row, negate every odd column. */ |
| 411 » » *dst_ptr++ = - *src_ptr++; | 597 » » for (j = 0; j < DCTSIZE; j += 2) { |
| 598 » » *dst_ptr++ = *src_ptr++; |
| 599 » » *dst_ptr++ = - *src_ptr++; |
| 600 » » } |
| 601 » » /* For odd row, negate every even column. */ |
| 602 » » for (j = 0; j < DCTSIZE; j += 2) { |
| 603 » » *dst_ptr++ = - *src_ptr++; |
| 604 » » *dst_ptr++ = *src_ptr++; |
| 605 » » } |
| 412 } | 606 } |
| 413 » /* For odd row, negate every even column. */ | 607 » } else { |
| 414 » for (j = 0; j < DCTSIZE; j += 2) { | 608 » /* Any remaining right-edge blocks are only mirrored vertically. *
/ |
| 415 » » *dst_ptr++ = - *src_ptr++; | 609 » src_ptr = src_row_ptr[x_crop_blocks + dst_blk_x]; |
| 416 » » *dst_ptr++ = *src_ptr++; | 610 » for (i = 0; i < DCTSIZE; i += 2) { |
| 611 » » for (j = 0; j < DCTSIZE; j++) |
| 612 » » *dst_ptr++ = *src_ptr++; |
| 613 » » for (j = 0; j < DCTSIZE; j++) |
| 614 » » *dst_ptr++ = - *src_ptr++; |
| 417 } | 615 } |
| 418 } | 616 } |
| 419 } | 617 } |
| 420 /* Any remaining right-edge blocks are only mirrored vertically. */ | |
| 421 for (; dst_blk_x < compptr->width_in_blocks; dst_blk_x++) { | |
| 422 dst_ptr = dst_row_ptr[dst_blk_x]; | |
| 423 src_ptr = src_row_ptr[dst_blk_x]; | |
| 424 for (i = 0; i < DCTSIZE; i += 2) { | |
| 425 for (j = 0; j < DCTSIZE; j++) | |
| 426 *dst_ptr++ = *src_ptr++; | |
| 427 for (j = 0; j < DCTSIZE; j++) | |
| 428 *dst_ptr++ = - *src_ptr++; | |
| 429 } | |
| 430 } | |
| 431 } else { | 618 } else { |
| 432 /* Remaining rows are just mirrored horizontally. */ | 619 /* Remaining rows are just mirrored horizontally. */ |
| 433 dst_row_ptr = dst_buffer[offset_y]; | |
| 434 src_row_ptr = src_buffer[offset_y]; | 620 src_row_ptr = src_buffer[offset_y]; |
| 435 » /* Process the blocks that can be mirrored. */ | 621 » for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks; dst_blk_x++)
{ |
| 436 » for (dst_blk_x = 0; dst_blk_x < comp_width; dst_blk_x++) { | 622 » if (x_crop_blocks + dst_blk_x < comp_width) { |
| 437 » dst_ptr = dst_row_ptr[dst_blk_x]; | 623 » /* Process the blocks that can be mirrored. */ |
| 438 » src_ptr = src_row_ptr[comp_width - dst_blk_x - 1]; | 624 » dst_ptr = dst_row_ptr[dst_blk_x]; |
| 439 » for (i = 0; i < DCTSIZE2; i += 2) { | 625 » src_ptr = src_row_ptr[comp_width - x_crop_blocks - dst_blk_x - 1]; |
| 440 » *dst_ptr++ = *src_ptr++; | 626 » for (i = 0; i < DCTSIZE2; i += 2) { |
| 441 » *dst_ptr++ = - *src_ptr++; | 627 » » *dst_ptr++ = *src_ptr++; |
| 628 » » *dst_ptr++ = - *src_ptr++; |
| 629 » } |
| 630 » } else { |
| 631 » /* Any remaining right-edge blocks are only copied. */ |
| 632 » jcopy_block_row(src_row_ptr + dst_blk_x + x_crop_blocks, |
| 633 » » » dst_row_ptr + dst_blk_x, |
| 634 » » » (JDIMENSION) 1); |
| 442 } | 635 } |
| 443 } | 636 } |
| 444 /* Any remaining right-edge blocks are only copied. */ | |
| 445 for (; dst_blk_x < compptr->width_in_blocks; dst_blk_x++) { | |
| 446 dst_ptr = dst_row_ptr[dst_blk_x]; | |
| 447 src_ptr = src_row_ptr[dst_blk_x]; | |
| 448 for (i = 0; i < DCTSIZE2; i++) | |
| 449 *dst_ptr++ = *src_ptr++; | |
| 450 } | |
| 451 } | 637 } |
| 452 } | 638 } |
| 453 } | 639 } |
| 454 } | 640 } |
| 455 } | 641 } |
| 456 | 642 |
| 457 | 643 |
| 458 LOCAL(void) | 644 LOCAL(void) |
| 459 do_transverse (j_decompress_ptr srcinfo, j_compress_ptr dstinfo, | 645 do_transverse (j_decompress_ptr srcinfo, j_compress_ptr dstinfo, |
| 646 JDIMENSION x_crop_offset, JDIMENSION y_crop_offset, |
| 460 jvirt_barray_ptr *src_coef_arrays, | 647 jvirt_barray_ptr *src_coef_arrays, |
| 461 jvirt_barray_ptr *dst_coef_arrays) | 648 jvirt_barray_ptr *dst_coef_arrays) |
| 462 /* Transverse transpose is equivalent to | 649 /* Transverse transpose is equivalent to |
| 463 * 1. 180 degree rotation; | 650 * 1. 180 degree rotation; |
| 464 * 2. Transposition; | 651 * 2. Transposition; |
| 465 * or | 652 * or |
| 466 * 1. Horizontal mirroring; | 653 * 1. Horizontal mirroring; |
| 467 * 2. Transposition; | 654 * 2. Transposition; |
| 468 * 3. Horizontal mirroring. | 655 * 3. Horizontal mirroring. |
| 469 * These steps are merged into a single processing routine. | 656 * These steps are merged into a single processing routine. |
| 470 */ | 657 */ |
| 471 { | 658 { |
| 472 JDIMENSION MCU_cols, MCU_rows, comp_width, comp_height, dst_blk_x, dst_blk_y; | 659 JDIMENSION MCU_cols, MCU_rows, comp_width, comp_height, dst_blk_x, dst_blk_y; |
| 660 JDIMENSION x_crop_blocks, y_crop_blocks; |
| 473 int ci, i, j, offset_x, offset_y; | 661 int ci, i, j, offset_x, offset_y; |
| 474 JBLOCKARRAY src_buffer, dst_buffer; | 662 JBLOCKARRAY src_buffer, dst_buffer; |
| 475 JCOEFPTR src_ptr, dst_ptr; | 663 JCOEFPTR src_ptr, dst_ptr; |
| 476 jpeg_component_info *compptr; | 664 jpeg_component_info *compptr; |
| 477 | 665 |
| 478 MCU_cols = dstinfo->image_width / (dstinfo->max_h_samp_factor * DCTSIZE); | 666 MCU_cols = srcinfo->output_height / |
| 479 MCU_rows = dstinfo->image_height / (dstinfo->max_v_samp_factor * DCTSIZE); | 667 (dstinfo->max_h_samp_factor * dstinfo_min_DCT_h_scaled_size); |
| 668 MCU_rows = srcinfo->output_width / |
| 669 (dstinfo->max_v_samp_factor * dstinfo_min_DCT_v_scaled_size); |
| 480 | 670 |
| 481 for (ci = 0; ci < dstinfo->num_components; ci++) { | 671 for (ci = 0; ci < dstinfo->num_components; ci++) { |
| 482 compptr = dstinfo->comp_info + ci; | 672 compptr = dstinfo->comp_info + ci; |
| 483 comp_width = MCU_cols * compptr->h_samp_factor; | 673 comp_width = MCU_cols * compptr->h_samp_factor; |
| 484 comp_height = MCU_rows * compptr->v_samp_factor; | 674 comp_height = MCU_rows * compptr->v_samp_factor; |
| 675 x_crop_blocks = x_crop_offset * compptr->h_samp_factor; |
| 676 y_crop_blocks = y_crop_offset * compptr->v_samp_factor; |
| 485 for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks; | 677 for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks; |
| 486 dst_blk_y += compptr->v_samp_factor) { | 678 dst_blk_y += compptr->v_samp_factor) { |
| 487 dst_buffer = (*srcinfo->mem->access_virt_barray) | 679 dst_buffer = (*srcinfo->mem->access_virt_barray) |
| 488 ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y, | 680 ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y, |
| 489 (JDIMENSION) compptr->v_samp_factor, TRUE); | 681 (JDIMENSION) compptr->v_samp_factor, TRUE); |
| 490 for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) { | 682 for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) { |
| 491 for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks; | 683 for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks; |
| 492 dst_blk_x += compptr->h_samp_factor) { | 684 dst_blk_x += compptr->h_samp_factor) { |
| 493 » src_buffer = (*srcinfo->mem->access_virt_barray) | 685 » if (x_crop_blocks + dst_blk_x < comp_width) { |
| 494 » ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_x, | 686 » /* Block is within the mirrorable area. */ |
| 495 » (JDIMENSION) compptr->h_samp_factor, FALSE); | 687 » src_buffer = (*srcinfo->mem->access_virt_barray) |
| 688 » ((j_common_ptr) srcinfo, src_coef_arrays[ci], |
| 689 » comp_width - x_crop_blocks - dst_blk_x - |
| 690 » (JDIMENSION) compptr->h_samp_factor, |
| 691 » (JDIMENSION) compptr->h_samp_factor, FALSE); |
| 692 » } else { |
| 693 » src_buffer = (*srcinfo->mem->access_virt_barray) |
| 694 » ((j_common_ptr) srcinfo, src_coef_arrays[ci], |
| 695 » dst_blk_x + x_crop_blocks, |
| 696 » (JDIMENSION) compptr->h_samp_factor, FALSE); |
| 697 » } |
| 496 for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) { | 698 for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) { |
| 497 » if (dst_blk_y < comp_height) { | 699 » dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x]; |
| 498 » src_ptr = src_buffer[offset_x] | 700 » if (y_crop_blocks + dst_blk_y < comp_height) { |
| 499 » » [comp_height - dst_blk_y - offset_y - 1]; | 701 » if (x_crop_blocks + dst_blk_x < comp_width) { |
| 500 » if (dst_blk_x < comp_width) { | |
| 501 /* Block is within the mirrorable area. */ | 702 /* Block is within the mirrorable area. */ |
| 502 » » dst_ptr = dst_buffer[offset_y] | 703 » » src_ptr = src_buffer[compptr->h_samp_factor - offset_x - 1] |
| 503 » » [comp_width - dst_blk_x - offset_x - 1]; | 704 » » [comp_height - y_crop_blocks - dst_blk_y - offset_y - 1]; |
| 504 for (i = 0; i < DCTSIZE; i++) { | 705 for (i = 0; i < DCTSIZE; i++) { |
| 505 for (j = 0; j < DCTSIZE; j++) { | 706 for (j = 0; j < DCTSIZE; j++) { |
| 506 dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j]; | 707 dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j]; |
| 507 j++; | 708 j++; |
| 508 dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j]; | 709 dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j]; |
| 509 } | 710 } |
| 510 i++; | 711 i++; |
| 511 for (j = 0; j < DCTSIZE; j++) { | 712 for (j = 0; j < DCTSIZE; j++) { |
| 512 dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j]; | 713 dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j]; |
| 513 j++; | 714 j++; |
| 514 dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j]; | 715 dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j]; |
| 515 } | 716 } |
| 516 } | 717 } |
| 517 } else { | 718 } else { |
| 518 /* Right-edge blocks are mirrored in y only */ | 719 /* Right-edge blocks are mirrored in y only */ |
| 519 » » dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x]; | 720 » » src_ptr = src_buffer[offset_x] |
| 721 » » [comp_height - y_crop_blocks - dst_blk_y - offset_y - 1]; |
| 520 for (i = 0; i < DCTSIZE; i++) { | 722 for (i = 0; i < DCTSIZE; i++) { |
| 521 for (j = 0; j < DCTSIZE; j++) { | 723 for (j = 0; j < DCTSIZE; j++) { |
| 522 dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j]; | 724 dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j]; |
| 523 j++; | 725 j++; |
| 524 dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j]; | 726 dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j]; |
| 525 } | 727 } |
| 526 } | 728 } |
| 527 } | 729 } |
| 528 } else { | 730 } else { |
| 529 » src_ptr = src_buffer[offset_x][dst_blk_y + offset_y]; | 731 » if (x_crop_blocks + dst_blk_x < comp_width) { |
| 530 » if (dst_blk_x < comp_width) { | |
| 531 /* Bottom-edge blocks are mirrored in x only */ | 732 /* Bottom-edge blocks are mirrored in x only */ |
| 532 » » dst_ptr = dst_buffer[offset_y] | 733 » » src_ptr = src_buffer[compptr->h_samp_factor - offset_x - 1] |
| 533 » » [comp_width - dst_blk_x - offset_x - 1]; | 734 » » [dst_blk_y + offset_y + y_crop_blocks]; |
| 534 for (i = 0; i < DCTSIZE; i++) { | 735 for (i = 0; i < DCTSIZE; i++) { |
| 535 for (j = 0; j < DCTSIZE; j++) | 736 for (j = 0; j < DCTSIZE; j++) |
| 536 dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j]; | 737 dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j]; |
| 537 i++; | 738 i++; |
| 538 for (j = 0; j < DCTSIZE; j++) | 739 for (j = 0; j < DCTSIZE; j++) |
| 539 dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j]; | 740 dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j]; |
| 540 } | 741 } |
| 541 } else { | 742 } else { |
| 542 /* At lower right corner, just transpose, no mirroring */ | 743 /* At lower right corner, just transpose, no mirroring */ |
| 543 » » dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x]; | 744 » » src_ptr = src_buffer[offset_x] |
| 745 » » [dst_blk_y + offset_y + y_crop_blocks]; |
| 544 for (i = 0; i < DCTSIZE; i++) | 746 for (i = 0; i < DCTSIZE; i++) |
| 545 for (j = 0; j < DCTSIZE; j++) | 747 for (j = 0; j < DCTSIZE; j++) |
| 546 dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j]; | 748 dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j]; |
| 547 } | 749 } |
| 548 } | 750 } |
| 549 } | 751 } |
| 550 } | 752 } |
| 551 } | 753 } |
| 552 } | 754 } |
| 553 } | 755 } |
| 554 } | 756 } |
| 555 | 757 |
| 556 | 758 |
| 759 /* Parse an unsigned integer: subroutine for jtransform_parse_crop_spec. |
| 760 * Returns TRUE if valid integer found, FALSE if not. |
| 761 * *strptr is advanced over the digit string, and *result is set to its value. |
| 762 */ |
| 763 |
| 764 LOCAL(boolean) |
| 765 jt_read_integer (const char ** strptr, JDIMENSION * result) |
| 766 { |
| 767 const char * ptr = *strptr; |
| 768 JDIMENSION val = 0; |
| 769 |
| 770 for (; isdigit(*ptr); ptr++) { |
| 771 val = val * 10 + (JDIMENSION) (*ptr - '0'); |
| 772 } |
| 773 *result = val; |
| 774 if (ptr == *strptr) |
| 775 return FALSE; /* oops, no digits */ |
| 776 *strptr = ptr; |
| 777 return TRUE; |
| 778 } |
| 779 |
| 780 |
| 781 /* Parse a crop specification (written in X11 geometry style). |
| 782 * The routine returns TRUE if the spec string is valid, FALSE if not. |
| 783 * |
| 784 * The crop spec string should have the format |
| 785 * <width>x<height>{+-}<xoffset>{+-}<yoffset> |
| 786 * where width, height, xoffset, and yoffset are unsigned integers. |
| 787 * Each of the elements can be omitted to indicate a default value. |
| 788 * (A weakness of this style is that it is not possible to omit xoffset |
| 789 * while specifying yoffset, since they look alike.) |
| 790 * |
| 791 * This code is loosely based on XParseGeometry from the X11 distribution. |
| 792 */ |
| 793 |
| 794 GLOBAL(boolean) |
| 795 jtransform_parse_crop_spec (jpeg_transform_info *info, const char *spec) |
| 796 { |
| 797 info->crop = FALSE; |
| 798 info->crop_width_set = JCROP_UNSET; |
| 799 info->crop_height_set = JCROP_UNSET; |
| 800 info->crop_xoffset_set = JCROP_UNSET; |
| 801 info->crop_yoffset_set = JCROP_UNSET; |
| 802 |
| 803 if (isdigit(*spec)) { |
| 804 /* fetch width */ |
| 805 if (! jt_read_integer(&spec, &info->crop_width)) |
| 806 return FALSE; |
| 807 info->crop_width_set = JCROP_POS; |
| 808 } |
| 809 if (*spec == 'x' || *spec == 'X') { |
| 810 /* fetch height */ |
| 811 spec++; |
| 812 if (! jt_read_integer(&spec, &info->crop_height)) |
| 813 return FALSE; |
| 814 info->crop_height_set = JCROP_POS; |
| 815 } |
| 816 if (*spec == '+' || *spec == '-') { |
| 817 /* fetch xoffset */ |
| 818 info->crop_xoffset_set = (*spec == '-') ? JCROP_NEG : JCROP_POS; |
| 819 spec++; |
| 820 if (! jt_read_integer(&spec, &info->crop_xoffset)) |
| 821 return FALSE; |
| 822 } |
| 823 if (*spec == '+' || *spec == '-') { |
| 824 /* fetch yoffset */ |
| 825 info->crop_yoffset_set = (*spec == '-') ? JCROP_NEG : JCROP_POS; |
| 826 spec++; |
| 827 if (! jt_read_integer(&spec, &info->crop_yoffset)) |
| 828 return FALSE; |
| 829 } |
| 830 /* We had better have gotten to the end of the string. */ |
| 831 if (*spec != '\0') |
| 832 return FALSE; |
| 833 info->crop = TRUE; |
| 834 return TRUE; |
| 835 } |
| 836 |
| 837 |
| 838 /* Trim off any partial iMCUs on the indicated destination edge */ |
| 839 |
| 840 LOCAL(void) |
| 841 trim_right_edge (jpeg_transform_info *info, JDIMENSION full_width) |
| 842 { |
| 843 JDIMENSION MCU_cols; |
| 844 |
| 845 MCU_cols = info->output_width / info->iMCU_sample_width; |
| 846 if (MCU_cols > 0 && info->x_crop_offset + MCU_cols == |
| 847 full_width / info->iMCU_sample_width) |
| 848 info->output_width = MCU_cols * info->iMCU_sample_width; |
| 849 } |
| 850 |
| 851 LOCAL(void) |
| 852 trim_bottom_edge (jpeg_transform_info *info, JDIMENSION full_height) |
| 853 { |
| 854 JDIMENSION MCU_rows; |
| 855 |
| 856 MCU_rows = info->output_height / info->iMCU_sample_height; |
| 857 if (MCU_rows > 0 && info->y_crop_offset + MCU_rows == |
| 858 full_height / info->iMCU_sample_height) |
| 859 info->output_height = MCU_rows * info->iMCU_sample_height; |
| 860 } |
| 861 |
| 862 |
| 557 /* Request any required workspace. | 863 /* Request any required workspace. |
| 558 * | 864 * |
| 865 * This routine figures out the size that the output image will be |
| 866 * (which implies that all the transform parameters must be set before |
| 867 * it is called). |
| 868 * |
| 559 * We allocate the workspace virtual arrays from the source decompression | 869 * We allocate the workspace virtual arrays from the source decompression |
| 560 * object, so that all the arrays (both the original data and the workspace) | 870 * object, so that all the arrays (both the original data and the workspace) |
| 561 * will be taken into account while making memory management decisions. | 871 * will be taken into account while making memory management decisions. |
| 562 * Hence, this routine must be called after jpeg_read_header (which reads | 872 * Hence, this routine must be called after jpeg_read_header (which reads |
| 563 * the image dimensions) and before jpeg_read_coefficients (which realizes | 873 * the image dimensions) and before jpeg_read_coefficients (which realizes |
| 564 * the source's virtual arrays). | 874 * the source's virtual arrays). |
| 875 * |
| 876 * This function returns FALSE right away if -perfect is given |
| 877 * and transformation is not perfect. Otherwise returns TRUE. |
| 565 */ | 878 */ |
| 566 | 879 |
| 567 GLOBAL(void) | 880 GLOBAL(boolean) |
| 568 jtransform_request_workspace (j_decompress_ptr srcinfo, | 881 jtransform_request_workspace (j_decompress_ptr srcinfo, |
| 569 jpeg_transform_info *info) | 882 jpeg_transform_info *info) |
| 570 { | 883 { |
| 571 jvirt_barray_ptr *coef_arrays = NULL; | 884 jvirt_barray_ptr *coef_arrays; |
| 885 boolean need_workspace, transpose_it; |
| 572 jpeg_component_info *compptr; | 886 jpeg_component_info *compptr; |
| 573 int ci; | 887 JDIMENSION xoffset, yoffset; |
| 574 | 888 JDIMENSION width_in_iMCUs, height_in_iMCUs; |
| 889 JDIMENSION width_in_blocks, height_in_blocks; |
| 890 int ci, h_samp_factor, v_samp_factor; |
| 891 |
| 892 /* Determine number of components in output image */ |
| 575 if (info->force_grayscale && | 893 if (info->force_grayscale && |
| 576 srcinfo->jpeg_color_space == JCS_YCbCr && | 894 srcinfo->jpeg_color_space == JCS_YCbCr && |
| 577 srcinfo->num_components == 3) { | 895 srcinfo->num_components == 3) |
| 578 /* We'll only process the first component */ | 896 /* We'll only process the first component */ |
| 579 info->num_components = 1; | 897 info->num_components = 1; |
| 580 } else { | 898 else |
| 581 /* Process all the components */ | 899 /* Process all the components */ |
| 582 info->num_components = srcinfo->num_components; | 900 info->num_components = srcinfo->num_components; |
| 583 } | 901 |
| 584 | 902 /* Compute output image dimensions and related values. */ |
| 903 #if JPEG_LIB_VERSION >= 80 |
| 904 jpeg_core_output_dimensions(srcinfo); |
| 905 #else |
| 906 srcinfo->output_width = srcinfo->image_width; |
| 907 srcinfo->output_height = srcinfo->image_height; |
| 908 #endif |
| 909 |
| 910 /* Return right away if -perfect is given and transformation is not perfect. |
| 911 */ |
| 912 if (info->perfect) { |
| 913 if (info->num_components == 1) { |
| 914 if (!jtransform_perfect_transform(srcinfo->output_width, |
| 915 » srcinfo->output_height, |
| 916 » srcinfo->_min_DCT_h_scaled_size, |
| 917 » srcinfo->_min_DCT_v_scaled_size, |
| 918 » info->transform)) |
| 919 » return FALSE; |
| 920 } else { |
| 921 if (!jtransform_perfect_transform(srcinfo->output_width, |
| 922 » srcinfo->output_height, |
| 923 » srcinfo->max_h_samp_factor * srcinfo->_min_DCT_h_scaled_size, |
| 924 » srcinfo->max_v_samp_factor * srcinfo->_min_DCT_v_scaled_size, |
| 925 » info->transform)) |
| 926 » return FALSE; |
| 927 } |
| 928 } |
| 929 |
| 930 /* If there is only one output component, force the iMCU size to be 1; |
| 931 * else use the source iMCU size. (This allows us to do the right thing |
| 932 * when reducing color to grayscale, and also provides a handy way of |
| 933 * cleaning up "funny" grayscale images whose sampling factors are not 1x1.) |
| 934 */ |
| 585 switch (info->transform) { | 935 switch (info->transform) { |
| 586 case JXFORM_NONE: | |
| 587 case JXFORM_FLIP_H: | |
| 588 /* Don't need a workspace array */ | |
| 589 break; | |
| 590 case JXFORM_FLIP_V: | |
| 591 case JXFORM_ROT_180: | |
| 592 /* Need workspace arrays having same dimensions as source image. | |
| 593 * Note that we allocate arrays padded out to the next iMCU boundary, | |
| 594 * so that transform routines need not worry about missing edge blocks. | |
| 595 */ | |
| 596 coef_arrays = (jvirt_barray_ptr *) | |
| 597 (*srcinfo->mem->alloc_small) ((j_common_ptr) srcinfo, JPOOL_IMAGE, | |
| 598 SIZEOF(jvirt_barray_ptr) * info->num_components); | |
| 599 for (ci = 0; ci < info->num_components; ci++) { | |
| 600 compptr = srcinfo->comp_info + ci; | |
| 601 coef_arrays[ci] = (*srcinfo->mem->request_virt_barray) | |
| 602 ((j_common_ptr) srcinfo, JPOOL_IMAGE, FALSE, | |
| 603 (JDIMENSION) jround_up((long) compptr->width_in_blocks, | |
| 604 (long) compptr->h_samp_factor), | |
| 605 (JDIMENSION) jround_up((long) compptr->height_in_blocks, | |
| 606 (long) compptr->v_samp_factor), | |
| 607 (JDIMENSION) compptr->v_samp_factor); | |
| 608 } | |
| 609 break; | |
| 610 case JXFORM_TRANSPOSE: | 936 case JXFORM_TRANSPOSE: |
| 611 case JXFORM_TRANSVERSE: | 937 case JXFORM_TRANSVERSE: |
| 612 case JXFORM_ROT_90: | 938 case JXFORM_ROT_90: |
| 613 case JXFORM_ROT_270: | 939 case JXFORM_ROT_270: |
| 614 /* Need workspace arrays having transposed dimensions. | 940 info->output_width = srcinfo->output_height; |
| 615 * Note that we allocate arrays padded out to the next iMCU boundary, | 941 info->output_height = srcinfo->output_width; |
| 616 * so that transform routines need not worry about missing edge blocks. | 942 if (info->num_components == 1) { |
| 617 */ | 943 info->iMCU_sample_width = srcinfo->_min_DCT_v_scaled_size; |
| 944 info->iMCU_sample_height = srcinfo->_min_DCT_h_scaled_size; |
| 945 } else { |
| 946 info->iMCU_sample_width = |
| 947 » srcinfo->max_v_samp_factor * srcinfo->_min_DCT_v_scaled_size; |
| 948 info->iMCU_sample_height = |
| 949 » srcinfo->max_h_samp_factor * srcinfo->_min_DCT_h_scaled_size; |
| 950 } |
| 951 break; |
| 952 default: |
| 953 info->output_width = srcinfo->output_width; |
| 954 info->output_height = srcinfo->output_height; |
| 955 if (info->num_components == 1) { |
| 956 info->iMCU_sample_width = srcinfo->_min_DCT_h_scaled_size; |
| 957 info->iMCU_sample_height = srcinfo->_min_DCT_v_scaled_size; |
| 958 } else { |
| 959 info->iMCU_sample_width = |
| 960 » srcinfo->max_h_samp_factor * srcinfo->_min_DCT_h_scaled_size; |
| 961 info->iMCU_sample_height = |
| 962 » srcinfo->max_v_samp_factor * srcinfo->_min_DCT_v_scaled_size; |
| 963 } |
| 964 break; |
| 965 } |
| 966 |
| 967 /* If cropping has been requested, compute the crop area's position and |
| 968 * dimensions, ensuring that its upper left corner falls at an iMCU boundary. |
| 969 */ |
| 970 if (info->crop) { |
| 971 /* Insert default values for unset crop parameters */ |
| 972 if (info->crop_xoffset_set == JCROP_UNSET) |
| 973 info->crop_xoffset = 0;» /* default to +0 */ |
| 974 if (info->crop_yoffset_set == JCROP_UNSET) |
| 975 info->crop_yoffset = 0;» /* default to +0 */ |
| 976 if (info->crop_xoffset >= info->output_width || |
| 977 » info->crop_yoffset >= info->output_height) |
| 978 ERREXIT(srcinfo, JERR_BAD_CROP_SPEC); |
| 979 if (info->crop_width_set == JCROP_UNSET) |
| 980 info->crop_width = info->output_width - info->crop_xoffset; |
| 981 if (info->crop_height_set == JCROP_UNSET) |
| 982 info->crop_height = info->output_height - info->crop_yoffset; |
| 983 /* Ensure parameters are valid */ |
| 984 if (info->crop_width <= 0 || info->crop_width > info->output_width || |
| 985 » info->crop_height <= 0 || info->crop_height > info->output_height || |
| 986 » info->crop_xoffset > info->output_width - info->crop_width || |
| 987 » info->crop_yoffset > info->output_height - info->crop_height) |
| 988 ERREXIT(srcinfo, JERR_BAD_CROP_SPEC); |
| 989 /* Convert negative crop offsets into regular offsets */ |
| 990 if (info->crop_xoffset_set == JCROP_NEG) |
| 991 xoffset = info->output_width - info->crop_width - info->crop_xoffset; |
| 992 else |
| 993 xoffset = info->crop_xoffset; |
| 994 if (info->crop_yoffset_set == JCROP_NEG) |
| 995 yoffset = info->output_height - info->crop_height - info->crop_yoffset; |
| 996 else |
| 997 yoffset = info->crop_yoffset; |
| 998 /* Now adjust so that upper left corner falls at an iMCU boundary */ |
| 999 info->output_width = |
| 1000 info->crop_width + (xoffset % info->iMCU_sample_width); |
| 1001 info->output_height = |
| 1002 info->crop_height + (yoffset % info->iMCU_sample_height); |
| 1003 /* Save x/y offsets measured in iMCUs */ |
| 1004 info->x_crop_offset = xoffset / info->iMCU_sample_width; |
| 1005 info->y_crop_offset = yoffset / info->iMCU_sample_height; |
| 1006 } else { |
| 1007 info->x_crop_offset = 0; |
| 1008 info->y_crop_offset = 0; |
| 1009 } |
| 1010 |
| 1011 /* Figure out whether we need workspace arrays, |
| 1012 * and if so whether they are transposed relative to the source. |
| 1013 */ |
| 1014 need_workspace = FALSE; |
| 1015 transpose_it = FALSE; |
| 1016 switch (info->transform) { |
| 1017 case JXFORM_NONE: |
| 1018 if (info->x_crop_offset != 0 || info->y_crop_offset != 0) |
| 1019 need_workspace = TRUE; |
| 1020 /* No workspace needed if neither cropping nor transforming */ |
| 1021 break; |
| 1022 case JXFORM_FLIP_H: |
| 1023 if (info->trim) |
| 1024 trim_right_edge(info, srcinfo->output_width); |
| 1025 if (info->y_crop_offset != 0 || info->slow_hflip) |
| 1026 need_workspace = TRUE; |
| 1027 /* do_flip_h_no_crop doesn't need a workspace array */ |
| 1028 break; |
| 1029 case JXFORM_FLIP_V: |
| 1030 if (info->trim) |
| 1031 trim_bottom_edge(info, srcinfo->output_height); |
| 1032 /* Need workspace arrays having same dimensions as source image. */ |
| 1033 need_workspace = TRUE; |
| 1034 break; |
| 1035 case JXFORM_TRANSPOSE: |
| 1036 /* transpose does NOT have to trim anything */ |
| 1037 /* Need workspace arrays having transposed dimensions. */ |
| 1038 need_workspace = TRUE; |
| 1039 transpose_it = TRUE; |
| 1040 break; |
| 1041 case JXFORM_TRANSVERSE: |
| 1042 if (info->trim) { |
| 1043 trim_right_edge(info, srcinfo->output_height); |
| 1044 trim_bottom_edge(info, srcinfo->output_width); |
| 1045 } |
| 1046 /* Need workspace arrays having transposed dimensions. */ |
| 1047 need_workspace = TRUE; |
| 1048 transpose_it = TRUE; |
| 1049 break; |
| 1050 case JXFORM_ROT_90: |
| 1051 if (info->trim) |
| 1052 trim_right_edge(info, srcinfo->output_height); |
| 1053 /* Need workspace arrays having transposed dimensions. */ |
| 1054 need_workspace = TRUE; |
| 1055 transpose_it = TRUE; |
| 1056 break; |
| 1057 case JXFORM_ROT_180: |
| 1058 if (info->trim) { |
| 1059 trim_right_edge(info, srcinfo->output_width); |
| 1060 trim_bottom_edge(info, srcinfo->output_height); |
| 1061 } |
| 1062 /* Need workspace arrays having same dimensions as source image. */ |
| 1063 need_workspace = TRUE; |
| 1064 break; |
| 1065 case JXFORM_ROT_270: |
| 1066 if (info->trim) |
| 1067 trim_bottom_edge(info, srcinfo->output_width); |
| 1068 /* Need workspace arrays having transposed dimensions. */ |
| 1069 need_workspace = TRUE; |
| 1070 transpose_it = TRUE; |
| 1071 break; |
| 1072 } |
| 1073 |
| 1074 /* Allocate workspace if needed. |
| 1075 * Note that we allocate arrays padded out to the next iMCU boundary, |
| 1076 * so that transform routines need not worry about missing edge blocks. |
| 1077 */ |
| 1078 if (need_workspace) { |
| 618 coef_arrays = (jvirt_barray_ptr *) | 1079 coef_arrays = (jvirt_barray_ptr *) |
| 619 (*srcinfo->mem->alloc_small) ((j_common_ptr) srcinfo, JPOOL_IMAGE, | 1080 (*srcinfo->mem->alloc_small) ((j_common_ptr) srcinfo, JPOOL_IMAGE, |
| 620 » SIZEOF(jvirt_barray_ptr) * info->num_components); | 1081 » » SIZEOF(jvirt_barray_ptr) * info->num_components); |
| 1082 width_in_iMCUs = (JDIMENSION) |
| 1083 jdiv_round_up((long) info->output_width, |
| 1084 » » (long) info->iMCU_sample_width); |
| 1085 height_in_iMCUs = (JDIMENSION) |
| 1086 jdiv_round_up((long) info->output_height, |
| 1087 » » (long) info->iMCU_sample_height); |
| 621 for (ci = 0; ci < info->num_components; ci++) { | 1088 for (ci = 0; ci < info->num_components; ci++) { |
| 622 compptr = srcinfo->comp_info + ci; | 1089 compptr = srcinfo->comp_info + ci; |
| 1090 if (info->num_components == 1) { |
| 1091 /* we're going to force samp factors to 1x1 in this case */ |
| 1092 h_samp_factor = v_samp_factor = 1; |
| 1093 } else if (transpose_it) { |
| 1094 h_samp_factor = compptr->v_samp_factor; |
| 1095 v_samp_factor = compptr->h_samp_factor; |
| 1096 } else { |
| 1097 h_samp_factor = compptr->h_samp_factor; |
| 1098 v_samp_factor = compptr->v_samp_factor; |
| 1099 } |
| 1100 width_in_blocks = width_in_iMCUs * h_samp_factor; |
| 1101 height_in_blocks = height_in_iMCUs * v_samp_factor; |
| 623 coef_arrays[ci] = (*srcinfo->mem->request_virt_barray) | 1102 coef_arrays[ci] = (*srcinfo->mem->request_virt_barray) |
| 624 ((j_common_ptr) srcinfo, JPOOL_IMAGE, FALSE, | 1103 ((j_common_ptr) srcinfo, JPOOL_IMAGE, FALSE, |
| 625 » (JDIMENSION) jround_up((long) compptr->height_in_blocks, | 1104 » width_in_blocks, height_in_blocks, (JDIMENSION) v_samp_factor); |
| 626 » » » » (long) compptr->v_samp_factor), | 1105 } |
| 627 » (JDIMENSION) jround_up((long) compptr->width_in_blocks, | 1106 info->workspace_coef_arrays = coef_arrays; |
| 628 » » » » (long) compptr->h_samp_factor), | 1107 } else |
| 629 » (JDIMENSION) compptr->h_samp_factor); | 1108 info->workspace_coef_arrays = NULL; |
| 630 } | 1109 |
| 631 break; | 1110 return TRUE; |
| 632 } | 1111 } |
| 633 info->workspace_coef_arrays = coef_arrays; | 1112 |
| 634 } | 1113 |
| 635 | |
| 636 | |
| 637 /* Transpose destination image parameters */ | 1114 /* Transpose destination image parameters */ |
| 638 | 1115 |
| 639 LOCAL(void) | 1116 LOCAL(void) |
| 640 transpose_critical_parameters (j_compress_ptr dstinfo) | 1117 transpose_critical_parameters (j_compress_ptr dstinfo) |
| 641 { | 1118 { |
| 642 int tblno, i, j, ci, itemp; | 1119 int tblno, i, j, ci, itemp; |
| 643 jpeg_component_info *compptr; | 1120 jpeg_component_info *compptr; |
| 644 JQUANT_TBL *qtblptr; | 1121 JQUANT_TBL *qtblptr; |
| 645 JDIMENSION dtemp; | 1122 JDIMENSION jtemp; |
| 646 UINT16 qtemp; | 1123 UINT16 qtemp; |
| 647 | 1124 |
| 648 /* Transpose basic image dimensions */ | 1125 /* Transpose image dimensions */ |
| 649 dtemp = dstinfo->image_width; | 1126 jtemp = dstinfo->image_width; |
| 650 dstinfo->image_width = dstinfo->image_height; | 1127 dstinfo->image_width = dstinfo->image_height; |
| 651 dstinfo->image_height = dtemp; | 1128 dstinfo->image_height = jtemp; |
| 1129 #if JPEG_LIB_VERSION >= 70 |
| 1130 itemp = dstinfo->min_DCT_h_scaled_size; |
| 1131 dstinfo->min_DCT_h_scaled_size = dstinfo->min_DCT_v_scaled_size; |
| 1132 dstinfo->min_DCT_v_scaled_size = itemp; |
| 1133 #endif |
| 652 | 1134 |
| 653 /* Transpose sampling factors */ | 1135 /* Transpose sampling factors */ |
| 654 for (ci = 0; ci < dstinfo->num_components; ci++) { | 1136 for (ci = 0; ci < dstinfo->num_components; ci++) { |
| 655 compptr = dstinfo->comp_info + ci; | 1137 compptr = dstinfo->comp_info + ci; |
| 656 itemp = compptr->h_samp_factor; | 1138 itemp = compptr->h_samp_factor; |
| 657 compptr->h_samp_factor = compptr->v_samp_factor; | 1139 compptr->h_samp_factor = compptr->v_samp_factor; |
| 658 compptr->v_samp_factor = itemp; | 1140 compptr->v_samp_factor = itemp; |
| 659 } | 1141 } |
| 660 | 1142 |
| 661 /* Transpose quantization tables */ | 1143 /* Transpose quantization tables */ |
| 662 for (tblno = 0; tblno < NUM_QUANT_TBLS; tblno++) { | 1144 for (tblno = 0; tblno < NUM_QUANT_TBLS; tblno++) { |
| 663 qtblptr = dstinfo->quant_tbl_ptrs[tblno]; | 1145 qtblptr = dstinfo->quant_tbl_ptrs[tblno]; |
| 664 if (qtblptr != NULL) { | 1146 if (qtblptr != NULL) { |
| 665 for (i = 0; i < DCTSIZE; i++) { | 1147 for (i = 0; i < DCTSIZE; i++) { |
| 666 for (j = 0; j < i; j++) { | 1148 for (j = 0; j < i; j++) { |
| 667 qtemp = qtblptr->quantval[i*DCTSIZE+j]; | 1149 qtemp = qtblptr->quantval[i*DCTSIZE+j]; |
| 668 qtblptr->quantval[i*DCTSIZE+j] = qtblptr->quantval[j*DCTSIZE+i]; | 1150 qtblptr->quantval[i*DCTSIZE+j] = qtblptr->quantval[j*DCTSIZE+i]; |
| 669 qtblptr->quantval[j*DCTSIZE+i] = qtemp; | 1151 qtblptr->quantval[j*DCTSIZE+i] = qtemp; |
| 670 } | 1152 } |
| 671 } | 1153 } |
| 672 } | 1154 } |
| 673 } | 1155 } |
| 674 } | 1156 } |
| 675 | 1157 |
| 676 | 1158 |
| 677 /* Trim off any partial iMCUs on the indicated destination edge */ | 1159 /* Adjust Exif image parameters. |
| 1160 * |
| 1161 * We try to adjust the Tags ExifImageWidth and ExifImageHeight if possible. |
| 1162 */ |
| 678 | 1163 |
| 679 LOCAL(void) | 1164 LOCAL(void) |
| 680 trim_right_edge (j_compress_ptr dstinfo) | 1165 adjust_exif_parameters (JOCTET FAR * data, unsigned int length, |
| 1166 » » » JDIMENSION new_width, JDIMENSION new_height) |
| 681 { | 1167 { |
| 682 int ci, max_h_samp_factor; | 1168 boolean is_motorola; /* Flag for byte order */ |
| 683 JDIMENSION MCU_cols; | 1169 unsigned int number_of_tags, tagnum; |
| 1170 unsigned int firstoffset, offset; |
| 1171 JDIMENSION new_value; |
| 684 | 1172 |
| 685 /* We have to compute max_h_samp_factor ourselves, | 1173 if (length < 12) return; /* Length of an IFD entry */ |
| 686 * because it hasn't been set yet in the destination | 1174 |
| 687 * (and we don't want to use the source's value). | 1175 /* Discover byte order */ |
| 688 */ | 1176 if (GETJOCTET(data[0]) == 0x49 && GETJOCTET(data[1]) == 0x49) |
| 689 max_h_samp_factor = 1; | 1177 is_motorola = FALSE; |
| 690 for (ci = 0; ci < dstinfo->num_components; ci++) { | 1178 else if (GETJOCTET(data[0]) == 0x4D && GETJOCTET(data[1]) == 0x4D) |
| 691 int h_samp_factor = dstinfo->comp_info[ci].h_samp_factor; | 1179 is_motorola = TRUE; |
| 692 max_h_samp_factor = MAX(max_h_samp_factor, h_samp_factor); | 1180 else |
| 1181 return; |
| 1182 |
| 1183 /* Check Tag Mark */ |
| 1184 if (is_motorola) { |
| 1185 if (GETJOCTET(data[2]) != 0) return; |
| 1186 if (GETJOCTET(data[3]) != 0x2A) return; |
| 1187 } else { |
| 1188 if (GETJOCTET(data[3]) != 0) return; |
| 1189 if (GETJOCTET(data[2]) != 0x2A) return; |
| 693 } | 1190 } |
| 694 MCU_cols = dstinfo->image_width / (max_h_samp_factor * DCTSIZE); | |
| 695 if (MCU_cols > 0) /* can't trim to 0 pixels */ | |
| 696 dstinfo->image_width = MCU_cols * (max_h_samp_factor * DCTSIZE); | |
| 697 } | |
| 698 | 1191 |
| 699 LOCAL(void) | 1192 /* Get first IFD offset (offset to IFD0) */ |
| 700 trim_bottom_edge (j_compress_ptr dstinfo) | 1193 if (is_motorola) { |
| 701 { | 1194 if (GETJOCTET(data[4]) != 0) return; |
| 702 int ci, max_v_samp_factor; | 1195 if (GETJOCTET(data[5]) != 0) return; |
| 703 JDIMENSION MCU_rows; | 1196 firstoffset = GETJOCTET(data[6]); |
| 1197 firstoffset <<= 8; |
| 1198 firstoffset += GETJOCTET(data[7]); |
| 1199 } else { |
| 1200 if (GETJOCTET(data[7]) != 0) return; |
| 1201 if (GETJOCTET(data[6]) != 0) return; |
| 1202 firstoffset = GETJOCTET(data[5]); |
| 1203 firstoffset <<= 8; |
| 1204 firstoffset += GETJOCTET(data[4]); |
| 1205 } |
| 1206 if (firstoffset > length - 2) return; /* check end of data segment */ |
| 704 | 1207 |
| 705 /* We have to compute max_v_samp_factor ourselves, | 1208 /* Get the number of directory entries contained in this IFD */ |
| 706 * because it hasn't been set yet in the destination | 1209 if (is_motorola) { |
| 707 * (and we don't want to use the source's value). | 1210 number_of_tags = GETJOCTET(data[firstoffset]); |
| 708 */ | 1211 number_of_tags <<= 8; |
| 709 max_v_samp_factor = 1; | 1212 number_of_tags += GETJOCTET(data[firstoffset+1]); |
| 710 for (ci = 0; ci < dstinfo->num_components; ci++) { | 1213 } else { |
| 711 int v_samp_factor = dstinfo->comp_info[ci].v_samp_factor; | 1214 number_of_tags = GETJOCTET(data[firstoffset+1]); |
| 712 max_v_samp_factor = MAX(max_v_samp_factor, v_samp_factor); | 1215 number_of_tags <<= 8; |
| 1216 number_of_tags += GETJOCTET(data[firstoffset]); |
| 713 } | 1217 } |
| 714 MCU_rows = dstinfo->image_height / (max_v_samp_factor * DCTSIZE); | 1218 if (number_of_tags == 0) return; |
| 715 if (MCU_rows > 0)» » /* can't trim to 0 pixels */ | 1219 firstoffset += 2; |
| 716 dstinfo->image_height = MCU_rows * (max_v_samp_factor * DCTSIZE); | 1220 |
| 1221 /* Search for ExifSubIFD offset Tag in IFD0 */ |
| 1222 for (;;) { |
| 1223 if (firstoffset > length - 12) return; /* check end of data segment */ |
| 1224 /* Get Tag number */ |
| 1225 if (is_motorola) { |
| 1226 tagnum = GETJOCTET(data[firstoffset]); |
| 1227 tagnum <<= 8; |
| 1228 tagnum += GETJOCTET(data[firstoffset+1]); |
| 1229 } else { |
| 1230 tagnum = GETJOCTET(data[firstoffset+1]); |
| 1231 tagnum <<= 8; |
| 1232 tagnum += GETJOCTET(data[firstoffset]); |
| 1233 } |
| 1234 if (tagnum == 0x8769) break; /* found ExifSubIFD offset Tag */ |
| 1235 if (--number_of_tags == 0) return; |
| 1236 firstoffset += 12; |
| 1237 } |
| 1238 |
| 1239 /* Get the ExifSubIFD offset */ |
| 1240 if (is_motorola) { |
| 1241 if (GETJOCTET(data[firstoffset+8]) != 0) return; |
| 1242 if (GETJOCTET(data[firstoffset+9]) != 0) return; |
| 1243 offset = GETJOCTET(data[firstoffset+10]); |
| 1244 offset <<= 8; |
| 1245 offset += GETJOCTET(data[firstoffset+11]); |
| 1246 } else { |
| 1247 if (GETJOCTET(data[firstoffset+11]) != 0) return; |
| 1248 if (GETJOCTET(data[firstoffset+10]) != 0) return; |
| 1249 offset = GETJOCTET(data[firstoffset+9]); |
| 1250 offset <<= 8; |
| 1251 offset += GETJOCTET(data[firstoffset+8]); |
| 1252 } |
| 1253 if (offset > length - 2) return; /* check end of data segment */ |
| 1254 |
| 1255 /* Get the number of directory entries contained in this SubIFD */ |
| 1256 if (is_motorola) { |
| 1257 number_of_tags = GETJOCTET(data[offset]); |
| 1258 number_of_tags <<= 8; |
| 1259 number_of_tags += GETJOCTET(data[offset+1]); |
| 1260 } else { |
| 1261 number_of_tags = GETJOCTET(data[offset+1]); |
| 1262 number_of_tags <<= 8; |
| 1263 number_of_tags += GETJOCTET(data[offset]); |
| 1264 } |
| 1265 if (number_of_tags < 2) return; |
| 1266 offset += 2; |
| 1267 |
| 1268 /* Search for ExifImageWidth and ExifImageHeight Tags in this SubIFD */ |
| 1269 do { |
| 1270 if (offset > length - 12) return; /* check end of data segment */ |
| 1271 /* Get Tag number */ |
| 1272 if (is_motorola) { |
| 1273 tagnum = GETJOCTET(data[offset]); |
| 1274 tagnum <<= 8; |
| 1275 tagnum += GETJOCTET(data[offset+1]); |
| 1276 } else { |
| 1277 tagnum = GETJOCTET(data[offset+1]); |
| 1278 tagnum <<= 8; |
| 1279 tagnum += GETJOCTET(data[offset]); |
| 1280 } |
| 1281 if (tagnum == 0xA002 || tagnum == 0xA003) { |
| 1282 if (tagnum == 0xA002) |
| 1283 » new_value = new_width; /* ExifImageWidth Tag */ |
| 1284 else |
| 1285 » new_value = new_height; /* ExifImageHeight Tag */ |
| 1286 if (is_motorola) { |
| 1287 » data[offset+2] = 0; /* Format = unsigned long (4 octets) */ |
| 1288 » data[offset+3] = 4; |
| 1289 » data[offset+4] = 0; /* Number Of Components = 1 */ |
| 1290 » data[offset+5] = 0; |
| 1291 » data[offset+6] = 0; |
| 1292 » data[offset+7] = 1; |
| 1293 » data[offset+8] = 0; |
| 1294 » data[offset+9] = 0; |
| 1295 » data[offset+10] = (JOCTET)((new_value >> 8) & 0xFF); |
| 1296 » data[offset+11] = (JOCTET)(new_value & 0xFF); |
| 1297 } else { |
| 1298 » data[offset+2] = 4; /* Format = unsigned long (4 octets) */ |
| 1299 » data[offset+3] = 0; |
| 1300 » data[offset+4] = 1; /* Number Of Components = 1 */ |
| 1301 » data[offset+5] = 0; |
| 1302 » data[offset+6] = 0; |
| 1303 » data[offset+7] = 0; |
| 1304 » data[offset+8] = (JOCTET)(new_value & 0xFF); |
| 1305 » data[offset+9] = (JOCTET)((new_value >> 8) & 0xFF); |
| 1306 » data[offset+10] = 0; |
| 1307 » data[offset+11] = 0; |
| 1308 } |
| 1309 } |
| 1310 offset += 12; |
| 1311 } while (--number_of_tags); |
| 717 } | 1312 } |
| 718 | 1313 |
| 719 | 1314 |
| 720 /* Adjust output image parameters as needed. | 1315 /* Adjust output image parameters as needed. |
| 721 * | 1316 * |
| 722 * This must be called after jpeg_copy_critical_parameters() | 1317 * This must be called after jpeg_copy_critical_parameters() |
| 723 * and before jpeg_write_coefficients(). | 1318 * and before jpeg_write_coefficients(). |
| 724 * | 1319 * |
| 725 * The return value is the set of virtual coefficient arrays to be written | 1320 * The return value is the set of virtual coefficient arrays to be written |
| 726 * (either the ones allocated by jtransform_request_workspace, or the | 1321 * (either the ones allocated by jtransform_request_workspace, or the |
| 727 * original source data arrays). The caller will need to pass this value | 1322 * original source data arrays). The caller will need to pass this value |
| 728 * to jpeg_write_coefficients(). | 1323 * to jpeg_write_coefficients(). |
| 729 */ | 1324 */ |
| 730 | 1325 |
| 731 GLOBAL(jvirt_barray_ptr *) | 1326 GLOBAL(jvirt_barray_ptr *) |
| 732 jtransform_adjust_parameters (j_decompress_ptr srcinfo, | 1327 jtransform_adjust_parameters (j_decompress_ptr srcinfo, |
| 733 j_compress_ptr dstinfo, | 1328 j_compress_ptr dstinfo, |
| 734 jvirt_barray_ptr *src_coef_arrays, | 1329 jvirt_barray_ptr *src_coef_arrays, |
| 735 jpeg_transform_info *info) | 1330 jpeg_transform_info *info) |
| 736 { | 1331 { |
| 737 /* If force-to-grayscale is requested, adjust destination parameters */ | 1332 /* If force-to-grayscale is requested, adjust destination parameters */ |
| 738 if (info->force_grayscale) { | 1333 if (info->force_grayscale) { |
| 739 /* We use jpeg_set_colorspace to make sure subsidiary settings get fixed | 1334 /* First, ensure we have YCbCr or grayscale data, and that the source's |
| 740 * properly. Among other things, the target h_samp_factor & v_samp_factor | 1335 * Y channel is full resolution. (No reasonable person would make Y |
| 741 * will get set to 1, which typically won't match the source. | 1336 * be less than full resolution, so actually coping with that case |
| 742 * In fact we do this even if the source is already grayscale; that | 1337 * isn't worth extra code space. But we check it to avoid crashing.) |
| 743 * provides an easy way of coercing a grayscale JPEG with funny sampling | |
| 744 * factors to the customary 1,1. (Some decoders fail on other factors.) | |
| 745 */ | 1338 */ |
| 746 if ((dstinfo->jpeg_color_space == JCS_YCbCr && | 1339 if (((dstinfo->jpeg_color_space == JCS_YCbCr && |
| 747 » dstinfo->num_components == 3) || | 1340 » dstinfo->num_components == 3) || |
| 748 » (dstinfo->jpeg_color_space == JCS_GRAYSCALE && | 1341 » (dstinfo->jpeg_color_space == JCS_GRAYSCALE && |
| 749 » dstinfo->num_components == 1)) { | 1342 » dstinfo->num_components == 1)) && |
| 750 /* We have to preserve the source's quantization table number. */ | 1343 » srcinfo->comp_info[0].h_samp_factor == srcinfo->max_h_samp_factor && |
| 1344 » srcinfo->comp_info[0].v_samp_factor == srcinfo->max_v_samp_factor) { |
| 1345 /* We use jpeg_set_colorspace to make sure subsidiary settings get fixed |
| 1346 * properly. Among other things, it sets the target h_samp_factor & |
| 1347 * v_samp_factor to 1, which typically won't match the source. |
| 1348 * We have to preserve the source's quantization table number, however. |
| 1349 */ |
| 751 int sv_quant_tbl_no = dstinfo->comp_info[0].quant_tbl_no; | 1350 int sv_quant_tbl_no = dstinfo->comp_info[0].quant_tbl_no; |
| 752 jpeg_set_colorspace(dstinfo, JCS_GRAYSCALE); | 1351 jpeg_set_colorspace(dstinfo, JCS_GRAYSCALE); |
| 753 dstinfo->comp_info[0].quant_tbl_no = sv_quant_tbl_no; | 1352 dstinfo->comp_info[0].quant_tbl_no = sv_quant_tbl_no; |
| 754 } else { | 1353 } else { |
| 755 /* Sorry, can't do it */ | 1354 /* Sorry, can't do it */ |
| 756 ERREXIT(dstinfo, JERR_CONVERSION_NOTIMPL); | 1355 ERREXIT(dstinfo, JERR_CONVERSION_NOTIMPL); |
| 757 } | 1356 } |
| 1357 } else if (info->num_components == 1) { |
| 1358 /* For a single-component source, we force the destination sampling factors |
| 1359 * to 1x1, with or without force_grayscale. This is useful because some |
| 1360 * decoders choke on grayscale images with other sampling factors. |
| 1361 */ |
| 1362 dstinfo->comp_info[0].h_samp_factor = 1; |
| 1363 dstinfo->comp_info[0].v_samp_factor = 1; |
| 758 } | 1364 } |
| 759 | 1365 |
| 760 /* Correct the destination's image dimensions etc if necessary */ | 1366 /* Correct the destination's image dimensions as necessary |
| 1367 * for rotate/flip, resize, and crop operations. |
| 1368 */ |
| 1369 #if JPEG_LIB_VERSION >= 70 |
| 1370 dstinfo->jpeg_width = info->output_width; |
| 1371 dstinfo->jpeg_height = info->output_height; |
| 1372 #endif |
| 1373 |
| 1374 /* Transpose destination image parameters */ |
| 761 switch (info->transform) { | 1375 switch (info->transform) { |
| 762 case JXFORM_NONE: | 1376 case JXFORM_TRANSPOSE: |
| 763 /* Nothing to do */ | 1377 case JXFORM_TRANSVERSE: |
| 1378 case JXFORM_ROT_90: |
| 1379 case JXFORM_ROT_270: |
| 1380 #if JPEG_LIB_VERSION < 70 |
| 1381 dstinfo->image_width = info->output_height; |
| 1382 dstinfo->image_height = info->output_width; |
| 1383 #endif |
| 1384 transpose_critical_parameters(dstinfo); |
| 764 break; | 1385 break; |
| 765 case JXFORM_FLIP_H: | 1386 default: |
| 766 if (info->trim) | 1387 #if JPEG_LIB_VERSION < 70 |
| 767 trim_right_edge(dstinfo); | 1388 dstinfo->image_width = info->output_width; |
| 1389 dstinfo->image_height = info->output_height; |
| 1390 #endif |
| 768 break; | 1391 break; |
| 769 case JXFORM_FLIP_V: | 1392 } |
| 770 if (info->trim) | 1393 |
| 771 trim_bottom_edge(dstinfo); | 1394 /* Adjust Exif properties */ |
| 772 break; | 1395 if (srcinfo->marker_list != NULL && |
| 773 case JXFORM_TRANSPOSE: | 1396 srcinfo->marker_list->marker == JPEG_APP0+1 && |
| 774 transpose_critical_parameters(dstinfo); | 1397 srcinfo->marker_list->data_length >= 6 && |
| 775 /* transpose does NOT have to trim anything */ | 1398 GETJOCTET(srcinfo->marker_list->data[0]) == 0x45 && |
| 776 break; | 1399 GETJOCTET(srcinfo->marker_list->data[1]) == 0x78 && |
| 777 case JXFORM_TRANSVERSE: | 1400 GETJOCTET(srcinfo->marker_list->data[2]) == 0x69 && |
| 778 transpose_critical_parameters(dstinfo); | 1401 GETJOCTET(srcinfo->marker_list->data[3]) == 0x66 && |
| 779 if (info->trim) { | 1402 GETJOCTET(srcinfo->marker_list->data[4]) == 0 && |
| 780 trim_right_edge(dstinfo); | 1403 GETJOCTET(srcinfo->marker_list->data[5]) == 0) { |
| 781 trim_bottom_edge(dstinfo); | 1404 /* Suppress output of JFIF marker */ |
| 782 } | 1405 dstinfo->write_JFIF_header = FALSE; |
| 783 break; | 1406 #if JPEG_LIB_VERSION >= 70 |
| 784 case JXFORM_ROT_90: | 1407 /* Adjust Exif image parameters */ |
| 785 transpose_critical_parameters(dstinfo); | 1408 if (dstinfo->jpeg_width != srcinfo->image_width || |
| 786 if (info->trim) | 1409 » dstinfo->jpeg_height != srcinfo->image_height) |
| 787 trim_right_edge(dstinfo); | 1410 /* Align data segment to start of TIFF structure for parsing */ |
| 788 break; | 1411 adjust_exif_parameters(srcinfo->marker_list->data + 6, |
| 789 case JXFORM_ROT_180: | 1412 » srcinfo->marker_list->data_length - 6, |
| 790 if (info->trim) { | 1413 » dstinfo->jpeg_width, dstinfo->jpeg_height); |
| 791 trim_right_edge(dstinfo); | 1414 #endif |
| 792 trim_bottom_edge(dstinfo); | |
| 793 } | |
| 794 break; | |
| 795 case JXFORM_ROT_270: | |
| 796 transpose_critical_parameters(dstinfo); | |
| 797 if (info->trim) | |
| 798 trim_bottom_edge(dstinfo); | |
| 799 break; | |
| 800 } | 1415 } |
| 801 | 1416 |
| 802 /* Return the appropriate output data set */ | 1417 /* Return the appropriate output data set */ |
| 803 if (info->workspace_coef_arrays != NULL) | 1418 if (info->workspace_coef_arrays != NULL) |
| 804 return info->workspace_coef_arrays; | 1419 return info->workspace_coef_arrays; |
| 805 return src_coef_arrays; | 1420 return src_coef_arrays; |
| 806 } | 1421 } |
| 807 | 1422 |
| 808 | 1423 |
| 809 /* Execute the actual transformation, if any. | 1424 /* Execute the actual transformation, if any. |
| 810 * | 1425 * |
| 811 * This must be called *after* jpeg_write_coefficients, because it depends | 1426 * This must be called *after* jpeg_write_coefficients, because it depends |
| 812 * on jpeg_write_coefficients to have computed subsidiary values such as | 1427 * on jpeg_write_coefficients to have computed subsidiary values such as |
| 813 * the per-component width and height fields in the destination object. | 1428 * the per-component width and height fields in the destination object. |
| 814 * | 1429 * |
| 815 * Note that some transformations will modify the source data arrays! | 1430 * Note that some transformations will modify the source data arrays! |
| 816 */ | 1431 */ |
| 817 | 1432 |
| 818 GLOBAL(void) | 1433 GLOBAL(void) |
| 819 jtransform_execute_transformation (j_decompress_ptr srcinfo, | 1434 jtransform_execute_transform (j_decompress_ptr srcinfo, |
| 820 » » » » j_compress_ptr dstinfo, | 1435 » » » j_compress_ptr dstinfo, |
| 821 » » » » jvirt_barray_ptr *src_coef_arrays, | 1436 » » » jvirt_barray_ptr *src_coef_arrays, |
| 822 » » » » jpeg_transform_info *info) | 1437 » » » jpeg_transform_info *info) |
| 823 { | 1438 { |
| 824 jvirt_barray_ptr *dst_coef_arrays = info->workspace_coef_arrays; | 1439 jvirt_barray_ptr *dst_coef_arrays = info->workspace_coef_arrays; |
| 825 | 1440 |
| 1441 /* Note: conditions tested here should match those in switch statement |
| 1442 * in jtransform_request_workspace() |
| 1443 */ |
| 826 switch (info->transform) { | 1444 switch (info->transform) { |
| 827 case JXFORM_NONE: | 1445 case JXFORM_NONE: |
| 1446 if (info->x_crop_offset != 0 || info->y_crop_offset != 0) |
| 1447 do_crop(srcinfo, dstinfo, info->x_crop_offset, info->y_crop_offset, |
| 1448 src_coef_arrays, dst_coef_arrays); |
| 828 break; | 1449 break; |
| 829 case JXFORM_FLIP_H: | 1450 case JXFORM_FLIP_H: |
| 830 do_flip_h(srcinfo, dstinfo, src_coef_arrays); | 1451 if (info->y_crop_offset != 0 || info->slow_hflip) |
| 1452 do_flip_h(srcinfo, dstinfo, info->x_crop_offset, info->y_crop_offset, |
| 1453 » » src_coef_arrays, dst_coef_arrays); |
| 1454 else |
| 1455 do_flip_h_no_crop(srcinfo, dstinfo, info->x_crop_offset, |
| 1456 » » » src_coef_arrays); |
| 831 break; | 1457 break; |
| 832 case JXFORM_FLIP_V: | 1458 case JXFORM_FLIP_V: |
| 833 do_flip_v(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays); | 1459 do_flip_v(srcinfo, dstinfo, info->x_crop_offset, info->y_crop_offset, |
| 1460 » src_coef_arrays, dst_coef_arrays); |
| 834 break; | 1461 break; |
| 835 case JXFORM_TRANSPOSE: | 1462 case JXFORM_TRANSPOSE: |
| 836 do_transpose(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays); | 1463 do_transpose(srcinfo, dstinfo, info->x_crop_offset, info->y_crop_offset, |
| 1464 » » src_coef_arrays, dst_coef_arrays); |
| 837 break; | 1465 break; |
| 838 case JXFORM_TRANSVERSE: | 1466 case JXFORM_TRANSVERSE: |
| 839 do_transverse(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays); | 1467 do_transverse(srcinfo, dstinfo, info->x_crop_offset, info->y_crop_offset, |
| 1468 » » src_coef_arrays, dst_coef_arrays); |
| 840 break; | 1469 break; |
| 841 case JXFORM_ROT_90: | 1470 case JXFORM_ROT_90: |
| 842 do_rot_90(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays); | 1471 do_rot_90(srcinfo, dstinfo, info->x_crop_offset, info->y_crop_offset, |
| 1472 » src_coef_arrays, dst_coef_arrays); |
| 843 break; | 1473 break; |
| 844 case JXFORM_ROT_180: | 1474 case JXFORM_ROT_180: |
| 845 do_rot_180(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays); | 1475 do_rot_180(srcinfo, dstinfo, info->x_crop_offset, info->y_crop_offset, |
| 1476 » src_coef_arrays, dst_coef_arrays); |
| 846 break; | 1477 break; |
| 847 case JXFORM_ROT_270: | 1478 case JXFORM_ROT_270: |
| 848 do_rot_270(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays); | 1479 do_rot_270(srcinfo, dstinfo, info->x_crop_offset, info->y_crop_offset, |
| 1480 » src_coef_arrays, dst_coef_arrays); |
| 849 break; | 1481 break; |
| 850 } | 1482 } |
| 851 } | 1483 } |
| 852 | 1484 |
| 1485 /* jtransform_perfect_transform |
| 1486 * |
| 1487 * Determine whether lossless transformation is perfectly |
| 1488 * possible for a specified image and transformation. |
| 1489 * |
| 1490 * Inputs: |
| 1491 * image_width, image_height: source image dimensions. |
| 1492 * MCU_width, MCU_height: pixel dimensions of MCU. |
| 1493 * transform: transformation identifier. |
| 1494 * Parameter sources from initialized jpeg_struct |
| 1495 * (after reading source header): |
| 1496 * image_width = cinfo.image_width |
| 1497 * image_height = cinfo.image_height |
| 1498 * MCU_width = cinfo.max_h_samp_factor * cinfo.block_size |
| 1499 * MCU_height = cinfo.max_v_samp_factor * cinfo.block_size |
| 1500 * Result: |
| 1501 * TRUE = perfect transformation possible |
| 1502 * FALSE = perfect transformation not possible |
| 1503 * (may use custom action then) |
| 1504 */ |
| 1505 |
| 1506 GLOBAL(boolean) |
| 1507 jtransform_perfect_transform(JDIMENSION image_width, JDIMENSION image_height, |
| 1508 int MCU_width, int MCU_height, |
| 1509 JXFORM_CODE transform) |
| 1510 { |
| 1511 boolean result = TRUE; /* initialize TRUE */ |
| 1512 |
| 1513 switch (transform) { |
| 1514 case JXFORM_FLIP_H: |
| 1515 case JXFORM_ROT_270: |
| 1516 if (image_width % (JDIMENSION) MCU_width) |
| 1517 result = FALSE; |
| 1518 break; |
| 1519 case JXFORM_FLIP_V: |
| 1520 case JXFORM_ROT_90: |
| 1521 if (image_height % (JDIMENSION) MCU_height) |
| 1522 result = FALSE; |
| 1523 break; |
| 1524 case JXFORM_TRANSVERSE: |
| 1525 case JXFORM_ROT_180: |
| 1526 if (image_width % (JDIMENSION) MCU_width) |
| 1527 result = FALSE; |
| 1528 if (image_height % (JDIMENSION) MCU_height) |
| 1529 result = FALSE; |
| 1530 break; |
| 1531 default: |
| 1532 break; |
| 1533 } |
| 1534 |
| 1535 return result; |
| 1536 } |
| 1537 |
| 853 #endif /* TRANSFORMS_SUPPORTED */ | 1538 #endif /* TRANSFORMS_SUPPORTED */ |
| 854 | 1539 |
| 855 | 1540 |
| 856 /* Setup decompression object to save desired markers in memory. | 1541 /* Setup decompression object to save desired markers in memory. |
| 857 * This must be called before jpeg_read_header() to have the desired effect. | 1542 * This must be called before jpeg_read_header() to have the desired effect. |
| 858 */ | 1543 */ |
| 859 | 1544 |
| 860 GLOBAL(void) | 1545 GLOBAL(void) |
| 861 jcopy_markers_setup (j_decompress_ptr srcinfo, JCOPY_OPTION option) | 1546 jcopy_markers_setup (j_decompress_ptr srcinfo, JCOPY_OPTION option) |
| 862 { | 1547 { |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 919 jpeg_write_m_header(dstinfo, marker->marker, marker->data_length); | 1604 jpeg_write_m_header(dstinfo, marker->marker, marker->data_length); |
| 920 for (i = 0; i < marker->data_length; i++) | 1605 for (i = 0; i < marker->data_length; i++) |
| 921 jpeg_write_m_byte(dstinfo, marker->data[i]); | 1606 jpeg_write_m_byte(dstinfo, marker->data[i]); |
| 922 } | 1607 } |
| 923 #else | 1608 #else |
| 924 jpeg_write_marker(dstinfo, marker->marker, | 1609 jpeg_write_marker(dstinfo, marker->marker, |
| 925 marker->data, marker->data_length); | 1610 marker->data, marker->data_length); |
| 926 #endif | 1611 #endif |
| 927 } | 1612 } |
| 928 } | 1613 } |
| OLD | NEW |