2 * Copyright (C)2011, 2013, 2018, 2022-2023 D. R. Commander.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
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.
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.
30 package org.libjpegturbo.turbojpeg;
35 * Lossless transform parameters
37 public class TJTransform extends Rectangle {
39 private static final long serialVersionUID = -127367705761430371L;
42 * The number of lossless transform operations
44 public static final int NUMOP = 8;
46 * Do not transform the position of the image pixels.
48 public static final int OP_NONE = 0;
50 * Flip (mirror) image horizontally. This transform is imperfect if there
51 * are any partial MCU blocks on the right edge.
54 public static final int OP_HFLIP = 1;
56 * Flip (mirror) image vertically. This transform is imperfect if there are
57 * any partial MCU blocks on the bottom edge.
60 public static final int OP_VFLIP = 2;
62 * Transpose image (flip/mirror along upper left to lower right axis). This
63 * transform is always perfect.
66 public static final int OP_TRANSPOSE = 3;
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
73 public static final int OP_TRANSVERSE = 4;
75 * Rotate image clockwise by 90 degrees. This transform is imperfect if
76 * there are any partial MCU blocks on the bottom edge.
79 public static final int OP_ROT90 = 5;
81 * Rotate image 180 degrees. This transform is imperfect if there are any
82 * partial MCU blocks in the image.
85 public static final int OP_ROT180 = 6;
87 * Rotate image counter-clockwise by 90 degrees. This transform is imperfect
88 * if there are any partial MCU blocks on the right edge.
91 public static final int OP_ROT270 = 7;
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.
108 public static final int OPT_PERFECT = (1 << 0);
110 * This option will discard any partial MCU blocks that cannot be
113 public static final int OPT_TRIM = (1 << 1);
115 * This option will enable lossless cropping.
117 public static final int OPT_CROP = (1 << 2);
119 * This option will discard the color data in the source image and produce a
120 * grayscale destination image.
122 public static final int OPT_GRAY = (1 << 3);
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
130 public static final int OPT_NOOUTPUT = (1 << 4);
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.
139 public static final int OPT_PROGRESSIVE = (1 << 5);
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.
145 public static final int OPT_COPYNONE = (1 << 6);
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}.
153 public static final int OPT_ARITHMETIC = (1 << 7);
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.)
159 public static final int OPT_OPTIMIZE = (1 << 8);
163 * Create a new lossless transform instance.
165 public TJTransform() {
169 * Create a new lossless transform instance with the given parameters.
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
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()})
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 -
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 -
187 * @param op one of the transform operations ({@link #OP_NONE OP_*})
189 * @param options the bitwise OR of one or more of the transform options
190 * ({@link #OPT_PERFECT OPT_*})
192 * @param cf an instance of an object that implements the
193 * {@link TJCustomFilter} interface, or null if no custom filter is needed
195 @SuppressWarnings("checkstyle:HiddenField")
196 public TJTransform(int x, int y, int w, int h, int op, int options,
200 this.options = options;
205 * Create a new lossless transform instance with the given parameters.
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
212 * @param op one of the transform operations ({@link #OP_NONE OP_*})
214 * @param options the bitwise OR of one or more of the transform options
215 * ({@link #OPT_PERFECT OPT_*})
217 * @param cf an instance of an object that implements the
218 * {@link TJCustomFilter} interface, or null if no custom filter is needed
220 @SuppressWarnings("checkstyle:HiddenField")
221 public TJTransform(Rectangle r, int op, int options,
225 this.options = options;
230 * Transform operation (one of {@link #OP_NONE OP_*})
232 @SuppressWarnings("checkstyle:VisibilityModifier")
236 * Transform options (bitwise OR of one or more of
237 * {@link #OPT_PERFECT OPT_*})
239 @SuppressWarnings("checkstyle:VisibilityModifier")
240 public int options = 0;
243 * Custom filter instance
245 @SuppressWarnings("checkstyle:VisibilityModifier")
246 public TJCustomFilter cf = null;