00001 //============================================== 00002 // copyright : (C) 2003-2005 by Will Stokes 00003 //============================================== 00004 // This program is free software; you can redistribute it 00005 // and/or modify it under the terms of the GNU General 00006 // Public License as published by the Free Software 00007 // Foundation; either version 2 of the License, or 00008 // (at your option) any later version. 00009 //============================================== 00010 00011 #ifndef BACKEND_TOOLS_JPEG_JPEGINTERNAL 00012 #define BACKEND_TOOLS_JPEG_JPEGINTERNAL 00013 00014 //Support for copying optional markers from source to destination file. 00015 typedef enum { 00016 JCOPYOPT_NONE, //copy no optional markers 00017 JCOPYOPT_COMMENTS,//copy only comment (COM) markers 00018 JCOPYOPT_ALL //copy all optional markers 00019 } JCOPY_OPTION; 00020 00021 //Codes for supported types of image transformations. 00022 typedef enum { 00023 JXFORM_NONE, // no transformation 00024 JXFORM_FLIP_H, // horizontal flip 00025 JXFORM_FLIP_V, // vertical flip 00026 JXFORM_TRANSPOSE, // transpose across UL-to-LR axis 00027 JXFORM_TRANSVERSE, // transpose across UR-to-LL axis 00028 JXFORM_ROT_90, // 90-degree clockwise rotation 00029 JXFORM_ROT_180, // 180-degree rotation 00030 JXFORM_ROT_270 // 270-degree clockwise (or 90 ccw) 00031 } JXFORM_CODE; 00032 00033 // Although rotating and flipping data expressed as DCT coefficients is not 00034 // hard, there is an asymmetry in the JPEG format specification for images 00035 // whose dimensions aren't multiples of the iMCU size. The right and bottom 00036 // image edges are padded out to the next iMCU boundary with junk data; but 00037 // no padding is possible at the top and left edges. If we were to flip 00038 // the whole image including the pad data, then pad garbage would become 00039 // visible at the top and/or left, and real pixels would disappear into the 00040 // pad margins --- perhaps permanently, since encoders & decoders may not 00041 // bother to preserve DCT blocks that appear to be completely outside the 00042 // nominal image area. So, we have to exclude any partial iMCUs from the 00043 // basic transformation. 00044 // 00045 // Transpose is the only transformation that can handle partial iMCUs at the 00046 // right and bottom edges completely cleanly. flip_h can flip partial iMCUs 00047 // at the bottom, but leaves any partial iMCUs at the right edge untouched. 00048 // Similarly flip_v leaves any partial iMCUs at the bottom edge untouched. 00049 // The other transforms are defined as combinations of these basic transforms 00050 // and process edge blocks in a way that preserves the equivalence. 00051 // 00052 // The "trim" option causes untransformable partial iMCUs to be dropped; 00053 // this is not strictly lossless, but it usually gives the best-looking 00054 // result for odd-size images. Note that when this option is active, 00055 // the expected mathematical equivalences between the transforms may not hold. 00056 // (For example, -rot 270 -trim trims only the bottom edge, but -rot 90 -trim 00057 // followed by -rot 180 -trim trims both edges.) 00058 // 00059 // We also offer a "force to grayscale" option, which simply discards the 00060 // chrominance channels of a YCbCr image. This is lossless in the sense that 00061 // the luminance channel is preserved exactly. It's not the same kind of 00062 // thing as the rotate/flip transformations, but it's convenient to handle it 00063 // as part of this package, mainly because the transformation routines have to 00064 // be aware of the option to know how many components to work on. 00065 typedef struct { 00066 //Options: set by caller 00067 JXFORM_CODE transform; // image transform operator 00068 boolean trim; // if TRUE, trim partial MCUs as needed 00069 boolean force_grayscale; // if TRUE, convert color image to grayscale 00070 00072 int num_components; // # of components in workspace 00073 jvirt_barray_ptr * workspace_coef_arrays; // workspace for transformations 00074 } jpeg_transform_info; 00075 00076 // Setup decompression object to save desired markers in memory 00077 void jcopy_markers_setup(j_decompress_ptr srcinfo, JCOPY_OPTION option); 00078 00079 // Request any required workspace 00080 void jtransform_request_workspace(j_decompress_ptr srcinfo, jpeg_transform_info *info); 00081 00082 // Adjust output image parameters 00083 jvirt_barray_ptr * jtransform_adjust_parameters(j_compress_ptr dstinfo, 00084 jvirt_barray_ptr *src_coef_arrays, 00085 jpeg_transform_info *info); 00086 // Execute the actual transformation, if any 00087 void jtransform_execute_transformation(j_decompress_ptr srcinfo, j_compress_ptr dstinfo, 00088 jvirt_barray_ptr *src_coef_arrays, 00089 jpeg_transform_info *info); 00090 00091 // Copy markers saved in the given source object to the destination object 00092 void jcopy_markers_execute(j_decompress_ptr srcinfo, j_compress_ptr dstinfo); 00093 00094 00095 void do_rot_90 (j_decompress_ptr srcinfo, j_compress_ptr dstinfo, 00096 jvirt_barray_ptr *src_coef_arrays, 00097 jvirt_barray_ptr *dst_coef_arrays); 00098 00099 void do_rot_270 (j_decompress_ptr srcinfo, j_compress_ptr dstinfo, 00100 jvirt_barray_ptr *src_coef_arrays, 00101 jvirt_barray_ptr *dst_coef_arrays); 00102 00103 void do_rot_180 (j_decompress_ptr srcinfo, j_compress_ptr dstinfo, 00104 jvirt_barray_ptr *src_coef_arrays, 00105 jvirt_barray_ptr *dst_coef_arrays); 00106 00107 void do_transverse (j_decompress_ptr srcinfo, j_compress_ptr dstinfo, 00108 jvirt_barray_ptr *src_coef_arrays, 00109 jvirt_barray_ptr *dst_coef_arrays); 00110 00111 void do_flip_v (j_decompress_ptr srcinfo, j_compress_ptr dstinfo, 00112 jvirt_barray_ptr *src_coef_arrays, 00113 jvirt_barray_ptr *dst_coef_arrays); 00114 00115 void do_flip_h (j_decompress_ptr srcinfo, j_compress_ptr dstinfo, 00116 jvirt_barray_ptr *src_coef_arrays); 00117 00118 void trim_bottom_edge (j_compress_ptr dstinfo); 00119 void trim_right_edge (j_compress_ptr dstinfo); 00120 00121 void do_transpose (j_decompress_ptr srcinfo, j_compress_ptr dstinfo, 00122 jvirt_barray_ptr *src_coef_arrays, 00123 jvirt_barray_ptr *dst_coef_arrays); 00124 00125 EXTERN(long) jround_up JPP((long a, long b)); 00126 00127 EXTERN(void) jcopy_block_row JPP((JBLOCKROW input_row, 00128 JBLOCKROW output_row, 00129 JDIMENSION num_blocks)); 00130 00131 #endif //BACKEND_TOOLS_JPEG_JPEGINTERNAL 00132