diff --git a/ChangeLog.txt b/ChangeLog.txt index e1069f5e..65e64de0 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -17,7 +17,8 @@ try-with-resources statement. [4] The TurboJPEG Java classes now throw unchecked idiomatic exceptions (IllegalArgumentException, IllegalStateException) for unrecoverable errors -caused by incorrect API usage. +caused by incorrect API usage, and those classes throw a new checked exception +type (TJException) for errors that are passed through from the C library. 1.4.1 diff --git a/java/CMakeLists.txt b/java/CMakeLists.txt index f9f9e572..0af8ae15 100644 --- a/java/CMakeLists.txt +++ b/java/CMakeLists.txt @@ -5,6 +5,7 @@ set(JAVA_CLASSNAMES org/libjpegturbo/turbojpeg/TJ org/libjpegturbo/turbojpeg/TJCompressor org/libjpegturbo/turbojpeg/TJCustomFilter org/libjpegturbo/turbojpeg/TJDecompressor + org/libjpegturbo/turbojpeg/TJException org/libjpegturbo/turbojpeg/TJScalingFactor org/libjpegturbo/turbojpeg/TJTransform org/libjpegturbo/turbojpeg/TJTransformer diff --git a/java/Makefile.am b/java/Makefile.am index 23e34129..475dd3fe 100644 --- a/java/Makefile.am +++ b/java/Makefile.am @@ -10,6 +10,7 @@ JAVASOURCES = org/libjpegturbo/turbojpeg/TJ.java \ org/libjpegturbo/turbojpeg/TJCompressor.java \ org/libjpegturbo/turbojpeg/TJCustomFilter.java \ org/libjpegturbo/turbojpeg/TJDecompressor.java \ + org/libjpegturbo/turbojpeg/TJException.java \ org/libjpegturbo/turbojpeg/TJScalingFactor.java \ org/libjpegturbo/turbojpeg/TJTransform.java \ org/libjpegturbo/turbojpeg/TJTransformer.java \ @@ -31,6 +32,7 @@ JAVA_CLASSES = org/libjpegturbo/turbojpeg/TJ.class \ org/libjpegturbo/turbojpeg/TJCompressor.class \ org/libjpegturbo/turbojpeg/TJCustomFilter.class \ org/libjpegturbo/turbojpeg/TJDecompressor.class \ + org/libjpegturbo/turbojpeg/TJException.class \ org/libjpegturbo/turbojpeg/TJLoader.class \ org/libjpegturbo/turbojpeg/TJScalingFactor.class \ org/libjpegturbo/turbojpeg/TJTransform.class \ diff --git a/java/TJExample.java b/java/TJExample.java index 75621143..da098078 100644 --- a/java/TJExample.java +++ b/java/TJExample.java @@ -1,5 +1,5 @@ /* - * Copyright (C)2011-2012, 2014 D. R. Commander. All Rights Reserved. + * Copyright (C)2011-2012, 2014-2015 D. R. Commander. All Rights Reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -351,7 +351,7 @@ public class TJExample implements TJCustomFilter { public void customFilter(ShortBuffer coeffBuffer, Rectangle bufferRegion, Rectangle planeRegion, int componentIndex, int transformIndex, TJTransform transform) - throws Exception { + throws TJException { for (int i = 0; i < bufferRegion.width * bufferRegion.height; i++) { coeffBuffer.put(i, (short)(-coeffBuffer.get(i))); } diff --git a/java/doc/allclasses-frame.html b/java/doc/allclasses-frame.html index 509ea508..fecac06d 100644 --- a/java/doc/allclasses-frame.html +++ b/java/doc/allclasses-frame.html @@ -13,6 +13,7 @@
yuvImage with the newly created
instance.
+public static int bufSize(int width,
int height,
- int jpegSubsamp)
- throws java.lang.Exception
+ int jpegSubsamp)
width - the width (in pixels) of the JPEG imageheight - the height (in pixels) of the JPEG imagejpegSubsamp - the level of chrominance subsampling to be used when
generating the JPEG image (one of TJ.SAMP_*)java.lang.Exceptionpublic static int bufSizeYUV(int width,
int pad,
int height,
- int subsamp)
- throws java.lang.Exception
+ int subsamp)
width - the width (in pixels) of the YUV imagepad - the width of each line in each plane of the image is padded to
the nearest multiple of this number of bytes (must be a power of 2.)height - the height (in pixels) of the YUV imagesubsamp - the level of chrominance subsampling used in the YUV
image (one of TJ.SAMP_*)java.lang.Exception@Deprecated
public static int bufSizeYUV(int width,
int height,
- int subsamp)
- throws java.lang.Exception
+ int subsamp)
bufSizeYUV(int, int, int, int) instead.java.lang.ExceptioncomponentID - ID number of the image plane (0 = Y, 1 = U/Cb,
@@ -1145,9 +1135,7 @@ public static int bufSizeYUV(int width,
height of the whole image, not the plane height.subsamp - the level of chrominance subsampling used in the YUV
image (one of TJ.SAMP_*)java.lang.Exceptionpublic static int planeWidth(int componentID,
int width,
- int subsamp)
- throws java.lang.Exception
+ int subsamp)
YUVImage for a description of plane width.componentID - ID number of the image plane (0 = Y, 1 = U/Cb,
2 = V/Cr)width - width (in pixels) of the YUV imagesubsamp - the level of chrominance subsampling used in the YUV image
(one of TJ.SAMP_*)java.lang.Exceptionpublic static int planeHeight(int componentID,
int height,
- int subsamp)
- throws java.lang.Exception
+ int subsamp)
YUVImage for a description of plane height.componentID - ID number of the image plane (0 = Y, 1 = U/Cb,
2 = V/Cr)height - height (in pixels) of the YUV imagesubsamp - the level of chrominance subsampling used in the YUV image
(one of TJ.SAMP_*)java.lang.Exceptionpublic static TJScalingFactor[] getScalingFactors() - throws java.lang.Exception+
public static TJScalingFactor[] getScalingFactors()
java.lang.Exceptionpublic TJCompressor() - throws java.lang.Exception+ throws TJException
java.lang.ExceptionTJExceptionsrcImage with the newly created
instance.srcImage - see setSourceImage(byte[], int, int, int, int, int, int) for descriptionx - see setSourceImage(byte[], int, int, int, int, int, int) for descriptiony - see setSourceImage(byte[], int, int, int, int, int, int) for descriptionwidth - see setSourceImage(byte[], int, int, int, int, int, int) for descriptionpitch - see setSourceImage(byte[], int, int, int, int, int, int) for descriptionheight - see setSourceImage(byte[], int, int, int, int, int, int) for descriptionpixelFormat - pixel format of the source image (one of
TJ.PF_*)java.lang.ExceptionTJExceptionTJCompressor(byte[], int, int, int, int, int, int) instead.java.lang.ExceptionTJExceptionsrcImage with the newly created
instance.setSourceImage(BufferedImage, int, int, int, int) for descriptionheight - see
setSourceImage(BufferedImage, int, int, int, int) for descriptionjava.lang.ExceptionTJExceptionsrcImage - image buffer containing RGB, grayscale, or CMYK pixels to
@@ -493,7 +493,7 @@ public TJCompressor(byte[] srcImage,
which the JPEG or YUV image should be compressed/encodedpixelFormat - pixel format of the source image (one of
TJ.PF_*)java.lang.ExceptionTJExceptionsetSourceImage(byte[], int, int, int, int, int, int) instead.java.lang.ExceptionTJExceptionsrcImage - a BufferedImage instance containing RGB or
@@ -538,7 +538,7 @@ public void setSourceImage(byte[] srcImage,
which the JPEG or YUV image should be compressed/encoded (0 = use the
height of the source image)java.lang.ExceptionTJExceptionpublic void setSourceImage(YUVImage srcImage) - throws java.lang.Exception+ throws TJException
srcImage - YUV planar image to be compressed. This image is not
modified.java.lang.ExceptionTJExceptionpublic void compress(byte[] dstBuf,
int flags)
- throws java.lang.Exception
+ throws TJException
dstBuf - buffer that will receive the JPEG image. Use
@@ -613,7 +613,7 @@ public void setSourceImage(byte[] srcImage,
subsampling.flags - the bitwise OR of one or more of
TJ.FLAG_*java.lang.ExceptionTJExceptionpublic byte[] compress(int flags) - throws java.lang.Exception+ throws TJException
flags - the bitwise OR of one or more of
@@ -631,7 +631,7 @@ public void setSourceImage(byte[] srcImage,
getCompressedSize() to obtain the size of the JPEG image.java.lang.ExceptionTJExceptionsetSourceImage(BufferedImage, int, int, int, int) and
compress(byte[], int) instead.java.lang.ExceptionTJException@Deprecated
public byte[] compress(java.awt.image.BufferedImage srcImage,
int flags)
- throws java.lang.Exception
+ throws TJException
java.lang.ExceptionTJExceptionpublic void encodeYUV(YUVImage dstImage,
int flags)
- throws java.lang.Exception
+ throws TJException
YUVImage instance. This method uses the accelerated color
@@ -688,7 +688,7 @@ public byte[] compress(java.awt.image.BufferedImage srcImage,
imageflags - the bitwise OR of one or more of
TJ.FLAG_*java.lang.ExceptionTJException@Deprecated
public void encodeYUV(byte[] dstBuf,
int flags)
- throws java.lang.Exception
+ throws TJException
encodeYUV(YUVImage, int) instead.java.lang.ExceptionTJExceptionpublic YUVImage encodeYUV(int pad, int flags) - throws java.lang.Exception+ throws TJException
YUVImage instance containing the encoded image. This method
@@ -727,7 +727,7 @@ public void encodeYUV(byte[] dstBuf,
TJ.FLAG_*
java.lang.ExceptionTJExceptionpublic YUVImage encodeYUV(int[] strides, int flags) - throws java.lang.Exception+ throws TJException
YUVImage instance containing the encoded image planes. This
@@ -755,7 +755,7 @@ public void encodeYUV(byte[] dstBuf,
TJ.FLAG_*
java.lang.ExceptionTJException@Deprecated public byte[] encodeYUV(int flags) - throws java.lang.Exception+ throws TJException
encodeYUV(int, int) instead.java.lang.ExceptionTJExceptionsetSourceImage(BufferedImage, int, int, int, int) and
encodeYUV(byte[], int) instead.java.lang.ExceptionTJException@Deprecated
public byte[] encodeYUV(java.awt.image.BufferedImage srcImage,
int flags)
- throws java.lang.Exception
+ throws TJException
java.lang.ExceptionTJExceptionpublic void close() - throws java.io.IOException+ throws TJException
close in interface java.lang.AutoCloseablejava.io.IOExceptionTJExceptiontransforms array that was passed to TJTransformer.transform().transform - a TJTransform instance that specifies the
parameters and/or cropping region for this transformjava.lang.ExceptionTJExceptionpublic TJDecompressor(byte[] jpegImage) - throws java.lang.Exception+ throws TJException
jpegImage with the newly created instance.jpegImage - JPEG image buffer (size of the JPEG image is assumed to
be the length of the array.) This buffer is not modified.java.lang.ExceptionTJExceptionpublic TJDecompressor(byte[] jpegImage,
int imageSize)
- throws java.lang.Exception
+ throws TJException
imageSize bytes stored in
jpegImage with the newly created instance.jpegImage - JPEG image buffer. This buffer is not modified.imageSize - size of the JPEG image (in bytes)java.lang.ExceptionTJExceptionpublic TJDecompressor(YUVImage yuvImage) - throws java.lang.Exception+ throws TJException
yuvImage with the newly created
instance.yuvImage - YUVImage instance containing a YUV planar
image to be decoded. This image is not modified.java.lang.ExceptionTJExceptionpublic void setSourceImage(byte[] jpegImage,
int imageSize)
- throws java.lang.Exception
+ throws TJException
imageSize bytes stored in
jpegImage with this decompressor instance. This image will
be used as the source image for subsequent decompress operations.jpegImage - JPEG image buffer. This buffer is not modified.imageSize - size of the JPEG image (in bytes)java.lang.ExceptionTJException@Deprecated
public void setJPEGImage(byte[] jpegImage,
int imageSize)
- throws java.lang.Exception
+ throws TJException
setSourceImage(byte[], int) instead.java.lang.ExceptionTJExceptionpublic void setSourceImage(YUVImage srcImage) - throws java.lang.Exception+
public void setSourceImage(YUVImage srcImage)
srcImage - YUVImage instance containing a YUV planar image to
- be decoded. This image is not modified.java.lang.Exceptionpublic int getScaledWidth(int desiredWidth, - int desiredHeight) - throws java.lang.Exception+ int desiredHeight)
java.lang.Exceptionpublic int getScaledHeight(int desiredWidth, - int desiredHeight) - throws java.lang.Exception+ int desiredHeight)
java.lang.ExceptionTJ.PF_*)flags - the bitwise OR of one or more of
TJ.FLAG_*java.lang.ExceptionTJExceptiondecompress(byte[], int, int, int, int, int, int, int) instead.java.lang.ExceptionTJExceptiondesiredWidth - see
@@ -887,7 +878,7 @@ public void decompress(byte[] dstBuf,
TJ.FLAG_*java.lang.ExceptionTJExceptionpublic void decompressToYUV(YUVImage dstImage, int flags) - throws java.lang.Exception+ throws TJException
YUVImage instance. This method performs JPEG decompression
@@ -913,7 +904,7 @@ public void decompress(byte[] dstBuf,
source image.flags - the bitwise OR of one or more of
TJ.FLAG_*java.lang.ExceptionTJException@Deprecated
public void decompressToYUV(byte[] dstBuf,
int flags)
- throws java.lang.Exception
+ throws TJException
decompressToYUV(YUVImage, int) instead.java.lang.ExceptionTJExceptionYUVImage instance containing the decompressed image planes.
@@ -971,7 +962,7 @@ public void decompressToYUV(byte[] dstBuf,
TJ.FLAG_*
java.lang.ExceptionTJExceptionYUVImage instance containing the decompressed image. This
@@ -1010,7 +1001,7 @@ public void decompressToYUV(byte[] dstBuf,
TJ.FLAG_*
java.lang.ExceptionTJException@Deprecated public byte[] decompressToYUV(int flags) - throws java.lang.Exception+ throws TJException
decompressToYUV(int, int, int, int) instead.java.lang.ExceptionTJExceptionTJ.PF_*)flags - the bitwise OR of one or more of
TJ.FLAG_*java.lang.ExceptionTJExceptionpublic void decompress(java.awt.image.BufferedImage dstImage,
int flags)
- throws java.lang.Exception
+ throws TJException
BufferedImage instance.flags - the bitwise OR of one or more of
TJ.FLAG_*java.lang.ExceptionTJExceptionBufferedImage
instance containing the decompressed/decoded image.BufferedImage instance containing the
decompressed/decoded image.java.lang.ExceptionTJExceptionpublic void close() - throws java.io.IOException+ throws TJException
close in interface java.lang.AutoCloseablejava.io.IOExceptionTJExceptionpublic TJTransform(java.awt.Rectangle r,
int op,
int options,
- TJCustomFilter cf)
- throws java.lang.Exception
+ TJCustomFilter cf)
r - a Rectangle instance that specifies the cropping
region. See TJTransform(int, int, int, int, int, int, TJCustomFilter) for more
detail.op - one of the transform operations (OP_*)options - the bitwise OR of one or more of the transform options
- (OPT_*)cf - an instance of an object that implements the TJCustomFilter interface, or null if no custom filter is neededjava.lang.ExceptionOPT_*)cf - an instance of an object that implements the TJCustomFilter interface, or null if no custom filter is neededpublic TJTransformer() - throws java.lang.Exception+ throws TJException
java.lang.ExceptionTJExceptionpublic TJTransformer(byte[] jpegImage) - throws java.lang.Exception+ throws TJException
jpegImage with the newly created instance.jpegImage - JPEG image buffer (size of the JPEG image is assumed to
be the length of the array.) This buffer is not modified.java.lang.ExceptionTJExceptionpublic TJTransformer(byte[] jpegImage,
int imageSize)
- throws java.lang.Exception
+ throws TJException
imageSize bytes stored in
jpegImage with the newly created instance.jpegImage - JPEG image buffer. This buffer is not modified.imageSize - size of the JPEG image (in bytes)java.lang.ExceptionTJExceptionflags - the bitwise OR of one or more of
TJ.FLAG_*java.lang.ExceptionTJExceptionpublic TJDecompressor[] transform(TJTransform[] transforms, int flags) - throws java.lang.Exception+ throws TJException
TJDecompressor instances, each of
which has a transformed JPEG image associated with it.TJDecompressor instances, each of
which has a transformed JPEG image associated with it.java.lang.ExceptionTJExceptionpublic YUVImage(int width,
int[] strides,
int height,
- int subsamp)
- throws java.lang.Exception
+ int subsamp)
YUVImage instance backed by separate image
planes, and allocate memory for the image planes.width - width (in pixels) of the YUV imagestrides - an array of integers, each specifying the number of bytes
@@ -445,9 +444,7 @@ extends java.lang.Object
strides for all planes will be set to their respective plane widths. When
using this constructor, the stride for each plane must be equal to or
greater than the plane width.height - height (in pixels) of the YUV imagesubsamp - the level of chrominance subsampling to be used in the YUV
- image (one of TJ.SAMP_*)java.lang.ExceptionTJ.SAMP_*)
@@ -459,15 +456,12 @@ extends java.lang.Object
public YUVImage(int width,
int pad,
int height,
- int subsamp)
- throws java.lang.Exception
+ int subsamp)
YUVImage instance backed by a unified image
buffer, and allocate memory for the image buffer.width - width (in pixels) of the YUV imagepad - Each line of each plane in the YUV image buffer will be padded
to this number of bytes (must be a power of 2.)height - height (in pixels) of the YUV imagesubsamp - the level of chrominance subsampling to be used in the YUV
- image (one of TJ.SAMP_*)java.lang.ExceptionTJ.SAMP_*)
@@ -481,8 +475,7 @@ extends java.lang.Object
int width,
int[] strides,
int height,
- int subsamp)
- throws java.lang.Exception
+ int subsamp)
YUVImage instance from a set of existing image
planes.planes - an array of buffers representing the Y, U (Cb), and V (Cr)
@@ -503,9 +496,7 @@ extends java.lang.Object
to each plane or to specify that this YUVImage instance is a
subregion of a larger image (in which case, strides[i] should
be set to the plane width of plane i in the larger image.)height - height (in pixels) of the new YUV image (or subregion)subsamp - the level of chrominance subsampling used in the YUV
- image (one of TJ.SAMP_*)java.lang.ExceptionTJ.SAMP_*)
@@ -518,8 +509,7 @@ extends java.lang.Object
int width,
int pad,
int height,
- int subsamp)
- throws java.lang.Exception
+ int subsamp)
YUVImage instance from an existing unified image
buffer.yuvImage - image buffer that contains or will contain YUV planar
@@ -529,9 +519,7 @@ extends java.lang.Object
of the image format.)width - width (in pixels) of the YUV imagepad - the line padding used in the YUV image buffer. For
instance, if each line in each plane of the buffer is padded to the
nearest multiple of 4 bytes, then pad should be set to 4.height - height (in pixels) of the YUV imagesubsamp - the level of chrominance subsampling used in the YUV
- image (one of TJ.SAMP_*)java.lang.ExceptionTJ.SAMP_*)
@@ -553,8 +541,7 @@ extends java.lang.Object
int width,
int[] strides,
int height,
- int subsamp)
- throws java.lang.Exception
+ int subsamp)
YUVImage instance.planes - an array of buffers representing the Y, U (Cb), and V (Cr)
image planes (or just the Y plane, if the image is grayscale.) These
@@ -574,9 +561,7 @@ extends java.lang.Object
to each plane or to specify that this YUVImage image is a
subregion of a larger image (in which case, strides[i] should
be set to the plane width of plane i in the larger image.)height - height (in pixels) of the YUV image (or subregion)subsamp - the level of chrominance subsampling used in the YUV
- image (one of TJ.SAMP_*)java.lang.ExceptionTJ.SAMP_*)
@@ -589,8 +574,7 @@ extends java.lang.Object
int width,
int pad,
int height,
- int subsamp)
- throws java.lang.Exception
+ int subsamp)
YUVImage instance.yuvImage - image buffer that contains or will contain YUV planar
image data. Use TJ.bufSizeYUV(int, int, int, int) to determine the minimum size for
@@ -599,9 +583,7 @@ extends java.lang.Object
of the image format.)width - width (in pixels) of the YUV imagepad - the line padding used in the YUV image buffer. For
instance, if each line in each plane of the buffer is padded to the
nearest multiple of 4 bytes, then pad should be set to 4.height - height (in pixels) of the YUV imagesubsamp - the level of chrominance subsampling used in the YUV
- image (one of TJ.SAMP_*)java.lang.ExceptionTJ.SAMP_*)
@@ -704,13 +686,10 @@ extends java.lang.Object
public int getSize() - throws java.lang.Exception+
public int getSize()
java.lang.Exception