in java/TJUnitTest.java [741:820]
static void decompTest(TJDecompressor tjd, byte[] jpegBuf, int jpegSize,
int w, int h, int pf, String baseName, int subsamp,
TJScalingFactor sf) throws Exception {
String pfStr, pfStrLong, tempStr;
boolean bottomUp = (tjd.get(TJ.PARAM_BOTTOMUP) == 1);
String buStrLong = bottomUp ? "Bottom-Up" : "Top-Down ";
int scaledWidth = sf.getScaled(w);
int scaledHeight = sf.getScaled(h);
int temp1, temp2, imgType = pf;
BufferedImage img = null;
Object dstBuf = null;
if (bi) {
pf = biTypePF(imgType);
pfStr = biTypeStr(imgType);
pfStrLong = pfStr + " (" + PIXFORMATSTR[pf] + ")";
} else {
pfStr = PIXFORMATSTR[pf];
pfStrLong = pfStr;
}
tjd.setSourceImage(jpegBuf, jpegSize);
tjd.setScalingFactor(sf);
if (lossless && subsamp != TJ.SAMP_444 && subsamp != TJ.SAMP_GRAY)
subsamp = TJ.SAMP_444;
if (tjd.getWidth() != w || tjd.getHeight() != h ||
tjd.get(TJ.PARAM_SUBSAMP) != subsamp)
throw new Exception("Incorrect JPEG header");
if (doYUV) {
System.out.format("JPEG -> YUV %s ", SUBNAME_LONG[subsamp]);
if (!sf.isOne())
System.out.format("%d/%d ... ", sf.getNum(), sf.getDenom());
else System.out.print("... ");
YUVImage yuvImage = tjd.decompressToYUV(yuvAlign);
if (checkBufYUV(yuvImage.getBuf(), yuvImage.getSize(), scaledWidth,
scaledHeight, subsamp, sf) == 1)
System.out.print("Passed.\n");
else {
System.out.print("FAILED!\n"); exitStatus = -1;
}
System.out.format("YUV %s -> %s %s ... ", SUBNAME_LONG[subsamp],
pfStrLong, buStrLong);
tjd.setSourceImage(yuvImage);
} else {
System.out.format("JPEG -> %s %s ", pfStrLong, buStrLong);
if (!sf.isOne())
System.out.format("%d/%d ... ", sf.getNum(), sf.getDenom());
else System.out.print("... ");
}
if (bi)
img = tjd.decompress8(imgType);
else {
if (precision == 8)
dstBuf = tjd.decompress8(0, pf);
else if (precision == 12)
dstBuf = tjd.decompress12(0, pf);
else
dstBuf = tjd.decompress16(0, pf);
}
if (bi) {
tempStr = baseName + "_dec_" + pfStr + "_" + (bottomUp ? "BU" : "TD") +
"_" + SUBNAME[subsamp] + "_" +
(double)sf.getNum() / (double)sf.getDenom() + "x" + ".png";
File file = new File(tempStr);
ImageIO.write(img, "png", file);
}
if ((bi && checkImg(img, pf, subsamp, sf, bottomUp) == 1) ||
(!bi && checkBuf(dstBuf, scaledWidth,
scaledWidth * TJ.getPixelSize(pf), scaledHeight, pf,
subsamp, sf, bottomUp) == 1))
System.out.print("Passed.\n");
else {
System.out.print("FAILED!\n");
exitStatus = -1;
}
}