diff --git a/ChangeLog.txt b/ChangeLog.txt index e1069f5ec..65e64de04 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 f9f9e572c..0af8ae155 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 23e341294..475dd3feb 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 756211435..da0980789 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 @@ else if (argv[i].length() > 2 && 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 509ea5084..fecac06d0 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.Exception
public 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.Exception
componentID
- ID number of the image plane (0 = Y, 1 = U/Cb,
@@ -1145,9 +1135,7 @@ subsamp
- the level of chrominance subsampling used in the YUV
image (one of TJ.SAMP_*
)java.lang.Exception
public 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.Exception
public 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.Exception
public static TJScalingFactor[] getScalingFactors() - throws java.lang.Exception+
public static TJScalingFactor[] getScalingFactors()
java.lang.Exception
public TJCompressor() - throws java.lang.Exception+ throws TJException
java.lang.Exception
TJException
srcImage
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.Exception
TJException
TJCompressor(byte[], int, int, int, int, int, int)
instead.java.lang.Exception
TJException
srcImage
with the newly created
instance.setSourceImage(BufferedImage, int, int, int, int)
for descriptionheight
- see
setSourceImage(BufferedImage, int, int, int, int)
for descriptionjava.lang.Exception
TJException
srcImage
- image buffer containing RGB, grayscale, or CMYK pixels to
@@ -493,7 +493,7 @@ pixelFormat
- pixel format of the source image (one of
TJ.PF_*
)java.lang.Exception
TJException
setSourceImage(byte[], int, int, int, int, int, int)
instead.java.lang.Exception
TJException
srcImage
- a BufferedImage
instance containing RGB or
@@ -538,7 +538,7 @@ java.lang.Exception
TJException
public void setSourceImage(YUVImage srcImage) - throws java.lang.Exception+ throws TJException
srcImage
- YUV planar image to be compressed. This image is not
modified.java.lang.Exception
TJException
public 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 @@ flags
- the bitwise OR of one or more of
TJ.FLAG_*
java.lang.Exception
TJException
public byte[] compress(int flags) - throws java.lang.Exception+ throws TJException
flags
- the bitwise OR of one or more of
@@ -631,7 +631,7 @@ getCompressedSize()
to obtain the size of the JPEG image.java.lang.Exception
TJException
setSourceImage(BufferedImage, int, int, int, int)
and
compress(byte[], int)
instead.java.lang.Exception
TJException
@Deprecated public byte[] compress(java.awt.image.BufferedImage srcImage, int flags) - throws java.lang.Exception+ throws TJException
java.lang.Exception
TJException
public void encodeYUV(YUVImage dstImage, int flags) - throws java.lang.Exception+ throws TJException
YUVImage
instance. This method uses the accelerated color
@@ -688,7 +688,7 @@ flags
- the bitwise OR of one or more of
TJ.FLAG_*
java.lang.Exception
TJException
@Deprecated public void encodeYUV(byte[] dstBuf, int flags) - throws java.lang.Exception+ throws TJException
encodeYUV(YUVImage, int)
instead.java.lang.Exception
TJException
public YUVImage encodeYUV(int pad, int flags) - throws java.lang.Exception+ throws TJException
YUVImage
instance containing the encoded image. This method
@@ -727,7 +727,7 @@ TJ.FLAG_*
java.lang.Exception
TJException
public YUVImage encodeYUV(int[] strides, int flags) - throws java.lang.Exception+ throws TJException
YUVImage
instance containing the encoded image planes. This
@@ -755,7 +755,7 @@ TJ.FLAG_*
java.lang.Exception
TJException
@Deprecated public byte[] encodeYUV(int flags) - throws java.lang.Exception+ throws TJException
encodeYUV(int, int)
instead.java.lang.Exception
TJException
setSourceImage(BufferedImage, int, int, int, int)
and
encodeYUV(byte[], int)
instead.java.lang.Exception
TJException
@Deprecated public byte[] encodeYUV(java.awt.image.BufferedImage srcImage, int flags) - throws java.lang.Exception+ throws TJException
java.lang.Exception
TJException
public void close() - throws java.io.IOException+ throws TJException
close
in interface java.lang.AutoCloseable
java.io.IOException
TJException
transforms
array that was passed to TJTransformer.transform()
.transform
- a TJTransform
instance that specifies the
parameters and/or cropping region for this transformjava.lang.Exception
TJException
public 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.Exception
TJException
public 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.Exception
TJException
public 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.Exception
TJException
public 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.Exception
TJException
@Deprecated public void setJPEGImage(byte[] jpegImage, int imageSize) - throws java.lang.Exception+ throws TJException
setSourceImage(byte[], int)
instead.java.lang.Exception
TJException
public 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.Exception
public int getScaledWidth(int desiredWidth, - int desiredHeight) - throws java.lang.Exception+ int desiredHeight)
java.lang.Exception
public int getScaledHeight(int desiredWidth, - int desiredHeight) - throws java.lang.Exception+ int desiredHeight)
java.lang.Exception
TJ.PF_*
)flags
- the bitwise OR of one or more of
TJ.FLAG_*
java.lang.Exception
TJException
decompress(byte[], int, int, int, int, int, int, int)
instead.java.lang.Exception
TJException
desiredWidth
- see
@@ -887,7 +878,7 @@ TJ.FLAG_*
java.lang.Exception
TJException
public void decompressToYUV(YUVImage dstImage, int flags) - throws java.lang.Exception+ throws TJException
YUVImage
instance. This method performs JPEG decompression
@@ -913,7 +904,7 @@ flags
- the bitwise OR of one or more of
TJ.FLAG_*
java.lang.Exception
TJException
@Deprecated public void decompressToYUV(byte[] dstBuf, int flags) - throws java.lang.Exception+ throws TJException
decompressToYUV(YUVImage, int)
instead.java.lang.Exception
TJException
YUVImage
instance containing the decompressed image planes.
@@ -971,7 +962,7 @@ TJ.FLAG_*
java.lang.Exception
TJException
YUVImage
instance containing the decompressed image. This
@@ -1010,7 +1001,7 @@ TJ.FLAG_*
java.lang.Exception
TJException
@Deprecated public byte[] decompressToYUV(int flags) - throws java.lang.Exception+ throws TJException
decompressToYUV(int, int, int, int)
instead.java.lang.Exception
TJException
TJ.PF_*
)flags
- the bitwise OR of one or more of
TJ.FLAG_*
java.lang.Exception
TJException
public 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.Exception
TJException
BufferedImage
instance containing the decompressed/decoded image.BufferedImage
instance containing the
decompressed/decoded image.java.lang.Exception
TJException
public void close() - throws java.io.IOException+ throws TJException
close
in interface java.lang.AutoCloseable
java.io.IOException
TJException
public 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.Exception
OPT_*
)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.Exception
TJException
public 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.Exception
TJException
public 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.Exception
TJException
public void transform(byte[][] dstBufs, TJTransform[] transforms, int flags) - throws java.lang.Exception+ throws TJException
flags
- the bitwise OR of one or more of
TJ.FLAG_*
java.lang.Exception
TJException
public 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.Exception
TJException
public 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 @@ 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.Exception
TJ.SAMP_*
)
@@ -459,15 +456,12 @@ 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.Exception
TJ.SAMP_*
)
@@ -481,8 +475,7 @@ 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 @@ 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.Exception
TJ.SAMP_*
)
@@ -518,8 +509,7 @@ YUVImage
instance from an existing unified image
buffer.yuvImage
- image buffer that contains or will contain YUV planar
@@ -529,9 +519,7 @@ 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.Exception
TJ.SAMP_*
)
@@ -553,8 +541,7 @@ 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 @@ 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.Exception
TJ.SAMP_*
)
@@ -589,8 +574,7 @@ 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 @@ 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.Exception
TJ.SAMP_*
)
@@ -704,13 +686,10 @@ public int getSize() - throws java.lang.Exception+
public int getSize()
java.lang.Exception