add libjpeg
[reactos.git] / reactos / include / reactos / libs / libjpeg / transupp.h
1 /*
2 * transupp.h
3 *
4 * Copyright (C) 1997-2001, 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.
7 *
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.
13 *
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.
18 */
19
20 /* If you happen not to want the image transform support, disable it here */
21 #ifndef TRANSFORMS_SUPPORTED
22 #define TRANSFORMS_SUPPORTED 1 /* 0 disables transform code */
23 #endif
24
25 /*
26 * Although rotating and flipping data expressed as DCT coefficients is not
27 * hard, there is an asymmetry in the JPEG format specification for images
28 * whose dimensions aren't multiples of the iMCU size. The right and bottom
29 * image edges are padded out to the next iMCU boundary with junk data; but
30 * no padding is possible at the top and left edges. If we were to flip
31 * the whole image including the pad data, then pad garbage would become
32 * visible at the top and/or left, and real pixels would disappear into the
33 * pad margins --- perhaps permanently, since encoders & decoders may not
34 * bother to preserve DCT blocks that appear to be completely outside the
35 * nominal image area. So, we have to exclude any partial iMCUs from the
36 * basic transformation.
37 *
38 * Transpose is the only transformation that can handle partial iMCUs at the
39 * right and bottom edges completely cleanly. flip_h can flip partial iMCUs
40 * at the bottom, but leaves any partial iMCUs at the right edge untouched.
41 * Similarly flip_v leaves any partial iMCUs at the bottom edge untouched.
42 * The other transforms are defined as combinations of these basic transforms
43 * and process edge blocks in a way that preserves the equivalence.
44 *
45 * The "trim" option causes untransformable partial iMCUs to be dropped;
46 * this is not strictly lossless, but it usually gives the best-looking
47 * result for odd-size images. Note that when this option is active,
48 * the expected mathematical equivalences between the transforms may not hold.
49 * (For example, -rot 270 -trim trims only the bottom edge, but -rot 90 -trim
50 * followed by -rot 180 -trim trims both edges.)
51 *
52 * We also offer a lossless-crop option, which discards data outside a given
53 * image region but losslessly preserves what is inside. Like the rotate and
54 * flip transforms, lossless crop is restricted by the JPEG format: the upper
55 * left corner of the selected region must fall on an iMCU boundary. If this
56 * does not hold for the given crop parameters, we silently move the upper left
57 * corner up and/or left to make it so, simultaneously increasing the region
58 * dimensions to keep the lower right crop corner unchanged. (Thus, the
59 * output image covers at least the requested region, but may cover more.)
60 *
61 * If both crop and a rotate/flip transform are requested, the crop is applied
62 * last --- that is, the crop region is specified in terms of the destination
63 * image.
64 *
65 * We also offer a "force to grayscale" option, which simply discards the
66 * chrominance channels of a YCbCr image. This is lossless in the sense that
67 * the luminance channel is preserved exactly. It's not the same kind of
68 * thing as the rotate/flip transformations, but it's convenient to handle it
69 * as part of this package, mainly because the transformation routines have to
70 * be aware of the option to know how many components to work on.
71 */
72
73
74 /* Short forms of external names for systems with brain-damaged linkers. */
75
76 #ifdef NEED_SHORT_EXTERNAL_NAMES
77 #define jtransform_parse_crop_spec jTrParCrop
78 #define jtransform_request_workspace jTrRequest
79 #define jtransform_adjust_parameters jTrAdjust
80 #define jtransform_execute_transform jTrExec
81 #define jtransform_perfect_transform jTrPerfect
82 #define jcopy_markers_setup jCMrkSetup
83 #define jcopy_markers_execute jCMrkExec
84 #endif /* NEED_SHORT_EXTERNAL_NAMES */
85
86
87 /*
88 * Codes for supported types of image transformations.
89 */
90
91 typedef enum {
92 JXFORM_NONE, /* no transformation */
93 JXFORM_FLIP_H, /* horizontal flip */
94 JXFORM_FLIP_V, /* vertical flip */
95 JXFORM_TRANSPOSE, /* transpose across UL-to-LR axis */
96 JXFORM_TRANSVERSE, /* transpose across UR-to-LL axis */
97 JXFORM_ROT_90, /* 90-degree clockwise rotation */
98 JXFORM_ROT_180, /* 180-degree rotation */
99 JXFORM_ROT_270, /* 270-degree clockwise (or 90 ccw) */
100 JXFORM_DROP /* drop */
101 } JXFORM_CODE;
102
103 /*
104 * Codes for crop parameters, which can individually be unspecified,
105 * positive, or negative. (Negative width or height makes no sense, though.)
106 */
107
108 typedef enum {
109 JCROP_UNSET,
110 JCROP_POS,
111 JCROP_NEG
112 } JCROP_CODE;
113
114 /*
115 * Transform parameters struct.
116 * NB: application must not change any elements of this struct after
117 * calling jtransform_request_workspace.
118 */
119
120 typedef struct {
121 /* Options: set by caller */
122 JXFORM_CODE transform; /* image transform operator */
123 boolean perfect; /* if TRUE, fail if partial MCUs are requested */
124 boolean trim; /* if TRUE, trim partial MCUs as needed */
125 boolean force_grayscale; /* if TRUE, convert color image to grayscale */
126 boolean crop; /* if TRUE, crop source image */
127
128 /* Crop parameters: application need not set these unless crop is TRUE.
129 * These can be filled in by jtransform_parse_crop_spec().
130 */
131 JDIMENSION crop_width; /* Width of selected region */
132 JCROP_CODE crop_width_set;
133 JDIMENSION crop_height; /* Height of selected region */
134 JCROP_CODE crop_height_set;
135 JDIMENSION crop_xoffset; /* X offset of selected region */
136 JCROP_CODE crop_xoffset_set; /* (negative measures from right edge) */
137 JDIMENSION crop_yoffset; /* Y offset of selected region */
138 JCROP_CODE crop_yoffset_set; /* (negative measures from bottom edge) */
139
140 /* Drop parameters: set by caller for drop request */
141 j_decompress_ptr drop_ptr;
142 jvirt_barray_ptr * drop_coef_arrays;
143
144 /* Internal workspace: caller should not touch these */
145 int num_components; /* # of components in workspace */
146 jvirt_barray_ptr * workspace_coef_arrays; /* workspace for transformations */
147 JDIMENSION output_width; /* cropped destination dimensions */
148 JDIMENSION output_height;
149 JDIMENSION x_crop_offset; /* destination crop offsets measured in iMCUs */
150 JDIMENSION y_crop_offset;
151 JDIMENSION drop_width; /* drop dimensions measured in iMCUs */
152 JDIMENSION drop_height;
153 int max_h_samp_factor; /* destination iMCU size */
154 int max_v_samp_factor;
155 } jpeg_transform_info;
156
157
158 #if TRANSFORMS_SUPPORTED
159
160 /* Parse a crop specification (written in X11 geometry style) */
161 EXTERN_1(boolean) jtransform_parse_crop_spec
162 JPP((jpeg_transform_info *info, const char *spec));
163 /* Request any required workspace */
164 EXTERN_1(void) jtransform_request_workspace
165 JPP((j_decompress_ptr srcinfo, jpeg_transform_info *info));
166 /* Adjust output image parameters */
167 EXTERN_1(jvirt_barray_ptr *) jtransform_adjust_parameters
168 JPP((j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
169 jvirt_barray_ptr *src_coef_arrays,
170 jpeg_transform_info *info));
171 /* Execute the actual transformation, if any */
172 EXTERN_1(void) jtransform_execute_transform
173 JPP((j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
174 jvirt_barray_ptr *src_coef_arrays,
175 jpeg_transform_info *info));
176 /* Determine whether lossless transformation is perfectly
177 * possible for a specified image and transformation.
178 */
179 EXTERN_1(boolean) jtransform_perfect_transform
180 JPP((JDIMENSION image_width, JDIMENSION image_height,
181 int MCU_width, int MCU_height,
182 JXFORM_CODE transform));
183
184 /* jtransform_execute_transform used to be called
185 * jtransform_execute_transformation, but some compilers complain about
186 * routine names that long. This macro is here to avoid breaking any
187 * old source code that uses the original name...
188 */
189 #define jtransform_execute_transformation jtransform_execute_transform
190
191 #endif /* TRANSFORMS_SUPPORTED */
192
193
194 /*
195 * Support for copying optional markers from source to destination file.
196 */
197
198 typedef enum {
199 JCOPYOPT_NONE, /* copy no optional markers */
200 JCOPYOPT_COMMENTS, /* copy only comment (COM) markers */
201 JCOPYOPT_ALL, /* copy all optional markers */
202 JCOPYOPT_EXIF /* copy Exif APP1 marker */
203 } JCOPY_OPTION;
204
205 #define JCOPYOPT_DEFAULT JCOPYOPT_COMMENTS /* recommended default */
206
207 /* Setup decompression object to save desired markers in memory */
208 EXTERN_1(void) jcopy_markers_setup
209 JPP((j_decompress_ptr srcinfo, JCOPY_OPTION option));
210 /* Copy markers saved in the given source object to the destination object */
211 EXTERN_1(void) jcopy_markers_execute
212 JPP((j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
213 JCOPY_OPTION option));