File indexing completed on 2024-05-12 04:19:44

0001 /*
0002  * transupp.h
0003  *
0004  * Copyright (C) 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 #ifndef TRANSUPP_H
0021 #define TRANSUPP_H
0022 
0023 /* If you happen not to want the image transform support, disable it here */
0024 #ifndef TRANSFORMS_SUPPORTED
0025 #define TRANSFORMS_SUPPORTED 1      /* 0 disables transform code */
0026 #endif
0027 
0028 /* Short forms of external names for systems with brain-damaged linkers. */
0029 
0030 #ifdef NEED_SHORT_EXTERNAL_NAMES
0031 #define jtransform_request_workspace        jTrRequest
0032 #define jtransform_adjust_parameters        jTrAdjust
0033 #define jtransform_execute_transformation   jTrExec
0034 #define jcopy_markers_setup         jCMrkSetup
0035 #define jcopy_markers_execute           jCMrkExec
0036 #endif /* NEED_SHORT_EXTERNAL_NAMES */
0037 
0038 /*
0039  * Codes for supported types of image transformations.
0040  */
0041 
0042 typedef enum {
0043     JXFORM_NONE,        /* no transformation */
0044     JXFORM_FLIP_H,      /* horizontal flip */
0045     JXFORM_FLIP_V,      /* vertical flip */
0046     JXFORM_TRANSPOSE,   /* transpose across UL-to-LR axis */
0047     JXFORM_TRANSVERSE,  /* transpose across UR-to-LL axis */
0048     JXFORM_ROT_90,      /* 90-degree clockwise rotation */
0049     JXFORM_ROT_180,     /* 180-degree rotation */
0050     JXFORM_ROT_270      /* 270-degree clockwise (or 90 ccw) */
0051 } JXFORM_CODE;
0052 
0053 /*
0054  * Although rotating and flipping data expressed as DCT coefficients is not
0055  * hard, there is an asymmetry in the JPEG format specification for images
0056  * whose dimensions aren't multiples of the iMCU size.  The right and bottom
0057  * image edges are padded out to the next iMCU boundary with junk data; but
0058  * no padding is possible at the top and left edges.  If we were to flip
0059  * the whole image including the pad data, then pad garbage would become
0060  * visible at the top and/or left, and real pixels would disappear into the
0061  * pad margins --- perhaps permanently, since encoders & decoders may not
0062  * bother to preserve DCT blocks that appear to be completely outside the
0063  * nominal image area.  So, we have to exclude any partial iMCUs from the
0064  * basic transformation.
0065  *
0066  * Transpose is the only transformation that can handle partial iMCUs at the
0067  * right and bottom edges completely cleanly.  flip_h can flip partial iMCUs
0068  * at the bottom, but leaves any partial iMCUs at the right edge untouched.
0069  * Similarly flip_v leaves any partial iMCUs at the bottom edge untouched.
0070  * The other transforms are defined as combinations of these basic transforms
0071  * and process edge blocks in a way that preserves the equivalence.
0072  *
0073  * The "trim" option causes untransformable partial iMCUs to be dropped;
0074  * this is not strictly lossless, but it usually gives the best-looking
0075  * result for odd-size images.  Note that when this option is active,
0076  * the expected mathematical equivalences between the transforms may not hold.
0077  * (For example, -rot 270 -trim trims only the bottom edge, but -rot 90 -trim
0078  * followed by -rot 180 -trim trims both edges.)
0079  *
0080  * We also offer a "force to grayscale" option, which simply discards the
0081  * chrominance channels of a YCbCr image.  This is lossless in the sense that
0082  * the luminance channel is preserved exactly.  It's not the same kind of
0083  * thing as the rotate/flip transformations, but it's convenient to handle it
0084  * as part of this package, mainly because the transformation routines have to
0085  * be aware of the option to know how many components to work on.
0086  */
0087 
0088 typedef struct {
0089     /* Options: set by caller */
0090     JXFORM_CODE transform;    /* image transform operator */
0091     boolean trim;         /* if TRUE, trim partial MCUs as needed */
0092     boolean force_grayscale;  /* if TRUE, convert color image to grayscale */
0093 
0094     /* Internal workspace: caller should not touch these */
0095     int num_components;       /* # of components in workspace */
0096     jvirt_barray_ptr * workspace_coef_arrays; /* workspace for transformations */
0097 } jpeg_transform_info;
0098 
0099 #if TRANSFORMS_SUPPORTED
0100 
0101 /* Request any required workspace */
0102 EXTERN(void) jtransform_request_workspace
0103 JPP((j_decompress_ptr srcinfo, jpeg_transform_info *info));
0104 /* Adjust output image parameters */
0105 EXTERN(jvirt_barray_ptr *) jtransform_adjust_parameters
0106 JPP((j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
0107      jvirt_barray_ptr *src_coef_arrays,
0108      jpeg_transform_info *info));
0109 /* Execute the actual transformation, if any */
0110 EXTERN(void) jtransform_execute_transformation
0111 JPP((j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
0112      jvirt_barray_ptr *src_coef_arrays,
0113      jpeg_transform_info *info));
0114 
0115 #endif /* TRANSFORMS_SUPPORTED */
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));
0136 
0137 #endif
0138