Re-work TJBUFSIZE() to take into account the level of chrominance subsampling

This commit is contained in:
DRC
2011-07-12 03:17:23 +00:00
parent 2bfd5d8c7d
commit 489864aefa
41 changed files with 268 additions and 180 deletions

View File

@@ -271,16 +271,21 @@ final public class TJ {
/**
* Returns the maximum size of the buffer (in bytes) required to hold a JPEG
* image with the given width and height.
* image with the given width and height, and level of chrominance
* subsampling.
*
* @param width the width (in pixels) of the JPEG image
*
* @param height the height (in pixels) of the JPEG image
*
* @param jpegSubsamp the level of chrominance subsampling to be used when
* generating the JPEG image (one of {@link TJ TJ.SAMP_*})
*
* @return the maximum size of the buffer (in bytes) required to hold a JPEG
* image with the given width and height
* image with the given width and height, and level of chrominance
* subsampling
*/
public native static int bufSize(int width, int height)
public native static int bufSize(int width, int height, int jpegSubsamp)
throws Exception;
/**
@@ -292,7 +297,7 @@ final public class TJ {
* @param height the height (in pixels) of the YUV image
*
* @param subsamp the level of chrominance subsampling used in the YUV
* image
* image (one of {@link TJ TJ.SAMP_*})
*
* @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

View File

@@ -160,7 +160,7 @@ public class TJCompressor {
public byte[] compress(int flags) throws Exception {
if(srcWidth < 1 || srcHeight < 1)
throw new Exception(NO_ASSOC_ERROR);
byte[] buf = new byte[TJ.bufSize(srcWidth, srcHeight)];
byte[] buf = new byte[TJ.bufSize(srcWidth, srcHeight, subsamp)];
compress(buf, flags);
return buf;
}
@@ -249,7 +249,7 @@ public class TJCompressor {
public byte[] compress(BufferedImage srcImage, int flags) throws Exception {
int width = srcImage.getWidth();
int height = srcImage.getHeight();
byte[] buf = new byte[TJ.bufSize(width, height)];
byte[] buf = new byte[TJ.bufSize(width, height, subsamp)];
compress(srcImage, buf, flags);
return buf;
}

View File

@@ -123,7 +123,7 @@ public class TJTransformer extends TJDecompressor {
if(transforms[i].width != 0) w = transforms[i].width;
if(transforms[i].height != 0) h = transforms[i].height;
}
dstBufs[i] = new byte[TJ.bufSize(w, h)];
dstBufs[i] = new byte[TJ.bufSize(w, h, jpegSubsamp)];
}
TJDecompressor[] tjd = new TJDecompressor[transforms.length];
transform(dstBufs, transforms, flags);