From fc26b6577a2c422899e5cb9f483ee9d3ed37e185 Mon Sep 17 00:00:00 2001 From: DRC Date: Sun, 16 Mar 2014 22:56:26 +0000 Subject: [PATCH] Extend the YUV decode functionality to the TurboJPEG Java API, and port the TJUnitTest modifications that treat YUV encoding/decoding as an intermediate step of the JPEG compression/decompression pipeline rather than a separate test case; Add the ability to encode YUV images from an arbitrary position in a large image buffer; Significantly refactor the handling of YUV images; numerous doc tweaks; other Java API cleanup and usability improvements git-svn-id: svn+ssh://svn.code.sf.net/p/libjpeg-turbo/code/trunk@1176 632fc199-4ca6-4c93-a231-07263d6284db --- ChangeLog.txt | 39 +- java/Makefile.am | 2 + java/TJBench.java | 24 +- java/TJExample.java | 2 +- java/TJUnitTest.java | 310 +++------ java/doc/allclasses-frame.html | 2 + java/doc/allclasses-noframe.html | 2 + java/doc/deprecated-list.html | 28 +- java/doc/index-all.html | 213 ++++-- .../libjpegturbo/turbojpeg/TJCompressor.html | 262 +++---- .../turbojpeg/TJDecompressor.html | 607 ++++++++++------ .../libjpegturbo/turbojpeg/TJTransformer.html | 36 +- .../libjpegturbo/turbojpeg/package-frame.html | 4 +- .../turbojpeg/package-summary.html | 5 + .../libjpegturbo/turbojpeg/package-tree.html | 2 +- java/doc/overview-tree.html | 2 +- .../libjpegturbo/turbojpeg/TJCompressor.java | 278 ++++---- .../turbojpeg/TJDecompressor.java | 652 +++++++++++------- .../libjpegturbo/turbojpeg/TJTransformer.java | 32 +- java/org/libjpegturbo/turbojpeg/YUVImage.java | 193 ++++++ .../org_libjpegturbo_turbojpeg_TJCompressor.h | 12 +- ...rg_libjpegturbo_turbojpeg_TJDecompressor.h | 16 + turbojpeg-jni.c | 150 +++- turbojpeg-mapfile.jni | 6 +- 24 files changed, 1792 insertions(+), 1087 deletions(-) create mode 100644 java/org/libjpegturbo/turbojpeg/YUVImage.java diff --git a/ChangeLog.txt b/ChangeLog.txt index 5c83016..25f673e 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,30 +1,31 @@ 1.4 pre-beta ============ -[1] The TurboJPEG API can now be used to generate YUV images with an arbitrary -line padding (previously, it only supported 4-byte padding, which was -compatible with X Video.) Also, the decompress-to-YUV function has been -extended to support image scaling. +[1] New features in the TurboJPEG API: +-- YUV planar images can now be generated with an arbitrary line padding +(previously only 4-byte padding, which was compatible with X Video, was +supported.) +-- The decompress-to-YUV function has been extended to support image scaling. +-- JPEG images can now be compressed from YUV planar source images. +-- YUV planar images can now be decoded into RGB or grayscale images. +-- 4:1:1 subsampling is now supported. This is mainly included for +compatibility, since 4:1:1 is not fully accelerated in libjpeg-turbo and has no +significant advantages relative to 4:2:0. +-- CMYK images are now supported. This feature allows CMYK source images to be +compressed to YCCK JPEGs and YCCK or CMYK JPEGs to be decompressed to CMYK +destination images. Conversion between CMYK and RGB or YUV images is not +supported. Such conversion requires a color management system and is out of +scope for a codec library. +-- The handling of YUV images in the Java API has been significantly refactored +and should now be much more intuitive. +-- The Java API now supports encoding a YUV image from an arbitrary position in +a large image buffer. [2] Added SIMD acceleration for DSPr2-capable MIPS platforms. This speeds up the compression of full-color JPEGs by 70-80% on such platforms and decompression by 25-35%. -[3] Added support for 4:1:1 subsampling to the TurboJPEG API. This is mainly -included for compatibility, since 4:1:1 is not fully accelerated in -libjpeg-turbo and has no significant advantages relative to 4:2:0. - -[4] Added support for CMYK images to the TurboJPEG API. This feature allows -CMYK source images to be compressed to YCCK JPEGs and YCCK or CMYK JPEGs to be -decompressed to CMYK destination images. Conversion between CMYK and RGB -images is not supported. Such conversion requires a color management system -and is out of scope for a codec library. - -[5] The TurboJPEG API can now be used to compress JPEG images from YUV planar -source images and to decode YUV planar images into RGB, grayscale, or extended -RGB images. - -[6] If an application attempts to decompress a Huffman-coded JPEG image whose +[3] If an application attempts to decompress a Huffman-coded JPEG image whose header does not contain Huffman tables, libjpeg-turbo will now insert the default Huffman tables. In order to save space, many motion JPEG video frames are encoded without the default Huffman tables, so these frames can now be diff --git a/java/Makefile.am b/java/Makefile.am index 1307d69..23e3412 100644 --- a/java/Makefile.am +++ b/java/Makefile.am @@ -13,6 +13,7 @@ JAVASOURCES = org/libjpegturbo/turbojpeg/TJ.java \ org/libjpegturbo/turbojpeg/TJScalingFactor.java \ org/libjpegturbo/turbojpeg/TJTransform.java \ org/libjpegturbo/turbojpeg/TJTransformer.java \ + org/libjpegturbo/turbojpeg/YUVImage.java \ TJExample.java \ TJUnitTest.java \ TJBench.java @@ -34,6 +35,7 @@ JAVA_CLASSES = org/libjpegturbo/turbojpeg/TJ.class \ org/libjpegturbo/turbojpeg/TJScalingFactor.class \ org/libjpegturbo/turbojpeg/TJTransform.class \ org/libjpegturbo/turbojpeg/TJTransformer.class \ + org/libjpegturbo/turbojpeg/YUVImage.class \ TJExample.class \ TJUnitTest.class \ TJBench.class diff --git a/java/TJBench.java b/java/TJBench.java index 50cbadf..7df0ce2 100644 --- a/java/TJBench.java +++ b/java/TJBench.java @@ -146,6 +146,7 @@ class TJBench { int scaledh = sf.getScaled(h); int yuvSize = TJ.bufSizeYUV(scaledw, yuvpad, scaledh, subsamp), bufsize; int pitch = scaledw * ps; + YUVImage yuvImage = null; if (jpegQual > 0) qualStr = new String("_Q" + jpegQual); @@ -161,9 +162,11 @@ class TJBench { Arrays.fill(dstBuf, (byte)127); /* Execute once to preload cache */ - tjd.setJPEGImage(jpegBuf[0], jpegSize[0]); - if (yuv == YUVDECODE) - tjd.decompressToYUV(dstBuf, scaledw, yuvpad, scaledh, flags); + tjd.setSourceImage(jpegBuf[0], jpegSize[0]); + if (yuv == YUVDECODE) { + yuvImage = new YUVImage(dstBuf, scaledw, yuvpad, scaledh, subsamp); + tjd.decompressToYUV(yuvImage, flags); + } else tjd.decompress(dstBuf, 0, 0, scaledw, pitch, scaledh, pf, flags); @@ -172,13 +175,13 @@ class TJBench { i++) { int tile = 0; if (yuv == YUVDECODE) - tjd.decompressToYUV(dstBuf, scaledw, yuvpad, scaledh, flags); + tjd.decompressToYUV(yuvImage, flags); else { for (int y = 0; y < h; y += tileh) { for (int x = 0; x < w; x += tilew, tile++) { int width = doTile ? Math.min(tilew, w - x) : scaledw; int height = doTile ? Math.min(tileh, h - y) : scaledh; - tjd.setJPEGImage(jpegBuf[tile], jpegSize[tile]); + tjd.setSourceImage(jpegBuf[tile], jpegSize[tile]); tjd.decompress(dstBuf, x, y, width, pitch, height, pf, flags); } } @@ -258,6 +261,7 @@ class TJBench { double start, elapsed; int ps = TJ.getPixelSize(pf), i; int yuvSize = 0; + YUVImage yuvImage; yuvSize = TJ.bufSizeYUV(w, yuvpad, h, subsamp); dstBuf = new byte[yuvSize]; @@ -277,12 +281,13 @@ class TJBench { tjc.setSubsamp(subsamp); /* Execute once to preload cache */ - tjc.encodeYUV(dstBuf, flags); + yuvImage = new YUVImage(dstBuf, w, yuvpad, h, subsamp); + tjc.encodeYUV(yuvImage, flags); /* Benchmark */ for (i = 0, start = getTime(); (elapsed = getTime() - start) < benchTime; i++) - tjc.encodeYUV(dstBuf, flags); + tjc.encodeYUV(yuvImage, flags); if (quiet == 1) System.out.format("%-4d %-4d\t", w, h); @@ -360,7 +365,8 @@ class TJBench { for (i = 0; i < h; i++) System.arraycopy(srcBuf, w * ps * i, tmpBuf, pitch * i, w * ps); if (yuv == YUVCOMPRESS) - tjc.setSourceImageYUV(srcBuf, tilew, yuvpad, tileh); + tjc.setSourceImage(new YUVImage(srcBuf, tilew, yuvpad, tileh, + subsamp)); else tjc.setSourceImage(srcBuf, 0, 0, tilew, pitch, tileh, pf); tjc.setJPEGQuality(jpegQual); @@ -458,7 +464,7 @@ class TJBench { tjt = new TJTransformer(); - tjt.setJPEGImage(srcBuf, srcSize); + tjt.setSourceImage(srcBuf, srcSize); w = tjt.getWidth(); h = tjt.getHeight(); subsamp = tjt.getSubsamp(); diff --git a/java/TJExample.java b/java/TJExample.java index 7562114..2c6324d 100644 --- a/java/TJExample.java +++ b/java/TJExample.java @@ -277,7 +277,7 @@ public class TJExample implements TJCustomFilter { scaleFactor.isOne()) { file = new File(argv[1]); FileOutputStream fos = new FileOutputStream(file); - fos.write(tjd.getJPEGBuf(), 0, tjd.getJPEGSize()); + fos.write(tjd.getSourceBuf(), 0, tjd.getSourceSize()); fos.close(); System.exit(0); } diff --git a/java/TJUnitTest.java b/java/TJUnitTest.java index 0bf8367..d8b5c85 100644 --- a/java/TJUnitTest.java +++ b/java/TJUnitTest.java @@ -92,9 +92,7 @@ public class TJUnitTest { TJ.PF_RGB }; - private static final int YUVENCODE = 1; - private static final int YUVDECODE = 2; - private static int yuv = 0; + private static boolean doYUV = false; private static int pad = 4; private static boolean bi = false; @@ -534,54 +532,6 @@ public class TJUnitTest { return ((v + (p) - 1) & (~((p) - 1))); } - private static void initBufYUV(byte[] buf, int w, int pad, int h, - int subsamp) throws Exception { - int row, col; - int hsf = TJ.getMCUWidth(subsamp) / 8, vsf = TJ.getMCUHeight(subsamp) / 8; - int pw = PAD(w, hsf), ph = PAD(h, vsf); - int cw = pw / hsf, ch = ph / vsf; - int ypitch = PAD(pw, pad), uvpitch = PAD(cw, pad); - int halfway = 16, blockSize = 8; - - Arrays.fill(buf, (byte)0); - for (row = 0; row < ph; row++) { - for (col = 0; col < pw; col++) { - int index = ypitch * row + col; - if (((row / blockSize) + (col / blockSize)) % 2 == 0) { - if (row < halfway) - buf[index] = (byte)255; - else - buf[index] = 0; - } else { - if (row < halfway) - buf[index] = 76; - else - buf[index] = (byte)226; - } - } - } - if (subsamp != TJ.SAMP_GRAY) { - halfway = 16 / vsf; - for (row = 0; row < ch; row++) { - for (col = 0; col < cw; col++) { - int uindex = ypitch * ph + (uvpitch * row + col), - vindex = ypitch * ph + uvpitch * ch + (uvpitch * row + col); - if (((row * vsf / blockSize) + (col * hsf / blockSize)) % 2 == 0) { - buf[uindex] = buf[vindex] = (byte)128; - } else { - if (row < halfway) { - buf[uindex] = 85; - buf[vindex] = (byte)255; - } else { - buf[uindex] = 0; - buf[vindex] = (byte)149; - } - } - } - } - } - } - private static int checkBufYUV(byte[] buf, int size, int w, int h, int subsamp, TJScalingFactor sf) throws Exception { @@ -686,87 +636,68 @@ public class TJUnitTest { private static int compTest(TJCompressor tjc, byte[] dstBuf, int w, int h, int pf, String baseName, int subsamp, int jpegQual, int flags) throws Exception { - String tempstr; + String tempStr; byte[] srcBuf = null; BufferedImage img = null; - String pfStr; + String pfStr, pfStrLong; + String buStr = (flags & TJ.FLAG_BOTTOMUP) != 0 ? "BU" : "TD"; String buStrLong = (flags & TJ.FLAG_BOTTOMUP) != 0 ? "Bottom-Up" : "Top-Down "; - String buStr = (flags & TJ.FLAG_BOTTOMUP) != 0 ? "BU" : "TD"; int size = 0, ps, imgType = pf; - if (yuv == YUVDECODE) { - System.out.format("YUV %s %s --> JPEG Q%d ... ", subNameLong[subsamp], - buStrLong, jpegQual); - srcBuf = new byte[TJ.bufSizeYUV(w, pad, h, subsamp)]; - initBufYUV(srcBuf, w, pad, h, subsamp); - pfStr = "YUV"; + if (bi) { + pf = biTypePF(imgType); + pfStr = biTypeStr(imgType); + pfStrLong = pfStr + " (" + pixFormatStr[pf] + ")"; } else { - if (bi) { - pf = biTypePF(imgType); - pfStr = biTypeStr(imgType); - } else - pfStr = pixFormatStr[pf]; - ps = TJ.getPixelSize(pf); - - System.out.print(pfStr + " "); - if (bi) - System.out.print("(" + pixFormatStr[pf] + ") "); - if (yuv == YUVENCODE) - System.out.format("%s -> %s YUV ... ", buStrLong, - subNameLong[subsamp]); - else - System.out.format("%s -> %s Q%d ... ", buStrLong, subNameLong[subsamp], - jpegQual); + pfStr = pixFormatStr[pf]; + pfStrLong = pfStr; + } + ps = TJ.getPixelSize(pf); - if (bi) { - img = new BufferedImage(w, h, imgType); - initImg(img, pf, flags); - tempstr = baseName + "_enc_" + pfStr + "_" + buStr + "_" + - subName[subsamp] + "_Q" + jpegQual + ".png"; - File file = new File(tempstr); - ImageIO.write(img, "png", file); - } else { - srcBuf = new byte[w * h * ps + 1]; - initBuf(srcBuf, w, w * ps, h, pf, flags); - } + if (bi) { + img = new BufferedImage(w, h, imgType); + initImg(img, pf, flags); + tempStr = baseName + "_enc_" + pfStr + "_" + buStr + "_" + + subName[subsamp] + "_Q" + jpegQual + ".png"; + File file = new File(tempStr); + ImageIO.write(img, "png", file); + tjc.setSourceImage(img, 0, 0, 0, 0); + } else { + srcBuf = new byte[w * h * ps + 1]; + initBuf(srcBuf, w, w * ps, h, pf, flags); + tjc.setSourceImage(srcBuf, 0, 0, w, 0, h, pf); } Arrays.fill(dstBuf, (byte)0); tjc.setSubsamp(subsamp); tjc.setJPEGQuality(jpegQual); - tjc.setYUVPad(pad); - if (yuv == YUVDECODE) - tjc.setSourceImageYUV(srcBuf, w, pad, h); - else if (bi) - tjc.setSourceImage(img, 0, 0, 0, 0); - else - tjc.setSourceImage(srcBuf, 0, 0, w, 0, h, pf); - if (yuv == YUVENCODE) - tjc.encodeYUV(dstBuf, flags); - else - tjc.compress(dstBuf, flags); - size = tjc.getCompressedSize(); - - if (yuv == YUVENCODE) - tempstr = baseName + "_enc_" + pfStr + "_" + buStr + "_" + - subName[subsamp] + ".yuv"; - else - tempstr = baseName + "_enc_" + pfStr + "_" + buStr + "_" + - subName[subsamp] + "_Q" + jpegQual + ".jpg"; - writeJPEG(dstBuf, size, tempstr); - - if (yuv == YUVENCODE) { - if (checkBufYUV(dstBuf, size, w, h, subsamp, - new TJScalingFactor(1, 1)) == 1) - System.out.print("Passed."); + if (doYUV) { + System.out.format("%s %s -> YUV %s ... ", pfStrLong, buStrLong, + subNameLong[subsamp]); + YUVImage yuvImage = tjc.encodeYUV(pad, flags); + if (checkBufYUV(yuvImage.getBuf(), yuvImage.getSize(), w, h, subsamp, + new TJScalingFactor(1, 1)) == 1) + System.out.print("Passed.\n"); else { - System.out.print("FAILED!"); + System.out.print("FAILED!\n"); exitStatus = -1; } - } else - System.out.print("Done."); - System.out.println("\n Result in " + tempstr); + + System.out.format("YUV %s %s -> JPEG Q%d ... ", subNameLong[subsamp], + buStrLong, jpegQual); + tjc.setSourceImage(yuvImage); + } else { + System.out.format("%s %s -> %s Q%d ... ", pfStrLong, buStrLong, + subNameLong[subsamp], jpegQual); + } + tjc.compress(dstBuf, flags); + size = tjc.getCompressedSize(); + + tempStr = baseName + "_enc_" + pfStr + "_" + buStr + "_" + + subName[subsamp] + "_Q" + jpegQual + ".jpg"; + writeJPEG(dstBuf, size, tempStr); + System.out.println("Done.\n Result in " + tempStr); return size; } @@ -775,39 +706,25 @@ public class TJUnitTest { int jpegSize, int w, int h, int pf, String baseName, int subsamp, int flags, TJScalingFactor sf) throws Exception { - String pfStr, tempstr; + String pfStr, pfStrLong, tempStr; + String buStrLong = (flags & TJ.FLAG_BOTTOMUP) != 0 ? + "Bottom-Up" : "Top-Down "; 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 + pfStrLong = pfStr + " (" + pixFormatStr[pf] + ")"; + } else { pfStr = pixFormatStr[pf]; - - System.out.print("JPEG -> "); - if (yuv == YUVDECODE) - System.out.print("YUV " + subNameLong[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 "); + pfStrLong = pfStr; } - if (!sf.isOne()) - System.out.print(sf.getNum() + "/" + sf.getDenom() + " ... "); - else - System.out.print("... "); - tjd.setJPEGImage(jpegBuf, jpegSize); + tjd.setSourceImage(jpegBuf, jpegSize); if (tjd.getWidth() != w || tjd.getHeight() != h || tjd.getSubsamp() != subsamp) throw new Exception("Incorrect JPEG header"); @@ -819,43 +736,52 @@ public class TJUnitTest { if (temp1 != scaledWidth || temp2 != scaledHeight) throw new Exception("Scaled size mismatch"); - if (yuv == YUVDECODE) - dstBuf = tjd.decompressToYUV(scaledWidth, pad, scaledHeight, flags); - else { - if (bi) - img = tjd.decompress(scaledWidth, scaledHeight, imgType, flags); - else - dstBuf = tjd.decompress(scaledWidth, 0, scaledHeight, pf, flags); + if (doYUV) { + System.out.format("JPEG -> YUV %s ", subNameLong[subsamp]); + if(!sf.isOne()) + System.out.format("%d/%d ... ", sf.getNum(), sf.getDenom()); + else System.out.print("... "); + YUVImage yuvImage = tjd.decompressToYUV(scaledWidth, pad, scaledHeight, + flags); + 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 ... ", subNameLong[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.decompress(scaledWidth, scaledHeight, imgType, flags); + else + dstBuf = tjd.decompress(scaledWidth, 0, scaledHeight, pf, flags); if (bi) { - tempstr = baseName + "_dec_" + pfStr + "_" + + 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); + File file = new File(tempStr); ImageIO.write(img, "png", file); } - if (yuv == YUVDECODE) { - if (checkBufYUV(dstBuf, dstBuf.length, scaledWidth, scaledHeight, - subsamp, sf) == 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; - } + 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.\n"); + else { + System.out.print("FAILED!\n"); + exitStatus = -1; } - System.out.print("\n"); } private static void decompTest(TJDecompressor tjd, byte[] jpegBuf, @@ -884,10 +810,7 @@ public class TJUnitTest { int size; byte[] dstBuf; - if (yuv == YUVENCODE) - dstBuf = new byte[TJ.bufSizeYUV(w, pad, h, subsamp)]; - else - dstBuf = new byte[TJ.bufSize(w, h, subsamp)]; + dstBuf = new byte[TJ.bufSize(w, h, subsamp)]; try { tjc = new TJCompressor(); @@ -900,20 +823,16 @@ public class TJUnitTest { if (subsamp == TJ.SAMP_422 || subsamp == TJ.SAMP_420 || subsamp == TJ.SAMP_440 || subsamp == TJ.SAMP_411) flags |= TJ.FLAG_FASTUPSAMPLE; - if (i == 1) { - if (yuv == YUVDECODE) { - tjc.close(); - tjd.close(); - return; - } else - flags |= TJ.FLAG_BOTTOMUP; - } + if (i == 1) + flags |= TJ.FLAG_BOTTOMUP; size = compTest(tjc, dstBuf, w, h, pf, baseName, subsamp, 100, flags); decompTest(tjd, dstBuf, size, w, h, pf, baseName, subsamp, flags); - if (pf >= TJ.PF_RGBX && pf <= TJ.PF_XRGB && !bi) + if (pf >= TJ.PF_RGBX && pf <= TJ.PF_XRGB && !bi) { + System.out.print("\n"); decompTest(tjd, dstBuf, size, w, h, pf + (TJ.PF_RGBA - TJ.PF_RGBX), baseName, subsamp, flags); + } System.out.print("\n"); } } @@ -929,7 +848,8 @@ public class TJUnitTest { private static void bufSizeTest() throws Exception { int w, h, i, subsamp; - byte[] srcBuf, dstBuf; + byte[] srcBuf, dstBuf = null; + YUVImage dstImage = null; TJCompressor tjc = null; Random r = new Random(); @@ -943,8 +863,8 @@ public class TJUnitTest { if (h % 100 == 0) System.out.format("%04d x %04d\b\b\b\b\b\b\b\b\b\b\b", w, h); srcBuf = new byte[w * h * 4]; - if (yuv == YUVENCODE) - dstBuf = new byte[TJ.bufSizeYUV(w, pad, h, subsamp)]; + if (doYUV) + dstImage = new YUVImage(w, pad, h, subsamp); else dstBuf = new byte[TJ.bufSize(w, h, subsamp)]; for (i = 0; i < w * h * 4; i++) { @@ -953,23 +873,22 @@ public class TJUnitTest { tjc.setSourceImage(srcBuf, 0, 0, w, 0, h, TJ.PF_BGRX); tjc.setSubsamp(subsamp); tjc.setJPEGQuality(100); - tjc.setYUVPad(pad); - if (yuv == YUVENCODE) - tjc.encodeYUV(dstBuf, 0); + if (doYUV) + tjc.encodeYUV(dstImage, 0); else tjc.compress(dstBuf, 0); srcBuf = new byte[h * w * 4]; - if (yuv == YUVENCODE) - dstBuf = new byte[TJ.bufSizeYUV(h, pad, w, subsamp)]; + if (doYUV) + dstImage = new YUVImage(h, pad, w, subsamp); else dstBuf = new byte[TJ.bufSize(h, w, subsamp)]; for (i = 0; i < h * w * 4; i++) { srcBuf[i] = (byte)(r.nextInt(2) * 255); } tjc.setSourceImage(srcBuf, 0, 0, h, 0, w, TJ.PF_BGRX); - if (yuv == YUVENCODE) - tjc.encodeYUV(dstBuf, 0); + if (doYUV) + tjc.encodeYUV(dstImage, 0); else tjc.compress(dstBuf, 0); } @@ -986,10 +905,9 @@ public class TJUnitTest { public static void main(String[] argv) { try { String testName = "javatest"; - boolean doyuv = false; for (int i = 0; i < argv.length; i++) { if (argv[i].equalsIgnoreCase("-yuv")) - doyuv = true; + doYUV = true; if (argv[i].equalsIgnoreCase("-noyuvpad")) pad = 1; if (argv[i].substring(0, 1).equalsIgnoreCase("-h") || @@ -1000,10 +918,8 @@ public class TJUnitTest { testName = "javabitest"; } } - if (doyuv) { - yuv = YUVENCODE; + if (doYUV) _4byteFormats[4] = -1; - } doTest(35, 39, bi ? _3byteFormatsBI : _3byteFormats, TJ.SAMP_444, testName); doTest(39, 41, bi ? _4byteFormatsBI : _4byteFormats, TJ.SAMP_444, @@ -1032,23 +948,15 @@ public class TJUnitTest { testName); if (!bi) bufSizeTest(); - if (doyuv && !bi) { + if (doYUV && !bi) { System.out.print("\n--------------------\n\n"); - yuv = YUVDECODE; doTest(48, 48, onlyRGB, TJ.SAMP_444, "javatest_yuv0"); - doTest(35, 39, onlyRGB, TJ.SAMP_444, "javatest_yuv1"); doTest(48, 48, onlyRGB, TJ.SAMP_422, "javatest_yuv0"); - doTest(39, 41, onlyRGB, TJ.SAMP_422, "javatest_yuv1"); doTest(48, 48, onlyRGB, TJ.SAMP_420, "javatest_yuv0"); - doTest(41, 35, onlyRGB, TJ.SAMP_420, "javatest_yuv1"); doTest(48, 48, onlyRGB, TJ.SAMP_440, "javatest_yuv0"); - doTest(35, 39, onlyRGB, TJ.SAMP_440, "javatest_yuv1"); doTest(48, 48, onlyRGB, TJ.SAMP_411, "javatest_yuv0"); - doTest(39, 41, onlyRGB, TJ.SAMP_411, "javatest_yuv1"); doTest(48, 48, onlyRGB, TJ.SAMP_GRAY, "javatest_yuv0"); - doTest(41, 35, onlyRGB, TJ.SAMP_GRAY, "javatest_yuv1"); doTest(48, 48, onlyGray, TJ.SAMP_GRAY, "javatest_yuv0"); - doTest(35, 39, onlyGray, TJ.SAMP_GRAY, "javatest_yuv1"); } } catch(Exception e) { e.printStackTrace(); diff --git a/java/doc/allclasses-frame.html b/java/doc/allclasses-frame.html index b2810b5..2183aa4 100644 --- a/java/doc/allclasses-frame.html +++ b/java/doc/allclasses-frame.html @@ -33,6 +33,8 @@ All Classes
TJTransformer
+YUVImage +
diff --git a/java/doc/allclasses-noframe.html b/java/doc/allclasses-noframe.html index ddc3d63..41ed55e 100644 --- a/java/doc/allclasses-noframe.html +++ b/java/doc/allclasses-noframe.html @@ -33,6 +33,8 @@ All Classes
TJTransformer
+YUVImage +
diff --git a/java/doc/deprecated-list.html b/java/doc/deprecated-list.html index bcf6858..a0a67a6 100644 --- a/java/doc/deprecated-list.html +++ b/java/doc/deprecated-list.html @@ -149,8 +149,7 @@ function windowTitle() org.libjpegturbo.turbojpeg.TJDecompressor.decompressToYUV(byte[], int)
-          Use TJDecompressor.decompressToYUV(byte[], int, int, int, int) - instead.  +          Use TJDecompressor.decompressToYUV(YUVImage, int) instead.  org.libjpegturbo.turbojpeg.TJDecompressor.decompressToYUV(int) @@ -172,6 +171,31 @@ function windowTitle() TJCompressor.encodeYUV(int) instead.  +org.libjpegturbo.turbojpeg.TJCompressor.encodeYUV(byte[], int) +
+          Use TJCompressor.encodeYUV(YUVImage, int) instead.  + + +org.libjpegturbo.turbojpeg.TJCompressor.encodeYUV(int) +
+          Use TJCompressor.encodeYUV(int, int) instead.  + + +org.libjpegturbo.turbojpeg.TJDecompressor.getJPEGBuf() +
+          Use TJDecompressor.getSourceBuf() instead.  + + +org.libjpegturbo.turbojpeg.TJDecompressor.getJPEGSize() +
+          Use TJDecompressor.getSourceSize() instead.  + + +org.libjpegturbo.turbojpeg.TJDecompressor.setJPEGImage(byte[], int) +
+          Use TJDecompressor.setSourceImage(byte[], int) instead.  + + org.libjpegturbo.turbojpeg.TJCompressor.setSourceImage(byte[], int, int, int, int)
          Use diff --git a/java/doc/index-all.html b/java/doc/index-all.html index 9db1075..df71bde 100644 --- a/java/doc/index-all.html +++ b/java/doc/index-all.html @@ -74,7 +74,7 @@ function windowTitle() -B C D E F G H I J N O P S T
