blob: ac4a4dd1806dfd64259b3ba8e302fda33671e8fc [file] [log] [blame]
DRCc5a41992011-02-08 06:54:36 +00001/*
DRC65d4a462013-04-27 01:06:52 +00002 * Copyright (C)2011-2013 D. R. Commander. All Rights Reserved.
DRCc5a41992011-02-08 06:54:36 +00003 *
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
29package org.libjpegturbo.turbojpeg;
30
DRC92549de2011-03-15 20:52:02 +000031/**
32 * TurboJPEG utility class (cannot be instantiated)
33 */
DRC67bee862013-04-27 12:36:07 +000034public final class TJ {
DRCc5a41992011-02-08 06:54:36 +000035
DRC92549de2011-03-15 20:52:02 +000036
37 /**
DRC92549de2011-03-15 20:52:02 +000038 * The number of chrominance subsampling options
39 */
DRCa5830622013-08-18 11:04:21 +000040 public static final int NUMSAMP = 6;
DRC92549de2011-03-15 20:52:02 +000041 /**
42 * 4:4:4 chrominance subsampling (no chrominance subsampling). The JPEG
43 * or YUV image will contain one chrominance component for every pixel in the
44 * source image.
45 */
DRC67bee862013-04-27 12:36:07 +000046 public static final int SAMP_444 = 0;
DRC92549de2011-03-15 20:52:02 +000047 /**
48 * 4:2:2 chrominance subsampling. The JPEG or YUV image will contain one
49 * chrominance component for every 2x1 block of pixels in the source image.
50 */
DRC67bee862013-04-27 12:36:07 +000051 public static final int SAMP_422 = 1;
DRC92549de2011-03-15 20:52:02 +000052 /**
53 * 4:2:0 chrominance subsampling. The JPEG or YUV image will contain one
54 * chrominance component for every 2x2 block of pixels in the source image.
55 */
DRC67bee862013-04-27 12:36:07 +000056 public static final int SAMP_420 = 2;
DRC92549de2011-03-15 20:52:02 +000057 /**
58 * Grayscale. The JPEG or YUV image will contain no chrominance components.
59 */
DRC67bee862013-04-27 12:36:07 +000060 public static final int SAMP_GRAY = 3;
DRC92549de2011-03-15 20:52:02 +000061 /**
62 * 4:4:0 chrominance subsampling. The JPEG or YUV image will contain one
63 * chrominance component for every 1x2 block of pixels in the source image.
DRCf82b9f92013-08-18 10:39:30 +000064 * Note that 4:4:0 subsampling is not fully accelerated in libjpeg-turbo.
DRC92549de2011-03-15 20:52:02 +000065 */
DRC67bee862013-04-27 12:36:07 +000066 public static final int SAMP_440 = 4;
DRCa5830622013-08-18 11:04:21 +000067 /**
68 * 4:1:1 chrominance subsampling. The JPEG or YUV image will contain one
69 * chrominance component for every 4x1 block of pixels in the source image.
70 * JPEG images compressed with 4:1:1 subsampling will be almost exactly the
71 * same size as those compressed with 4:2:0 subsampling, and in the
72 * aggregate, both subsampling methods produce approximately the same
73 * perceptual quality. However, 4:1:1 is better able to reproduce sharp
74 * horizontal features. Note that 4:1:1 subsampling is not fully accelerated
75 * in libjpeg-turbo.
76 */
77 public static final int SAMP_411 = 5;
DRC92549de2011-03-15 20:52:02 +000078
79
80 /**
81 * Returns the MCU block width for the given level of chrominance
82 * subsampling.
83 *
DRC2c74e512011-03-16 00:02:53 +000084 * @param subsamp the level of chrominance subsampling (one of
85 * <code>SAMP_*</code>)
DRC92549de2011-03-15 20:52:02 +000086 *
87 * @return the MCU block width for the given level of chrominance subsampling
88 */
89 public static int getMCUWidth(int subsamp) throws Exception {
DRC67bee862013-04-27 12:36:07 +000090 if (subsamp < 0 || subsamp >= NUMSAMP)
DRC92549de2011-03-15 20:52:02 +000091 throw new Exception("Invalid subsampling type");
92 return mcuWidth[subsamp];
93 }
DRCd0a81362011-03-04 13:04:24 +000094
DRC67bee862013-04-27 12:36:07 +000095 private static final int[] mcuWidth = {
DRCa5830622013-08-18 11:04:21 +000096 8, 16, 16, 8, 8, 32
DRCd0a81362011-03-04 13:04:24 +000097 };
98
DRC92549de2011-03-15 20:52:02 +000099
100 /**
101 * Returns the MCU block height for the given level of chrominance
102 * subsampling.
103 *
DRC2c74e512011-03-16 00:02:53 +0000104 * @param subsamp the level of chrominance subsampling (one of
105 * <code>SAMP_*</code>)
DRC92549de2011-03-15 20:52:02 +0000106 *
107 * @return the MCU block height for the given level of chrominance
108 * subsampling
109 */
110 public static int getMCUHeight(int subsamp) throws Exception {
DRC67bee862013-04-27 12:36:07 +0000111 if (subsamp < 0 || subsamp >= NUMSAMP)
DRCd0a81362011-03-04 13:04:24 +0000112 throw new Exception("Invalid subsampling type");
DRC92549de2011-03-15 20:52:02 +0000113 return mcuHeight[subsamp];
DRCd0a81362011-03-04 13:04:24 +0000114 }
115
DRC67bee862013-04-27 12:36:07 +0000116 private static final int[] mcuHeight = {
DRCa5830622013-08-18 11:04:21 +0000117 8, 8, 16, 8, 16, 8
DRCd0a81362011-03-04 13:04:24 +0000118 };
119
DRCc5a41992011-02-08 06:54:36 +0000120
DRC92549de2011-03-15 20:52:02 +0000121 /**
122 * The number of pixel formats
123 */
DRC38cb1ec2013-08-23 04:45:43 +0000124 public static final int NUMPF = 12;
DRC92549de2011-03-15 20:52:02 +0000125 /**
126 * RGB pixel format. The red, green, and blue components in the image are
127 * stored in 3-byte pixels in the order R, G, B from lowest to highest byte
128 * address within each pixel.
129 */
DRC67bee862013-04-27 12:36:07 +0000130 public static final int PF_RGB = 0;
DRC92549de2011-03-15 20:52:02 +0000131 /**
132 * BGR pixel format. The red, green, and blue components in the image are
133 * stored in 3-byte pixels in the order B, G, R from lowest to highest byte
134 * address within each pixel.
135 */
DRC67bee862013-04-27 12:36:07 +0000136 public static final int PF_BGR = 1;
DRC92549de2011-03-15 20:52:02 +0000137 /**
138 * RGBX pixel format. The red, green, and blue components in the image are
139 * stored in 4-byte pixels in the order R, G, B from lowest to highest byte
DRC67ce3b22011-12-19 02:21:03 +0000140 * address within each pixel. The X component is ignored when compressing
141 * and undefined when decompressing.
DRC92549de2011-03-15 20:52:02 +0000142 */
DRC67bee862013-04-27 12:36:07 +0000143 public static final int PF_RGBX = 2;
DRC92549de2011-03-15 20:52:02 +0000144 /**
145 * BGRX pixel format. The red, green, and blue components in the image are
146 * stored in 4-byte pixels in the order B, G, R from lowest to highest byte
DRC67ce3b22011-12-19 02:21:03 +0000147 * address within each pixel. The X component is ignored when compressing
148 * and undefined when decompressing.
DRC92549de2011-03-15 20:52:02 +0000149 */
DRC67bee862013-04-27 12:36:07 +0000150 public static final int PF_BGRX = 3;
DRC92549de2011-03-15 20:52:02 +0000151 /**
152 * XBGR pixel format. The red, green, and blue components in the image are
153 * stored in 4-byte pixels in the order R, G, B from highest to lowest byte
DRC67ce3b22011-12-19 02:21:03 +0000154 * address within each pixel. The X component is ignored when compressing
155 * and undefined when decompressing.
DRC92549de2011-03-15 20:52:02 +0000156 */
DRC67bee862013-04-27 12:36:07 +0000157 public static final int PF_XBGR = 4;
DRC92549de2011-03-15 20:52:02 +0000158 /**
159 * XRGB pixel format. The red, green, and blue components in the image are
160 * stored in 4-byte pixels in the order B, G, R from highest to lowest byte
DRC67ce3b22011-12-19 02:21:03 +0000161 * address within each pixel. The X component is ignored when compressing
162 * and undefined when decompressing.
DRC92549de2011-03-15 20:52:02 +0000163 */
DRC67bee862013-04-27 12:36:07 +0000164 public static final int PF_XRGB = 5;
DRC92549de2011-03-15 20:52:02 +0000165 /**
166 * Grayscale pixel format. Each 1-byte pixel represents a luminance
167 * (brightness) level from 0 to 255.
168 */
DRC67bee862013-04-27 12:36:07 +0000169 public static final int PF_GRAY = 6;
DRC67ce3b22011-12-19 02:21:03 +0000170 /**
171 * RGBA pixel format. This is the same as {@link #PF_RGBX}, except that when
172 * decompressing, the X byte is guaranteed to be 0xFF, which can be
173 * interpreted as an opaque alpha channel.
174 */
DRC67bee862013-04-27 12:36:07 +0000175 public static final int PF_RGBA = 7;
DRC67ce3b22011-12-19 02:21:03 +0000176 /**
177 * BGRA pixel format. This is the same as {@link #PF_BGRX}, except that when
178 * decompressing, the X byte is guaranteed to be 0xFF, which can be
179 * interpreted as an opaque alpha channel.
180 */
DRC67bee862013-04-27 12:36:07 +0000181 public static final int PF_BGRA = 8;
DRC67ce3b22011-12-19 02:21:03 +0000182 /**
183 * ABGR pixel format. This is the same as {@link #PF_XBGR}, except that when
184 * decompressing, the X byte is guaranteed to be 0xFF, which can be
185 * interpreted as an opaque alpha channel.
186 */
DRC67bee862013-04-27 12:36:07 +0000187 public static final int PF_ABGR = 9;
DRC67ce3b22011-12-19 02:21:03 +0000188 /**
189 * ARGB pixel format. This is the same as {@link #PF_XRGB}, except that when
190 * decompressing, the X byte is guaranteed to be 0xFF, which can be
191 * interpreted as an opaque alpha channel.
192 */
DRC67bee862013-04-27 12:36:07 +0000193 public static final int PF_ARGB = 10;
DRC38cb1ec2013-08-23 04:45:43 +0000194 /**
DRCb2c47452013-08-23 06:38:59 +0000195 * CMYK pixel format. Unlike RGB, which is an additive color model used
196 * primarily for display, CMYK (Cyan/Magenta/Yellow/Key) is a subtractive
197 * color model used primarily for printing. In the CMYK color model, the
198 * value of each color component typically corresponds to an amount of cyan,
199 * magenta, yellow, or black ink that is applied to a white background. In
200 * order to convert between CMYK and RGB, it is necessary to use a color
201 * management system (CMS.) A CMS will attempt to map colors within the
202 * printer's gamut to perceptually similar colors in the display's gamut and
203 * vice versa, but the mapping is typically not 1:1 or reversible, nor can it
204 * be defined with a simple formula. Thus, such a conversion is out of scope
205 * for a codec library. However, the TurboJPEG API allows for compressing
206 * CMYK pixels into a YCCK JPEG image (see {@link #CS_YCCK}) and
207 * decompressing YCCK JPEG images into CMYK pixels.
DRC38cb1ec2013-08-23 04:45:43 +0000208 */
209 public static final int PF_CMYK = 11;
DRC92549de2011-03-15 20:52:02 +0000210
211
212 /**
DRC65d4a462013-04-27 01:06:52 +0000213 * Returns the pixel size (in bytes) for the given pixel format.
DRC2c74e512011-03-16 00:02:53 +0000214 *
215 * @param pixelFormat the pixel format (one of <code>PF_*</code>)
216 *
DRC65d4a462013-04-27 01:06:52 +0000217 * @return the pixel size (in bytes) for the given pixel format
DRC92549de2011-03-15 20:52:02 +0000218 */
219 public static int getPixelSize(int pixelFormat) throws Exception {
DRC67bee862013-04-27 12:36:07 +0000220 if (pixelFormat < 0 || pixelFormat >= NUMPF)
DRC92549de2011-03-15 20:52:02 +0000221 throw new Exception("Invalid pixel format");
222 return pixelSize[pixelFormat];
223 }
DRC36336fc2011-02-22 10:27:31 +0000224
DRC67bee862013-04-27 12:36:07 +0000225 private static final int[] pixelSize = {
DRC38cb1ec2013-08-23 04:45:43 +0000226 3, 3, 4, 4, 4, 4, 1, 4, 4, 4, 4, 4
DRC36336fc2011-02-22 10:27:31 +0000227 };
228
DRC92549de2011-03-15 20:52:02 +0000229
230 /**
DRC2c74e512011-03-16 00:02:53 +0000231 * For the given pixel format, returns the number of bytes that the red
232 * component is offset from the start of the pixel. For instance, if a pixel
233 * of format <code>TJ.PF_BGRX</code> is stored in <code>char pixel[]</code>,
234 * then the red component will be
235 * <code>pixel[TJ.getRedOffset(TJ.PF_BGRX)]</code>.
DRC92549de2011-03-15 20:52:02 +0000236 *
DRC2c74e512011-03-16 00:02:53 +0000237 * @param pixelFormat the pixel format (one of <code>PF_*</code>)
DRC92549de2011-03-15 20:52:02 +0000238 *
DRC2c74e512011-03-16 00:02:53 +0000239 * @return the red offset for the given pixel format
DRC92549de2011-03-15 20:52:02 +0000240 */
DRC2c74e512011-03-16 00:02:53 +0000241 public static int getRedOffset(int pixelFormat) throws Exception {
DRC67bee862013-04-27 12:36:07 +0000242 if (pixelFormat < 0 || pixelFormat >= NUMPF)
DRC36336fc2011-02-22 10:27:31 +0000243 throw new Exception("Invalid pixel format");
DRC2c74e512011-03-16 00:02:53 +0000244 return redOffset[pixelFormat];
DRC36336fc2011-02-22 10:27:31 +0000245 }
246
DRC67bee862013-04-27 12:36:07 +0000247 private static final int[] redOffset = {
DRC38cb1ec2013-08-23 04:45:43 +0000248 0, 2, 0, 2, 3, 1, 0, 0, 2, 3, 1, -1
DRC4f1580c2011-02-25 06:11:03 +0000249 };
250
DRC92549de2011-03-15 20:52:02 +0000251
252 /**
DRC2c74e512011-03-16 00:02:53 +0000253 * For the given pixel format, returns the number of bytes that the green
254 * component is offset from the start of the pixel. For instance, if a pixel
255 * of format <code>TJ.PF_BGRX</code> is stored in <code>char pixel[]</code>,
256 * then the green component will be
257 * <code>pixel[TJ.getGreenOffset(TJ.PF_BGRX)]</code>.
DRC92549de2011-03-15 20:52:02 +0000258 *
DRC2c74e512011-03-16 00:02:53 +0000259 * @param pixelFormat the pixel format (one of <code>PF_*</code>)
DRC92549de2011-03-15 20:52:02 +0000260 *
DRC2c74e512011-03-16 00:02:53 +0000261 * @return the green offset for the given pixel format
DRC92549de2011-03-15 20:52:02 +0000262 */
DRC2c74e512011-03-16 00:02:53 +0000263 public static int getGreenOffset(int pixelFormat) throws Exception {
DRC67bee862013-04-27 12:36:07 +0000264 if (pixelFormat < 0 || pixelFormat >= NUMPF)
DRC4f1580c2011-02-25 06:11:03 +0000265 throw new Exception("Invalid pixel format");
DRC2c74e512011-03-16 00:02:53 +0000266 return greenOffset[pixelFormat];
DRC4f1580c2011-02-25 06:11:03 +0000267 }
268
DRC67bee862013-04-27 12:36:07 +0000269 private static final int[] greenOffset = {
DRC38cb1ec2013-08-23 04:45:43 +0000270 1, 1, 1, 1, 2, 2, 0, 1, 1, 2, 2, -1
DRC4f1580c2011-02-25 06:11:03 +0000271 };
272
DRC92549de2011-03-15 20:52:02 +0000273
274 /**
DRC2c74e512011-03-16 00:02:53 +0000275 * For the given pixel format, returns the number of bytes that the blue
276 * component is offset from the start of the pixel. For instance, if a pixel
277 * of format <code>TJ.PF_BGRX</code> is stored in <code>char pixel[]</code>,
278 * then the blue component will be
279 * <code>pixel[TJ.getBlueOffset(TJ.PF_BGRX)]</code>.
DRC92549de2011-03-15 20:52:02 +0000280 *
DRC2c74e512011-03-16 00:02:53 +0000281 * @param pixelFormat the pixel format (one of <code>PF_*</code>)
DRC92549de2011-03-15 20:52:02 +0000282 *
DRC2c74e512011-03-16 00:02:53 +0000283 * @return the blue offset for the given pixel format
DRC92549de2011-03-15 20:52:02 +0000284 */
DRC2c74e512011-03-16 00:02:53 +0000285 public static int getBlueOffset(int pixelFormat) throws Exception {
DRC67bee862013-04-27 12:36:07 +0000286 if (pixelFormat < 0 || pixelFormat >= NUMPF)
DRC4f1580c2011-02-25 06:11:03 +0000287 throw new Exception("Invalid pixel format");
DRC2c74e512011-03-16 00:02:53 +0000288 return blueOffset[pixelFormat];
DRC4f1580c2011-02-25 06:11:03 +0000289 }
290
DRC67bee862013-04-27 12:36:07 +0000291 private static final int[] blueOffset = {
DRC38cb1ec2013-08-23 04:45:43 +0000292 2, 0, 2, 0, 1, 3, 0, 2, 0, 1, 3, -1
DRC4f1580c2011-02-25 06:11:03 +0000293 };
294
DRC4f1580c2011-02-25 06:11:03 +0000295
DRC92549de2011-03-15 20:52:02 +0000296 /**
DRC38cb1ec2013-08-23 04:45:43 +0000297 * The number of JPEG colorspaces
298 */
299 public static final int NUMCS = 5;
300 /**
301 * RGB colorspace. When compressing the JPEG image, the R, G, and B
302 * components in the source image are reordered into image planes, but no
303 * colorspace conversion or subsampling is performed. RGB JPEG images can be
304 * decompressed to any of the extended RGB pixel formats or grayscale, but
305 * they cannot be decompressed to YUV images.
306 */
307 public static final int CS_RGB = 0;
308 /**
309 * YCbCr colorspace. YCbCr is not an absolute colorspace but rather a
310 * mathematical transformation of RGB designed solely for storage and
311 * transmission. YCbCr images must be converted to RGB before they can
312 * actually be displayed. In the YCbCr colorspace, the Y (luminance)
313 * component represents the black & white portion of the original image, and
314 * the Cb and Cr (chrominance) components represent the color portion of the
315 * original image. Originally, the analog equivalent of this transformation
316 * allowed the same signal to drive both black & white and color televisions,
317 * but JPEG images use YCbCr primarily because it allows the color data to be
318 * optionally subsampled for the purposes of reducing bandwidth or disk
319 * space. YCbCr is the most common JPEG colorspace, and YCbCr JPEG images
320 * can be compressed from and decompressed to any of the extended RGB pixel
321 * formats or grayscale, or they can be decompressed to YUV planar images.
322 */
323 public static final int CS_YCbCr = 1;
324 /**
325 * Grayscale colorspace. The JPEG image retains only the luminance data (Y
326 * component), and any color data from the source image is discarded.
327 * Grayscale JPEG images can be compressed from and decompressed to any of
328 * the extended RGB pixel formats or grayscale, or they can be decompressed
329 * to YUV planar images.
330 */
331 public static final int CS_GRAY = 2;
332 /**
333 * CMYK colorspace. When compressing the JPEG image, the C, M, Y, and K
334 * components in the source image are reordered into image planes, but no
335 * colorspace conversion or subsampling is performed. CMYK JPEG images can
336 * only be decompressed to CMYK pixels.
337 */
338 public static final int CS_CMYK = 3;
339 /**
340 * YCCK colorspace. YCCK (AKA "YCbCrK") is not an absolute colorspace but
341 * rather a mathematical transformation of CMYK designed solely for storage
342 * and transmission. It is to CMYK as YCbCr is to RGB. CMYK pixels can be
343 * reversibly transformed into YCCK, and as with YCbCr, the chrominance
344 * components in the YCCK pixels can be subsampled without incurring major
345 * perceptual loss. YCCK JPEG images can only be compressed from and
346 * decompressed to CMYK pixels.
347 */
348 public static final int CS_YCCK = 4;
349
350
351 /**
DRC92549de2011-03-15 20:52:02 +0000352 * The uncompressed source/destination image is stored in bottom-up (Windows,
353 * OpenGL) order, not top-down (X11) order.
354 */
DRC67bee862013-04-27 12:36:07 +0000355 public static final int FLAG_BOTTOMUP = 2;
DRC07e982d2013-10-31 07:11:39 +0000356
357 @Deprecated
DRC67bee862013-04-27 12:36:07 +0000358 public static final int FLAG_FORCEMMX = 8;
DRC07e982d2013-10-31 07:11:39 +0000359 @Deprecated
DRC67bee862013-04-27 12:36:07 +0000360 public static final int FLAG_FORCESSE = 16;
DRC07e982d2013-10-31 07:11:39 +0000361 @Deprecated
DRC67bee862013-04-27 12:36:07 +0000362 public static final int FLAG_FORCESSE2 = 32;
DRC07e982d2013-10-31 07:11:39 +0000363 @Deprecated
DRC67bee862013-04-27 12:36:07 +0000364 public static final int FLAG_FORCESSE3 = 128;
DRC07e982d2013-10-31 07:11:39 +0000365
DRC92549de2011-03-15 20:52:02 +0000366 /**
DRC65d4a462013-04-27 01:06:52 +0000367 * When decompressing an image that was compressed using chrominance
368 * subsampling, use the fastest chrominance upsampling algorithm available in
369 * the underlying codec. The default is to use smooth upsampling, which
370 * creates a smooth transition between neighboring chrominance components in
371 * order to reduce upsampling artifacts in the decompressed image.
DRC92549de2011-03-15 20:52:02 +0000372 */
DRC67bee862013-04-27 12:36:07 +0000373 public static final int FLAG_FASTUPSAMPLE = 256;
DRC73d74c12012-06-29 23:46:38 +0000374 /**
375 * Use the fastest DCT/IDCT algorithm available in the underlying codec. The
DRCf82b9f92013-08-18 10:39:30 +0000376 * default if this flag is not specified is implementation-specific. For
377 * example, the implementation of TurboJPEG for libjpeg[-turbo] uses the fast
378 * algorithm by default when compressing, because this has been shown to have
379 * only a very slight effect on accuracy, but it uses the accurate algorithm
380 * when decompressing, because this has been shown to have a larger effect.
DRC73d74c12012-06-29 23:46:38 +0000381 */
DRC67bee862013-04-27 12:36:07 +0000382 public static final int FLAG_FASTDCT = 2048;
DRC73d74c12012-06-29 23:46:38 +0000383 /**
384 * Use the most accurate DCT/IDCT algorithm available in the underlying
385 * codec. The default if this flag is not specified is
DRCf82b9f92013-08-18 10:39:30 +0000386 * implementation-specific. For example, the implementation of TurboJPEG for
387 * libjpeg[-turbo] uses the fast algorithm by default when compressing,
388 * because this has been shown to have only a very slight effect on accuracy,
389 * but it uses the accurate algorithm when decompressing, because this has
390 * been shown to have a larger effect.
DRC73d74c12012-06-29 23:46:38 +0000391 */
DRC67bee862013-04-27 12:36:07 +0000392 public static final int FLAG_ACCURATEDCT = 4096;
DRCe8573012011-03-04 10:13:59 +0000393
DRCe8573012011-03-04 10:13:59 +0000394
DRC92549de2011-03-15 20:52:02 +0000395 /**
396 * Returns the maximum size of the buffer (in bytes) required to hold a JPEG
DRC65d4a462013-04-27 01:06:52 +0000397 * image with the given width, height, and level of chrominance subsampling.
DRC92549de2011-03-15 20:52:02 +0000398 *
399 * @param width the width (in pixels) of the JPEG image
400 *
401 * @param height the height (in pixels) of the JPEG image
402 *
DRC9b49f0e2011-07-12 03:17:23 +0000403 * @param jpegSubsamp the level of chrominance subsampling to be used when
404 * generating the JPEG image (one of {@link TJ TJ.SAMP_*})
405 *
DRC92549de2011-03-15 20:52:02 +0000406 * @return the maximum size of the buffer (in bytes) required to hold a JPEG
DRC65d4a462013-04-27 01:06:52 +0000407 * image with the given width, height, and level of chrominance subsampling
DRC92549de2011-03-15 20:52:02 +0000408 */
DRC67bee862013-04-27 12:36:07 +0000409 public static native int bufSize(int width, int height, int jpegSubsamp)
DRC36336fc2011-02-22 10:27:31 +0000410 throws Exception;
411
DRC92549de2011-03-15 20:52:02 +0000412 /**
DRC2c74e512011-03-16 00:02:53 +0000413 * Returns the size of the buffer (in bytes) required to hold a YUV planar
414 * image with the given width, height, and level of chrominance subsampling.
DRC92549de2011-03-15 20:52:02 +0000415 *
416 * @param width the width (in pixels) of the YUV image
417 *
DRCfef98522013-04-28 01:32:52 +0000418 * @param pad the width of each line in each plane of the image is padded to
419 * the nearest multiple of this number of bytes (must be a power of
420 * 2.)
421 *
DRC92549de2011-03-15 20:52:02 +0000422 * @param height the height (in pixels) of the YUV image
423 *
424 * @param subsamp the level of chrominance subsampling used in the YUV
DRC9b49f0e2011-07-12 03:17:23 +0000425 * image (one of {@link TJ TJ.SAMP_*})
DRC92549de2011-03-15 20:52:02 +0000426 *
DRC2c74e512011-03-16 00:02:53 +0000427 * @return the size of the buffer (in bytes) required to hold a YUV planar
428 * image with the given width, height, and level of chrominance subsampling
DRC92549de2011-03-15 20:52:02 +0000429 */
DRCfef98522013-04-28 01:32:52 +0000430 public static native int bufSizeYUV(int width, int pad, int height,
431 int subsamp)
432 throws Exception;
433
434 /**
435 * @deprecated Use {@link #bufSizeYUV(int, int, int, int)} instead.
436 */
437 @Deprecated
DRC1d29c5f2013-04-27 20:54:44 +0000438 public static native int bufSizeYUV(int width, int height, int subsamp)
DRC36336fc2011-02-22 10:27:31 +0000439 throws Exception;
DRC3bad53f2011-02-23 02:20:49 +0000440
DRC92549de2011-03-15 20:52:02 +0000441 /**
442 * Returns a list of fractional scaling factors that the JPEG decompressor in
443 * this implementation of TurboJPEG supports.
444 *
445 * @return a list of fractional scaling factors that the JPEG decompressor in
446 * this implementation of TurboJPEG supports
447 */
DRC67bee862013-04-27 12:36:07 +0000448 public static native TJScalingFactor[] getScalingFactors()
DRC109a5782011-03-01 09:53:07 +0000449 throws Exception;
450
DRC3bad53f2011-02-23 02:20:49 +0000451 static {
DRCb2f94152011-04-02 02:09:03 +0000452 TJLoader.load();
DRC3bad53f2011-02-23 02:20:49 +0000453 }
DRCc5a41992011-02-08 06:54:36 +0000454};