TJTransform.java 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. /*
  2. * Copyright (C)2011, 2013 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. * Create a new lossless transform instance.
  124. */
  125. public TJTransform() {
  126. }
  127. /**
  128. * Create a new lossless transform instance with the given parameters.
  129. *
  130. * @param x the left boundary of the cropping region. This must be evenly
  131. * divisible by the MCU block width (see {@link TJ#getMCUWidth})
  132. *
  133. * @param y the upper boundary of the cropping region. This must be evenly
  134. * divisible by the MCU block height (see {@link TJ#getMCUHeight})
  135. *
  136. * @param w the width of the cropping region. Setting this to 0 is the
  137. * equivalent of setting it to (width of the source JPEG image -
  138. * <code>x</code>).
  139. *
  140. * @param h the height of the cropping region. Setting this to 0 is the
  141. * equivalent of setting it to (height of the source JPEG image -
  142. * <code>y</code>).
  143. *
  144. * @param op one of the transform operations (<code>OP_*</code>)
  145. *
  146. * @param options the bitwise OR of one or more of the transform options
  147. * (<code>OPT_*</code>)
  148. *
  149. * @param cf an instance of an object that implements the {@link
  150. * TJCustomFilter} interface, or null if no custom filter is needed
  151. */
  152. public TJTransform(int x, int y, int w, int h, int op, int options,
  153. TJCustomFilter cf) {
  154. super(x, y, w, h);
  155. this.op = op;
  156. this.options = options;
  157. this.cf = cf;
  158. }
  159. /**
  160. * Create a new lossless transform instance with the given parameters.
  161. *
  162. * @param r a <code>Rectangle</code> instance that specifies the cropping
  163. * region. See {@link
  164. * #TJTransform(int, int, int, int, int, int, TJCustomFilter)} for more
  165. * detail.
  166. *
  167. * @param op one of the transform operations (<code>OP_*</code>)
  168. *
  169. * @param options the bitwise OR of one or more of the transform options
  170. * (<code>OPT_*</code>)
  171. *
  172. * @param cf an instance of an object that implements the {@link
  173. * TJCustomFilter} interface, or null if no custom filter is needed
  174. */
  175. public TJTransform(Rectangle r, int op, int options,
  176. TJCustomFilter cf) {
  177. super(r);
  178. this.op = op;
  179. this.options = options;
  180. this.cf = cf;
  181. }
  182. /**
  183. * Transform operation (one of <code>OP_*</code>)
  184. */
  185. public int op = 0;
  186. /**
  187. * Transform options (bitwise OR of one or more of <code>OPT_*</code>)
  188. */
  189. public int options = 0;
  190. /**
  191. * Custom filter instance
  192. */
  193. public TJCustomFilter cf = null;
  194. }