TJTransform.java 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. /*
  2. * Copyright (C)2011, 2013, 2018 D. R. Commander. All Rights Reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions are met:
  6. *
  7. * - Redistributions of source code must retain the above copyright notice,
  8. * this list of conditions and the following disclaimer.
  9. * - Redistributions in binary form must reproduce the above copyright notice,
  10. * this list of conditions and the following disclaimer in the documentation
  11. * and/or other materials provided with the distribution.
  12. * - Neither the name of the libjpeg-turbo Project nor the names of its
  13. * contributors may be used to endorse or promote products derived from this
  14. * software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS",
  17. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  18. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  19. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
  20. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  21. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  22. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  23. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  24. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  25. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  26. * POSSIBILITY OF SUCH DAMAGE.
  27. */
  28. package org.libjpegturbo.turbojpeg;
  29. import java.awt.*;
  30. /**
  31. * Lossless transform parameters
  32. */
  33. public class TJTransform extends Rectangle {
  34. private static final long serialVersionUID = -127367705761430371L;
  35. /**
  36. * The number of lossless transform operations
  37. */
  38. public static final int NUMOP = 8;
  39. /**
  40. * Do not transform the position of the image pixels.
  41. */
  42. public static final int OP_NONE = 0;
  43. /**
  44. * Flip (mirror) image horizontally. This transform is imperfect if there
  45. * are any partial MCU blocks on the right edge.
  46. * @see #OPT_PERFECT
  47. */
  48. public static final int OP_HFLIP = 1;
  49. /**
  50. * Flip (mirror) image vertically. This transform is imperfect if there are
  51. * any partial MCU blocks on the bottom edge.
  52. * @see #OPT_PERFECT
  53. */
  54. public static final int OP_VFLIP = 2;
  55. /**
  56. * Transpose image (flip/mirror along upper left to lower right axis). This
  57. * transform is always perfect.
  58. * @see #OPT_PERFECT
  59. */
  60. public static final int OP_TRANSPOSE = 3;
  61. /**
  62. * Transverse transpose image (flip/mirror along upper right to lower left
  63. * axis). This transform is imperfect if there are any partial MCU blocks in
  64. * the image.
  65. * @see #OPT_PERFECT
  66. */
  67. public static final int OP_TRANSVERSE = 4;
  68. /**
  69. * Rotate image clockwise by 90 degrees. This transform is imperfect if
  70. * there are any partial MCU blocks on the bottom edge.
  71. * @see #OPT_PERFECT
  72. */
  73. public static final int OP_ROT90 = 5;
  74. /**
  75. * Rotate image 180 degrees. This transform is imperfect if there are any
  76. * partial MCU blocks in the image.
  77. * @see #OPT_PERFECT
  78. */
  79. public static final int OP_ROT180 = 6;
  80. /**
  81. * Rotate image counter-clockwise by 90 degrees. This transform is imperfect
  82. * if there are any partial MCU blocks on the right edge.
  83. * @see #OPT_PERFECT
  84. */
  85. public static final int OP_ROT270 = 7;
  86. /**
  87. * This option will cause {@link TJTransformer#transform
  88. * TJTransformer.transform()} to throw an exception if the transform is not
  89. * perfect. Lossless transforms operate on MCU blocks, whose size depends on
  90. * the level of chrominance subsampling used. If the image's width or height
  91. * is not evenly divisible by the MCU block size (see {@link TJ#getMCUWidth}
  92. * and {@link TJ#getMCUHeight}), then there will be partial MCU blocks on the
  93. * right and/or bottom edges. It is not possible to move these partial MCU
  94. * blocks to the top or left of the image, so any transform that would
  95. * require that is "imperfect." If this option is not specified, then any
  96. * partial MCU blocks that cannot be transformed will be left in place, which
  97. * will create odd-looking strips on the right or bottom edge of the image.
  98. */
  99. public static final int OPT_PERFECT = 1;
  100. /**
  101. * This option will discard any partial MCU blocks that cannot be
  102. * transformed.
  103. */
  104. public static final int OPT_TRIM = 2;
  105. /**
  106. * This option will enable lossless cropping.
  107. */
  108. public static final int OPT_CROP = 4;
  109. /**
  110. * This option will discard the color data in the input image and produce
  111. * a grayscale output image.
  112. */
  113. public static final int OPT_GRAY = 8;
  114. /**
  115. * This option will prevent {@link TJTransformer#transform
  116. * TJTransformer.transform()} from outputting a JPEG image for this
  117. * particular transform. This can be used in conjunction with a custom
  118. * filter to capture the transformed DCT coefficients without transcoding
  119. * them.
  120. */
  121. public static final int OPT_NOOUTPUT = 16;
  122. /**
  123. * This option will enable progressive entropy coding in the output image
  124. * generated by this particular transform. Progressive entropy coding will
  125. * generally improve compression relative to baseline entropy coding (the
  126. * default), but it will reduce compression and decompression performance
  127. * considerably.
  128. */
  129. public static final int OPT_PROGRESSIVE = 32;
  130. /**
  131. * This option will prevent {@link TJTransformer#transform
  132. * TJTransformer.transform()} from copying any extra markers (including EXIF
  133. * and ICC profile data) from the source image to the output image.
  134. */
  135. public static final int OPT_COPYNONE = 64;
  136. /**
  137. * Create a new lossless transform instance.
  138. */
  139. public TJTransform() {
  140. }
  141. /**
  142. * Create a new lossless transform instance with the given parameters.
  143. *
  144. * @param x the left boundary of the cropping region. This must be evenly
  145. * divisible by the MCU block width (see {@link TJ#getMCUWidth})
  146. *
  147. * @param y the upper boundary of the cropping region. This must be evenly
  148. * divisible by the MCU block height (see {@link TJ#getMCUHeight})
  149. *
  150. * @param w the width of the cropping region. Setting this to 0 is the
  151. * equivalent of setting it to (width of the source JPEG image -
  152. * <code>x</code>).
  153. *
  154. * @param h the height of the cropping region. Setting this to 0 is the
  155. * equivalent of setting it to (height of the source JPEG image -
  156. * <code>y</code>).
  157. *
  158. * @param op one of the transform operations (<code>OP_*</code>)
  159. *
  160. * @param options the bitwise OR of one or more of the transform options
  161. * (<code>OPT_*</code>)
  162. *
  163. * @param cf an instance of an object that implements the {@link
  164. * TJCustomFilter} interface, or null if no custom filter is needed
  165. */
  166. @SuppressWarnings("checkstyle:HiddenField")
  167. public TJTransform(int x, int y, int w, int h, int op, int options,
  168. TJCustomFilter cf) {
  169. super(x, y, w, h);
  170. this.op = op;
  171. this.options = options;
  172. this.cf = cf;
  173. }
  174. /**
  175. * Create a new lossless transform instance with the given parameters.
  176. *
  177. * @param r a <code>Rectangle</code> instance that specifies the cropping
  178. * region. See {@link
  179. * #TJTransform(int, int, int, int, int, int, TJCustomFilter)} for more
  180. * detail.
  181. *
  182. * @param op one of the transform operations (<code>OP_*</code>)
  183. *
  184. * @param options the bitwise OR of one or more of the transform options
  185. * (<code>OPT_*</code>)
  186. *
  187. * @param cf an instance of an object that implements the {@link
  188. * TJCustomFilter} interface, or null if no custom filter is needed
  189. */
  190. @SuppressWarnings("checkstyle:HiddenField")
  191. public TJTransform(Rectangle r, int op, int options,
  192. TJCustomFilter cf) {
  193. super(r);
  194. this.op = op;
  195. this.options = options;
  196. this.cf = cf;
  197. }
  198. /**
  199. * Transform operation (one of <code>OP_*</code>)
  200. */
  201. @SuppressWarnings("checkstyle:VisibilityModifier")
  202. public int op = 0;
  203. /**
  204. * Transform options (bitwise OR of one or more of <code>OPT_*</code>)
  205. */
  206. @SuppressWarnings("checkstyle:VisibilityModifier")
  207. public int options = 0;
  208. /**
  209. * Custom filter instance
  210. */
  211. @SuppressWarnings("checkstyle:VisibilityModifier")
  212. public TJCustomFilter cf = null;
  213. }