2 * Copyright (C)2011, 2013, 2018 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 public static final int NUMOP = 8;
45 * Do not transform the position of the image pixels.
47 public static final 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 public static final 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 public static final int OP_VFLIP = 2;
61 * Transpose image (flip/mirror along upper left to lower right axis). This
62 * transform is always perfect.
65 public static final 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 public static final 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 public static final 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 public static final 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 public static final 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 public static final int OPT_PERFECT = 1;
108 * This option will discard any partial MCU blocks that cannot be
111 public static final int OPT_TRIM = 2;
113 * This option will enable lossless cropping.
115 public static final int OPT_CROP = 4;
117 * This option will discard the color data in the input image and produce
118 * a grayscale output image.
120 public static final 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 public static final int OPT_NOOUTPUT = 16;
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
136 public static final int OPT_PROGRESSIVE = 32;
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.
142 public static final int OPT_COPYNONE = 64;
146 * Create a new lossless transform instance.
148 public TJTransform() {
152 * Create a new lossless transform instance with the given parameters.
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})
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})
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 -
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 -
168 * @param op one of the transform operations (<code>OP_*</code>)
170 * @param options the bitwise OR of one or more of the transform options
171 * (<code>OPT_*</code>)
173 * @param cf an instance of an object that implements the {@link
174 * TJCustomFilter} interface, or null if no custom filter is needed
176 @SuppressWarnings("checkstyle:HiddenField")
177 public TJTransform(int x, int y, int w, int h, int op, int options,
181 this.options = options;
186 * Create a new lossless transform instance with the given parameters.
188 * @param r a <code>Rectangle</code> instance that specifies the cropping
190 * #TJTransform(int, int, int, int, int, int, TJCustomFilter)} for more
193 * @param op one of the transform operations (<code>OP_*</code>)
195 * @param options the bitwise OR of one or more of the transform options
196 * (<code>OPT_*</code>)
198 * @param cf an instance of an object that implements the {@link
199 * TJCustomFilter} interface, or null if no custom filter is needed
201 @SuppressWarnings("checkstyle:HiddenField")
202 public TJTransform(Rectangle r, int op, int options,
206 this.options = options;
211 * Transform operation (one of <code>OP_*</code>)
213 @SuppressWarnings("checkstyle:VisibilityModifier")
217 * Transform options (bitwise OR of one or more of <code>OPT_*</code>)
219 @SuppressWarnings("checkstyle:VisibilityModifier")
220 public int options = 0;
223 * Custom filter instance
225 @SuppressWarnings("checkstyle:VisibilityModifier")
226 public TJCustomFilter cf = null;