File indexing completed on 2025-01-19 03:55:52
0001 /* 0002 * transupp.h 0003 * 0004 * SPDX-FileCopyrightText: 1997, Thomas G. Lane. 0005 * This file is part of the Independent JPEG Group's software. 0006 * For conditions of distribution and use, see the accompanying README file. 0007 * 0008 * This file contains declarations for image transformation routines and 0009 * other utility code used by the jpegtran sample application. These are 0010 * NOT part of the core JPEG library. But we keep these routines separate 0011 * from jpegtran.c to ease the task of maintaining jpegtran-like programs 0012 * that have other user interfaces. 0013 * 0014 * NOTE: all the routines declared here have very specific requirements 0015 * about when they are to be executed during the reading and writing of the 0016 * source and destination files. See the comments in transupp.c, or see 0017 * jpegtran.c for an example of correct usage. 0018 */ 0019 0020 /* If you happen not to want the image transform support, disable it here */ 0021 #ifndef TRANSFORMS_SUPPORTED 0022 #define TRANSFORMS_SUPPORTED 1 /* 0 disables transform code */ 0023 #endif 0024 0025 /* Short forms of external names for systems with brain-damaged linkers. */ 0026 0027 #ifdef NEED_SHORT_EXTERNAL_NAMES 0028 #define jtransform_request_workspace jTrRequest 0029 #define jtransform_adjust_parameters jTrAdjust 0030 #define jtransform_execute_transformation jTrExec 0031 #define jcopy_markers_setup jCMrkSetup 0032 #define jcopy_markers_execute jCMrkExec 0033 #endif /* NEED_SHORT_EXTERNAL_NAMES */ 0034 0035 0036 /* 0037 * Codes for supported types of image transformations. 0038 */ 0039 0040 typedef enum { 0041 JXFORM_NONE, /* no transformation */ 0042 JXFORM_FLIP_H, /* horizontal flip */ 0043 JXFORM_FLIP_V, /* vertical flip */ 0044 JXFORM_TRANSPOSE, /* transpose across UL-to-LR axis */ 0045 JXFORM_TRANSVERSE, /* transpose across UR-to-LL axis */ 0046 JXFORM_ROT_90, /* 90-degree clockwise rotation */ 0047 JXFORM_ROT_180, /* 180-degree rotation */ 0048 JXFORM_ROT_270 /* 270-degree clockwise (or 90 ccw) */ 0049 } JXFORM_CODE; 0050 0051 /* 0052 * Although rotating and flipping data expressed as DCT coefficients is not 0053 * hard, there is an asymmetry in the JPEG format specification for images 0054 * whose dimensions aren't multiples of the iMCU size. The right and bottom 0055 * image edges are padded out to the next iMCU boundary with junk data; but 0056 * no padding is possible at the top and left edges. If we were to flip 0057 * the whole image including the pad data, then pad garbage would become 0058 * visible at the top and/or left, and real pixels would disappear into the 0059 * pad margins --- perhaps permanently, since encoders & decoders may not 0060 * bother to preserve DCT blocks that appear to be completely outside the 0061 * nominal image area. So, we have to exclude any partial iMCUs from the 0062 * basic transformation. 0063 * 0064 * Transpose is the only transformation that can handle partial iMCUs at the 0065 * right and bottom edges completely cleanly. flip_h can flip partial iMCUs 0066 * at the bottom, but leaves any partial iMCUs at the right edge untouched. 0067 * Similarly flip_v leaves any partial iMCUs at the bottom edge untouched. 0068 * The other transforms are defined as combinations of these basic transforms 0069 * and process edge blocks in a way that preserves the equivalence. 0070 * 0071 * The "trim" option causes untransformable partial iMCUs to be dropped; 0072 * this is not strictly lossless, but it usually gives the best-looking 0073 * result for odd-size images. Note that when this option is active, 0074 * the expected mathematical equivalences between the transforms may not hold. 0075 * (For example, -rot 270 -trim trims only the bottom edge, but -rot 90 -trim 0076 * followed by -rot 180 -trim trims both edges.) 0077 * 0078 * We also offer a "force to grayscale" option, which simply discards the 0079 * chrominance channels of a YCbCr image. This is lossless in the sense that 0080 * the luminance channel is preserved exactly. It's not the same kind of 0081 * thing as the rotate/flip transformations, but it's convenient to handle it 0082 * as part of this package, mainly because the transformation routines have to 0083 * be aware of the option to know how many components to work on. 0084 */ 0085 0086 typedef struct { 0087 /* Options: set by caller */ 0088 JXFORM_CODE transform; /* image transform operator */ 0089 boolean trim; /* if TRUE, trim partial MCUs as needed */ 0090 boolean force_grayscale; /* if TRUE, convert color image to grayscale */ 0091 0092 /* Internal workspace: caller should not touch these */ 0093 int num_components; /* # of components in workspace */ 0094 jvirt_barray_ptr * workspace_coef_arrays; /* workspace for transformations */ 0095 } jpeg_transform_info; 0096 0097 0098 #if TRANSFORMS_SUPPORTED 0099 0100 /* Request any required workspace */ 0101 EXTERN(void) jtransform_request_workspace 0102 JPP((j_decompress_ptr srcinfo, jpeg_transform_info *info)); 0103 /* Adjust output image parameters */ 0104 EXTERN(jvirt_barray_ptr *) jtransform_adjust_parameters 0105 JPP((j_decompress_ptr srcinfo, j_compress_ptr dstinfo, 0106 jvirt_barray_ptr *src_coef_arrays, 0107 jpeg_transform_info *info)); 0108 /* Execute the actual transformation, if any */ 0109 EXTERN(void) jtransform_execute_transformation 0110 JPP((j_decompress_ptr srcinfo, j_compress_ptr dstinfo, 0111 jvirt_barray_ptr *src_coef_arrays, 0112 jpeg_transform_info *info)); 0113 0114 #endif /* TRANSFORMS_SUPPORTED */ 0115 0116 0117 /* 0118 * Support for copying optional markers from source to destination file. 0119 */ 0120 0121 typedef enum { 0122 JCOPYOPT_NONE, /* copy no optional markers */ 0123 JCOPYOPT_COMMENTS, /* copy only comment (COM) markers */ 0124 JCOPYOPT_ALL /* copy all optional markers */ 0125 } JCOPY_OPTION; 0126 0127 #define JCOPYOPT_DEFAULT JCOPYOPT_COMMENTS /* recommended default */ 0128 0129 /* Setup decompression object to save desired markers in memory */ 0130 EXTERN(void) jcopy_markers_setup 0131 JPP((j_decompress_ptr srcinfo, JCOPY_OPTION option)); 0132 /* Copy markers saved in the given source object to the destination object */ 0133 EXTERN(void) jcopy_markers_execute 0134 JPP((j_decompress_ptr srcinfo, j_compress_ptr dstinfo, 0135 JCOPY_OPTION option));