Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

210 lines
8.9 KiB

  1. /*
  2. * transupp.h
  3. *
  4. * Copyright (C) 1997-2009, Thomas G. Lane, Guido Vollbeding.
  5. * This file is part of the Independent JPEG Group's software.
  6. * For conditions of distribution and use, see the accompanying README file.
  7. *
  8. * This file contains declarations for image transformation routines and
  9. * other utility code used by the jpegtran sample application. These are
  10. * NOT part of the core JPEG library. But we keep these routines separate
  11. * from jpegtran.c to ease the task of maintaining jpegtran-like programs
  12. * that have other user interfaces.
  13. *
  14. * NOTE: all the routines declared here have very specific requirements
  15. * about when they are to be executed during the reading and writing of the
  16. * source and destination files. See the comments in transupp.c, or see
  17. * jpegtran.c for an example of correct usage.
  18. */
  19. /* If you happen not to want the image transform support, disable it here */
  20. #ifndef TRANSFORMS_SUPPORTED
  21. #define TRANSFORMS_SUPPORTED 1 /* 0 disables transform code */
  22. #endif
  23. /*
  24. * Although rotating and flipping data expressed as DCT coefficients is not
  25. * hard, there is an asymmetry in the JPEG format specification for images
  26. * whose dimensions aren't multiples of the iMCU size. The right and bottom
  27. * image edges are padded out to the next iMCU boundary with junk data; but
  28. * no padding is possible at the top and left edges. If we were to flip
  29. * the whole image including the pad data, then pad garbage would become
  30. * visible at the top and/or left, and real pixels would disappear into the
  31. * pad margins --- perhaps permanently, since encoders & decoders may not
  32. * bother to preserve DCT blocks that appear to be completely outside the
  33. * nominal image area. So, we have to exclude any partial iMCUs from the
  34. * basic transformation.
  35. *
  36. * Transpose is the only transformation that can handle partial iMCUs at the
  37. * right and bottom edges completely cleanly. flip_h can flip partial iMCUs
  38. * at the bottom, but leaves any partial iMCUs at the right edge untouched.
  39. * Similarly flip_v leaves any partial iMCUs at the bottom edge untouched.
  40. * The other transforms are defined as combinations of these basic transforms
  41. * and process edge blocks in a way that preserves the equivalence.
  42. *
  43. * The "trim" option causes untransformable partial iMCUs to be dropped;
  44. * this is not strictly lossless, but it usually gives the best-looking
  45. * result for odd-size images. Note that when this option is active,
  46. * the expected mathematical equivalences between the transforms may not hold.
  47. * (For example, -rot 270 -trim trims only the bottom edge, but -rot 90 -trim
  48. * followed by -rot 180 -trim trims both edges.)
  49. *
  50. * We also offer a lossless-crop option, which discards data outside a given
  51. * image region but losslessly preserves what is inside. Like the rotate and
  52. * flip transforms, lossless crop is restricted by the JPEG format: the upper
  53. * left corner of the selected region must fall on an iMCU boundary. If this
  54. * does not hold for the given crop parameters, we silently move the upper left
  55. * corner up and/or left to make it so, simultaneously increasing the region
  56. * dimensions to keep the lower right crop corner unchanged. (Thus, the
  57. * output image covers at least the requested region, but may cover more.)
  58. *
  59. * We also provide a lossless-resize option, which is kind of a lossless-crop
  60. * operation in the DCT coefficient block domain - it discards higher-order
  61. * coefficients and losslessly preserves lower-order coefficients of a
  62. * sub-block.
  63. *
  64. * Rotate/flip transform, resize, and crop can be requested together in a
  65. * single invocation. The crop is applied last --- that is, the crop region
  66. * is specified in terms of the destination image after transform/resize.
  67. *
  68. * We also offer a "force to grayscale" option, which simply discards the
  69. * chrominance channels of a YCbCr image. This is lossless in the sense that
  70. * the luminance channel is preserved exactly. It's not the same kind of
  71. * thing as the rotate/flip transformations, but it's convenient to handle it
  72. * as part of this package, mainly because the transformation routines have to
  73. * be aware of the option to know how many components to work on.
  74. */
  75. /* Short forms of external names for systems with brain-damaged linkers. */
  76. #ifdef NEED_SHORT_EXTERNAL_NAMES
  77. #define jtransform_parse_crop_spec jTrParCrop
  78. #define jtransform_request_workspace jTrRequest
  79. #define jtransform_adjust_parameters jTrAdjust
  80. #define jtransform_execute_transform jTrExec
  81. #define jtransform_perfect_transform jTrPerfect
  82. #define jcopy_markers_setup jCMrkSetup
  83. #define jcopy_markers_execute jCMrkExec
  84. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  85. /*
  86. * Codes for supported types of image transformations.
  87. */
  88. typedef enum {
  89. JXFORM_NONE, /* no transformation */
  90. JXFORM_FLIP_H, /* horizontal flip */
  91. JXFORM_FLIP_V, /* vertical flip */
  92. JXFORM_TRANSPOSE, /* transpose across UL-to-LR axis */
  93. JXFORM_TRANSVERSE, /* transpose across UR-to-LL axis */
  94. JXFORM_ROT_90, /* 90-degree clockwise rotation */
  95. JXFORM_ROT_180, /* 180-degree rotation */
  96. JXFORM_ROT_270 /* 270-degree clockwise (or 90 ccw) */
  97. } JXFORM_CODE;
  98. /*
  99. * Codes for crop parameters, which can individually be unspecified,
  100. * positive, or negative. (Negative width or height makes no sense, though.)
  101. */
  102. typedef enum {
  103. JCROP_UNSET,
  104. JCROP_POS,
  105. JCROP_NEG
  106. } JCROP_CODE;
  107. /*
  108. * Transform parameters struct.
  109. * NB: application must not change any elements of this struct after
  110. * calling jtransform_request_workspace.
  111. */
  112. typedef struct {
  113. /* Options: set by caller */
  114. JXFORM_CODE transform; /* image transform operator */
  115. boolean perfect; /* if TRUE, fail if partial MCUs are requested */
  116. boolean trim; /* if TRUE, trim partial MCUs as needed */
  117. boolean force_grayscale; /* if TRUE, convert color image to grayscale */
  118. boolean crop; /* if TRUE, crop source image */
  119. /* Crop parameters: application need not set these unless crop is TRUE.
  120. * These can be filled in by jtransform_parse_crop_spec().
  121. */
  122. JDIMENSION crop_width; /* Width of selected region */
  123. JCROP_CODE crop_width_set;
  124. JDIMENSION crop_height; /* Height of selected region */
  125. JCROP_CODE crop_height_set;
  126. JDIMENSION crop_xoffset; /* X offset of selected region */
  127. JCROP_CODE crop_xoffset_set; /* (negative measures from right edge) */
  128. JDIMENSION crop_yoffset; /* Y offset of selected region */
  129. JCROP_CODE crop_yoffset_set; /* (negative measures from bottom edge) */
  130. /* Internal workspace: caller should not touch these */
  131. int num_components; /* # of components in workspace */
  132. jvirt_barray_ptr * workspace_coef_arrays; /* workspace for transformations */
  133. JDIMENSION output_width; /* cropped destination dimensions */
  134. JDIMENSION output_height;
  135. JDIMENSION x_crop_offset; /* destination crop offsets measured in iMCUs */
  136. JDIMENSION y_crop_offset;
  137. int iMCU_sample_width; /* destination iMCU size */
  138. int iMCU_sample_height;
  139. } jpeg_transform_info;
  140. #if TRANSFORMS_SUPPORTED
  141. /* Parse a crop specification (written in X11 geometry style) */
  142. EXTERN(boolean) jtransform_parse_crop_spec
  143. JPP((jpeg_transform_info *info, const char *spec));
  144. /* Request any required workspace */
  145. EXTERN(boolean) jtransform_request_workspace
  146. JPP((j_decompress_ptr srcinfo, jpeg_transform_info *info));
  147. /* Adjust output image parameters */
  148. EXTERN(jvirt_barray_ptr *) jtransform_adjust_parameters
  149. JPP((j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  150. jvirt_barray_ptr *src_coef_arrays,
  151. jpeg_transform_info *info));
  152. /* Execute the actual transformation, if any */
  153. EXTERN(void) jtransform_execute_transform
  154. JPP((j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  155. jvirt_barray_ptr *src_coef_arrays,
  156. jpeg_transform_info *info));
  157. /* Determine whether lossless transformation is perfectly
  158. * possible for a specified image and transformation.
  159. */
  160. EXTERN(boolean) jtransform_perfect_transform
  161. JPP((JDIMENSION image_width, JDIMENSION image_height,
  162. int MCU_width, int MCU_height,
  163. JXFORM_CODE transform));
  164. /* jtransform_execute_transform used to be called
  165. * jtransform_execute_transformation, but some compilers complain about
  166. * routine names that long. This macro is here to avoid breaking any
  167. * old source code that uses the original name...
  168. */
  169. #define jtransform_execute_transformation jtransform_execute_transform
  170. #endif /* TRANSFORMS_SUPPORTED */
  171. /*
  172. * Support for copying optional markers from source to destination file.
  173. */
  174. typedef enum {
  175. JCOPYOPT_NONE, /* copy no optional markers */
  176. JCOPYOPT_COMMENTS, /* copy only comment (COM) markers */
  177. JCOPYOPT_ALL /* copy all optional markers */
  178. } JCOPY_OPTION;
  179. #define JCOPYOPT_DEFAULT JCOPYOPT_COMMENTS /* recommended default */
  180. /* Setup decompression object to save desired markers in memory */
  181. EXTERN(void) jcopy_markers_setup
  182. JPP((j_decompress_ptr srcinfo, JCOPY_OPTION option));
  183. /* Copy markers saved in the given source object to the destination object */
  184. EXTERN(void) jcopy_markers_execute
  185. JPP((j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  186. JCOPY_OPTION option));