transupp.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /*
  2. * transupp.h
  3. *
  4. * Copyright (C) 1997, Thomas G. Lane.
  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. /* Short forms of external names for systems with brain-damaged linkers. */
  24. #ifdef NEED_SHORT_EXTERNAL_NAMES
  25. #define jtransform_request_workspace jTrRequest
  26. #define jtransform_adjust_parameters jTrAdjust
  27. #define jtransform_execute_transformation jTrExec
  28. #define jcopy_markers_setup jCMrkSetup
  29. #define jcopy_markers_execute jCMrkExec
  30. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  31. /*
  32. * Codes for supported types of image transformations.
  33. */
  34. typedef enum {
  35. JXFORM_NONE, /* no transformation */
  36. JXFORM_FLIP_H, /* horizontal flip */
  37. JXFORM_FLIP_V, /* vertical flip */
  38. JXFORM_TRANSPOSE, /* transpose across UL-to-LR axis */
  39. JXFORM_TRANSVERSE, /* transpose across UR-to-LL axis */
  40. JXFORM_ROT_90, /* 90-degree clockwise rotation */
  41. JXFORM_ROT_180, /* 180-degree rotation */
  42. JXFORM_ROT_270 /* 270-degree clockwise (or 90 ccw) */
  43. } JXFORM_CODE;
  44. /*
  45. * Although rotating and flipping data expressed as DCT coefficients is not
  46. * hard, there is an asymmetry in the JPEG format specification for images
  47. * whose dimensions aren't multiples of the iMCU size. The right and bottom
  48. * image edges are padded out to the next iMCU boundary with junk data; but
  49. * no padding is possible at the top and left edges. If we were to flip
  50. * the whole image including the pad data, then pad garbage would become
  51. * visible at the top and/or left, and real pixels would disappear into the
  52. * pad margins --- perhaps permanently, since encoders & decoders may not
  53. * bother to preserve DCT blocks that appear to be completely outside the
  54. * nominal image area. So, we have to exclude any partial iMCUs from the
  55. * basic transformation.
  56. *
  57. * Transpose is the only transformation that can handle partial iMCUs at the
  58. * right and bottom edges completely cleanly. flip_h can flip partial iMCUs
  59. * at the bottom, but leaves any partial iMCUs at the right edge untouched.
  60. * Similarly flip_v leaves any partial iMCUs at the bottom edge untouched.
  61. * The other transforms are defined as combinations of these basic transforms
  62. * and process edge blocks in a way that preserves the equivalence.
  63. *
  64. * The "trim" option causes untransformable partial iMCUs to be dropped;
  65. * this is not strictly lossless, but it usually gives the best-looking
  66. * result for odd-size images. Note that when this option is active,
  67. * the expected mathematical equivalences between the transforms may not hold.
  68. * (For example, -rot 270 -trim trims only the bottom edge, but -rot 90 -trim
  69. * followed by -rot 180 -trim trims both edges.)
  70. *
  71. * We also offer a "force to grayscale" option, which simply discards the
  72. * chrominance channels of a YCbCr image. This is lossless in the sense that
  73. * the luminance channel is preserved exactly. It's not the same kind of
  74. * thing as the rotate/flip transformations, but it's convenient to handle it
  75. * as part of this package, mainly because the transformation routines have to
  76. * be aware of the option to know how many components to work on.
  77. */
  78. typedef struct {
  79. /* Options: set by caller */
  80. JXFORM_CODE transform; /* image transform operator */
  81. boolean trim; /* if TRUE, trim partial MCUs as needed */
  82. boolean force_grayscale; /* if TRUE, convert color image to grayscale */
  83. /* Internal workspace: caller should not touch these */
  84. int num_components; /* # of components in workspace */
  85. jvirt_barray_ptr * workspace_coef_arrays; /* workspace for transformations */
  86. } jpeg_transform_info;
  87. #if TRANSFORMS_SUPPORTED
  88. /* Request any required workspace */
  89. EXTERN(void) jtransform_request_workspace
  90. JPP((j_decompress_ptr srcinfo, jpeg_transform_info *info));
  91. /* Adjust output image parameters */
  92. EXTERN(jvirt_barray_ptr *) jtransform_adjust_parameters
  93. JPP((j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  94. jvirt_barray_ptr *src_coef_arrays,
  95. jpeg_transform_info *info));
  96. /* Execute the actual transformation, if any */
  97. EXTERN(void) jtransform_execute_transformation
  98. JPP((j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  99. jvirt_barray_ptr *src_coef_arrays,
  100. jpeg_transform_info *info));
  101. #endif /* TRANSFORMS_SUPPORTED */
  102. /*
  103. * Support for copying optional markers from source to destination file.
  104. */
  105. typedef enum {
  106. JCOPYOPT_NONE, /* copy no optional markers */
  107. JCOPYOPT_COMMENTS, /* copy only comment (COM) markers */
  108. JCOPYOPT_ALL /* copy all optional markers */
  109. } JCOPY_OPTION;
  110. #define JCOPYOPT_DEFAULT JCOPYOPT_COMMENTS /* recommended default */
  111. /* Setup decompression object to save desired markers in memory */
  112. EXTERN(void) jcopy_markers_setup
  113. JPP((j_decompress_ptr srcinfo, JCOPY_OPTION option));
  114. /* Copy markers saved in the given source object to the destination object */
  115. EXTERN(void) jcopy_markers_execute
  116. JPP((j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  117. JCOPY_OPTION option));