/** * Create a TurboJPEG decompressor instance and associate the JPEG image of length <code>imageSize * </code> bytes stored in <code>jpegImage</code> with the newly-created instance. * * @param jpegImage JPEG image buffer * @param imageSize size of the JPEG image (in bytes) */ public TJDecompressor(byte[] jpegImage, int imageSize) throws Exception { init(); setJPEGImage(jpegImage, imageSize); }
private static void decompTest( TJDecompressor tjd, byte[] jpegBuf, int jpegSize, int w, int h, int pf, String baseName, int subsamp, int flags, TJScalingFactor sf) throws Exception { String pfStr, tempstr; double t; int scaledWidth = sf.getScaled(w); int scaledHeight = sf.getScaled(h); int temp1, temp2, imgType = pf; BufferedImage img = null; byte[] dstBuf = null; if (yuv == YUVENCODE) return; if (bi) { pf = biTypePF(imgType); pfStr = biTypeStr(imgType); } else pfStr = pixFormatStr[pf]; System.out.print("JPEG -> "); if (yuv == YUVDECODE) System.out.print("YUV " + subName[subsamp] + " ... "); else { System.out.print(pfStr + " "); if (bi) System.out.print("(" + pixFormatStr[pf] + ") "); if ((flags & TJ.FLAG_BOTTOMUP) != 0) System.out.print("Bottom-Up "); else System.out.print("Top-Down "); if (!sf.isOne()) System.out.print(sf.getNum() + "/" + sf.getDenom() + " ... "); else System.out.print("... "); } t = getTime(); tjd.setJPEGImage(jpegBuf, jpegSize); if (tjd.getWidth() != w || tjd.getHeight() != h || tjd.getSubsamp() != subsamp) throw new Exception("Incorrect JPEG header"); temp1 = scaledWidth; temp2 = scaledHeight; temp1 = tjd.getScaledWidth(temp1, temp2); temp2 = tjd.getScaledHeight(temp1, temp2); if (temp1 != scaledWidth || temp2 != scaledHeight) throw new Exception("Scaled size mismatch"); if (yuv == YUVDECODE) dstBuf = tjd.decompressToYUV(flags); else { if (bi) img = tjd.decompress(scaledWidth, scaledHeight, imgType, flags); else dstBuf = tjd.decompress(scaledWidth, 0, scaledHeight, pf, flags); } t = getTime() - t; if (bi) { tempstr = baseName + "_dec_" + pfStr + "_" + (((flags & TJ.FLAG_BOTTOMUP) != 0) ? "BU" : "TD") + "_" + subName[subsamp] + "_" + (double) sf.getNum() / (double) sf.getDenom() + "x" + ".png"; File file = new File(tempstr); ImageIO.write(img, "png", file); } if (yuv == YUVDECODE) { if (checkBufYUV(dstBuf, dstBuf.length, w, h, subsamp) == 1) System.out.print("Passed."); else { System.out.print("FAILED!"); exitStatus = -1; } } else { if ((bi && checkImg(img, pf, subsamp, sf, flags) == 1) || (!bi && checkBuf( dstBuf, scaledWidth, scaledWidth * TJ.getPixelSize(pf), scaledHeight, pf, subsamp, sf, flags) == 1)) System.out.print("Passed."); else { System.out.print("FAILED!"); exitStatus = -1; } } System.out.format(" %.6f ms\n", t * 1000.); }
/** * Create a TurboJPEG decompressor instance and associate the JPEG image stored in <code>jpegImage * </code> with the newly-created instance. * * @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(); setJPEGImage(jpegImage, jpegImage.length); }