Use consistent formatting conventions

git-svn-id: svn+ssh://svn.code.sf.net/p/libjpeg-turbo/code/trunk@479 632fc199-4ca6-4c93-a231-07263d6284db
This commit is contained in:
DRC
2011-03-01 20:03:32 +00:00
parent 20ec358b3c
commit f7f3ea404c
5 changed files with 824 additions and 900 deletions

View File

@@ -64,7 +64,7 @@ public class TJExample {
public static void main(String argv[]) { public static void main(String argv[]) {
BufferedImage img = null; byte [] bmpBuf = null; BufferedImage img = null; byte[] bmpBuf = null;
try { try {
@@ -82,7 +82,7 @@ public class TJExample {
if(argv[i].length() > 2 if(argv[i].length() > 2
&& argv[i].substring(0, 3).equalsIgnoreCase("-sc")) { && argv[i].substring(0, 3).equalsIgnoreCase("-sc")) {
if(i < argv.length - 1) { if(i < argv.length - 1) {
String [] scaleArg = argv[++i].split("/"); String[] scaleArg = argv[++i].split("/");
if(scaleArg.length != 2 || Integer.parseInt(scaleArg[0]) != 1 if(scaleArg.length != 2 || Integer.parseInt(scaleArg[0]) != 1
|| (scaleFactor = Integer.parseInt(scaleArg[1])) < 1 || (scaleFactor = Integer.parseInt(scaleArg[1])) < 1
|| scaleFactor > 8 || (scaleFactor & (scaleFactor - 1)) != 0) || scaleFactor > 8 || (scaleFactor & (scaleFactor - 1)) != 0)
@@ -116,10 +116,10 @@ public class TJExample {
} }
} }
} }
String [] inFileTokens = argv[0].split("\\."); String[] inFileTokens = argv[0].split("\\.");
if(inFileTokens.length > 1) if(inFileTokens.length > 1)
inFormat = inFileTokens[inFileTokens.length - 1]; inFormat = inFileTokens[inFileTokens.length - 1];
String [] outFileTokens = argv[1].split("\\."); String[] outFileTokens = argv[1].split("\\.");
if(outFileTokens.length > 1) if(outFileTokens.length > 1)
outFormat = outFileTokens[outFileTokens.length - 1]; outFormat = outFileTokens[outFileTokens.length - 1];
@@ -133,7 +133,7 @@ public class TJExample {
System.out.println("Input file contains no data"); System.out.println("Input file contains no data");
System.exit(1); System.exit(1);
} }
byte [] inputBuf = new byte[inputSize]; byte[] inputBuf = new byte[inputSize];
fis.read(inputBuf); fis.read(inputBuf);
fis.close(); fis.close();
@@ -146,8 +146,8 @@ public class TJExample {
if(outSubsamp < 0) outSubsamp = inSubsamp; if(outSubsamp < 0) outSubsamp = inSubsamp;
if(scaleFactor != 1) { if(scaleFactor != 1) {
width = (width + scaleFactor - 1)/scaleFactor; width = (width + scaleFactor - 1) / scaleFactor;
height = (height + scaleFactor - 1)/scaleFactor; height = (height + scaleFactor - 1) / scaleFactor;
} }
if(!outFormat.equalsIgnoreCase("jpg")) if(!outFormat.equalsIgnoreCase("jpg"))
@@ -173,7 +173,7 @@ public class TJExample {
+ " subsampling, quality = " + outQual); + " subsampling, quality = " + outQual);
TJCompressor tjc = new TJCompressor(); TJCompressor tjc = new TJCompressor();
int jpegSize; int jpegSize;
byte [] jpegBuf; byte[] jpegBuf;
tjc.setSubsamp(outSubsamp); tjc.setSubsamp(outSubsamp);
tjc.setJPEGQuality(outQual); tjc.setJPEGQuality(outQual);
@@ -197,7 +197,8 @@ public class TJExample {
ImageIO.write(img, outFormat, file); ImageIO.write(img, outFormat, file);
} }
} catch(Exception e) { }
catch(Exception e) {
System.out.println(e); System.out.println(e);
} }
} }

