More Java API cleanup

git-svn-id: svn+ssh://svn.code.sf.net/p/libjpeg-turbo/code/trunk@519 632fc199-4ca6-4c93-a231-07263d6284db
This commit is contained in:
DRC
2011-03-16 00:02:53 +00:00
parent 92549de2c2
commit 2c74e5124d
13 changed files with 391 additions and 379 deletions

View File

@@ -84,7 +84,8 @@ final public class TJ {
* Returns the MCU block width for the given level of chrominance
* subsampling.
*
* @param subsamp the level of chrominance subsampling
* @param subsamp the level of chrominance subsampling (one of
* <code>SAMP_*</code>)
*
* @return the MCU block width for the given level of chrominance subsampling
*/
@@ -103,7 +104,8 @@ final public class TJ {
* Returns the MCU block height for the given level of chrominance
* subsampling.
*
* @param subsamp the level of chrominance subsampling
* @param subsamp the level of chrominance subsampling (one of
* <code>SAMP_*</code>)
*
* @return the MCU block height for the given level of chrominance
* subsampling
@@ -167,8 +169,10 @@ final public class TJ {
/**
* Returns the pixel size (in bytes) for the given pixel format.
* @param pixelFormat the pixel format
* Returns the pixel size (in bytes) of the given pixel format.
*
* @param pixelFormat the pixel format (one of <code>PF_*</code>)
*
* @return the pixel size (in bytes) of the given pixel format
*/
public static int getPixelSize(int pixelFormat) throws Exception {
@@ -183,65 +187,68 @@ final public class TJ {
/**
* Returns the red shift for the given pixel format. For instance, if a
* pixel of format <code>TJ.PF_BGRX</code> is stored as an int, then the red
* component will be
* <code>(pixel >> TJ.getRedShift(TJ.PF_BGRX)) & 0xFF</code>.
* For the given pixel format, returns the number of bytes that the red
* component is offset from the start of the pixel. For instance, if a pixel
* of format <code>TJ.PF_BGRX</code> is stored in <code>char pixel[]</code>,
* then the red component will be
* <code>pixel[TJ.getRedOffset(TJ.PF_BGRX)]</code>.
*
* @param pixelFormat the pixel format
* @param pixelFormat the pixel format (one of <code>PF_*</code>)
*
* @return the red shift for the given pixel format
* @return the red offset for the given pixel format
*/
public static int getRedShift(int pixelFormat) throws Exception {
public static int getRedOffset(int pixelFormat) throws Exception {
if(pixelFormat < 0 || pixelFormat >= NUMPF)
throw new Exception("Invalid pixel format");
return redShift[pixelFormat];
return redOffset[pixelFormat];
}
final private static int redShift[] = {
0, 16, 0, 16, 24, 8, 0
final private static int redOffset[] = {
0, 2, 0, 2, 3, 1, 0
};
/**
* Returns the green shift for the given pixel format. For instance, if a
* pixel of format <code>TJ.PF_BGRX</code> is stored as an int, then the
* green component will be
* <code>(pixel >> TJ.getGreenShift(TJ.PF_BGRX)) & 0xFF</code>.
* For the given pixel format, returns the number of bytes that the green
* component is offset from the start of the pixel. For instance, if a pixel
* of format <code>TJ.PF_BGRX</code> is stored in <code>char pixel[]</code>,
* then the green component will be
* <code>pixel[TJ.getGreenOffset(TJ.PF_BGRX)]</code>.
*
* @param pixelFormat the pixel format
* @param pixelFormat the pixel format (one of <code>PF_*</code>)
*
* @return the green shift for the given pixel format
* @return the green offset for the given pixel format
*/
public static int getGreenShift(int pixelFormat) throws Exception {
public static int getGreenOffset(int pixelFormat) throws Exception {
if(pixelFormat < 0 || pixelFormat >= NUMPF)
throw new Exception("Invalid pixel format");
return greenShift[pixelFormat];
return greenOffset[pixelFormat];
}
final private static int greenShift[] = {
8, 8, 8, 8, 16, 16, 0
final private static int greenOffset[] = {
1, 1, 1, 1, 2, 2, 0
};
/**
* Returns the blue shift for the given pixel format. For instance, if a
* pixel of format <code>TJ.PF_BGRX</code> is stored as an int, then the blue
* component will be
* <code>(pixel >> TJ.getBlueShift(TJ.PF_BGRX)) & 0xFF</code>.
* For the given pixel format, returns the number of bytes that the blue
* component is offset from the start of the pixel. For instance, if a pixel
* of format <code>TJ.PF_BGRX</code> is stored in <code>char pixel[]</code>,
* then the blue component will be
* <code>pixel[TJ.getBlueOffset(TJ.PF_BGRX)]</code>.
*
* @param pixelFormat the pixel format
* @param pixelFormat the pixel format (one of <code>PF_*</code>)
*
* @return the blue shift for the given pixel format
* @return the blue offset for the given pixel format
*/
public static int getBlueShift(int pixelFormat) throws Exception {
public static int getBlueOffset(int pixelFormat) throws Exception {
if(pixelFormat < 0 || pixelFormat >= NUMPF)
throw new Exception("Invalid pixel format");
return blueShift[pixelFormat];
return blueOffset[pixelFormat];
}
final private static int blueShift[] = {
16, 0, 16, 0, 8, 24, 0
final private static int blueOffset[] = {
2, 0, 2, 0, 1, 3, 0
};
@@ -292,8 +299,8 @@ final public class TJ {
throws Exception;
/**
* Returns the size of the buffer required to hold a YUV planar image with
* the given width, height, and level of chrominance subsampling.
* Returns the size of the buffer (in bytes) required to hold a YUV planar
* image with the given width, height, and level of chrominance subsampling.
*
* @param width the width (in pixels) of the YUV image
*
@@ -302,8 +309,8 @@ final public class TJ {
* @param subsamp the level of chrominance subsampling used in the YUV
* image
*
* @return the size of the buffer required to hold a YUV planar image with
* the given width, height, and level of chrominance subsampling
* @return the size of the buffer (in bytes) required to hold a YUV planar
* image with the given width, height, and level of chrominance subsampling
*/
public native static int bufSizeYUV(int width, int height,
int subsamp)

View File

@@ -35,6 +35,9 @@ import java.awt.image.*;
*/
public class TJCompressor {
private final static String NO_ASSOC_ERROR =
"No source image is associated with this instance";
/**
* Create a TurboJPEG compressor instance.
*/
@@ -44,27 +47,28 @@ public class TJCompressor {
/**
* Create a TurboJPEG compressor instance and associate the uncompressed
* source image stored in <code>buf</code> with the newly-created instance.
* source image stored in <code>srcImage</code> with the newly-created
* instance.
*
* @param buf see {@link #setBitmapBuffer} for description
* @param srcImage see {@link #setSourceImage} for description
*
* @param width see {@link #setBitmapBuffer} for description
* @param width see {@link #setSourceImage} for description
*
* @param pitch see {@link #setBitmapBuffer} for description
* @param pitch see {@link #setSourceImage} for description
*
* @param height see {@link #setBitmapBuffer} for description
* @param height see {@link #setSourceImage} for description
*
* @param pixelFormat see {@link #setBitmapBuffer} for description
* @param pixelFormat see {@link #setSourceImage} for description
*/
public TJCompressor(byte[] buf, int width, int pitch, int height,
public TJCompressor(byte[] srcImage, int width, int pitch, int height,
int pixelFormat) throws Exception {
setBitmapBuffer(buf, width, pitch, height, pixelFormat);
setSourceImage(srcImage, width, pitch, height, pixelFormat);
}
/**
* Associate an uncompressed source image with this compressor instance.
*
* @param buf image buffer containing RGB or grayscale pixels to be
* @param srcImage image buffer containing RGB or grayscale pixels to be
* compressed
*
* @param width width (in pixels) of the source image
@@ -80,32 +84,32 @@ public class TJCompressor {
*
* @param height height (in pixels) of the source image
*
* @param pixelFormat pixel format of the source image (see
* {@link TJ})
* @param pixelFormat pixel format of the source image (one of
* {@link TJ TJ.PF_*})
*/
public void setBitmapBuffer(byte[] buf, int width, int pitch, int height,
int pixelFormat) throws Exception {
public void setSourceImage(byte[] srcImage, int width, int pitch,
int height, int pixelFormat) throws Exception {
if(handle == 0) init();
if(buf == null || width < 1 || height < 1 || pitch < 0 || pixelFormat < 0
|| pixelFormat >= TJ.NUMPFOPT)
throw new Exception("Invalid argument in setBitmapBuffer()");
bitmapBuf = buf;
bitmapWidth = width;
if(pitch == 0) bitmapPitch = width * TJ.getPixelSize(pixelFormat);
else bitmapPitch = pitch;
bitmapHeight = height;
bitmapPixelFormat = pixelFormat;
if(srcImage == null || width < 1 || height < 1 || pitch < 0
|| pixelFormat < 0 || pixelFormat >= TJ.NUMPF)
throw new Exception("Invalid argument in setSourceImage()");
srcBuf = srcImage;
srcWidth = width;
if(pitch == 0) srcPitch = width * TJ.getPixelSize(pixelFormat);
else srcPitch = pitch;
srcHeight = height;
srcPixelFormat = pixelFormat;
}
/**
* Set the level of chrominance subsampling for subsequent compress/encode
* operations.
*
* @param newSubsamp the new level of chrominance subsampling (see
* {@link TJ})
* @param newSubsamp the new level of chrominance subsampling (one of
* {@link TJ TJ.SAMP_*})
*/
public void setSubsamp(int newSubsamp) throws Exception {
if(newSubsamp < 0 || newSubsamp >= TJ.NUMSAMPOPT)
if(newSubsamp < 0 || newSubsamp >= TJ.NUMSAMP)
throw new Exception("Invalid argument in setSubsamp()");
subsamp = newSubsamp;
}
@@ -130,34 +134,32 @@ public class TJCompressor {
* {@link TJ#bufSize} to determine the maximum size for this buffer based on
* the image width and height.
*
* @param flags the bitwise OR of one or more of the flags described in
* {@link TJ}
* @param flags the bitwise OR of one or more of {@link TJ TJ.FLAG_*}
*/
public void compress(byte[] dstBuf, int flags) throws Exception {
if(dstBuf == null || flags < 0)
throw new Exception("Invalid argument in compress()");
if(bitmapBuf == null) throw new Exception("Bitmap buffer not initialized");
if(srcBuf == null) throw new Exception(NO_ASSOC_ERROR);
if(jpegQuality < 0) throw new Exception("JPEG Quality not set");
if(subsamp < 0) throw new Exception("Subsampling level not set");
compressedSize = compress(bitmapBuf, bitmapWidth, bitmapPitch,
bitmapHeight, bitmapPixelFormat, dstBuf, subsamp, jpegQuality, flags);
compressedSize = compress(srcBuf, srcWidth, srcPitch,
srcHeight, srcPixelFormat, dstBuf, subsamp, jpegQuality, flags);
}
/**
* Compress the uncompressed source image associated with this compressor
* instance and return a buffer containing a JPEG image.
*
* @param flags the bitwise OR of one or more of the flags described in
* {@link TJ}
* @param flags the bitwise OR of one or more of {@link TJ TJ.FLAG_*}
*
* @return a buffer containing a JPEG image. The length of this buffer will
* not be equal to the size of the JPEG image. Use {@link
* #getCompressedSize} to obtain the size of the JPEG image.
*/
public byte[] compress(int flags) throws Exception {
if(bitmapWidth < 1 || bitmapHeight < 1)
throw new Exception("Bitmap buffer not initialized");
byte[] buf = new byte[TJ.bufSize(bitmapWidth, bitmapHeight)];
if(srcWidth < 1 || srcHeight < 1)
throw new Exception(NO_ASSOC_ERROR);
byte[] buf = new byte[TJ.bufSize(srcWidth, srcHeight)];
compress(buf, flags);
return buf;
}
@@ -173,8 +175,7 @@ public class TJCompressor {
* {@link TJ#bufSize} to determine the maximum size for this buffer based on
* the image width and height.
*
* @param flags the bitwise OR of one or more of the flags described in
* {@link TJ}
* @param flags the bitwise OR of one or more of {@link TJ TJ.FLAG_*}
*/
public void compress(BufferedImage srcImage, byte[] dstBuf, int flags)
throws Exception {
@@ -228,8 +229,7 @@ public class TJCompressor {
* @param srcImage a <code>BufferedImage</code> instance containing RGB or
* grayscale pixels to be compressed
*
* @param flags the bitwise OR of one or more of the flags described in
* {@link TJ}
* @param flags the bitwise OR of one or more of {@link TJ TJ.FLAG_*}
*
* @return a buffer containing a JPEG image. The length of this buffer will
* not be equal to the size of the JPEG image. Use {@link
@@ -246,7 +246,7 @@ public class TJCompressor {
/**
* Encode the uncompressed source image associated with this compressor
* instance and output a YUV planar image to the given destination buffer.
* This function uses the accelerated color conversion routines in
* This method uses the accelerated color conversion routines in
* TurboJPEG's underlying codec to produce a planar YUV image that is
* suitable for direct video display. Specifically, if the chrominance
* components are subsampled along the horizontal dimension, then the width
@@ -262,17 +262,16 @@ public class TJCompressor {
* {@link TJ#bufSizeYUV} to determine the appropriate size for this buffer
* based on the image width, height, and level of chrominance subsampling.
*
* @param flags the bitwise OR of one or more of the flags described in
* {@link TJ}
* @param flags the bitwise OR of one or more of {@link TJ TJ.FLAG_*}
*/
public void encodeYUV(byte[] dstBuf, int flags) throws Exception {
if(dstBuf == null || flags < 0)
throw new Exception("Invalid argument in compress()");
if(bitmapBuf == null) throw new Exception("Bitmap buffer not initialized");
if(srcBuf == null) throw new Exception(NO_ASSOC_ERROR);
if(subsamp < 0) throw new Exception("Subsampling level not set");
encodeYUV(bitmapBuf, bitmapWidth, bitmapPitch, bitmapHeight,
bitmapPixelFormat, dstBuf, subsamp, flags);
compressedSize = TJ.bufSizeYUV(bitmapWidth, bitmapHeight, subsamp);
encodeYUV(srcBuf, srcWidth, srcPitch, srcHeight,
srcPixelFormat, dstBuf, subsamp, flags);
compressedSize = TJ.bufSizeYUV(srcWidth, srcHeight, subsamp);
}
/**
@@ -280,16 +279,15 @@ public class TJCompressor {
* instance and return a buffer containing a YUV planar image. See
* {@link #encodeYUV(byte[], int)} for more detail.
*
* @param flags the bitwise OR of one or more of the flags described in
* {@link TJ}
* @param flags the bitwise OR of one or more of {@link TJ TJ.FLAG_*}
*
* @return a buffer containing a YUV planar image
*/
public byte[] encodeYUV(int flags) throws Exception {
if(bitmapWidth < 1 || bitmapHeight < 1)
throw new Exception("Bitmap buffer not initialized");
if(srcWidth < 1 || srcHeight < 1)
throw new Exception(NO_ASSOC_ERROR);
if(subsamp < 0) throw new Exception("Subsampling level not set");
byte[] buf = new byte[TJ.bufSizeYUV(bitmapWidth, bitmapHeight, subsamp)];
byte[] buf = new byte[TJ.bufSizeYUV(srcWidth, srcHeight, subsamp)];
encodeYUV(buf, flags);
return buf;
}
@@ -306,8 +304,7 @@ public class TJCompressor {
* {@link TJ#bufSizeYUV} to determine the appropriate size for this buffer
* based on the image width, height, and level of chrominance subsampling.
*
* @param flags the bitwise OR of one or more of the flags described in
* {@link TJ}
* @param flags the bitwise OR of one or more of {@link TJ TJ.FLAG_*}
*/
public void encodeYUV(BufferedImage srcImage, byte[] dstBuf, int flags)
throws Exception {
@@ -362,8 +359,7 @@ public class TJCompressor {
* @param srcImage a <code>BufferedImage</code> instance containing RGB or
* grayscale pixels to be encoded
*
* @param flags the bitwise OR of one or more of the flags described in
* {@link TJ}
* @param flags the bitwise OR of one or more of {@link TJ TJ.FLAG_*}
*
* @return a buffer containing a YUV planar image
*/
@@ -431,11 +427,11 @@ public class TJCompressor {
}
private long handle = 0;
private byte[] bitmapBuf = null;
private int bitmapWidth = 0;
private int bitmapHeight = 0;
private int bitmapPitch = 0;
private int bitmapPixelFormat = -1;
private byte[] srcBuf = null;
private int srcWidth = 0;
private int srcHeight = 0;
private int srcPitch = 0;
private int srcPixelFormat = -1;
private int subsamp = -1;
private int jpegQuality = -1;
private int compressedSize = 0;

View File

@@ -35,6 +35,9 @@ import java.awt.image.*;
*/
public class TJDecompressor {
private final static String NO_ASSOC_ERROR =
"No JPEG image is associated with this instance";
/**
* Create a TurboJPEG decompresssor instance.
*/
@@ -46,12 +49,12 @@ public class TJDecompressor {
* Create a TurboJPEG decompressor instance and associate the JPEG image
* stored in <code>jpegImage</code> with the newly-created instance.
*
* @param jpegImage JPEG image buffer (size of JPEG image is assumed to be
* the length of the buffer)
* @param jpegImage JPEG image buffer (size of the JPEG image is assumed to
* be the length of the array)
*/
public TJDecompressor(byte[] jpegImage) throws Exception {
init();
setJPEGBuffer(jpegImage, jpegImage.length);
setJPEGImage(jpegImage, jpegImage.length);
}
/**
@@ -61,25 +64,25 @@ public class TJDecompressor {
*
* @param jpegImage JPEG image buffer
*
* @param imageSize size of JPEG image (in bytes)
* @param imageSize size of the JPEG image (in bytes)
*/
public TJDecompressor(byte[] jpegImage, int imageSize) throws Exception {
init();
setJPEGBuffer(jpegImage, imageSize);
setJPEGImage(jpegImage, imageSize);
}
/**
* Associate a JPEG image buffer with this decompressor instance. This
* buffer will be used as the source buffer for subsequent decompress
* operations.
* Associate the JPEG image of length <code>imageSize</code> bytes stored in
* <code>jpegImage</code> with this decompressor instance. This image will
* be used as the source image for subsequent decompress operations.
*
* @param jpegImage JPEG image buffer
*
* @param imageSize size of JPEG image (in bytes)
* @param imageSize size of the JPEG image (in bytes)
*/
public void setJPEGBuffer(byte[] jpegImage, int imageSize) throws Exception {
public void setJPEGImage(byte[] jpegImage, int imageSize) throws Exception {
if(jpegImage == null || imageSize < 1)
throw new Exception("Invalid argument in setJPEGBuffer()");
throw new Exception("Invalid argument in setJPEGImage()");
jpegBuf = jpegImage;
jpegBufSize = imageSize;
decompressHeader(jpegBuf, jpegBufSize);
@@ -93,7 +96,7 @@ public class TJDecompressor {
* instance
*/
public int getWidth() throws Exception {
if(jpegWidth < 1) throw new Exception("JPEG buffer not initialized");
if(jpegWidth < 1) throw new Exception(NO_ASSOC_ERROR);
return jpegWidth;
}
@@ -105,7 +108,7 @@ public class TJDecompressor {
* instance
*/
public int getHeight() throws Exception {
if(jpegHeight < 1) throw new Exception("JPEG buffer not initialized");
if(jpegHeight < 1) throw new Exception(NO_ASSOC_ERROR);
return jpegHeight;
}
@@ -117,8 +120,8 @@ public class TJDecompressor {
* associated with this decompressor instance
*/
public int getSubsamp() throws Exception {
if(jpegSubsamp < 0) throw new Exception("JPEG buffer not initialized");
if(jpegSubsamp >= TJ.NUMSAMPOPT)
if(jpegSubsamp < 0) throw new Exception(NO_ASSOC_ERROR);
if(jpegSubsamp >= TJ.NUMSAMP)
throw new Exception("JPEG header information is invalid");
return jpegSubsamp;
}
@@ -129,7 +132,7 @@ public class TJDecompressor {
* @return the JPEG image buffer associated with this decompressor instance
*/
public byte[] getJPEGBuf() throws Exception {
if(jpegBuf == null) throw new Exception("JPEG buffer not initialized");
if(jpegBuf == null) throw new Exception(NO_ASSOC_ERROR);
return jpegBuf;
}
@@ -141,7 +144,7 @@ public class TJDecompressor {
* decompressor instance
*/
public int getJPEGSize() throws Exception {
if(jpegBufSize < 1) throw new Exception("JPEG buffer not initialized");
if(jpegBufSize < 1) throw new Exception(NO_ASSOC_ERROR);
return jpegBufSize;
}
@@ -152,12 +155,14 @@ public class TJDecompressor {
* height.
*
* @param desiredWidth desired width (in pixels) of the decompressed image.
* If this is set to 0, then only the height will be considered when
* determining the scaled image size.
* Setting this to 0 is the same as setting it to the width of the JPEG image
* (in other words, the width will not be considered when determining the
* scaled image size.)
*
* @param desiredHeight desired height (in pixels) of the decompressed image.
* If this is set to 0, then only the width will be considered when
* determining the scaled image size.
* Setting this to 0 is the same as setting it to the height of the JPEG
* image (in other words, the height will not be considered when determining
* the scaled image size.)
*
* @return the width of the largest scaled down image that the TurboJPEG
* decompressor can generate without exceeding the desired image width and
@@ -166,7 +171,7 @@ public class TJDecompressor {
public int getScaledWidth(int desiredWidth, int desiredHeight)
throws Exception {
if(jpegWidth < 1 || jpegHeight < 1)
throw new Exception("JPEG buffer not initialized");
throw new Exception(NO_ASSOC_ERROR);
if(desiredWidth < 0 || desiredHeight < 0)
throw new Exception("Invalid argument in getScaledWidth()");
TJ.ScalingFactor sf[] = TJ.getScalingFactors();
@@ -190,12 +195,14 @@ public class TJDecompressor {
* height.
*
* @param desiredWidth desired width (in pixels) of the decompressed image.
* If this is set to 0, then only the height will be considered when
* determining the scaled image size.
* Setting this to 0 is the same as setting it to the width of the JPEG image
* (in other words, the width will not be considered when determining the
* scaled image size.)
*
* @param desiredHeight desired height (in pixels) of the decompressed image.
* If this is set to 0, then only the width will be considered when
* determining the scaled image size.
* Setting this to 0 is the same as setting it to the height of the JPEG
* image (in other words, the height will not be considered when determining
* the scaled image size.)
*
* @return the height of the largest scaled down image that the TurboJPEG
* decompressor can generate without exceeding the desired image width and
@@ -204,7 +211,7 @@ public class TJDecompressor {
public int getScaledHeight(int desiredWidth, int desiredHeight)
throws Exception {
if(jpegWidth < 1 || jpegHeight < 1)
throw new Exception("JPEG buffer not initialized");
throw new Exception(NO_ASSOC_ERROR);
if(desiredWidth < 0 || desiredHeight < 0)
throw new Exception("Invalid argument in getScaledHeight()");
TJ.ScalingFactor sf[] = TJ.getScalingFactors();
@@ -236,8 +243,9 @@ public class TJDecompressor {
* If the desired image dimensions are smaller than the dimensions of the
* JPEG image being decompressed, then TurboJPEG will use scaling in the JPEG
* decompressor to generate the largest possible image that will fit within
* the desired dimensions. If desiredWidth is set to 0, then only the height
* will be considered when determining the scaled image size.
* the desired dimensions. Setting this to 0 is the same as setting it to
* the width of the JPEG image (in other words, the width will not be
* considered when determining the scaled image size.)
*
* @param pitch bytes per line of the destination image. Normally, this
* should be set to <code>scaledWidth * TJ.pixelSize(pixelFormat)</code> if
@@ -245,26 +253,26 @@ public class TJDecompressor {
* pad each line of the decompressed image to a 4-byte boundary. NOTE:
* <code>scaledWidth = ceil(jpegWidth * scalingFactor)</code>. Setting this
* parameter to 0 is the equivalent of setting it to
* <code>scaledWidth * pixelSize</code>.
* <code>scaledWidth * TJ.pixelSize(pixelFormat)</code>.
*
* @param desiredHeight desired height (in pixels) of the decompressed image.
* If the desired image dimensions are smaller than the dimensions of the
* JPEG image being decompressed, then TurboJPEG will use scaling in the JPEG
* decompressor to generate the largest possible image that will fit within
* the desired dimensions. If desiredHeight is set to 0, then only the
* width will be considered when determining the scaled image size.
* the desired dimensions. Setting this to 0 is the same as setting it to
* the height of the JPEG image (in other words, the height will not be
* considered when determining the scaled image size.)
*
* @param pixelFormat Pixel format of the decompressed image (see
* {@link TJ})
* @param pixelFormat pixel format of the decompressed image (one of
* {@link TJ TJ.PF_*})
*
* @param flags the bitwise OR of one or more of the flags described in
* {@link TJ}
* @param flags the bitwise OR of one or more of {@link TJ TJ.FLAG_*}
*/
public void decompress(byte[] dstBuf, int desiredWidth, int pitch,
int desiredHeight, int pixelFormat, int flags) throws Exception {
if(jpegBuf == null) throw new Exception("JPEG buffer not initialized");
if(jpegBuf == null) throw new Exception(NO_ASSOC_ERROR);
if(dstBuf == null || desiredWidth < 0 || pitch < 0 || desiredHeight < 0
|| pixelFormat < 0 || pixelFormat >= TJ.NUMPFOPT || flags < 0)
|| pixelFormat < 0 || pixelFormat >= TJ.NUMPF || flags < 0)
throw new Exception("Invalid argument in decompress()");
decompress(jpegBuf, jpegBufSize, dstBuf, desiredWidth, pitch,
desiredHeight, pixelFormat, flags);
@@ -283,18 +291,17 @@ public class TJDecompressor {
* @param desiredHeight see
* {@link #decompress(byte[], int, int, int, int, int)} for description
*
* @param pixelFormat Pixel format of the decompressed image (see
* {@link TJ})
* @param pixelFormat pixel format of the decompressed image (one of
* {@link TJ TJ.PF_*})
*
* @param flags the bitwise OR of one or more of the flags described in
* {@link TJ}
* @param flags the bitwise OR of one or more of {@link TJ TJ.FLAG_*}
*
* @return a buffer containing the decompressed image
*/
public byte[] decompress(int desiredWidth, int pitch, int desiredHeight,
int pixelFormat, int flags) throws Exception {
if(desiredWidth < 0 || pitch < 0 || desiredHeight < 0
|| pixelFormat < 0 || pixelFormat >= TJ.NUMPFOPT || flags < 0)
|| pixelFormat < 0 || pixelFormat >= TJ.NUMPF || flags < 0)
throw new Exception("Invalid argument in decompress()");
int pixelSize = TJ.getPixelSize(pixelFormat);
int scaledWidth = getScaledWidth(desiredWidth, desiredHeight);
@@ -320,11 +327,10 @@ public class TJDecompressor {
* {@link TJ#bufSizeYUV} to determine the appropriate size for this buffer
* based on the image width, height, and level of chrominance subsampling.
*
* @param flags the bitwise OR of one or more of the flags described in
* {@link TJ}
* @param flags the bitwise OR of one or more of {@link TJ TJ.FLAG_*}
*/
public void decompressToYUV(byte[] dstBuf, int flags) throws Exception {
if(jpegBuf == null) throw new Exception("JPEG buffer not initialized");
if(jpegBuf == null) throw new Exception(NO_ASSOC_ERROR);
if(dstBuf == null || flags < 0)
throw new Exception("Invalid argument in decompressToYUV()");
decompressToYUV(jpegBuf, jpegBufSize, dstBuf, flags);
@@ -336,8 +342,7 @@ public class TJDecompressor {
* instance and return a buffer containing a YUV planar image. See {@link
* #decompressToYUV(byte[], int)} for more detail.
*
* @param flags the bitwise OR of one or more of the flags described in
* {@link TJ}
* @param flags the bitwise OR of one or more of {@link TJ TJ.FLAG_*}
*
* @return a buffer containing a YUV planar image
*/
@@ -345,8 +350,8 @@ public class TJDecompressor {
if(flags < 0)
throw new Exception("Invalid argument in decompressToYUV()");
if(jpegWidth < 1 || jpegHeight < 1 || jpegSubsamp < 0)
throw new Exception("JPEG buffer not initialized");
if(jpegSubsamp >= TJ.NUMSAMPOPT)
throw new Exception(NO_ASSOC_ERROR);
if(jpegSubsamp >= TJ.NUMSAMP)
throw new Exception("JPEG header information is invalid");
byte[] buf = new byte[TJ.bufSizeYUV(jpegWidth, jpegHeight, jpegSubsamp)];
decompressToYUV(buf, flags);
@@ -361,8 +366,7 @@ public class TJDecompressor {
* @param dstImage a <code>BufferedImage</code> instance which will receive
* the decompressed image
*
* @param flags the bitwise OR of one or more of the flags described in
* {@link TJ}
* @param flags the bitwise OR of one or more of {@link TJ TJ.FLAG_*}
*/
public void decompress(BufferedImage dstImage, int flags) throws Exception {
if(dstImage == null || flags < 0)
@@ -393,7 +397,7 @@ public class TJDecompressor {
int pitch = sm.getScanlineStride();
DataBufferInt db = (DataBufferInt)wr.getDataBuffer();
int[] buf = db.getData();
if(jpegBuf == null) throw new Exception("JPEG buffer not initialized");
if(jpegBuf == null) throw new Exception(NO_ASSOC_ERROR);
decompress(jpegBuf, jpegBufSize, buf, scaledWidth, pitch, scaledHeight,
pixelFormat, flags);
}
@@ -421,11 +425,11 @@ public class TJDecompressor {
* @param desiredHeight see
* {@link #decompress(byte[], int, int, int, int, int)} for description
*
* @param bufferedImageType the image type of the <code>BufferedImage</code>
* instance to create (for instance, <code>BufferedImage.TYPE_INT_RGB</code>)
* @param bufferedImageType the image type of the newly-created
* <code>BufferedImage</code> instance (for instance,
* <code>BufferedImage.TYPE_INT_RGB</code>)
*
* @param flags the bitwise OR of one or more of the flags described in
* {@link TJ}
* @param flags the bitwise OR of one or more of {@link TJ TJ.FLAG_*}
*
* @return a <code>BufferedImage</code> instance containing the
* decompressed image

View File

@@ -155,8 +155,8 @@ public class TJTransform extends Rectangle {
* Create a new lossless transform instance with the given parameters.
*
* @param r a <code>Rectangle</code> instance which specifies the cropping
* region. See {@link #TJTransform(int, int, int, int, int, int)} for a
* description of the cropping region.
* region. See {@link #TJTransform(int, int, int, int, int, int)} for more
* detail.
*
* @param op one of the transform operations (<code>OP_*</code>)
*

View File

@@ -44,12 +44,12 @@ public class TJTransformer extends TJDecompressor {
* Create a TurboJPEG lossless transformer instance and associate the JPEG
* image stored in <code>jpegImage</code> with the newly-created instance.
*
* @param jpegImage JPEG image buffer (size of JPEG image is assumed to be
* the length of the buffer)
* @param jpegImage JPEG image buffer (size of the JPEG image is assumed to
* be the length of the array)
*/
public TJTransformer(byte[] jpegImage) throws Exception {
init();
setJPEGBuffer(jpegImage, jpegImage.length);
setJPEGImage(jpegImage, jpegImage.length);
}
/**
@@ -59,11 +59,11 @@ public class TJTransformer extends TJDecompressor {
*
* @param jpegImage JPEG image buffer
*
* @param imageSize size of JPEG image (in bytes)
* @param imageSize size of the JPEG image (in bytes)
*/
public TJTransformer(byte[] jpegImage, int imageSize) throws Exception {
init();
setJPEGBuffer(jpegImage, imageSize);
setJPEGImage(jpegImage, imageSize);
}
/**
@@ -75,22 +75,21 @@ public class TJTransformer extends TJDecompressor {
* image, transforming it, and re-compressing it, lossless transforms are not
* free. Each lossless transform requires reading and Huffman decoding all
* of the coefficients in the source image, regardless of the size of the
* destination image. Thus, this function provides a means of generating
* destination image. Thus, this method provides a means of generating
* multiple transformed images from the same source or of applying multiple
* transformations simultaneously, in order to eliminate the need to read the
* source coefficients multiple times.
*
* @param dstBufs an array of n image buffers. <code>dstbufs[i]</code> will
* @param dstBufs an array of image buffers. <code>dstbufs[i]</code> will
* receive a JPEG image that has been transformed using the parameters in
* <code>transforms[i]</code>. Use {@link TJ#bufSizeYUV} to determine the
* <code>transforms[i]</code>. Use {@link TJ#bufSize} to determine the
* maximum size for each buffer based on the cropped width and height.
*
* @param transforms an array of n {@link TJTransform} instances, each of
* @param transforms an array of {@link TJTransform} instances, each of
* which specifies the transform parameters and/or cropping region for the
* corresponding transformed output image
*
* @param flags the bitwise OR of one or more of the flags described in
* {@link TJ}
* @param flags the bitwise OR of one or more of {@link TJ TJ.FLAG_*}
*/
public void transform(byte[][] dstBufs, TJTransform[] transforms,
int flags) throws Exception {
@@ -104,15 +103,14 @@ public class TJTransformer extends TJDecompressor {
* instance and return an array of {@link TJDecompressor} instances, each of
* which has a transformed JPEG image associated with it.
*
* @param transforms an array of n {@link TJTransform} instances, each of
* @param transforms an array of {@link TJTransform} instances, each of
* which specifies the transform parameters and/or cropping region for the
* corresponding transformed output image
*
* @return an array of {@link TJDecompressor} instances, each of
* which has a transformed JPEG image associated with it
*
* @param flags the bitwise OR of one or more of the flags described in
* {@link TJ}
* @param flags the bitwise OR of one or more of {@link TJ TJ.FLAG_*}
*/
public TJDecompressor[] transform(TJTransform[] transforms, int flags)
throws Exception {