2 * Copyright (C)2011 D. R. Commander. All Rights Reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
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.
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.
29 package org.libjpegturbo.turbojpeg;
34 * Lossless transform parameters
36 public class TJTransform extends Rectangle {
38 private static final long serialVersionUID = -127367705761430371L;
41 * The number of lossless transform operations
43 final public static int NUMOP = 8;
45 * Do not transform the position of the image pixels.
47 final public static int OP_NONE = 0;
49 * Flip (mirror) image horizontally. This transform is imperfect if there
50 * are any partial MCU blocks on the right edge.
53 final public static int OP_HFLIP = 1;
55 * Flip (mirror) image vertically. This transform is imperfect if there are
56 * any partial MCU blocks on the bottom edge.
59 final public static int OP_VFLIP = 2;
61 * Transpose image (flip/mirror along upper left to lower right axis). This
62 * transform is always perfect.
65 final public static int OP_TRANSPOSE = 3;
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
72 final public static int OP_TRANSVERSE = 4;
74 * Rotate image clockwise by 90 degrees. This transform is imperfect if
75 * there are any partial MCU blocks on the bottom edge.
78 final public static int OP_ROT90 = 5;
80 * Rotate image 180 degrees. This transform is imperfect if there are any
81 * partial MCU blocks in the image.
84 final public static int OP_ROT180 = 6;
86 * Rotate image counter-clockwise by 90 degrees. This transform is imperfect
87 * if there are any partial MCU blocks on the right edge.
90 final public static int OP_ROT270 = 7;
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.
106 final public static int OPT_PERFECT = 1;
108 * This option will discard any partial MCU blocks that cannot be
111 final public static int OPT_TRIM = 2;
113 * This option will enable lossless cropping.
115 final public static int OPT_CROP = 4;
117 * This option will discard the color data in the input image and produce
118 * a grayscale output image.
120 final public static int OPT_GRAY = 8;
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
128 final public static int OPT_NOOUTPUT = 16;
132 * Create a new lossless transform instance.
134 public TJTransform() {
138 * Create a new lossless transform instance with the given parameters.
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})
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})
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.
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.
152 * @param op one of the transform operations (<code>OP_*</code>)
154 * @param options the bitwise OR of one or more of the transform options
155 * (<code>OPT_*</code>)
157 * @param cf an instance of an object that implements the {@link
158 * TJCustomFilter} interface, or null if no custom filter is needed
160 public TJTransform(int x, int y, int w, int h, int op, int options,
161 TJCustomFilter cf) throws Exception {
163 this.op = op; this.options = options; this.cf = cf;
167 * Create a new lossless transform instance with the given parameters.
169 * @param r a <code>Rectangle</code> instance that specifies the cropping
171 * #TJTransform(int, int, int, int, int, int, TJCustomFilter)} for more
174 * @param op one of the transform operations (<code>OP_*</code>)
176 * @param options the bitwise OR of one or more of the transform options
177 * (<code>OPT_*</code>)
179 * @param cf an instance of an object that implements the {@link
180 * TJCustomFilter} interface, or null if no custom filter is needed
182 public TJTransform(Rectangle r, int op, int options,
183 TJCustomFilter cf) throws Exception {
185 this.op = op; this.options = options; this.cf = cf;
189 * Transform operation (one of <code>OP_*</code>)
194 * Transform options (bitwise OR of one or more of <code>OPT_*</code>)
196 public int options = 0;
199 * Custom filter instance
201 public TJCustomFilter cf = null;