+B C D E F G H I J N O P S T Y

B

@@ -148,8 +148,9 @@ Method in interface org.libjpegturbo.turbojpeg.decompress(byte[], int, int, int, int, int, int, int) - Method in class org.libjpegturbo.turbojpeg.TJDecompressor -
Decompress the JPEG source image associated with this decompressor - instance and output a decompressed image to the given destination buffer. +
Decompress the JPEG source image or decode the YUV source image associated + with this decompressor instance and output a grayscale, RGB, or CMYK image + to the given destination buffer.
decompress(byte[], int, int, int, int, int) - Method in class org.libjpegturbo.turbojpeg.TJDecompressor
Deprecated. Use @@ -160,30 +161,32 @@ Method in class org.libjpegturbo.turbojpeg.decompress(int[], int, int, int, int, int, int, int) - Method in class org.libjpegturbo.turbojpeg.TJDecompressor -
Decompress the JPEG source image associated with this decompressor - instance and output a decompressed image to the given destination buffer. +
Decompress the JPEG source image or decode the YUV source image associated + with this decompressor instance and output a grayscale, RGB, or CMYK image + to the given destination buffer.
decompress(BufferedImage, int) - Method in class org.libjpegturbo.turbojpeg.TJDecompressor -
Decompress the JPEG source image associated with this decompressor - instance and output a decompressed image to the given - BufferedImage instance. +
Decompress the JPEG source image or decode the YUV source image associated + with this decompressor instance and output a decompressed/decoded image to + the given BufferedImage instance.
decompress(int, int, int, int) - Method in class org.libjpegturbo.turbojpeg.TJDecompressor -
Decompress the JPEG source image associated with this decompressor - instance and return a BufferedImage instance containing the - decompressed image. -
decompressToYUV(byte[], int, int, int, int) - +
Decompress the JPEG source image or decode the YUV source image associated + with this decompressor instance and return a BufferedImage + instance containing the decompressed/decoded image. +
decompressToYUV(YUVImage, int) - Method in class org.libjpegturbo.turbojpeg.TJDecompressor
Decompress the JPEG source image associated with this decompressor - instance and output a YUV planar image to the given destination buffer. + instance into a YUV planar image and store it in the given + YUVImage instance.
decompressToYUV(byte[], int) - Method in class org.libjpegturbo.turbojpeg.TJDecompressor -
Deprecated. Use TJDecompressor.decompressToYUV(byte[], int, int, int, int) - instead. +
Deprecated. Use TJDecompressor.decompressToYUV(YUVImage, int) instead.
decompressToYUV(int, int, int, int) - Method in class org.libjpegturbo.turbojpeg.TJDecompressor
Decompress the JPEG source image associated with this decompressor - instance and return a buffer containing a YUV planar image. + instance into a YUV planar image and return a YUVImage + instance containing the decompressed image.
decompressToYUV(int) - Method in class org.libjpegturbo.turbojpeg.TJDecompressor
Deprecated. Use TJDecompressor.decompressToYUV(int, int, int, int) instead. @@ -192,14 +195,22 @@ Method in class org.libjpegturbo.turbojpeg.

E

+
encodeYUV(YUVImage, int) - +Method in class org.libjpegturbo.turbojpeg.TJCompressor +
Encode the uncompressed source image associated with this compressor + instance into a YUV planar image and store it in the given + YUVImage instance.
encodeYUV(byte[], int) - Method in class org.libjpegturbo.turbojpeg.TJCompressor +
Deprecated. Use TJCompressor.encodeYUV(YUVImage, int) instead. +
encodeYUV(int, int) - +Method in class org.libjpegturbo.turbojpeg.TJCompressor
Encode the uncompressed source image associated with this compressor - instance and output a YUV planar image to the given destination buffer. + instance into a YUV planar image and return a YUVImage + instance containing the encoded image.
encodeYUV(int) - Method in class org.libjpegturbo.turbojpeg.TJCompressor -
Encode the uncompressed source image associated with this compressor - instance and return a buffer containing a YUV planar image. +
Deprecated. Use TJCompressor.encodeYUV(int, int) instead.
encodeYUV(BufferedImage, byte[], int) - Method in class org.libjpegturbo.turbojpeg.TJCompressor
Deprecated. Use @@ -262,10 +273,13 @@ Static variable in class org.libjpegturbo.turbojpeg.TJ
For the given pixel format, returns the number of bytes that the blue component is offset from the start of the pixel. +
getBuf() - +Method in class org.libjpegturbo.turbojpeg.YUVImage +
Returns the YUV image buffer
getColorspace() - Method in class org.libjpegturbo.turbojpeg.TJDecompressor -
Returns the colorspace used in the JPEG image associated with this - decompressor instance. +
Returns the colorspace used in the source image (JPEG or YUV) associated + with this decompressor instance.
getCompressedSize() - Method in class org.libjpegturbo.turbojpeg.TJCompressor
Returns the size of the image (in bytes) generated by the most recent @@ -279,15 +293,17 @@ Static method in class org.libjpegturbo.turbojpeg.getHeight() - Method in class org.libjpegturbo.turbojpeg.TJDecompressor -
Returns the height of the JPEG image associated with this decompressor - instance. +
Returns the height of the source image (JPEG or YUV) associated with this + decompressor instance. +
getHeight() - +Method in class org.libjpegturbo.turbojpeg.YUVImage +
Returns the height of the YUV image.
getJPEGBuf() - Method in class org.libjpegturbo.turbojpeg.TJDecompressor -
Returns the JPEG image buffer associated with this decompressor instance. +
Deprecated. Use TJDecompressor.getSourceBuf() instead.
getJPEGSize() - Method in class org.libjpegturbo.turbojpeg.TJDecompressor -
Returns the size of the JPEG image (in bytes) associated with this - decompressor instance. +
Deprecated. Use TJDecompressor.getSourceSize() instead.
getMCUHeight(int) - Static method in class org.libjpegturbo.turbojpeg.TJ
Returns the MCU block height for the given level of chrominance @@ -299,6 +315,9 @@ Static method in class org.libjpegturbo.turbojpeg.getNum() - Method in class org.libjpegturbo.turbojpeg.TJScalingFactor
Returns numerator +
getPad() - +Method in class org.libjpegturbo.turbojpeg.YUVImage +
Returns the line padding used in the YUV image buffer.
getPixelSize(int) - Static method in class org.libjpegturbo.turbojpeg.TJ
Returns the pixel size (in bytes) for the given pixel format. @@ -323,18 +342,35 @@ Method in class org.libjpegturbo.turbojpeg.TJ
Returns a list of fractional scaling factors that the JPEG decompressor in this implementation of TurboJPEG supports. +
getSize() - +Method in class org.libjpegturbo.turbojpeg.YUVImage +
Returns the size (in bytes) of the YUV image buffer +
getSourceBuf() - +Method in class org.libjpegturbo.turbojpeg.TJDecompressor +
Returns the source image buffer associated with this decompressor + instance. +
getSourceSize() - +Method in class org.libjpegturbo.turbojpeg.TJDecompressor +
Returns the size of the source image (in bytes) associated with this + decompressor instance.
getSubsamp() - Method in class org.libjpegturbo.turbojpeg.TJDecompressor -
Returns the level of chrominance subsampling used in the JPEG image - associated with this decompressor instance. +
Returns the level of chrominance subsampling used in the source image + (JPEG or YUV) associated with this decompressor instance. +
getSubsamp() - +Method in class org.libjpegturbo.turbojpeg.YUVImage +
Returns the level of chrominance subsampling used in the YUV image.
getTransformedSizes() - Method in class org.libjpegturbo.turbojpeg.TJTransformer -
Returns an array containing the sizes of the transformed JPEG images from - the most recent call to transform(). +
Returns an array containing the sizes of the transformed JPEG images + generated by the most recent transform operation.
getWidth() - Method in class org.libjpegturbo.turbojpeg.TJDecompressor -
Returns the width of the JPEG image associated with this decompressor - instance. +
Returns the width of the source image (JPEG or YUV) associated with this + decompressor instance. +
getWidth() - +Method in class org.libjpegturbo.turbojpeg.YUVImage +
Returns the width of the YUV image.

@@ -343,6 +379,9 @@ Method in class org.libjpegturbo.turbojpeg.handle - Variable in class org.libjpegturbo.turbojpeg.TJDecompressor
  +
handle - +Variable in class org.libjpegturbo.turbojpeg.YUVImage +
 


@@ -363,18 +402,6 @@ Variable in class org.libjpegturbo.turbojpeg.jpegBufSize - Variable in class org.libjpegturbo.turbojpeg.TJDecompressor
  -
jpegColorspace - -Variable in class org.libjpegturbo.turbojpeg.TJDecompressor -
  -
jpegHeight - -Variable in class org.libjpegturbo.turbojpeg.TJDecompressor -
  -
jpegSubsamp - -Variable in class org.libjpegturbo.turbojpeg.TJDecompressor -
  -
jpegWidth - -Variable in class org.libjpegturbo.turbojpeg.TJDecompressor -
 

@@ -513,32 +540,50 @@ Static variable in class org.libjpegturbo.turbojpeg.setJPEGImage(byte[], int) - Method in class org.libjpegturbo.turbojpeg.TJDecompressor -
Associate the JPEG image of length imageSize bytes stored in - jpegImage with this decompressor instance. +
Deprecated. Use TJDecompressor.setSourceImage(byte[], int) instead.
setJPEGQuality(int) - Method in class org.libjpegturbo.turbojpeg.TJCompressor
Set the JPEG image quality level for subsequent compress operations.
setSourceImage(byte[], int, int, int, int, int, int) - Method in class org.libjpegturbo.turbojpeg.TJCompressor -
Associate an uncompressed source image with this compressor instance. +
Associate an uncompressed RGB, grayscale, or CMYK source image with this + compressor instance.
setSourceImage(byte[], int, int, int, int) - Method in class org.libjpegturbo.turbojpeg.TJCompressor
Deprecated. Use TJCompressor.setSourceImage(byte[], int, int, int, int, int, int) instead.
setSourceImage(BufferedImage, int, int, int, int) - Method in class org.libjpegturbo.turbojpeg.TJCompressor -
Associate an uncompressed source image with this compressor instance. -
setSourceImageYUV(byte[], int, int, int) - +
Associate an uncompressed RGB or grayscale source image with this + compressor instance. +
setSourceImage(YUVImage) - Method in class org.libjpegturbo.turbojpeg.TJCompressor
Associate an uncompressed YUV planar source image with this compressor instance. +
setSourceImage(byte[], int) - +Method in class org.libjpegturbo.turbojpeg.TJDecompressor +
Associate the JPEG image of length imageSize bytes stored in + srcImage with this decompressor instance. +
setSourceImage(YUVImage) - +Method in class org.libjpegturbo.turbojpeg.TJDecompressor +
Associate the specified YUV planar source image with this decompressor + instance.
setSubsamp(int) - Method in class org.libjpegturbo.turbojpeg.TJCompressor
Set the level of chrominance subsampling for subsequent compress/encode operations. -
setYUVPad(int) - -Method in class org.libjpegturbo.turbojpeg.TJCompressor -
Set the plane padding for subsequent YUV encode operations. +
srcColorspace - +Variable in class org.libjpegturbo.turbojpeg.TJDecompressor +
  +
srcHeight - +Variable in class org.libjpegturbo.turbojpeg.TJDecompressor +
  +
srcSubsamp - +Variable in class org.libjpegturbo.turbojpeg.TJDecompressor +
  +
srcWidth - +Variable in class org.libjpegturbo.turbojpeg.TJDecompressor +
 

@@ -550,32 +595,37 @@ Constructor for class org.libjpegturbo.turbojpeg.TJCompressor - Class in org.libjpegturbo.turbojpeg
TurboJPEG compressor
TJCompressor() - Constructor for class org.libjpegturbo.turbojpeg.TJCompressor
Create a TurboJPEG compressor instance. -
TJCompressor(byte[], int, int, int, int) - -Constructor for class org.libjpegturbo.turbojpeg.TJCompressor -
Deprecated. Use - TJCompressor.TJCompressor(byte[], int, int, int, int, int, int) instead.
TJCompressor(byte[], int, int, int, int, int, int) - Constructor for class org.libjpegturbo.turbojpeg.TJCompressor
Create a TurboJPEG compressor instance and associate the uncompressed - source image stored in srcImage with the newly-created + source image stored in srcImage with the newly created instance. +
TJCompressor(byte[], int, int, int, int) - +Constructor for class org.libjpegturbo.turbojpeg.TJCompressor +
Deprecated. Use + TJCompressor.TJCompressor(byte[], int, int, int, int, int, int) instead.
TJCompressor(BufferedImage, int, int, int, int) - Constructor for class org.libjpegturbo.turbojpeg.TJCompressor
Create a TurboJPEG compressor instance and associate the uncompressed - source image stored in srcImage with the newly-created + source image stored in srcImage with the newly created instance.
TJCustomFilter - Interface in org.libjpegturbo.turbojpeg
Custom filter callback interface
TJDecompressor - Class in org.libjpegturbo.turbojpeg
TurboJPEG decompressor
TJDecompressor() - Constructor for class org.libjpegturbo.turbojpeg.TJDecompressor
Create a TurboJPEG decompresssor instance.
TJDecompressor(byte[]) - Constructor for class org.libjpegturbo.turbojpeg.TJDecompressor -
Create a TurboJPEG decompressor instance and associate the JPEG image - stored in jpegImage with the newly-created instance. +
Create a TurboJPEG decompressor instance and associate the JPEG source + image stored in jpegImage with the newly created instance.
TJDecompressor(byte[], int) - Constructor for class org.libjpegturbo.turbojpeg.TJDecompressor -
Create a TurboJPEG decompressor instance and associate the JPEG image - of length imageSize bytes stored in jpegImage - with the newly-created instance. +
Create a TurboJPEG decompressor instance and associate the JPEG source + image of length imageSize bytes stored in + jpegImage with the newly created instance. +
TJDecompressor(YUVImage) - +Constructor for class org.libjpegturbo.turbojpeg.TJDecompressor +
Create a TurboJPEG decompressor instance and associate the YUV planar + source image stored in yuvImage with the newly created + instance.
TJScalingFactor - Class in org.libjpegturbo.turbojpeg
Fractional scaling factor
TJScalingFactor(int, int) - Constructor for class org.libjpegturbo.turbojpeg.TJScalingFactor
  @@ -594,12 +644,12 @@ Constructor for class org.libjpegturbo.turbojpeg.TJTransformer(byte[]) - Constructor for class org.libjpegturbo.turbojpeg.TJTransformer
Create a TurboJPEG lossless transformer instance and associate the JPEG - image stored in jpegImage with the newly-created instance. + image stored in jpegImage with the newly created instance.
TJTransformer(byte[], int) - Constructor for class org.libjpegturbo.turbojpeg.TJTransformer
Create a TurboJPEG lossless transformer instance and associate the JPEG image of length imageSize bytes stored in - jpegImage with the newly-created instance. + jpegImage with the newly created instance.
transform(byte[][], TJTransform[], int) - Method in class org.libjpegturbo.turbojpeg.TJTransformer
Losslessly transform the JPEG image associated with this transformer @@ -612,7 +662,38 @@ Method in class org.libjpegturbo.turbojpeg.B C D E F G H I J N O P S T +

+Y

+
+
yuvBuf - +Variable in class org.libjpegturbo.turbojpeg.YUVImage +
  +
yuvHeight - +Variable in class org.libjpegturbo.turbojpeg.YUVImage +
  +
yuvImage - +Variable in class org.libjpegturbo.turbojpeg.TJDecompressor +
  +
YUVImage - Class in org.libjpegturbo.turbojpeg
This class encapsulates a YUV planar image buffer and the metadata + associated with it.
YUVImage(int, int, int, int) - +Constructor for class org.libjpegturbo.turbojpeg.YUVImage +
Create a YUVImage instance with a new image buffer. +
YUVImage(byte[], int, int, int, int) - +Constructor for class org.libjpegturbo.turbojpeg.YUVImage +
Create a YUVImage instance from an existing YUV planar image + buffer. +
yuvPad - +Variable in class org.libjpegturbo.turbojpeg.YUVImage +
  +
