33 return (
a + b - 1) / b;
36#if JPEG_LIB_VERSION >= 70
37#define dstinfo_min_DCT_h_scaled_size dstinfo->min_DCT_h_scaled_size
38#define dstinfo_min_DCT_v_scaled_size dstinfo->min_DCT_v_scaled_size
40#define dstinfo_min_DCT_h_scaled_size DCTSIZE
41#define dstinfo_min_DCT_v_scaled_size DCTSIZE
45#if TRANSFORMS_SUPPORTED
96static void lcl_jcopy_block_row (JBLOCKROW input_row, JBLOCKROW output_row, JDIMENSION num_blocks)
100 FMEMCOPY(output_row, input_row, num_blocks * (DCTSIZE2 *
SIZEOF(JCOEF)));
102 JCOEFPTR inptr, outptr;
105 inptr = (JCOEFPTR) input_row;
106 outptr = (JCOEFPTR) output_row;
108 *outptr++ = *inptr++;
114do_crop (j_decompress_ptr srcinfo, j_compress_ptr
dstinfo,
115 JDIMENSION x_crop_offset, JDIMENSION y_crop_offset,
116 jvirt_barray_ptr *src_coef_arrays,
117 jvirt_barray_ptr *dst_coef_arrays)
120 JDIMENSION dst_blk_y, x_crop_blocks, y_crop_blocks;
122 JBLOCKARRAY src_buffer, dst_buffer;
123 jpeg_component_info *compptr;
128 for (ci = 0; ci <
dstinfo->num_components; ci++) {
129 compptr =
dstinfo->comp_info + ci;
130 x_crop_blocks = x_crop_offset * compptr->h_samp_factor;
131 y_crop_blocks = y_crop_offset * compptr->v_samp_factor;
132 for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
133 dst_blk_y += compptr->v_samp_factor) {
134 dst_buffer = (*srcinfo->mem->access_virt_barray)
135 ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
136 (JDIMENSION) compptr->v_samp_factor, TRUE);
137 src_buffer = (*srcinfo->mem->access_virt_barray)
138 ((j_common_ptr) srcinfo, src_coef_arrays[ci],
139 dst_blk_y + y_crop_blocks,
140 (JDIMENSION) compptr->v_samp_factor, FALSE);
141 for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
142 lcl_jcopy_block_row(src_buffer[offset_y] + x_crop_blocks,
143 dst_buffer[offset_y],
144 compptr->width_in_blocks);
152do_flip_h_no_crop (j_decompress_ptr srcinfo, j_compress_ptr
dstinfo,
153 JDIMENSION x_crop_offset,
154 jvirt_barray_ptr *src_coef_arrays)
159 JDIMENSION MCU_cols, comp_width, blk_x, blk_y, x_crop_blocks;
164 jpeg_component_info *compptr;
171 MCU_cols = srcinfo->output_width /
174 for (ci = 0; ci <
dstinfo->num_components; ci++) {
175 compptr =
dstinfo->comp_info + ci;
176 comp_width = MCU_cols * compptr->h_samp_factor;
177 x_crop_blocks = x_crop_offset * compptr->h_samp_factor;
178 for (blk_y = 0; blk_y < compptr->height_in_blocks;
179 blk_y += compptr->v_samp_factor) {
180 buffer = (*srcinfo->mem->access_virt_barray)
181 ((j_common_ptr) srcinfo, src_coef_arrays[ci], blk_y,
182 (JDIMENSION) compptr->v_samp_factor, TRUE);
183 for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
185 for (blk_x = 0; blk_x * 2 < comp_width; blk_x++) {
186 ptr1 = buffer[offset_y][blk_x];
187 ptr2 = buffer[offset_y][comp_width - blk_x - 1];
189 for (k = 0; k < DCTSIZE2; k += 2) {
200 if (x_crop_blocks > 0) {
206 for (blk_x = 0; blk_x < compptr->width_in_blocks; blk_x++) {
207 lcl_jcopy_block_row(buffer[offset_y] + blk_x + x_crop_blocks,
208 buffer[offset_y] + blk_x,
219do_flip_h (j_decompress_ptr srcinfo, j_compress_ptr
dstinfo,
220 JDIMENSION x_crop_offset, JDIMENSION y_crop_offset,
221 jvirt_barray_ptr *src_coef_arrays,
222 jvirt_barray_ptr *dst_coef_arrays)
225 JDIMENSION MCU_cols, comp_width, dst_blk_x, dst_blk_y;
226 JDIMENSION x_crop_blocks, y_crop_blocks;
228 JBLOCKARRAY src_buffer, dst_buffer;
229 JBLOCKROW src_row_ptr, dst_row_ptr;
230 JCOEFPTR src_ptr, dst_ptr;
231 jpeg_component_info *compptr;
237 MCU_cols = srcinfo->output_width /
240 for (ci = 0; ci <
dstinfo->num_components; ci++) {
241 compptr =
dstinfo->comp_info + ci;
242 comp_width = MCU_cols * compptr->h_samp_factor;
243 x_crop_blocks = x_crop_offset * compptr->h_samp_factor;
244 y_crop_blocks = y_crop_offset * compptr->v_samp_factor;
245 for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
246 dst_blk_y += compptr->v_samp_factor) {
247 dst_buffer = (*srcinfo->mem->access_virt_barray)
248 ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
249 (JDIMENSION) compptr->v_samp_factor, TRUE);
250 src_buffer = (*srcinfo->mem->access_virt_barray)
251 ((j_common_ptr) srcinfo, src_coef_arrays[ci],
252 dst_blk_y + y_crop_blocks,
253 (JDIMENSION) compptr->v_samp_factor, FALSE);
254 for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
255 dst_row_ptr = dst_buffer[offset_y];
256 src_row_ptr = src_buffer[offset_y];
257 for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks; dst_blk_x++) {
258 if (x_crop_blocks + dst_blk_x < comp_width) {
260 dst_ptr = dst_row_ptr[dst_blk_x];
261 src_ptr = src_row_ptr[comp_width - x_crop_blocks - dst_blk_x - 1];
263 for (k = 0; k < DCTSIZE2; k += 2) {
264 *dst_ptr++ = *src_ptr++;
265 *dst_ptr++ = - *src_ptr++;
269 lcl_jcopy_block_row(src_row_ptr + dst_blk_x + x_crop_blocks,
270 dst_row_ptr + dst_blk_x,
281do_flip_v (j_decompress_ptr srcinfo, j_compress_ptr
dstinfo,
282 JDIMENSION x_crop_offset, JDIMENSION y_crop_offset,
283 jvirt_barray_ptr *src_coef_arrays,
284 jvirt_barray_ptr *dst_coef_arrays)
287 JDIMENSION MCU_rows, comp_height, dst_blk_x, dst_blk_y;
288 JDIMENSION x_crop_blocks, y_crop_blocks;
289 int ci,
i, j, offset_y;
290 JBLOCKARRAY src_buffer, dst_buffer;
291 JBLOCKROW src_row_ptr, dst_row_ptr;
292 JCOEFPTR src_ptr, dst_ptr;
293 jpeg_component_info *compptr;
302 MCU_rows = srcinfo->output_height /
305 for (ci = 0; ci <
dstinfo->num_components; ci++) {
306 compptr =
dstinfo->comp_info + ci;
307 comp_height = MCU_rows * compptr->v_samp_factor;
308 x_crop_blocks = x_crop_offset * compptr->h_samp_factor;
309 y_crop_blocks = y_crop_offset * compptr->v_samp_factor;
310 for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
311 dst_blk_y += compptr->v_samp_factor) {
312 dst_buffer = (*srcinfo->mem->access_virt_barray)
313 ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
314 (JDIMENSION) compptr->v_samp_factor, TRUE);
315 if (y_crop_blocks + dst_blk_y < comp_height) {
317 src_buffer = (*srcinfo->mem->access_virt_barray)
318 ((j_common_ptr) srcinfo, src_coef_arrays[ci],
319 comp_height - y_crop_blocks - dst_blk_y -
320 (JDIMENSION) compptr->v_samp_factor,
321 (JDIMENSION) compptr->v_samp_factor,
FALSE);
324 src_buffer = (*srcinfo->mem->access_virt_barray)
325 ((j_common_ptr) srcinfo, src_coef_arrays[ci],
326 dst_blk_y + y_crop_blocks,
327 (JDIMENSION) compptr->v_samp_factor, FALSE);
329 for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
330 if (y_crop_blocks + dst_blk_y < comp_height) {
332 dst_row_ptr = dst_buffer[offset_y];
333 src_row_ptr = src_buffer[compptr->v_samp_factor - offset_y - 1];
334 src_row_ptr += x_crop_blocks;
335 for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
337 dst_ptr = dst_row_ptr[dst_blk_x];
338 src_ptr = src_row_ptr[dst_blk_x];
339 for (i = 0;
i < DCTSIZE;
i += 2) {
341 for (j = 0; j < DCTSIZE; j++)
342 *dst_ptr++ = *src_ptr++;
344 for (j = 0; j < DCTSIZE; j++)
345 *dst_ptr++ = - *src_ptr++;
350 lcl_jcopy_block_row(src_buffer[offset_y] + x_crop_blocks,
351 dst_buffer[offset_y],
352 compptr->width_in_blocks);
361do_transpose (j_decompress_ptr srcinfo, j_compress_ptr
dstinfo,
362 JDIMENSION x_crop_offset, JDIMENSION y_crop_offset,
363 jvirt_barray_ptr *src_coef_arrays,
364 jvirt_barray_ptr *dst_coef_arrays)
367 JDIMENSION dst_blk_x, dst_blk_y, x_crop_blocks, y_crop_blocks;
368 int ci,
i, j, offset_x, offset_y;
369 JBLOCKARRAY src_buffer, dst_buffer;
370 JCOEFPTR src_ptr, dst_ptr;
371 jpeg_component_info *compptr;
378 for (ci = 0; ci <
dstinfo->num_components; ci++) {
379 compptr =
dstinfo->comp_info + ci;
380 x_crop_blocks = x_crop_offset * compptr->h_samp_factor;
381 y_crop_blocks = y_crop_offset * compptr->v_samp_factor;
382 for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
383 dst_blk_y += compptr->v_samp_factor) {
384 dst_buffer = (*srcinfo->mem->access_virt_barray)
385 ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
386 (JDIMENSION) compptr->v_samp_factor, TRUE);
387 for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
388 for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
389 dst_blk_x += compptr->h_samp_factor) {
390 src_buffer = (*srcinfo->mem->access_virt_barray)
391 ((j_common_ptr) srcinfo, src_coef_arrays[ci],
392 dst_blk_x + x_crop_blocks,
393 (JDIMENSION) compptr->h_samp_factor, FALSE);
394 for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) {
395 dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
396 src_ptr = src_buffer[offset_x][dst_blk_y + offset_y + y_crop_blocks];
397 for (i = 0;
i < DCTSIZE;
i++)
398 for (j = 0; j < DCTSIZE; j++)
399 dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
409do_rot_90 (j_decompress_ptr srcinfo, j_compress_ptr
dstinfo,
410 JDIMENSION x_crop_offset, JDIMENSION y_crop_offset,
411 jvirt_barray_ptr *src_coef_arrays,
412 jvirt_barray_ptr *dst_coef_arrays)
419 JDIMENSION MCU_cols, comp_width, dst_blk_x, dst_blk_y;
420 JDIMENSION x_crop_blocks, y_crop_blocks;
421 int ci,
i, j, offset_x, offset_y;
422 JBLOCKARRAY src_buffer, dst_buffer;
423 JCOEFPTR src_ptr, dst_ptr;
424 jpeg_component_info *compptr;
430 MCU_cols = srcinfo->output_height /
433 for (ci = 0; ci <
dstinfo->num_components; ci++) {
434 compptr =
dstinfo->comp_info + ci;
435 comp_width = MCU_cols * compptr->h_samp_factor;
436 x_crop_blocks = x_crop_offset * compptr->h_samp_factor;
437 y_crop_blocks = y_crop_offset * compptr->v_samp_factor;
438 for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
439 dst_blk_y += compptr->v_samp_factor) {
440 dst_buffer = (*srcinfo->mem->access_virt_barray)
441 ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
442 (JDIMENSION) compptr->v_samp_factor, TRUE);
443 for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
444 for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
445 dst_blk_x += compptr->h_samp_factor) {
446 if (x_crop_blocks + dst_blk_x < comp_width) {
448 src_buffer = (*srcinfo->mem->access_virt_barray)
449 ((j_common_ptr) srcinfo, src_coef_arrays[ci],
450 comp_width - x_crop_blocks - dst_blk_x -
451 (JDIMENSION) compptr->h_samp_factor,
452 (JDIMENSION) compptr->h_samp_factor,
FALSE);
455 src_buffer = (*srcinfo->mem->access_virt_barray)
456 ((j_common_ptr) srcinfo, src_coef_arrays[ci],
457 dst_blk_x + x_crop_blocks,
458 (JDIMENSION) compptr->h_samp_factor, FALSE);
460 for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) {
461 dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
462 if (x_crop_blocks + dst_blk_x < comp_width) {
464 src_ptr = src_buffer[compptr->h_samp_factor - offset_x - 1]
465 [dst_blk_y + offset_y + y_crop_blocks];
466 for (i = 0;
i < DCTSIZE;
i++) {
467 for (j = 0; j < DCTSIZE; j++)
468 dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
470 for (j = 0; j < DCTSIZE; j++)
471 dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
475 src_ptr = src_buffer[offset_x]
476 [dst_blk_y + offset_y + y_crop_blocks];
477 for (i = 0;
i < DCTSIZE;
i++)
478 for (j = 0; j < DCTSIZE; j++)
479 dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
490do_rot_270 (j_decompress_ptr srcinfo, j_compress_ptr
dstinfo,
491 JDIMENSION x_crop_offset, JDIMENSION y_crop_offset,
492 jvirt_barray_ptr *src_coef_arrays,
493 jvirt_barray_ptr *dst_coef_arrays)
500 JDIMENSION MCU_rows, comp_height, dst_blk_x, dst_blk_y;
501 JDIMENSION x_crop_blocks, y_crop_blocks;
502 int ci,
i, j, offset_x, offset_y;
503 JBLOCKARRAY src_buffer, dst_buffer;
504 JCOEFPTR src_ptr, dst_ptr;
505 jpeg_component_info *compptr;
511 MCU_rows = srcinfo->output_width /
514 for (ci = 0; ci <
dstinfo->num_components; ci++) {
515 compptr =
dstinfo->comp_info + ci;
516 comp_height = MCU_rows * compptr->v_samp_factor;
517 x_crop_blocks = x_crop_offset * compptr->h_samp_factor;
518 y_crop_blocks = y_crop_offset * compptr->v_samp_factor;
519 for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
520 dst_blk_y += compptr->v_samp_factor) {
521 dst_buffer = (*srcinfo->mem->access_virt_barray)
522 ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
523 (JDIMENSION) compptr->v_samp_factor, TRUE);
524 for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
525 for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
526 dst_blk_x += compptr->h_samp_factor) {
527 src_buffer = (*srcinfo->mem->access_virt_barray)
528 ((j_common_ptr) srcinfo, src_coef_arrays[ci],
529 dst_blk_x + x_crop_blocks,
530 (JDIMENSION) compptr->h_samp_factor, FALSE);
531 for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) {
532 dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
533 if (y_crop_blocks + dst_blk_y < comp_height) {
535 src_ptr = src_buffer[offset_x]
536 [comp_height - y_crop_blocks - dst_blk_y - offset_y - 1];
537 for (i = 0;
i < DCTSIZE;
i++) {
538 for (j = 0; j < DCTSIZE; j++) {
539 dst_ptr[j*DCTSIZE+
i] = src_ptr[
i*DCTSIZE+j];
541 dst_ptr[j*DCTSIZE+
i] = -src_ptr[
i*DCTSIZE+j];
546 src_ptr = src_buffer[offset_x]
547 [dst_blk_y + offset_y + y_crop_blocks];
548 for (i = 0;
i < DCTSIZE;
i++)
549 for (j = 0; j < DCTSIZE; j++)
550 dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
561do_rot_180 (j_decompress_ptr srcinfo, j_compress_ptr
dstinfo,
562 JDIMENSION x_crop_offset, JDIMENSION y_crop_offset,
563 jvirt_barray_ptr *src_coef_arrays,
564 jvirt_barray_ptr *dst_coef_arrays)
571 JDIMENSION MCU_cols, MCU_rows, comp_width, comp_height, dst_blk_x, dst_blk_y;
572 JDIMENSION x_crop_blocks, y_crop_blocks;
573 int ci,
i, j, offset_y;
574 JBLOCKARRAY src_buffer, dst_buffer;
575 JBLOCKROW src_row_ptr, dst_row_ptr;
576 JCOEFPTR src_ptr, dst_ptr;
577 jpeg_component_info *compptr;
579 MCU_cols = srcinfo->output_width /
581 MCU_rows = srcinfo->output_height /
584 for (ci = 0; ci <
dstinfo->num_components; ci++) {
585 compptr =
dstinfo->comp_info + ci;
586 comp_width = MCU_cols * compptr->h_samp_factor;
587 comp_height = MCU_rows * compptr->v_samp_factor;
588 x_crop_blocks = x_crop_offset * compptr->h_samp_factor;
589 y_crop_blocks = y_crop_offset * compptr->v_samp_factor;
590 for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
591 dst_blk_y += compptr->v_samp_factor) {
592 dst_buffer = (*srcinfo->mem->access_virt_barray)
593 ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
594 (JDIMENSION) compptr->v_samp_factor, TRUE);
595 if (y_crop_blocks + dst_blk_y < comp_height) {
597 src_buffer = (*srcinfo->mem->access_virt_barray)
598 ((j_common_ptr) srcinfo, src_coef_arrays[ci],
599 comp_height - y_crop_blocks - dst_blk_y -
600 (JDIMENSION) compptr->v_samp_factor,
601 (JDIMENSION) compptr->v_samp_factor,
FALSE);
604 src_buffer = (*srcinfo->mem->access_virt_barray)
605 ((j_common_ptr) srcinfo, src_coef_arrays[ci],
606 dst_blk_y + y_crop_blocks,
607 (JDIMENSION) compptr->v_samp_factor, FALSE);
609 for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
610 dst_row_ptr = dst_buffer[offset_y];
611 if (y_crop_blocks + dst_blk_y < comp_height) {
613 src_row_ptr = src_buffer[compptr->v_samp_factor - offset_y - 1];
614 for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks; dst_blk_x++) {
615 dst_ptr = dst_row_ptr[dst_blk_x];
616 if (x_crop_blocks + dst_blk_x < comp_width) {
618 src_ptr = src_row_ptr[comp_width - x_crop_blocks - dst_blk_x - 1];
619 for (i = 0;
i < DCTSIZE;
i += 2) {
621 for (j = 0; j < DCTSIZE; j += 2) {
622 *dst_ptr++ = *src_ptr++;
623 *dst_ptr++ = - *src_ptr++;
626 for (j = 0; j < DCTSIZE; j += 2) {
627 *dst_ptr++ = - *src_ptr++;
628 *dst_ptr++ = *src_ptr++;
633 src_ptr = src_row_ptr[x_crop_blocks + dst_blk_x];
634 for (i = 0;
i < DCTSIZE;
i += 2) {
635 for (j = 0; j < DCTSIZE; j++)
636 *dst_ptr++ = *src_ptr++;
637 for (j = 0; j < DCTSIZE; j++)
638 *dst_ptr++ = - *src_ptr++;
644 src_row_ptr = src_buffer[offset_y];
645 for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks; dst_blk_x++) {
646 if (x_crop_blocks + dst_blk_x < comp_width) {
648 dst_ptr = dst_row_ptr[dst_blk_x];
649 src_ptr = src_row_ptr[comp_width - x_crop_blocks - dst_blk_x - 1];
650 for (i = 0;
i < DCTSIZE2;
i += 2) {
651 *dst_ptr++ = *src_ptr++;
652 *dst_ptr++ = - *src_ptr++;
656 lcl_jcopy_block_row(src_row_ptr + dst_blk_x + x_crop_blocks,
657 dst_row_ptr + dst_blk_x,
669do_transverse (j_decompress_ptr srcinfo, j_compress_ptr
dstinfo,
670 JDIMENSION x_crop_offset, JDIMENSION y_crop_offset,
671 jvirt_barray_ptr *src_coef_arrays,
672 jvirt_barray_ptr *dst_coef_arrays)
683 JDIMENSION MCU_cols, MCU_rows, comp_width, comp_height, dst_blk_x, dst_blk_y;
684 JDIMENSION x_crop_blocks, y_crop_blocks;
685 int ci,
i, j, offset_x, offset_y;
686 JBLOCKARRAY src_buffer, dst_buffer;
687 JCOEFPTR src_ptr, dst_ptr;
688 jpeg_component_info *compptr;
690 MCU_cols = srcinfo->output_height /
692 MCU_rows = srcinfo->output_width /
695 for (ci = 0; ci <
dstinfo->num_components; ci++) {
696 compptr =
dstinfo->comp_info + ci;
697 comp_width = MCU_cols * compptr->h_samp_factor;
698 comp_height = MCU_rows * compptr->v_samp_factor;
699 x_crop_blocks = x_crop_offset * compptr->h_samp_factor;
700 y_crop_blocks = y_crop_offset * compptr->v_samp_factor;
701 for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
702 dst_blk_y += compptr->v_samp_factor) {
703 dst_buffer = (*srcinfo->mem->access_virt_barray)
704 ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
705 (JDIMENSION) compptr->v_samp_factor, TRUE);
706 for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
707 for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
708 dst_blk_x += compptr->h_samp_factor) {
709 if (x_crop_blocks + dst_blk_x < comp_width) {
711 src_buffer = (*srcinfo->mem->access_virt_barray)
712 ((j_common_ptr) srcinfo, src_coef_arrays[ci],
713 comp_width - x_crop_blocks - dst_blk_x -
714 (JDIMENSION) compptr->h_samp_factor,
715 (JDIMENSION) compptr->h_samp_factor,
FALSE);
717 src_buffer = (*srcinfo->mem->access_virt_barray)
718 ((j_common_ptr) srcinfo, src_coef_arrays[ci],
719 dst_blk_x + x_crop_blocks,
720 (JDIMENSION) compptr->h_samp_factor, FALSE);
722 for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) {
723 dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
724 if (y_crop_blocks + dst_blk_y < comp_height) {
725 if (x_crop_blocks + dst_blk_x < comp_width) {
727 src_ptr = src_buffer[compptr->h_samp_factor - offset_x - 1]
728 [comp_height - y_crop_blocks - dst_blk_y - offset_y - 1];
729 for (i = 0;
i < DCTSIZE;
i++) {
730 for (j = 0; j < DCTSIZE; j++) {
731 dst_ptr[j*DCTSIZE+
i] = src_ptr[
i*DCTSIZE+j];
733 dst_ptr[j*DCTSIZE+
i] = -src_ptr[
i*DCTSIZE+j];
736 for (j = 0; j < DCTSIZE; j++) {
737 dst_ptr[j*DCTSIZE+
i] = -src_ptr[
i*DCTSIZE+j];
739 dst_ptr[j*DCTSIZE+
i] = src_ptr[
i*DCTSIZE+j];
744 src_ptr = src_buffer[offset_x]
745 [comp_height - y_crop_blocks - dst_blk_y - offset_y - 1];
746 for (i = 0;
i < DCTSIZE;
i++) {
747 for (j = 0; j < DCTSIZE; j++) {
748 dst_ptr[j*DCTSIZE+
i] = src_ptr[
i*DCTSIZE+j];
750 dst_ptr[j*DCTSIZE+
i] = -src_ptr[
i*DCTSIZE+j];
755 if (x_crop_blocks + dst_blk_x < comp_width) {
757 src_ptr = src_buffer[compptr->h_samp_factor - offset_x - 1]
758 [dst_blk_y + offset_y + y_crop_blocks];
759 for (i = 0;
i < DCTSIZE;
i++) {
760 for (j = 0; j < DCTSIZE; j++)
761 dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
763 for (j = 0; j < DCTSIZE; j++)
764 dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
768 src_ptr = src_buffer[offset_x]
769 [dst_blk_y + offset_y + y_crop_blocks];
770 for (i = 0;
i < DCTSIZE;
i++)
771 for (j = 0; j < DCTSIZE; j++)
772 dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
826jtransform_request_workspace (j_decompress_ptr srcinfo,
829 jvirt_barray_ptr *coef_arrays;
830 boolean need_workspace, transpose_it;
831 jpeg_component_info *compptr;
832 JDIMENSION xoffset, yoffset;
833 JDIMENSION width_in_iMCUs, height_in_iMCUs;
834 JDIMENSION width_in_blocks, height_in_blocks;
835 int ci, h_samp_factor, v_samp_factor;
839 srcinfo->jpeg_color_space == JCS_YCbCr &&
840 srcinfo->num_components == 3)
848#if JPEG_LIB_VERSION >= 80
849 jpeg_core_output_dimensions(srcinfo);
851 srcinfo->output_width = srcinfo->image_width;
852 srcinfo->output_height = srcinfo->image_height;
859 if (!jtransform_perfect_transform(srcinfo->output_width,
860 srcinfo->output_height,
861 srcinfo->min_DCT_h_scaled_size_,
862 srcinfo->min_DCT_v_scaled_size_,
866 if (!jtransform_perfect_transform(srcinfo->output_width,
867 srcinfo->output_height,
868 srcinfo->max_h_samp_factor * srcinfo->min_DCT_h_scaled_size_,
869 srcinfo->max_v_samp_factor * srcinfo->min_DCT_v_scaled_size_,
892 srcinfo->max_v_samp_factor * srcinfo->min_DCT_v_scaled_size_;
894 srcinfo->max_h_samp_factor * srcinfo->min_DCT_h_scaled_size_;
905 srcinfo->max_h_samp_factor * srcinfo->min_DCT_h_scaled_size_;
907 srcinfo->max_v_samp_factor * srcinfo->min_DCT_v_scaled_size_;
923 ERREXIT(srcinfo, JERR_CONVERSION_NOTIMPL);
933 ERREXIT(srcinfo, JERR_CONVERSION_NOTIMPL);
965 need_workspace =
FALSE;
966 transpose_it =
FALSE;
970 need_workspace =
TRUE;
975 trim_right_edge(info, srcinfo->output_width);
977 need_workspace =
TRUE;
982 trim_bottom_edge(info, srcinfo->output_height);
984 need_workspace =
TRUE;
989 need_workspace =
TRUE;
994 trim_right_edge(info, srcinfo->output_height);
995 trim_bottom_edge(info, srcinfo->output_width);
998 need_workspace =
TRUE;
1003 trim_right_edge(info, srcinfo->output_height);
1005 need_workspace =
TRUE;
1006 transpose_it =
TRUE;
1010 trim_right_edge(info, srcinfo->output_width);
1011 trim_bottom_edge(info, srcinfo->output_height);
1014 need_workspace =
TRUE;
1018 trim_bottom_edge(info, srcinfo->output_width);
1020 need_workspace =
TRUE;
1021 transpose_it =
TRUE;
1029 if (need_workspace) {
1030 coef_arrays = (jvirt_barray_ptr *)
1031 (*srcinfo->mem->alloc_small) ((j_common_ptr) srcinfo, JPOOL_IMAGE,
1033 width_in_iMCUs = (JDIMENSION)
1036 height_in_iMCUs = (JDIMENSION)
1040 compptr = srcinfo->comp_info + ci;
1043 h_samp_factor = v_samp_factor = 1;
1044 }
else if (transpose_it) {
1045 h_samp_factor = compptr->v_samp_factor;
1046 v_samp_factor = compptr->h_samp_factor;
1048 h_samp_factor = compptr->h_samp_factor;
1049 v_samp_factor = compptr->v_samp_factor;
1051 width_in_blocks = width_in_iMCUs * h_samp_factor;
1052 height_in_blocks = height_in_iMCUs * v_samp_factor;
1053 coef_arrays[ci] = (*srcinfo->mem->request_virt_barray)
1054 ((j_common_ptr) srcinfo, JPOOL_IMAGE,
FALSE,
1055 width_in_blocks, height_in_blocks, (JDIMENSION) v_samp_factor);
1068transpose_critical_parameters (j_compress_ptr
dstinfo)
1070 int tblno,
i, j, ci, itemp;
1071 jpeg_component_info *compptr;
1072 JQUANT_TBL *qtblptr;
1079 dstinfo->image_height = jtemp;
1080#if JPEG_LIB_VERSION >= 70
1081 itemp =
dstinfo->min_DCT_h_scaled_size;
1083 dstinfo->min_DCT_v_scaled_size = itemp;
1087 for (ci = 0; ci <
dstinfo->num_components; ci++) {
1088 compptr =
dstinfo->comp_info + ci;
1089 itemp = compptr->h_samp_factor;
1090 compptr->h_samp_factor = compptr->v_samp_factor;
1091 compptr->v_samp_factor = itemp;
1095 for (tblno = 0; tblno < NUM_QUANT_TBLS; tblno++) {
1096 qtblptr =
dstinfo->quant_tbl_ptrs[tblno];
1097 if (qtblptr != NULL) {
1098 for (i = 0;
i < DCTSIZE;
i++) {
1099 for (j = 0; j <
i; j++) {
1100 qtemp = qtblptr->quantval[
i*DCTSIZE+j];
1101 qtblptr->quantval[
i*DCTSIZE+j] = qtblptr->quantval[j*DCTSIZE+
i];
1102 qtblptr->quantval[j*DCTSIZE+
i] = qtemp;
1115#if JPEG_LIB_VERSION >= 70
1117adjust_exif_parameters (JOCTET FAR * data,
unsigned int length,
1118 JDIMENSION new_width, JDIMENSION new_height)
1120 boolean is_motorola;
1121 unsigned int number_of_tags, tagnum;
1122 unsigned int firstoffset, offset;
1123 JDIMENSION new_value;
1125 if (length < 12)
return;
1128 if (GETJOCTET(data[0]) == 0x49 && GETJOCTET(data[1]) == 0x49)
1129 is_motorola =
FALSE;
1130 else if (GETJOCTET(data[0]) == 0x4D && GETJOCTET(data[1]) == 0x4D)
1137 if (GETJOCTET(data[2]) != 0)
return;
1138 if (GETJOCTET(data[3]) != 0x2A)
return;
1140 if (GETJOCTET(data[3]) != 0)
return;
1141 if (GETJOCTET(data[2]) != 0x2A)
return;
1146 if (GETJOCTET(data[4]) != 0)
return;
1147 if (GETJOCTET(data[5]) != 0)
return;
1148 firstoffset = GETJOCTET(data[6]);
1150 firstoffset += GETJOCTET(data[7]);
1152 if (GETJOCTET(data[7]) != 0)
return;
1153 if (GETJOCTET(data[6]) != 0)
return;
1154 firstoffset = GETJOCTET(data[5]);
1156 firstoffset += GETJOCTET(data[4]);
1158 if (firstoffset > length - 2)
return;
1162 number_of_tags = GETJOCTET(data[firstoffset]);
1163 number_of_tags <<= 8;
1164 number_of_tags += GETJOCTET(data[firstoffset+1]);
1166 number_of_tags = GETJOCTET(data[firstoffset+1]);
1167 number_of_tags <<= 8;
1168 number_of_tags += GETJOCTET(data[firstoffset]);
1170 if (number_of_tags == 0)
return;
1175 if (firstoffset > length - 12)
return;
1178 tagnum = GETJOCTET(data[firstoffset]);
1180 tagnum += GETJOCTET(data[firstoffset+1]);
1182 tagnum = GETJOCTET(data[firstoffset+1]);
1184 tagnum += GETJOCTET(data[firstoffset]);
1186 if (tagnum == 0x8769)
break;
1187 if (--number_of_tags == 0)
return;
1193 if (GETJOCTET(data[firstoffset+8]) != 0)
return;
1194 if (GETJOCTET(data[firstoffset+9]) != 0)
return;
1195 offset = GETJOCTET(data[firstoffset+10]);
1197 offset += GETJOCTET(data[firstoffset+11]);
1199 if (GETJOCTET(data[firstoffset+11]) != 0)
return;
1200 if (GETJOCTET(data[firstoffset+10]) != 0)
return;
1201 offset = GETJOCTET(data[firstoffset+9]);
1203 offset += GETJOCTET(data[firstoffset+8]);
1205 if (offset > length - 2)
return;
1209 number_of_tags = GETJOCTET(data[offset]);
1210 number_of_tags <<= 8;
1211 number_of_tags += GETJOCTET(data[offset+1]);
1213 number_of_tags = GETJOCTET(data[offset+1]);
1214 number_of_tags <<= 8;
1215 number_of_tags += GETJOCTET(data[offset]);
1217 if (number_of_tags < 2)
return;
1222 if (offset > length - 12)
return;
1225 tagnum = GETJOCTET(data[offset]);
1227 tagnum += GETJOCTET(data[offset+1]);
1229 tagnum = GETJOCTET(data[offset+1]);
1231 tagnum += GETJOCTET(data[offset]);
1233 if (tagnum == 0xA002 || tagnum == 0xA003) {
1234 if (tagnum == 0xA002)
1235 new_value = new_width;
1237 new_value = new_height;
1247 data[offset+10] = (JOCTET)((new_value >> 8) & 0xFF);
1248 data[offset+11] = (JOCTET)(new_value & 0xFF);
1256 data[offset+8] = (JOCTET)(new_value & 0xFF);
1257 data[offset+9] = (JOCTET)((new_value >> 8) & 0xFF);
1258 data[offset+10] = 0;
1259 data[offset+11] = 0;
1263 }
while (--number_of_tags);
1279GLOBAL(jvirt_barray_ptr *)
1280jtransform_adjust_parameters (j_decompress_ptr srcinfo,
1282 jvirt_barray_ptr *src_coef_arrays,
1292 if (((
dstinfo->jpeg_color_space == JCS_YCbCr &&
1293 dstinfo->num_components == 3) ||
1294 (
dstinfo->jpeg_color_space == JCS_GRAYSCALE &&
1295 dstinfo->num_components == 1)) &&
1296 srcinfo->comp_info[0].h_samp_factor == srcinfo->max_h_samp_factor &&
1297 srcinfo->comp_info[0].v_samp_factor == srcinfo->max_v_samp_factor) {
1303 int sv_quant_tbl_no =
dstinfo->comp_info[0].quant_tbl_no;
1304 jpeg_set_colorspace(
dstinfo, JCS_GRAYSCALE);
1305 dstinfo->comp_info[0].quant_tbl_no = sv_quant_tbl_no;
1308 ERREXIT(
dstinfo, JERR_CONVERSION_NOTIMPL);
1315 dstinfo->comp_info[0].h_samp_factor = 1;
1316 dstinfo->comp_info[0].v_samp_factor = 1;
1322#if JPEG_LIB_VERSION >= 70
1333#if JPEG_LIB_VERSION < 70
1337 transpose_critical_parameters(
dstinfo);
1340#if JPEG_LIB_VERSION < 70
1348 if (srcinfo->marker_list != NULL &&
1349 srcinfo->marker_list->marker == JPEG_APP0+1 &&
1350 srcinfo->marker_list->data_length >= 6 &&
1351 GETJOCTET(srcinfo->marker_list->data[0]) == 0x45 &&
1352 GETJOCTET(srcinfo->marker_list->data[1]) == 0x78 &&
1353 GETJOCTET(srcinfo->marker_list->data[2]) == 0x69 &&
1354 GETJOCTET(srcinfo->marker_list->data[3]) == 0x66 &&
1355 GETJOCTET(srcinfo->marker_list->data[4]) == 0 &&
1356 GETJOCTET(srcinfo->marker_list->data[5]) == 0) {
1359#if JPEG_LIB_VERSION >= 70
1361 if (
dstinfo->jpeg_width != srcinfo->image_width ||
1362 dstinfo->jpeg_height != srcinfo->image_height)
1364 adjust_exif_parameters(srcinfo->marker_list->data + 6,
1365 srcinfo->marker_list->data_length - 6,
1373 return src_coef_arrays;
1387jtransform_execute_transform (j_decompress_ptr srcinfo,
1389 jvirt_barray_ptr *src_coef_arrays,
1401 src_coef_arrays, dst_coef_arrays);
1406 src_coef_arrays, dst_coef_arrays);
1413 src_coef_arrays, dst_coef_arrays);
1417 src_coef_arrays, dst_coef_arrays);
1421 src_coef_arrays, dst_coef_arrays);
1425 src_coef_arrays, dst_coef_arrays);
1429 src_coef_arrays, dst_coef_arrays);
1433 src_coef_arrays, dst_coef_arrays);
1460jtransform_perfect_transform(JDIMENSION image_width, JDIMENSION image_height,
1461 int MCU_width,
int MCU_height,
1466 switch (transform) {
1469 if (image_width % (JDIMENSION) MCU_width)
1474 if (image_height % (JDIMENSION) MCU_height)
1479 if (image_width % (JDIMENSION) MCU_width)
1481 if (image_height % (JDIMENSION) MCU_height)
1501#ifdef SAVE_MARKERS_SUPPORTED
1506 jpeg_save_markers(srcinfo, JPEG_COM, 0xFFFF);
1510 for (
m = 0;
m < 16;
m++)
1511 jpeg_save_markers(srcinfo, JPEG_APP0 +
m, 0xFFFF);
1514 (void) srcinfo; (void)
option;
1529 jpeg_saved_marker_ptr marker;
1538 for (marker = srcinfo->marker_list; marker !=
NULL; marker = marker->next) {
1539 if (
dstinfo->write_JFIF_header &&
1540 marker->marker == JPEG_APP0 &&
1541 marker->data_length >= 5 &&
1542 GETJOCTET(marker->data[0]) == 0x4A &&
1543 GETJOCTET(marker->data[1]) == 0x46 &&
1544 GETJOCTET(marker->data[2]) == 0x49 &&
1545 GETJOCTET(marker->data[3]) == 0x46 &&
1546 GETJOCTET(marker->data[4]) == 0)
1548 if (
dstinfo->write_Adobe_marker &&
1549 marker->marker == JPEG_APP0+14 &&
1550 marker->data_length >= 5 &&
1551 GETJOCTET(marker->data[0]) == 0x41 &&
1552 GETJOCTET(marker->data[1]) == 0x64 &&
1553 GETJOCTET(marker->data[2]) == 0x6F &&
1554 GETJOCTET(marker->data[3]) == 0x62 &&
1555 GETJOCTET(marker->data[4]) == 0x65)
1557#ifdef NEED_FAR_POINTERS
1561 jpeg_write_m_header(
dstinfo, marker->marker, marker->data_length);
1562 for (
i = 0;
i < marker->data_length;
i++)
1563 jpeg_write_m_byte(
dstinfo, marker->data[
i]);
1566 jpeg_write_marker(
dstinfo, marker->marker,
1567 marker->data, marker->data_length);
jcopy_markers_setup(j_decompress_ptr srcinfo, JCOPY_OPTION option)
static long jdiv_round_up(long a, long b)
#define dstinfo_min_DCT_h_scaled_size
jcopy_markers_execute(j_decompress_ptr srcinfo, j_compress_ptr dstinfo, JCOPY_OPTION option)
#define dstinfo_min_DCT_v_scaled_size