From: DRC Date: Sun, 28 Apr 2013 01:32:52 +0000 (+0000) Subject: Extend the TurboJPEG Java API to support generating YUV images with arbitrary padding... X-Git-Tag: 1.3.90~234 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=fef9852da3a80bfaf84862462609f97d77ad6db7;p=libjpeg-turbo Extend the TurboJPEG Java API to support generating YUV images with arbitrary padding and to support image scaling when decompressing to YUV git-svn-id: svn+ssh://svn.code.sf.net/p/libjpeg-turbo/code/trunk@975 632fc199-4ca6-4c93-a231-07263d6284db --- diff --git a/CMakeLists.txt b/CMakeLists.txt index ffffebb..495ac2d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -314,8 +314,10 @@ set(MD5_JPEG_CROP b4197f377e621c4e9b1d20471432610d) if(WITH_JAVA) add_test(TJUnitTest ${JAVA_RUNTIME} -cp java/${OBJDIR}turbojpeg.jar -Djava.library.path=${CMAKE_CURRENT_BINARY_DIR}/${OBJDIR} TJUnitTest) add_test(TJUnitTest-yuv ${JAVA_RUNTIME} -cp java/${OBJDIR}turbojpeg.jar -Djava.library.path=${CMAKE_CURRENT_BINARY_DIR}/${OBJDIR} TJUnitTest -yuv) +add_test(TJUnitTest-yuv-nopad ${JAVA_RUNTIME} -cp java/${OBJDIR}turbojpeg.jar -Djava.library.path=${CMAKE_CURRENT_BINARY_DIR}/${OBJDIR} TJUnitTest -yuv -noyuvpad) add_test(TJUnitTest-bi ${JAVA_RUNTIME} -cp java/${OBJDIR}turbojpeg.jar -Djava.library.path=${CMAKE_CURRENT_BINARY_DIR}/${OBJDIR} TJUnitTest -bi) add_test(TJUnitTest-bi-yuv ${JAVA_RUNTIME} -cp java/${OBJDIR}turbojpeg.jar -Djava.library.path=${CMAKE_CURRENT_BINARY_DIR}/${OBJDIR} TJUnitTest -bi -yuv) +add_test(TJUnitTest-bi-yuv-nopad ${JAVA_RUNTIME} -cp java/${OBJDIR}turbojpeg.jar -Djava.library.path=${CMAKE_CURRENT_BINARY_DIR}/${OBJDIR} TJUnitTest -bi -yuv -noyuvpad) endif() add_test(tjunittest tjunittest) add_test(tjunittest-alloc tjunittest -alloc) diff --git a/Makefile.am b/Makefile.am index dab99b4..de6c307 100644 --- a/Makefile.am +++ b/Makefile.am @@ -200,7 +200,9 @@ if WITH_JAVA $(JAVA) -cp java/turbojpeg.jar -Djava.library.path=.libs TJUnitTest $(JAVA) -cp java/turbojpeg.jar -Djava.library.path=.libs TJUnitTest -bi $(JAVA) -cp java/turbojpeg.jar -Djava.library.path=.libs TJUnitTest -yuv + $(JAVA) -cp java/turbojpeg.jar -Djava.library.path=.libs TJUnitTest -yuv -noyuvpad $(JAVA) -cp java/turbojpeg.jar -Djava.library.path=.libs TJUnitTest -yuv -bi + $(JAVA) -cp java/turbojpeg.jar -Djava.library.path=.libs TJUnitTest -yuv -bi -noyuvpad endif ./tjunittest ./tjunittest -alloc diff --git a/java/TJUnitTest.java b/java/TJUnitTest.java index d0a609a..4b1a52d 100644 --- a/java/TJUnitTest.java +++ b/java/TJUnitTest.java @@ -1,5 +1,5 @@ /* - * Copyright (C)2011-2012 D. R. Commander. All Rights Reserved. + * Copyright (C)2011-2013 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: @@ -46,6 +46,8 @@ public class TJUnitTest { System.out.println("\nUSAGE: java " + classname + " [options]\n"); System.out.println("Options:\n"); System.out.println("-yuv = test YUV encoding/decoding support\n"); + System.out.println("-noyuvpad = do not pad each line of each Y, U, and V plane to the nearest\n"); + System.out.println(" 4-byte boundary\n"); System.out.println("-bi = test BufferedImage support\n"); System.exit(1); } @@ -93,6 +95,7 @@ public class TJUnitTest { private static final int YUVENCODE = 1; private static final int YUVDECODE = 2; private static int yuv = 0; + private static int pad = 4; private static boolean bi = false; private static int exitStatus = 0; @@ -472,16 +475,18 @@ public class TJUnitTest { } private static int checkBufYUV(byte[] buf, int size, int w, int h, - int subsamp) throws Exception { + int subsamp, TJScalingFactor sf) + 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, 4), uvpitch = PAD(cw, 4); + int ypitch = PAD(pw, pad), uvpitch = PAD(cw, pad); int retval = 1; int correctsize = ypitch * ph + (subsamp == TJ.SAMP_GRAY ? 0 : uvpitch * ch * 2); - int halfway = 16; + int halfway = 16 * sf.getNum() / sf.getDenom(); + int blockSize = 8 * sf.getNum() / sf.getDenom(); try { if (size != correctsize) @@ -491,7 +496,7 @@ public class TJUnitTest { for (row = 0; row < ph; row++) { for (col = 0; col < pw; col++) { byte y = buf[ypitch * row + col]; - if (((row / 8) + (col / 8)) % 2 == 0) { + if (((row / blockSize) + (col / blockSize)) % 2 == 0) { if (row < halfway) checkVal255(row, col, y, "Y"); else @@ -505,12 +510,12 @@ public class TJUnitTest { } } if (subsamp != TJ.SAMP_GRAY) { - halfway = 16 / vsf; + halfway = 16 / vsf * sf.getNum() / sf.getDenom(); for (row = 0; row < ch; row++) { for (col = 0; col < cw; col++) { byte u = buf[ypitch * ph + (uvpitch * row + col)], v = buf[ypitch * ph + uvpitch * ch + (uvpitch * row + col)]; - if (((row * vsf / 8) + (col * hsf / 8)) % 2 == 0) { + if (((row * vsf / blockSize) + (col * hsf / blockSize)) % 2 == 0) { checkVal(row, col, u, "U", 128); checkVal(row, col, v, "V", 128); } else { @@ -618,6 +623,7 @@ public class TJUnitTest { t = getTime(); tjc.setSubsamp(subsamp); tjc.setJPEGQuality(jpegQual); + tjc.setYUVPad(pad); if (bi) { if (yuv == YUVENCODE) tjc.encodeYUV(img, dstBuf, flags); @@ -644,7 +650,8 @@ public class TJUnitTest { writeJPEG(dstBuf, size, tempstr); if (yuv == YUVENCODE) { - if (checkBufYUV(dstBuf, size, w, h, subsamp) == 1) + if (checkBufYUV(dstBuf, size, w, h, subsamp, + new TJScalingFactor(1, 1)) == 1) System.out.print("Passed."); else { System.out.print("FAILED!"); @@ -680,7 +687,7 @@ public class TJUnitTest { System.out.print("JPEG -> "); if (yuv == YUVDECODE) - System.out.print("YUV " + subName[subsamp] + " ... "); + System.out.print("YUV " + subNameLong[subsamp] + " "); else { System.out.print(pfStr + " "); if (bi) @@ -689,11 +696,11 @@ public class TJUnitTest { System.out.print("Bottom-Up "); else System.out.print("Top-Down "); - if (!sf.isOne()) - System.out.print(sf.getNum() + "/" + sf.getDenom() + " ... "); - else - System.out.print("... "); } + if (!sf.isOne()) + System.out.print(sf.getNum() + "/" + sf.getDenom() + " ... "); + else + System.out.print("... "); t = getTime(); tjd.setJPEGImage(jpegBuf, jpegSize); @@ -709,7 +716,7 @@ public class TJUnitTest { throw new Exception("Scaled size mismatch"); if (yuv == YUVDECODE) - dstBuf = tjd.decompressToYUV(flags); + dstBuf = tjd.decompressToYUV(scaledWidth, pad, scaledHeight, flags); else { if (bi) img = tjd.decompress(scaledWidth, scaledHeight, imgType, flags); @@ -728,7 +735,8 @@ public class TJUnitTest { } if (yuv == YUVDECODE) { - if (checkBufYUV(dstBuf, dstBuf.length, w, h, subsamp) == 1) + if (checkBufYUV(dstBuf, dstBuf.length, scaledWidth, scaledHeight, + subsamp, sf) == 1) System.out.print("Passed."); else { System.out.print("FAILED!"); exitStatus = -1; @@ -752,7 +760,7 @@ public class TJUnitTest { String baseName, int subsamp, int flags) throws Exception { int i; - if ((subsamp == TJ.SAMP_444 || subsamp == TJ.SAMP_GRAY) && yuv == 0) { + if (subsamp == TJ.SAMP_444 || subsamp == TJ.SAMP_GRAY) { TJScalingFactor[] sf = TJ.getScalingFactors(); for (i = 0; i < sf.length; i++) decompTest(tjd, jpegBuf, jpegSize, w, h, pf, baseName, subsamp, @@ -771,7 +779,7 @@ public class TJUnitTest { byte[] dstBuf; if (yuv == YUVENCODE) - dstBuf = new byte[TJ.bufSizeYUV(w, h, subsamp)]; + dstBuf = new byte[TJ.bufSizeYUV(w, pad, h, subsamp)]; else dstBuf = new byte[TJ.bufSize(w, h, subsamp)]; @@ -860,6 +868,8 @@ public class TJUnitTest { for (int i = 0; i < argv.length; i++) { if (argv[i].equalsIgnoreCase("-yuv")) doyuv = true; + if (argv[i].equalsIgnoreCase("-noyuvpad")) + pad = 1; if (argv[i].substring(0, 1).equalsIgnoreCase("-h") || argv[i].equalsIgnoreCase("-?")) usage(); diff --git a/java/doc/allclasses-frame.html b/java/doc/allclasses-frame.html index c02463d..3ee3e6f 100644 --- a/java/doc/allclasses-frame.html +++ b/java/doc/allclasses-frame.html @@ -2,12 +2,12 @@ - + All Classes - + diff --git a/java/doc/allclasses-noframe.html b/java/doc/allclasses-noframe.html index 1f134aa..249acfb 100644 --- a/java/doc/allclasses-noframe.html +++ b/java/doc/allclasses-noframe.html @@ -2,12 +2,12 @@ - + All Classes - + diff --git a/java/doc/constant-values.html b/java/doc/constant-values.html index 5c6ab69..3978d19 100644 --- a/java/doc/constant-values.html +++ b/java/doc/constant-values.html @@ -2,12 +2,12 @@ - + Constant Field Values - + diff --git a/java/doc/deprecated-list.html b/java/doc/deprecated-list.html index a19b026..9a73159 100644 --- a/java/doc/deprecated-list.html +++ b/java/doc/deprecated-list.html @@ -2,12 +2,12 @@ - + Deprecated List - + @@ -93,12 +93,28 @@ function windowTitle() Deprecated Methods +org.libjpegturbo.turbojpeg.TJ.bufSizeYUV(int, int, int) +
+          Use TJ.bufSizeYUV(int, int, int, int) instead.  + + org.libjpegturbo.turbojpeg.TJDecompressor.decompress(byte[], int, int, int, int, int)
          Use TJDecompressor.decompress(byte[], int, int, int, int, int, int, int) instead.  +org.libjpegturbo.turbojpeg.TJDecompressor.decompressToYUV(byte[], int) +
