4 * Copyright (C) 1997, Thomas G. Lane.
5 * This file is part of the Independent JPEG Group's software.
6 * For conditions of distribution and use, see the accompanying README file.
8 * This file contains declarations for image transformation routines and
9 * other utility code used by the jpegtran sample application. These are
10 * NOT part of the core JPEG library. But we keep these routines separate
11 * from jpegtran.c to ease the task of maintaining jpegtran-like programs
12 * that have other user interfaces.
14 * NOTE: all the routines declared here have very specific requirements
15 * about when they are to be executed during the reading and writing of the
16 * source and destination files. See the comments in transupp.c, or see
17 * jpegtran.c for an example of correct usage.
23 /* If you happen not to want the image transform support, disable it here */
24 #ifndef TRANSFORMS_SUPPORTED
25 #define TRANSFORMS_SUPPORTED 1 /* 0 disables transform code */
28 /* Short forms of external names for systems with brain-damaged linkers. */
30 #ifdef NEED_SHORT_EXTERNAL_NAMES
31 #define jtransform_request_workspace jTrRequest
32 #define jtransform_adjust_parameters jTrAdjust
33 #define jtransform_execute_transformation jTrExec
34 #define jcopy_markers_setup jCMrkSetup
35 #define jcopy_markers_execute jCMrkExec
36 #endif /* NEED_SHORT_EXTERNAL_NAMES */
40 * Codes for supported types of image transformations.
44 JXFORM_NONE
, /* no transformation */
45 JXFORM_FLIP_H
, /* horizontal flip */
46 JXFORM_FLIP_V
, /* vertical flip */
47 JXFORM_TRANSPOSE
, /* transpose across UL-to-LR axis */
48 JXFORM_TRANSVERSE
, /* transpose across UR-to-LL axis */
49 JXFORM_ROT_90
, /* 90-degree clockwise rotation */
50 JXFORM_ROT_180
, /* 180-degree rotation */
51 JXFORM_ROT_270
/* 270-degree clockwise (or 90 ccw) */
55 * Although rotating and flipping data expressed as DCT coefficients is not
56 * hard, there is an asymmetry in the JPEG format specification for images
57 * whose dimensions aren't multiples of the iMCU size. The right and bottom
58 * image edges are padded out to the next iMCU boundary with junk data; but
59 * no padding is possible at the top and left edges. If we were to flip
60 * the whole image including the pad data, then pad garbage would become
61 * visible at the top and/or left, and real pixels would disappear into the
62 * pad margins --- perhaps permanently, since encoders & decoders may not
63 * bother to preserve DCT blocks that appear to be completely outside the
64 * nominal image area. So, we have to exclude any partial iMCUs from the
65 * basic transformation.
67 * Transpose is the only transformation that can handle partial iMCUs at the
68 * right and bottom edges completely cleanly. flip_h can flip partial iMCUs
69 * at the bottom, but leaves any partial iMCUs at the right edge untouched.
70 * Similarly flip_v leaves any partial iMCUs at the bottom edge untouched.
71 * The other transforms are defined as combinations of these basic transforms
72 * and process edge blocks in a way that preserves the equivalence.
74 * The "trim" option causes untransformable partial iMCUs to be dropped;
75 * this is not strictly lossless, but it usually gives the best-looking
76 * result for odd-size images. Note that when this option is active,
77 * the expected mathematical equivalences between the transforms may not hold.
78 * (For example, -rot 270 -trim trims only the bottom edge, but -rot 90 -trim
79 * followed by -rot 180 -trim trims both edges.)
81 * We also offer a "force to grayscale" option, which simply discards the
82 * chrominance channels of a YCbCr image. This is lossless in the sense that
83 * the luminance channel is preserved exactly. It's not the same kind of
84 * thing as the rotate/flip transformations, but it's convenient to handle it
85 * as part of this package, mainly because the transformation routines have to
86 * be aware of the option to know how many components to work on.
90 /* Options: set by caller */
91 JXFORM_CODE transform
; /* image transform operator */
92 boolean trim
; /* if TRUE, trim partial MCUs as needed */
93 boolean force_grayscale
; /* if TRUE, convert color image to grayscale */
95 /* Internal workspace: caller should not touch these */
96 int num_components
; /* # of components in workspace */
97 jvirt_barray_ptr
* workspace_coef_arrays
; /* workspace for transformations */
98 } jpeg_transform_info
;
101 #if TRANSFORMS_SUPPORTED
103 /* Request any required workspace */
104 EXTERN(void) jtransform_request_workspace
105 JPP((j_decompress_ptr srcinfo
, jpeg_transform_info
*info
));
106 /* Adjust output image parameters */
107 EXTERN(jvirt_barray_ptr
*) jtransform_adjust_parameters
108 JPP((j_decompress_ptr srcinfo
, j_compress_ptr dstinfo
,
109 jvirt_barray_ptr
*src_coef_arrays
,
110 jpeg_transform_info
*info
));
111 /* Execute the actual transformation, if any */
112 EXTERN(void) jtransform_execute_transformation
113 JPP((j_decompress_ptr srcinfo
, j_compress_ptr dstinfo
,
114 jvirt_barray_ptr
*src_coef_arrays
,
115 jpeg_transform_info
*info
));
117 #endif /* TRANSFORMS_SUPPORTED */
121 * Support for copying optional markers from source to destination file.
125 JCOPYOPT_NONE
, /* copy no optional markers */
126 JCOPYOPT_COMMENTS
, /* copy only comment (COM) markers */
127 JCOPYOPT_ALL
/* copy all optional markers */
130 #define JCOPYOPT_DEFAULT JCOPYOPT_COMMENTS /* recommended default */
132 /* Setup decompression object to save desired markers in memory */
133 EXTERN(void) jcopy_markers_setup
134 JPP((j_decompress_ptr srcinfo
, JCOPY_OPTION option
));
135 /* Copy markers saved in the given source object to the destination object */
136 EXTERN(void) jcopy_markers_execute
137 JPP((j_decompress_ptr srcinfo
, j_compress_ptr dstinfo
,
138 JCOPY_OPTION option
));