19f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project/* 29f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * transupp.h 39f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * 49f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * Copyright (C) 1997, Thomas G. Lane. 59f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * This file is part of the Independent JPEG Group's software. 69f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * For conditions of distribution and use, see the accompanying README file. 79f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * 89f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * This file contains declarations for image transformation routines and 99f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * other utility code used by the jpegtran sample application. These are 109f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * NOT part of the core JPEG library. But we keep these routines separate 119f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * from jpegtran.c to ease the task of maintaining jpegtran-like programs 129f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * that have other user interfaces. 139f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * 149f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * NOTE: all the routines declared here have very specific requirements 159f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * about when they are to be executed during the reading and writing of the 169f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * source and destination files. See the comments in transupp.c, or see 179f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * jpegtran.c for an example of correct usage. 189f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project */ 199f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 209f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project/* If you happen not to want the image transform support, disable it here */ 219f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project#ifndef TRANSFORMS_SUPPORTED 229f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project#define TRANSFORMS_SUPPORTED 1 /* 0 disables transform code */ 239f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project#endif 249f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 259f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project/* Short forms of external names for systems with brain-damaged linkers. */ 269f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 279f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project#ifdef NEED_SHORT_EXTERNAL_NAMES 289f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project#define jtransform_request_workspace jTrRequest 299f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project#define jtransform_adjust_parameters jTrAdjust 309f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project#define jtransform_execute_transformation jTrExec 319f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project#define jcopy_markers_setup jCMrkSetup 329f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project#define jcopy_markers_execute jCMrkExec 339f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project#endif /* NEED_SHORT_EXTERNAL_NAMES */ 349f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 359f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 369f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project/* 379f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * Codes for supported types of image transformations. 389f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project */ 399f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 409f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Projecttypedef enum { 419f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project JXFORM_NONE, /* no transformation */ 429f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project JXFORM_FLIP_H, /* horizontal flip */ 439f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project JXFORM_FLIP_V, /* vertical flip */ 449f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project JXFORM_TRANSPOSE, /* transpose across UL-to-LR axis */ 459f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project JXFORM_TRANSVERSE, /* transpose across UR-to-LL axis */ 469f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project JXFORM_ROT_90, /* 90-degree clockwise rotation */ 479f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project JXFORM_ROT_180, /* 180-degree rotation */ 489f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project JXFORM_ROT_270 /* 270-degree clockwise (or 90 ccw) */ 499f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project} JXFORM_CODE; 509f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 519f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project/* 529f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * Although rotating and flipping data expressed as DCT coefficients is not 539f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * hard, there is an asymmetry in the JPEG format specification for images 549f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * whose dimensions aren't multiples of the iMCU size. The right and bottom 559f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * image edges are padded out to the next iMCU boundary with junk data; but 569f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * no padding is possible at the top and left edges. If we were to flip 579f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * the whole image including the pad data, then pad garbage would become 589f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * visible at the top and/or left, and real pixels would disappear into the 599f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * pad margins --- perhaps permanently, since encoders & decoders may not 609f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * bother to preserve DCT blocks that appear to be completely outside the 619f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * nominal image area. So, we have to exclude any partial iMCUs from the 629f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * basic transformation. 639f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * 649f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * Transpose is the only transformation that can handle partial iMCUs at the 659f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * right and bottom edges completely cleanly. flip_h can flip partial iMCUs 669f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * at the bottom, but leaves any partial iMCUs at the right edge untouched. 679f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * Similarly flip_v leaves any partial iMCUs at the bottom edge untouched. 689f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * The other transforms are defined as combinations of these basic transforms 699f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * and process edge blocks in a way that preserves the equivalence. 709f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * 719f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * The "trim" option causes untransformable partial iMCUs to be dropped; 729f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * this is not strictly lossless, but it usually gives the best-looking 739f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * result for odd-size images. Note that when this option is active, 749f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * the expected mathematical equivalences between the transforms may not hold. 759f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * (For example, -rot 270 -trim trims only the bottom edge, but -rot 90 -trim 769f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * followed by -rot 180 -trim trims both edges.) 779f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * 789f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * We also offer a "force to grayscale" option, which simply discards the 799f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * chrominance channels of a YCbCr image. This is lossless in the sense that 809f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * the luminance channel is preserved exactly. It's not the same kind of 819f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * thing as the rotate/flip transformations, but it's convenient to handle it 829f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * as part of this package, mainly because the transformation routines have to 839f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * be aware of the option to know how many components to work on. 849f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project */ 859f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 869f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Projecttypedef struct { 879f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project /* Options: set by caller */ 889f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project JXFORM_CODE transform; /* image transform operator */ 899f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project boolean trim; /* if TRUE, trim partial MCUs as needed */ 909f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project boolean force_grayscale; /* if TRUE, convert color image to grayscale */ 919f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 929f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project /* Internal workspace: caller should not touch these */ 939f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project int num_components; /* # of components in workspace */ 949f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project jvirt_barray_ptr * workspace_coef_arrays; /* workspace for transformations */ 959f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project} jpeg_transform_info; 969f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 979f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 989f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project#if TRANSFORMS_SUPPORTED 999f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 1009f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project/* Request any required workspace */ 1019f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source ProjectEXTERN(void) jtransform_request_workspace 1029f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project JPP((j_decompress_ptr srcinfo, jpeg_transform_info *info)); 1039f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project/* Adjust output image parameters */ 1049f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source ProjectEXTERN(jvirt_barray_ptr *) jtransform_adjust_parameters 1059f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project JPP((j_decompress_ptr srcinfo, j_compress_ptr dstinfo, 1069f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project jvirt_barray_ptr *src_coef_arrays, 1079f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project jpeg_transform_info *info)); 1089f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project/* Execute the actual transformation, if any */ 1099f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source ProjectEXTERN(void) jtransform_execute_transformation 1109f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project JPP((j_decompress_ptr srcinfo, j_compress_ptr dstinfo, 1119f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project jvirt_barray_ptr *src_coef_arrays, 1129f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project jpeg_transform_info *info)); 1139f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 1149f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project#endif /* TRANSFORMS_SUPPORTED */ 1159f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 1169f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 1179f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project/* 1189f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * Support for copying optional markers from source to destination file. 1199f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project */ 1209f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 1219f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Projecttypedef enum { 1229f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project JCOPYOPT_NONE, /* copy no optional markers */ 1239f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project JCOPYOPT_COMMENTS, /* copy only comment (COM) markers */ 1249f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project JCOPYOPT_ALL /* copy all optional markers */ 1259f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project} JCOPY_OPTION; 1269f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 1279f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project#define JCOPYOPT_DEFAULT JCOPYOPT_COMMENTS /* recommended default */ 1289f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 1299f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project/* Setup decompression object to save desired markers in memory */ 1309f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source ProjectEXTERN(void) jcopy_markers_setup 1319f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project JPP((j_decompress_ptr srcinfo, JCOPY_OPTION option)); 1329f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project/* Copy markers saved in the given source object to the destination object */ 1339f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source ProjectEXTERN(void) jcopy_markers_execute 1349f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project JPP((j_decompress_ptr srcinfo, j_compress_ptr dstinfo, 1359f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project JCOPY_OPTION option)); 136