diff --git a/java/TJExample.java b/java/TJExample.java index 12b2b3a7..76f2b1b4 100644 --- a/java/TJExample.java +++ b/java/TJExample.java @@ -282,7 +282,7 @@ public class TJExample { if(img != null) jpegBuf = tjc.compress(img, 0); else { - tjc.setBitmapBuffer(bmpBuf, width, 0, height, TJ.PF_BGRX); + tjc.setSourceImage(bmpBuf, width, 0, height, TJ.PF_BGRX); jpegBuf = tjc.compress(0); } jpegSize = tjc.getCompressedSize(); diff --git a/java/TJUnitTest.java b/java/TJUnitTest.java index 5a6dd452..6f60993f 100644 --- a/java/TJUnitTest.java +++ b/java/TJUnitTest.java @@ -108,9 +108,9 @@ public class TJUnitTest { private static void initBuf(byte[] buf, int w, int pitch, int h, int pf, int flags) throws Exception { - int roffset = TJ.getRedShift(pf) / 8; - int goffset = TJ.getGreenShift(pf) / 8; - int boffset = TJ.getBlueShift(pf) / 8; + int roffset = TJ.getRedOffset(pf); + int goffset = TJ.getGreenOffset(pf); + int boffset = TJ.getBlueOffset(pf); int ps = TJ.getPixelSize(pf); int i, _i, j; @@ -159,9 +159,9 @@ public class TJUnitTest { private static void initIntBuf(int[] buf, int w, int pitch, int h, int pf, int flags) throws Exception { - int rshift = TJ.getRedShift(pf); - int gshift = TJ.getGreenShift(pf); - int bshift = TJ.getBlueShift(pf); + int rshift = TJ.getRedOffset(pf) * 8; + int gshift = TJ.getGreenOffset(pf) * 8; + int bshift = TJ.getBlueOffset(pf) * 8; int i, _i, j; Arrays.fill(buf, 0); @@ -239,9 +239,9 @@ public class TJUnitTest { private static int checkBuf(byte[] buf, int w, int pitch, int h, int pf, int subsamp, int scaleNum, int scaleDenom, int flags) throws Exception { - int roffset = TJ.getRedShift(pf) / 8; - int goffset = TJ.getGreenShift(pf) / 8; - int boffset = TJ.getBlueShift(pf) / 8; + int roffset = TJ.getRedOffset(pf); + int goffset = TJ.getGreenOffset(pf); + int boffset = TJ.getBlueOffset(pf); int ps = TJ.getPixelSize(pf); int i, _i, j, retval = 1; int halfway = 16 * scaleNum / scaleDenom; @@ -323,9 +323,9 @@ public class TJUnitTest { private static int checkIntBuf(int[] buf, int w, int pitch, int h, int pf, int subsamp, int scaleNum, int scaleDenom, int flags) throws Exception { - int rshift = TJ.getRedShift(pf); - int gshift = TJ.getGreenShift(pf); - int bshift = TJ.getBlueShift(pf); + int rshift = TJ.getRedOffset(pf) * 8; + int gshift = TJ.getGreenOffset(pf) * 8; + int bshift = TJ.getBlueOffset(pf) * 8; int i, _i, j, retval = 1; int halfway = 16 * scaleNum / scaleDenom; int blockSize = 8 * scaleNum / scaleDenom; @@ -577,7 +577,7 @@ public class TJUnitTest { else tjc.compress(img, jpegBuf, flags); } else { - tjc.setBitmapBuffer(bmpBuf, w, 0, h, pf); + tjc.setSourceImage(bmpBuf, w, 0, h, pf); if(yuv == YUVENCODE) tjc.encodeYUV(jpegBuf, flags); else tjc.compress(jpegBuf, flags); } @@ -635,7 +635,7 @@ public class TJUnitTest { } t = getTime(); - tjd.setJPEGBuffer(jpegBuf, jpegsize); + tjd.setJPEGImage(jpegBuf, jpegsize); if(tjd.getWidth() != w || tjd.getHeight() != h || tjd.getSubsamp() != subsamp) throw new Exception("Incorrect JPEG header"); @@ -761,7 +761,7 @@ public class TJUnitTest { bmpBuf[i2 * 4 + 1] = pixels[i2 % 9][1]; bmpBuf[i2 * 4 + 2] = pixels[i2 % 9][0]; } - tjc.setBitmapBuffer(bmpBuf, i, 0, j, TJ.PF_BGRX); + tjc.setSourceImage(bmpBuf, i, 0, j, TJ.PF_BGRX); tjc.setSubsamp(TJ.SAMP_444); tjc.setJPEGQuality(100); tjc.compress(jpegBuf, 0); @@ -773,7 +773,7 @@ public class TJUnitTest { bmpBuf[i2 * 4 + 1] = bmpBuf[i2 * 4 + 2] = (byte)0xFF; else bmpBuf[i2 * 4] = bmpBuf[i2 * 4 + 1] = bmpBuf[i2 * 4 + 2] = 0; } - tjc.setBitmapBuffer(bmpBuf, j, 0, i, TJ.PF_BGRX); + tjc.setSourceImage(bmpBuf, j, 0, i, TJ.PF_BGRX); tjc.compress(jpegBuf, 0); } } diff --git a/java/doc/index-all.html b/java/doc/index-all.html index 36419294..820fd953 100644 --- a/java/doc/index-all.html +++ b/java/doc/index-all.html @@ -2,7 +2,7 @@
- +imageSize bytes stored in
+ jpegImage with this decompressor instance.
buf with the newly-created instance.
+ source image stored in srcImage with the newly-created
+ instance.
static intgetBlueShift(int pixelFormat)
+getBlueOffset(int pixelFormat)
static intgetGreenShift(int pixelFormat)
+getGreenOffset(int pixelFormat)
getPixelSize(int pixelFormat)
static intgetRedShift(int pixelFormat)
+getRedOffset(int pixelFormat)
subsamp - the level of chrominance subsampling
+subsamp - the level of chrominance subsampling (one of
+ SAMP_*)
java.lang.Exception
subsamp - the level of chrominance subsampling
+subsamp - the level of chrominance subsampling (one of
+ SAMP_*)
pixelFormat - the pixel format
+pixelFormat - the pixel format (one of PF_*)
java.lang.Exception-public static int getRedShift(int pixelFormat) - throws java.lang.Exception-
TJ.PF_BGRX is stored as an int, then the red
- component will be
- (pixel >> TJ.getRedShift(TJ.PF_BGRX)) & 0xFF.
--
pixelFormat - the pixel format
-java.lang.Exception-public static int getGreenShift(int pixelFormat) - throws java.lang.Exception-
TJ.PF_BGRX is stored as an int, then the
- green component will be
- (pixel >> TJ.getGreenShift(TJ.PF_BGRX)) & 0xFF.
--
pixelFormat - the pixel format
-java.lang.Exception
-public static int getBlueShift(int pixelFormat)
+public static int getRedOffset(int pixelFormat)
throws java.lang.Exception
TJ.PF_BGRX is stored as an int, then the blue
- component will be
- (pixel >> TJ.getBlueShift(TJ.PF_BGRX)) & 0xFF.
+TJ.PF_BGRX is stored in char pixel[],
+ then the red component will be
+ pixel[TJ.getRedOffset(TJ.PF_BGRX)].
pixelFormat - the pixel format
-pixelFormat - the pixel format (one of PF_*)
+java.lang.Exception+public static int getGreenOffset(int pixelFormat) + throws java.lang.Exception+
TJ.PF_BGRX is stored in char pixel[],
+ then the green component will be
+ pixel[TJ.getGreenOffset(TJ.PF_BGRX)].
++
pixelFormat - the pixel format (one of PF_*)
+java.lang.Exception+public static int getBlueOffset(int pixelFormat) + throws java.lang.Exception+
TJ.PF_BGRX is stored in char pixel[],
+ then the blue component will be
+ pixel[TJ.getBlueOffset(TJ.PF_BGRX)].
++
pixelFormat - the pixel format (one of PF_*)
+java.lang.Exception
width - the width (in pixels) of the YUV imageheight - the height (in pixels) of the YUV imagesubsamp - the level of chrominance subsampling used in the YUV
image
-java.lang.ExceptionTJCompressor(byte[] buf,
+TJCompressor(byte[] srcImage,
int width,
int pitch,
int height,
@@ -130,7 +130,8 @@ TurboJPEG compressor
Create a TurboJPEG compressor instance and associate the uncompressed
- source image stored in buf with the newly-created instance.
+ source image stored in srcImage with the newly-created
+ instance. voidsetBitmapBuffer(byte[] buf,
- int width,
- int pitch,
- int height,
- int pixelFormat)
-
- voidsetJPEGQuality(int quality)
voidsetSourceImage(byte[] srcImage,
+ int width,
+ int pitch,
+ int height,
+ int pixelFormat)
+
+ voidsetSubsamp(int newSubsamp)
-public TJCompressor(byte[] buf,
+public TJCompressor(byte[] srcImage,
int width,
int pitch,
int height,
@@ -325,10 +326,11 @@ public TJCompressor(byte[] buf,
throws java.lang.Exception
buf with the newly-created instance.
+ source image stored in srcImage with the newly-created
+ instance.
buf - see setBitmapBuffer(byte[], int, int, int, int) for descriptionwidth - see setBitmapBuffer(byte[], int, int, int, int) for descriptionpitch - see setBitmapBuffer(byte[], int, int, int, int) for descriptionheight - see setBitmapBuffer(byte[], int, int, int, int) for descriptionpixelFormat - see setBitmapBuffer(byte[], int, int, int, int) for description
+srcImage - see setSourceImage(byte[], int, int, int, int) for descriptionwidth - see setSourceImage(byte[], int, int, int, int) for descriptionpitch - see setSourceImage(byte[], int, int, int, int) for descriptionheight - see setSourceImage(byte[], int, int, int, int) for descriptionpixelFormat - see setSourceImage(byte[], int, int, int, int) for description
java.lang.Exception-public void setBitmapBuffer(byte[] buf, - int width, - int pitch, - int height, - int pixelFormat) - throws java.lang.Exception+public void setSourceImage(byte[] srcImage, + int width, + int pitch, + int height, + int pixelFormat) + throws java.lang.Exception
buf - image buffer containing RGB or grayscale pixels to be
+srcImage - image buffer containing RGB or grayscale pixels to be
compressedwidth - width (in pixels) of the source imagepitch - bytes per line of the source image. Normally, this should be
width * TJ.pixelSize(pixelFormat) if the source image is
unpadded, but you can use this parameter to, for instance, specify that
@@ -364,8 +366,8 @@ public void setBitmapBuffer(byte[] buf,
the case for Windows bitmaps. You can also be clever and use this
parameter to skip lines, etc. Setting this parameter to 0 is the
equivalent of setting it to width *
- TJ.pixelSize(pixelFormat).height - height (in pixels) of the source imagepixelFormat - pixel format of the source image (see
- TJ)
+ TJ.pixelSize(pixelFormat).height - height (in pixels) of the source imagepixelFormat - pixel format of the source image (one of
+ TJ.PF_*)
java.lang.Exception
newSubsamp - the new level of chrominance subsampling (see
- TJ)
+newSubsamp - the new level of chrominance subsampling (one of
+ TJ.SAMP_*)
java.lang.ExceptiondstBuf - buffer which will receive the JPEG image. Use
TJ.bufSize(int, int) to determine the maximum size for this buffer based on
- the image width and height.flags - the bitwise OR of one or more of the flags described in
- TJ
+ the image width and height.flags - the bitwise OR of one or more of TJ.FLAG_*
java.lang.Exception
flags - the bitwise OR of one or more of the flags described in
- TJ
+flags - the bitwise OR of one or more of TJ.FLAG_*
getCompressedSize() to obtain the size of the JPEG image.
srcImage - a BufferedImage instance containing RGB or
grayscale pixels to be compresseddstBuf - buffer which will receive the JPEG image. Use
TJ.bufSize(int, int) to determine the maximum size for this buffer based on
- the image width and height.flags - the bitwise OR of one or more of the flags described in
- TJ
+ the image width and height.flags - the bitwise OR of one or more of TJ.FLAG_*
java.lang.Exception
srcImage - a BufferedImage instance containing RGB or
- grayscale pixels to be compressedflags - the bitwise OR of one or more of the flags described in
- TJ
+ grayscale pixels to be compressedflags - the bitwise OR of one or more of TJ.FLAG_*
getCompressedSize() to obtain the size of the JPEG image.
dstBuf - buffer which will receive the YUV planar image. Use
TJ.bufSizeYUV(int, int, int) to determine the appropriate size for this buffer
- based on the image width, height, and level of chrominance subsampling.flags - the bitwise OR of one or more of the flags described in
- TJ
+ based on the image width, height, and level of chrominance subsampling.flags - the bitwise OR of one or more of TJ.FLAG_*
java.lang.ExceptionencodeYUV(byte[], int) for more detail.
flags - the bitwise OR of one or more of the flags described in
- TJ
+flags - the bitwise OR of one or more of TJ.FLAG_*
java.lang.ExceptionsrcImage - a BufferedImage instance containing RGB or
grayscale pixels to be encodeddstBuf - buffer which will receive the YUV planar image. Use
TJ.bufSizeYUV(int, int, int) to determine the appropriate size for this buffer
- based on the image width, height, and level of chrominance subsampling.flags - the bitwise OR of one or more of the flags described in
- TJ
+ based on the image width, height, and level of chrominance subsampling.flags - the bitwise OR of one or more of TJ.FLAG_*
java.lang.Exception
srcImage - a BufferedImage instance containing RGB or
- grayscale pixels to be encodedflags - the bitwise OR of one or more of the flags described in
- TJ
+ grayscale pixels to be encodedflags - the bitwise OR of one or more of TJ.FLAG_*
java.lang.Exception voidsetJPEGBuffer(byte[] jpegImage,
- int imageSize)
+setJPEGImage(byte[] jpegImage,
+ int imageSize)
imageSize bytes stored in
+ jpegImage with this decompressor instance.
jpegImage with the newly-created instance.
jpegImage - JPEG image buffer (size of JPEG image is assumed to be
- the length of the buffer)
+jpegImage - JPEG image buffer (size of the JPEG image is assumed to
+ be the length of the array)
java.lang.Exception
jpegImage - JPEG image bufferimageSize - size of JPEG image (in bytes)
+jpegImage - JPEG image bufferimageSize - size of the JPEG image (in bytes)
java.lang.Exception-public void setJPEGBuffer(byte[] jpegImage, - int imageSize) - throws java.lang.Exception+public void setJPEGImage(byte[] jpegImage, + int imageSize) + throws java.lang.Exception
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 bufferimageSize - size of JPEG image (in bytes)
+jpegImage - JPEG image bufferimageSize - size of the JPEG image (in bytes)
java.lang.Exception
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.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 width of the JPEG image
+ (in other words, the width will not be considered when determining the
+ scaled image size.)desiredHeight - desired height (in pixels) of the decompressed image.
+ 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.)
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.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 width of the JPEG image
+ (in other words, the width will not be considered when determining the
+ scaled image size.)desiredHeight - desired height (in pixels) of the decompressed image.
+ 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.)
pitch - bytes per line of the destination image. Normally, this
+ 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.)pitch - bytes per line of the destination image. Normally, this
should be set to scaledWidth * TJ.pixelSize(pixelFormat) if
the decompressed image is unpadded, but you can use this to, for instance,
pad each line of the decompressed image to a 4-byte boundary. NOTE:
scaledWidth = ceil(jpegWidth * scalingFactor). Setting this
parameter to 0 is the equivalent of setting it to
- scaledWidth * pixelSize.desiredHeight - desired height (in pixels) of the decompressed image.
+ scaledWidth * TJ.pixelSize(pixelFormat).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.pixelFormat - Pixel format of the decompressed image (see
- TJ)flags - the bitwise OR of one or more of the flags described in
- TJ
+ 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.)pixelFormat - pixel format of the decompressed image (one of
+ TJ.PF_*)flags - the bitwise OR of one or more of TJ.FLAG_*
java.lang.ExceptiondesiredWidth - see
decompress(byte[], int, int, int, int, int) for descriptionpitch - see
decompress(byte[], int, int, int, int, int) for descriptiondesiredHeight - see
- decompress(byte[], int, int, int, int, int) for descriptionpixelFormat - Pixel format of the decompressed image (see
- TJ)flags - the bitwise OR of one or more of the flags described in
- TJ
+ decompress(byte[], int, int, int, int, int) for descriptionpixelFormat - pixel format of the decompressed image (one of
+ TJ.PF_*)flags - the bitwise OR of one or more of TJ.FLAG_*
java.lang.ExceptiondstBuf - buffer which will receive the YUV planar image. Use
TJ.bufSizeYUV(int, int, int) to determine the appropriate size for this buffer
- based on the image width, height, and level of chrominance subsampling.flags - the bitwise OR of one or more of the flags described in
- TJ
+ based on the image width, height, and level of chrominance subsampling.flags - the bitwise OR of one or more of TJ.FLAG_*
java.lang.ExceptiondecompressToYUV(byte[], int) for more detail.
flags - the bitwise OR of one or more of the flags described in
- TJ
+flags - the bitwise OR of one or more of TJ.FLAG_*
java.lang.Exception
dstImage - a BufferedImage instance which will receive
- the decompressed imageflags - the bitwise OR of one or more of the flags described in
- TJ
+ the decompressed imageflags - the bitwise OR of one or more of TJ.FLAG_*
java.lang.ExceptiondesiredWidth - see
decompress(byte[], int, int, int, int, int) for descriptiondesiredHeight - see
- decompress(byte[], int, int, int, int, int) for descriptionbufferedImageType - the image type of the BufferedImage
- instance to create (for instance, BufferedImage.TYPE_INT_RGB)flags - the bitwise OR of one or more of the flags described in
- TJ
+ decompress(byte[], int, int, int, int, int) for descriptionbufferedImageType - the image type of the newly-created
+ BufferedImage instance (for instance,
+ BufferedImage.TYPE_INT_RGB)flags - the bitwise OR of one or more of TJ.FLAG_*
BufferedImage instance containing the
decompressed image
r - a Rectangle instance which specifies the cropping
- region. See TJTransform(int, int, int, int, int, int) for a
- description of the cropping region.op - one of the transform operations (OP_*)options - the bitwise OR of one or more of the transform options
+ region. See TJTransform(int, int, int, int, int, int) for more
+ detail.op - one of the transform operations (OP_*)options - the bitwise OR of one or more of the transform options
(OPT_*)
java.lang.Exceptionclose, decompress, decompress, decompress, decompress, decompressToYUV, decompressToYUV, finalize, getHeight, getJPEGBuf, getJPEGSize, getScaledHeight, getScaledWidth, getSubsamp, getWidth, setJPEGBufferclose, decompress, decompress, decompress, decompress, decompressToYUV, decompressToYUV, finalize, getHeight, getJPEGBuf, getJPEGSize, getScaledHeight, getScaledWidth, getSubsamp, getWidth, setJPEGImagejpegImage with the newly-created instance.
jpegImage - JPEG image buffer (size of JPEG image is assumed to be
- the length of the buffer)
+jpegImage - JPEG image buffer (size of the JPEG image is assumed to
+ be the length of the array)
java.lang.ExceptionjpegImage with the newly-created instance.
jpegImage - JPEG image bufferimageSize - size of JPEG image (in bytes)
+jpegImage - JPEG image bufferimageSize - size of the JPEG image (in bytes)
java.lang.Exception
dstBufs - an array of n image buffers. dstbufs[i] will
+dstBufs - an array of image buffers. dstbufs[i] will
receive a JPEG image that has been transformed using the parameters in
- transforms[i]. Use TJ.bufSizeYUV(int, int, int) to determine the
- maximum size for each buffer based on the cropped width and height.transforms - an array of n TJTransform instances, each of
+ transforms[i]. Use TJ.bufSize(int, int) to determine the
+ maximum size for each buffer based on the cropped width and height.transforms - an array of TJTransform instances, each of
which specifies the transform parameters and/or cropping region for the
- corresponding transformed output imageflags - the bitwise OR of one or more of the flags described in
- TJ
+ corresponding transformed output imageflags - the bitwise OR of one or more of TJ.FLAG_*
java.lang.ExceptionTJTransform instances, each of
+transforms - an array of TJTransform instances, each of
which specifies the transform parameters and/or cropping region for the
- corresponding transformed output imageflags - the bitwise OR of one or more of the flags described in
- TJ
+ corresponding transformed output imageflags - the bitwise OR of one or more of TJ.FLAG_*
TJDecompressor instances, each of
which has a transformed JPEG image associated with it
SAMP_*)
*
* @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
+ * SAMP_*)
*
* @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 PF_*)
+ *
* @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 TJ.PF_BGRX is stored as an int, then the red
- * component will be
- * (pixel >> TJ.getRedShift(TJ.PF_BGRX)) & 0xFF.
+ * 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 TJ.PF_BGRX is stored in char pixel[],
+ * then the red component will be
+ * pixel[TJ.getRedOffset(TJ.PF_BGRX)].
*
- * @param pixelFormat the pixel format
+ * @param pixelFormat the pixel format (one of PF_*)
*
- * @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 TJ.PF_BGRX is stored as an int, then the
- * green component will be
- * (pixel >> TJ.getGreenShift(TJ.PF_BGRX)) & 0xFF.
+ * 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 TJ.PF_BGRX is stored in char pixel[],
+ * then the green component will be
+ * pixel[TJ.getGreenOffset(TJ.PF_BGRX)].
*
- * @param pixelFormat the pixel format
+ * @param pixelFormat the pixel format (one of PF_*)
*
- * @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 TJ.PF_BGRX is stored as an int, then the blue
- * component will be
- * (pixel >> TJ.getBlueShift(TJ.PF_BGRX)) & 0xFF.
+ * 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 TJ.PF_BGRX is stored in char pixel[],
+ * then the blue component will be
+ * pixel[TJ.getBlueOffset(TJ.PF_BGRX)].
*
- * @param pixelFormat the pixel format
+ * @param pixelFormat the pixel format (one of PF_*)
*
- * @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)
diff --git a/java/org/libjpegturbo/turbojpeg/TJCompressor.java b/java/org/libjpegturbo/turbojpeg/TJCompressor.java
index c9b56875..832023ae 100644
--- a/java/org/libjpegturbo/turbojpeg/TJCompressor.java
+++ b/java/org/libjpegturbo/turbojpeg/TJCompressor.java
@@ -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 buf with the newly-created instance.
+ * source image stored in srcImage 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 BufferedImage 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 BufferedImage 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;
diff --git a/java/org/libjpegturbo/turbojpeg/TJDecompressor.java b/java/org/libjpegturbo/turbojpeg/TJDecompressor.java
index 232d46cb..19f0c94a 100644
--- a/java/org/libjpegturbo/turbojpeg/TJDecompressor.java
+++ b/java/org/libjpegturbo/turbojpeg/TJDecompressor.java
@@ -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 jpegImage 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 imageSize bytes stored in
+ * jpegImage 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 scaledWidth * TJ.pixelSize(pixelFormat) if
@@ -245,26 +253,26 @@ public class TJDecompressor {
* pad each line of the decompressed image to a 4-byte boundary. NOTE:
* scaledWidth = ceil(jpegWidth * scalingFactor). Setting this
* parameter to 0 is the equivalent of setting it to
- * scaledWidth * pixelSize.
+ * scaledWidth * TJ.pixelSize(pixelFormat).
*
* @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 BufferedImage 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 BufferedImage
- * instance to create (for instance, BufferedImage.TYPE_INT_RGB)
+ * @param bufferedImageType the image type of the newly-created
+ * BufferedImage instance (for instance,
+ * BufferedImage.TYPE_INT_RGB)
*
- * @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 BufferedImage instance containing the
* decompressed image
diff --git a/java/org/libjpegturbo/turbojpeg/TJTransform.java b/java/org/libjpegturbo/turbojpeg/TJTransform.java
index 25bb45bb..7a637f26 100644
--- a/java/org/libjpegturbo/turbojpeg/TJTransform.java
+++ b/java/org/libjpegturbo/turbojpeg/TJTransform.java
@@ -155,8 +155,8 @@ public class TJTransform extends Rectangle {
* Create a new lossless transform instance with the given parameters.
*
* @param r a Rectangle 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 (OP_*)
*
diff --git a/java/org/libjpegturbo/turbojpeg/TJTransformer.java b/java/org/libjpegturbo/turbojpeg/TJTransformer.java
index 22b2599e..6976cd1c 100644
--- a/java/org/libjpegturbo/turbojpeg/TJTransformer.java
+++ b/java/org/libjpegturbo/turbojpeg/TJTransformer.java
@@ -44,12 +44,12 @@ public class TJTransformer extends TJDecompressor {
* Create a TurboJPEG lossless transformer instance and associate the JPEG
* image stored in jpegImage 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. dstbufs[i] will
+ * @param dstBufs an array of image buffers. dstbufs[i] will
* receive a JPEG image that has been transformed using the parameters in
- * transforms[i]. Use {@link TJ#bufSizeYUV} to determine the
+ * transforms[i]. 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 {