File diff suppressed because it is too large Load Diff

View File

@@ -110,7 +110,7 @@ final public class TJ {
int subsamp) int subsamp)
throws Exception; throws Exception;
public native final static ScalingFactor [] getScalingFactors() public native final static ScalingFactor[] getScalingFactors()
throws Exception; throws Exception;
static { static {

View File

@@ -36,12 +36,12 @@ public class TJCompressor {
init(); init();
} }
public TJCompressor(byte [] buf, int width, int pitch, int height, public TJCompressor(byte[] buf, int width, int pitch, int height,
int pixelFormat) throws Exception { int pixelFormat) throws Exception {
setBitmapBuffer(buf, width, pitch, height, pixelFormat); setBitmapBuffer(buf, width, pitch, height, pixelFormat);
} }
public void setBitmapBuffer(byte [] buf, int width, int pitch, int height, public void setBitmapBuffer(byte[] buf, int width, int pitch, int height,
int pixelFormat) throws Exception { int pixelFormat) throws Exception {
if(handle == 0) init(); if(handle == 0) init();
if(buf == null || width < 1 || height < 1 || pitch < 0 || pixelFormat < 0 if(buf == null || width < 1 || height < 1 || pitch < 0 || pixelFormat < 0
@@ -57,17 +57,17 @@ public class TJCompressor {
public void setSubsamp(int newSubsamp) throws Exception { public void setSubsamp(int newSubsamp) throws Exception {
if(newSubsamp < 0 || newSubsamp >= TJ.NUMSAMPOPT) if(newSubsamp < 0 || newSubsamp >= TJ.NUMSAMPOPT)
throw new Exception ("Invalid argument in setSubsamp()"); throw new Exception("Invalid argument in setSubsamp()");
subsamp = newSubsamp; subsamp = newSubsamp;
} }
public void setJPEGQuality(int quality) throws Exception { public void setJPEGQuality(int quality) throws Exception {
if(quality < 1 || quality > 100) if(quality < 1 || quality > 100)
throw new Exception ("Invalid argument in setJPEGQuality()"); throw new Exception("Invalid argument in setJPEGQuality()");
jpegQuality = quality; jpegQuality = quality;
} }
public void compress(byte [] dstBuf, int flags) throws Exception { public void compress(byte[] dstBuf, int flags) throws Exception {
if(dstBuf == null || flags < 0) if(dstBuf == null || flags < 0)
throw new Exception("Invalid argument in compress()"); throw new Exception("Invalid argument in compress()");
if(bitmapBuf == null) throw new Exception("Bitmap buffer not initialized"); if(bitmapBuf == null) throw new Exception("Bitmap buffer not initialized");
@@ -77,30 +77,30 @@ public class TJCompressor {
bitmapHeight, bitmapPixelFormat, dstBuf, subsamp, jpegQuality, flags); bitmapHeight, bitmapPixelFormat, dstBuf, subsamp, jpegQuality, flags);
} }
public byte [] compress(int flags) throws Exception { public byte[] compress(int flags) throws Exception {
if(bitmapWidth < 1 || bitmapHeight < 1) if(bitmapWidth < 1 || bitmapHeight < 1)
throw new Exception("Bitmap buffer not initialized"); throw new Exception("Bitmap buffer not initialized");
byte [] buf = new byte[TJ.bufSize(bitmapWidth, bitmapHeight)]; byte[] buf = new byte[TJ.bufSize(bitmapWidth, bitmapHeight)];
compress(buf, flags); compress(buf, flags);
return buf; return buf;
} }
public void compress(BufferedImage srcImage, byte [] dstBuf, int flags) public void compress(BufferedImage srcImage, byte[] dstBuf, int flags)
throws Exception { throws Exception {
if(srcImage == null || dstBuf == null || flags < 0) if(srcImage == null || dstBuf == null || flags < 0)
throw new Exception("Invalid argument in compress()"); throw new Exception("Invalid argument in compress()");
int width = srcImage.getWidth(); int width = srcImage.getWidth();
int height = srcImage.getHeight(); int height = srcImage.getHeight();
int pixelFormat; boolean intPixels=false; int pixelFormat; boolean intPixels = false;
switch(srcImage.getType()) { switch(srcImage.getType()) {
case BufferedImage.TYPE_3BYTE_BGR: case BufferedImage.TYPE_3BYTE_BGR:
pixelFormat=TJ.PF_BGR; break; pixelFormat = TJ.PF_BGR; break;
case BufferedImage.TYPE_BYTE_GRAY: case BufferedImage.TYPE_BYTE_GRAY:
pixelFormat=TJ.PF_GRAY; break; pixelFormat = TJ.PF_GRAY; break;
case BufferedImage.TYPE_INT_BGR: case BufferedImage.TYPE_INT_BGR:
pixelFormat=TJ.PF_RGBX; intPixels=true; break; pixelFormat = TJ.PF_RGBX; intPixels = true; break;
case BufferedImage.TYPE_INT_RGB: case BufferedImage.TYPE_INT_RGB:
pixelFormat=TJ.PF_BGRX; intPixels=true; break; pixelFormat = TJ.PF_BGRX; intPixels = true; break;
default: default:
throw new Exception("Unsupported BufferedImage format"); throw new Exception("Unsupported BufferedImage format");
} }
@@ -112,7 +112,7 @@ public class TJCompressor {
(SinglePixelPackedSampleModel)srcImage.getSampleModel(); (SinglePixelPackedSampleModel)srcImage.getSampleModel();
int pitch = sm.getScanlineStride(); int pitch = sm.getScanlineStride();
DataBufferInt db = (DataBufferInt)wr.getDataBuffer(); DataBufferInt db = (DataBufferInt)wr.getDataBuffer();
int [] buf = db.getData(); int[] buf = db.getData();
compressedSize = compress(buf, width, pitch, height, pixelFormat, dstBuf, compressedSize = compress(buf, width, pitch, height, pixelFormat, dstBuf,
subsamp, jpegQuality, flags); subsamp, jpegQuality, flags);
} }
@@ -124,21 +124,21 @@ public class TJCompressor {
throw new Exception("Inconsistency between pixel format and pixel size in BufferedImage"); throw new Exception("Inconsistency between pixel format and pixel size in BufferedImage");
int pitch = sm.getScanlineStride(); int pitch = sm.getScanlineStride();
DataBufferByte db = (DataBufferByte)wr.getDataBuffer(); DataBufferByte db = (DataBufferByte)wr.getDataBuffer();
byte [] buf = db.getData(); byte[] buf = db.getData();
compressedSize = compress(buf, width, pitch, height, pixelFormat, dstBuf, compressedSize = compress(buf, width, pitch, height, pixelFormat, dstBuf,
subsamp, jpegQuality, flags); subsamp, jpegQuality, flags);
} }
} }
public byte [] compress(BufferedImage srcImage, int flags) throws Exception { public byte[] compress(BufferedImage srcImage, int flags) throws Exception {
int width = srcImage.getWidth(); int width = srcImage.getWidth();
int height = srcImage.getHeight(); int height = srcImage.getHeight();
byte [] buf = new byte[TJ.bufSize(width, height)]; byte[] buf = new byte[TJ.bufSize(width, height)];
compress(srcImage, buf, flags); compress(srcImage, buf, flags);
return buf; return buf;
} }
public void encodeYUV(byte [] dstBuf, int flags) throws Exception { public void encodeYUV(byte[] dstBuf, int flags) throws Exception {
if(dstBuf == null || flags < 0) if(dstBuf == null || flags < 0)
throw new Exception("Invalid argument in compress()"); throw new Exception("Invalid argument in compress()");
if(bitmapBuf == null) throw new Exception("Bitmap buffer not initialized"); if(bitmapBuf == null) throw new Exception("Bitmap buffer not initialized");
@@ -148,31 +148,31 @@ public class TJCompressor {
compressedSize = TJ.bufSizeYUV(bitmapWidth, bitmapHeight, subsamp); compressedSize = TJ.bufSizeYUV(bitmapWidth, bitmapHeight, subsamp);
} }
public byte [] encodeYUV(int flags) throws Exception { public byte[] encodeYUV(int flags) throws Exception {
if(bitmapWidth < 1 || bitmapHeight < 1) if(bitmapWidth < 1 || bitmapHeight < 1)
throw new Exception("Bitmap buffer not initialized"); throw new Exception("Bitmap buffer not initialized");
if(subsamp < 0) throw new Exception("Subsampling level not set"); 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(bitmapWidth, bitmapHeight, subsamp)];
encodeYUV(buf, flags); encodeYUV(buf, flags);
return buf; return buf;
} }
public void encodeYUV(BufferedImage srcImage, byte [] dstBuf, int flags) public void encodeYUV(BufferedImage srcImage, byte[] dstBuf, int flags)
throws Exception { throws Exception {
if(srcImage == null || dstBuf == null || flags < 0) if(srcImage == null || dstBuf == null || flags < 0)
throw new Exception("Invalid argument in encodeYUV()"); throw new Exception("Invalid argument in encodeYUV()");
int width = srcImage.getWidth(); int width = srcImage.getWidth();
int height = srcImage.getHeight(); int height = srcImage.getHeight();
int pixelFormat; boolean intPixels=false; int pixelFormat; boolean intPixels = false;
switch(srcImage.getType()) { switch(srcImage.getType()) {
case BufferedImage.TYPE_3BYTE_BGR: case BufferedImage.TYPE_3BYTE_BGR:
pixelFormat=TJ.PF_BGR; break; pixelFormat = TJ.PF_BGR; break;
case BufferedImage.TYPE_BYTE_GRAY: case BufferedImage.TYPE_BYTE_GRAY:
pixelFormat=TJ.PF_GRAY; break; pixelFormat = TJ.PF_GRAY; break;
case BufferedImage.TYPE_INT_BGR: case BufferedImage.TYPE_INT_BGR:
pixelFormat=TJ.PF_RGBX; intPixels=true; break; pixelFormat = TJ.PF_RGBX; intPixels = true; break;
case BufferedImage.TYPE_INT_RGB: case BufferedImage.TYPE_INT_RGB:
pixelFormat=TJ.PF_BGRX; intPixels=true; break; pixelFormat = TJ.PF_BGRX; intPixels = true; break;
default: default:
throw new Exception("Unsupported BufferedImage format"); throw new Exception("Unsupported BufferedImage format");
} }
@@ -183,7 +183,7 @@ public class TJCompressor {
(SinglePixelPackedSampleModel)srcImage.getSampleModel(); (SinglePixelPackedSampleModel)srcImage.getSampleModel();
int pitch = sm.getScanlineStride(); int pitch = sm.getScanlineStride();
DataBufferInt db = (DataBufferInt)wr.getDataBuffer(); DataBufferInt db = (DataBufferInt)wr.getDataBuffer();
int [] buf = db.getData(); int[] buf = db.getData();
encodeYUV(buf, width, pitch, height, pixelFormat, dstBuf, subsamp, encodeYUV(buf, width, pitch, height, pixelFormat, dstBuf, subsamp,
flags); flags);
} }
@@ -195,19 +195,19 @@ public class TJCompressor {
throw new Exception("Inconsistency between pixel format and pixel size in BufferedImage"); throw new Exception("Inconsistency between pixel format and pixel size in BufferedImage");
int pitch = sm.getScanlineStride(); int pitch = sm.getScanlineStride();
DataBufferByte db = (DataBufferByte)wr.getDataBuffer(); DataBufferByte db = (DataBufferByte)wr.getDataBuffer();
byte [] buf = db.getData(); byte[] buf = db.getData();
encodeYUV(buf, width, pitch, height, pixelFormat, dstBuf, subsamp, encodeYUV(buf, width, pitch, height, pixelFormat, dstBuf, subsamp,
flags); flags);
} }
compressedSize = TJ.bufSizeYUV(width, height, subsamp); compressedSize = TJ.bufSizeYUV(width, height, subsamp);
} }
public byte [] encodeYUV(BufferedImage srcImage, int flags) public byte[] encodeYUV(BufferedImage srcImage, int flags)
throws Exception { throws Exception {
if(subsamp < 0) throw new Exception("Subsampling level not set"); if(subsamp < 0) throw new Exception("Subsampling level not set");
int width = srcImage.getWidth(); int width = srcImage.getWidth();
int height = srcImage.getHeight(); int height = srcImage.getHeight();
byte [] buf = new byte[TJ.bufSizeYUV(width, height, subsamp)]; byte[] buf = new byte[TJ.bufSizeYUV(width, height, subsamp)];
encodeYUV(srcImage, buf, flags); encodeYUV(srcImage, buf, flags);
return buf; return buf;
} }
@@ -223,8 +223,8 @@ public class TJCompressor {
protected void finalize() throws Throwable { protected void finalize() throws Throwable {
try { try {
close(); close();
} catch(Exception e) {
} }
catch(Exception e) {}
finally { finally {
super.finalize(); super.finalize();
} }
@@ -235,20 +235,20 @@ public class TJCompressor {
private native void destroy() throws Exception; private native void destroy() throws Exception;
// JPEG size in bytes is returned // JPEG size in bytes is returned
private native int compress(byte [] srcBuf, int width, int pitch, private native int compress(byte[] srcBuf, int width, int pitch,
int height, int pixelFormat, byte [] dstbuf, int jpegSubsamp, int jpegQual, int height, int pixelFormat, byte[] dstbuf, int jpegSubsamp, int jpegQual,
int flags) throws Exception; int flags) throws Exception;
private native int compress(int [] srcBuf, int width, int pitch, private native int compress(int[] srcBuf, int width, int pitch,
int height, int pixelFormat, byte [] dstbuf, int jpegSubsamp, int jpegQual, int height, int pixelFormat, byte[] dstbuf, int jpegSubsamp, int jpegQual,
int flags) throws Exception; int flags) throws Exception;
private native void encodeYUV(byte [] srcBuf, int width, int pitch, private native void encodeYUV(byte[] srcBuf, int width, int pitch,
int height, int pixelFormat, byte [] dstbuf, int subsamp, int flags) int height, int pixelFormat, byte[] dstbuf, int subsamp, int flags)
throws Exception; throws Exception;
private native void encodeYUV(int [] srcBuf, int width, int pitch, private native void encodeYUV(int[] srcBuf, int width, int pitch,
int height, int pixelFormat, byte [] dstbuf, int subsamp, int flags) int height, int pixelFormat, byte[] dstbuf, int subsamp, int flags)
throws Exception; throws Exception;
static { static {
@@ -256,7 +256,7 @@ public class TJCompressor {
} }
private long handle = 0; private long handle = 0;
private byte [] bitmapBuf = null; private byte[] bitmapBuf = null;
private int bitmapWidth = 0; private int bitmapWidth = 0;
private int bitmapHeight = 0; private int bitmapHeight = 0;
private int bitmapPitch = 0; private int bitmapPitch = 0;

View File

@@ -36,15 +36,15 @@ public class TJDecompressor {
init(); init();
} }
public TJDecompressor(byte [] buf) throws Exception { public TJDecompressor(byte[] buf) throws Exception {
setJPEGBuffer(buf, buf.length); setJPEGBuffer(buf, buf.length);
} }
public TJDecompressor(byte [] buf, int bufSize) throws Exception { public TJDecompressor(byte[] buf, int bufSize) throws Exception {
setJPEGBuffer(buf, bufSize); setJPEGBuffer(buf, bufSize);
} }
public void setJPEGBuffer(byte [] buf, int bufSize) throws Exception { public void setJPEGBuffer(byte[] buf, int bufSize) throws Exception {
if(handle == 0) init(); if(handle == 0) init();
if(buf == null || bufSize < 1) if(buf == null || bufSize < 1)
throw new Exception("Invalid argument in setJPEGBuffer()"); throw new Exception("Invalid argument in setJPEGBuffer()");
@@ -76,11 +76,11 @@ public class TJDecompressor {
throw new Exception("JPEG buffer not initialized"); throw new Exception("JPEG buffer not initialized");
if(desiredWidth < 0 || desiredHeight < 0) if(desiredWidth < 0 || desiredHeight < 0)
throw new Exception("Invalid argument in getScaledWidth()"); throw new Exception("Invalid argument in getScaledWidth()");
TJ.ScalingFactor sf [] = TJ.getScalingFactors(); TJ.ScalingFactor sf[] = TJ.getScalingFactors();
if(desiredWidth == 0) desiredWidth = jpegWidth; if(desiredWidth == 0) desiredWidth = jpegWidth;
if(desiredHeight == 0) desiredHeight = jpegHeight; if(desiredHeight == 0) desiredHeight = jpegHeight;
int scaledWidth = jpegWidth, scaledHeight = jpegHeight; int scaledWidth = jpegWidth, scaledHeight = jpegHeight;
for(int i=0; i<sf.length; i++) { for(int i = 0; i < sf.length; i++) {
scaledWidth = (jpegWidth * sf[i].num + sf[i].denom - 1) / sf[i].denom; scaledWidth = (jpegWidth * sf[i].num + sf[i].denom - 1) / sf[i].denom;
scaledHeight = (jpegHeight * sf[i].num + sf[i].denom - 1) / sf[i].denom; scaledHeight = (jpegHeight * sf[i].num + sf[i].denom - 1) / sf[i].denom;
if(scaledWidth <= desiredWidth && scaledHeight <= desiredHeight) if(scaledWidth <= desiredWidth && scaledHeight <= desiredHeight)
@@ -97,11 +97,11 @@ public class TJDecompressor {
throw new Exception("JPEG buffer not initialized"); throw new Exception("JPEG buffer not initialized");
if(desiredWidth < 0 || desiredHeight < 0) if(desiredWidth < 0 || desiredHeight < 0)
throw new Exception("Invalid argument in getScaledHeight()"); throw new Exception("Invalid argument in getScaledHeight()");
TJ.ScalingFactor sf [] = TJ.getScalingFactors(); TJ.ScalingFactor sf[] = TJ.getScalingFactors();
if(desiredWidth == 0) desiredWidth = jpegWidth; if(desiredWidth == 0) desiredWidth = jpegWidth;
if(desiredHeight == 0) desiredHeight = jpegHeight; if(desiredHeight == 0) desiredHeight = jpegHeight;
int scaledWidth = jpegWidth, scaledHeight = jpegHeight; int scaledWidth = jpegWidth, scaledHeight = jpegHeight;
for(int i=0; i<sf.length; i++) { for(int i = 0; i < sf.length; i++) {
scaledWidth = (jpegWidth * sf[i].num + sf[i].denom - 1) / sf[i].denom; scaledWidth = (jpegWidth * sf[i].num + sf[i].denom - 1) / sf[i].denom;
scaledHeight = (jpegHeight * sf[i].num + sf[i].denom - 1) / sf[i].denom; scaledHeight = (jpegHeight * sf[i].num + sf[i].denom - 1) / sf[i].denom;
if(scaledWidth <= desiredWidth && scaledHeight <= desiredHeight) if(scaledWidth <= desiredWidth && scaledHeight <= desiredHeight)
@@ -112,7 +112,7 @@ public class TJDecompressor {
return scaledHeight; return scaledHeight;
} }
public void decompress(byte [] dstBuf, int desiredWidth, int pitch, public void decompress(byte[] dstBuf, int desiredWidth, int pitch,
int desiredHeight, int pixelFormat, int flags) throws Exception { int desiredHeight, int pixelFormat, int flags) throws Exception {
if(jpegBuf == null) throw new Exception("JPEG buffer not initialized"); if(jpegBuf == null) throw new Exception("JPEG buffer not initialized");
if(dstBuf == null || desiredWidth < 0 || pitch < 0 || desiredHeight < 0 if(dstBuf == null || desiredWidth < 0 || pitch < 0 || desiredHeight < 0
@@ -122,7 +122,7 @@ public class TJDecompressor {
desiredHeight, pixelFormat, flags); desiredHeight, pixelFormat, flags);
} }
public byte [] decompress(int desiredWidth, int pitch, int desiredHeight, public byte[] decompress(int desiredWidth, int pitch, int desiredHeight,
int pixelFormat, int flags) throws Exception { int pixelFormat, int flags) throws Exception {
if(desiredWidth < 0 || pitch < 0 || desiredHeight < 0 if(desiredWidth < 0 || pitch < 0 || desiredHeight < 0
|| pixelFormat < 0 || pixelFormat >= TJ.NUMPFOPT || flags < 0) || pixelFormat < 0 || pixelFormat >= TJ.NUMPFOPT || flags < 0)
@@ -131,26 +131,26 @@ public class TJDecompressor {
int scaledWidth = getScaledWidth(desiredWidth, desiredHeight); int scaledWidth = getScaledWidth(desiredWidth, desiredHeight);
int scaledHeight = getScaledHeight(desiredWidth, desiredHeight); int scaledHeight = getScaledHeight(desiredWidth, desiredHeight);
if(pitch == 0) pitch = scaledWidth * pixelSize; if(pitch == 0) pitch = scaledWidth * pixelSize;
byte [] buf = new byte[pitch * scaledHeight]; byte[] buf = new byte[pitch * scaledHeight];
decompress(buf, desiredWidth, pitch, desiredHeight, pixelFormat, flags); decompress(buf, desiredWidth, pitch, desiredHeight, pixelFormat, flags);
return buf; return buf;
} }
public void decompressToYUV(byte [] dstBuf, int flags) throws Exception { 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("JPEG buffer not initialized");
if(dstBuf == null || flags < 0) if(dstBuf == null || flags < 0)
throw new Exception("Invalid argument in decompressToYUV()"); throw new Exception("Invalid argument in decompressToYUV()");
decompressToYUV(jpegBuf, jpegBufSize, dstBuf, flags); decompressToYUV(jpegBuf, jpegBufSize, dstBuf, flags);
} }
public byte [] decompressToYUV(int flags) throws Exception { public byte[] decompressToYUV(int flags) throws Exception {
if(flags < 0) if(flags < 0)
throw new Exception("Invalid argument in decompressToYUV()"); throw new Exception("Invalid argument in decompressToYUV()");
if(jpegWidth < 1 || jpegHeight < 1 || jpegSubsamp < 0) if(jpegWidth < 1 || jpegHeight < 1 || jpegSubsamp < 0)
throw new Exception("JPEG buffer not initialized"); throw new Exception("JPEG buffer not initialized");
if(jpegSubsamp >= TJ.NUMSAMPOPT) if(jpegSubsamp >= TJ.NUMSAMPOPT)
throw new Exception("JPEG header information is invalid"); throw new Exception("JPEG header information is invalid");
byte [] buf = new byte[TJ.bufSizeYUV(jpegWidth, jpegHeight, jpegSubsamp)]; byte[] buf = new byte[TJ.bufSizeYUV(jpegWidth, jpegHeight, jpegSubsamp)];
decompressToYUV(buf, flags); decompressToYUV(buf, flags);
return buf; return buf;
} }
@@ -164,16 +164,16 @@ public class TJDecompressor {
int scaledHeight = getScaledHeight(desiredWidth, desiredHeight); int scaledHeight = getScaledHeight(desiredWidth, desiredHeight);
if(scaledWidth != desiredWidth || scaledHeight != desiredHeight) if(scaledWidth != desiredWidth || scaledHeight != desiredHeight)
throw new Exception("BufferedImage dimensions do not match a scaled image size that TurboJPEG is capable of generating."); throw new Exception("BufferedImage dimensions do not match a scaled image size that TurboJPEG is capable of generating.");
int pixelFormat; boolean intPixels=false; int pixelFormat; boolean intPixels = false;
switch(dstImage.getType()) { switch(dstImage.getType()) {
case BufferedImage.TYPE_3BYTE_BGR: case BufferedImage.TYPE_3BYTE_BGR:
pixelFormat=TJ.PF_BGR; break; pixelFormat = TJ.PF_BGR; break;
case BufferedImage.TYPE_BYTE_GRAY: case BufferedImage.TYPE_BYTE_GRAY:
pixelFormat=TJ.PF_GRAY; break; pixelFormat = TJ.PF_GRAY; break;
case BufferedImage.TYPE_INT_BGR: case BufferedImage.TYPE_INT_BGR:
pixelFormat=TJ.PF_RGBX; intPixels=true; break; pixelFormat = TJ.PF_RGBX; intPixels = true; break;
case BufferedImage.TYPE_INT_RGB: case BufferedImage.TYPE_INT_RGB:
pixelFormat=TJ.PF_BGRX; intPixels=true; break; pixelFormat = TJ.PF_BGRX; intPixels = true; break;
default: default:
throw new Exception("Unsupported BufferedImage format"); throw new Exception("Unsupported BufferedImage format");
} }
@@ -183,7 +183,7 @@ public class TJDecompressor {
(SinglePixelPackedSampleModel)dstImage.getSampleModel(); (SinglePixelPackedSampleModel)dstImage.getSampleModel();
int pitch = sm.getScanlineStride(); int pitch = sm.getScanlineStride();
DataBufferInt db = (DataBufferInt)wr.getDataBuffer(); DataBufferInt db = (DataBufferInt)wr.getDataBuffer();
int [] buf = db.getData(); int[] buf = db.getData();
if(jpegBuf == null) throw new Exception("JPEG buffer not initialized"); if(jpegBuf == null) throw new Exception("JPEG buffer not initialized");
decompress(jpegBuf, jpegBufSize, buf, scaledWidth, pitch, scaledHeight, decompress(jpegBuf, jpegBufSize, buf, scaledWidth, pitch, scaledHeight,
pixelFormat, flags); pixelFormat, flags);
@@ -196,7 +196,7 @@ public class TJDecompressor {
throw new Exception("Inconsistency between pixel format and pixel size in BufferedImage"); throw new Exception("Inconsistency between pixel format and pixel size in BufferedImage");
int pitch = sm.getScanlineStride(); int pitch = sm.getScanlineStride();
DataBufferByte db = (DataBufferByte)wr.getDataBuffer(); DataBufferByte db = (DataBufferByte)wr.getDataBuffer();
byte [] buf = db.getData(); byte[] buf = db.getData();
decompress(buf, scaledWidth, pitch, scaledHeight, pixelFormat, flags); decompress(buf, scaledWidth, pitch, scaledHeight, pixelFormat, flags);
} }
} }
@@ -220,8 +220,8 @@ public class TJDecompressor {
protected void finalize() throws Throwable { protected void finalize() throws Throwable {
try { try {
close(); close();
} catch(Exception e) {
} }
catch(Exception e) {}
finally { finally {
super.finalize(); super.finalize();
} }
@@ -231,18 +231,18 @@ public class TJDecompressor {
private native void destroy() throws Exception; private native void destroy() throws Exception;
private native void decompressHeader(byte [] srcBuf, int size) private native void decompressHeader(byte[] srcBuf, int size)
throws Exception; throws Exception;
private native void decompress(byte [] srcBuf, int size, byte [] dstBuf, private native void decompress(byte[] srcBuf, int size, byte[] dstBuf,
int desiredWidth, int pitch, int desiredHeight, int pixelFormat, int flags) int desiredWidth, int pitch, int desiredHeight, int pixelFormat, int flags)
throws Exception; throws Exception;
private native void decompress(byte [] srcBuf, int size, int [] dstBuf, private native void decompress(byte[] srcBuf, int size, int[] dstBuf,
int desiredWidth, int pitch, int desiredHeight, int pixelFormat, int flags) int desiredWidth, int pitch, int desiredHeight, int pixelFormat, int flags)
throws Exception; throws Exception;
private native void decompressToYUV(byte [] srcBuf, int size, byte [] dstBuf, private native void decompressToYUV(byte[] srcBuf, int size, byte[] dstBuf,
int flags) int flags)
throws Exception; throws Exception;
@@ -251,7 +251,7 @@ public class TJDecompressor {
} }
private long handle = 0; private long handle = 0;
private byte [] jpegBuf = null; private byte[] jpegBuf = null;
private int jpegBufSize = 0; private int jpegBufSize = 0;
private int jpegWidth = 0; private int jpegWidth = 0;
private int jpegHeight = 0; private int jpegHeight = 0;