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