170a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkine/* 270a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkine * transupp.h 370a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkine * 470a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkine * Copyright (C) 1997, Thomas G. Lane. 570a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkine * This file is part of the Independent JPEG Group's software. 670a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkine * For conditions of distribution and use, see the accompanying README file. 770a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkine * 870a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkine * This file contains declarations for image transformation routines and 970a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkine * other utility code used by the jpegtran sample application. These are 1070a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkine * NOT part of the core JPEG library. But we keep these routines separate 1170a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkine * from jpegtran.c to ease the task of maintaining jpegtran-like programs 1270a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkine * that have other user interfaces. 1370a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkine * 1470a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkine * NOTE: all the routines declared here have very specific requirements 1570a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkine * about when they are to be executed during the reading and writing of the 1670a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkine * source and destination files. See the comments in transupp.c, or see 1770a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkine * jpegtran.c for an example of correct usage. 1870a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkine */ 1970a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkine 2070a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkine/* If you happen not to want the image transform support, disable it here */ 2170a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkine#ifndef TRANSFORMS_SUPPORTED 2270a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkine#define TRANSFORMS_SUPPORTED 1 /* 0 disables transform code */ 2370a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkine#endif 2470a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkine 2570a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkine/* Short forms of external names for systems with brain-damaged linkers. */ 2670a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkine 2770a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkine#ifdef NEED_SHORT_EXTERNAL_NAMES 2870a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkine#define jtransform_request_workspace jTrRequest 2970a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkine#define jtransform_adjust_parameters jTrAdjust 3070a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkine#define jtransform_execute_transformation jTrExec 3170a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkine#define jcopy_markers_setup jCMrkSetup 3270a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkine#define jcopy_markers_execute jCMrkExec 3370a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkine#endif /* NEED_SHORT_EXTERNAL_NAMES */ 3470a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkine 3570a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkine 3670a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkine/* 3770a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkine * Codes for supported types of image transformations. 3870a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkine */ 3970a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkine 4070a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkinetypedef enum { 4170a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkine JXFORM_NONE, /* no transformation */ 4270a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkine JXFORM_FLIP_H, /* horizontal flip */ 4370a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkine JXFORM_FLIP_V, /* vertical flip */ 4470a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkine JXFORM_TRANSPOSE, /* transpose across UL-to-LR axis */ 4570a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkine JXFORM_TRANSVERSE, /* transpose across UR-to-LL axis */ 4670a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkine JXFORM_ROT_90, /* 90-degree clockwise rotation */ 4770a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkine JXFORM_ROT_180, /* 180-degree rotation */ 4870a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkine JXFORM_ROT_270 /* 270-degree clockwise (or 90 ccw) */ 4970a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkine} JXFORM_CODE; 5070a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkine 5170a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkine/* 5270a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkine * Although rotating and flipping data expressed as DCT coefficients is not 5370a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkine * hard, there is an asymmetry in the JPEG format specification for images 5470a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkine * whose dimensions aren't multiples of the iMCU size. The right and bottom 5570a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkine * image edges are padded out to the next iMCU boundary with junk data; but 5670a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkine * no padding is possible at the top and left edges. If we were to flip 5770a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkine * the whole image including the pad data, then pad garbage would become 5870a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkine * visible at the top and/or left, and real pixels would disappear into the 5970a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkine * pad margins --- perhaps permanently, since encoders & decoders may not 6070a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkine * bother to preserve DCT blocks that appear to be completely outside the 6170a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkine * nominal image area. So, we have to exclude any partial iMCUs from the 6270a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkine * basic transformation. 6370a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkine * 6470a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkine * Transpose is the only transformation that can handle partial iMCUs at the 6570a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkine * right and bottom edges completely cleanly. flip_h can flip partial iMCUs 6670a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkine * at the bottom, but leaves any partial iMCUs at the right edge untouched. 6770a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkine * Similarly flip_v leaves any partial iMCUs at the bottom edge untouched. 6870a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkine * The other transforms are defined as combinations of these basic transforms 6970a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkine * and process edge blocks in a way that preserves the equivalence. 7070a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkine * 7170a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkine * The "trim" option causes untransformable partial iMCUs to be dropped; 7270a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkine * this is not strictly lossless, but it usually gives the best-looking 7370a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkine * result for odd-size images. Note that when this option is active, 7470a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkine * the expected mathematical equivalences between the transforms may not hold. 7570a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkine * (For example, -rot 270 -trim trims only the bottom edge, but -rot 90 -trim 7670a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkine * followed by -rot 180 -trim trims both edges.) 7770a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkine * 7870a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkine * We also offer a "force to grayscale" option, which simply discards the 7970a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkine * chrominance channels of a YCbCr image. This is lossless in the sense that 8070a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkine * the luminance channel is preserved exactly. It's not the same kind of 8170a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkine * thing as the rotate/flip transformations, but it's convenient to handle it 8270a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkine * as part of this package, mainly because the transformation routines have to 8370a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkine * be aware of the option to know how many components to work on. 8470a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkine */ 8570a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkine 8670a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkinetypedef struct { 8770a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkine /* Options: set by caller */ 8870a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkine JXFORM_CODE transform; /* image transform operator */ 8970a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkine boolean trim; /* if TRUE, trim partial MCUs as needed */ 9070a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkine boolean force_grayscale; /* if TRUE, convert color image to grayscale */ 9170a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkine 9270a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkine /* Internal workspace: caller should not touch these */ 9370a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkine int num_components; /* # of components in workspace */ 9470a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkine jvirt_barray_ptr * workspace_coef_arrays; /* workspace for transformations */ 9570a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkine} jpeg_transform_info; 9670a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkine 9770a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkine 9870a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkine#if TRANSFORMS_SUPPORTED 9970a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkine 10070a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkine/* Request any required workspace */ 10170a18cd874a22452aca9e39e22275ed4538ed20bVladimir ChtchetkineEXTERN(void) jtransform_request_workspace 10270a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkine JPP((j_decompress_ptr srcinfo, jpeg_transform_info *info)); 10370a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkine/* Adjust output image parameters */ 10470a18cd874a22452aca9e39e22275ed4538ed20bVladimir ChtchetkineEXTERN(jvirt_barray_ptr *) jtransform_adjust_parameters 10570a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkine JPP((j_decompress_ptr srcinfo, j_compress_ptr dstinfo, 10670a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkine jvirt_barray_ptr *src_coef_arrays, 10770a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkine jpeg_transform_info *info)); 10870a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkine/* Execute the actual transformation, if any */ 10970a18cd874a22452aca9e39e22275ed4538ed20bVladimir ChtchetkineEXTERN(void) jtransform_execute_transformation 11070a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkine JPP((j_decompress_ptr srcinfo, j_compress_ptr dstinfo, 11170a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkine jvirt_barray_ptr *src_coef_arrays, 11270a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkine jpeg_transform_info *info)); 11370a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkine 11470a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkine#endif /* TRANSFORMS_SUPPORTED */ 11570a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkine 11670a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkine 11770a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkine/* 11870a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkine * Support for copying optional markers from source to destination file. 11970a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkine */ 12070a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkine 12170a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkinetypedef enum { 12270a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkine JCOPYOPT_NONE, /* copy no optional markers */ 12370a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkine JCOPYOPT_COMMENTS, /* copy only comment (COM) markers */ 12470a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkine JCOPYOPT_ALL /* copy all optional markers */ 12570a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkine} JCOPY_OPTION; 12670a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkine 12770a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkine#define JCOPYOPT_DEFAULT JCOPYOPT_COMMENTS /* recommended default */ 12870a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkine 12970a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkine/* Setup decompression object to save desired markers in memory */ 13070a18cd874a22452aca9e39e22275ed4538ed20bVladimir ChtchetkineEXTERN(void) jcopy_markers_setup 13170a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkine JPP((j_decompress_ptr srcinfo, JCOPY_OPTION option)); 13270a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkine/* Copy markers saved in the given source object to the destination object */ 13370a18cd874a22452aca9e39e22275ed4538ed20bVladimir ChtchetkineEXTERN(void) jcopy_markers_execute 13470a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkine JPP((j_decompress_ptr srcinfo, j_compress_ptr dstinfo, 13570a18cd874a22452aca9e39e22275ed4538ed20bVladimir Chtchetkine JCOPY_OPTION option)); 136