+          Use TJDecompressor.decompressToYUV(byte[], int, int, int, int) + instead.  + + +org.libjpegturbo.turbojpeg.TJDecompressor.decompressToYUV(int) +
+          Use TJDecompressor.decompressToYUV(int, int, int, int) instead.  + + org.libjpegturbo.turbojpeg.TJCompressor.setSourceImage(byte[], int, int, int, int)
          Use diff --git a/java/doc/help-doc.html b/java/doc/help-doc.html index 7fb7c44..ebffee0 100644 --- a/java/doc/help-doc.html +++ b/java/doc/help-doc.html @@ -2,12 +2,12 @@ - + API Help - + diff --git a/java/doc/index-all.html b/java/doc/index-all.html index 36435a7..820876f 100644 --- a/java/doc/index-all.html +++ b/java/doc/index-all.html @@ -2,12 +2,12 @@ - + Index - + @@ -84,10 +84,13 @@ function windowTitle() Static method in class org.libjpegturbo.turbojpeg.TJ
Returns the maximum size of the buffer (in bytes) required to hold a JPEG image with the given width, height, and level of chrominance subsampling. -
bufSizeYUV(int, int, int) - +
bufSizeYUV(int, int, int, int) - Static method in class org.libjpegturbo.turbojpeg.TJ
Returns the size of the buffer (in bytes) required to hold a YUV planar image with the given width, height, and level of chrominance subsampling. +
bufSizeYUV(int, int, int) - +Static method in class org.libjpegturbo.turbojpeg.TJ +
Deprecated. Use TJ.bufSizeYUV(int, int, int, int) instead.