yuvSubsamp - +Variable in class org.libjpegturbo.turbojpeg.YUVImage +
  +
yuvWidth - +Variable in class org.libjpegturbo.turbojpeg.YUVImage +
  +
+
+B C D E F G H I J N O P S T Y diff --git a/java/doc/org/libjpegturbo/turbojpeg/TJCompressor.html b/java/doc/org/libjpegturbo/turbojpeg/TJCompressor.html index b6452f3..3c24544 100644 --- a/java/doc/org/libjpegturbo/turbojpeg/TJCompressor.html +++ b/java/doc/org/libjpegturbo/turbojpeg/TJCompressor.html @@ -128,7 +128,7 @@ TurboJPEG compressor
          Create a TurboJPEG compressor instance and associate the uncompressed - source image stored in srcImage with the newly-created + source image stored in srcImage with the newly created instance. @@ -153,7 +153,7 @@ TurboJPEG compressor
          Create a TurboJPEG compressor instance and associate the uncompressed - source image stored in srcImage with the newly-created + source image stored in srcImage with the newly created instance. @@ -246,17 +246,37 @@ TurboJPEG compressor int flags)
-          Encode the uncompressed source image associated with this compressor - instance and output a YUV planar image to the given destination buffer. +          Deprecated. Use encodeYUV(YUVImage, int) instead.  byte[] encodeYUV(int flags) +
+          Deprecated. Use encodeYUV(int, int) instead. + + + + YUVImage +encodeYUV(int pad, + int flags) +
          Encode the uncompressed source image associated with this compressor - instance and return a buffer containing a YUV planar image. + instance into a YUV planar image and return a YUVImage + instance containing the encoded image. + + + + void +encodeYUV(YUVImage dstImage, + int flags) + +
+          Encode the uncompressed source image associated with this compressor + instance into a YUV planar image and store it in the given + YUVImage instance. @@ -293,7 +313,8 @@ TurboJPEG compressor int height)
-          Associate an uncompressed source image with this compressor instance. +          Associate an uncompressed RGB or grayscale source image with this + compressor instance. @@ -320,15 +341,13 @@ TurboJPEG compressor int pixelFormat)
-          Associate an uncompressed source image with this compressor instance. +          Associate an uncompressed RGB, grayscale, or CMYK source image with this + compressor instance.  void -setSourceImageYUV(byte[] srcImage, - int width, - int pad, - int height) +setSourceImage(YUVImage srcImage)
          Associate an uncompressed YUV planar source image with this compressor @@ -343,14 +362,6 @@ TurboJPEG compressor           Set the level of chrominance subsampling for subsequent compress/encode operations. - - - void -setYUVPad(int pad) - -
-          Set the plane padding for subsequent YUV encode operations. -   @@ -389,27 +400,6 @@ public TJCompressor()
-

-TJCompressor

-
-@Deprecated
-public TJCompressor(byte[] srcImage,
-                               int width,
-                               int pitch,
-                               int height,
-                               int pixelFormat)
-             throws java.lang.Exception
-
-
Deprecated. Use - TJCompressor(byte[], int, int, int, int, int, int) instead. -

-

- -
Throws: -
java.lang.Exception
-
-
-

TJCompressor

@@ -423,12 +413,33 @@ public TJCompressor(byte[] srcImage,
              throws java.lang.Exception
Create a TurboJPEG compressor instance and associate the uncompressed - source image stored in srcImage with the newly-created + source image stored in srcImage with the newly created instance.

Parameters:
srcImage - see setSourceImage(byte[], int, int, int, int, int, int) for description
x - see setSourceImage(byte[], int, int, int, int, int, int) for description
y - see setSourceImage(byte[], int, int, int, int, int, int) for description
width - see setSourceImage(byte[], int, int, int, int, int, int) for description
pitch - see setSourceImage(byte[], int, int, int, int, int, int) for description
height - see setSourceImage(byte[], int, int, int, int, int, int) for description
pixelFormat - pixel format of the source image (one of - TJ.PF_*) + TJ.PF_*) +
Throws: +
java.lang.Exception
+
+
+ +

+TJCompressor

+
+@Deprecated
+public TJCompressor(byte[] srcImage,
+                               int width,
+                               int pitch,
+                               int height,
+                               int pixelFormat)
+             throws java.lang.Exception
+
+
Deprecated. Use + TJCompressor(byte[], int, int, int, int, int, int) instead. +

+

+
Throws:
java.lang.Exception
@@ -445,7 +456,7 @@ public TJCompressor(java.awt.image.BufferedImage srcImage, throws java.lang.Exception
Create a TurboJPEG compressor instance and associate the uncompressed - source image stored in srcImage with the newly-created + source image stored in srcImage with the newly created instance.

@@ -481,23 +492,24 @@ public void setSourceImage(byte[] srcImage, int pixelFormat) throws java.lang.Exception
-
Associate an uncompressed source image with this compressor instance. +
Associate an uncompressed RGB, grayscale, or CMYK source image with this + compressor instance.

Parameters:
srcImage - image buffer containing RGB, grayscale, or CMYK pixels to - be compressed
x - x offset (in pixels) of the region from which the JPEG image - should be compressed, relative to the start of srcImage.
y - y offset (in pixels) of the region from which the JPEG image - should be compressed, relative to the start of srcImage.
width - width (in pixels) of the region in the source image from - which the JPEG image should be compressed.
pitch - bytes per line of the source image. Normally, this should be + be compressed or encoded
x - x offset (in pixels) of the region in the source image from which + the JPEG or YUV image should be compressed/encoded
y - y offset (in pixels) of the region in the source image from which + the JPEG or YUV image should be compressed/encoded
width - width (in pixels) of the region in the source image from + which the JPEG or YUV image should be compressed/encoded
pitch - bytes per line of the source image. Normally, this should be width * TJ.pixelSize(pixelFormat) if the source image is unpadded, but you can use this parameter to, for instance, specify that the scanlines in the source image are padded to a 4-byte boundary or to - compress a JPEG image from a region of a larger source image. You can - also be clever and use this parameter to skip lines, etc. Setting this - parameter to 0 is the equivalent of setting it to width * - TJ.pixelSize(pixelFormat).
height - height (in pixels) of the region in the source image from - which the JPEG image should be compressed.
pixelFormat - pixel format of the source image (one of - TJ.PF_*) + compress/encode a JPEG or YUV image from a region of a larger source + image. You can also be clever and use this parameter to skip lines, etc. + Setting this parameter to 0 is the equivalent of setting it to + width * TJ.pixelSize(pixelFormat).
height - height (in pixels) of the region in the source image from + which the JPEG or YUV image should be compressed/encoded
pixelFormat - pixel format of the source image (one of + TJ.PF_*)
Throws:
java.lang.Exception
@@ -536,47 +548,35 @@ public void setSourceImage(java.awt.image.BufferedImage srcImage, int height) throws java.lang.Exception
-
Associate an uncompressed source image with this compressor instance. +
Associate an uncompressed RGB or grayscale source image with this + compressor instance.

Parameters:
srcImage - a BufferedImage instance containing RGB or - grayscale pixels to be compressed
x - x offset (in pixels) of the region in the source image from which - the JPEG image should be compressed
y - y offset (in pixels) of the region in the source image from which - the JPEG image should be compressed
width - width (in pixels) of the region in the source image from - which the JPEG image should be compressed (0 = compress the whole image)
height - height (in pixels) of the region in the source image from - which the JPEG image should be compressed (0 = compress the whole image) + grayscale pixels to be compressed or encoded
x - x offset (in pixels) of the region in the source image from which + the JPEG or YUV image should be compressed/encoded
y - y offset (in pixels) of the region in the source image from which + the JPEG or YUV image should be compressed/encoded
width - width (in pixels) of the region in the source image from + which the JPEG or YUV image should be compressed/encoded (0 = use the + width of the source image)
height - height (in pixels) of the region in the source image from + which the JPEG or YUV image should be compressed/encoded (0 = use the + height of the source image)
Throws:
java.lang.Exception

-

-setSourceImageYUV

+

+setSourceImage

-public void setSourceImageYUV(byte[] srcImage,
-                              int width,
-                              int pad,
-                              int height)
-                       throws java.lang.Exception
+public void setSourceImage(YUVImage srcImage) + throws java.lang.Exception
Associate an uncompressed YUV planar source image with this compressor instance.

-
Parameters:
srcImage - image buffer containing a YUV planar image to be - compressed. The Y, U (Cb), and V (Cr) image planes should be stored - sequentially in the buffer, and the size of each plane is determined by - the specified width, height, and padding, as well as the level of - chrominance subsampling (specified using setSubsamp(int).) If the - chrominance components are subsampled along the horizontal dimension, then - the width of the luminance plane should be padded to the nearest multiple - of 2 (same goes for the height of the luminance plane, if the chrominance - components are subsampled along the vertical dimension.) This is - irrespective of any additional padding specified in the pad - parameter.
width - width (in pixels) of the source image
pad - the line padding used in the source image. For instance, if - each line in each plane of the YUV image is padded to the nearest multiple - of 4 bytes, then pad should be set to 4.
height - height (in pixels) of the source image +
Parameters:
srcImage - YUV planar image to be compressed
Throws:
java.lang.Exception
@@ -598,13 +598,17 @@ public void setSubsamp(int newSubsamp) sensitive to small changes in brightness than to small changes in color.) This is called "chrominance subsampling".

- NOTE: When compressing a YUV planar image into a JPEG image, this method - also specifies the level of chrominance subsampling used in the source - image. + NOTE: This method has no effect when compressing a JPEG image from a YUV + planar source. In that case, the level of chrominance subsampling in + the JPEG image is determined by the source. Further, this method has no + effect when encoding to a pre-allocated YUVImage instance. In + that case, the level of chrominance subsampling is determined by the + destination.

