Lines 1-7
Link Here
|
1 |
/* |
1 |
/* |
2 |
* transupp.c |
2 |
* transupp.c |
3 |
* |
3 |
* |
4 |
* Copyright (C) 1997-2011, Thomas G. Lane, Guido Vollbeding. |
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 |
* |
Lines 20-28
Link Here
|
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" |
23 |
#include <ctype.h> /* to declare isdigit() */ |
25 |
#include <ctype.h> /* to declare isdigit() */ |
24 |
|
26 |
|
25 |
|
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 |
35 |
|
36 |
|
26 |
#if TRANSFORMS_SUPPORTED |
37 |
#if TRANSFORMS_SUPPORTED |
27 |
|
38 |
|
28 |
/* |
39 |
/* |
Lines 134-140
Link Here
|
134 |
* Partial iMCUs at the right edge are left untouched. |
145 |
* Partial iMCUs at the right edge are left untouched. |
135 |
*/ |
146 |
*/ |
136 |
MCU_cols = srcinfo->output_width / |
147 |
MCU_cols = srcinfo->output_width / |
137 |
(dstinfo->max_h_samp_factor * dstinfo->min_DCT_h_scaled_size); |
148 |
(dstinfo->max_h_samp_factor * dstinfo_min_DCT_h_scaled_size); |
138 |
|
149 |
|
139 |
for (ci = 0; ci < dstinfo->num_components; ci++) { |
150 |
for (ci = 0; ci < dstinfo->num_components; ci++) { |
140 |
compptr = dstinfo->comp_info + ci; |
151 |
compptr = dstinfo->comp_info + ci; |
Lines 200-206
Link Here
|
200 |
* this is essentially the same as the routine above. |
211 |
* this is essentially the same as the routine above. |
201 |
*/ |
212 |
*/ |
202 |
MCU_cols = srcinfo->output_width / |
213 |
MCU_cols = srcinfo->output_width / |
203 |
(dstinfo->max_h_samp_factor * dstinfo->min_DCT_h_scaled_size); |
214 |
(dstinfo->max_h_samp_factor * dstinfo_min_DCT_h_scaled_size); |
204 |
|
215 |
|
205 |
for (ci = 0; ci < dstinfo->num_components; ci++) { |
216 |
for (ci = 0; ci < dstinfo->num_components; ci++) { |
206 |
compptr = dstinfo->comp_info + ci; |
217 |
compptr = dstinfo->comp_info + ci; |
Lines 265-271
Link Here
|
265 |
* Partial iMCUs at the bottom edge are copied verbatim. |
276 |
* Partial iMCUs at the bottom edge are copied verbatim. |
266 |
*/ |
277 |
*/ |
267 |
MCU_rows = srcinfo->output_height / |
278 |
MCU_rows = srcinfo->output_height / |
268 |
(dstinfo->max_v_samp_factor * dstinfo->min_DCT_v_scaled_size); |
279 |
(dstinfo->max_v_samp_factor * dstinfo_min_DCT_v_scaled_size); |
269 |
|
280 |
|
270 |
for (ci = 0; ci < dstinfo->num_components; ci++) { |
281 |
for (ci = 0; ci < dstinfo->num_components; ci++) { |
271 |
compptr = dstinfo->comp_info + ci; |
282 |
compptr = dstinfo->comp_info + ci; |
Lines 393-399
Link Here
|
393 |
* not mirrored. |
404 |
* not mirrored. |
394 |
*/ |
405 |
*/ |
395 |
MCU_cols = srcinfo->output_height / |
406 |
MCU_cols = srcinfo->output_height / |
396 |
(dstinfo->max_h_samp_factor * dstinfo->min_DCT_h_scaled_size); |
407 |
(dstinfo->max_h_samp_factor * dstinfo_min_DCT_h_scaled_size); |
397 |
|
408 |
|
398 |
for (ci = 0; ci < dstinfo->num_components; ci++) { |
409 |
for (ci = 0; ci < dstinfo->num_components; ci++) { |
399 |
compptr = dstinfo->comp_info + ci; |
410 |
compptr = dstinfo->comp_info + ci; |
Lines 474-480
Link Here
|
474 |
* not mirrored. |
485 |
* not mirrored. |
475 |
*/ |
486 |
*/ |
476 |
MCU_rows = srcinfo->output_width / |
487 |
MCU_rows = srcinfo->output_width / |
477 |
(dstinfo->max_v_samp_factor * dstinfo->min_DCT_v_scaled_size); |
488 |
(dstinfo->max_v_samp_factor * dstinfo_min_DCT_v_scaled_size); |
478 |
|
489 |
|
479 |
for (ci = 0; ci < dstinfo->num_components; ci++) { |
490 |
for (ci = 0; ci < dstinfo->num_components; ci++) { |
480 |
compptr = dstinfo->comp_info + ci; |
491 |
compptr = dstinfo->comp_info + ci; |
Lines 542-550
Link Here
|
542 |
jpeg_component_info *compptr; |
553 |
jpeg_component_info *compptr; |
543 |
|
554 |
|
544 |
MCU_cols = srcinfo->output_width / |
555 |
MCU_cols = srcinfo->output_width / |
545 |
(dstinfo->max_h_samp_factor * dstinfo->min_DCT_h_scaled_size); |
556 |
(dstinfo->max_h_samp_factor * dstinfo_min_DCT_h_scaled_size); |
546 |
MCU_rows = srcinfo->output_height / |
557 |
MCU_rows = srcinfo->output_height / |
547 |
(dstinfo->max_v_samp_factor * dstinfo->min_DCT_v_scaled_size); |
558 |
(dstinfo->max_v_samp_factor * dstinfo_min_DCT_v_scaled_size); |
548 |
|
559 |
|
549 |
for (ci = 0; ci < dstinfo->num_components; ci++) { |
560 |
for (ci = 0; ci < dstinfo->num_components; ci++) { |
550 |
compptr = dstinfo->comp_info + ci; |
561 |
compptr = dstinfo->comp_info + ci; |
Lines 653-661
Link Here
|
653 |
jpeg_component_info *compptr; |
664 |
jpeg_component_info *compptr; |
654 |
|
665 |
|
655 |
MCU_cols = srcinfo->output_height / |
666 |
MCU_cols = srcinfo->output_height / |
656 |
(dstinfo->max_h_samp_factor * dstinfo->min_DCT_h_scaled_size); |
667 |
(dstinfo->max_h_samp_factor * dstinfo_min_DCT_h_scaled_size); |
657 |
MCU_rows = srcinfo->output_width / |
668 |
MCU_rows = srcinfo->output_width / |
658 |
(dstinfo->max_v_samp_factor * dstinfo->min_DCT_v_scaled_size); |
669 |
(dstinfo->max_v_samp_factor * dstinfo_min_DCT_v_scaled_size); |
659 |
|
670 |
|
660 |
for (ci = 0; ci < dstinfo->num_components; ci++) { |
671 |
for (ci = 0; ci < dstinfo->num_components; ci++) { |
661 |
compptr = dstinfo->comp_info + ci; |
672 |
compptr = dstinfo->comp_info + ci; |
Lines 771-777
Link Here
|
771 |
* The routine returns TRUE if the spec string is valid, FALSE if not. |
782 |
* The routine returns TRUE if the spec string is valid, FALSE if not. |
772 |
* |
783 |
* |
773 |
* The crop spec string should have the format |
784 |
* The crop spec string should have the format |
774 |
* <width>[f]x<height>[f]{+-}<xoffset>{+-}<yoffset> |
785 |
* <width>x<height>{+-}<xoffset>{+-}<yoffset> |
775 |
* where width, height, xoffset, and yoffset are unsigned integers. |
786 |
* where width, height, xoffset, and yoffset are unsigned integers. |
776 |
* Each of the elements can be omitted to indicate a default value. |
787 |
* Each of the elements can be omitted to indicate a default value. |
777 |
* (A weakness of this style is that it is not possible to omit xoffset |
788 |
* (A weakness of this style is that it is not possible to omit xoffset |
Lines 793-814
Link Here
|
793 |
/* fetch width */ |
804 |
/* fetch width */ |
794 |
if (! jt_read_integer(&spec, &info->crop_width)) |
805 |
if (! jt_read_integer(&spec, &info->crop_width)) |
795 |
return FALSE; |
806 |
return FALSE; |
796 |
if (*spec == 'f' || *spec == 'F') { |
807 |
info->crop_width_set = JCROP_POS; |
797 |
spec++; |
|
|
798 |
info->crop_width_set = JCROP_FORCE; |
799 |
} else |
800 |
info->crop_width_set = JCROP_POS; |
801 |
} |
808 |
} |
802 |
if (*spec == 'x' || *spec == 'X') { |
809 |
if (*spec == 'x' || *spec == 'X') { |
803 |
/* fetch height */ |
810 |
/* fetch height */ |
804 |
spec++; |
811 |
spec++; |
805 |
if (! jt_read_integer(&spec, &info->crop_height)) |
812 |
if (! jt_read_integer(&spec, &info->crop_height)) |
806 |
return FALSE; |
813 |
return FALSE; |
807 |
if (*spec == 'f' || *spec == 'F') { |
814 |
info->crop_height_set = JCROP_POS; |
808 |
spec++; |
|
|
809 |
info->crop_height_set = JCROP_FORCE; |
810 |
} else |
811 |
info->crop_height_set = JCROP_POS; |
812 |
} |
815 |
} |
813 |
if (*spec == '+' || *spec == '-') { |
816 |
if (*spec == '+' || *spec == '-') { |
814 |
/* fetch xoffset */ |
817 |
/* fetch xoffset */ |
Lines 897-903
Link Here
|
897 |
info->num_components = srcinfo->num_components; |
900 |
info->num_components = srcinfo->num_components; |
898 |
|
901 |
|
899 |
/* Compute output image dimensions and related values. */ |
902 |
/* Compute output image dimensions and related values. */ |
|
|
903 |
#if JPEG_LIB_VERSION >= 80 |
900 |
jpeg_core_output_dimensions(srcinfo); |
904 |
jpeg_core_output_dimensions(srcinfo); |
|
|
905 |
#else |
906 |
srcinfo->output_width = srcinfo->image_width; |
907 |
srcinfo->output_height = srcinfo->image_height; |
908 |
#endif |
901 |
|
909 |
|
902 |
/* Return right away if -perfect is given and transformation is not perfect. |
910 |
/* Return right away if -perfect is given and transformation is not perfect. |
903 |
*/ |
911 |
*/ |
Lines 905-919
Link Here
|
905 |
if (info->num_components == 1) { |
913 |
if (info->num_components == 1) { |
906 |
if (!jtransform_perfect_transform(srcinfo->output_width, |
914 |
if (!jtransform_perfect_transform(srcinfo->output_width, |
907 |
srcinfo->output_height, |
915 |
srcinfo->output_height, |
908 |
srcinfo->min_DCT_h_scaled_size, |
916 |
srcinfo->_min_DCT_h_scaled_size, |
909 |
srcinfo->min_DCT_v_scaled_size, |
917 |
srcinfo->_min_DCT_v_scaled_size, |
910 |
info->transform)) |
918 |
info->transform)) |
911 |
return FALSE; |
919 |
return FALSE; |
912 |
} else { |
920 |
} else { |
913 |
if (!jtransform_perfect_transform(srcinfo->output_width, |
921 |
if (!jtransform_perfect_transform(srcinfo->output_width, |
914 |
srcinfo->output_height, |
922 |
srcinfo->output_height, |
915 |
srcinfo->max_h_samp_factor * srcinfo->min_DCT_h_scaled_size, |
923 |
srcinfo->max_h_samp_factor * srcinfo->_min_DCT_h_scaled_size, |
916 |
srcinfo->max_v_samp_factor * srcinfo->min_DCT_v_scaled_size, |
924 |
srcinfo->max_v_samp_factor * srcinfo->_min_DCT_v_scaled_size, |
917 |
info->transform)) |
925 |
info->transform)) |
918 |
return FALSE; |
926 |
return FALSE; |
919 |
} |
927 |
} |
Lines 932-957
Link Here
|
932 |
info->output_width = srcinfo->output_height; |
940 |
info->output_width = srcinfo->output_height; |
933 |
info->output_height = srcinfo->output_width; |
941 |
info->output_height = srcinfo->output_width; |
934 |
if (info->num_components == 1) { |
942 |
if (info->num_components == 1) { |
935 |
info->iMCU_sample_width = srcinfo->min_DCT_v_scaled_size; |
943 |
info->iMCU_sample_width = srcinfo->_min_DCT_v_scaled_size; |
936 |
info->iMCU_sample_height = srcinfo->min_DCT_h_scaled_size; |
944 |
info->iMCU_sample_height = srcinfo->_min_DCT_h_scaled_size; |
937 |
} else { |
945 |
} else { |
938 |
info->iMCU_sample_width = |
946 |
info->iMCU_sample_width = |
939 |
srcinfo->max_v_samp_factor * srcinfo->min_DCT_v_scaled_size; |
947 |
srcinfo->max_v_samp_factor * srcinfo->_min_DCT_v_scaled_size; |
940 |
info->iMCU_sample_height = |
948 |
info->iMCU_sample_height = |
941 |
srcinfo->max_h_samp_factor * srcinfo->min_DCT_h_scaled_size; |
949 |
srcinfo->max_h_samp_factor * srcinfo->_min_DCT_h_scaled_size; |
942 |
} |
950 |
} |
943 |
break; |
951 |
break; |
944 |
default: |
952 |
default: |
945 |
info->output_width = srcinfo->output_width; |
953 |
info->output_width = srcinfo->output_width; |
946 |
info->output_height = srcinfo->output_height; |
954 |
info->output_height = srcinfo->output_height; |
947 |
if (info->num_components == 1) { |
955 |
if (info->num_components == 1) { |
948 |
info->iMCU_sample_width = srcinfo->min_DCT_h_scaled_size; |
956 |
info->iMCU_sample_width = srcinfo->_min_DCT_h_scaled_size; |
949 |
info->iMCU_sample_height = srcinfo->min_DCT_v_scaled_size; |
957 |
info->iMCU_sample_height = srcinfo->_min_DCT_v_scaled_size; |
950 |
} else { |
958 |
} else { |
951 |
info->iMCU_sample_width = |
959 |
info->iMCU_sample_width = |
952 |
srcinfo->max_h_samp_factor * srcinfo->min_DCT_h_scaled_size; |
960 |
srcinfo->max_h_samp_factor * srcinfo->_min_DCT_h_scaled_size; |
953 |
info->iMCU_sample_height = |
961 |
info->iMCU_sample_height = |
954 |
srcinfo->max_v_samp_factor * srcinfo->min_DCT_v_scaled_size; |
962 |
srcinfo->max_v_samp_factor * srcinfo->_min_DCT_v_scaled_size; |
955 |
} |
963 |
} |
956 |
break; |
964 |
break; |
957 |
} |
965 |
} |
Lines 988-1003
Link Here
|
988 |
else |
996 |
else |
989 |
yoffset = info->crop_yoffset; |
997 |
yoffset = info->crop_yoffset; |
990 |
/* Now adjust so that upper left corner falls at an iMCU boundary */ |
998 |
/* Now adjust so that upper left corner falls at an iMCU boundary */ |
991 |
if (info->crop_width_set == JCROP_FORCE) |
999 |
info->output_width = |
992 |
info->output_width = info->crop_width; |
1000 |
info->crop_width + (xoffset % info->iMCU_sample_width); |
993 |
else |
1001 |
info->output_height = |
994 |
info->output_width = |
1002 |
info->crop_height + (yoffset % info->iMCU_sample_height); |
995 |
info->crop_width + (xoffset % info->iMCU_sample_width); |
|
|
996 |
if (info->crop_height_set == JCROP_FORCE) |
997 |
info->output_height = info->crop_height; |
998 |
else |
999 |
info->output_height = |
1000 |
info->crop_height + (yoffset % info->iMCU_sample_height); |
1001 |
/* Save x/y offsets measured in iMCUs */ |
1003 |
/* Save x/y offsets measured in iMCUs */ |
1002 |
info->x_crop_offset = xoffset / info->iMCU_sample_width; |
1004 |
info->x_crop_offset = xoffset / info->iMCU_sample_width; |
1003 |
info->y_crop_offset = yoffset / info->iMCU_sample_height; |
1005 |
info->y_crop_offset = yoffset / info->iMCU_sample_height; |
Lines 1020-1026
Link Here
|
1020 |
case JXFORM_FLIP_H: |
1022 |
case JXFORM_FLIP_H: |
1021 |
if (info->trim) |
1023 |
if (info->trim) |
1022 |
trim_right_edge(info, srcinfo->output_width); |
1024 |
trim_right_edge(info, srcinfo->output_width); |
1023 |
if (info->y_crop_offset != 0) |
1025 |
if (info->y_crop_offset != 0 || info->slow_hflip) |
1024 |
need_workspace = TRUE; |
1026 |
need_workspace = TRUE; |
1025 |
/* do_flip_h_no_crop doesn't need a workspace array */ |
1027 |
/* do_flip_h_no_crop doesn't need a workspace array */ |
1026 |
break; |
1028 |
break; |
Lines 1124-1132
Link Here
|
1124 |
jtemp = dstinfo->image_width; |
1126 |
jtemp = dstinfo->image_width; |
1125 |
dstinfo->image_width = dstinfo->image_height; |
1127 |
dstinfo->image_width = dstinfo->image_height; |
1126 |
dstinfo->image_height = jtemp; |
1128 |
dstinfo->image_height = jtemp; |
|
|
1129 |
#if JPEG_LIB_VERSION >= 70 |
1127 |
itemp = dstinfo->min_DCT_h_scaled_size; |
1130 |
itemp = dstinfo->min_DCT_h_scaled_size; |
1128 |
dstinfo->min_DCT_h_scaled_size = dstinfo->min_DCT_v_scaled_size; |
1131 |
dstinfo->min_DCT_h_scaled_size = dstinfo->min_DCT_v_scaled_size; |
1129 |
dstinfo->min_DCT_v_scaled_size = itemp; |
1132 |
dstinfo->min_DCT_v_scaled_size = itemp; |
|
|
1133 |
#endif |
1130 |
|
1134 |
|
1131 |
/* Transpose sampling factors */ |
1135 |
/* Transpose sampling factors */ |
1132 |
for (ci = 0; ci < dstinfo->num_components; ci++) { |
1136 |
for (ci = 0; ci < dstinfo->num_components; ci++) { |
Lines 1362-1369
Link Here
|
1362 |
/* Correct the destination's image dimensions as necessary |
1366 |
/* Correct the destination's image dimensions as necessary |
1363 |
* for rotate/flip, resize, and crop operations. |
1367 |
* for rotate/flip, resize, and crop operations. |
1364 |
*/ |
1368 |
*/ |
|
|
1369 |
#if JPEG_LIB_VERSION >= 70 |
1365 |
dstinfo->jpeg_width = info->output_width; |
1370 |
dstinfo->jpeg_width = info->output_width; |
1366 |
dstinfo->jpeg_height = info->output_height; |
1371 |
dstinfo->jpeg_height = info->output_height; |
|
|
1372 |
#endif |
1367 |
|
1373 |
|
1368 |
/* Transpose destination image parameters */ |
1374 |
/* Transpose destination image parameters */ |
1369 |
switch (info->transform) { |
1375 |
switch (info->transform) { |
Lines 1371-1379
Link Here
|
1371 |
case JXFORM_TRANSVERSE: |
1377 |
case JXFORM_TRANSVERSE: |
1372 |
case JXFORM_ROT_90: |
1378 |
case JXFORM_ROT_90: |
1373 |
case JXFORM_ROT_270: |
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 |
1374 |
transpose_critical_parameters(dstinfo); |
1384 |
transpose_critical_parameters(dstinfo); |
1375 |
break; |
1385 |
break; |
1376 |
default: |
1386 |
default: |
|
|
1387 |
#if JPEG_LIB_VERSION < 70 |
1388 |
dstinfo->image_width = info->output_width; |
1389 |
dstinfo->image_height = info->output_height; |
1390 |
#endif |
1377 |
break; |
1391 |
break; |
1378 |
} |
1392 |
} |
1379 |
|
1393 |
|
Lines 1389-1394
Link Here
|
1389 |
GETJOCTET(srcinfo->marker_list->data[5]) == 0) { |
1403 |
GETJOCTET(srcinfo->marker_list->data[5]) == 0) { |
1390 |
/* Suppress output of JFIF marker */ |
1404 |
/* Suppress output of JFIF marker */ |
1391 |
dstinfo->write_JFIF_header = FALSE; |
1405 |
dstinfo->write_JFIF_header = FALSE; |
|
|
1406 |
#if JPEG_LIB_VERSION >= 70 |
1392 |
/* Adjust Exif image parameters */ |
1407 |
/* Adjust Exif image parameters */ |
1393 |
if (dstinfo->jpeg_width != srcinfo->image_width || |
1408 |
if (dstinfo->jpeg_width != srcinfo->image_width || |
1394 |
dstinfo->jpeg_height != srcinfo->image_height) |
1409 |
dstinfo->jpeg_height != srcinfo->image_height) |
Lines 1396-1401
Link Here
|
1396 |
adjust_exif_parameters(srcinfo->marker_list->data + 6, |
1411 |
adjust_exif_parameters(srcinfo->marker_list->data + 6, |
1397 |
srcinfo->marker_list->data_length - 6, |
1412 |
srcinfo->marker_list->data_length - 6, |
1398 |
dstinfo->jpeg_width, dstinfo->jpeg_height); |
1413 |
dstinfo->jpeg_width, dstinfo->jpeg_height); |
|
|
1414 |
#endif |
1399 |
} |
1415 |
} |
1400 |
|
1416 |
|
1401 |
/* Return the appropriate output data set */ |
1417 |
/* Return the appropriate output data set */ |
Lines 1432-1438
Link Here
|
1432 |
src_coef_arrays, dst_coef_arrays); |
1448 |
src_coef_arrays, dst_coef_arrays); |
1433 |
break; |
1449 |
break; |
1434 |
case JXFORM_FLIP_H: |
1450 |
case JXFORM_FLIP_H: |
1435 |
if (info->y_crop_offset != 0) |
1451 |
if (info->y_crop_offset != 0 || info->slow_hflip) |
1436 |
do_flip_h(srcinfo, dstinfo, info->x_crop_offset, info->y_crop_offset, |
1452 |
do_flip_h(srcinfo, dstinfo, info->x_crop_offset, info->y_crop_offset, |
1437 |
src_coef_arrays, dst_coef_arrays); |
1453 |
src_coef_arrays, dst_coef_arrays); |
1438 |
else |
1454 |
else |