@@ -154,14 +157,21 @@ Method in class org.libjpegturbo.turbojpeg.decompressToYUV(byte[], int) - +
decompressToYUV(byte[], int, int, int, 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. -
decompressToYUV(int) - +
decompressToYUV(byte[], int) - +Method in class org.libjpegturbo.turbojpeg.TJDecompressor +
Deprecated. Use TJDecompressor.decompressToYUV(byte[], int, int, int, 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. +
decompressToYUV(int) - +Method in class org.libjpegturbo.turbojpeg.TJDecompressor +
Deprecated. Use TJDecompressor.decompressToYUV(int, int, int, int) instead.

@@ -490,6 +500,9 @@ 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.

diff --git a/java/doc/index.html b/java/doc/index.html index f187a87..d555848 100644 --- a/java/doc/index.html +++ b/java/doc/index.html @@ -2,7 +2,7 @@ - + Generated Documentation (Untitled) diff --git a/java/doc/org/libjpegturbo/turbojpeg/TJ.html b/java/doc/org/libjpegturbo/turbojpeg/TJ.html index 2a11b78..3103cd4 100644 --- a/java/doc/org/libjpegturbo/turbojpeg/TJ.html +++ b/java/doc/org/libjpegturbo/turbojpeg/TJ.html @@ -2,12 +2,12 @@ - + TJ - + @@ -374,6 +374,17 @@ TurboJPEG utility class (cannot be instantiated) int height, int subsamp) +
+          Deprecated. Use bufSizeYUV(int, int, int, int) instead. + + + +static int +bufSizeYUV(int width, + int pad, + int height, + int subsamp) +
          Returns the size of the buffer (in bytes) required to hold a YUV planar image with the given width, height, and level of chrominance subsampling. @@ -992,10 +1003,11 @@ public static int bufSize(int width,
-

+

bufSizeYUV

 public static int bufSizeYUV(int width,
+                             int pad,
                              int height,
                              int subsamp)
                       throws java.lang.Exception
@@ -1004,7 +1016,9 @@ public static int bufSizeYUV(int width, image with the given width, height, and level of chrominance subsampling.

-
Parameters:
width - the width (in pixels) of the YUV image
height - the height (in pixels) of the YUV image
subsamp - the level of chrominance subsampling used in the YUV +
Parameters:
width - the width (in pixels) of the YUV image
pad - the width of each line in each plane of the image is padded to + the nearest multiple of this number of bytes (must be a power of + 2.)
height - the height (in pixels) of the YUV image
subsamp - the level of chrominance subsampling used in the YUV image (one of TJ.SAMP_*)
Returns:
the size of the buffer (in bytes) required to hold a YUV planar image with the given width, height, and level of chrominance subsampling @@ -1014,6 +1028,25 @@ public static int bufSizeYUV(int width,

+

+bufSizeYUV

+
+@Deprecated
+public static int bufSizeYUV(int width,
+                                        int height,
+                                        int subsamp)
+                      throws java.lang.Exception
+
+
Deprecated. Use bufSizeYUV(int, int, int, int) instead. +

+

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

getScalingFactors

diff --git a/java/doc/org/libjpegturbo/turbojpeg/TJCompressor.html b/java/doc/org/libjpegturbo/turbojpeg/TJCompressor.html
index 871d9bc..ee829c8 100644
--- a/java/doc/org/libjpegturbo/turbojpeg/TJCompressor.html
+++ b/java/doc/org/libjpegturbo/turbojpeg/TJCompressor.html
@@ -2,12 +2,12 @@
 
 
 
-
+
 
 TJCompressor
 
 
-
+
 
 
 
@@ -306,6 +306,14 @@ 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. +   @@ -437,11 +445,12 @@ public void setSourceImage(byte[] srcImage,

setSourceImage

-public void setSourceImage(byte[] srcImage,
-                           int width,
-                           int pitch,
-                           int height,
-                           int pixelFormat)
+@Deprecated
+public void setSourceImage(byte[] srcImage,
+                                      int width,
+                                      int pitch,
+                                      int height,
+                                      int pixelFormat)
                     throws java.lang.Exception
Deprecated. Use @@ -572,6 +581,25 @@ public byte[] compress(java.awt.image.BufferedImage srcImage,

+

+setYUVPad

+
+public void setYUVPad(int pad)
+               throws java.lang.Exception
+
+
Set the plane padding for subsequent YUV encode operations. +

+

+
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. +
Throws: +
java.lang.Exception
+
+
+
+

encodeYUV

@@ -581,21 +609,20 @@ public void encodeYUV(byte[] dstBuf,
 
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 to produce a planar YUV image that is - suitable for direct video display. Specifically, 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.) - Also, each line of each plane in the output image is padded to 4 bytes. - Although this will work with any subsampling option, it is really only - useful in combination with TJ.SAMP_420, which produces an image - compatible with the I420 (AKA "YUV420P") format. + 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, and V 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.)

Parameters:
dstBuf - buffer that will receive the YUV planar image. Use - TJ.bufSizeYUV(int, int, int) to determine the appropriate size for this buffer + 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_*
Throws:
java.lang.Exception
@@ -637,7 +664,7 @@ public void encodeYUV(java.awt.image.BufferedImage srcImage,
Parameters:
srcImage - a BufferedImage instance containing RGB or grayscale pixels to be encoded
dstBuf - buffer that will receive the YUV planar image. Use - TJ.bufSizeYUV(int, int, int) to determine the appropriate size for this buffer + 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_*
Throws:
java.lang.Exception
diff --git a/java/doc/org/libjpegturbo/turbojpeg/TJCustomFilter.html b/java/doc/org/libjpegturbo/turbojpeg/TJCustomFilter.html index c91978d..350d636 100644 --- a/java/doc/org/libjpegturbo/turbojpeg/TJCustomFilter.html +++ b/java/doc/org/libjpegturbo/turbojpeg/TJCustomFilter.html @@ -2,12 +2,12 @@ - + TJCustomFilter - + diff --git a/java/doc/org/libjpegturbo/turbojpeg/TJDecompressor.html b/java/doc/org/libjpegturbo/turbojpeg/TJDecompressor.html index d7c6495..013c054 100644 --- a/java/doc/org/libjpegturbo/turbojpeg/TJDecompressor.html +++ b/java/doc/org/libjpegturbo/turbojpeg/TJDecompressor.html @@ -2,12 +2,12 @@ - + TJDecompressor - + @@ -304,6 +304,19 @@ TurboJPEG decompressor
+ + + + @@ -313,6 +326,17 @@ TurboJPEG decompressor  byte[] + + + + @@ -779,12 +803,13 @@ public void decompress(byte[] dstBuf,

decompress

-public void decompress(byte[] dstBuf,
-                       int desiredWidth,
-                       int pitch,
-                       int desiredHeight,
-                       int pixelFormat,
-                       int flags)
+@Deprecated
+public void decompress(byte[] dstBuf,
+                                  int desiredWidth,
+                                  int pitch,
+                                  int desiredHeight,
+                                  int pixelFormat,
+                                  int flags)
                 throws java.lang.Exception
Deprecated. Use @@ -827,10 +852,13 @@ public byte[] decompress(int desiredWidth,

-

+

decompressToYUV

 public void decompressToYUV(byte[] dstBuf,
+                            int desiredWidth,
+                            int pad,
+                            int desiredHeight,
                             int flags)
                      throws java.lang.Exception
@@ -846,25 +874,63 @@ public void decompressToYUV(byte[] dstBuf,

Parameters:
dstBuf - buffer that will receive the YUV planar image. Use - TJ.bufSizeYUV(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_* + 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_*
Throws:
java.lang.Exception

-

+

decompressToYUV

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

+

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

+decompressToYUV

+
+public byte[] 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) for more detail. + instance and return a buffer containing a YUV planar image. See decompressToYUV(byte[], int, int, int, int) for more detail.

-
Parameters:
flags - the bitwise OR of one or more of TJ.FLAG_* +
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
Throws:
java.lang.Exception
@@ -872,6 +938,23 @@ public byte[] decompressToYUV(int flags)

+

+decompressToYUV

+
+@Deprecated
+public byte[] decompressToYUV(int flags)
+                       throws java.lang.Exception
+
+
Deprecated. Use decompressToYUV(int, int, int, int) instead. +

+

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

decompress

diff --git a/java/doc/org/libjpegturbo/turbojpeg/TJScalingFactor.html b/java/doc/org/libjpegturbo/turbojpeg/TJScalingFactor.html
index 9262c49..8badc52 100644
--- a/java/doc/org/libjpegturbo/turbojpeg/TJScalingFactor.html
+++ b/java/doc/org/libjpegturbo/turbojpeg/TJScalingFactor.html
@@ -2,12 +2,12 @@
 
 
 
-
+
 
 TJScalingFactor
 
 
-
+
 
 
 
diff --git a/java/doc/org/libjpegturbo/turbojpeg/TJTransform.html b/java/doc/org/libjpegturbo/turbojpeg/TJTransform.html
index 5a31980..7e9f660 100644
--- a/java/doc/org/libjpegturbo/turbojpeg/TJTransform.html
+++ b/java/doc/org/libjpegturbo/turbojpeg/TJTransform.html
@@ -2,12 +2,12 @@
 
 
 
-
+
 
 TJTransform
 
 
-
+
 
 
 
diff --git a/java/doc/org/libjpegturbo/turbojpeg/TJTransformer.html b/java/doc/org/libjpegturbo/turbojpeg/TJTransformer.html
index dfef713..c597fa7 100644
--- a/java/doc/org/libjpegturbo/turbojpeg/TJTransformer.html
+++ b/java/doc/org/libjpegturbo/turbojpeg/TJTransformer.html
@@ -2,12 +2,12 @@
 
 
 
-
+
 
 TJTransformer
 
 
-
+
 
 
 
@@ -205,7 +205,7 @@ TurboJPEG lossless transformer
 
- +
decompressToYUV(byte[] dstBuf, int flags) +
+          Deprecated. Use decompressToYUV(byte[], int, int, int, int) + instead.
+ voiddecompressToYUV(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.
decompressToYUV(int flags) +
+          Deprecated. Use decompressToYUV(int, int, int, int) instead.
+ byte[]decompressToYUV(int desiredWidth, + int pad, + int desiredHeight, + int flags) +
          Decompress the JPEG source image associated with this decompressor instance and return a buffer containing a YUV planar image.
Methods inherited from class org.libjpegturbo.turbojpeg.TJDecompressor
close, decompress, decompress, decompress, decompress, decompress, decompress, decompressToYUV, decompressToYUV, finalize, getHeight, getJPEGBuf, getJPEGSize, getScaledHeight, getScaledWidth, getSubsamp, getWidth, setJPEGImageclose, decompress, decompress, decompress, decompress, decompress, decompress, decompressToYUV, decompressToYUV, decompressToYUV, decompressToYUV, finalize, getHeight, getJPEGBuf, getJPEGSize, getScaledHeight, getScaledWidth, getSubsamp, getWidth, setJPEGImage
  diff --git a/java/doc/org/libjpegturbo/turbojpeg/package-frame.html b/java/doc/org/libjpegturbo/turbojpeg/package-frame.html index 7286078..035d330 100644 --- a/java/doc/org/libjpegturbo/turbojpeg/package-frame.html +++ b/java/doc/org/libjpegturbo/turbojpeg/package-frame.html @@ -2,12 +2,12 @@ - + org.libjpegturbo.turbojpeg - + diff --git a/java/doc/org/libjpegturbo/turbojpeg/package-summary.html b/java/doc/org/libjpegturbo/turbojpeg/package-summary.html index bafbf52..7a16142 100644 --- a/java/doc/org/libjpegturbo/turbojpeg/package-summary.html +++ b/java/doc/org/libjpegturbo/turbojpeg/package-summary.html @@ -2,12 +2,12 @@ - + org.libjpegturbo.turbojpeg - + diff --git a/java/doc/org/libjpegturbo/turbojpeg/package-tree.html b/java/doc/org/libjpegturbo/turbojpeg/package-tree.html index 40eb910..9066835 100644 --- a/java/doc/org/libjpegturbo/turbojpeg/package-tree.html +++ b/java/doc/org/libjpegturbo/turbojpeg/package-tree.html @@ -2,12 +2,12 @@ - + org.libjpegturbo.turbojpeg Class Hierarchy - + diff --git a/java/doc/overview-tree.html b/java/doc/overview-tree.html index 93c07d3..dd01dd9 100644 --- a/java/doc/overview-tree.html +++ b/java/doc/overview-tree.html @@ -2,12 +2,12 @@ - + Class Hierarchy - + diff --git a/java/doc/serialized-form.html b/java/doc/serialized-form.html index d6162a9..bc8b1bb 100644 --- a/java/doc/serialized-form.html +++ b/java/doc/serialized-form.html @@ -2,12 +2,12 @@ - + Serialized Form - + diff --git a/java/org/libjpegturbo/turbojpeg/TJ.java b/java/org/libjpegturbo/turbojpeg/TJ.java index 9f7c682..eb9f027 100644 --- a/java/org/libjpegturbo/turbojpeg/TJ.java +++ b/java/org/libjpegturbo/turbojpeg/TJ.java @@ -342,6 +342,10 @@ public final class TJ { * * @param width the width (in pixels) of the YUV image * + * @param pad the width of each line in each plane of the image is padded to + * the nearest multiple of this number of bytes (must be a power of + * 2.) + * * @param height the height (in pixels) of the YUV image * * @param subsamp the level of chrominance subsampling used in the YUV @@ -350,6 +354,14 @@ public final class TJ { * @return the size of the buffer (in bytes) required to hold a YUV planar * image with the given width, height, and level of chrominance subsampling */ + public static native int bufSizeYUV(int width, int pad, int height, + int subsamp) + throws Exception; + + /** + * @deprecated Use {@link #bufSizeYUV(int, int, int, int)} instead. + */ + @Deprecated public static native int bufSizeYUV(int width, int height, int subsamp) throws Exception; diff --git a/java/org/libjpegturbo/turbojpeg/TJCompressor.java b/java/org/libjpegturbo/turbojpeg/TJCompressor.java index f8f82ac..18fa192 100644 --- a/java/org/libjpegturbo/turbojpeg/TJCompressor.java +++ b/java/org/libjpegturbo/turbojpeg/TJCompressor.java @@ -145,6 +145,7 @@ public class TJCompressor { * @deprecated Use * {@link #setSourceImage(byte[], int, int, int, int, int, int)} instead. */ + @Deprecated public void setSourceImage(byte[] srcImage, int width, int pitch, int height, int pixelFormat) throws Exception { setSourceImage(srcImage, 0, 0, width, pitch, height, pixelFormat); @@ -330,20 +331,34 @@ public class TJCompressor { return buf; } + + /** + * 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 to produce a planar YUV image that is - * suitable for direct video display. Specifically, 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.) - * Also, each line of each plane in the output image is padded to 4 bytes. - * Although this will work with any subsampling option, it is really only - * useful in combination with {@link TJ#SAMP_420}, which produces an image - * compatible with the I420 (AKA "YUV420P") format. + * 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, and V 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.) * * @param dstBuf buffer that will receive the YUV planar image. Use * {@link TJ#bufSizeYUV} to determine the appropriate size for this buffer @@ -358,9 +373,9 @@ public class TJCompressor { throw new Exception(NO_ASSOC_ERROR); if (subsamp < 0) throw new Exception("Subsampling level not set"); - encodeYUV(srcBuf, srcWidth, srcPitch, srcHeight, - srcPixelFormat, dstBuf, subsamp, flags); - compressedSize = TJ.bufSizeYUV(srcWidth, srcHeight, subsamp); + encodeYUV(srcBuf, srcWidth, srcPitch, srcHeight, srcPixelFormat, dstBuf, + yuvPad, subsamp, flags); + compressedSize = TJ.bufSizeYUV(srcWidth, yuvPad, srcHeight, subsamp); } /** @@ -377,7 +392,7 @@ public class TJCompressor { throw new Exception(NO_ASSOC_ERROR); if (subsamp < 0) throw new Exception("Subsampling level not set"); - byte[] buf = new byte[TJ.bufSizeYUV(srcWidth, srcHeight, subsamp)]; + byte[] buf = new byte[TJ.bufSizeYUV(srcWidth, yuvPad, srcHeight, subsamp)]; encodeYUV(buf, flags); return buf; } @@ -438,8 +453,8 @@ public class TJCompressor { int stride = sm.getScanlineStride(); DataBufferInt db = (DataBufferInt)wr.getDataBuffer(); int[] buf = db.getData(); - encodeYUV(buf, width, stride, height, pixelFormat, dstBuf, subsamp, - flags); + encodeYUV(buf, width, stride, height, pixelFormat, dstBuf, yuvPad, + subsamp, flags); } else { ComponentSampleModel sm = (ComponentSampleModel)srcImage.getSampleModel(); @@ -449,10 +464,10 @@ public class TJCompressor { int pitch = sm.getScanlineStride(); DataBufferByte db = (DataBufferByte)wr.getDataBuffer(); byte[] buf = db.getData(); - encodeYUV(buf, width, pitch, height, pixelFormat, dstBuf, subsamp, - flags); + encodeYUV(buf, width, pitch, height, pixelFormat, dstBuf, yuvPad, + subsamp, flags); } - compressedSize = TJ.bufSizeYUV(width, height, subsamp); + compressedSize = TJ.bufSizeYUV(width, yuvPad, height, subsamp); } /** @@ -472,7 +487,7 @@ public class TJCompressor { throw new Exception("Subsampling level not set"); int width = srcImage.getWidth(); int height = srcImage.getHeight(); - byte[] buf = new byte[TJ.bufSizeYUV(width, height, subsamp)]; + byte[] buf = new byte[TJ.bufSizeYUV(width, yuvPad, height, subsamp)]; encodeYUV(srcImage, buf, flags); return buf; } @@ -527,11 +542,19 @@ public class TJCompressor { private native void encodeYUV(byte[] srcBuf, int width, int pitch, int height, int pixelFormat, byte[] dstBuf, int subsamp, int flags) - throws Exception; + 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(int[] srcBuf, int width, int stride, int height, int pixelFormat, byte[] dstBuf, int subsamp, int flags) - throws Exception; + 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; static { TJLoader.load(); @@ -548,5 +571,6 @@ public class TJCompressor { private int subsamp = -1; private int jpegQuality = -1; private int compressedSize = 0; + private int yuvPad = 4; private ByteOrder byteOrder = null; }; diff --git a/java/org/libjpegturbo/turbojpeg/TJDecompressor.java b/java/org/libjpegturbo/turbojpeg/TJDecompressor.java index c2d361e..eb8d31c 100644 --- a/java/org/libjpegturbo/turbojpeg/TJDecompressor.java +++ b/java/org/libjpegturbo/turbojpeg/TJDecompressor.java @@ -313,6 +313,7 @@ public class TJDecompressor { * @deprecated Use * {@link #decompress(byte[], int, int, int, int, int, int, int)} instead. */ + @Deprecated public void decompress(byte[] dstBuf, int desiredWidth, int pitch, int desiredHeight, int pixelFormat, int flags) throws Exception { @@ -373,38 +374,90 @@ public class TJDecompressor { * {@link TJ#bufSizeYUV} to determine the appropriate size for this buffer * based on the image width, height, and level of chrominance subsampling. * + * @param 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.) + * + * @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 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.) + * * @param flags the bitwise OR of one or more of {@link TJ TJ.FLAG_*} */ - public void decompressToYUV(byte[] dstBuf, int flags) throws Exception { + 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 || flags < 0) + 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, flags); + 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)} for more detail. + * #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 TJ.FLAG_*} * * @return a buffer containing a YUV planar image */ - public byte[] decompressToYUV(int flags) throws Exception { + public byte[] 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) throw new Exception(NO_ASSOC_ERROR); if (jpegSubsamp >= TJ.NUMSAMP) throw new Exception("JPEG header information is invalid"); - byte[] buf = new byte[TJ.bufSizeYUV(jpegWidth, jpegHeight, jpegSubsamp)]; - decompressToYUV(buf, flags); + 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; } + /** + * @deprecated Use {@link #decompressToYUV(int, int, int, int)} instead. + */ + @Deprecated + public byte[] decompressToYUV(int flags) throws Exception { + return decompressToYUV(0, 4, 0, flags); + } + /** * Decompress the JPEG source image associated with this decompressor * instance and output a decompressed image to the given destination buffer. @@ -619,7 +672,10 @@ public class TJDecompressor { int flags) throws Exception; private native void decompressToYUV(byte[] srcBuf, int size, byte[] dstBuf, - int flags) throws Exception; + int flags) throws Exception; // deprecated + + private native void decompressToYUV(byte[] srcBuf, int size, byte[] dstBuf, + int desiredWidth, int pad, int desiredheight, int flags) throws Exception; static { TJLoader.load(); diff --git a/java/org_libjpegturbo_turbojpeg_TJ.h b/java/org_libjpegturbo_turbojpeg_TJ.h index d7b032a..cec69e4 100644 --- a/java/org_libjpegturbo_turbojpeg_TJ.h +++ b/java/org_libjpegturbo_turbojpeg_TJ.h @@ -67,12 +67,20 @@ extern "C" { JNIEXPORT jint JNICALL Java_org_libjpegturbo_turbojpeg_TJ_bufSize (JNIEnv *, jclass, jint, jint, jint); +/* + * Class: org_libjpegturbo_turbojpeg_TJ + * Method: bufSizeYUV + * Signature: (IIII)I + */ +JNIEXPORT jint JNICALL Java_org_libjpegturbo_turbojpeg_TJ_bufSizeYUV__IIII + (JNIEnv *, jclass, jint, jint, jint, jint); + /* * Class: org_libjpegturbo_turbojpeg_TJ * Method: bufSizeYUV * Signature: (III)I */ -JNIEXPORT jint JNICALL Java_org_libjpegturbo_turbojpeg_TJ_bufSizeYUV +JNIEXPORT jint JNICALL Java_org_libjpegturbo_turbojpeg_TJ_bufSizeYUV__III (JNIEnv *, jclass, jint, jint, jint); /* diff --git a/java/org_libjpegturbo_turbojpeg_TJCompressor.h b/java/org_libjpegturbo_turbojpeg_TJCompressor.h index 2fc9136..afec077 100644 --- a/java/org_libjpegturbo_turbojpeg_TJCompressor.h +++ b/java/org_libjpegturbo_turbojpeg_TJCompressor.h @@ -63,6 +63,14 @@ JNIEXPORT jint JNICALL Java_org_libjpegturbo_turbojpeg_TJCompressor_compress___3 JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJCompressor_encodeYUV___3BIIII_3BII (JNIEnv *, jobject, jbyteArray, jint, jint, jint, jint, jbyteArray, jint, jint); +/* + * Class: org_libjpegturbo_turbojpeg_TJCompressor + * Method: encodeYUV + * Signature: ([BIIII[BIII)V + */ +JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJCompressor_encodeYUV___3BIIII_3BIII + (JNIEnv *, jobject, jbyteArray, jint, jint, jint, jint, jbyteArray, jint, jint, jint); + /* * Class: org_libjpegturbo_turbojpeg_TJCompressor * Method: encodeYUV @@ -71,6 +79,14 @@ JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJCompressor_encodeYUV___ JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJCompressor_encodeYUV___3IIIII_3BII (JNIEnv *, jobject, jintArray, jint, jint, jint, jint, jbyteArray, jint, jint); +/* + * Class: org_libjpegturbo_turbojpeg_TJCompressor + * Method: encodeYUV + * Signature: ([IIIII[BIII)V + */ +JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJCompressor_encodeYUV___3IIIII_3BIII + (JNIEnv *, jobject, jintArray, jint, jint, jint, jint, jbyteArray, jint, jint, jint); + #ifdef __cplusplus } #endif diff --git a/java/org_libjpegturbo_turbojpeg_TJDecompressor.h b/java/org_libjpegturbo_turbojpeg_TJDecompressor.h index f798a77..203f004 100644 --- a/java/org_libjpegturbo_turbojpeg_TJDecompressor.h +++ b/java/org_libjpegturbo_turbojpeg_TJDecompressor.h @@ -68,9 +68,17 @@ JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJDecompressor_decompress * Method: decompressToYUV * Signature: ([BI[BI)V */ -JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJDecompressor_decompressToYUV +JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJDecompressor_decompressToYUV___3BI_3BI (JNIEnv *, jobject, jbyteArray, jint, jbyteArray, jint); +/* + * Class: org_libjpegturbo_turbojpeg_TJDecompressor + * Method: decompressToYUV + * Signature: ([BI[BIIII)V + */ +JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJDecompressor_decompressToYUV___3BI_3BIIII + (JNIEnv *, jobject, jbyteArray, jint, jbyteArray, jint, jint, jint, jint); + #ifdef __cplusplus } #endif diff --git a/tjunittest.c b/tjunittest.c index a1e6f33..7a44b94 100644 --- a/tjunittest.c +++ b/tjunittest.c @@ -48,7 +48,7 @@ void usage(char *progName) printf("Options:\n"); printf("-yuv = test YUV encoding/decoding support\n"); printf("-noyuvpad = do not pad each line of each Y, U, and V plane to the nearest\n"); - printf(" 4-byte boundary.\n"); + printf(" 4-byte boundary\n"); printf("-alloc = test automatic buffer allocation\n"); exit(1); } diff --git a/turbojpeg-jni.c b/turbojpeg-jni.c index 634bedf..174558e 100644 --- a/turbojpeg-jni.c +++ b/turbojpeg-jni.c @@ -67,16 +67,23 @@ JNIEXPORT jint JNICALL Java_org_libjpegturbo_turbojpeg_TJ_bufSize return retval; } -JNIEXPORT jint JNICALL Java_org_libjpegturbo_turbojpeg_TJ_bufSizeYUV - (JNIEnv *env, jclass cls, jint width, jint height, jint subsamp) +JNIEXPORT jint JNICALL Java_org_libjpegturbo_turbojpeg_TJ_bufSizeYUV__IIII + (JNIEnv *env, jclass cls, jint width, jint pad, jint height, jint subsamp) { - jint retval=(jint)tjBufSizeYUV(width, height, subsamp); + jint retval=(jint)tjBufSizeYUV2(width, pad, height, subsamp); if(retval==-1) _throw(tjGetErrorStr()); bailout: return retval; } +JNIEXPORT jint JNICALL Java_org_libjpegturbo_turbojpeg_TJ_bufSizeYUV__III + (JNIEnv *env, jclass cls, jint width, jint height, jint subsamp) +{ + return Java_org_libjpegturbo_turbojpeg_TJ_bufSizeYUV__IIII(env, cls, width, + 4, height, subsamp); +} + JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJCompressor_init (JNIEnv *env, jobject obj) { @@ -207,12 +214,12 @@ JNIEXPORT jint JNICALL Java_org_libjpegturbo_turbojpeg_TJCompressor_compress___3 flags); } -JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJCompressor_encodeYUV___3BIIII_3BII +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 subsamp, jint flags) + jint height, jint pf, jbyteArray dst, jint pad, jint subsamp, jint flags) { tjhandle handle=0; - jsize arraySize=0; + jsize arraySize=0, yuvSize; unsigned char *srcBuf=NULL, *dstBuf=NULL; gethandle(); @@ -226,15 +233,17 @@ JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJCompressor_encodeYUV___ arraySize=(pitch==0)? width*tjPixelSize[pf]*height:pitch*height; if((*env)->GetArrayLength(env, src)GetArrayLength(env, dst) - <(jsize)tjBufSizeYUV(width, height, subsamp)) + yuvSize=(jsize)tjBufSizeYUV2(width, pad, height, subsamp); + if(yuvSize==(unsigned long)-1) + _throw(tjGetErrorStr()); + if((*env)->GetArrayLength(env, dst)GetPrimitiveArrayCritical(env, src, 0)); bailif0(dstBuf=(*env)->GetPrimitiveArrayCritical(env, dst, 0)); - if(tjEncodeYUV2(handle, srcBuf, width, pitch, height, pf, dstBuf, subsamp, - flags)==-1) + if(tjEncodeYUV3(handle, srcBuf, width, pitch, height, pf, dstBuf, pad, + subsamp, flags)==-1) { (*env)->ReleasePrimitiveArrayCritical(env, dst, dstBuf, 0); (*env)->ReleasePrimitiveArrayCritical(env, src, srcBuf, 0); @@ -248,12 +257,20 @@ JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJCompressor_encodeYUV___ return; } -JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJCompressor_encodeYUV___3IIIII_3BII - (JNIEnv *env, jobject obj, jintArray src, jint width, jint stride, +JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJCompressor_encodeYUV___3BIIII_3BII + (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); +} + +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) { tjhandle handle=0; - jsize arraySize=0; + jsize arraySize=0, yuvSize; unsigned char *srcBuf=NULL, *dstBuf=NULL; gethandle(); @@ -269,15 +286,17 @@ JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJCompressor_encodeYUV___ arraySize=(stride==0)? width*height:stride*height; if((*env)->GetArrayLength(env, src)GetArrayLength(env, dst) - <(jsize)tjBufSizeYUV(width, height, subsamp)) + yuvSize=(jsize)tjBufSizeYUV2(width, pad, height, subsamp); + if(yuvSize==(unsigned long)-1) + _throw(tjGetErrorStr()); + if((*env)->GetArrayLength(env, dst)GetPrimitiveArrayCritical(env, src, 0)); bailif0(dstBuf=(*env)->GetPrimitiveArrayCritical(env, dst, 0)); - if(tjEncodeYUV2(handle, srcBuf, width, stride*sizeof(jint), height, pf, - dstBuf, subsamp, flags)==-1) + if(tjEncodeYUV3(handle, srcBuf, width, stride*sizeof(jint), height, pf, + dstBuf, pad, subsamp, flags)==-1) { (*env)->ReleasePrimitiveArrayCritical(env, dst, dstBuf, 0); (*env)->ReleasePrimitiveArrayCritical(env, src, srcBuf, 0); @@ -291,6 +310,14 @@ JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJCompressor_encodeYUV___ return; } +JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJCompressor_encodeYUV___3IIIII_3BII + (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); +} + JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJCompressor_destroy (JNIEnv *env, jobject obj) { @@ -484,13 +511,14 @@ JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJDecompressor_decompress } -JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJDecompressor_decompressToYUV +JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJDecompressor_decompressToYUV___3BI_3BIIII (JNIEnv *env, jobject obj, jbyteArray src, jint jpegSize, jbyteArray dst, - jint flags) + jint desiredWidth, jint pad, jint desiredHeight, jint flags) { tjhandle handle=0; unsigned char *jpegBuf=NULL, *dstBuf=NULL; int jpegSubsamp=-1, jpegWidth=0, jpegHeight=0; + jsize yuvSize; gethandle(); @@ -502,15 +530,18 @@ JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJDecompressor_decompress jpegWidth=(int)(*env)->GetIntField(env, obj, _fid); bailif0(_fid=(*env)->GetFieldID(env, _cls, "jpegHeight", "I")); jpegHeight=(int)(*env)->GetIntField(env, obj, _fid); - if((*env)->GetArrayLength(env, dst) - <(jsize)tjBufSizeYUV(jpegWidth, jpegHeight, jpegSubsamp)) - _throw("Destination buffer is not large enough"); + yuvSize=(jsize)tjBufSizeYUV2(desiredWidth==0? jpegWidth:desiredWidth, + pad, desiredHeight==0? jpegHeight:desiredHeight, jpegSubsamp); + if(yuvSize==(unsigned long)-1) + _throw(tjGetErrorStr()); + if((*env)->GetArrayLength(env, dst)GetPrimitiveArrayCritical(env, src, 0)); bailif0(dstBuf=(*env)->GetPrimitiveArrayCritical(env, dst, 0)); - if(tjDecompressToYUV(handle, jpegBuf, (unsigned long)jpegSize, dstBuf, - flags)==-1) + if(tjDecompressToYUV2(handle, jpegBuf, (unsigned long)jpegSize, dstBuf, + desiredWidth, pad, desiredHeight, flags)==-1) { (*env)->ReleasePrimitiveArrayCritical(env, dst, dstBuf, 0); (*env)->ReleasePrimitiveArrayCritical(env, src, jpegBuf, 0); @@ -524,6 +555,14 @@ JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJDecompressor_decompress return; } +JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJDecompressor_decompressToYUV___3BI_3BI + (JNIEnv *env, jobject obj, jbyteArray src, jint jpegSize, jbyteArray dst, + jint flags) +{ + Java_org_libjpegturbo_turbojpeg_TJDecompressor_decompressToYUV___3BI_3BIIII( + env, obj, src, jpegSize, dst, 0, 4, 0, flags); +} + JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJTransformer_init (JNIEnv *env, jobject obj) { diff --git a/turbojpeg-mapfile.jni b/turbojpeg-mapfile.jni index ca39c9e..5ca59b4 100755 --- a/turbojpeg-mapfile.jni +++ b/turbojpeg-mapfile.jni @@ -36,7 +36,7 @@ TURBOJPEG_1.2 tjInitTransform; tjTransform; Java_org_libjpegturbo_turbojpeg_TJ_bufSize; - Java_org_libjpegturbo_turbojpeg_TJ_bufSizeYUV; + Java_org_libjpegturbo_turbojpeg_TJ_bufSizeYUV__III; Java_org_libjpegturbo_turbojpeg_TJ_getScalingFactors; Java_org_libjpegturbo_turbojpeg_TJCompressor_init; Java_org_libjpegturbo_turbojpeg_TJCompressor_compress___3BIIII_3BIII; @@ -48,7 +48,7 @@ TURBOJPEG_1.2 Java_org_libjpegturbo_turbojpeg_TJDecompressor_decompressHeader; Java_org_libjpegturbo_turbojpeg_TJDecompressor_decompress___3BI_3BIIIII; Java_org_libjpegturbo_turbojpeg_TJDecompressor_decompress___3BI_3IIIIII; - Java_org_libjpegturbo_turbojpeg_TJDecompressor_decompressToYUV; + Java_org_libjpegturbo_turbojpeg_TJDecompressor_decompressToYUV___3BI_3BI; Java_org_libjpegturbo_turbojpeg_TJDecompressor_destroy; Java_org_libjpegturbo_turbojpeg_TJTransformer_init; Java_org_libjpegturbo_turbojpeg_TJTransformer_transform; @@ -62,3 +62,15 @@ TURBOJPEG_1.3 Java_org_libjpegturbo_turbojpeg_TJDecompressor_decompress___3BI_3BIIIIIII; Java_org_libjpegturbo_turbojpeg_TJDecompressor_decompress___3BI_3IIIIIIII; } TURBOJPEG_1.2; + +TURBOJPEG_1.4 +{ + global: + tjBufSizeYUV2; + tjDecompressToYUV2; + tjEncodeYUV3; + Java_org_libjpegturbo_turbojpeg_TJ_bufSizeYUV__IIII; + Java_org_libjpegturbo_turbojpeg_TJCompressor_encodeYUV___3BIIII_3BIII; + Java_org_libjpegturbo_turbojpeg_TJCompressor_encodeYUV___3IIIII_3BIII; + Java_org_libjpegturbo_turbojpeg_TJDecompressor_decompressToYUV___3BI_3BIIII; +} TURBOJPEG_1.3;