41c4b45ed73de8da4fb7445d3f35bd1e647db402
[platform/upstream/libjpeg-turbo.git] / java / org / libjpegturbo / turbojpeg / TJTransform.java
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
29 package org.libjpegturbo.turbojpeg;
30
31 import java.awt.*;
32
33 /**
34  * Lossless transform parameters
35  */
36 public class TJTransform extends Rectangle {
37
38   private static final long serialVersionUID = -127367705761430371L;
39
40   /**
41    * The number of lossless transform operations
42    */
43   public static final int NUMOP         = 8;
44   /**
45    * Do not transform the position of the image pixels.
46    */
47   public static final int OP_NONE       = 0;
48   /**
49    * Flip (mirror) image horizontally.  This transform is imperfect if there
50    * are any partial MCU blocks on the right edge.
51    * @see #OPT_PERFECT
52    */
53   public static final int OP_HFLIP      = 1;
54   /**
55    * Flip (mirror) image vertically.  This transform is imperfect if there are
56    * any partial MCU blocks on the bottom edge.
57    * @see #OPT_PERFECT
58    */
59   public static final int OP_VFLIP      = 2;
60   /**
61    * Transpose image (flip/mirror along upper left to lower right axis).  This
62    * transform is always perfect.
63    * @see #OPT_PERFECT
64    */
65   public static final int OP_TRANSPOSE  = 3;
66   /**
67    * Transverse transpose image (flip/mirror along upper right to lower left
68    * axis).  This transform is imperfect if there are any partial MCU blocks in
69    * the image.
70    * @see #OPT_PERFECT
71    */
72   public static final int OP_TRANSVERSE = 4;
73   /**
74    * Rotate image clockwise by 90 degrees.  This transform is imperfect if
75    * there are any partial MCU blocks on the bottom edge.
76    * @see #OPT_PERFECT
77    */
78   public static final int OP_ROT90      = 5;
79   /**
80    * Rotate image 180 degrees.  This transform is imperfect if there are any
81    * partial MCU blocks in the image.
82    * @see #OPT_PERFECT
83    */
84   public static final int OP_ROT180     = 6;
85   /**
86    * Rotate image counter-clockwise by 90 degrees.  This transform is imperfect
87    * if there are any partial MCU blocks on the right edge.
88    * @see #OPT_PERFECT
89    */
90   public static final int OP_ROT270     = 7;
91
92
93   /**
94    * This option will cause {@link TJTransformer#transform
95    * TJTransformer.transform()} to throw an exception if the transform is not
96    * perfect.  Lossless transforms operate on MCU blocks, whose size depends on
97    * the level of chrominance subsampling used.  If the image's width or height
98    * is not evenly divisible by the MCU block size (see {@link TJ#getMCUWidth}
99    * and {@link TJ#getMCUHeight}), then there will be partial MCU blocks on the
100    * right and/or bottom edges.   It is not possible to move these partial MCU
101    * blocks to the top or left of the image, so any transform that would
102    * require that is "imperfect."  If this option is not specified, then any
103    * partial MCU blocks that cannot be transformed will be left in place, which
104    * will create odd-looking strips on the right or bottom edge of the image.
105    */
106   public static final int OPT_PERFECT     = 1;
107   /**
108    * This option will discard any partial MCU blocks that cannot be
109    * transformed.
110    */
111   public static final int OPT_TRIM        = 2;
112   /**
113    * This option will enable lossless cropping.
114    */
115   public static final int OPT_CROP        = 4;
116   /**
117    * This option will discard the color data in the input image and produce
118    * a grayscale output image.
119    */
120   public static final int OPT_GRAY        = 8;
121   /**
122    * This option will prevent {@link TJTransformer#transform
123    * TJTransformer.transform()} from outputting a JPEG image for this
124    * particular transform.  This can be used in conjunction with a custom
125    * filter to capture the transformed DCT coefficients without transcoding
126    * them.
127    */
128   public static final int OPT_NOOUTPUT    = 16;
129   /**
130    * This option will enable progressive entropy coding in the output image
131    * generated by this particular transform.  Progressive entropy coding will
132    * generally improve compression relative to baseline entropy coding (the
133    * default), but it will reduce compression and decompression performance
134    * considerably.
135    */
136   public static final int OPT_PROGRESSIVE = 32;
137   /**
138    * This option will prevent {@link TJTransformer#transform
139    * TJTransformer.transform()} from copying any extra markers (including EXIF
140    * and ICC profile data) from the source image to the output image.
141    */
142   public static final int OPT_COPYNONE    = 64;
143
144
145   /**
146    * Create a new lossless transform instance.
147    */
148   public TJTransform() {
149   }
150
151   /**
152    * Create a new lossless transform instance with the given parameters.
153    *
154    * @param x the left boundary of the cropping region.  This must be evenly
155    * divisible by the MCU block width (see {@link TJ#getMCUWidth})
156    *
157    * @param y the upper boundary of the cropping region.  This must be evenly
158    * divisible by the MCU block height (see {@link TJ#getMCUHeight})
159    *
160    * @param w the width of the cropping region.  Setting this to 0 is the
161    * equivalent of setting it to (width of the source JPEG image -
162    * <code>x</code>).
163    *
164    * @param h the height of the cropping region.  Setting this to 0 is the
165    * equivalent of setting it to (height of the source JPEG image -
166    * <code>y</code>).
167    *
168    * @param op one of the transform operations (<code>OP_*</code>)
169    *
170    * @param options the bitwise OR of one or more of the transform options
171    * (<code>OPT_*</code>)
172    *
173    * @param cf an instance of an object that implements the {@link
174    * TJCustomFilter} interface, or null if no custom filter is needed
175    */
176   @SuppressWarnings("checkstyle:HiddenField")
177   public TJTransform(int x, int y, int w, int h, int op, int options,
178                      TJCustomFilter cf) {
179     super(x, y, w, h);
180     this.op = op;
181     this.options = options;
182     this.cf = cf;
183   }
184
185   /**
186    * Create a new lossless transform instance with the given parameters.
187    *
188    * @param r a <code>Rectangle</code> instance that specifies the cropping
189    * region.  See {@link
190    * #TJTransform(int, int, int, int, int, int, TJCustomFilter)} for more
191    * detail.
192    *
193    * @param op one of the transform operations (<code>OP_*</code>)
194    *
195    * @param options the bitwise OR of one or more of the transform options
196    * (<code>OPT_*</code>)
197    *
198    * @param cf an instance of an object that implements the {@link
199    * TJCustomFilter} interface, or null if no custom filter is needed
200    */
201   @SuppressWarnings("checkstyle:HiddenField")
202   public TJTransform(Rectangle r, int op, int options,
203                      TJCustomFilter cf) {
204     super(r);
205     this.op = op;
206     this.options = options;
207     this.cf = cf;
208   }
209
210   /**
211    * Transform operation (one of <code>OP_*</code>)
212    */
213   @SuppressWarnings("checkstyle:VisibilityModifier")
214   public int op = 0;
215
216   /**
217    * Transform options (bitwise OR of one or more of <code>OPT_*</code>)
218    */
219   @SuppressWarnings("checkstyle:VisibilityModifier")
220   public int options = 0;
221
222   /**
223    * Custom filter instance
224    */
225   @SuppressWarnings("checkstyle:VisibilityModifier")
226   public TJCustomFilter cf = null;
227 }