update latest
[external/libjpeg-turbo.git] / java / org / libjpegturbo / turbojpeg / TJTransform.java
1 /*
2  * Copyright (C)2011 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   final public static int NUMOP         = 8;
44   /**
45    * Do not transform the position of the image pixels.
46    */
47   final public static 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   final public static 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   final public static 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   final public static 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   final public static 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   final public static 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   final public static 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   final public static 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   final public static int OPT_PERFECT  = 1;
107   /**
108    * This option will discard any partial MCU blocks that cannot be
109    * transformed.
110    */
111   final public static int OPT_TRIM     = 2;
112   /**
113    * This option will enable lossless cropping.
114    */
115   final public static 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   final public static 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   final public static int OPT_NOOUTPUT = 16;
129
130   
131   /**
132    * Create a new lossless transform instance.
133    */
134   public TJTransform() {
135   }
136
137   /**
138    * Create a new lossless transform instance with the given parameters.
139    *
140    * @param x the left boundary of the cropping region.  This must be evenly
141    * divisible by the MCU block width (see {@link TJ#getMCUWidth})
142    *
143    * @param y the upper boundary of the cropping region.  This must be evenly
144    * divisible by the MCU block height (see {@link TJ#getMCUHeight})
145    *
146    * @param w the width of the cropping region.  Setting this to 0 is the
147    * equivalent of setting it to the width of the source JPEG image - x.
148    *
149    * @param h the height of the cropping region.  Setting this to 0 is the
150    * equivalent of setting it to the height of the source JPEG image - y.
151    *
152    * @param op one of the transform operations (<code>OP_*</code>)
153    *
154    * @param options the bitwise OR of one or more of the transform options
155    * (<code>OPT_*</code>)
156    *
157    * @param cf an instance of an object that implements the {@link
158    * TJCustomFilter} interface, or null if no custom filter is needed
159    */
160   public TJTransform(int x, int y, int w, int h, int op, int options,
161     TJCustomFilter cf) throws Exception {
162     super(x, y, w, h);
163     this.op = op;  this.options = options;  this.cf = cf;
164   }
165
166   /**
167    * Create a new lossless transform instance with the given parameters.
168    *
169    * @param r a <code>Rectangle</code> instance that specifies the cropping
170    * region.  See {@link
171    * #TJTransform(int, int, int, int, int, int, TJCustomFilter)} for more
172    * detail.
173    *
174    * @param op one of the transform operations (<code>OP_*</code>)
175    *
176    * @param options the bitwise OR of one or more of the transform options
177    * (<code>OPT_*</code>)
178    *
179    * @param cf an instance of an object that implements the {@link
180    * TJCustomFilter} interface, or null if no custom filter is needed
181    */
182   public TJTransform(Rectangle r, int op, int options,
183     TJCustomFilter cf) throws Exception {
184     super(r);
185     this.op = op;  this.options = options;  this.cf = cf;
186   }
187
188   /**
189    * Transform operation (one of <code>OP_*</code>)
190    */
191   public int op = 0;
192
193   /**
194    * Transform options (bitwise OR of one or more of <code>OPT_*</code>)
195    */
196   public int options = 0;
197
198   /**
199    * Custom filter instance
200    */
201   public TJCustomFilter cf = null;
202 }