tjGetScaledSize() would never be able to accommodate scaling factors > 1, so replace it with a function that returns a list of fractional scaling factors that TurboJPEG supports.
git-svn-id: svn+ssh://svn.code.sf.net/p/libjpeg-turbo/code/trunk@477 632fc199-4ca6-4c93-a231-07263d6284db
This commit is contained in:
@@ -253,14 +253,14 @@ public class TJUnitTest {
|
||||
}
|
||||
|
||||
private static int checkbuf(byte [] buf, int w, int pitch, int h, int pf,
|
||||
int subsamp, int scalefactor, int flags) throws Exception
|
||||
int subsamp, int scale_num, int scale_denom, int flags) throws Exception
|
||||
{
|
||||
int roffset=TJ.getRedShift(pf)/8;
|
||||
int goffset=TJ.getGreenShift(pf)/8;
|
||||
int boffset=TJ.getBlueShift(pf)/8;
|
||||
int ps=TJ.getPixelSize(pf);
|
||||
int i, _i, j, retval=1;
|
||||
int halfway=16/scalefactor, blocksize=8/scalefactor;
|
||||
int halfway=16*scale_num/scale_denom, blocksize=8*scale_num/scale_denom;
|
||||
|
||||
try
|
||||
{
|
||||
@@ -350,13 +350,13 @@ public class TJUnitTest {
|
||||
}
|
||||
|
||||
private static int checkintbuf(int [] buf, int w, int pitch, int h, int pf,
|
||||
int subsamp, int scalefactor, int flags) throws Exception
|
||||
int subsamp, int scale_num, int scale_denom, int flags) throws Exception
|
||||
{
|
||||
int rshift=TJ.getRedShift(pf);
|
||||
int gshift=TJ.getGreenShift(pf);
|
||||
int bshift=TJ.getBlueShift(pf);
|
||||
int i, _i, j, retval=1;
|
||||
int halfway=16/scalefactor, blocksize=8/scalefactor;
|
||||
int halfway=16*scale_num/scale_denom, blocksize=8*scale_num/scale_denom;
|
||||
|
||||
try
|
||||
{
|
||||
@@ -448,7 +448,7 @@ public class TJUnitTest {
|
||||
}
|
||||
|
||||
private static int checkimg(BufferedImage img, int pf,
|
||||
int subsamp, int scalefactor, int flags) throws Exception
|
||||
int subsamp, int scale_num, int scale_denom, int flags) throws Exception
|
||||
{
|
||||
WritableRaster wr=img.getRaster();
|
||||
int imgtype=img.getType();
|
||||
@@ -461,7 +461,7 @@ public class TJUnitTest {
|
||||
DataBufferInt db=(DataBufferInt)wr.getDataBuffer();
|
||||
int [] buf = db.getData();
|
||||
return checkintbuf(buf, img.getWidth(), pitch, img.getHeight(), pf,
|
||||
subsamp, scalefactor, flags);
|
||||
subsamp, scale_num, scale_denom, flags);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -471,7 +471,7 @@ public class TJUnitTest {
|
||||
DataBufferByte db=(DataBufferByte)wr.getDataBuffer();
|
||||
byte [] buf = db.getData();
|
||||
return checkbuf(buf, img.getWidth(), pitch, img.getHeight(), pf, subsamp,
|
||||
scalefactor, flags);
|
||||
scale_num, scale_denom, flags);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -681,12 +681,12 @@ public class TJUnitTest {
|
||||
|
||||
private static void _gentestbmp(TJDecompressor tjd, byte [] jpegbuf,
|
||||
int jpegsize, int w, int h, int pf, String basefilename, int subsamp,
|
||||
int flags, int scalefactor) throws Exception
|
||||
int flags, int scale_num, int scale_denom) throws Exception
|
||||
{
|
||||
String pixformat, tempstr; int _hdrw=0, _hdrh=0, _hdrsubsamp=-1;
|
||||
double t;
|
||||
int scaledw=(w+scalefactor-1)/scalefactor;
|
||||
int scaledh=(h+scalefactor-1)/scalefactor;
|
||||
int scaledw=(w*scale_num+scale_denom-1)/scale_denom;
|
||||
int scaledh=(h*scale_num+scale_denom-1)/scale_denom;
|
||||
int temp1, temp2;
|
||||
BufferedImage img=null; byte [] bmpbuf=null;
|
||||
|
||||
@@ -701,7 +701,8 @@ public class TJUnitTest {
|
||||
System.out.print(pixformat+" ");
|
||||
if((flags&TJ.BOTTOMUP)!=0) System.out.print("Bottom-Up ");
|
||||
else System.out.print("Top-Down ");
|
||||
if(scalefactor!=1) System.out.print("1/"+scalefactor+" ... ");
|
||||
if(scale_num!=1 || scale_denom!=1)
|
||||
System.out.print(scale_num+"/"+scale_denom+" ... ");
|
||||
else System.out.print("... ");
|
||||
}
|
||||
|
||||
@@ -728,7 +729,7 @@ public class TJUnitTest {
|
||||
{
|
||||
tempstr=basefilename+"_dec_"+pixformat+"_"
|
||||
+(((flags&TJ.BOTTOMUP)!=0)? "BU":"TD")+"_"+_subnames[subsamp]
|
||||
+"_"+scalefactor+"x"+".png";
|
||||
+"_"+(double)scale_num/(double)scale_denom+"x"+".png";
|
||||
File file=new File(tempstr);
|
||||
ImageIO.write(img, "png", file);
|
||||
}
|
||||
@@ -741,9 +742,9 @@ public class TJUnitTest {
|
||||
}
|
||||
else
|
||||
{
|
||||
if((bi && checkimg(img, pf, subsamp, scalefactor, flags)==1)
|
||||
if((bi && checkimg(img, pf, subsamp, scale_num, scale_denom, flags)==1)
|
||||
|| (!bi && checkbuf(bmpbuf, scaledw, scaledw*TJ.getPixelSize(pf),
|
||||
scaledh, pf, subsamp, scalefactor, flags)==1))
|
||||
scaledh, pf, subsamp, scale_num, scale_denom, flags)==1))
|
||||
System.out.print("Passed.");
|
||||
else
|
||||
{
|
||||
@@ -760,13 +761,14 @@ public class TJUnitTest {
|
||||
int i;
|
||||
if((subsamp==TJ.SAMP_444 || subsamp==TJ.SAMP_GRAY) && yuv==0)
|
||||
{
|
||||
for(i=1; i<=8; i*=2)
|
||||
TJ.ScalingFactor sf []=TJ.getScalingFactors();
|
||||
for(i=0; i<sf.length; i++)
|
||||
_gentestbmp(tjd, jpegbuf, jpegsize, w, h, pf, basefilename, subsamp,
|
||||
flags, i);
|
||||
flags, sf[i].num, sf[i].denom);
|
||||
}
|
||||
else
|
||||
_gentestbmp(tjd, jpegbuf, jpegsize, w, h, pf, basefilename, subsamp,
|
||||
flags, 1);
|
||||
flags, 1, 1);
|
||||
System.out.print("\n");
|
||||
}
|
||||
|
||||
|
||||
@@ -30,6 +30,11 @@ package org.libjpegturbo.turbojpeg;
|
||||
|
||||
final public class TJ {
|
||||
|
||||
final public class ScalingFactor {
|
||||
public int num = 1;
|
||||
public int denom = 1;
|
||||
};
|
||||
|
||||
// Chrominance subsampling options
|
||||
final public static int
|
||||
NUMSAMPOPT = 4,
|
||||
@@ -105,6 +110,9 @@ final public class TJ {
|
||||
int subsamp)
|
||||
throws Exception;
|
||||
|
||||
public native final static ScalingFactor [] getScalingFactors()
|
||||
throws Exception;
|
||||
|
||||
static {
|
||||
System.loadLibrary("turbojpeg");
|
||||
}
|
||||
|
||||
@@ -76,8 +76,19 @@ public class TJDecompressor {
|
||||
throw new Exception("JPEG buffer not initialized");
|
||||
if(desiredWidth < 0 || desiredHeight < 0)
|
||||
throw new Exception("Invalid argument in getScaledWidth()");
|
||||
return getScaledWidth(jpegWidth, jpegHeight, desiredWidth,
|
||||
desiredHeight);
|
||||
TJ.ScalingFactor sf [] = TJ.getScalingFactors();
|
||||
if(desiredWidth == 0) desiredWidth = jpegWidth;
|
||||
if(desiredHeight == 0) desiredHeight = jpegHeight;
|
||||
int scaledWidth = jpegWidth, scaledHeight = jpegHeight;
|
||||
for(int i=0; i<sf.length; i++) {
|
||||
scaledWidth = (jpegWidth * 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)
|
||||
break;
|
||||
}
|
||||
if(scaledWidth > desiredWidth || scaledHeight > desiredHeight)
|
||||
throw new Exception("Could not scale down to desired image dimensions");
|
||||
return scaledWidth;
|
||||
}
|
||||
|
||||
public int getScaledHeight(int desiredWidth, int desiredHeight)
|
||||
@@ -86,8 +97,19 @@ public class TJDecompressor {
|
||||
throw new Exception("JPEG buffer not initialized");
|
||||
if(desiredWidth < 0 || desiredHeight < 0)
|
||||
throw new Exception("Invalid argument in getScaledHeight()");
|
||||
return getScaledHeight(jpegWidth, jpegHeight, desiredWidth,
|
||||
desiredHeight);
|
||||
TJ.ScalingFactor sf [] = TJ.getScalingFactors();
|
||||
if(desiredWidth == 0) desiredWidth = jpegWidth;
|
||||
if(desiredHeight == 0) desiredHeight = jpegHeight;
|
||||
int scaledWidth = jpegWidth, scaledHeight = jpegHeight;
|
||||
for(int i=0; i<sf.length; i++) {
|
||||
scaledWidth = (jpegWidth * 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)
|
||||
break;
|
||||
}
|
||||
if(scaledWidth > desiredWidth || scaledHeight > desiredHeight)
|
||||
throw new Exception("Could not scale down to desired image dimensions");
|
||||
return scaledHeight;
|
||||
}
|
||||
|
||||
public void decompress(byte [] dstBuf, int desiredWidth, int pitch,
|
||||
@@ -224,12 +246,6 @@ public class TJDecompressor {
|
||||
int flags)
|
||||
throws Exception;
|
||||
|
||||
private native int getScaledWidth(int jpegWidth, int jpegHeight,
|
||||
int desiredWidth, int desiredHeight) throws Exception;
|
||||
|
||||
private native int getScaledHeight(int jpegWidth, int jpegHeight,
|
||||
int desiredWidth, int desiredHeight) throws Exception;
|
||||
|
||||
static {
|
||||
System.loadLibrary("turbojpeg");
|
||||
}
|
||||
|
||||
@@ -61,6 +61,14 @@ JNIEXPORT jint JNICALL Java_org_libjpegturbo_turbojpeg_TJ_bufSize
|
||||
JNIEXPORT jint JNICALL Java_org_libjpegturbo_turbojpeg_TJ_bufSizeYUV
|
||||
(JNIEnv *, jclass, jint, jint, jint);
|
||||
|
||||
/*
|
||||
* Class: org_libjpegturbo_turbojpeg_TJ
|
||||
* Method: getScalingFactors
|
||||
* Signature: ()[Lorg/libjpegturbo/turbojpeg/TJ/ScalingFactor;
|
||||
*/
|
||||
JNIEXPORT jobjectArray JNICALL Java_org_libjpegturbo_turbojpeg_TJ_getScalingFactors
|
||||
(JNIEnv *, jclass);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -55,22 +55,6 @@ JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJDecompressor_decompress
|
||||
JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJDecompressor_decompressToYUV
|
||||
(JNIEnv *, jobject, jbyteArray, jint, jbyteArray, jint);
|
||||
|
||||
/*
|
||||
* Class: org_libjpegturbo_turbojpeg_TJDecompressor
|
||||
* Method: getScaledWidth
|
||||
* Signature: (IIII)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_org_libjpegturbo_turbojpeg_TJDecompressor_getScaledWidth
|
||||
(JNIEnv *, jobject, jint, jint, jint, jint);
|
||||
|
||||
/*
|
||||
* Class: org_libjpegturbo_turbojpeg_TJDecompressor
|
||||
* Method: getScaledHeight
|
||||
* Signature: (IIII)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_org_libjpegturbo_turbojpeg_TJDecompressor_getScaledHeight
|
||||
(JNIEnv *, jobject, jint, jint, jint, jint);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user