-
Parameters:
newSubsamp - the new level of chrominance subsampling (one of - TJ.SAMP_*) +
Parameters:
newSubsamp - the level of chrominance subsampling to use in + subsequent compress/encode oeprations (one of + TJ.SAMP_*)
Throws:
java.lang.Exception
@@ -641,7 +645,9 @@ public void compress(byte[] dstBuf,
Parameters:
dstBuf - buffer that will receive the JPEG image. Use TJ.bufSize(int, int, int) to determine the maximum size for this buffer based on - the image width, height, and level of chrominance subsampling.
flags - the bitwise OR of one or more of TJ.FLAG_* + the source image's width and height and the desired level of chrominance + subsampling.
flags - the bitwise OR of one or more of + TJ.FLAG_*
Throws:
java.lang.Exception
@@ -658,7 +664,8 @@ public byte[] compress(int flags) instance and return a buffer containing a JPEG image.

-
Parameters:
flags - the bitwise OR of one or more of TJ.FLAG_* +
Parameters:
flags - the bitwise OR of one or more of + TJ.FLAG_*
Returns:
a buffer containing a JPEG image. The length of this buffer will not be equal to the size of the JPEG image. Use getCompressedSize() to obtain the size of the JPEG image.
Throws: @@ -708,19 +715,24 @@ compress

-

-setYUVPad

+

+encodeYUV

-public void setYUVPad(int pad)
+public void encodeYUV(YUVImage dstImage,
+                      int flags)
                throws java.lang.Exception
-
Set the plane padding for subsequent YUV encode operations. +
Encode the uncompressed source image associated with this compressor + instance into a YUV planar image and store it in the given + YUVImage instance. This method uses the accelerated color + conversion routines in TurboJPEG's underlying codec but does not execute + any of the other steps in the JPEG compression process. Encoding + CMYK source images to YUV is not supported.

-
Parameters:
pad - the width of each line in each plane of the YUV image will be - padded to the nearest multiple of this number of bytes (must be a - power of 2.) The default padding is 4 bytes, which generates - images suitable for direct video display. +
Parameters:
dstImage - YUVImage instance that will receive the YUV planar + image
flags - the bitwise OR of one or more of + TJ.FLAG_*
Throws:
java.lang.Exception
@@ -730,31 +742,41 @@ public void setYUVPad(int pad)

encodeYUV

-public void encodeYUV(byte[] dstBuf,
-                      int flags)
+@Deprecated
+public void encodeYUV(byte[] dstBuf,
+                                 int flags)
                throws java.lang.Exception
+
Deprecated. Use encodeYUV(YUVImage, int) instead. +

+

+ +
Throws: +
java.lang.Exception
+
+
+
+ +

+encodeYUV

+
+public YUVImage encodeYUV(int pad,
+                          int flags)
+                   throws java.lang.Exception
+
Encode the uncompressed source image associated with this compressor - instance and output a YUV planar image to the given destination buffer. - This method uses the accelerated color conversion routines in TurboJPEG's - underlying codec but does not execute any of the other steps in the JPEG - compression process. The Y, U (Cb), and V (Cr) image planes are stored - sequentially into the destination buffer, and the size of each plane is - determined by the width and height of the source image, as well as the - specified padding and level of chrominance subsampling. If the - chrominance components are subsampled along the horizontal dimension, then - the width of the luminance plane is padded to the nearest multiple of 2 in - the output image (same goes for the height of the luminance plane, if the - chrominance components are subsampled along the vertical dimension.) -

- NOTE: Technically, the JPEG format uses the YCbCr colorspace, but per the - convention of the digital video community, the TurboJPEG API uses "YUV" to - refer to an image format consisting of Y, Cb, and Cr image planes. + instance into a YUV planar image and return a YUVImage + instance containing the encoded image. This method uses the accelerated + color conversion routines in TurboJPEG's underlying codec but does not + execute any of the other steps in the JPEG compression process. Encoding + CMYK source images to YUV is not supported.

-
Parameters:
dstBuf - buffer that will receive the YUV planar image. Use - TJ.bufSizeYUV(int, int, int, int) to determine the appropriate size for this buffer - based on the image width, height, and level of chrominance subsampling.
flags - the bitwise OR of one or more of TJ.FLAG_* +
Parameters:
pad - the width of each line in each plane of the YUV image will be + padded to the nearest multiple of this number of bytes (must be a power of + 2.)
flags - the bitwise OR of one or more of + TJ.FLAG_* +
Returns:
a YUV planar image
Throws:
java.lang.Exception
@@ -764,16 +786,14 @@ public void encodeYUV(byte[] dstBuf,

encodeYUV

-public byte[] encodeYUV(int flags)
+@Deprecated
+public byte[] encodeYUV(int flags)
                  throws java.lang.Exception
-
Encode the uncompressed source image associated with this compressor - instance and return a buffer containing a YUV planar image. See - encodeYUV(byte[], int) for more detail. +
Deprecated. Use encodeYUV(int, int) instead.

-
Parameters:
flags - the bitwise OR of one or more of TJ.FLAG_* -
Returns:
a buffer containing a YUV planar image +
Throws:
java.lang.Exception
diff --git a/java/doc/org/libjpegturbo/turbojpeg/TJDecompressor.html b/java/doc/org/libjpegturbo/turbojpeg/TJDecompressor.html index 2dc3cc6..01007b3 100644 --- a/java/doc/org/libjpegturbo/turbojpeg/TJDecompressor.html +++ b/java/doc/org/libjpegturbo/turbojpeg/TJDecompressor.html @@ -142,7 +142,7 @@ TurboJPEG decompressor
- @@ -150,7 +150,7 @@ TurboJPEG decompressor - @@ -158,7 +158,7 @@ TurboJPEG decompressor - @@ -166,7 +166,15 @@ TurboJPEG decompressor - + + + + @@ -191,17 +199,25 @@ TurboJPEG decompressor +          Create a TurboJPEG decompressor instance and associate the JPEG source + image stored in jpegImage with the newly created instance. +          Create a TurboJPEG decompressor instance and associate the JPEG source + image of length imageSize bytes stored in + jpegImage with the newly created instance. + + +
protected  intjpegColorspace +srcColorspace
           
protected  intjpegHeight +srcHeight
           
protected  intjpegSubsamp +srcSubsamp
           
protected  intjpegWidth +srcWidth + +
+           
+protected  YUVImageyuvImage
           
TJDecompressor(byte[] jpegImage)
-          Create a TurboJPEG decompressor instance and associate the JPEG image - stored in jpegImage with the newly-created instance.
TJDecompressor(byte[] jpegImage, int imageSize)
-          Create a TurboJPEG decompressor instance and associate the JPEG image - of length imageSize bytes stored in jpegImage - with the newly-created instance.
TJDecompressor(YUVImage yuvImage) + +
+          Create a TurboJPEG decompressor instance and associate the YUV planar + source image stored in yuvImage with the newly created + instance.
  @@ -228,9 +244,9 @@ TurboJPEG decompressor int flags)
-          Decompress the JPEG source image associated with this decompressor - instance and output a decompressed image to the given - BufferedImage instance. +          Decompress the JPEG source image or decode the YUV source image associated + with this decompressor instance and output a decompressed/decoded image to + the given BufferedImage instance. @@ -259,8 +275,9 @@ TurboJPEG decompressor int flags)
-          Decompress the JPEG source image associated with this decompressor - instance and output a decompressed image to the given destination buffer. +          Decompress the JPEG source image or decode the YUV source image associated + with this decompressor instance and output a grayscale, RGB, or CMYK image + to the given destination buffer. @@ -275,8 +292,9 @@ TurboJPEG decompressor int flags)
-          Decompress the JPEG source image associated with this decompressor - instance and output a decompressed image to the given destination buffer. +          Decompress the JPEG source image or decode the YUV source image associated + with this decompressor instance and output a grayscale, RGB, or CMYK image + to the given destination buffer. @@ -287,9 +305,9 @@ TurboJPEG decompressor int flags)
-          Decompress the JPEG source image associated with this decompressor - instance and return a BufferedImage instance containing the - decompressed image. +          Decompress the JPEG source image or decode the YUV source image associated + with this decompressor instance and return a BufferedImage + instance containing the decompressed/decoded image. @@ -311,21 +329,7 @@ TurboJPEG decompressor int flags)
-          Deprecated. Use decompressToYUV(byte[], int, int, int, int) - instead. - - - - void -decompressToYUV(byte[] dstBuf, - int desiredWidth, - int pad, - int desiredHeight, - int flags) - -
-          Decompress the JPEG source image associated with this decompressor - instance and output a YUV planar image to the given destination buffer. +          Deprecated. Use decompressToYUV(YUVImage, int) instead. @@ -337,7 +341,7 @@ TurboJPEG decompressor - byte[] + YUVImage decompressToYUV(int desiredWidth, int pad, int desiredHeight, @@ -345,7 +349,19 @@ TurboJPEG decompressor
          Decompress the JPEG source image associated with this decompressor - instance and return a buffer containing a YUV planar image. + instance into a YUV planar image and return a YUVImage + instance containing the decompressed image. + + + + void +decompressToYUV(YUVImage dstImage, + int flags) + +
+          Decompress the JPEG source image associated with this decompressor + instance into a YUV planar image and store it in the given + YUVImage instance. @@ -361,8 +377,8 @@ TurboJPEG decompressor getColorspace()
-          Returns the colorspace used in the JPEG image associated with this - decompressor instance. +          Returns the colorspace used in the source image (JPEG or YUV) associated + with this decompressor instance. @@ -370,8 +386,8 @@ TurboJPEG decompressor getHeight()
-          Returns the height of the JPEG image associated with this decompressor - instance. +          Returns the height of the source image (JPEG or YUV) associated with this + decompressor instance. @@ -379,7 +395,7 @@ TurboJPEG decompressor getJPEGBuf()
-          Returns the JPEG image buffer associated with this decompressor instance. +          Deprecated. Use getSourceBuf() instead. @@ -387,8 +403,7 @@ TurboJPEG decompressor getJPEGSize()
-          Returns the size of the JPEG image (in bytes) associated with this - decompressor instance. +          Deprecated. Use getSourceSize() instead. @@ -414,12 +429,30 @@ TurboJPEG decompressor + byte[] +getSourceBuf() + +
+          Returns the source image buffer associated with this decompressor + instance. + + + + int +getSourceSize() + +
+          Returns the size of the source image (in bytes) associated with this + decompressor instance. + + +  int getSubsamp()
-          Returns the level of chrominance subsampling used in the JPEG image - associated with this decompressor instance. +          Returns the level of chrominance subsampling used in the source image + (JPEG or YUV) associated with this decompressor instance. @@ -427,8 +460,8 @@ TurboJPEG decompressor getWidth()
-          Returns the width of the JPEG image associated with this decompressor - instance. +          Returns the width of the source image (JPEG or YUV) associated with this + decompressor instance. @@ -436,9 +469,27 @@ TurboJPEG decompressor setJPEGImage(byte[] jpegImage, int imageSize) +
+          Deprecated. Use setSourceImage(byte[], int) instead. + + + + void +setSourceImage(byte[] srcImage, + int imageSize) +
          Associate the JPEG image of length imageSize bytes stored in - jpegImage with this decompressor instance. + srcImage with this decompressor instance. + + + + void +setSourceImage(YUVImage srcImage) + +
+          Associate the specified YUV planar source image with this decompressor + instance.   @@ -493,40 +544,50 @@ protected int jpegBufSize
-

-jpegWidth

+

+yuvImage

+
+protected YUVImage yuvImage
+
+
+
+
+
+ +

+srcWidth

-protected int jpegWidth
+protected int srcWidth

-

-jpegHeight

+

+srcHeight

-protected int jpegHeight
+protected int srcHeight

-

-jpegSubsamp

+

+srcSubsamp

-protected int jpegSubsamp
+protected int srcSubsamp

-

-jpegColorspace

+

+srcColorspace

-protected int jpegColorspace
+protected int srcColorspace
@@ -563,8 +624,8 @@ TJDecompressor

public TJDecompressor(byte[] jpegImage) throws java.lang.Exception
-
Create a TurboJPEG decompressor instance and associate the JPEG image - stored in jpegImage with the newly-created instance. +
Create a TurboJPEG decompressor instance and associate the JPEG source + image stored in jpegImage with the newly created instance.

Parameters:
jpegImage - JPEG image buffer (size of the JPEG image is assumed to @@ -581,15 +642,33 @@ public TJDecompressor(byte[] jpegImage, int imageSize) throws java.lang.Exception
-
Create a TurboJPEG decompressor instance and associate the JPEG image - of length imageSize bytes stored in jpegImage - with the newly-created instance. +
Create a TurboJPEG decompressor instance and associate the JPEG source + image of length imageSize bytes stored in + jpegImage with the newly created instance.

Parameters:
jpegImage - JPEG image buffer
imageSize - size of the JPEG image (in bytes)
Throws:
java.lang.Exception
+
+ +

+TJDecompressor

+
+public TJDecompressor(YUVImage yuvImage)
+               throws java.lang.Exception
+
+
Create a TurboJPEG decompressor instance and associate the YUV planar + source image stored in yuvImage with the newly created + instance. +

+

+
Parameters:
yuvImage - YUVImage instance containing a YUV planar + image to be decoded +
Throws: +
java.lang.Exception
+
@@ -601,19 +680,56 @@ public TJDecompressor(byte[] jpegImage, +

+setSourceImage

+
+public void setSourceImage(byte[] srcImage,
+                           int imageSize)
+                    throws java.lang.Exception
+
+
Associate the JPEG image of length imageSize bytes stored in + srcImage with this decompressor instance. This image will + be used as the source image for subsequent decompress operations. +

+

+
Parameters:
srcImage - JPEG image buffer
imageSize - size of the JPEG image (in bytes) +
Throws: +
java.lang.Exception
+
+
+
+

setJPEGImage

-public void setJPEGImage(byte[] jpegImage,
-                         int imageSize)
+@Deprecated
+public void setJPEGImage(byte[] jpegImage,
+                                    int imageSize)
                   throws java.lang.Exception
-
Associate the JPEG image of length imageSize bytes stored in - jpegImage with this decompressor instance. This image will - be used as the source image for subsequent decompress operations. +
Deprecated. Use setSourceImage(byte[], int) instead.

-
Parameters:
jpegImage - JPEG image buffer
imageSize - size of the JPEG image (in bytes) + +
Throws: +
java.lang.Exception
+
+
+
+ +

+setSourceImage

+
+public void setSourceImage(YUVImage srcImage)
+                    throws java.lang.Exception
+
+
Associate the specified YUV planar source image with this decompressor + instance. Subsequent decompress operations will decode this image into an + RGB or grayscale destination image. +

+

+
Parameters:
srcImage - YUVImage instance containing a YUV planar image to + be decoded
Throws:
java.lang.Exception
@@ -626,13 +742,13 @@ getWidth

public int getWidth() throws java.lang.Exception
-
Returns the width of the JPEG image associated with this decompressor - instance. +
Returns the width of the source image (JPEG or YUV) associated with this + decompressor instance.

-
Returns:
the width of the JPEG image associated with this decompressor - instance +
Returns:
the width of the source image (JPEG or YUV) associated with this + decompressor instance
Throws:
java.lang.Exception
@@ -645,13 +761,13 @@ getHeight

public int getHeight() throws java.lang.Exception
-
Returns the height of the JPEG image associated with this decompressor - instance. +
Returns the height of the source image (JPEG or YUV) associated with this + decompressor instance.

-
Returns:
the height of the JPEG image associated with this decompressor - instance +
Returns:
the height of the source image (JPEG or YUV) associated with this + decompressor instance
Throws:
java.lang.Exception
@@ -664,13 +780,14 @@ getSubsamp public int getSubsamp() throws java.lang.Exception
-
Returns the level of chrominance subsampling used in the JPEG image - associated with this decompressor instance. See TJ.SAMP_*. +
Returns the level of chrominance subsampling used in the source image + (JPEG or YUV) associated with this decompressor instance. See + TJ.SAMP_*.

-
Returns:
the level of chrominance subsampling used in the JPEG image - associated with this decompressor instance +
Returns:
the level of chrominance subsampling used in the source image + (JPEG or YUV) associated with this decompressor instance
Throws:
java.lang.Exception
@@ -683,13 +800,32 @@ getColorspace public int getColorspace() throws java.lang.Exception
-
Returns the colorspace used in the JPEG image associated with this - decompressor instance. See TJ.CS_*. +
Returns the colorspace used in the source image (JPEG or YUV) associated + with this decompressor instance. See TJ.CS_*. If the + source image is YUV, then this always returns TJ.CS_YCbCr.

-
Returns:
the colorspace used in the JPEG image associated with this - decompressor instance +
Returns:
the colorspace used in the source image (JPEG or YUV) associated + with this decompressor instance +
Throws: +
java.lang.Exception
+
+
+
+ +

+getSourceBuf

+
+public byte[] getSourceBuf()
+                    throws java.lang.Exception
+
+
Returns the source image buffer associated with this decompressor + instance. +

+

+ +
Returns:
the source image buffer associated with this decompressor instance
Throws:
java.lang.Exception
@@ -699,14 +835,33 @@ public int getColorspace()

getJPEGBuf

-public byte[] getJPEGBuf()
+@Deprecated
+public byte[] getJPEGBuf()
                   throws java.lang.Exception
-
Returns the JPEG image buffer associated with this decompressor instance. +
Deprecated. Use getSourceBuf() instead.

-
Returns:
the JPEG image buffer associated with this decompressor instance +
Throws: +
java.lang.Exception
+
+
+
+ +

+getSourceSize

+
+public int getSourceSize()
+                  throws java.lang.Exception
+
+
Returns the size of the source image (in bytes) associated with this + decompressor instance. +

+

+ +
Returns:
the size of the source image (in bytes) associated with this + decompressor instance
Throws:
java.lang.Exception
@@ -716,16 +871,14 @@ public byte[] getJPEGBuf()

getJPEGSize

-public int getJPEGSize()
+@Deprecated
+public int getJPEGSize()
                 throws java.lang.Exception
-
Returns the size of the JPEG image (in bytes) associated with this - decompressor instance. +
Deprecated. Use getSourceSize() instead.

-
Returns:
the size of the JPEG image (in bytes) associated with this - decompressor instance
Throws:
java.lang.Exception
@@ -801,43 +954,54 @@ public void decompress(byte[] dstBuf, int flags) throws java.lang.Exception
-
Decompress the JPEG source image associated with this decompressor - instance and output a decompressed image to the given destination buffer. +
Decompress the JPEG source image or decode the YUV source image associated + with this decompressor instance and output a grayscale, RGB, or CMYK image + to the given destination buffer.

-
Parameters:
dstBuf - buffer that will receive the decompressed image. This - buffer should normally be pitch * scaledHeight bytes in size, - where scaledHeight can be determined by calling +
Parameters:
dstBuf - buffer that will receive the decompressed/decoded image. + If the source image is a JPEG image, then this buffer should normally be + pitch * scaledHeight bytes in size, where + scaledHeight can be determined by calling scalingFactor.getScaled(jpegHeight) - with one of the scaling factors returned from TJ.getScalingFactors() or by calling getScaledHeight(int, int). However, - the buffer may also be larger than the dimensions of the JPEG image, in - which case the x, y, and pitch - parameters can be used to specify the region into which the JPEG image - should be decompressed.
x - x offset (in pixels) of the region into which the JPEG image - should be decompressed, relative to the start of dstBuf.
y - y offset (in pixels) of the region into which the JPEG image - should be decompressed, relative to the start of dstBuf.
desiredWidth - desired width (in pixels) of the decompressed image - (or image region.) If the desired image dimensions are different than the - dimensions of the JPEG image being decompressed, then TurboJPEG will use - scaling in the JPEG decompressor to generate the largest possible image - that will fit within the desired dimensions. Setting this to 0 is the - same as setting it to the width of the JPEG image (in other words, the - width will not be considered when determining the scaled image size.)
pitch - bytes per line of the destination image. Normally, this + with one of the scaling factors returned from TJ.getScalingFactors() or by calling getScaledHeight(int, int). If the + source image is a YUV image, then this buffer should normally be + pitch * height bytes in size, where height is + the height of the YUV image. However, the buffer may also be larger than + the dimensions of the source image, in which case the x, + y, and pitch parameters can be used to specify + the region into which the source image should be decompressed/decoded.
x - x offset (in pixels) of the region in the destination image into + which the source image should be decompressed/decoded
y - y offset (in pixels) of the region in the destination image into + which the source image should be decompressed/decoded
desiredWidth - If the source image is a JPEG image, then this + specifies the desired width (in pixels) of the decompressed image (or + image region.) If the desired destination image dimensions are different + than the source image dimensions, then TurboJPEG will use scaling in the + JPEG decompressor to generate the largest possible image that will fit + within the desired dimensions. Setting this to 0 is the same as setting + it to the width of the JPEG image (in other words, the width will not be + considered when determining the scaled image size.) This parameter is + ignored if the source image is a YUV image.
pitch - bytes per line of the destination image. Normally, this should be set to scaledWidth * TJ.pixelSize(pixelFormat) if - the decompressed image is unpadded, but you can use this to, for instance, - pad each line of the decompressed image to a 4-byte boundary or to - decompress the JPEG image into a region of a larger image. NOTE: - scaledWidth can be determined by calling + the destination image is unpadded, but you can use this to, for instance, + pad each line of the destination image to a 4-byte boundary or to + decompress/decode the source image into a region of a larger image. NOTE: + if the source image is a JPEG image, then scaledWidth can be + determined by calling scalingFactor.getScaled(jpegWidth) - or by calling getScaledWidth(int, int). Setting this parameter to - 0 is the equivalent of setting it to scaledWidth * - TJ.pixelSize(pixelFormat).
desiredHeight - desired height (in pixels) of the decompressed image - (or image region.) If the desired image dimensions are different than the - dimensions of the JPEG image being decompressed, then TurboJPEG will use - scaling in the JPEG decompressor to generate the largest possible image - that will fit within the desired dimensions. Setting this to 0 is the - same as setting it to the height of the JPEG image (in other words, the - height will not be considered when determining the scaled image size.)
pixelFormat - pixel format of the decompressed image (one of - TJ.PF_*)
flags - the bitwise OR of one or more of TJ.FLAG_* + or by calling getScaledWidth(int, int). If the source image is a + YUV image, then scaledWidth is the width of the YUV image. + Setting this parameter to 0 is the equivalent of setting it to + scaledWidth * TJ.pixelSize(pixelFormat).
desiredHeight - If the source image is a JPEG image, then this + specifies the desired height (in pixels) of the decompressed image (or + image region.) If the desired destination image dimensions are different + than the source image dimensions, then TurboJPEG will use scaling in the + JPEG decompressor to generate the largest possible image that will fit + within the desired dimensions. Setting this to 0 is the same as setting + it to the height of the JPEG image (in other words, the height will not be + considered when determining the scaled image size.) This parameter is + ignored if the source image is a YUV image.
pixelFormat - pixel format of the decompressed/decoded image (one of + TJ.PF_*)
flags - the bitwise OR of one or more of + TJ.FLAG_*
Throws:
java.lang.Exception
@@ -888,7 +1052,8 @@ public byte[] decompress(int desiredWidth, for description
desiredHeight - see decompress(byte[], int, int, int, int, int, int, int) for description
pixelFormat - pixel format of the decompressed image (one of - TJ.PF_*)
flags - the bitwise OR of one or more of TJ.FLAG_* + TJ.PF_*)
flags - the bitwise OR of one or more of + TJ.FLAG_*
Returns:
a buffer containing the decompressed image
Throws:
java.lang.Exception
@@ -896,48 +1061,28 @@ public byte[] decompress(int desiredWidth,

-

+

decompressToYUV

-public void decompressToYUV(byte[] dstBuf,
-                            int desiredWidth,
-                            int pad,
-                            int desiredHeight,
+public void decompressToYUV(YUVImage dstImage,
                             int flags)
                      throws java.lang.Exception
Decompress the JPEG source image associated with this decompressor - instance and output a YUV planar image to the given destination buffer. - This method performs JPEG decompression but leaves out the color - conversion step, so a planar YUV image is generated instead of an RGB - image. The padding of the planes in this image is the same as in the - images generated by TJCompressor.encodeYUV(byte[], int). Note - that, if the width or height of the image is not an even multiple of the - MCU block size (see TJ.getMCUWidth(int) and TJ.getMCUHeight(int)), - then an intermediate buffer copy will be performed within TurboJPEG. -

- NOTE: Technically, the JPEG format uses the YCbCr colorspace, but per the - convention of the digital video community, the TurboJPEG API uses "YUV" to - refer to an image format consisting of Y, Cb, and Cr image planes. + instance into a YUV planar image and store it in the given + YUVImage instance. This method performs JPEG decompression + but leaves out the color conversion step, so a planar YUV image is + generated instead of an RGB or grayscale image. This method cannot be + used to decompress JPEG source images with the CMYK or YCCK colorspace.

-
Parameters:
dstBuf - buffer that will receive the YUV planar image. Use - TJ.bufSizeYUV(int, int, int, int) to determine the appropriate size for this buffer - based on the image width, height, and level of chrominance subsampling.
desiredWidth - desired width (in pixels) of the YUV image. If the - desired image dimensions are different than the dimensions of the JPEG - image being decompressed, then TurboJPEG will use scaling in the JPEG - decompressor to generate the largest possible image that will fit within - the desired dimensions. Setting this to 0 is the same as setting it to - the width of the JPEG image (in other words, the width will not be - considered when determining the scaled image size.)
pad - the width of each line in each plane of the YUV image will be - padded to the nearest multiple of this number of bytes (must be a power of - 2.)
desiredHeight - desired height (in pixels) of the YUV image. If the - desired image dimensions are different than the dimensions of the JPEG - image being decompressed, then TurboJPEG will use scaling in the JPEG - decompressor to generate the largest possible image that will fit within - the desired dimensions. Setting this to 0 is the same as setting it to - the height of the JPEG image (in other words, the height will not be - considered when determining the scaled image size.)
flags - the bitwise OR of one or more of TJ.FLAG_* +
Parameters:
dstImage - YUVImage instance that will receive the YUV planar + image. The level of subsampling specified in this YUVImage + instance must match that of the JPEG image, and the width and height + specified in the YUVImage instance must match one of the + scaled image sizes that TurboJPEG is capable of generating from the JPEG + source image.
flags - the bitwise OR of one or more of + TJ.FLAG_*
Throws:
java.lang.Exception
@@ -952,8 +1097,7 @@ decompressToYUV int flags) throws java.lang.Exception
-
Deprecated. Use decompressToYUV(byte[], int, int, int, int) - instead. +
Deprecated. Use decompressToYUV(YUVImage, int) instead.

@@ -966,20 +1110,38 @@ decompressToYUV

decompressToYUV

-public byte[] decompressToYUV(int desiredWidth,
-                              int pad,
-                              int desiredHeight,
-                              int flags)
-                       throws java.lang.Exception
+public YUVImage decompressToYUV(int desiredWidth, + int pad, + int desiredHeight, + int flags) + throws java.lang.Exception
Decompress the JPEG source image associated with this decompressor - instance and return a buffer containing a YUV planar image. See decompressToYUV(byte[], int, int, int, int) for more detail. + instance into a YUV planar image and return a YUVImage + instance containing the decompressed image. This method performs JPEG + decompression but leaves out the color conversion step, so a planar YUV + image is generated instead of an RGB or grayscale image. This method + cannot be used to decompress JPEG source images with the CMYK or YCCK + colorspace.

-
Parameters:
desiredWidth - see - decompressToYUV(byte[], int, int, int, int) for description
pad - see decompressToYUV(byte[], int, int, int, int) for - description
desiredHeight - see decompressToYUV(byte[], int, int, int, int) for description
flags - the bitwise OR of one or more of TJ.FLAG_* -
Returns:
a buffer containing a YUV planar image +
Parameters:
desiredWidth - desired width (in pixels) of the YUV image. If the + desired image dimensions are different than the dimensions of the JPEG + image being decompressed, then TurboJPEG will use scaling in the JPEG + decompressor to generate the largest possible image that will fit within + the desired dimensions. Setting this to 0 is the same as setting it to + the width of the JPEG image (in other words, the width will not be + considered when determining the scaled image size.)
pad - the width of each line in each plane of the YUV image will be + padded to the nearest multiple of this number of bytes (must be a power of + 2.)
desiredHeight - desired height (in pixels) of the YUV image. If the + desired image dimensions are different than the dimensions of the JPEG + image being decompressed, then TurboJPEG will use scaling in the JPEG + decompressor to generate the largest possible image that will fit within + the desired dimensions. Setting this to 0 is the same as setting it to + the height of the JPEG image (in other words, the height will not be + considered when determining the scaled image size.)
flags - the bitwise OR of one or more of + TJ.FLAG_* +
Returns:
a YUV planar image
Throws:
java.lang.Exception
@@ -1016,40 +1178,52 @@ public void decompress(int[] dstBuf, int flags) throws java.lang.Exception
-
Decompress the JPEG source image associated with this decompressor - instance and output a decompressed image to the given destination buffer. +
Decompress the JPEG source image or decode the YUV source image associated + with this decompressor instance and output a grayscale, RGB, or CMYK image + to the given destination buffer.

-
Parameters:
dstBuf - buffer that will receive the decompressed image. This - buffer should normally be stride * scaledHeight pixels in - size, where scaledHeight can be determined by calling +
Parameters:
dstBuf - buffer that will receive the decompressed/decoded image. + If the source image is a JPEG image, then this buffer should normally be + stride * scaledHeight pixels in size, where + scaledHeight can be determined by calling scalingFactor.getScaled(jpegHeight) - with one of the scaling factors returned from TJ.getScalingFactors() or by calling getScaledHeight(int, int). However, - the buffer may also be larger than the dimensions of the JPEG image, in - which case the x, y, and stride - parameters can be used to specify the region into which the JPEG image - should be decompressed.
x - x offset (in pixels) of the region into which the JPEG image - should be decompressed, relative to the start of dstBuf.
y - y offset (in pixels) of the region into which the JPEG image - should be decompressed, relative to the start of dstBuf.
desiredWidth - desired width (in pixels) of the decompressed image - (or image region.) If the desired image dimensions are different than the - dimensions of the JPEG image being decompressed, then TurboJPEG will use - scaling in the JPEG decompressor to generate the largest possible image - that will fit within the desired dimensions. Setting this to 0 is the - same as setting it to the width of the JPEG image (in other words, the - width will not be considered when determining the scaled image size.)
stride - pixels per line of the destination image. Normally, this + with one of the scaling factors returned from TJ.getScalingFactors() or by calling getScaledHeight(int, int). If the + source image is a YUV image, then this buffer should normally be + stride * height pixels in size, where height is + the height of the YUV image. However, the buffer may also be larger than + the dimensions of the JPEG image, in which case the x, + y, and stride parameters can be used to specify + the region into which the source image should be decompressed.
x - x offset (in pixels) of the region in the destination image into + which the source image should be decompressed/decoded
y - y offset (in pixels) of the region in the destination image into + which the source image should be decompressed/decoded
desiredWidth - If the source image is a JPEG image, then this + specifies the desired width (in pixels) of the decompressed image (or + image region.) If the desired destination image dimensions are different + than the source image dimensions, then TurboJPEG will use scaling in the + JPEG decompressor to generate the largest possible image that will fit + within the desired dimensions. Setting this to 0 is the same as setting + it to the width of the JPEG image (in other words, the width will not be + considered when determining the scaled image size.) This parameter is + ignored if the source image is a YUV image.
stride - pixels per line of the destination image. Normally, this should be set to scaledWidth, but you can use this to, for instance, decompress the JPEG image into a region of a larger image. - NOTE: scaledWidth can be determined by calling + NOTE: if the source image is a JPEG image, then scaledWidth + can be determined by calling scalingFactor.getScaled(jpegWidth) - or by calling getScaledWidth(int, int). Setting this parameter to - 0 is the equivalent of setting it to scaledWidth.
desiredHeight - desired height (in pixels) of the decompressed image - (or image region.) If the desired image dimensions are different than the - dimensions of the JPEG image being decompressed, then TurboJPEG will use - scaling in the JPEG decompressor to generate the largest possible image - that will fit within the desired dimensions. Setting this to 0 is the - same as setting it to the height of the JPEG image (in other words, the - height will not be considered when determining the scaled image size.)
pixelFormat - pixel format of the decompressed image (one of - TJ.PF_*)
flags - the bitwise OR of one or more of TJ.FLAG_* + or by calling getScaledWidth(int, int). If the source image is a + YUV image, then scaledWidth is the width of the YUV image. + Setting this parameter to 0 is the equivalent of setting it to + scaledWidth.
desiredHeight - If the source image is a JPEG image, then this + specifies the desired height (in pixels) of the decompressed image (or + image region.) If the desired destination image dimensions are different + than the source image dimensions, then TurboJPEG will use scaling in the + JPEG decompressor to generate the largest possible image that will fit + within the desired dimensions. Setting this to 0 is the same as setting + it to the height of the JPEG image (in other words, the height will not be + considered when determining the scaled image size.) This parameter is + ignored if the source image is a YUV image.
pixelFormat - pixel format of the decompressed image (one of + TJ.PF_*)
flags - the bitwise OR of one or more of + TJ.FLAG_*
Throws:
java.lang.Exception
@@ -1063,13 +1237,19 @@ public void decompress(java.awt.image.BufferedImage dstImage, int flags) throws java.lang.Exception
-
Decompress the JPEG source image associated with this decompressor - instance and output a decompressed image to the given - BufferedImage instance. +
Decompress the JPEG source image or decode the YUV source image associated + with this decompressor instance and output a decompressed/decoded image to + the given BufferedImage instance.

Parameters:
dstImage - a BufferedImage instance that will receive - the decompressed image
flags - the bitwise OR of one or more of TJ.FLAG_* + the decompressed/decoded image. If the source image is a JPEG image, then + the width and height of the BufferedImage instance must match + one of the scaled image sizes that TurboJPEG is capable of generating from + the JPEG image. If the source image is a YUV image, then the width and + height of the BufferedImage instance must match the width and + height of the YUV image.
flags - the bitwise OR of one or more of + TJ.FLAG_*
Throws:
java.lang.Exception
@@ -1085,20 +1265,21 @@ public java.awt.image.BufferedImage decompress(int desiredWidth, int flags) throws java.lang.Exception
-
Decompress the JPEG source image associated with this decompressor - instance and return a BufferedImage instance containing the - decompressed image. +
Decompress the JPEG source image or decode the YUV source image associated + with this decompressor instance and return a BufferedImage + instance containing the decompressed/decoded image.

Parameters:
desiredWidth - see decompress(byte[], int, int, int, int, int, int, int) for description
desiredHeight - see decompress(byte[], int, int, int, int, int, int, int) for - description
bufferedImageType - the image type of the newly-created - BufferedImage instance (for instance, - BufferedImage.TYPE_INT_RGB)
flags - the bitwise OR of one or more of TJ.FLAG_* + description
bufferedImageType - the image type of the BufferedImage + instance that will be created (for instance, + BufferedImage.TYPE_INT_RGB)
flags - the bitwise OR of one or more of + TJ.FLAG_*
Returns:
a BufferedImage instance containing the - decompressed image + decompressed/decoded image
Throws:
java.lang.Exception
diff --git a/java/doc/org/libjpegturbo/turbojpeg/TJTransformer.html b/java/doc/org/libjpegturbo/turbojpeg/TJTransformer.html index 0811b51..75fedf7 100644 --- a/java/doc/org/libjpegturbo/turbojpeg/TJTransformer.html +++ b/java/doc/org/libjpegturbo/turbojpeg/TJTransformer.html @@ -52,7 +52,7 @@ function windowTitle()  PREV CLASS  - NEXT CLASSNEXT CLASS FRAMES    NO FRAMES   @@ -120,7 +120,7 @@ TurboJPEG lossless transformer Fields inherited from class org.libjpegturbo.turbojpeg.TJDecompressor -handle, jpegBuf, jpegBufSize, jpegColorspace, jpegHeight, jpegSubsamp, jpegWidth +handle, jpegBuf, jpegBufSize, srcColorspace, srcHeight, srcSubsamp, srcWidth, yuvImage   @@ -143,7 +143,7 @@ TurboJPEG lossless transformer
          Create a TurboJPEG lossless transformer instance and associate the JPEG - image stored in jpegImage with the newly-created instance. + image stored in jpegImage with the newly created instance. TJTransformer(byte[] jpegImage, @@ -152,7 +152,7 @@ TurboJPEG lossless transformer
          Create a TurboJPEG lossless transformer instance and associate the JPEG image of length imageSize bytes stored in - jpegImage with the newly-created instance. + jpegImage with the newly created instance.   @@ -170,8 +170,8 @@ TurboJPEG lossless transformer getTransformedSizes()
-          Returns an array containing the sizes of the transformed JPEG images from - the most recent call to transform(). +          Returns an array containing the sizes of the transformed JPEG images + generated by the most recent transform operation. @@ -203,7 +203,7 @@ TurboJPEG lossless transformer Methods inherited from class org.libjpegturbo.turbojpeg.TJDecompressor -close, decompress, decompress, decompress, decompress, decompress, decompress, decompressToYUV, decompressToYUV, decompressToYUV, decompressToYUV, finalize, getColorspace, getHeight, getJPEGBuf, getJPEGSize, getScaledHeight, getScaledWidth, getSubsamp, getWidth, setJPEGImage +close, decompress, decompress, decompress, decompress, decompress, decompress, decompressToYUV, decompressToYUV, decompressToYUV, decompressToYUV, finalize, getColorspace, getHeight, getJPEGBuf, getJPEGSize, getScaledHeight, getScaledWidth, getSourceBuf, getSourceSize, getSubsamp, getWidth, setJPEGImage, setSourceImage, setSourceImage   @@ -250,7 +250,7 @@ public TJTransformer(byte[] jpegImage) throws java.lang.Exception
Create a TurboJPEG lossless transformer instance and associate the JPEG - image stored in jpegImage with the newly-created instance. + image stored in jpegImage with the newly created instance.

Parameters:
jpegImage - JPEG image buffer (size of the JPEG image is assumed to @@ -269,7 +269,7 @@ public TJTransformer(byte[] jpegImage,
Create a TurboJPEG lossless transformer instance and associate the JPEG image of length imageSize bytes stored in - jpegImage with the newly-created instance. + jpegImage with the newly created instance.

Parameters:
jpegImage - JPEG image buffer
imageSize - size of the JPEG image (in bytes) @@ -313,9 +313,10 @@ public void transform(byte[][] dstBufs, receive a JPEG image that has been transformed using the parameters in transforms[i]. Use TJ.bufSize(int, int, int) to determine the maximum size for each buffer based on the transformed or cropped width and - height.
transforms - an array of TJTransform instances, each of + height and the level of subsampling used in the source image.
transforms - an array of TJTransform instances, each of which specifies the transform parameters and/or cropping region for the - corresponding transformed output image
flags - the bitwise OR of one or more of TJ.FLAG_* + corresponding transformed output image
flags - the bitwise OR of one or more of + TJ.FLAG_*
Throws:
java.lang.Exception
@@ -336,7 +337,8 @@ public TJTransform instances, each of which specifies the transform parameters and/or cropping region for the - corresponding transformed output image
flags - the bitwise OR of one or more of TJ.FLAG_* + corresponding transformed output image
flags - the bitwise OR of one or more of + TJ.FLAG_*
Returns:
an array of TJDecompressor instances, each of which has a transformed JPEG image associated with it
Throws: @@ -351,13 +353,13 @@ getTransformedSizes public int[] getTransformedSizes() throws java.lang.Exception
-
Returns an array containing the sizes of the transformed JPEG images from - the most recent call to transform(). +
Returns an array containing the sizes of the transformed JPEG images + generated by the most recent transform operation.

-
Returns:
an array containing the sizes of the transformed JPEG images from - the most recent call to transform() +
Returns:
an array containing the sizes of the transformed JPEG images + generated by the most recent transform operation
Throws:
java.lang.Exception
@@ -392,7 +394,7 @@ public int[] getTransformedSizes()  PREV CLASS  - NEXT CLASSNEXT CLASS
FRAMES    NO FRAMES   diff --git a/java/doc/org/libjpegturbo/turbojpeg/package-frame.html b/java/doc/org/libjpegturbo/turbojpeg/package-frame.html index f160418..215bdea 100644 --- a/java/doc/org/libjpegturbo/turbojpeg/package-frame.html +++ b/java/doc/org/libjpegturbo/turbojpeg/package-frame.html @@ -42,7 +42,9 @@ Classes 
TJTransform
-TJTransformer
+TJTransformer +
+YUVImage diff --git a/java/doc/org/libjpegturbo/turbojpeg/package-summary.html b/java/doc/org/libjpegturbo/turbojpeg/package-summary.html index 505512c..12c047b 100644 --- a/java/doc/org/libjpegturbo/turbojpeg/package-summary.html +++ b/java/doc/org/libjpegturbo/turbojpeg/package-summary.html @@ -122,6 +122,11 @@ Package org.libjpegturbo.turbojpeg TJTransformer TurboJPEG lossless transformer + +YUVImage +This class encapsulates a YUV planar image buffer and the metadata + associated with it. +   diff --git a/java/doc/org/libjpegturbo/turbojpeg/package-tree.html b/java/doc/org/libjpegturbo/turbojpeg/package-tree.html index e13143d..5910278 100644 --- a/java/doc/org/libjpegturbo/turbojpeg/package-tree.html +++ b/java/doc/org/libjpegturbo/turbojpeg/package-tree.html @@ -95,7 +95,7 @@ Class Hierarchy
  • org.libjpegturbo.turbojpeg.TJ
  • org.libjpegturbo.turbojpeg.TJCompressor
  • org.libjpegturbo.turbojpeg.TJDecompressor -
  • org.libjpegturbo.turbojpeg.TJScalingFactor +
  • org.libjpegturbo.turbojpeg.TJScalingFactor
  • org.libjpegturbo.turbojpeg.YUVImage

    Interface Hierarchy diff --git a/java/doc/overview-tree.html b/java/doc/overview-tree.html index 1c12b10..563b579 100644 --- a/java/doc/overview-tree.html +++ b/java/doc/overview-tree.html @@ -97,7 +97,7 @@ Class Hierarchy
  • org.libjpegturbo.turbojpeg.TJ
  • org.libjpegturbo.turbojpeg.TJCompressor
  • org.libjpegturbo.turbojpeg.TJDecompressor -
  • org.libjpegturbo.turbojpeg.TJScalingFactor +
  • org.libjpegturbo.turbojpeg.TJScalingFactor
  • org.libjpegturbo.turbojpeg.YUVImage

    Interface Hierarchy diff --git a/java/org/libjpegturbo/turbojpeg/TJCompressor.java b/java/org/libjpegturbo/turbojpeg/TJCompressor.java index ed8d8e1..0debf53 100644 --- a/java/org/libjpegturbo/turbojpeg/TJCompressor.java +++ b/java/org/libjpegturbo/turbojpeg/TJCompressor.java @@ -46,19 +46,9 @@ public class TJCompressor { init(); } - /** - * @deprecated Use - * {@link #TJCompressor(byte[], int, int, int, int, int, int)} instead. - */ - @Deprecated - public TJCompressor(byte[] srcImage, int width, int pitch, int height, - int pixelFormat) throws Exception { - setSourceImage(srcImage, width, pitch, height, pixelFormat); - } - /** * Create a TurboJPEG compressor instance and associate the uncompressed - * source image stored in srcImage with the newly-created + * source image stored in srcImage with the newly created * instance. * * @param srcImage see {@link #setSourceImage} for description @@ -74,16 +64,26 @@ public class TJCompressor { * @param height see {@link #setSourceImage} for description * * @param pixelFormat pixel format of the source image (one of - * {@link TJ TJ.PF_*}) + * {@link TJ#PF_RGB TJ.PF_*}) */ public TJCompressor(byte[] srcImage, int x, int y, int width, int pitch, int height, int pixelFormat) throws Exception { setSourceImage(srcImage, x, y, width, pitch, height, pixelFormat); } + /** + * @deprecated Use + * {@link #TJCompressor(byte[], int, int, int, int, int, int)} instead. + */ + @Deprecated + public TJCompressor(byte[] srcImage, int width, int pitch, int height, + int pixelFormat) throws Exception { + setSourceImage(srcImage, width, pitch, height, pixelFormat); + } + /** * Create a TurboJPEG compressor instance and associate the uncompressed - * source image stored in srcImage with the newly-created + * source image stored in srcImage with the newly created * instance. * * @param srcImage see @@ -107,34 +107,35 @@ public class TJCompressor { } /** - * Associate an uncompressed source image with this compressor instance. + * Associate an uncompressed RGB, grayscale, or CMYK source image with this + * compressor instance. * * @param srcImage image buffer containing RGB, grayscale, or CMYK pixels to - * be compressed + * be compressed or encoded * - * @param x x offset (in pixels) of the region from which the JPEG image - * should be compressed, relative to the start of srcImage. + * @param x x offset (in pixels) of the region in the source image from which + * the JPEG or YUV image should be compressed/encoded * - * @param y y offset (in pixels) of the region from which the JPEG image - * should be compressed, relative to the start of srcImage. + * @param y y offset (in pixels) of the region in the source image from which + * the JPEG or YUV image should be compressed/encoded * * @param width width (in pixels) of the region in the source image from - * which the JPEG image should be compressed. + * which the JPEG or YUV image should be compressed/encoded * * @param pitch bytes per line of the source image. Normally, this should be * width * TJ.pixelSize(pixelFormat) if the source image is * unpadded, but you can use this parameter to, for instance, specify that * the scanlines in the source image are padded to a 4-byte boundary or to - * compress a JPEG image from a region of a larger source image. You can - * also be clever and use this parameter to skip lines, etc. Setting this - * parameter to 0 is the equivalent of setting it to width * - * TJ.pixelSize(pixelFormat). + * compress/encode a JPEG or YUV image from a region of a larger source + * image. You can also be clever and use this parameter to skip lines, etc. + * Setting this parameter to 0 is the equivalent of setting it to + * width * TJ.pixelSize(pixelFormat). * * @param height height (in pixels) of the region in the source image from - * which the JPEG image should be compressed. + * which the JPEG or YUV image should be compressed/encoded * * @param pixelFormat pixel format of the source image (one of - * {@link TJ TJ.PF_*}) + * {@link TJ#PF_RGB TJ.PF_*}) */ public void setSourceImage(byte[] srcImage, int x, int y, int width, int pitch, int height, int pixelFormat) @@ -154,7 +155,7 @@ public class TJCompressor { srcX = x; srcY = y; srcBufInt = null; - srcIsYUV = false; + srcYUVImage = null; } /** @@ -169,22 +170,25 @@ public class TJCompressor { } /** - * Associate an uncompressed source image with this compressor instance. + * Associate an uncompressed RGB or grayscale source image with this + * compressor instance. * * @param srcImage a BufferedImage instance containing RGB or - * grayscale pixels to be compressed + * grayscale pixels to be compressed or encoded * * @param x x offset (in pixels) of the region in the source image from which - * the JPEG image should be compressed + * the JPEG or YUV image should be compressed/encoded * * @param y y offset (in pixels) of the region in the source image from which - * the JPEG image should be compressed + * the JPEG or YUV image should be compressed/encoded * * @param width width (in pixels) of the region in the source image from - * which the JPEG image should be compressed (0 = compress the whole image) + * which the JPEG or YUV image should be compressed/encoded (0 = use the + * width of the source image) * * @param height height (in pixels) of the region in the source image from - * which the JPEG image should be compressed (0 = compress the whole image) + * which the JPEG or YUV image should be compressed/encoded (0 = use the + * height of the source image) */ public void setSourceImage(BufferedImage srcImage, int x, int y, int width, int height) throws Exception { @@ -248,42 +252,22 @@ public class TJCompressor { srcBuf = db.getData(); srcBufInt = null; } + srcYUVImage = null; } /** * Associate an uncompressed YUV planar source image with this compressor * instance. * - * @param srcImage image buffer containing a YUV planar image to be - * compressed. The Y, U (Cb), and V (Cr) image planes should be stored - * sequentially in the buffer, and the size of each plane is determined by - * the specified width, height, and padding, as well as the level of - * chrominance subsampling (specified using {@link #setSubsamp}.) If the - * chrominance components are subsampled along the horizontal dimension, then - * the width of the luminance plane should be padded to the nearest multiple - * of 2 (same goes for the height of the luminance plane, if the chrominance - * components are subsampled along the vertical dimension.) This is - * irrespective of any additional padding specified in the pad - * parameter. - * - * @param width width (in pixels) of the source image - * - * @param pad the line padding used in the source image. For instance, if - * each line in each plane of the YUV image is padded to the nearest multiple - * of 4 bytes, then pad should be set to 4. - * - * @param height height (in pixels) of the source image + * @param srcImage YUV planar image to be compressed */ - public void setSourceImageYUV(byte[] srcImage, int width, int pad, - int height) throws Exception { + public void setSourceImage(YUVImage srcImage) throws Exception { if (handle == 0) init(); - if (srcImage == null || width < 1 || pad < 1 || height < 1) - throw new Exception("Invalid argument in setSourceImageYUV()"); - srcBuf = srcImage; - srcWidth = width; - srcYUVPad = pad; - srcHeight = height; - srcIsYUV = true; + if (srcImage == null) + throw new Exception("Invalid argument in setSourceImage()"); + srcYUVImage = srcImage; + srcBuf = null; + srcBufInt = null; } /** @@ -296,12 +280,16 @@ public class TJCompressor { * sensitive to small changes in brightness than to small changes in color.) * This is called "chrominance subsampling". *

    - * NOTE: When compressing a YUV planar image into a JPEG image, this method - * also specifies the level of chrominance subsampling used in the source - * image. - * - * @param newSubsamp the new level of chrominance subsampling (one of - * {@link TJ TJ.SAMP_*}) + * NOTE: This method has no effect when compressing a JPEG image from a YUV + * planar source. In that case, the level of chrominance subsampling in + * the JPEG image is determined by the source. Further, this method has no + * effect when encoding to a pre-allocated {@link YUVImage} instance. In + * that case, the level of chrominance subsampling is determined by the + * destination. + * + * @param newSubsamp the level of chrominance subsampling to use in + * subsequent compress/encode oeprations (one of + * {@link TJ#SAMP_444 TJ.SAMP_*}) */ public void setSubsamp(int newSubsamp) throws Exception { if (newSubsamp < 0 || newSubsamp >= TJ.NUMSAMP) @@ -327,23 +315,29 @@ public class TJCompressor { * * @param dstBuf buffer that will receive the JPEG image. Use * {@link TJ#bufSize} to determine the maximum size for this buffer based on - * the image width, height, and level of chrominance subsampling. + * the source image's width and height and the desired level of chrominance + * subsampling. * - * @param flags the bitwise OR of one or more of {@link TJ TJ.FLAG_*} + * @param flags the bitwise OR of one or more of + * {@link TJ#FLAG_BOTTOMUP TJ.FLAG_*} */ public void compress(byte[] dstBuf, int flags) throws Exception { if (dstBuf == null || flags < 0) throw new Exception("Invalid argument in compress()"); - if (srcBuf == null && (srcBufInt == null || srcIsYUV)) + if (srcBuf == null && srcBufInt == null && srcYUVImage == null) throw new Exception(NO_ASSOC_ERROR); if (jpegQuality < 0) throw new Exception("JPEG Quality not set"); - if (subsamp < 0) + if (subsamp < 0 && srcYUVImage == null) throw new Exception("Subsampling level not set"); - if (srcIsYUV) - compressedSize = compressFromYUV(srcBuf, srcWidth, srcYUVPad, srcHeight, - subsamp, dstBuf, jpegQuality, flags); + if (srcYUVImage != null) + compressedSize = compressFromYUV(srcYUVImage.getBuf(), + srcYUVImage.getWidth(), + srcYUVImage.getPad(), + srcYUVImage.getHeight(), + srcYUVImage.getSubsamp(), + dstBuf, jpegQuality, flags); else if (srcBuf != null) { if (srcX >= 0 && srcY >= 0) compressedSize = compress(srcBuf, srcX, srcY, srcWidth, srcPitch, @@ -369,7 +363,8 @@ public class TJCompressor { * Compress the uncompressed source image associated with this compressor * instance and return a buffer containing a JPEG image. * - * @param flags the bitwise OR of one or more of {@link TJ TJ.FLAG_*} + * @param flags the bitwise OR of one or more of + * {@link TJ#FLAG_BOTTOMUP TJ.FLAG_*} * * @return a buffer containing a JPEG image. The length of this buffer will * not be equal to the size of the JPEG image. Use {@link @@ -406,82 +401,100 @@ public class TJCompressor { return compress(flags); } - - /** - * Set the plane padding for subsequent YUV encode operations. - * - * @param pad the width of each line in each plane of the YUV image will be - * padded to the nearest multiple of this number of bytes (must be a - * power of 2.) The default padding is 4 bytes, which generates - * images suitable for direct video display. - */ - public void setYUVPad(int pad) throws Exception { - if(pad < 1 || ((pad & (pad - 1)) != 0)) - throw new Exception("Invalid argument in setYUVPad()"); - yuvPad = pad; - } - /** * Encode the uncompressed source image associated with this compressor - * instance and output a YUV planar image to the given destination buffer. - * This method uses the accelerated color conversion routines in TurboJPEG's - * underlying codec but does not execute any of the other steps in the JPEG - * compression process. The Y, U (Cb), and V (Cr) image planes are stored - * sequentially into the destination buffer, and the size of each plane is - * determined by the width and height of the source image, as well as the - * specified padding and level of chrominance subsampling. If the - * chrominance components are subsampled along the horizontal dimension, then - * the width of the luminance plane is padded to the nearest multiple of 2 in - * the output image (same goes for the height of the luminance plane, if the - * chrominance components are subsampled along the vertical dimension.) - *

    - * NOTE: Technically, the JPEG format uses the YCbCr colorspace, but per the - * convention of the digital video community, the TurboJPEG API uses "YUV" to - * refer to an image format consisting of Y, Cb, and Cr image planes. + * instance into a YUV planar image and store it in the given + * YUVImage instance. This method uses the accelerated color + * conversion routines in TurboJPEG's underlying codec but does not execute + * any of the other steps in the JPEG compression process. Encoding + * CMYK source images to YUV is not supported. * - * @param dstBuf buffer that will receive the YUV planar image. Use - * {@link TJ#bufSizeYUV} to determine the appropriate size for this buffer - * based on the image width, height, and level of chrominance subsampling. + * @param dstImage {@link YUVImage} instance that will receive the YUV planar + * image * - * @param flags the bitwise OR of one or more of {@link TJ TJ.FLAG_*} + * @param flags the bitwise OR of one or more of + * {@link TJ#FLAG_BOTTOMUP TJ.FLAG_*} */ - public void encodeYUV(byte[] dstBuf, int flags) throws Exception { - if (dstBuf == null || flags < 0) - throw new Exception("Invalid argument in compress()"); + public void encodeYUV(YUVImage dstImage, int flags) throws Exception { + if (dstImage == null || flags < 0) + throw new Exception("Invalid argument in encodeYUV()"); if (srcBuf == null && srcBufInt == null) throw new Exception(NO_ASSOC_ERROR); - if (srcIsYUV) + if (srcYUVImage != null) throw new Exception("Source image is not correct type"); if (subsamp < 0) throw new Exception("Subsampling level not set"); + if (srcWidth != dstImage.getWidth() || srcHeight != dstImage.getHeight()) + throw new Exception("Destination image is the wrong size"); if (srcBufInt != null) { - encodeYUV(srcBufInt, srcWidth, srcStride, srcHeight, srcPixelFormat, - dstBuf, yuvPad, subsamp, flags); + encodeYUV(srcBufInt, srcX, srcY, srcWidth, srcStride, srcHeight, + srcPixelFormat, dstImage.getBuf(), dstImage.getPad(), + dstImage.getSubsamp(), flags); } else { - encodeYUV(srcBuf, srcWidth, srcPitch, srcHeight, srcPixelFormat, dstBuf, - yuvPad, subsamp, flags); + encodeYUV(srcBuf, srcX, srcY, srcWidth, srcPitch, srcHeight, + srcPixelFormat, dstImage.getBuf(), dstImage.getPad(), + dstImage.getSubsamp(), flags); } - compressedSize = TJ.bufSizeYUV(srcWidth, yuvPad, srcHeight, subsamp); + compressedSize = dstImage.getSize(); + } + + /** + * @deprecated Use {@link #encodeYUV(YUVImage, int)} instead. + */ + @Deprecated + public void encodeYUV(byte[] dstBuf, int flags) throws Exception { + if(dstBuf == null) + throw new Exception("Invalid argument in encodeYUV()"); + if (srcWidth < 1 || srcHeight < 1) + throw new Exception(NO_ASSOC_ERROR); + if (subsamp < 0) + throw new Exception("Subsampling level not set"); + YUVImage yuvImage = new YUVImage(dstBuf, srcWidth, 4, srcHeight, subsamp); + encodeYUV(yuvImage, flags); } /** * Encode the uncompressed source image associated with this compressor - * instance and return a buffer containing a YUV planar image. See - * {@link #encodeYUV(byte[], int)} for more detail. + * instance into a YUV planar image and return a YUVImage + * instance containing the encoded image. This method uses the accelerated + * color conversion routines in TurboJPEG's underlying codec but does not + * execute any of the other steps in the JPEG compression process. Encoding + * CMYK source images to YUV is not supported. + * + * @param pad the width of each line in each plane of the YUV image will be + * padded to the nearest multiple of this number of bytes (must be a power of + * 2.) * - * @param flags the bitwise OR of one or more of {@link TJ TJ.FLAG_*} + * @param flags the bitwise OR of one or more of + * {@link TJ#FLAG_BOTTOMUP TJ.FLAG_*} * - * @return a buffer containing a YUV planar image + * @return a YUV planar image + */ + public YUVImage encodeYUV(int pad, int flags) throws Exception { + if (srcWidth < 1 || srcHeight < 1) + throw new Exception(NO_ASSOC_ERROR); + if (subsamp < 0) + throw new Exception("Subsampling level not set"); + if(pad < 1 || ((pad & (pad - 1)) != 0)) + throw new Exception("Invalid argument in encodeYUV()"); + YUVImage yuvImage = new YUVImage(srcWidth, pad, srcHeight, subsamp); + encodeYUV(yuvImage, flags); + return yuvImage; + } + + /** + * @deprecated Use {@link #encodeYUV(int, int)} instead. */ + @Deprecated public byte[] encodeYUV(int flags) throws Exception { if (srcWidth < 1 || srcHeight < 1) throw new Exception(NO_ASSOC_ERROR); if (subsamp < 0) throw new Exception("Subsampling level not set"); - byte[] buf = new byte[TJ.bufSizeYUV(srcWidth, yuvPad, srcHeight, subsamp)]; - encodeYUV(buf, flags); - return buf; + YUVImage yuvImage = new YUVImage(srcWidth, 4, srcHeight, subsamp); + encodeYUV(yuvImage, flags); + return yuvImage.getBuf(); } /** @@ -563,17 +576,17 @@ public class TJCompressor { int height, int pixelFormat, byte[] dstBuf, int subsamp, int flags) throws Exception; // deprecated - private native void encodeYUV(byte[] srcBuf, int width, int pitch, - int height, int pixelFormat, byte[] dstBuf, int pad, int subsamp, - int flags) throws Exception; + private native void encodeYUV(byte[] srcBuf, int x, int y, int width, + int pitch, int height, int pixelFormat, byte[] dstBuf, int pad, + int subsamp, int flags) throws Exception; private native void encodeYUV(int[] srcBuf, int width, int stride, int height, int pixelFormat, byte[] dstBuf, int subsamp, int flags) throws Exception; // deprecated - private native void encodeYUV(int[] srcBuf, int width, int pitch, - int height, int pixelFormat, byte[] dstBuf, int pad, int subsamp, - int flags) throws Exception; + private native void encodeYUV(int[] srcBuf, int x, int y, int width, + int pitch, int height, int pixelFormat, byte[] dstBuf, int pad, + int subsamp, int flags) throws Exception; static { TJLoader.load(); @@ -589,8 +602,7 @@ public class TJCompressor { private int srcPitch = 0; private int srcStride = 0; private int srcPixelFormat = -1; - private int srcYUVPad = -1; - private boolean srcIsYUV; + private YUVImage srcYUVImage = null; private int subsamp = -1; private int jpegQuality = -1; private int compressedSize = 0; diff --git a/java/org/libjpegturbo/turbojpeg/TJDecompressor.java b/java/org/libjpegturbo/turbojpeg/TJDecompressor.java index d14a989..8305721 100644 --- a/java/org/libjpegturbo/turbojpeg/TJDecompressor.java +++ b/java/org/libjpegturbo/turbojpeg/TJDecompressor.java @@ -1,5 +1,5 @@ /* - * Copyright (C)2011-2013 D. R. Commander. All Rights Reserved. + * Copyright (C)2011-2014 D. R. Commander. All Rights Reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -37,7 +37,7 @@ import java.nio.*; public class TJDecompressor { private static final String NO_ASSOC_ERROR = - "No JPEG image is associated with this instance"; + "No source image is associated with this instance"; /** * Create a TurboJPEG decompresssor instance. @@ -47,21 +47,21 @@ public class TJDecompressor { } /** - * Create a TurboJPEG decompressor instance and associate the JPEG image - * stored in jpegImage with the newly-created instance. + * Create a TurboJPEG decompressor instance and associate the JPEG source + * image stored in jpegImage 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); + setSourceImage(jpegImage, jpegImage.length); } /** - * Create a TurboJPEG decompressor instance and associate the JPEG image - * of length imageSize bytes stored in jpegImage - * with the newly-created instance. + * Create a TurboJPEG decompressor instance and associate the JPEG source + * image of length imageSize bytes stored in + * jpegImage with the newly created instance. * * @param jpegImage JPEG image buffer * @@ -69,87 +69,150 @@ public class TJDecompressor { */ public TJDecompressor(byte[] jpegImage, int imageSize) throws Exception { init(); - setJPEGImage(jpegImage, imageSize); + setSourceImage(jpegImage, imageSize); + } + + /** + * Create a TurboJPEG decompressor instance and associate the YUV planar + * source image stored in yuvImage with the newly created + * instance. + * + * @param yuvImage {@link YUVImage} instance containing a YUV planar + * image to be decoded + */ + public TJDecompressor(YUVImage yuvImage) throws Exception { + init(); + setSourceImage(yuvImage); } /** * Associate the JPEG image of length imageSize bytes stored in - * jpegImage with this decompressor instance. This image will + * srcImage with this decompressor instance. This image will * be used as the source image for subsequent decompress operations. * - * @param jpegImage JPEG image buffer + * @param srcImage JPEG image buffer * * @param imageSize size of the JPEG image (in bytes) */ - public void setJPEGImage(byte[] jpegImage, int imageSize) throws Exception { - if (jpegImage == null || imageSize < 1) - throw new Exception("Invalid argument in setJPEGImage()"); - jpegBuf = jpegImage; + public void setSourceImage(byte[] srcImage, int imageSize) + throws Exception { + if (srcImage == null || imageSize < 1) + throw new Exception("Invalid argument in setSourceImage()"); + jpegBuf = srcImage; jpegBufSize = imageSize; decompressHeader(jpegBuf, jpegBufSize); + yuvImage = null; } /** - * Returns the width of the JPEG image associated with this decompressor - * instance. + * @deprecated Use {@link #setSourceImage(byte[], int)} instead. + */ + @Deprecated + public void setJPEGImage(byte[] jpegImage, int imageSize) throws Exception { + setSourceImage(jpegImage, imageSize); + } + + /** + * Associate the specified YUV planar source image with this decompressor + * instance. Subsequent decompress operations will decode this image into an + * RGB or grayscale destination image. + * + * @param srcImage {@link YUVImage} instance containing a YUV planar image to + * be decoded + */ + public void setSourceImage(YUVImage srcImage) throws Exception { + if (srcImage == null) + throw new Exception("Invalid argument in setSourceImage()"); + yuvImage = srcImage; + jpegBuf = null; + jpegBufSize = 0; + } + + + /** + * Returns the width of the source image (JPEG or YUV) associated with this + * decompressor instance. * - * @return the width of the JPEG image associated with this decompressor - * instance + * @return the width of the source image (JPEG or YUV) associated with this + * decompressor instance */ public int getWidth() throws Exception { - if (jpegWidth < 1) + if (yuvImage != null) + return yuvImage.getWidth(); + if (srcWidth < 1) throw new Exception(NO_ASSOC_ERROR); - return jpegWidth; + return srcWidth; } /** - * Returns the height of the JPEG image associated with this decompressor - * instance. + * Returns the height of the source image (JPEG or YUV) associated with this + * decompressor instance. * - * @return the height of the JPEG image associated with this decompressor - * instance + * @return the height of the source image (JPEG or YUV) associated with this + * decompressor instance */ public int getHeight() throws Exception { - if (jpegHeight < 1) + if (yuvImage != null) + return yuvImage.getHeight(); + if (srcHeight < 1) throw new Exception(NO_ASSOC_ERROR); - return jpegHeight; + return srcHeight; } /** - * Returns the level of chrominance subsampling used in the JPEG image - * associated with this decompressor instance. See {@link TJ TJ.SAMP_*}. + * Returns the level of chrominance subsampling used in the source image + * (JPEG or YUV) associated with this decompressor instance. See + * {@link TJ#SAMP_444 TJ.SAMP_*}. * - * @return the level of chrominance subsampling used in the JPEG image - * associated with this decompressor instance + * @return the level of chrominance subsampling used in the source image + * (JPEG or YUV) associated with this decompressor instance */ public int getSubsamp() throws Exception { - if (jpegSubsamp < 0) + if (yuvImage != null) + return yuvImage.getSubsamp(); + if (srcSubsamp < 0) throw new Exception(NO_ASSOC_ERROR); - if (jpegSubsamp >= TJ.NUMSAMP) + if (srcSubsamp >= TJ.NUMSAMP) throw new Exception("JPEG header information is invalid"); - return jpegSubsamp; + return srcSubsamp; } /** - * Returns the colorspace used in the JPEG image associated with this - * decompressor instance. See {@link TJ TJ.CS_*}. + * Returns the colorspace used in the source image (JPEG or YUV) associated + * with this decompressor instance. See {@link TJ#CS_RGB TJ.CS_*}. If the + * source image is YUV, then this always returns {@link TJ#CS_YCbCr}. * - * @return the colorspace used in the JPEG image associated with this - * decompressor instance + * @return the colorspace used in the source image (JPEG or YUV) associated + * with this decompressor instance */ public int getColorspace() throws Exception { - if (jpegColorspace < 0) + if (yuvImage != null) + return TJ.CS_YCbCr; + if (srcColorspace < 0) throw new Exception(NO_ASSOC_ERROR); - if (jpegColorspace >= TJ.NUMCS) + if (srcColorspace >= TJ.NUMCS) throw new Exception("JPEG header information is invalid"); - return jpegColorspace; + return srcColorspace; } /** - * Returns the JPEG image buffer associated with this decompressor instance. + * Returns the source image buffer associated with this decompressor + * instance. * - * @return the JPEG image buffer associated with this decompressor instance + * @return the source image buffer associated with this decompressor instance */ + public byte[] getSourceBuf() throws Exception { + if (yuvImage != null) + return yuvImage.getBuf(); + if (jpegBuf == null) + throw new Exception(NO_ASSOC_ERROR); + return jpegBuf; + } + + /** + * @deprecated Use {@link #getSourceBuf} instead. + */ + @Deprecated public byte[] getJPEGBuf() throws Exception { if (jpegBuf == null) throw new Exception(NO_ASSOC_ERROR); @@ -157,18 +220,29 @@ public class TJDecompressor { } /** - * Returns the size of the JPEG image (in bytes) associated with this + * Returns the size of the source image (in bytes) associated with this * decompressor instance. * - * @return the size of the JPEG image (in bytes) associated with this + * @return the size of the source image (in bytes) associated with this * decompressor instance */ - public int getJPEGSize() throws Exception { + public int getSourceSize() throws Exception { + if (yuvImage != null) + return yuvImage.getSize(); if (jpegBufSize < 1) throw new Exception(NO_ASSOC_ERROR); return jpegBufSize; } + /** + * @deprecated Use {@link #getSourceSize} instead. + */ + @Deprecated + public int getJPEGSize() throws Exception { + if (jpegBufSize < 1) + throw new Exception(NO_ASSOC_ERROR); + return jpegBufSize; + } /** * Returns the width of the largest scaled-down image that the TurboJPEG @@ -191,19 +265,19 @@ public class TJDecompressor { */ public int getScaledWidth(int desiredWidth, int desiredHeight) throws Exception { - if (jpegWidth < 1 || jpegHeight < 1) + if (srcWidth < 1 || srcHeight < 1) throw new Exception(NO_ASSOC_ERROR); if (desiredWidth < 0 || desiredHeight < 0) throw new Exception("Invalid argument in getScaledWidth()"); TJScalingFactor[] sf = TJ.getScalingFactors(); if (desiredWidth == 0) - desiredWidth = jpegWidth; + desiredWidth = srcWidth; if (desiredHeight == 0) - desiredHeight = jpegHeight; - int scaledWidth = jpegWidth, scaledHeight = jpegHeight; + desiredHeight = srcHeight; + int scaledWidth = srcWidth, scaledHeight = srcHeight; for (int i = 0; i < sf.length; i++) { - scaledWidth = sf[i].getScaled(jpegWidth); - scaledHeight = sf[i].getScaled(jpegHeight); + scaledWidth = sf[i].getScaled(srcWidth); + scaledHeight = sf[i].getScaled(srcHeight); if (scaledWidth <= desiredWidth && scaledHeight <= desiredHeight) break; } @@ -233,19 +307,19 @@ public class TJDecompressor { */ public int getScaledHeight(int desiredWidth, int desiredHeight) throws Exception { - if (jpegWidth < 1 || jpegHeight < 1) + if (srcWidth < 1 || srcHeight < 1) throw new Exception(NO_ASSOC_ERROR); if (desiredWidth < 0 || desiredHeight < 0) throw new Exception("Invalid argument in getScaledHeight()"); TJScalingFactor[] sf = TJ.getScalingFactors(); if (desiredWidth == 0) - desiredWidth = jpegWidth; + desiredWidth = srcWidth; if (desiredHeight == 0) - desiredHeight = jpegHeight; - int scaledWidth = jpegWidth, scaledHeight = jpegHeight; + desiredHeight = srcHeight; + int scaledWidth = srcWidth, scaledHeight = srcHeight; for (int i = 0; i < sf.length; i++) { - scaledWidth = sf[i].getScaled(jpegWidth); - scaledHeight = sf[i].getScaled(jpegHeight); + scaledWidth = sf[i].getScaled(srcWidth); + scaledHeight = sf[i].getScaled(srcHeight); if (scaledWidth <= desiredWidth && scaledHeight <= desiredHeight) break; } @@ -255,73 +329,90 @@ public class TJDecompressor { } /** - * Decompress the JPEG source image associated with this decompressor - * instance and output a decompressed image to the given destination buffer. - * - * @param dstBuf buffer that will receive the decompressed image. This - * buffer should normally be pitch * scaledHeight bytes in size, - * where scaledHeight can be determined by calling + * Decompress the JPEG source image or decode the YUV source image associated + * with this decompressor instance and output a grayscale, RGB, or CMYK image + * to the given destination buffer. + * + * @param dstBuf buffer that will receive the decompressed/decoded image. + * If the source image is a JPEG image, then this buffer should normally be + * pitch * scaledHeight bytes in size, where + * scaledHeight can be determined by calling * scalingFactor.{@link TJScalingFactor#getScaled getScaled}(jpegHeight) * with one of the scaling factors returned from {@link - * TJ#getScalingFactors} or by calling {@link #getScaledHeight}. However, - * the buffer may also be larger than the dimensions of the JPEG image, in - * which case the x, y, and pitch - * parameters can be used to specify the region into which the JPEG image - * should be decompressed. - * - * @param x x offset (in pixels) of the region into which the JPEG image - * should be decompressed, relative to the start of dstBuf. - * - * @param y y offset (in pixels) of the region into which the JPEG image - * should be decompressed, relative to the start of dstBuf. - * - * @param desiredWidth desired width (in pixels) of the decompressed image - * (or image region.) If the desired image dimensions are different than the - * dimensions of the JPEG image being decompressed, then TurboJPEG will use - * scaling in the JPEG decompressor to generate the largest possible image - * that will fit within the desired dimensions. Setting this to 0 is the - * same as setting it to the width of the JPEG image (in other words, the - * width will not be considered when determining the scaled image size.) + * TJ#getScalingFactors} or by calling {@link #getScaledHeight}. If the + * source image is a YUV image, then this buffer should normally be + * pitch * height bytes in size, where height is + * the height of the YUV image. However, the buffer may also be larger than + * the dimensions of the source image, in which case the x, + * y, and pitch parameters can be used to specify + * the region into which the source image should be decompressed/decoded. + * + * @param x x offset (in pixels) of the region in the destination image into + * which the source image should be decompressed/decoded + * + * @param y y offset (in pixels) of the region in the destination image into + * which the source image should be decompressed/decoded + * + * @param desiredWidth If the source image is a JPEG image, then this + * specifies the desired width (in pixels) of the decompressed image (or + * image region.) If the desired destination image dimensions are different + * than the source image dimensions, then TurboJPEG will use scaling in the + * JPEG decompressor to generate the largest possible image that will fit + * within the desired dimensions. Setting this to 0 is the same as setting + * it to the width of the JPEG image (in other words, the width will not be + * considered when determining the scaled image size.) This parameter is + * ignored if the source image is a YUV image. * * @param pitch bytes per line of the destination image. Normally, this * should be set to scaledWidth * TJ.pixelSize(pixelFormat) if - * the decompressed image is unpadded, but you can use this to, for instance, - * pad each line of the decompressed image to a 4-byte boundary or to - * decompress the JPEG image into a region of a larger image. NOTE: - * scaledWidth can be determined by calling + * the destination image is unpadded, but you can use this to, for instance, + * pad each line of the destination image to a 4-byte boundary or to + * decompress/decode the source image into a region of a larger image. NOTE: + * if the source image is a JPEG image, then scaledWidth can be + * determined by calling * scalingFactor.{@link TJScalingFactor#getScaled getScaled}(jpegWidth) - * or by calling {@link #getScaledWidth}. Setting this parameter to - * 0 is the equivalent of setting it to scaledWidth * - * TJ.pixelSize(pixelFormat). - * - * @param desiredHeight desired height (in pixels) of the decompressed image - * (or image region.) If the desired image dimensions are different than the - * dimensions of the JPEG image being decompressed, then TurboJPEG will use - * scaling in the JPEG decompressor to generate the largest possible image - * that will fit within the desired dimensions. Setting this to 0 is the - * same as setting it to the height of the JPEG image (in other words, the - * height will not be considered when determining the scaled image size.) - * - * @param pixelFormat pixel format of the decompressed image (one of - * {@link TJ TJ.PF_*}) - * - * @param flags the bitwise OR of one or more of {@link TJ TJ.FLAG_*} + * or by calling {@link #getScaledWidth}. If the source image is a + * YUV image, then scaledWidth is the width of the YUV image. + * Setting this parameter to 0 is the equivalent of setting it to + * scaledWidth * TJ.pixelSize(pixelFormat). + * + * @param desiredHeight If the source image is a JPEG image, then this + * specifies the desired height (in pixels) of the decompressed image (or + * image region.) If the desired destination image dimensions are different + * than the source image dimensions, then TurboJPEG will use scaling in the + * JPEG decompressor to generate the largest possible image that will fit + * within the desired dimensions. Setting this to 0 is the same as setting + * it to the height of the JPEG image (in other words, the height will not be + * considered when determining the scaled image size.) This parameter is + * ignored if the source image is a YUV image. + * + * @param pixelFormat pixel format of the decompressed/decoded image (one of + * {@link TJ#PF_RGB TJ.PF_*}) + * + * @param flags the bitwise OR of one or more of + * {@link TJ#FLAG_BOTTOMUP TJ.FLAG_*} */ public void decompress(byte[] dstBuf, int x, int y, int desiredWidth, int pitch, int desiredHeight, int pixelFormat, int flags) throws Exception { - if (jpegBuf == null) + if (jpegBuf == null && yuvImage == null) throw new Exception(NO_ASSOC_ERROR); - if (dstBuf == null || x < 0 || y < 0 || desiredWidth < 0 || pitch < 0 || - desiredHeight < 0 || pixelFormat < 0 || pixelFormat >= TJ.NUMPF || - flags < 0) + if (dstBuf == null || x < 0 || y < 0 || pitch < 0 || + (yuvImage != null && (desiredWidth < 0 || desiredHeight < 0)) || + pixelFormat < 0 || pixelFormat >= TJ.NUMPF || flags < 0) throw new Exception("Invalid argument in decompress()"); - if (x > 0 || y > 0) - decompress(jpegBuf, jpegBufSize, dstBuf, x, y, desiredWidth, pitch, - desiredHeight, pixelFormat, flags); - else - decompress(jpegBuf, jpegBufSize, dstBuf, desiredWidth, pitch, - desiredHeight, pixelFormat, flags); + if (yuvImage != null) + decodeYUV(yuvImage.getBuf(), yuvImage.getPad(), yuvImage.getSubsamp(), + dstBuf, x, y, yuvImage.getWidth(), pitch, yuvImage.getHeight(), + pixelFormat, flags); + else { + if (x > 0 || y > 0) + decompress(jpegBuf, jpegBufSize, dstBuf, x, y, desiredWidth, pitch, + desiredHeight, pixelFormat, flags); + else + decompress(jpegBuf, jpegBufSize, dstBuf, desiredWidth, pitch, + desiredHeight, pixelFormat, flags); + } } /** @@ -353,15 +444,17 @@ public class TJDecompressor { * for description * * @param pixelFormat pixel format of the decompressed image (one of - * {@link TJ TJ.PF_*}) + * {@link TJ#PF_RGB TJ.PF_*}) * - * @param flags the bitwise OR of one or more of {@link TJ TJ.FLAG_*} + * @param flags the bitwise OR of one or more of + * {@link TJ#FLAG_BOTTOMUP TJ.FLAG_*} * * @return a buffer containing the decompressed image */ public byte[] decompress(int desiredWidth, int pitch, int desiredHeight, int pixelFormat, int flags) throws Exception { - if (desiredWidth < 0 || pitch < 0 || desiredHeight < 0 || + if (pitch < 0 || + (yuvImage == null && (desiredWidth < 0 || desiredHeight < 0)) || pixelFormat < 0 || pixelFormat >= TJ.NUMPF || flags < 0) throw new Exception("Invalid argument in decompress()"); int pixelSize = TJ.getPixelSize(pixelFormat); @@ -376,22 +469,60 @@ public class TJDecompressor { /** * Decompress the JPEG source image associated with this decompressor - * instance and output a YUV planar image to the given destination buffer. - * This method performs JPEG decompression but leaves out the color - * conversion step, so a planar YUV image is generated instead of an RGB - * image. The padding of the planes in this image is the same as in the - * images generated by {@link TJCompressor#encodeYUV(byte[], int)}. Note - * that, if the width or height of the image is not an even multiple of the - * MCU block size (see {@link TJ#getMCUWidth} and {@link TJ#getMCUHeight}), - * then an intermediate buffer copy will be performed within TurboJPEG. - *

    - * NOTE: Technically, the JPEG format uses the YCbCr colorspace, but per the - * convention of the digital video community, the TurboJPEG API uses "YUV" to - * refer to an image format consisting of Y, Cb, and Cr image planes. - * - * @param dstBuf buffer that will receive the YUV planar image. Use - * {@link TJ#bufSizeYUV} to determine the appropriate size for this buffer - * based on the image width, height, and level of chrominance subsampling. + * instance into a YUV planar image and store it in the given + * YUVImage instance. This method performs JPEG decompression + * but leaves out the color conversion step, so a planar YUV image is + * generated instead of an RGB or grayscale image. This method cannot be + * used to decompress JPEG source images with the CMYK or YCCK colorspace. + * + * @param dstImage {@link YUVImage} instance that will receive the YUV planar + * image. The level of subsampling specified in this YUVImage + * instance must match that of the JPEG image, and the width and height + * specified in the YUVImage instance must match one of the + * scaled image sizes that TurboJPEG is capable of generating from the JPEG + * source image. + * + * @param flags the bitwise OR of one or more of + * {@link TJ#FLAG_BOTTOMUP TJ.FLAG_*} + */ + public void decompressToYUV(YUVImage dstImage, int flags) throws Exception { + if (jpegBuf == null) + throw new Exception(NO_ASSOC_ERROR); + if (dstImage == null || flags < 0) + throw new Exception("Invalid argument in decompressToYUV()"); + int scaledWidth = getScaledWidth(dstImage.getWidth(), + dstImage.getHeight()); + int scaledHeight = getScaledHeight(dstImage.getWidth(), + dstImage.getHeight()); + if (scaledWidth != dstImage.getWidth() || + scaledHeight != dstImage.getHeight()) + throw new Exception("YUVImage dimensions do not match one of the scaled image sizes that TurboJPEG is capable of generating."); + if (srcSubsamp != dstImage.getSubsamp()) + throw new Exception("YUVImage subsampling level does not match that of the JPEG image"); + + decompressToYUV(jpegBuf, jpegBufSize, dstImage.getBuf(), + dstImage.getWidth(), dstImage.getPad(), + dstImage.getHeight(), flags); + } + + /** + * @deprecated Use {@link #decompressToYUV(YUVImage, int)} instead. + */ + @Deprecated + public void decompressToYUV(byte[] dstBuf, int flags) throws Exception { + YUVImage dstImage = new YUVImage(dstBuf, srcWidth, 4, srcHeight, + srcSubsamp); + decompressToYUV(dstImage, flags); + } + + /** + * Decompress the JPEG source image associated with this decompressor + * instance into a YUV planar image and return a YUVImage + * instance containing the decompressed image. This method performs JPEG + * decompression but leaves out the color conversion step, so a planar YUV + * image is generated instead of an RGB or grayscale image. This method + * cannot be used to decompress JPEG source images with the CMYK or YCCK + * colorspace. * * @param desiredWidth desired width (in pixels) of the YUV image. If the * desired image dimensions are different than the dimensions of the JPEG @@ -413,60 +544,28 @@ public class TJDecompressor { * the height of the JPEG image (in other words, the height will not be * considered when determining the scaled image size.) * - * @param flags the bitwise OR of one or more of {@link TJ TJ.FLAG_*} - */ - public void decompressToYUV(byte[] dstBuf, int desiredWidth, int pad, - int desiredHeight, int flags) throws Exception { - if (jpegBuf == null) - throw new Exception(NO_ASSOC_ERROR); - if (dstBuf == null || desiredWidth < 0 || pad < 1 || - ((pad & (pad - 1)) != 0) || desiredHeight < 0 || flags < 0) - throw new Exception("Invalid argument in decompressToYUV()"); - decompressToYUV(jpegBuf, jpegBufSize, dstBuf, desiredWidth, pad, - desiredHeight, flags); - } - - /** - * @deprecated Use {@link #decompressToYUV(byte[], int, int, int, int)} - * instead. - */ - @Deprecated - public void decompressToYUV(byte[] dstBuf, int flags) throws Exception { - decompressToYUV(dstBuf, 0, 4, 0, flags); - } - - /** - * Decompress the JPEG source image associated with this decompressor - * instance and return a buffer containing a YUV planar image. See {@link - * #decompressToYUV(byte[], int, int, int, int)} for more detail. - * - * @param desiredWidth see - * {@link #decompressToYUV(byte[], int, int, int, int)} for description - * - * @param pad see {@link #decompressToYUV(byte[], int, int, int, int)} for - * description - * - * @param desiredHeight see {@link - * #decompressToYUV(byte[], int, int, int, int)} for description + * @param flags the bitwise OR of one or more of + * {@link TJ#FLAG_BOTTOMUP TJ.FLAG_*} * - * @param flags the bitwise OR of one or more of {@link TJ TJ.FLAG_*} - * - * @return a buffer containing a YUV planar image + * @return a YUV planar image */ - public byte[] decompressToYUV(int desiredWidth, int pad, int desiredHeight, - int flags) throws Exception { + public YUVImage decompressToYUV(int desiredWidth, int pad, int desiredHeight, + int flags) throws Exception { if (flags < 0) throw new Exception("Invalid argument in decompressToYUV()"); - if (jpegWidth < 1 || jpegHeight < 1 || jpegSubsamp < 0) + if (srcWidth < 1 || srcHeight < 1 || srcSubsamp < 0) throw new Exception(NO_ASSOC_ERROR); - if (jpegSubsamp >= TJ.NUMSAMP) + if (srcSubsamp >= TJ.NUMSAMP) throw new Exception("JPEG header information is invalid"); + if (yuvImage != null) + throw new Exception("Source image is the wrong type"); + int scaledWidth = getScaledWidth(desiredWidth, desiredHeight); int scaledHeight = getScaledHeight(desiredWidth, desiredHeight); - byte[] buf = new byte[TJ.bufSizeYUV(scaledWidth, pad, scaledHeight, - jpegSubsamp)]; - decompressToYUV(buf, desiredWidth, pad, desiredHeight, flags); - return buf; + YUVImage yuvImage = new YUVImage(scaledWidth, pad, scaledHeight, + srcSubsamp); + decompressToYUV(yuvImage, flags); + return yuvImage; } /** @@ -474,91 +573,126 @@ public class TJDecompressor { */ @Deprecated public byte[] decompressToYUV(int flags) throws Exception { - return decompressToYUV(0, 4, 0, flags); + YUVImage dstImage = new YUVImage(srcWidth, 4, srcHeight, srcSubsamp); + decompressToYUV(dstImage, flags); + return dstImage.getBuf(); } /** - * Decompress the JPEG source image associated with this decompressor - * instance and output a decompressed image to the given destination buffer. - * - * @param dstBuf buffer that will receive the decompressed image. This - * buffer should normally be stride * scaledHeight pixels in - * size, where scaledHeight can be determined by calling + * Decompress the JPEG source image or decode the YUV source image associated + * with this decompressor instance and output a grayscale, RGB, or CMYK image + * to the given destination buffer. + * + * @param dstBuf buffer that will receive the decompressed/decoded image. + * If the source image is a JPEG image, then this buffer should normally be + * stride * scaledHeight pixels in size, where + * scaledHeight can be determined by calling * scalingFactor.{@link TJScalingFactor#getScaled getScaled}(jpegHeight) * with one of the scaling factors returned from {@link - * TJ#getScalingFactors} or by calling {@link #getScaledHeight}. However, - * the buffer may also be larger than the dimensions of the JPEG image, in - * which case the x, y, and stride - * parameters can be used to specify the region into which the JPEG image - * should be decompressed. - * - * @param x x offset (in pixels) of the region into which the JPEG image - * should be decompressed, relative to the start of dstBuf. - * - * @param y y offset (in pixels) of the region into which the JPEG image - * should be decompressed, relative to the start of dstBuf. - * - * @param desiredWidth desired width (in pixels) of the decompressed image - * (or image region.) If the desired image dimensions are different than the - * dimensions of the JPEG image being decompressed, then TurboJPEG will use - * scaling in the JPEG decompressor to generate the largest possible image - * that will fit within the desired dimensions. Setting this to 0 is the - * same as setting it to the width of the JPEG image (in other words, the - * width will not be considered when determining the scaled image size.) + * TJ#getScalingFactors} or by calling {@link #getScaledHeight}. If the + * source image is a YUV image, then this buffer should normally be + * stride * height pixels in size, where height is + * the height of the YUV image. However, the buffer may also be larger than + * the dimensions of the JPEG image, in which case the x, + * y, and stride parameters can be used to specify + * the region into which the source image should be decompressed. + * + * @param x x offset (in pixels) of the region in the destination image into + * which the source image should be decompressed/decoded + * + * @param y y offset (in pixels) of the region in the destination image into + * which the source image should be decompressed/decoded + * + * @param desiredWidth If the source image is a JPEG image, then this + * specifies the desired width (in pixels) of the decompressed image (or + * image region.) If the desired destination image dimensions are different + * than the source image dimensions, then TurboJPEG will use scaling in the + * JPEG decompressor to generate the largest possible image that will fit + * within the desired dimensions. Setting this to 0 is the same as setting + * it to the width of the JPEG image (in other words, the width will not be + * considered when determining the scaled image size.) This parameter is + * ignored if the source image is a YUV image. * * @param stride pixels per line of the destination image. Normally, this * should be set to scaledWidth, but you can use this to, for * instance, decompress the JPEG image into a region of a larger image. - * NOTE: scaledWidth can be determined by calling + * NOTE: if the source image is a JPEG image, then scaledWidth + * can be determined by calling * scalingFactor.{@link TJScalingFactor#getScaled getScaled}(jpegWidth) - * or by calling {@link #getScaledWidth}. Setting this parameter to - * 0 is the equivalent of setting it to scaledWidth. - * - * @param desiredHeight desired height (in pixels) of the decompressed image - * (or image region.) If the desired image dimensions are different than the - * dimensions of the JPEG image being decompressed, then TurboJPEG will use - * scaling in the JPEG decompressor to generate the largest possible image - * that will fit within the desired dimensions. Setting this to 0 is the - * same as setting it to the height of the JPEG image (in other words, the - * height will not be considered when determining the scaled image size.) + * or by calling {@link #getScaledWidth}. If the source image is a + * YUV image, then scaledWidth is the width of the YUV image. + * Setting this parameter to 0 is the equivalent of setting it to + * scaledWidth. + * + * @param desiredHeight If the source image is a JPEG image, then this + * specifies the desired height (in pixels) of the decompressed image (or + * image region.) If the desired destination image dimensions are different + * than the source image dimensions, then TurboJPEG will use scaling in the + * JPEG decompressor to generate the largest possible image that will fit + * within the desired dimensions. Setting this to 0 is the same as setting + * it to the height of the JPEG image (in other words, the height will not be + * considered when determining the scaled image size.) This parameter is + * ignored if the source image is a YUV image. * * @param pixelFormat pixel format of the decompressed image (one of - * {@link TJ TJ.PF_*}) + * {@link TJ#PF_RGB TJ.PF_*}) * - * @param flags the bitwise OR of one or more of {@link TJ TJ.FLAG_*} + * @param flags the bitwise OR of one or more of + * {@link TJ#FLAG_BOTTOMUP TJ.FLAG_*} */ public void decompress(int[] dstBuf, int x, int y, int desiredWidth, int stride, int desiredHeight, int pixelFormat, int flags) throws Exception { - if (jpegBuf == null) + if (jpegBuf == null && yuvImage == null) throw new Exception(NO_ASSOC_ERROR); - if (dstBuf == null || x < 0 || y < 0 || desiredWidth < 0 || stride < 0 || - desiredHeight < 0 || pixelFormat < 0 || pixelFormat >= TJ.NUMPF || - flags < 0) + if (dstBuf == null || x < 0 || y < 0 || stride < 0 || + (yuvImage != null && (desiredWidth < 0 || desiredHeight < 0)) || + pixelFormat < 0 || pixelFormat >= TJ.NUMPF || flags < 0) throw new Exception("Invalid argument in decompress()"); - decompress(jpegBuf, jpegBufSize, dstBuf, x, y, desiredWidth, stride, - desiredHeight, pixelFormat, flags); + if (yuvImage != null) + decodeYUV(yuvImage.getBuf(), yuvImage.getPad(), yuvImage.getSubsamp(), + dstBuf, x, y, yuvImage.getWidth(), stride, + yuvImage.getHeight(), pixelFormat, flags); + else + decompress(jpegBuf, jpegBufSize, dstBuf, x, y, desiredWidth, stride, + desiredHeight, pixelFormat, flags); } /** - * Decompress the JPEG source image associated with this decompressor - * instance and output a decompressed image to the given - * BufferedImage instance. + * Decompress the JPEG source image or decode the YUV source image associated + * with this decompressor instance and output a decompressed/decoded image to + * the given BufferedImage instance. * * @param dstImage a BufferedImage instance that will receive - * the decompressed image - * - * @param flags the bitwise OR of one or more of {@link TJ TJ.FLAG_*} + * the decompressed/decoded image. If the source image is a JPEG image, then + * the width and height of the BufferedImage instance must match + * one of the scaled image sizes that TurboJPEG is capable of generating from + * the JPEG image. If the source image is a YUV image, then the width and + * height of the BufferedImage instance must match the width and + * height of the YUV image. + * + * @param flags the bitwise OR of one or more of + * {@link TJ#FLAG_BOTTOMUP TJ.FLAG_*} */ public void decompress(BufferedImage dstImage, int flags) throws Exception { if (dstImage == null || flags < 0) throw new Exception("Invalid argument in decompress()"); int desiredWidth = dstImage.getWidth(); int desiredHeight = dstImage.getHeight(); - int scaledWidth = getScaledWidth(desiredWidth, desiredHeight); - int scaledHeight = getScaledHeight(desiredWidth, desiredHeight); - if (scaledWidth != desiredWidth || scaledHeight != desiredHeight) - throw new Exception("BufferedImage dimensions do not match a scaled image size that TurboJPEG is capable of generating."); + int scaledWidth, scaledHeight; + + if (yuvImage != null) { + if (desiredWidth != yuvImage.getWidth() || + desiredHeight != yuvImage.getHeight()) + throw new Exception("BufferedImage dimensions do not match the dimensions of the source image."); + scaledWidth = yuvImage.getWidth(); + scaledHeight = yuvImage.getHeight(); + } else { + scaledWidth = getScaledWidth(desiredWidth, desiredHeight); + scaledHeight = getScaledHeight(desiredWidth, desiredHeight); + if (scaledWidth != desiredWidth || scaledHeight != desiredHeight) + throw new Exception("BufferedImage dimensions do not match one of the scaled image sizes that TurboJPEG is capable of generating."); + } int pixelFormat; boolean intPixels = false; if (byteOrder == null) byteOrder = ByteOrder.nativeOrder(); @@ -599,10 +733,16 @@ public class TJDecompressor { int stride = sm.getScanlineStride(); DataBufferInt db = (DataBufferInt)wr.getDataBuffer(); int[] buf = db.getData(); - if (jpegBuf == null) - throw new Exception(NO_ASSOC_ERROR); - decompress(jpegBuf, jpegBufSize, buf, scaledWidth, stride, scaledHeight, - pixelFormat, flags); + if (yuvImage != null) + decodeYUV(yuvImage.getBuf(), yuvImage.getPad(), yuvImage.getSubsamp(), + buf, 0, 0, yuvImage.getWidth(), stride, yuvImage.getHeight(), + pixelFormat, flags); + else { + if (jpegBuf == null) + throw new Exception(NO_ASSOC_ERROR); + decompress(jpegBuf, jpegBufSize, buf, 0, 0, scaledWidth, stride, + scaledHeight, pixelFormat, flags); + } } else { ComponentSampleModel sm = (ComponentSampleModel)dstImage.getSampleModel(); @@ -612,14 +752,15 @@ public class TJDecompressor { int pitch = sm.getScanlineStride(); DataBufferByte db = (DataBufferByte)wr.getDataBuffer(); byte[] buf = db.getData(); - decompress(buf, scaledWidth, pitch, scaledHeight, pixelFormat, flags); + decompress(buf, 0, 0, scaledWidth, pitch, scaledHeight, pixelFormat, + flags); } } /** - * Decompress the JPEG source image associated with this decompressor - * instance and return a BufferedImage instance containing the - * decompressed image. + * Decompress the JPEG source image or decode the YUV source image associated + * with this decompressor instance and return a BufferedImage + * instance containing the decompressed/decoded image. * * @param desiredWidth see * {@link #decompress(byte[], int, int, int, int, int, int, int)} for @@ -629,19 +770,21 @@ public class TJDecompressor { * {@link #decompress(byte[], int, int, int, int, int, int, int)} for * description * - * @param bufferedImageType the image type of the newly-created - * BufferedImage instance (for instance, + * @param bufferedImageType the image type of the BufferedImage + * instance that will be created (for instance, * BufferedImage.TYPE_INT_RGB) * - * @param flags the bitwise OR of one or more of {@link TJ TJ.FLAG_*} + * @param flags the bitwise OR of one or more of + * {@link TJ#FLAG_BOTTOMUP TJ.FLAG_*} * * @return a BufferedImage instance containing the - * decompressed image + * decompressed/decoded image */ public BufferedImage decompress(int desiredWidth, int desiredHeight, int bufferedImageType, int flags) throws Exception { - if (desiredWidth < 0 || desiredHeight < 0 || flags < 0) + if ((yuvImage == null && (desiredWidth < 0 || desiredHeight < 0)) || + flags < 0) throw new Exception("Invalid argument in decompress()"); int scaledWidth = getScaledWidth(desiredWidth, desiredHeight); int scaledHeight = getScaledHeight(desiredWidth, desiredHeight); @@ -696,6 +839,14 @@ public class TJDecompressor { private native void decompressToYUV(byte[] srcBuf, int size, byte[] dstBuf, int desiredWidth, int pad, int desiredheight, int flags) throws Exception; + private native void decodeYUV(byte[] srcBuf, int pad, int subsamp, + byte[] dstBuf, int x, int y, int width, int pitch, int height, + int pixelFormat, int flags) throws Exception; + + private native void decodeYUV(byte[] srcBuf, int pad, int subsamp, + int[] dstBuf, int x, int y, int width, int stride, int height, + int pixelFormat, int flags) throws Exception; + static { TJLoader.load(); } @@ -703,9 +854,10 @@ public class TJDecompressor { protected long handle = 0; protected byte[] jpegBuf = null; protected int jpegBufSize = 0; - protected int jpegWidth = 0; - protected int jpegHeight = 0; - protected int jpegSubsamp = -1; - protected int jpegColorspace = -1; + protected YUVImage yuvImage = null; + protected int srcWidth = 0; + protected int srcHeight = 0; + protected int srcSubsamp = -1; + protected int srcColorspace = -1; private ByteOrder byteOrder = null; }; diff --git a/java/org/libjpegturbo/turbojpeg/TJTransformer.java b/java/org/libjpegturbo/turbojpeg/TJTransformer.java index f84eaa1..ee1f607 100644 --- a/java/org/libjpegturbo/turbojpeg/TJTransformer.java +++ b/java/org/libjpegturbo/turbojpeg/TJTransformer.java @@ -1,5 +1,5 @@ /* - * Copyright (C)2011, 2013 D. R. Commander. All Rights Reserved. + * Copyright (C)2011, 2013-2014 D. R. Commander. All Rights Reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -42,20 +42,20 @@ public class TJTransformer extends TJDecompressor { /** * Create a TurboJPEG lossless transformer instance and associate the JPEG - * image stored in jpegImage with the newly-created instance. + * image stored in jpegImage 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 TJTransformer(byte[] jpegImage) throws Exception { init(); - setJPEGImage(jpegImage, jpegImage.length); + setSourceImage(jpegImage, jpegImage.length); } /** * Create a TurboJPEG lossless transformer instance and associate the JPEG * image of length imageSize bytes stored in - * jpegImage with the newly-created instance. + * jpegImage with the newly created instance. * * @param jpegImage JPEG image buffer * @@ -63,7 +63,7 @@ public class TJTransformer extends TJDecompressor { */ public TJTransformer(byte[] jpegImage, int imageSize) throws Exception { init(); - setJPEGImage(jpegImage, imageSize); + setSourceImage(jpegImage, imageSize); } /** @@ -84,13 +84,14 @@ public class TJTransformer extends TJDecompressor { * receive a JPEG image that has been transformed using the parameters in * transforms[i]. Use {@link TJ#bufSize} to determine the * maximum size for each buffer based on the transformed or cropped width and - * height. + * height and the level of subsampling used in the source image. * * @param transforms an array of {@link TJTransform} instances, each of * which specifies the transform parameters and/or cropping region for the * corresponding transformed output image * - * @param flags the bitwise OR of one or more of {@link TJ TJ.FLAG_*} + * @param flags the bitwise OR of one or more of + * {@link TJ#FLAG_BOTTOMUP TJ.FLAG_*} */ public void transform(byte[][] dstBufs, TJTransform[] transforms, int flags) throws Exception { @@ -112,20 +113,21 @@ public class TJTransformer extends TJDecompressor { * @return an array of {@link TJDecompressor} instances, each of * which has a transformed JPEG image associated with it * - * @param flags the bitwise OR of one or more of {@link TJ TJ.FLAG_*} + * @param flags the bitwise OR of one or more of + * {@link TJ#FLAG_BOTTOMUP TJ.FLAG_*} */ public TJDecompressor[] transform(TJTransform[] transforms, int flags) throws Exception { byte[][] dstBufs = new byte[transforms.length][]; - if (jpegWidth < 1 || jpegHeight < 1) + if (srcWidth < 1 || srcHeight < 1) throw new Exception("JPEG buffer not initialized"); for (int i = 0; i < transforms.length; i++) { - int w = jpegWidth, h = jpegHeight; + int w = srcWidth, h = srcHeight; if ((transforms[i].options & TJTransform.OPT_CROP) != 0) { 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, jpegSubsamp)]; + dstBufs[i] = new byte[TJ.bufSize(w, h, srcSubsamp)]; } TJDecompressor[] tjd = new TJDecompressor[transforms.length]; transform(dstBufs, transforms, flags); @@ -135,11 +137,11 @@ public class TJTransformer extends TJDecompressor { } /** - * Returns an array containing the sizes of the transformed JPEG images from - * the most recent call to {@link #transform transform()}. + * Returns an array containing the sizes of the transformed JPEG images + * generated by the most recent transform operation. * - * @return an array containing the sizes of the transformed JPEG images from - * the most recent call to {@link #transform transform()} + * @return an array containing the sizes of the transformed JPEG images + * generated by the most recent transform operation */ public int[] getTransformedSizes() throws Exception { if (transformedSizes == null) diff --git a/java/org/libjpegturbo/turbojpeg/YUVImage.java b/java/org/libjpegturbo/turbojpeg/YUVImage.java new file mode 100644 index 0000000..6793593 --- /dev/null +++ b/java/org/libjpegturbo/turbojpeg/YUVImage.java @@ -0,0 +1,193 @@ +/* + * Copyright (C)2014 D. R. Commander. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * - Neither the name of the libjpeg-turbo Project nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS", + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +package org.libjpegturbo.turbojpeg; + +/** + * This class encapsulates a YUV planar image buffer and the metadata + * associated with it. The TurboJPEG API allows both the JPEG compression and + * decompression pipelines to be split into stages: YUV encode, compress from + * YUV, decompress to YUV, and YUV decode. A YUVImage instance + * serves as the destination image for YUV encode and decompress-to-YUV + * operations and as the source image for compress-from-YUV and YUV decode + * operations. + *

    + * Technically, the JPEG format uses the YCbCr colorspace (which technically is + * not a "colorspace" but rather a "color transform"), but per the convention + * of the digital video community, the TurboJPEG API uses "YUV" to refer to an + * image format consisting of Y, Cb, and Cr image planes. In this image + * format, the Y, Cb (U), and Cr (V) planes are stored sequentially in the same + * image buffer, and the size of each plane is determined by the image width, + * height, line padding, and level of chrominance subsampling. If the + * chrominance components are subsampled along the horizontal dimension, then + * the width of the luminance plane would be padded to the nearest multiple of + * 2 (same goes for the height of the luminance plane, if the chrominance + * components are subsampled along the vertical dimension.) For instance, if + * the source image is 35 x 35 pixels and 4:2:2 subsampling is used, then the + * luminance plane would be 36 x 35 bytes, and each of the chrominance planes + * would be 18 x 35 bytes. If you specify, for instance, a line padding of 4 + * bytes on top of this, then the luminance plane would be 36 x 35 bytes, and + * each of the chrominance planes would be 20 x 35 bytes. + */ +public class YUVImage { + + private static final String NO_ASSOC_ERROR = + "No YUV buffer is associated with this instance"; + + /** + * Create a YUVImage instance with a new image buffer. + * + * @param width width (in pixels) of the YUV image + * + * @param pad Each line of each plane in the YUV image buffer will be padded + * to this number of bytes (must be a power of 2.) + * + * @param height height (in pixels) of the YUV image + * + * @param subsamp the level of chrominance subsampling to be used in the YUV + * image (one of {@link TJ#SAMP_444 TJ.SAMP_*}) + */ + public YUVImage(int width, int pad, int height, int subsamp) + throws Exception { + setBuffer(new byte[TJ.bufSizeYUV(width, pad, height, subsamp)], width, pad, + height, subsamp); + } + + /** + * Create a YUVImage instance from an existing YUV planar image + * buffer. + * + * @param yuvImage image buffer that contains or will contain YUV planar + * image data. See {@link YUVImage above} for a description of the image + * format. You can use {@link TJ#bufSizeYUV} to determine the appropriate + * size for this buffer. + * + * @param width width (in pixels) of the YUV image + * + * @param pad the line padding used in the YUV image buffer. For + * instance, if each line in each plane of the buffer is padded to the + * nearest multiple of 4 bytes, then pad should be set to 4. + * + * @param height height (in pixels) of the YUV image + * + * @param subsamp the level of chrominance subsampling used in the YUV + * image (one of {@link TJ#SAMP_444 TJ.SAMP_*}) + */ + public YUVImage(byte[] yuvImage, int width, int pad, int height, + int subsamp) throws Exception { + setBuffer(yuvImage, width, pad, height, subsamp); + } + + private void setBuffer(byte[] yuvImage, int width, int pad, int height, + int subsamp) throws Exception { + if (yuvImage == null || width < 1 || pad < 1 || ((pad & (pad - 1)) != 0) || + height < 1 || subsamp < 0 || subsamp >= TJ.NUMSAMP) + throw new Exception("Invalid argument in YUVImage()"); + if (yuvImage.length != TJ.bufSizeYUV(width, pad, height, subsamp)) + throw new Exception("YUV image buffer is the wrong size"); + yuvBuf = yuvImage; + yuvWidth = width; + yuvPad = pad; + yuvHeight = height; + yuvSubsamp = subsamp; + } + + /** + * Returns the width of the YUV image. + * + * @return the width of the YUV image + */ + public int getWidth() throws Exception { + if (yuvWidth < 1) + throw new Exception(NO_ASSOC_ERROR); + return yuvWidth; + } + + /** + * Returns the height of the YUV image. + * + * @return the height of the YUV image + */ + public int getHeight() throws Exception { + if (yuvHeight < 1) + throw new Exception(NO_ASSOC_ERROR); + return yuvHeight; + } + + /** + * Returns the line padding used in the YUV image buffer. + * + * @return the line padding used in the YUV image buffer + */ + public int getPad() throws Exception { + if (yuvPad < 1 || ((yuvPad & (yuvPad - 1)) != 0)) + throw new Exception(NO_ASSOC_ERROR); + return yuvPad; + } + + /** + * Returns the level of chrominance subsampling used in the YUV image. See + * {@link TJ#SAMP_444 TJ.SAMP_*}. + * + * @return the level of chrominance subsampling used in the YUV image + */ + public int getSubsamp() throws Exception { + if (yuvSubsamp < 0 || yuvSubsamp >= TJ.NUMSAMP) + throw new Exception(NO_ASSOC_ERROR); + return yuvSubsamp; + } + + /** + * Returns the YUV image buffer + * + * @return the YUV image buffer + */ + public byte[] getBuf() throws Exception { + if (yuvBuf == null) + throw new Exception(NO_ASSOC_ERROR); + return yuvBuf; + } + + /** + * Returns the size (in bytes) of the YUV image buffer + * + * @return the size (in bytes) of the YUV image buffer + */ + public int getSize() throws Exception { + if (yuvBuf == null) + throw new Exception(NO_ASSOC_ERROR); + return yuvBuf.length; + } + + protected long handle = 0; + protected byte[] yuvBuf = null; + protected int yuvPad = 0; + protected int yuvWidth = 0; + protected int yuvHeight = 0; + protected int yuvSubsamp = -1; +}; diff --git a/java/org_libjpegturbo_turbojpeg_TJCompressor.h b/java/org_libjpegturbo_turbojpeg_TJCompressor.h index 50070ef..edb23b4 100644 --- a/java/org_libjpegturbo_turbojpeg_TJCompressor.h +++ b/java/org_libjpegturbo_turbojpeg_TJCompressor.h @@ -74,10 +74,10 @@ JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJCompressor_encodeYUV___ /* * Class: org_libjpegturbo_turbojpeg_TJCompressor * Method: encodeYUV - * Signature: ([BIIII[BIII)V + * Signature: ([BIIIIII[BIII)V */ -JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJCompressor_encodeYUV___3BIIII_3BIII - (JNIEnv *, jobject, jbyteArray, jint, jint, jint, jint, jbyteArray, jint, jint, jint); +JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJCompressor_encodeYUV___3BIIIIII_3BIII + (JNIEnv *, jobject, jbyteArray, jint, jint, jint, jint, jint, jint, jbyteArray, jint, jint, jint); /* * Class: org_libjpegturbo_turbojpeg_TJCompressor @@ -90,10 +90,10 @@ JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJCompressor_encodeYUV___ /* * Class: org_libjpegturbo_turbojpeg_TJCompressor * Method: encodeYUV - * Signature: ([IIIII[BIII)V + * Signature: ([IIIIIII[BIII)V */ -JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJCompressor_encodeYUV___3IIIII_3BIII - (JNIEnv *, jobject, jintArray, jint, jint, jint, jint, jbyteArray, jint, jint, jint); +JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJCompressor_encodeYUV___3IIIIIII_3BIII + (JNIEnv *, jobject, jintArray, jint, jint, jint, jint, jint, jint, jbyteArray, jint, jint, jint); #ifdef __cplusplus } diff --git a/java/org_libjpegturbo_turbojpeg_TJDecompressor.h b/java/org_libjpegturbo_turbojpeg_TJDecompressor.h index 203f004..1d8205c 100644 --- a/java/org_libjpegturbo_turbojpeg_TJDecompressor.h +++ b/java/org_libjpegturbo_turbojpeg_TJDecompressor.h @@ -79,6 +79,22 @@ JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJDecompressor_decompress JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJDecompressor_decompressToYUV___3BI_3BIIII (JNIEnv *, jobject, jbyteArray, jint, jbyteArray, jint, jint, jint, jint); +/* + * Class: org_libjpegturbo_turbojpeg_TJDecompressor + * Method: decodeYUV + * Signature: ([BII[BIIIIIII)V + */ +JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJDecompressor_decodeYUV___3BII_3BIIIIIII + (JNIEnv *, jobject, jbyteArray, jint, jint, jbyteArray, jint, jint, jint, jint, jint, jint, jint); + +/* + * Class: org_libjpegturbo_turbojpeg_TJDecompressor + * Method: decodeYUV + * Signature: ([BII[IIIIIIII)V + */ +JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJDecompressor_decodeYUV___3BII_3IIIIIIII + (JNIEnv *, jobject, jbyteArray, jint, jint, jintArray, jint, jint, jint, jint, jint, jint, jint); + #ifdef __cplusplus } #endif diff --git a/turbojpeg-jni.c b/turbojpeg-jni.c index efe5590..e796cc1 100644 --- a/turbojpeg-jni.c +++ b/turbojpeg-jni.c @@ -1,5 +1,5 @@ /* - * Copyright (C)2011-2013 D. R. Commander. All Rights Reserved. + * Copyright (C)2011-2014 D. R. Commander. All Rights Reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -250,12 +250,13 @@ JNIEXPORT jint JNICALL Java_org_libjpegturbo_turbojpeg_TJCompressor_compressFrom return (jint)jpegSize; } -JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJCompressor_encodeYUV___3BIIII_3BIII - (JNIEnv *env, jobject obj, jbyteArray src, jint width, jint pitch, - jint height, jint pf, jbyteArray dst, jint pad, jint subsamp, jint flags) +JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJCompressor_encodeYUV___3BIIIIII_3BIII + (JNIEnv *env, jobject obj, jbyteArray src, jint x, jint y, jint width, + jint pitch, jint height, jint pf, jbyteArray dst, jint pad, jint subsamp, + jint flags) { tjhandle handle=0; - jsize arraySize=0, yuvSize; + jsize arraySize=0, actualPitch, yuvSize; unsigned char *srcBuf=NULL, *dstBuf=NULL; gethandle(); @@ -266,7 +267,8 @@ JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJCompressor_encodeYUV___ if(org_libjpegturbo_turbojpeg_TJ_NUMPF!=TJ_NUMPF) _throw("Mismatch between Java and C API"); - arraySize=(pitch==0)? width*tjPixelSize[pf]*height:pitch*height; + actualPitch=(pitch==0)? width*tjPixelSize[pf]:pitch; + arraySize=(y+height-1)*actualPitch + x+width; if((*env)->GetArrayLength(env, src)GetPrimitiveArrayCritical(env, src, 0)); bailif0(dstBuf=(*env)->GetPrimitiveArrayCritical(env, dst, 0)); - if(tjEncodeYUV3(handle, srcBuf, width, pitch, height, pf, dstBuf, pad, - subsamp, flags)==-1) + if(tjEncodeYUV3(handle, &srcBuf[y*actualPitch + x*tjPixelSize[pf]], width, + pitch, height, pf, dstBuf, pad, subsamp, flags)==-1) { (*env)->ReleasePrimitiveArrayCritical(env, dst, dstBuf, 0); (*env)->ReleasePrimitiveArrayCritical(env, src, srcBuf, 0); @@ -297,16 +299,17 @@ JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJCompressor_encodeYUV___ (JNIEnv *env, jobject obj, jbyteArray src, jint width, jint pitch, jint height, jint pf, jbyteArray dst, jint subsamp, jint flags) { - Java_org_libjpegturbo_turbojpeg_TJCompressor_encodeYUV___3BIIII_3BIII( - env, obj, src, width, pitch, height, pf, dst, 4, subsamp, flags); + Java_org_libjpegturbo_turbojpeg_TJCompressor_encodeYUV___3BIIIIII_3BIII( + env, obj, src, 0, 0, width, pitch, height, pf, dst, 4, subsamp, flags); } -JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJCompressor_encodeYUV___3IIIII_3BIII - (JNIEnv *env, jobject obj, jintArray src, jint width, jint stride, - jint height, jint pf, jbyteArray dst, jint pad, jint subsamp, jint flags) +JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJCompressor_encodeYUV___3IIIIIII_3BIII + (JNIEnv *env, jobject obj, jintArray src, jint x, jint y, jint width, + jint stride, jint height, jint pf, jbyteArray dst, jint pad, jint subsamp, + jint flags) { tjhandle handle=0; - jsize arraySize=0, yuvSize; + jsize arraySize=0, actualStride, yuvSize; unsigned char *srcBuf=NULL, *dstBuf=NULL; gethandle(); @@ -319,7 +322,8 @@ JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJCompressor_encodeYUV___ if(tjPixelSize[pf]!=sizeof(jint)) _throw("Pixel format must be 32-bit when encoding from an integer buffer."); - arraySize=(stride==0)? width*height:stride*height; + actualStride=(stride==0)? width:stride; + arraySize=(y+height-1)*actualStride + x+width; if((*env)->GetArrayLength(env, src)GetPrimitiveArrayCritical(env, src, 0)); bailif0(dstBuf=(*env)->GetPrimitiveArrayCritical(env, dst, 0)); - if(tjEncodeYUV3(handle, srcBuf, width, stride*sizeof(jint), height, pf, - dstBuf, pad, subsamp, flags)==-1) + if(tjEncodeYUV3(handle, &srcBuf[(y*actualStride + x)*sizeof(int)], width, + stride*sizeof(jint), height, pf, dstBuf, pad, subsamp, flags)==-1) { (*env)->ReleasePrimitiveArrayCritical(env, dst, dstBuf, 0); (*env)->ReleasePrimitiveArrayCritical(env, src, srcBuf, 0); @@ -350,8 +354,8 @@ JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJCompressor_encodeYUV___ (JNIEnv *env, jobject obj, jintArray src, jint width, jint pitch, jint height, jint pf, jbyteArray dst, jint subsamp, jint flags) { - Java_org_libjpegturbo_turbojpeg_TJCompressor_encodeYUV___3IIIII_3BIII( - env, obj, src, width, pitch, height, pf, dst, 4, subsamp, flags); + Java_org_libjpegturbo_turbojpeg_TJCompressor_encodeYUV___3IIIIIII_3BIII( + env, obj, src, 0, 0, width, pitch, height, pf, dst, 4, subsamp, flags); } JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJCompressor_destroy @@ -435,13 +439,13 @@ JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJDecompressor_decompress } (*env)->ReleasePrimitiveArrayCritical(env, src, jpegBuf, 0); jpegBuf=NULL; - bailif0(_fid=(*env)->GetFieldID(env, _cls, "jpegSubsamp", "I")); + bailif0(_fid=(*env)->GetFieldID(env, _cls, "srcSubsamp", "I")); (*env)->SetIntField(env, obj, _fid, jpegSubsamp); - bailif0(_fid=(*env)->GetFieldID(env, _cls, "jpegColorspace", "I")); + bailif0(_fid=(*env)->GetFieldID(env, _cls, "srcColorspace", "I")); (*env)->SetIntField(env, obj, _fid, jpegColorspace); - bailif0(_fid=(*env)->GetFieldID(env, _cls, "jpegWidth", "I")); + bailif0(_fid=(*env)->GetFieldID(env, _cls, "srcWidth", "I")); (*env)->SetIntField(env, obj, _fid, width); - bailif0(_fid=(*env)->GetFieldID(env, _cls, "jpegHeight", "I")); + bailif0(_fid=(*env)->GetFieldID(env, _cls, "srcHeight", "I")); (*env)->SetIntField(env, obj, _fid, height); bailout: @@ -562,11 +566,11 @@ JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJDecompressor_decompress if((*env)->GetArrayLength(env, src)GetFieldID(env, _cls, "jpegSubsamp", "I")); + bailif0(_fid=(*env)->GetFieldID(env, _cls, "srcSubsamp", "I")); jpegSubsamp=(int)(*env)->GetIntField(env, obj, _fid); - bailif0(_fid=(*env)->GetFieldID(env, _cls, "jpegWidth", "I")); + bailif0(_fid=(*env)->GetFieldID(env, _cls, "srcWidth", "I")); jpegWidth=(int)(*env)->GetIntField(env, obj, _fid); - bailif0(_fid=(*env)->GetFieldID(env, _cls, "jpegHeight", "I")); + bailif0(_fid=(*env)->GetFieldID(env, _cls, "srcHeight", "I")); jpegHeight=(int)(*env)->GetIntField(env, obj, _fid); yuvSize=(jsize)tjBufSizeYUV2(desiredWidth==0? jpegWidth:desiredWidth, @@ -601,6 +605,94 @@ JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJDecompressor_decompress env, obj, src, jpegSize, dst, 0, 4, 0, flags); } +JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJDecompressor_decodeYUV___3BII_3BIIIIIII + (JNIEnv *env, jobject obj, jbyteArray src, jint pad, jint subsamp, + jbyteArray dst, jint x, jint y, jint width, jint pitch, jint height, + jint pf, jint flags) +{ + tjhandle handle=0; + jsize arraySize=0, actualPitch; + unsigned char *srcBuf=NULL, *dstBuf=NULL; + + gethandle(); + + if(pf<0 || pf>=org_libjpegturbo_turbojpeg_TJ_NUMPF) + _throw("Invalid argument in decodeYUV()"); + if(org_libjpegturbo_turbojpeg_TJ_NUMPF!=TJ_NUMPF) + _throw("Mismatch between Java and C API"); + + arraySize=tjBufSizeYUV2(width, pad, height, subsamp); + if((*env)->GetArrayLength(env, src)GetArrayLength(env, dst)GetPrimitiveArrayCritical(env, src, 0)); + bailif0(dstBuf=(*env)->GetPrimitiveArrayCritical(env, dst, 0)); + + if(tjDecodeYUV(handle, srcBuf, pad, subsamp, + &dstBuf[y*actualPitch + x*tjPixelSize[pf]], width, pitch, height, pf, + flags)==-1) + { + (*env)->ReleasePrimitiveArrayCritical(env, dst, dstBuf, 0); + (*env)->ReleasePrimitiveArrayCritical(env, src, srcBuf, 0); + dstBuf=srcBuf=NULL; + _throw(tjGetErrorStr()); + } + + bailout: + if(dstBuf) (*env)->ReleasePrimitiveArrayCritical(env, dst, dstBuf, 0); + if(srcBuf) (*env)->ReleasePrimitiveArrayCritical(env, src, srcBuf, 0); + return; +} + +JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJDecompressor_decodeYUV___3BII_3IIIIIIII + (JNIEnv *env, jobject obj, jbyteArray src, jint pad, jint subsamp, + jintArray dst, jint x, jint y, jint width, jint stride, jint height, + jint pf, jint flags) +{ + tjhandle handle=0; + jsize arraySize=0, actualStride; + unsigned char *srcBuf=NULL, *dstBuf=NULL; + + gethandle(); + + if(pf<0 || pf>=org_libjpegturbo_turbojpeg_TJ_NUMPF) + _throw("Invalid argument in decodeYUV()"); + if(org_libjpegturbo_turbojpeg_TJ_NUMPF!=TJ_NUMPF) + _throw("Mismatch between Java and C API"); + if(tjPixelSize[pf]!=sizeof(jint)) + _throw("Pixel format must be 32-bit when decoding to an integer buffer."); + + arraySize=tjBufSizeYUV2(width, pad, height, subsamp); + if((*env)->GetArrayLength(env, src)GetArrayLength(env, dst)GetPrimitiveArrayCritical(env, src, 0)); + bailif0(dstBuf=(*env)->GetPrimitiveArrayCritical(env, dst, 0)); + + if(tjDecodeYUV(handle, srcBuf, pad, subsamp, + &dstBuf[(y*actualStride + x)*sizeof(int)], width, stride*sizeof(jint), + height, pf, flags)==-1) + { + (*env)->ReleasePrimitiveArrayCritical(env, dst, dstBuf, 0); + (*env)->ReleasePrimitiveArrayCritical(env, src, srcBuf, 0); + dstBuf=srcBuf=NULL; + _throw(tjGetErrorStr()); + } + + bailout: + if(dstBuf) (*env)->ReleasePrimitiveArrayCritical(env, dst, dstBuf, 0); + if(srcBuf) (*env)->ReleasePrimitiveArrayCritical(env, src, srcBuf, 0); + return; +} + JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJTransformer_init (JNIEnv *env, jobject obj) { @@ -698,11 +790,11 @@ JNIEXPORT jintArray JNICALL Java_org_libjpegturbo_turbojpeg_TJTransformer_transf if((*env)->GetArrayLength(env, jsrcBuf)GetFieldID(env, _cls, "jpegWidth", "I")); + bailif0(_fid=(*env)->GetFieldID(env, _cls, "srcWidth", "I")); jpegWidth=(int)(*env)->GetIntField(env, obj, _fid); - bailif0(_fid=(*env)->GetFieldID(env, _cls, "jpegHeight", "I")); + bailif0(_fid=(*env)->GetFieldID(env, _cls, "srcHeight", "I")); jpegHeight=(int)(*env)->GetIntField(env, obj, _fid); - bailif0(_fid=(*env)->GetFieldID(env, _cls, "jpegSubsamp", "I")); + bailif0(_fid=(*env)->GetFieldID(env, _cls, "srcSubsamp", "I")); jpegSubsamp=(int)(*env)->GetIntField(env, obj, _fid); n=(*env)->GetArrayLength(env, dstobjs); diff --git a/turbojpeg-mapfile.jni b/turbojpeg-mapfile.jni index a1be1fd..283e01f 100755 --- a/turbojpeg-mapfile.jni +++ b/turbojpeg-mapfile.jni @@ -74,7 +74,9 @@ TURBOJPEG_1.4 tjEncodeYUV3; Java_org_libjpegturbo_turbojpeg_TJ_bufSizeYUV__IIII; Java_org_libjpegturbo_turbojpeg_TJCompressor_compressFromYUV___3BIIII_3BII; - Java_org_libjpegturbo_turbojpeg_TJCompressor_encodeYUV___3BIIII_3BIII; - Java_org_libjpegturbo_turbojpeg_TJCompressor_encodeYUV___3IIIII_3BIII; + Java_org_libjpegturbo_turbojpeg_TJCompressor_encodeYUV___3BIIIIII_3BIII; + Java_org_libjpegturbo_turbojpeg_TJCompressor_encodeYUV___3IIIIIII_3BIII; Java_org_libjpegturbo_turbojpeg_TJDecompressor_decompressToYUV___3BI_3BIIII; + Java_org_libjpegturbo_turbojpeg_TJDecompressor_decodeYUV___3BII_3BIIIIIII; + Java_org_libjpegturbo_turbojpeg_TJDecompressor_decodeYUV___3BII_3IIIIIIII; } TURBOJPEG_1.3; -- 2.40.0