diff --git a/BUILDING.txt b/BUILDING.txt index 318cc233..038c1c18 100644 --- a/BUILDING.txt +++ b/BUILDING.txt @@ -50,12 +50,12 @@ Build Requirements is suggested that you install Apple GCC v4.2 through MacPorts. -- If building the MozJPEG Java wrapper, JDK or OpenJDK 1.5 or later is - required. Some systems, such as OS X 10.4, Solaris 10 and later, and Red - Hat Enterprise Linux 5 and later, have this pre-installed. On OS X 10.5 and - later, it will be necessary to install the Java Developer Package, which can - be downloaded from http://developer.apple.com/downloads (Apple ID required.) - For systems that do not have a JDK installed, you can obtain the Oracle Java - Development Kit from http://www.java.com. + required. Some systems, such as Solaris 10 and later and Red Hat Enterprise + Linux 5 and later, have this pre-installed. On OS X 10.5 and later, it will + be necessary to install the Java Developer Package, which can be downloaded + from http://developer.apple.com/downloads (Apple ID required.) For systems + that do not have a JDK installed, you can obtain the Oracle Java Development + Kit from http://www.java.com. ================== @@ -243,12 +243,12 @@ to the configure command line. Add --host x86_64-apple-darwin NASM=/opt/local/bin/nasm \ - CFLAGS='-isysroot /Developer/SDKs/MacOSX10.4u.sdk \ - -mmacosx-version-min=10.4 -O3' \ - LDFLAGS='-isysroot /Developer/SDKs/MacOSX10.4u.sdk \ - -mmacosx-version-min=10.4' + CFLAGS='-isysroot /Developer/SDKs/MacOSX10.5.sdk \ + -mmacosx-version-min=10.5 -O3' \ + LDFLAGS='-isysroot /Developer/SDKs/MacOSX10.5.sdk \ + -mmacosx-version-min=10.5' -to the configure command line. The OS X 10.4 SDK, and NASM 2.07 or later from +to the configure command line. The OS X 10.5 SDK, and NASM 2.07 or later from MacPorts, must be installed. @@ -258,12 +258,12 @@ MacPorts, must be installed. Add --host i686-apple-darwin \ - CFLAGS='-isysroot /Developer/SDKs/MacOSX10.4u.sdk \ - -mmacosx-version-min=10.4 -O3 -m32' \ - LDFLAGS='-isysroot /Developer/SDKs/MacOSX10.4u.sdk \ - -mmacosx-version-min=10.4 -m32' + CFLAGS='-isysroot /Developer/SDKs/MacOSX10.5.sdk \ + -mmacosx-version-min=10.5 -O3 -m32' \ + LDFLAGS='-isysroot /Developer/SDKs/MacOSX10.5.sdk \ + -mmacosx-version-min=10.5 -m32' -to the configure command line. The OS X 10.4 SDK must be installed. +to the configure command line. The OS X 10.5 SDK must be installed. 64-bit Library Build on 64-bit Solaris @@ -333,31 +333,40 @@ examples accordingly. Additional build requirements: - gas-preprocessor.pl (https://github.com/yuvi/gas-preprocessor) should be - installed in your PATH. + gas-preprocessor.pl + (https://sourceforge.net/p/libjpeg-turbo/code/HEAD/tree/gas-preprocessor) + should be installed in your PATH. Set the following shell variables for simplicity: - Xcode 3.2.x / iOS 4.3 SDK: - IOS_PLATFORMDIR="/Developer/Platforms/iPhoneOS.platform" - IOS_SYSROOT="$IOS_PLATFORMDIR/Developer/SDKs/iPhoneOS4.3.sdk" - IOS_GCC="$IOS_PLATFORMDIR/Developer/usr/bin/arm-apple-darwin10-llvm-gcc-4.2" + Xcode 4.2 and earlier: + IOS_PLATFORMDIR=/Developer/Platforms/iPhoneOS.platform + Xcode 4.3 and later: + IOS_PLATFORMDIR=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform - Xcode 4.5.x / iOS 6.0 SDK: - IOS_PLATFORMDIR="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform" - IOS_SYSROOT="$IOS_PLATFORMDIR/Developer/SDKs/iPhoneOS6.0.sdk" - IOS_GCC="$IOS_PLATFORMDIR/Developer/usr/bin/arm-apple-darwin10-llvm-gcc-4.2" + IOS_SYSROOT=$IOS_PLATFORMDIR/Developer/SDKs/iPhoneOS*.sdk + + Xcode 4.6.x and earlier: + IOS_GCC=$IOS_PLATFORMDIR/Developer/usr/bin/arm-apple-darwin10-llvm-gcc-4.2 + Xcode 5.0.x and later: + IOS_GCC=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang ARM v6 only (up to and including iPhone 3G): [NOTE: Requires Xcode 4.4.x or earlier] IOS_CFLAGS="-march=armv6 -mcpu=arm1176jzf-s -mfpu=vfp" ARM v7 only (iPhone 3GS-4S, iPad 1st-3rd Generation): + Xcode 4.6.x and earlier: IOS_CFLAGS="-march=armv7 -mcpu=cortex-a8 -mtune=cortex-a8 -mfpu=neon" + Xcode 5.0.x and later: + IOS_CFLAGS="-arch armv7" ARM v7s only (iPhone 5, iPad 4th Generation): [NOTE: Requires Xcode 4.5 or later] + Xcode 4.6.x and earlier: IOS_CFLAGS="-march=armv7s -mcpu=swift -mtune=swift -mfpu=neon" + Xcode 5.0.x and later: + IOS_CFLAGS="-arch armv7s" Follow the procedure under "Building libmozjpeg" above, adding @@ -366,8 +375,16 @@ Follow the procedure under "Building libmozjpeg" above, adding CFLAGS="-mfloat-abi=softfp -isysroot $IOS_SYSROOT -O3 $IOS_CFLAGS" \ LDFLAGS="-mfloat-abi=softfp -isysroot $IOS_SYSROOT $IOS_CFLAGS" +to the configure command line. If using Xcode 5.0.x or later, also add + + CCASFLAGS="-no-integrated-as $IOS_CFLAGS" + to the configure command line. +NOTE: You can also add -miphoneos-version-min={version} to $IOS_CFLAGS above +in order to support older versions of iOS than the default version supported by +the SDK. + Once built, lipo can be used to combine the ARM v6, v7, and/or v7s variants into a universal library. @@ -695,11 +712,11 @@ make deb make dmg - Create Macintosh package/disk image. This requires the PackageMaker - application, which must be installed in /Developer/Applications/Utilities. - Note that PackageMaker is not included in recent releases of Xcode, but it - can be obtained by downloading the "Auxiliary Tools for Xcode" package from - http://developer.apple.com/downloads. + Create Macintosh package/disk image. This requires pkgbuild and + productbuild, which are installed by default on OS X 10.7 and later and which + can be obtained by installing Xcode 3.2.6 (with the "Unix Development" + option) on OS X 10.6. Packages built in this manner can be installed on OS X + 10.5 and later, but they must be built on OS X 10.6 or later. make udmg [BUILDDIR32={32-bit build directory}] diff --git a/CMakeLists.txt b/CMakeLists.txt index 6ec8e9a3..44f6a8bc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,8 @@ # Setup # -cmake_minimum_required(VERSION 2.6) +cmake_minimum_required(VERSION 2.8.8) +cmake_policy(SET CMP0022 OLD) project(libmozjpeg C) set(VERSION 2.0.1) diff --git a/ChangeLog.txt b/ChangeLog.txt index f44e0bb5..36e8a5b6 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,27 +1,52 @@ 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. +[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 +successfully decompressed by libjpeg-turbo without additional work on the part +of the application. An application can still override the Huffman tables, for +instance to re-use tables from a previous frame of the same video. -[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. +[4] The Mac packaging system now uses pkgbuild and productbuild rather than +PackageMaker (which is obsolete and no longer supported.) This means that +OS X 10.6 "Snow Leopard" or later must be used when packaging libjpeg-turbo, +although the packages produced can be installed on OS X 10.5 "Leopard" or +later. OS X 10.4 "Tiger" is no longer supported. -[5] The TurboJPEG API can now be used to compress JPEG images from YUV planar -source images. +[5] The Huffman encoder now uses clz and bsr instructions for bit counting on +ARM platforms rather than a lookup table. This reduces the memory footprint +by 64k, which may be important for some mobile applications. Out of four +Android devices that were tested, two demonstrated a small loss (~3-4% on +average) with ARMv6 code and a small gain (also ~3-4%) with ARMv7 code when +enabling this new feature, but the other two devices demonstrated a +significant performance gain across the board (~10-20%.) Actual mileage may +vary. 1.3.1 @@ -48,6 +73,20 @@ omitted at compile time". [4] Fixed a couple of issues whereby malformed JPEG images would cause libjpeg-turbo to use uninitialized memory during decompression. +[5] Fixed an error ("Buffer passed to JPEG library is too small") that occurred +when calling the TurboJPEG YUV encoding function with a very small (< 5x5) +source image, and added a unit test to check for this error. + +[6] The Java classes should now build properly under Visual Studio 2010 and +later. + +[7] Fixed an issue that prevented SRPMs generated using the in-tree packaging +tools from being rebuilt on certain newer Linux distributions. + +[8] Numerous minor fixes to eliminate compilation and build/packaging system +warnings, fix cosmetic issues, improve documentation clarity, and other general +source cleanup. + 1.3.0 ===== diff --git a/Makefile.am b/Makefile.am index e7ca0b74..63d0fc92 100644 --- a/Makefile.am +++ b/Makefile.am @@ -162,7 +162,7 @@ dist_example_DATA = example.c EXTRA_DIST = win release $(DOCS) testimages CMakeLists.txt \ sharedlib/CMakeLists.txt cmakescripts libjpeg.map.in doc doxygen.config \ - jccolext.c jdcolext.c jdmrgext.c + jccolext.c jdcolext.c jdmrgext.c jstdhuff.c dist-hook: rm -rf `find $(distdir) -name .svn` @@ -335,8 +335,10 @@ testclean: tjtest: sh ./tjbenchtest + sh ./tjbenchtest -yuv if WITH_JAVA sh ./tjbenchtest.java + sh ./tjbenchtest.java -yuv endif diff --git a/README-turbo.txt b/README-turbo.txt index b81299f1..24e86ed2 100755 --- a/README-turbo.txt +++ b/README-turbo.txt @@ -81,131 +81,6 @@ JPEG images: There is no significant performance advantage to either API when both are used to perform similar operations. -====================== -Installation Directory -====================== - -This document assumes that libjpeg-turbo will be installed in the default -directory (/opt/libjpeg-turbo on Un*x and Mac systems and -c:\libjpeg-turbo[-gcc][64] on Windows systems. If your installation of -libjpeg-turbo resides in a different directory, then adjust the instructions -accordingly. - -============================= -Replacing libjpeg at Run Time -============================= - -Un*x ----- - -If a Un*x application is dynamically linked with libjpeg, then you can replace -libjpeg with libjpeg-turbo at run time by manipulating LD_LIBRARY_PATH. -For instance: - - [Using libjpeg] - > time cjpeg vgl_5674_0098.jpg - real 0m0.392s - user 0m0.074s - sys 0m0.020s - - [Using libjpeg-turbo] - > export LD_LIBRARY_PATH=/opt/libjpeg-turbo/{lib}:$LD_LIBRARY_PATH - > time cjpeg vgl_5674_0098.jpg - real 0m0.109s - user 0m0.029s - sys 0m0.010s - -({lib} = lib32 or lib64, depending on whether you wish to use the 32-bit or the -64-bit version of libjpeg-turbo.) - -System administrators can also replace the libjpeg symlinks in /usr/lib* with -links to the libjpeg-turbo dynamic library located in /opt/libjpeg-turbo/{lib}. -This will effectively accelerate every application that uses the libjpeg -dynamic library on the system. - -Windows -------- - -If a Windows application is dynamically linked with libjpeg, then you can -replace libjpeg with libjpeg-turbo at run time by backing up the application's -copy of jpeg62.dll, jpeg7.dll, or jpeg8.dll (assuming the application has its -own local copy of this library) and copying the corresponding DLL from -libjpeg-turbo into the application's install directory. The official -libjpeg-turbo binary packages only provide jpeg62.dll. If the application uses -jpeg7.dll or jpeg8.dll instead, then it will be necessary to build -libjpeg-turbo from source (see "libjpeg v7 and v8 API/ABI Emulation" below.) - -The following information is specific to the official libjpeg-turbo binary -packages for Visual C++: - --- jpeg62.dll requires the Visual C++ 2008 C run-time DLL (msvcr90.dll). -msvcr90.dll ships with more recent versions of Windows, but users of older -Windows releases can obtain it from the Visual C++ 2008 Redistributable -Package, which is available as a free download from Microsoft's web site. - --- Features of the libjpeg API that require passing a C run-time structure, -such as a file handle, from an application to the library will probably not -work with jpeg62.dll, unless the application is also built to use the Visual -C++ 2008 C run-time DLL. In particular, this affects jpeg_stdio_dest() and -jpeg_stdio_src(). - -Mac ---- - -Mac applications typically embed their own copies of the libjpeg dylib inside -the (hidden) application bundle, so it is not possible to globally replace -libjpeg on OS X systems. Replacing the application's version of the libjpeg -dylib would generally involve copying libjpeg.*.dylib from libjpeg-turbo into -the appropriate place in the application bundle and using install_name_tool to -repoint the libjpeg-turbo dylib to its new directory. This requires an -advanced knowledge of OS X and would not survive an upgrade or a re-install of -the application. Thus, it is not recommended for most users. - -======================================== -Using libjpeg-turbo in Your Own Programs -======================================== - -For the most part, libjpeg-turbo should work identically to libjpeg, so in -most cases, an application can be built against libjpeg and then run against -libjpeg-turbo. On Un*x systems and Cygwin, you can build against libjpeg-turbo -instead of libjpeg by setting - - CPATH=/opt/libjpeg-turbo/include - and - LIBRARY_PATH=/opt/libjpeg-turbo/{lib} - -({lib} = lib32 or lib64, depending on whether you are building a 32-bit or a -64-bit application.) - -If using MinGW, then set - - CPATH=/c/libjpeg-turbo-gcc[64]/include - and - LIBRARY_PATH=/c/libjpeg-turbo-gcc[64]/lib - -Building against libjpeg-turbo is useful, for instance, if you want to build an -application that leverages the libjpeg-turbo colorspace extensions (see below.) -On Un*x systems, you would still need to manipulate LD_LIBRARY_PATH or create -appropriate symlinks to use libjpeg-turbo at run time. On such systems, you -can pass -R /opt/libjpeg-turbo/{lib} to the linker to force the use of -libjpeg-turbo at run time rather than libjpeg (also useful if you want to -leverage the colorspace extensions), or you can link against the libjpeg-turbo -static library. - -To force a Un*x or MinGW application to link against the static version of -libjpeg-turbo, you can use the following linker options: - - -Wl,-Bstatic -ljpeg -Wl,-Bdynamic - -On OS X, simply add /opt/libjpeg-turbo/lib/libjpeg.a to the linker command -line. - -To build Visual C++ applications using libjpeg-turbo, add -c:\libjpeg-turbo[64]\include to the system or user INCLUDE environment -variable and c:\libjpeg-turbo[64]\lib to the system or user LIB environment -variable, and then link against either jpeg.lib (to use the DLL version of -libjpeg-turbo) or jpeg-static.lib (to use the static version of libjpeg-turbo.) - ===================== Colorspace Extensions ===================== @@ -265,7 +140,7 @@ compression and decompression structures. Unfortunately, due to the exposed nature of those structures, extending them also necessitated breaking backward ABI compatibility with previous libjpeg releases. Thus, programs that were built to use libjpeg v7 or v8 did not work with libjpeg-turbo, since it is -based on the libjpeg v6b code base. Although libjpeg v7 and v8 are still not +based on the libjpeg v6b code base. Although libjpeg v7 and v8 are not as widely used as v6b, enough programs (including a few Linux distros) made the switch that there was a demand to emulate the libjpeg v7 and v8 ABIs in libjpeg-turbo. It should be noted, however, that this feature was added diff --git a/acinclude.m4 b/acinclude.m4 index 978a469b..40a9e52f 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -210,3 +210,36 @@ AC_DEFUN([AC_CHECK_COMPATIBLE_MIPSEL_ASSEMBLER_IFELSE],[ $2 fi ]) + +AC_DEFUN([AC_CHECK_COMPATIBLE_ARM64_ASSEMBLER_IFELSE],[ + ac_good_gnu_arm_assembler=no + ac_save_CC="$CC" + ac_save_CFLAGS="$CFLAGS" + CFLAGS="$CCASFLAGS -x assembler-with-cpp" + CC="$CCAS" + AC_COMPILE_IFELSE([AC_LANG_SOURCE([[ + .text + movi v0.16b, #100]])], ac_good_gnu_arm_assembler=yes) + + ac_use_gas_preprocessor=no + if test "x$ac_good_gnu_arm_assembler" = "xno" ; then + CC="gas-preprocessor.pl $CCAS" + AC_COMPILE_IFELSE([AC_LANG_SOURCE([[ + .text + movi v0.16b, #100]])], ac_use_gas_preprocessor=yes) + fi + CFLAGS="$ac_save_CFLAGS" + CC="$ac_save_CC" + + if test "x$ac_use_gas_preprocessor" = "xyes" ; then + CCAS="gas-preprocessor.pl $CCAS" + AC_SUBST([CCAS]) + ac_good_gnu_arm_assembler=yes + fi + + if test "x$ac_good_gnu_arm_assembler" = "xyes" ; then + $1 + else + $2 + fi +]) diff --git a/bmp.c b/bmp.c index 4caefb41..fa4479da 100644 --- a/bmp.c +++ b/bmp.c @@ -169,7 +169,7 @@ int loadbmp(char *filename, unsigned char **buf, int *w, int *h, nlines); } cinfo.next_scanline+=nlines; - } + } (*src->finish_input)(&cinfo, src); @@ -236,7 +236,7 @@ int savebmp(char *filename, unsigned char *buf, int w, int h, int srcpf, _throw("savebmp(): Could not initialize PPM writer"); } - dst->output_file=file; + dst->output_file=file; (*dst->start_output)(&dinfo, dst); (*dinfo.mem->realize_virt_arrays)((j_common_ptr)&dinfo); @@ -258,7 +258,7 @@ int savebmp(char *filename, unsigned char *buf, int w, int h, int srcpf, } (*dst->put_pixel_rows)(&dinfo, dst, nlines); dinfo.output_scanline+=nlines; - } + } (*dst->finish_output)(&dinfo, dst); diff --git a/configure.ac b/configure.ac index b637a169..2ab3c8d2 100644 --- a/configure.ac +++ b/configure.ac @@ -17,8 +17,9 @@ SAVED_CFLAGS=${CFLAGS} SAVED_CPPFLAGS=${CPPFLAGS} AC_PROG_CPP AC_PROG_CC -AM_PROG_CC_C_O +m4_ifdef([AM_PROG_AR], [AM_PROG_AR]) AM_PROG_AS +AM_PROG_CC_C_O AC_PROG_INSTALL m4_ifdef([AM_PROG_AR], [AM_PROG_AR]) AC_PROG_LIBTOOL @@ -434,7 +435,23 @@ if test "x${with_simd}" != "xno"; then AC_MSG_ERROR([SIMD support can't be enabled.]) else AC_MSG_WARN([SIMD support can't be enabled. Performance will suffer.]) + fi fi + ;; + aarch64*) + AC_MSG_RESULT([yes (arm64)]) + AC_MSG_CHECKING([if the assembler is GNU-compatible and can be used]) + AC_CHECK_COMPATIBLE_ARM64_ASSEMBLER_IFELSE( + [AC_MSG_RESULT([yes]) + simd_arch=aarch64], + [AC_MSG_RESULT([no]) + with_simd=no]) + if test "x${with_simd}" = "xno"; then + if test "x${require_simd}" = "xyes"; then + AC_MSG_ERROR([SIMD support can't be enabled.]) + else + AC_MSG_WARN([SIMD support can't be enabled. Performance will suffer.]) + fi fi ;; mipsel*) @@ -476,6 +493,7 @@ AM_CONDITIONAL([WITH_SSE_FLOAT_DCT], [test "x$simd_arch" = "xx86_64" -o "x$simd_ AM_CONDITIONAL([SIMD_I386], [test "x$simd_arch" = "xi386"]) AM_CONDITIONAL([SIMD_X86_64], [test "x$simd_arch" = "xx86_64"]) AM_CONDITIONAL([SIMD_ARM], [test "x$simd_arch" = "xarm"]) +AM_CONDITIONAL([SIMD_ARM_64], [test "x$simd_arch" = "xaarch64"]) AM_CONDITIONAL([SIMD_MIPSEL], [test "x$simd_arch" = "xmipsel"]) AM_CONDITIONAL([X86_64], [test "x$host_cpu" = "xx86_64" -o "x$host_cpu" = "xamd64"]) AM_CONDITIONAL([WITH_TURBOJPEG], [test "x$with_turbojpeg" != "xno"]) @@ -513,8 +531,6 @@ AC_CONFIG_FILES([pkgscripts/libmozjpeg.spec.tmpl:release/libmozjpeg.spec.in]) AC_CONFIG_FILES([pkgscripts/makecygwinpkg.tmpl:release/makecygwinpkg.in]) AC_CONFIG_FILES([pkgscripts/makedpkg.tmpl:release/makedpkg.in]) AC_CONFIG_FILES([pkgscripts/makemacpkg.tmpl:release/makemacpkg.in]) -AC_CONFIG_FILES([pkgscripts/Description.plist:release/Description.plist.in]) -AC_CONFIG_FILES([pkgscripts/Info.plist:release/Info.plist.in]) AC_CONFIG_FILES([pkgscripts/uninstall.tmpl:release/uninstall.in]) if test "x$with_turbojpeg" != "xno"; then AC_CONFIG_FILES([tjbenchtest]) diff --git a/doc/html/group___turbo_j_p_e_g.html b/doc/html/group___turbo_j_p_e_g.html index 2c3395b7..6936e5df 100644 --- a/doc/html/group___turbo_j_p_e_g.html +++ b/doc/html/group___turbo_j_p_e_g.html @@ -255,6 +255,9 @@ Functions DLLEXPORT int DLLCALL tjDecompressToYUV2 (tjhandle handle, unsigned char *jpegBuf, unsigned long jpegSize, unsigned char *dstBuf, int width, int pad, int height, int flags)  Decompress a JPEG image to a YUV planar image. More...
  +DLLEXPORT int DLLCALL tjDecodeYUV (tjhandle handle, unsigned char *srcBuf, int pad, int subsamp, unsigned char *dstBuf, int width, int pitch, int height, int pixelFormat, int flags) + Decode a YUV planar image into an RGB or grayscale image. More...
+  DLLEXPORT tjhandle DLLCALL tjInitTransform (void)  Create a new TurboJPEG transformer instance. More...
  @@ -1064,6 +1067,7 @@ If you choose option 1, *jpegSize should be set to the size of your

Compress a YUV planar image into a JPEG image.

+

Note that, if the width or height of the YUV image is not an even multiple of the MCU block size (see tjMCUWidth and tjMCUHeight), then an intermediate buffer copy will be performed within TurboJPEG.

Parameters
@@ -1086,6 +1090,100 @@ If you choose option 1, *jpegSize should be set to the size of your
Returns
0 if successful, or -1 if an error occurred (see tjGetErrorStr().)
+ + + +
+
+
handlea handle to a TurboJPEG compressor or transformer instance
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
DLLEXPORT int DLLCALL tjDecodeYUV (tjhandle handle,
unsigned char * srcBuf,
int pad,
int subsamp,
unsigned char * dstBuf,
int width,
int pitch,
int height,
int pixelFormat,
int flags 
)
+
+ +

Decode a YUV planar image into an RGB or grayscale image.

+

This function uses the accelerated color conversion routines in the underlying codec but does not execute any of the other steps in the JPEG decompression process. The Y, U (Cb), and V (Cr) image planes should be stored sequentially in the source 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 should be padded to the nearest multiple of 2 in the input 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.

+
Parameters
+ + + + + + + + + + + +
handlea handle to a TurboJPEG decompressor or transformer instance
srcBufpointer to an image buffer containing a YUV planar image to be decoded. The size of this buffer should match the value returned by tjBufSizeYUV2() for the given image width, height, padding, and level of chrominance subsampling.
padUse this parameter to specify that the width of each line in each plane of the YUV source image is padded to the nearest multiple of this number of bytes (must be a power of 2.)
subsampthe level of chrominance subsampling used in the YUV source image (see Chrominance subsampling options.)
dstBufpointer to an image buffer that will receive the decoded image. This buffer should normally be pitch * height bytes in size, but the dstBuf pointer can also be used to decode into a specific region of a larger buffer.
widthwidth (in pixels) of the source and destination images
pitchbytes per line of the destination image. Normally, this should be width * tjPixelSize[pixelFormat] if the destination image is unpadded, or TJPAD(width * tjPixelSize[pixelFormat]) if each line of the destination image should be padded to the nearest 32-bit boundary, as is the case for Windows bitmaps. You can also be clever and use the pitch parameter to skip lines, etc. Setting this parameter to 0 is the equivalent of setting it to width * tjPixelSize[pixelFormat].
heightheight (in pixels) of the source and destination images
pixelFormatpixel format of the destination image (see Pixel formats.)
flagsthe bitwise OR of one or more of the flags.
+
+
+
Returns
0 if successful, or -1 if an error occurred (see tjGetErrorStr().)
+
@@ -1422,7 +1520,7 @@ If you choose option 1, *jpegSize should be set to the size of your

Encode an RGB or grayscale image into a YUV planar image.

-

This function 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.)

+

This function uses the accelerated color conversion routines in the 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.

Parameters
diff --git a/doc/html/search/all_74.js b/doc/html/search/all_74.js index 21e0ced8..435cec4d 100644 --- a/doc/html/search/all_74.js +++ b/doc/html/search/all_74.js @@ -16,6 +16,7 @@ var searchData= ['tjcs_5frgb',['TJCS_RGB',['../group___turbo_j_p_e_g.html#gga4f83ad3368e0e29d1957be0efa7c3720a677cb7ccb85c4038ac41964a2e09e555',1,'turbojpeg.h']]], ['tjcs_5fycbcr',['TJCS_YCbCr',['../group___turbo_j_p_e_g.html#gga4f83ad3368e0e29d1957be0efa7c3720a7389b8f65bb387ffedce3efd0d78ec75',1,'turbojpeg.h']]], ['tjcs_5fycck',['TJCS_YCCK',['../group___turbo_j_p_e_g.html#gga4f83ad3368e0e29d1957be0efa7c3720a53839e0fe867b76b58d16b0a1a7c598e',1,'turbojpeg.h']]], + ['tjdecodeyuv',['tjDecodeYUV',['../group___turbo_j_p_e_g.html#ga132ae2c2cadcf64c8bb0f3bdf69da3ed',1,'turbojpeg.h']]], ['tjdecompress2',['tjDecompress2',['../group___turbo_j_p_e_g.html#gada69cc6443d1bb493b40f1626259e5e9',1,'turbojpeg.h']]], ['tjdecompressheader3',['tjDecompressHeader3',['../group___turbo_j_p_e_g.html#gacd0fac3af74b3511d39b4781b7103086',1,'turbojpeg.h']]], ['tjdecompresstoyuv2',['tjDecompressToYUV2',['../group___turbo_j_p_e_g.html#ga7c08b340ad7f8e85d407bd9e81d44d07',1,'turbojpeg.h']]], diff --git a/doc/html/search/functions_74.js b/doc/html/search/functions_74.js index 4a42d2aa..0a0e6cdc 100644 --- a/doc/html/search/functions_74.js +++ b/doc/html/search/functions_74.js @@ -5,6 +5,7 @@ var searchData= ['tjbufsizeyuv2',['tjBufSizeYUV2',['../group___turbo_j_p_e_g.html#gaf451664a62c1f6c7cc5a6401f32908c9',1,'turbojpeg.h']]], ['tjcompress2',['tjCompress2',['../group___turbo_j_p_e_g.html#gaba62b7a98f960839b588579898495cf2',1,'turbojpeg.h']]], ['tjcompressfromyuv',['tjCompressFromYUV',['../group___turbo_j_p_e_g.html#ga0b931126c7a615ddc3bbd0cca6698d67',1,'turbojpeg.h']]], + ['tjdecodeyuv',['tjDecodeYUV',['../group___turbo_j_p_e_g.html#ga132ae2c2cadcf64c8bb0f3bdf69da3ed',1,'turbojpeg.h']]], ['tjdecompress2',['tjDecompress2',['../group___turbo_j_p_e_g.html#gada69cc6443d1bb493b40f1626259e5e9',1,'turbojpeg.h']]], ['tjdecompressheader3',['tjDecompressHeader3',['../group___turbo_j_p_e_g.html#gacd0fac3af74b3511d39b4781b7103086',1,'turbojpeg.h']]], ['tjdecompresstoyuv2',['tjDecompressToYUV2',['../group___turbo_j_p_e_g.html#ga7c08b340ad7f8e85d407bd9e81d44d07',1,'turbojpeg.h']]], diff --git a/java/CMakeLists.txt b/java/CMakeLists.txt index fc293afb..602a82f7 100644 --- a/java/CMakeLists.txt +++ b/java/CMakeLists.txt @@ -8,12 +8,13 @@ set(JAVA_CLASSNAMES org/libjpegturbo/turbojpeg/TJ org/libjpegturbo/turbojpeg/TJScalingFactor org/libjpegturbo/turbojpeg/TJTransform org/libjpegturbo/turbojpeg/TJTransformer + org/libjpegturbo/turbojpeg/YUVImage TJUnitTest TJExample TJBench) if(MSVC_IDE) - set(OBJDIR "${CMAKE_CURRENT_BINARY_DIR}/$(OutDir)") + set(OBJDIR "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}") else() set(OBJDIR "${CMAKE_CURRENT_BINARY_DIR}") endif() diff --git a/java/Makefile.am b/java/Makefile.am index 1307d69a..23e34129 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 5257a1b5..617d312d 100644 --- a/java/TJBench.java +++ b/java/TJBench.java @@ -1,5 +1,5 @@ /* - * Copyright (C)2009-2013 D. R. Commander. All Rights Reserved. + * Copyright (C)2009-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: @@ -34,12 +34,8 @@ import org.libjpegturbo.turbojpeg.*; class TJBench { - static final int YUVENCODE = 1; - static final int YUVDECODE = 2; - static final int YUVCOMPRESS = 3; - - static int flags = 0, yuv = 0, quiet = 0, pf = TJ.PF_BGR, yuvpad = 1; - static boolean compOnly, decompOnly, doTile; + static int flags = 0, quiet = 0, pf = TJ.PF_BGR, yuvpad = 1, warmup = 1; + static boolean compOnly, decompOnly, doTile, doYUV; static final String[] pixFormatStr = { "RGB", "BGR", "RGBX", "BGRX", "XBGR", "XRGB", "GRAY" @@ -134,68 +130,97 @@ class TJBench { /* Decompression test */ - static void decompTest(byte[] srcBuf, byte[][] jpegBuf, int[] jpegSize, - byte[] dstBuf, int w, int h, int subsamp, - int jpegQual, String fileName, int tilew, int tileh) - throws Exception { + static void decomp(byte[] srcBuf, byte[][] jpegBuf, int[] jpegSize, + byte[] dstBuf, int w, int h, int subsamp, int jpegQual, + String fileName, int tilew, int tileh) throws Exception { String qualStr = new String(""), sizeStr, tempStr; TJDecompressor tjd; - double start, elapsed; - int ps = TJ.getPixelSize(pf), i; + double elapsed, elapsedDecode; + int ps = TJ.getPixelSize(pf), i, iter = 0; int scaledw = sf.getScaled(w); 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); tjd = new TJDecompressor(); - int bufSize = (yuv == YUVDECODE ? yuvSize : pitch * scaledh); if (dstBuf == null) - dstBuf = new byte[bufSize]; + dstBuf = new byte[pitch * scaledh]; /* Set the destination buffer to gray so we know whether the decompressor attempted to write to it */ 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); - else - tjd.decompress(dstBuf, scaledw, pitch, scaledh, pf, flags); - - /* Benchmark */ - for (i = 0, start = getTime(); (elapsed = getTime() - start) < benchTime; - i++) { - int tile = 0; - if (yuv == YUVDECODE) - tjd.decompressToYUV(dstBuf, scaledw, yuvpad, scaledh, 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.decompress(dstBuf, x, y, width, pitch, height, pf, flags); - } - } - } + if (doYUV) { + int width = doTile ? tilew : scaledw; + int height = doTile ? tileh : scaledh; + yuvImage = new YUVImage(width, yuvpad, height, subsamp); + Arrays.fill(yuvImage.getBuf(), (byte)127); } + /* Benchmark */ + iter -= warmup; + elapsed = elapsedDecode = 0.0; + while (true) { + int tile = 0; + double start = getTime(); + 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.setSourceImage(jpegBuf[tile], jpegSize[tile]); + if (doYUV) { + yuvImage.setBuf(yuvImage.getBuf(), width, yuvpad, height, subsamp); + tjd.decompressToYUV(yuvImage, flags); + double startDecode = getTime(); + tjd.setSourceImage(yuvImage); + tjd.decompress(dstBuf, x, y, width, pitch, height, pf, flags); + if (iter >= 0) + elapsedDecode += getTime() - startDecode; + } else + tjd.decompress(dstBuf, x, y, width, pitch, height, pf, flags); + } + } + iter++; + if (iter >= 1) { + elapsed += getTime() - start; + if (elapsed >= benchTime) + break; + } + } + if(doYUV) + elapsed -= elapsedDecode; + tjd = null; + for (i = 0; i < jpegBuf.length; i++) + jpegBuf[i] = null; + jpegBuf = null; jpegSize = null; System.gc(); - if (quiet != 0) - System.out.println( - sigFig((double)(w * h) / 1000000. * (double)i / elapsed, 4)); - else { - System.out.format("D--> Frame rate: %f fps\n", - (double)i / elapsed); - System.out.format(" Dest. throughput: %f Megapixels/sec\n", - (double)(w * h) / 1000000. * (double)i / elapsed); + if (quiet != 0) { + System.out.format("%-6s%s", + sigFig((double)(w * h) / 1000000. * (double)iter / elapsed, 4), + quiet == 2 ? "\n" : " "); + if (doYUV) + System.out.format("%s\n", + sigFig((double)(w * h) / 1000000. * (double)iter / elapsedDecode, 4)); + else if (quiet != 2) + System.out.print("\n"); + } else { + System.out.format("%s --> Frame rate: %f fps\n", + (doYUV ? "Decomp to YUV":"Decompress "), + (double)iter / elapsed); + System.out.format(" Throughput: %f Megapixels/sec\n", + (double)(w * h) / 1000000. * (double)iter / elapsed); + if (doYUV) { + System.out.format("YUV Decode --> Frame rate: %f fps\n", + (double)iter / elapsedDecode); + System.out.format(" Throughput: %f Megapixels/sec\n", + (double)(w * h) / 1000000. * (double)iter / elapsedDecode); + } } if (sf.getNum() != 1 || sf.getDenom() != 1) @@ -205,130 +230,57 @@ class TJBench { else sizeStr = new String("full"); if (decompOnly) - tempStr = new String(fileName + "_" + sizeStr + - (yuv != 0 ? ".yuv" : ".bmp")); + tempStr = new String(fileName + "_" + sizeStr + ".bmp"); else tempStr = new String(fileName + "_" + subName[subsamp] + qualStr + - "_" + sizeStr + (yuv != 0 ? ".yuv" : ".bmp")); + "_" + sizeStr + ".bmp"); - if (yuv == YUVDECODE) { - FileOutputStream fos = new FileOutputStream(tempStr); - fos.write(dstBuf, 0, yuvSize); - fos.close(); - } else { - saveImage(tempStr, dstBuf, scaledw, scaledh, pf); - int ndx = tempStr.indexOf('.'); - tempStr = new String(tempStr.substring(0, ndx) + "-err.bmp"); - if (srcBuf != null && sf.getNum() == 1 && sf.getDenom() == 1) { - if (quiet == 0) - System.out.println("Compression error written to " + tempStr + "."); - if (subsamp == TJ.SAMP_GRAY) { - for (int y = 0, index = 0; y < h; y++, index += pitch) { - for (int x = 0, index2 = index; x < w; x++, index2 += ps) { - int rindex = index2 + TJ.getRedOffset(pf); - int gindex = index2 + TJ.getGreenOffset(pf); - int bindex = index2 + TJ.getBlueOffset(pf); - int lum = (int)((double)(srcBuf[rindex] & 0xff) * 0.299 + - (double)(srcBuf[gindex] & 0xff) * 0.587 + - (double)(srcBuf[bindex] & 0xff) * 0.114 + 0.5); - if (lum > 255) lum = 255; - if (lum < 0) lum = 0; - dstBuf[rindex] = (byte)Math.abs((dstBuf[rindex] & 0xff) - lum); - dstBuf[gindex] = (byte)Math.abs((dstBuf[gindex] & 0xff) - lum); - dstBuf[bindex] = (byte)Math.abs((dstBuf[bindex] & 0xff) - lum); - } + saveImage(tempStr, dstBuf, scaledw, scaledh, pf); + int ndx = tempStr.indexOf('.'); + tempStr = new String(tempStr.substring(0, ndx) + "-err.bmp"); + if (srcBuf != null && sf.getNum() == 1 && sf.getDenom() == 1) { + if (quiet == 0) + System.out.println("Compression error written to " + tempStr + "."); + if (subsamp == TJ.SAMP_GRAY) { + for (int y = 0, index = 0; y < h; y++, index += pitch) { + for (int x = 0, index2 = index; x < w; x++, index2 += ps) { + int rindex = index2 + TJ.getRedOffset(pf); + int gindex = index2 + TJ.getGreenOffset(pf); + int bindex = index2 + TJ.getBlueOffset(pf); + int lum = (int)((double)(srcBuf[rindex] & 0xff) * 0.299 + + (double)(srcBuf[gindex] & 0xff) * 0.587 + + (double)(srcBuf[bindex] & 0xff) * 0.114 + 0.5); + if (lum > 255) lum = 255; + if (lum < 0) lum = 0; + dstBuf[rindex] = (byte)Math.abs((dstBuf[rindex] & 0xff) - lum); + dstBuf[gindex] = (byte)Math.abs((dstBuf[gindex] & 0xff) - lum); + dstBuf[bindex] = (byte)Math.abs((dstBuf[bindex] & 0xff) - lum); } - } else { - for (int y = 0; y < h; y++) - for (int x = 0; x < w * ps; x++) - dstBuf[pitch * y + x] = - (byte)Math.abs((dstBuf[pitch * y + x] & 0xff) - - (srcBuf[pitch * y + x] & 0xff)); } - saveImage(tempStr, dstBuf, w, h, pf); + } else { + for (int y = 0; y < h; y++) + for (int x = 0; x < w * ps; x++) + dstBuf[pitch * y + x] = + (byte)Math.abs((dstBuf[pitch * y + x] & 0xff) - + (srcBuf[pitch * y + x] & 0xff)); } + saveImage(tempStr, dstBuf, w, h, pf); } } - static void doTestYUV(byte[] srcBuf, int w, int h, int subsamp, - String fileName) throws Exception { - TJCompressor tjc; - byte[] dstBuf; - double start, elapsed; - int ps = TJ.getPixelSize(pf), i; - int yuvSize = 0; - - yuvSize = TJ.bufSizeYUV(w, h, subsamp); - dstBuf = new byte[yuvSize]; - - if (quiet == 0) - System.out.format(">>>>> %s (%s) <--> YUV %s <<<<<\n", - pixFormatStr[pf], - (flags & TJ.FLAG_BOTTOMUP) != 0 ? "Bottom-up" : "Top-down", - subNameLong[subsamp]); - - if (quiet == 1) - System.out.format("%s\t%s\t%s\tN/A\t", pixFormatStr[pf], - (flags & TJ.FLAG_BOTTOMUP) != 0 ? "BU" : "TD", - subNameLong[subsamp]); - - tjc = new TJCompressor(srcBuf, w, 0, h, pf); - tjc.setSubsamp(subsamp); - - /* Execute once to preload cache */ - tjc.encodeYUV(dstBuf, flags); - - /* Benchmark */ - for (i = 0, start = getTime(); - (elapsed = getTime() - start) < benchTime; i++) - tjc.encodeYUV(dstBuf, flags); - - if (quiet == 1) - System.out.format("%-4d %-4d\t", w, h); - if (quiet != 0) { - System.out.format("%s%c%s%c", - sigFig((double)(w * h) / 1000000. * (double) i / elapsed, 4), - quiet == 2 ? '\n' : '\t', - sigFig((double)(w * h * ps) / (double)yuvSize, 4), - quiet == 2 ? '\n' : '\t'); - } else { - System.out.format("\n%s size: %d x %d\n", "Image", w, h); - System.out.format("C--> Frame rate: %f fps\n", - (double)i / elapsed); - System.out.format(" Output image size: %d bytes\n", yuvSize); - System.out.format(" Compression ratio: %f:1\n", - (double)(w * h * ps) / (double)yuvSize); - System.out.format(" Source throughput: %f Megapixels/sec\n", - (double)(w * h) / 1000000. * (double)i / elapsed); - System.out.format(" Output bit stream: %f Megabits/sec\n", - (double)yuvSize * 8. / 1000000. * (double)i / elapsed); - } - String tempStr = fileName + "_" + subName[subsamp] + ".yuv"; - FileOutputStream fos = new FileOutputStream(tempStr); - fos.write(dstBuf, 0, yuvSize); - fos.close(); - if (quiet == 0) - System.out.println("Reference image written to " + tempStr); - } - - - static void doTest(byte[] srcBuf, int w, int h, int subsamp, int jpegQual, - String fileName) throws Exception { + static void fullTest(byte[] srcBuf, int w, int h, int subsamp, int jpegQual, + String fileName) throws Exception { TJCompressor tjc; byte[] tmpBuf; byte[][] jpegBuf; int[] jpegSize; - double start, elapsed; - int totalJpegSize = 0, tilew, tileh, i; - int ps = (yuv == YUVCOMPRESS ? 3 : TJ.getPixelSize(pf)); + double start, elapsed, elapsedEncode; + int totalJpegSize = 0, tilew, tileh, i, iter; + int ps = TJ.getPixelSize(pf); int ntilesw = 1, ntilesh = 1, pitch = w * ps; - String pfStr = (yuv == YUVCOMPRESS ? "YUV" : pixFormatStr[pf]); - - if (yuv == YUVENCODE) { - doTestYUV(srcBuf, w, h, subsamp, fileName); - return; - } + String pfStr = pixFormatStr[pf]; + YUVImage yuvImage = null; tmpBuf = new byte[pitch * h]; @@ -353,61 +305,94 @@ class TJBench { /* Compression test */ if (quiet == 1) - System.out.format("%s\t%s\t%s\t%d\t", pfStr, + System.out.format("%-4s (%s) %-5s %-3d ", pfStr, (flags & TJ.FLAG_BOTTOMUP) != 0 ? "BU" : "TD", subNameLong[subsamp], jpegQual); - if (yuv != YUVCOMPRESS) - 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); - else - tjc.setSourceImage(srcBuf, tilew, pitch, tileh, pf); + for (i = 0; i < h; i++) + System.arraycopy(srcBuf, w * ps * i, tmpBuf, pitch * i, w * ps); tjc.setJPEGQuality(jpegQual); tjc.setSubsamp(subsamp); - /* Execute once to preload cache */ - tjc.compress(jpegBuf[0], flags); + if (doYUV) { + yuvImage = new YUVImage(tilew, yuvpad, tileh, subsamp); + Arrays.fill(yuvImage.getBuf(), (byte)127); + } /* Benchmark */ - for (i = 0, start = getTime(); - (elapsed = getTime() - start) < benchTime; i++) { + iter = -warmup; + elapsed = elapsedEncode = 0.0; + while (true) { int tile = 0; totalJpegSize = 0; + start = getTime(); for (int y = 0; y < h; y += tileh) { for (int x = 0; x < w; x += tilew, tile++) { int width = Math.min(tilew, w - x); int height = Math.min(tileh, h - y); - if (yuv != YUVCOMPRESS) - tjc.setSourceImage(srcBuf, x, y, width, pitch, height, pf); + tjc.setSourceImage(srcBuf, x, y, width, pitch, height, pf); + if (doYUV) { + double startEncode = getTime(); + yuvImage.setBuf(yuvImage.getBuf(), width, yuvpad, height, + subsamp); + tjc.encodeYUV(yuvImage, flags); + if (iter >= 0) + elapsedEncode += getTime() - startEncode; + tjc.setSourceImage(yuvImage); + } tjc.compress(jpegBuf[tile], flags); jpegSize[tile] = tjc.getCompressedSize(); totalJpegSize += jpegSize[tile]; } } + iter++; + if (iter >= 1) { + elapsed += getTime() - start; + if (elapsed >= benchTime) + break; + } } + if (doYUV) + elapsed -= elapsedEncode; if (quiet == 1) - System.out.format("%-4d %-4d\t", tilew, tileh); + System.out.format("%-5d %-5d ", tilew, tileh); if (quiet != 0) { - System.out.format("%s%c%s%c", - sigFig((double)(w * h) / 1000000. * (double) i / elapsed, 4), - quiet == 2 ? '\n' : '\t', + if (doYUV) + System.out.format("%-6s%s", + sigFig((double)(w * h) / 1000000. * (double)iter / elapsedEncode, 4), + quiet == 2 ? "\n" : " "); + System.out.format("%-6s%s", + sigFig((double)(w * h) / 1000000. * (double)iter / elapsed, 4), + quiet == 2 ? "\n" : " "); + System.out.format("%-6s%s", sigFig((double)(w * h * ps) / (double)totalJpegSize, 4), - quiet == 2 ? '\n' : '\t'); + quiet == 2 ? "\n" : " "); } else { System.out.format("\n%s size: %d x %d\n", doTile ? "Tile" : "Image", tilew, tileh); - System.out.format("C--> Frame rate: %f fps\n", - (double)i / elapsed); - System.out.format(" Output image size: %d bytes\n", + if (doYUV) { + System.out.format("Encode YUV --> Frame rate: %f fps\n", + (double)iter / elapsedEncode); + System.out.format(" Output image size: %d bytes\n", + yuvImage.getSize()); + System.out.format(" Compression ratio: %f:1\n", + (double)(w * h * ps) / (double)yuvImage.getSize()); + System.out.format(" Throughput: %f Megapixels/sec\n", + (double)(w * h) / 1000000. * (double)iter / elapsedEncode); + System.out.format(" Output bit stream: %f Megabits/sec\n", + (double)yuvImage.getSize() * 8. / 1000000. * (double)iter / elapsedEncode); + } + System.out.format("%s --> Frame rate: %f fps\n", + doYUV ? "Comp from YUV" : "Compress ", + (double)iter / elapsed); + System.out.format(" Output image size: %d bytes\n", totalJpegSize); - System.out.format(" Compression ratio: %f:1\n", + System.out.format(" Compression ratio: %f:1\n", (double)(w * h * ps) / (double)totalJpegSize); - System.out.format(" Source throughput: %f Megapixels/sec\n", - (double)(w * h) / 1000000. * (double)i / elapsed); - System.out.format(" Output bit stream: %f Megabits/sec\n", - (double)totalJpegSize * 8. / 1000000. * (double)i / elapsed); + System.out.format(" Throughput: %f Megapixels/sec\n", + (double)(w * h) / 1000000. * (double)iter / elapsed); + System.out.format(" Output bit stream: %f Megabits/sec\n", + (double)totalJpegSize * 8. / 1000000. * (double)iter / elapsed); } if (tilew == w && tileh == h) { String tempStr = fileName + "_" + subName[subsamp] + "_" + "Q" + @@ -421,27 +406,22 @@ class TJBench { /* Decompression test */ if (!compOnly) - decompTest(srcBuf, jpegBuf, jpegSize, tmpBuf, w, h, subsamp, jpegQual, - fileName, tilew, tileh); - - for (i = 0; i < ntilesw * ntilesh; i++) - jpegBuf[i] = null; - jpegBuf = null; jpegSize = null; - System.gc(); + decomp(srcBuf, jpegBuf, jpegSize, tmpBuf, w, h, subsamp, jpegQual, + fileName, tilew, tileh); if (tilew == w && tileh == h) break; } } - static void doDecompTest(String fileName) throws Exception { + static void decompTest(String fileName) throws Exception { TJTransformer tjt; - byte[][] jpegBuf; + byte[][] jpegBuf = null; byte[] srcBuf; - int[] jpegSize; + int[] jpegSize = null; int totalJpegSize; int w = 0, h = 0, subsamp = -1, cs = -1, _w, _h, _tilew, _tileh, - _ntilesw, _ntilesh, _subsamp, x, y; + _ntilesw, _ntilesh, _subsamp, x, y, iter; int ntilesw = 1, ntilesh = 1; double start, elapsed; int ps = TJ.getPixelSize(pf), tile; @@ -458,7 +438,7 @@ class TJBench { tjt = new TJTransformer(); - tjt.setJPEGImage(srcBuf, srcSize); + tjt.setSourceImage(srcBuf, srcSize); w = tjt.getWidth(); h = tjt.getHeight(); subsamp = tjt.getSubsamp(); @@ -466,19 +446,20 @@ class TJBench { if (quiet == 1) { System.out.println("All performance values in Mpixels/sec\n"); - System.out.format("Bitmap\tBitmap\tJPEG\tJPEG\t%s %s \tXform\tComp\tDecomp\n", + System.out.format("Bitmap JPEG JPEG %s %s Xform Comp Decomp ", (doTile ? "Tile " : "Image"), (doTile ? "Tile " : "Image")); - System.out.println("Format\tOrder\tCS\tSubsamp\tWidth Height\tPerf \tRatio\tPerf\n"); - } else if (quiet == 0) { - if (yuv == YUVDECODE) - System.out.format(">>>>> JPEG %s --> YUV <<<<<", - formatName(subsamp, cs)); - else - System.out.format(">>>>> JPEG %s --> %s (%s) <<<<<", - formatName(subsamp, cs), pixFormatStr[pf], - (flags & TJ.FLAG_BOTTOMUP) != 0 ? "Bottom-up" : "Top-down"); - } + if (doYUV) + System.out.print("Decode"); + System.out.print("\n"); + System.out.print("Format CS Subsamp Width Height Perf Ratio Perf "); + if (doYUV) + System.out.print("Perf"); + System.out.println("\n"); + } else if (quiet == 0) + System.out.format(">>>>> JPEG %s --> %s (%s) <<<<<\n", + formatName(subsamp, cs), pixFormatStr[pf], + (flags & TJ.FLAG_BOTTOMUP) != 0 ? "Bottom-up" : "Top-down"); for (int tilew = doTile ? 16 : w, tileh = doTile ? 16 : h; ; tilew *= 2, tileh *= 2) { @@ -498,10 +479,10 @@ class TJBench { sf.getScaled(_h)); System.out.println(""); } else if (quiet == 1) { - System.out.format("%s\t%s\t%s\t%s\t", pixFormatStr[pf], + System.out.format("%-4s (%s) %-5s %-5s ", pixFormatStr[pf], (flags & TJ.FLAG_BOTTOMUP) != 0 ? "BU" : "TD", csName[cs], subNameLong[subsamp]); - System.out.format("%-4d %-4d\t", tilew, tileh); + System.out.format("%-5d %-5d ", tilew, tileh); } _subsamp = subsamp; @@ -530,6 +511,16 @@ class TJBench { _ntilesw = (_w + _tilew - 1) / _tilew; _ntilesh = (_h + _tileh - 1) / _tileh; + if (xformOp == TJTransform.OP_TRANSPOSE || + xformOp == TJTransform.OP_TRANSVERSE || + xformOp == TJTransform.OP_ROT90 || + xformOp == TJTransform.OP_ROT270) { + if (_subsamp == TJ.SAMP_422) + _subsamp = TJ.SAMP_440; + else if (_subsamp == TJ.SAMP_440) + _subsamp = TJ.SAMP_422; + } + TJTransform[] t = new TJTransform[_ntilesw * _ntilesh]; jpegBuf = new byte[_ntilesw * _ntilesh][TJ.bufSize(_tilew, _tileh, subsamp)]; @@ -548,37 +539,45 @@ class TJBench { } } - start = getTime(); - tjt.transform(jpegBuf, t, flags); - jpegSize = tjt.getTransformedSizes(); - elapsed = getTime() - start; - + iter = -warmup; + elapsed = 0.; + while (true) { + start = getTime(); + tjt.transform(jpegBuf, t, flags); + jpegSize = tjt.getTransformedSizes(); + iter++; + if (iter >= 1) { + elapsed += getTime() - start; + if (elapsed >= benchTime) + break; + } + } t = null; for (tile = 0, totalJpegSize = 0; tile < _ntilesw * _ntilesh; tile++) totalJpegSize += jpegSize[tile]; if (quiet != 0) { - System.out.format("%s%c%s%c", + System.out.format("%-6s%s%-6s%s", sigFig((double)(w * h) / 1000000. / elapsed, 4), - quiet == 2 ? '\n' : '\t', + quiet == 2 ? "\n" : " ", sigFig((double)(w * h * ps) / (double)totalJpegSize, 4), - quiet == 2 ? '\n' : '\t'); + quiet == 2 ? "\n" : " "); } else if (quiet == 0) { - System.out.format("X--> Frame rate: %f fps\n", + System.out.format("Transform --> Frame rate: %f fps\n", 1.0 / elapsed); - System.out.format(" Output image size: %lu bytes\n", + System.out.format(" Output image size: %d bytes\n", totalJpegSize); - System.out.format(" Compression ratio: %f:1\n", + System.out.format(" Compression ratio: %f:1\n", (double)(w * h * ps) / (double)totalJpegSize); - System.out.format(" Source throughput: %f Megapixels/sec\n", + System.out.format(" Throughput: %f Megapixels/sec\n", (double)(w * h) / 1000000. / elapsed); - System.out.format(" Output bit stream: %f Megabits/sec\n", + System.out.format(" Output bit stream: %f Megabits/sec\n", (double)totalJpegSize * 8. / 1000000. / elapsed); } } else { if (quiet == 1) - System.out.print("N/A\tN/A\t"); + System.out.print("N/A N/A "); jpegBuf = new byte[1][TJ.bufSize(_tilew, _tileh, subsamp)]; jpegSize = new int[1]; jpegSize[0] = srcSize; @@ -590,8 +589,8 @@ class TJBench { if (h == tileh) _tileh = _h; if ((xformOpt & TJTransform.OPT_NOOUTPUT) == 0) - decompTest(null, jpegBuf, jpegSize, null, _w, _h, _subsamp, 0, - fileName, _tilew, _tileh); + decomp(null, jpegBuf, jpegSize, null, _w, _h, _subsamp, 0, + fileName, _tilew, _tileh); else if (quiet == 1) System.out.println("N/A"); @@ -610,7 +609,7 @@ class TJBench { String className = new TJBench().getClass().getName(); System.out.println("\nUSAGE: java " + className); - System.out.println(" [options]\n"); + System.out.println(" [options]\n"); System.out.println(" java " + className); System.out.println(" [options]\n"); System.out.println("Options:\n"); @@ -618,32 +617,24 @@ class TJBench { System.out.println("-bottomup = Test bottom-up compression/decompression"); System.out.println("-tile = Test performance of the codec when the image is encoded as separate"); System.out.println(" tiles of varying sizes."); - System.out.println("-forcemmx, -forcesse, -forcesse2, -forcesse3 ="); - System.out.println(" Force MMX, SSE, SSE2, or SSE3 code paths in the underlying codec"); System.out.println("-rgb, -bgr, -rgbx, -bgrx, -xbgr, -xrgb ="); - System.out.println(" Test the specified color conversion path in the codec (default: BGR)"); + System.out.println(" Test the specified color conversion path in the codec (default = BGR)"); System.out.println("-fastupsample = Use the fastest chrominance upsampling algorithm available in"); System.out.println(" the underlying codec"); System.out.println("-fastdct = Use the fastest DCT/IDCT algorithms available in the underlying"); System.out.println(" codec"); System.out.println("-accuratedct = Use the most accurate DCT/IDCT algorithms available in the"); System.out.println(" underlying codec"); - System.out.println("-subsamp = if compressing a JPEG image from a YUV planar source image,"); - System.out.println(" this specifies the level of chrominance subsampling used in the source"); - System.out.println(" image. Otherwise, this specifies the level of chrominance subsampling"); - System.out.println(" to use in the JPEG destination image. = 444, 422, 440, 420, 411,"); - System.out.println(" or GRAY"); + System.out.println("-subsamp = When testing JPEG compression, this option specifies the level"); + System.out.println(" of chrominance subsampling to use ( = 444, 422, 440, 420, 411, or"); + System.out.println(" GRAY). The default is to test Grayscale, 4:2:0, 4:2:2, and 4:4:4 in"); + System.out.println(" sequence."); System.out.println("-quiet = Output results in tabular rather than verbose format"); - System.out.println("-yuvencode = Encode RGB input as planar YUV rather than compressing as JPEG"); - System.out.println("-yuvdecode = Decode JPEG image to planar YUV rather than RGB"); - System.out.println("-yuvsize WxH = if compressing a JPEG image from a YUV planar source image, this"); - System.out.println(" specifies the width and height of the source image."); - System.out.println("-yuvpad

= if compressing a JPEG image from a YUV planar source image, this"); - System.out.println(" specifies the number of bytes to which each row of each plane in the"); - System.out.println(" source image is padded. If decompressing a JPEG image to a YUV planar"); - System.out.println(" destination image, this specifies the row padding for each plane of the"); - System.out.println(" destination image. (default=1)"); - System.out.println("-scale M/N = scale down the width/height of the decompressed JPEG image by a"); + System.out.println("-yuv = Test YUV encoding/decoding functions"); + System.out.println("-yuvpad

= If testing YUV encoding/decoding, this specifies the number of"); + System.out.println(" bytes to which each row of each plane in the intermediate YUV image is"); + System.out.println(" padded (default = 1)"); + System.out.println("-scale M/N = Scale down the width/height of the decompressed JPEG image by a"); System.out.print (" factor of M/N (M/N = "); for (i = 0; i < nsf; i++) { System.out.format("%d/%d", scalingFactors[i].getNum(), @@ -666,7 +657,9 @@ class TJBench { System.out.println("-grayscale = Perform lossless grayscale conversion prior to decompression"); System.out.println(" test (can be combined with the other transforms above)"); System.out.println("-benchtime = Run each benchmark for at least seconds (default = 5.0)"); - System.out.println("-componly = Stop after running compression tests. Do not test decompression.\n"); + System.out.println("-warmup = Execute each benchmark times to prime the cache before"); + System.out.println(" taking performance measurements (default = 1)"); + System.out.println("-componly = Stop after running compression tests. Do not test decompression.\n"); System.out.println("NOTE: If the quality is specified as a range (e.g. 90-100), a separate"); System.out.println("test will be performed for all quality values in the range.\n"); System.exit(1); @@ -687,25 +680,10 @@ class TJBench { String tempStr = argv[0].toLowerCase(); if (tempStr.endsWith(".jpg") || tempStr.endsWith(".jpeg")) decompOnly = true; - if (tempStr.endsWith(".yuv")) - yuv = YUVCOMPRESS; System.out.println(""); - if (argv.length > minArg) { - for (int i = minArg; i < argv.length; i++) { - if (argv[i].equalsIgnoreCase("-yuvencode")) { - System.out.println("Testing YUV planar encoding\n"); - yuv = YUVENCODE; maxQual = minQual = 100; - } - if (argv[i].equalsIgnoreCase("-yuvdecode")) { - System.out.println("Testing YUV planar decoding\n"); - yuv = YUVDECODE; - } - } - } - - if (!decompOnly && yuv != YUVENCODE) { + if (!decompOnly) { minArg = 2; if (argv.length < minArg) usage(); @@ -729,22 +707,6 @@ class TJBench { if (argv[i].equalsIgnoreCase("-tile")) { doTile = true; xformOpt |= TJTransform.OPT_CROP; } - if (argv[i].equalsIgnoreCase("-forcesse3")) { - System.out.println("Forcing SSE3 code\n"); - flags |= TJ.FLAG_FORCESSE3; - } - if (argv[i].equalsIgnoreCase("-forcesse2")) { - System.out.println("Forcing SSE2 code\n"); - flags |= TJ.FLAG_FORCESSE2; - } - if (argv[i].equalsIgnoreCase("-forcesse")) { - System.out.println("Forcing SSE code\n"); - flags |= TJ.FLAG_FORCESSE; - } - if (argv[i].equalsIgnoreCase("-forcemmx")) { - System.out.println("Forcing MMX code\n"); - flags |= TJ.FLAG_FORCEMMX; - } if (argv[i].equalsIgnoreCase("-fastupsample")) { System.out.println("Using fast upsampling code\n"); flags |= TJ.FLAG_FASTUPSAMPLE; @@ -826,18 +788,9 @@ class TJBench { else usage(); } - if (argv[i].equalsIgnoreCase("-yuvsize") && i < argv.length - 1) { - int temp1 = 0, temp2 = 0; - Scanner scanner = new Scanner(argv[++i]).useDelimiter("x"); - try { - temp1 = scanner.nextInt(); - temp2 = scanner.nextInt(); - } catch(Exception e) {} - if (temp1 >= 1 && temp2 >= 1) { - w = temp1; - h = temp2; - } else - usage(); + if (argv[i].equalsIgnoreCase("-yuv")) { + System.out.println("Testing YUV planar encoding/decoding\n"); + doYUV = true; } if (argv[i].equalsIgnoreCase("-yuvpad") && i < argv.length - 1) { int temp = 0; @@ -864,6 +817,16 @@ class TJBench { } if (argv[i].equalsIgnoreCase("-componly")) compOnly = true; + if (argv[i].equalsIgnoreCase("-warmup") && i < argv.length - 1) { + int temp = -1; + try { + temp = Integer.parseInt(argv[++i]); + } catch (NumberFormatException e) {} + if (temp >= 0) { + warmup = temp; + System.out.format("Warmup runs = %d\n\n", warmup); + } + } if (argv[i].equalsIgnoreCase("-?")) usage(); } @@ -878,67 +841,60 @@ class TJBench { doTile = false; } - if (yuv != 0 && doTile) { - System.out.println("Disabling tiled compression/decompression tests, because those tests do not"); - System.out.println("work when YUV encoding, compression, or decoding is enabled.\n"); - doTile = false; - } - if (!decompOnly) { - if(yuv == YUVCOMPRESS) { - if (w < 1 || h < 1 || subsamp < 0 || subsamp >= TJ.NUMSAMP) - throw new Exception("YUV image size and/or subsampling not specified"); - FileInputStream fis = new FileInputStream(argv[0]); - int srcSize = (int)fis.getChannel().size(); - if (srcSize != TJ.bufSizeYUV(w, yuvpad, h, subsamp)) - throw new Exception("YUV image file is the wrong size"); - srcBuf = new byte[srcSize]; - fis.read(srcBuf, 0, srcSize); - fis.close(); - } - else { - int[] width = new int[1], height = new int[1]; - srcBuf = loadImage(argv[0], width, height, pf); - w = width[0]; h = height[0]; - int index = -1; - if ((index = argv[0].indexOf('.')) >= 0) - argv[0] = argv[0].substring(0, index); - } + int[] width = new int[1], height = new int[1]; + srcBuf = loadImage(argv[0], width, height, pf); + w = width[0]; h = height[0]; + int index = -1; + if ((index = argv[0].indexOf('.')) >= 0) + argv[0] = argv[0].substring(0, index); } if (quiet == 1 && !decompOnly) { System.out.println("All performance values in Mpixels/sec\n"); - System.out.format("Bitmap\tBitmap\tJPEG\tJPEG\t%s %s \tComp\tComp\tDecomp\n", + System.out.format("Bitmap JPEG JPEG %s %s ", (doTile ? "Tile " : "Image"), (doTile ? "Tile " : "Image")); - System.out.println("Format\tOrder\tSubsamp\tQual\tWidth Height\tPerf \tRatio\tPerf\n"); + if (doYUV) + System.out.print("Encode "); + System.out.print("Comp Comp Decomp "); + if (doYUV) + System.out.print("Decode"); + System.out.print("\n"); + System.out.print("Format Subsamp Qual Width Height "); + if (doYUV) + System.out.print("Perf "); + System.out.print("Perf Ratio Perf "); + if (doYUV) + System.out.print("Perf"); + System.out.println("\n"); } if (decompOnly) { - doDecompTest(argv[0]); + decompTest(argv[0]); System.out.println(""); System.exit(retval); } System.gc(); - if (yuv == YUVCOMPRESS || (subsamp >= 0 && subsamp < TJ.NUMSAMP)) { + if (subsamp >= 0 && subsamp < TJ.NUMSAMP) { for (int i = maxQual; i >= minQual; i--) - doTest(srcBuf, w, h, subsamp, i, argv[0]); + fullTest(srcBuf, w, h, subsamp, i, argv[0]); System.out.println(""); } else { for (int i = maxQual; i >= minQual; i--) - doTest(srcBuf, w, h, TJ.SAMP_GRAY, i, argv[0]); + fullTest(srcBuf, w, h, TJ.SAMP_GRAY, i, argv[0]); System.out.println(""); System.gc(); for (int i = maxQual; i >= minQual; i--) - doTest(srcBuf, w, h, TJ.SAMP_420, i, argv[0]); + fullTest(srcBuf, w, h, TJ.SAMP_420, i, argv[0]); System.out.println(""); System.gc(); for (int i = maxQual; i >= minQual; i--) - doTest(srcBuf, w, h, TJ.SAMP_422, i, argv[0]); + fullTest(srcBuf, w, h, TJ.SAMP_422, i, argv[0]); System.out.println(""); System.gc(); for (int i = maxQual; i >= minQual; i--) - doTest(srcBuf, w, h, TJ.SAMP_444, i, argv[0]); + fullTest(srcBuf, w, h, TJ.SAMP_444, i, argv[0]); System.out.println(""); } diff --git a/java/TJExample.java b/java/TJExample.java index a4971a46..2c6324dc 100644 --- a/java/TJExample.java +++ b/java/TJExample.java @@ -1,5 +1,5 @@ /* - * Copyright (C)2011-2012 D. R. Commander. All Rights Reserved. + * Copyright (C)2011-2012, 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: @@ -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); } @@ -324,11 +324,11 @@ public class TJExample implements TJCustomFilter { tjc.setSubsamp(outSubsamp); tjc.setJPEGQuality(outQual); if (img != null) - jpegBuf = tjc.compress(img, flags); + tjc.setSourceImage(img, 0, 0, 0, 0); else { - tjc.setSourceImage(bmpBuf, width, 0, height, TJ.PF_BGRX); - jpegBuf = tjc.compress(flags); + tjc.setSourceImage(bmpBuf, 0, 0, width, 0, height, TJ.PF_BGRX); } + jpegBuf = tjc.compress(flags); jpegSize = tjc.getCompressedSize(); tjc.close(); diff --git a/java/TJUnitTest.java b/java/TJUnitTest.java index 4d57f127..d8b5c854 100644 --- a/java/TJUnitTest.java +++ b/java/TJUnitTest.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: @@ -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; @@ -152,10 +150,6 @@ public class TJUnitTest { return "Unknown"; } - private static double getTime() { - return (double)System.nanoTime() / 1.0e9; - } - private static void initBuf(byte[] buf, int w, int pitch, int h, int pf, int flags) throws Exception { int roffset = TJ.getRedOffset(pf); @@ -538,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 { @@ -690,96 +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"; - double t; 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); + pfStr = pixFormatStr[pf]; + pfStrLong = pfStr; + } + 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); - - 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); - t = getTime(); tjc.setSubsamp(subsamp); tjc.setJPEGQuality(jpegQual); - tjc.setYUVPad(pad); - if (bi) { - if (yuv == YUVENCODE) - tjc.encodeYUV(img, dstBuf, flags); - else - tjc.compress(img, dstBuf, flags); - } else { - if (yuv == YUVDECODE) - tjc.setSourceImageYUV(srcBuf, w, pad, h); - else - tjc.setSourceImage(srcBuf, w, 0, h, pf); - if (yuv == YUVENCODE) - tjc.encodeYUV(dstBuf, flags); - else - tjc.compress(dstBuf, flags); - } - size = tjc.getCompressedSize(); - t = getTime() - t; - - 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.format(" %.6f ms\n", t * 1000.); - System.out.println(" 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; } @@ -788,41 +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; - double t; + 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("... "); - t = getTime(); - tjd.setJPEGImage(jpegBuf, jpegSize); + tjd.setSourceImage(jpegBuf, jpegSize); if (tjd.getWidth() != w || tjd.getHeight() != h || tjd.getSubsamp() != subsamp) throw new Exception("Incorrect JPEG header"); @@ -834,44 +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("... "); } - t = getTime() - t; + 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.format(" %.6f ms\n", t * 1000.); } private static void decompTest(TJDecompressor tjd, byte[] jpegBuf, @@ -900,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(); @@ -916,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"); } } @@ -945,7 +848,8 @@ public class TJUnitTest { private static void bufSizeTest() throws Exception { int w, h, i, subsamp; - byte[] srcBuf, jpegBuf; + byte[] srcBuf, dstBuf = null; + YUVImage dstImage = null; TJCompressor tjc = null; Random r = new Random(); @@ -959,22 +863,34 @@ 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]; - jpegBuf = new byte[TJ.bufSize(w, 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++) { srcBuf[i] = (byte)(r.nextInt(2) * 255); } - tjc.setSourceImage(srcBuf, w, 0, h, TJ.PF_BGRX); + tjc.setSourceImage(srcBuf, 0, 0, w, 0, h, TJ.PF_BGRX); tjc.setSubsamp(subsamp); tjc.setJPEGQuality(100); - tjc.compress(jpegBuf, 0); + if (doYUV) + tjc.encodeYUV(dstImage, 0); + else + tjc.compress(dstBuf, 0); srcBuf = new byte[h * w * 4]; - jpegBuf = new byte[TJ.bufSize(h, 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, h, 0, w, TJ.PF_BGRX); - tjc.compress(jpegBuf, 0); + tjc.setSourceImage(srcBuf, 0, 0, h, 0, w, TJ.PF_BGRX); + if (doYUV) + tjc.encodeYUV(dstImage, 0); + else + tjc.compress(dstBuf, 0); } } } @@ -989,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") || @@ -1003,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, @@ -1033,24 +946,17 @@ public class TJUnitTest { _4byteFormats[4] = -1; doTest(35, 39, bi ? _4byteFormatsBI : _4byteFormats, TJ.SAMP_GRAY, testName); - if (!doyuv && !bi) + if (!bi) bufSizeTest(); - if (doyuv && !bi) { - yuv = YUVDECODE; + if (doYUV && !bi) { + System.out.print("\n--------------------\n\n"); 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 b2810b52..509ea508 100644 --- a/java/doc/allclasses-frame.html +++ b/java/doc/allclasses-frame.html @@ -1,41 +1,23 @@ - - - - -All Classes - - - - - - - - - - -All Classes -
- -

- - - -
TJ -
-TJCompressor -
-TJCustomFilter -
-TJDecompressor -
-TJScalingFactor -
-TJTransform -
-TJTransformer -
-
- - - + + + +All Classes + + + +

All Classes

+ + + diff --git a/java/doc/allclasses-noframe.html b/java/doc/allclasses-noframe.html index ddc3d633..3eac18fa 100644 --- a/java/doc/allclasses-noframe.html +++ b/java/doc/allclasses-noframe.html @@ -1,41 +1,23 @@ - - - - -All Classes - - - - - - - - - - -All Classes -
- - - - - -
TJ -
-TJCompressor -
-TJCustomFilter -
-TJDecompressor -
-TJScalingFactor -
-TJTransform -
-TJTransformer -
-
- - - + + + +All Classes + + + +

All Classes

+ + + diff --git a/java/doc/constant-values.html b/java/doc/constant-values.html index 01f950f3..ec1b21d4 100644 --- a/java/doc/constant-values.html +++ b/java/doc/constant-values.html @@ -1,462 +1,479 @@ - - - - -Constant Field Values - - - - - - - - - - - -
- - +//--> + + - - - - - - - - - - - - -
- -
- + +
+ + + - -
-
-

-Constant Field Values

-
-
-Contents - - - - - - -
-org.libjpegturbo.*
- -

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
org.libjpegturbo.turbojpeg.TJ
-public static final intCS_CMYK3
-public static final intCS_GRAY2
-public static final intCS_RGB0
-public static final intCS_YCbCr1
-public static final intCS_YCCK4
-public static final intFLAG_ACCURATEDCT4096
-public static final intFLAG_BOTTOMUP2
-public static final intFLAG_FASTDCT2048
-public static final intFLAG_FASTUPSAMPLE256
-public static final intFLAG_FORCEMMX8
-public static final intFLAG_FORCESSE16
-public static final intFLAG_FORCESSE232
-public static final intFLAG_FORCESSE3128
-public static final intNUMCS5
-public static final intNUMPF12
-public static final intNUMSAMP6
-public static final intPF_ABGR9
-public static final intPF_ARGB10
-public static final intPF_BGR1
-public static final intPF_BGRA8
-public static final intPF_BGRX3
-public static final intPF_CMYK11
-public static final intPF_GRAY6
-public static final intPF_RGB0
-public static final intPF_RGBA7
-public static final intPF_RGBX2
-public static final intPF_XBGR4
-public static final intPF_XRGB5
-public static final intSAMP_4115
-public static final intSAMP_4202
-public static final intSAMP_4221
-public static final intSAMP_4404
-public static final intSAMP_4440
-public static final intSAMP_GRAY3
- -

- -

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
org.libjpegturbo.turbojpeg.TJTransform
-public static final intNUMOP8
-public static final intOP_HFLIP1
-public static final intOP_NONE0
-public static final intOP_ROT1806
-public static final intOP_ROT2707
-public static final intOP_ROT905
-public static final intOP_TRANSPOSE3
-public static final intOP_TRANSVERSE4
-public static final intOP_VFLIP2
-public static final intOPT_CROP4
-public static final intOPT_GRAY8
-public static final intOPT_NOOUTPUT16
-public static final intOPT_PERFECT1
-public static final intOPT_TRIM2
- -

- -

-


- - +
+

Constant Field Values

+

Contents

+ +
+
+ + +

org.libjpegturbo.*

+ +
- - - - - - - - - - - - -
- -
- + + + + + - -
- - - + + diff --git a/java/doc/deprecated-list.html b/java/doc/deprecated-list.html index 9f3b4fd3..79fd7ed9 100644 --- a/java/doc/deprecated-list.html +++ b/java/doc/deprecated-list.html @@ -1,208 +1,258 @@ - - - - -Deprecated List - - - - - - - - - - - -
- - +//--> + + - - - - - - - - - - - - -
- -
- + + + + + - -
-
-

-Deprecated API

-
-
-Contents - - - - - - - - - - - - - - - - - - -
-Deprecated Fields
org.libjpegturbo.turbojpeg.TJ.FLAG_FORCEMMX -
-           
org.libjpegturbo.turbojpeg.TJ.FLAG_FORCESSE -
-           
org.libjpegturbo.turbojpeg.TJ.FLAG_FORCESSE2 -
-           
org.libjpegturbo.turbojpeg.TJ.FLAG_FORCESSE3 -
-           
-  -

- - - - - - - - - - - - - - - - - - - - -
-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 - TJCompressor.setSourceImage(byte[], int, int, int, int, int, int) instead. 
-  -

-


- - + +
+ + + + + + + + + + + +
- - - - - - - - - - - - -
- -
- + + + + + - -
- - - + + diff --git a/java/doc/help-doc.html b/java/doc/help-doc.html index b919d0aa..ce749a93 100644 --- a/java/doc/help-doc.html +++ b/java/doc/help-doc.html @@ -1,207 +1,206 @@ - - - - -API Help - - - - - - - - - - - -
- - +//--> + + - - - - - - - - - - - - -
- -
- + + + + + - -
-
-

-How This API Document Is Organized

-
-This API (Application Programming Interface) document has pages corresponding to the items in the navigation bar, described as follows.

-Package

-
- -

-Each package has a page that contains a list of its classes and interfaces, with a summary for each. This page can contain four categories:

    -
  • Interfaces (italic)
  • Classes
  • Enums
  • Exceptions
  • Errors
  • Annotation Types
-
-

-Class/Interface

-
- -

-Each class, interface, nested class and nested interface has its own separate page. Each of these pages has three sections consisting of a class/interface description, summary tables, and detailed member descriptions:

    -
  • Class inheritance diagram
  • Direct Subclasses
  • All Known Subinterfaces
  • All Known Implementing Classes
  • Class/interface declaration
  • Class/interface description -

    -

  • Nested Class Summary
  • Field Summary
  • Constructor Summary
  • Method Summary -

    -

  • Field Detail
  • Constructor Detail
  • Method Detail
-Each summary entry contains the first sentence from the detailed description for that item. The summary entries are alphabetical, while the detailed descriptions are in the order they appear in the source code. This preserves the logical groupings established by the programmer.
- -

-Annotation Type

-
- -

-Each annotation type has its own separate page with the following sections:

    -
  • Annotation Type declaration
  • Annotation Type description
  • Required Element Summary
  • Optional Element Summary
  • Element Detail
-
- -

-Enum

-
- -

-Each enum has its own separate page with the following sections:

    -
  • Enum declaration
  • Enum description
  • Enum Constant Summary
  • Enum Constant Detail
-
-

-Tree (Class Hierarchy)

-
-There is a Class Hierarchy page for all packages, plus a hierarchy for each package. Each hierarchy page contains a list of classes and a list of interfaces. The classes are organized by inheritance structure starting with java.lang.Object. The interfaces do not inherit from java.lang.Object.
    -
  • When viewing the Overview page, clicking on "Tree" displays the hierarchy for all packages.
  • When viewing a particular package, class or interface page, clicking "Tree" displays the hierarchy for only that package.
-
-

-Deprecated API

-
-The Deprecated API page lists all of the API that have been deprecated. A deprecated API is not recommended for use, generally due to improvements, and a replacement API is usually given. Deprecated APIs may be removed in future implementations.
-

-Index

-
-The Index contains an alphabetic list of all classes, interfaces, constructors, methods, and fields.
-

-Prev/Next

-These links take you to the next or previous class, interface, package, or related page.

-Frames/No Frames

-These links show and hide the HTML frames. All pages are available with or without frames. -

-

-Serialized Form

-Each serializable or externalizable class has a description of its serialization fields and methods. This information is of interest to re-implementors, not to developers using the API. While there is no link in the navigation bar, you can get to this information by going to any serialized class and clicking "Serialized Form" in the "See also" section of the class description. -

-

-Constant Field Values

-The Constant Field Values page lists the static final fields and their values. -

- - -This help file applies to API documentation generated using the standard doclet. - -
-


- - +
+

How This API Document Is Organized

+
This API (Application Programming Interface) document has pages corresponding to the items in the navigation bar, described as follows.
+
+
+
    +
  • +

    Package

    +

    Each package has a page that contains a list of its classes and interfaces, with a summary for each. This page can contain six categories:

    +
      +
    • Interfaces (italic)
    • +
    • Classes
    • +
    • Enums
    • +
    • Exceptions
    • +
    • Errors
    • +
    • Annotation Types
    • +
    +
  • +
  • +

    Class/Interface

    +

    Each class, interface, nested class and nested interface has its own separate page. Each of these pages has three sections consisting of a class/interface description, summary tables, and detailed member descriptions:

    +
      +
    • Class inheritance diagram
    • +
    • Direct Subclasses
    • +
    • All Known Subinterfaces
    • +
    • All Known Implementing Classes
    • +
    • Class/interface declaration
    • +
    • Class/interface description
    • +
    +
      +
    • Nested Class Summary
    • +
    • Field Summary
    • +
    • Constructor Summary
    • +
    • Method Summary
    • +
    +
      +
    • Field Detail
    • +
    • Constructor Detail
    • +
    • Method Detail
    • +
    +

    Each summary entry contains the first sentence from the detailed description for that item. The summary entries are alphabetical, while the detailed descriptions are in the order they appear in the source code. This preserves the logical groupings established by the programmer.

    +
  • +
  • +

    Annotation Type

    +

    Each annotation type has its own separate page with the following sections:

    +
      +
    • Annotation Type declaration
    • +
    • Annotation Type description
    • +
    • Required Element Summary
    • +
    • Optional Element Summary
    • +
    • Element Detail
    • +
    +
  • +
  • +

    Enum

    +

    Each enum has its own separate page with the following sections:

    +
      +
    • Enum declaration
    • +
    • Enum description
    • +
    • Enum Constant Summary
    • +
    • Enum Constant Detail
    • +
    +
  • +
  • +

    Tree (Class Hierarchy)

    +

    There is a Class Hierarchy page for all packages, plus a hierarchy for each package. Each hierarchy page contains a list of classes and a list of interfaces. The classes are organized by inheritance structure starting with java.lang.Object. The interfaces do not inherit from java.lang.Object.

    +
      +
    • When viewing the Overview page, clicking on "Tree" displays the hierarchy for all packages.
    • +
    • When viewing a particular package, class or interface page, clicking "Tree" displays the hierarchy for only that package.
    • +
    +
  • +
  • +

    Deprecated API

    +

    The Deprecated API page lists all of the API that have been deprecated. A deprecated API is not recommended for use, generally due to improvements, and a replacement API is usually given. Deprecated APIs may be removed in future implementations.

    +
  • +
  • +

    Index

    +

    The Index contains an alphabetic list of all classes, interfaces, constructors, methods, and fields.

    +
  • +
  • +

    Prev/Next

    +

    These links take you to the next or previous class, interface, package, or related page.

    +
  • +
  • +

    Frames/No Frames

    +

    These links show and hide the HTML frames. All pages are available with or without frames.

    +
  • +
  • +

    All Classes

    +

    The All Classes link shows all classes and interfaces except non-static nested types.

    +
  • +
  • +

    Serialized Form

    +

    Each serializable or externalizable class has a description of its serialization fields and methods. This information is of interest to re-implementors, not to developers using the API. While there is no link in the navigation bar, you can get to this information by going to any serialized class and clicking "Serialized Form" in the "See also" section of the class description.

    +
  • +
  • +

    Constant Field Values

    +

    The Constant Field Values page lists the static final fields and their values.

    +
  • +
+This help file applies to API documentation generated using the standard doclet.
- - - - - - - - - - - - -
- -
- + + + + + - -
- - - + + diff --git a/java/doc/index-all.html b/java/doc/index-all.html index 81d9b45a..fa92e3c9 100644 --- a/java/doc/index-all.html +++ b/java/doc/index-all.html @@ -1,657 +1,924 @@ - - - - -Index - - - - - - - - - - - -
- - +//--> + + - - - - - - - - - - - - -
- -
- + + + + + - -B C D E F G H I J N O P S T
-

-B

-
-
bufSize(int, int, int) - -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, 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. -
-
-

-C

-
-
cf - -Variable in class org.libjpegturbo.turbojpeg.TJTransform -
Custom filter instance -
close() - -Method in class org.libjpegturbo.turbojpeg.TJCompressor -
Free the native structures associated with this compressor instance. -
close() - -Method in class org.libjpegturbo.turbojpeg.TJDecompressor -
Free the native structures associated with this decompressor instance. -
compress(byte[], int) - -Method in class org.libjpegturbo.turbojpeg.TJCompressor -
Compress the uncompressed source image associated with this compressor - instance and output a JPEG image to the given destination buffer. -
compress(int) - -Method in class org.libjpegturbo.turbojpeg.TJCompressor -
Compress the uncompressed source image associated with this compressor - instance and return a buffer containing a JPEG image. -
compress(BufferedImage, byte[], int) - -Method in class org.libjpegturbo.turbojpeg.TJCompressor -
Compress the uncompressed source image stored in srcImage - and output a JPEG image to the given destination buffer. -
compress(BufferedImage, int) - -Method in class org.libjpegturbo.turbojpeg.TJCompressor -
Compress the uncompressed source image stored in srcImage - and return a buffer containing a JPEG image. -
CS_CMYK - -Static variable in class org.libjpegturbo.turbojpeg.TJ -
CMYK colorspace. -
CS_GRAY - -Static variable in class org.libjpegturbo.turbojpeg.TJ -
Grayscale colorspace. -
CS_RGB - -Static variable in class org.libjpegturbo.turbojpeg.TJ -
RGB colorspace. -
CS_YCbCr - -Static variable in class org.libjpegturbo.turbojpeg.TJ -
YCbCr colorspace. -
CS_YCCK - -Static variable in class org.libjpegturbo.turbojpeg.TJ -
YCCK colorspace. -
customFilter(ShortBuffer, Rectangle, Rectangle, int, int, TJTransform) - -Method in interface org.libjpegturbo.turbojpeg.TJCustomFilter -
A callback function that can be used to modify the DCT coefficients after +
B C D E F G H I J N O P S T Y  + + +

B

+
+
bufSize(int, int, int) - 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, 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. + +
+
+
+ + + +

C

+
+
cf - Variable in class org.libjpegturbo.turbojpeg.TJTransform
+
+
Custom filter instance
+
+
close() - Method in class org.libjpegturbo.turbojpeg.TJCompressor
+
+
Free the native structures associated with this compressor instance.
+
+
close() - Method in class org.libjpegturbo.turbojpeg.TJDecompressor
+
+
Free the native structures associated with this decompressor instance.
+
+
compress(byte[], int) - Method in class org.libjpegturbo.turbojpeg.TJCompressor
+
+
Compress the uncompressed source image associated with this compressor + instance and output a JPEG image to the given destination buffer.
+
+
compress(int) - Method in class org.libjpegturbo.turbojpeg.TJCompressor
+
+
Compress the uncompressed source image associated with this compressor + instance and return a buffer containing a JPEG image.
+
+
compress(BufferedImage, byte[], int) - Method in class org.libjpegturbo.turbojpeg.TJCompressor
+
+ +
+
compress(BufferedImage, int) - Method in class org.libjpegturbo.turbojpeg.TJCompressor
+
+ +
+
CS_CMYK - Static variable in class org.libjpegturbo.turbojpeg.TJ
+
+
CMYK colorspace.
+
+
CS_GRAY - Static variable in class org.libjpegturbo.turbojpeg.TJ
+
+
Grayscale colorspace.
+
+
CS_RGB - Static variable in class org.libjpegturbo.turbojpeg.TJ
+
+
RGB colorspace.
+
+
CS_YCbCr - Static variable in class org.libjpegturbo.turbojpeg.TJ
+
+
YCbCr colorspace.
+
+
CS_YCCK - Static variable in class org.libjpegturbo.turbojpeg.TJ
+
+
YCCK colorspace.
+
+
customFilter(ShortBuffer, Rectangle, Rectangle, int, int, TJTransform) - Method in interface org.libjpegturbo.turbojpeg.TJCustomFilter
+
+
A callback function that can be used to modify the DCT coefficients after they are losslessly transformed but before they are transcoded to a new - JPEG image. -
-
-

-D

-
-
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(byte[], int, int, int, int, int) - -Method in class org.libjpegturbo.turbojpeg.TJDecompressor -
Deprecated. Use - TJDecompressor.decompress(byte[], int, int, int, int, int, int, int) instead. -
decompress(int, 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 the decompressed image. -
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(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(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) - -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(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. -
-
-

-E

-
-
encodeYUV(byte[], 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. -
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. -
encodeYUV(BufferedImage, byte[], int) - -Method in class org.libjpegturbo.turbojpeg.TJCompressor -
Encode the uncompressed source image stored in srcImage - and output a YUV planar image to the given destination buffer. -
encodeYUV(BufferedImage, int) - -Method in class org.libjpegturbo.turbojpeg.TJCompressor -
Encode the uncompressed source image stored in srcImage - and return a buffer containing a YUV planar image. -
equals(TJScalingFactor) - -Method in class org.libjpegturbo.turbojpeg.TJScalingFactor -
Returns true or false, depending on whether this instance and - other have the same numerator and denominator. -
-
-

-F

-
-
finalize() - -Method in class org.libjpegturbo.turbojpeg.TJCompressor -
  -
finalize() - -Method in class org.libjpegturbo.turbojpeg.TJDecompressor -
  -
FLAG_ACCURATEDCT - -Static variable in class org.libjpegturbo.turbojpeg.TJ -
Use the most accurate DCT/IDCT algorithm available in the underlying - codec. -
FLAG_BOTTOMUP - -Static variable in class org.libjpegturbo.turbojpeg.TJ -
The uncompressed source/destination image is stored in bottom-up (Windows, - OpenGL) order, not top-down (X11) order. -
FLAG_FASTDCT - -Static variable in class org.libjpegturbo.turbojpeg.TJ -
Use the fastest DCT/IDCT algorithm available in the underlying codec. -
FLAG_FASTUPSAMPLE - -Static variable in class org.libjpegturbo.turbojpeg.TJ -
When decompressing an image that was compressed using chrominance + JPEG image.
+
+
+ + + +

D

+
+
decompress(byte[], int, int, int, int, int, int, int) - Method in class org.libjpegturbo.turbojpeg.TJDecompressor
+
+
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
+
+ +
+
decompress(int, 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 the decompressed image.
+
+
decompress(int[], int, int, int, int, int, int, int) - Method in class org.libjpegturbo.turbojpeg.TJDecompressor
+
+
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 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 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 into a YUV planar image and store it in the given + YUVImage instance.
+
+
decompressToYUV(byte[], int) - Method in class org.libjpegturbo.turbojpeg.TJDecompressor
+
+ +
+
decompressToYUV(int, int, int, int) - Method in class org.libjpegturbo.turbojpeg.TJDecompressor
+
+
Decompress the JPEG source image associated with this decompressor + instance into a YUV planar image and return a YUVImage + instance containing the decompressed image.
+
+
decompressToYUV(int) - Method in class org.libjpegturbo.turbojpeg.TJDecompressor
+
+ +
+
+ + + +

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. + +
+
+
encodeYUV(int, int) - Method in class org.libjpegturbo.turbojpeg.TJCompressor
+
+
Encode the uncompressed source image associated with this compressor + instance into a YUV planar image and return a YUVImage + instance containing the encoded image.
+
+
encodeYUV(int) - Method in class org.libjpegturbo.turbojpeg.TJCompressor
+
+
Deprecated. + +
+
+
encodeYUV(BufferedImage, byte[], int) - Method in class org.libjpegturbo.turbojpeg.TJCompressor
+
+ +
+
encodeYUV(BufferedImage, int) - Method in class org.libjpegturbo.turbojpeg.TJCompressor
+
+ +
+
equals(TJScalingFactor) - Method in class org.libjpegturbo.turbojpeg.TJScalingFactor
+
+
Returns true or false, depending on whether this instance and + other have the same numerator and denominator.
+
+
+ + + +

F

+
+
finalize() - Method in class org.libjpegturbo.turbojpeg.TJCompressor
+
 
+
finalize() - Method in class org.libjpegturbo.turbojpeg.TJDecompressor
+
 
+
FLAG_ACCURATEDCT - Static variable in class org.libjpegturbo.turbojpeg.TJ
+
+
Use the most accurate DCT/IDCT algorithm available in the underlying + codec.
+
+
FLAG_BOTTOMUP - Static variable in class org.libjpegturbo.turbojpeg.TJ
+
+
The uncompressed source/destination image is stored in bottom-up (Windows, + OpenGL) order, not top-down (X11) order.
+
+
FLAG_FASTDCT - Static variable in class org.libjpegturbo.turbojpeg.TJ
+
+
Use the fastest DCT/IDCT algorithm available in the underlying codec.
+
+
FLAG_FASTUPSAMPLE - Static variable in class org.libjpegturbo.turbojpeg.TJ
+
+
When decompressing an image that was compressed using chrominance subsampling, use the fastest chrominance upsampling algorithm available in - the underlying codec. -
FLAG_FORCEMMX - -Static variable in class org.libjpegturbo.turbojpeg.TJ -
Deprecated.  -
FLAG_FORCESSE - -Static variable in class org.libjpegturbo.turbojpeg.TJ -
Deprecated.  -
FLAG_FORCESSE2 - -Static variable in class org.libjpegturbo.turbojpeg.TJ -
Deprecated.  -
FLAG_FORCESSE3 - -Static variable in class org.libjpegturbo.turbojpeg.TJ -
Deprecated.  -
-
-

-G

-
-
getBlueOffset(int) - -Static method 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. -
getColorspace() - -Method in class org.libjpegturbo.turbojpeg.TJDecompressor -
Returns the colorspace used in the JPEG image 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 - compress/encode operation. -
getDenom() - -Method in class org.libjpegturbo.turbojpeg.TJScalingFactor -
Returns denominator -
getGreenOffset(int) - -Static method in class org.libjpegturbo.turbojpeg.TJ -
For the given pixel format, returns the number of bytes that the green - component is offset from the start of the pixel. -
getHeight() - -Method in class org.libjpegturbo.turbojpeg.TJDecompressor -
Returns the height of the JPEG image associated with this decompressor - instance. -
getJPEGBuf() - -Method in class org.libjpegturbo.turbojpeg.TJDecompressor -
Returns the JPEG image buffer associated with this decompressor instance. -
getJPEGSize() - -Method in class org.libjpegturbo.turbojpeg.TJDecompressor -
Returns the size of the JPEG image (in bytes) associated with this - decompressor instance. -
getMCUHeight(int) - -Static method in class org.libjpegturbo.turbojpeg.TJ -
Returns the MCU block height for the given level of chrominance - subsampling. -
getMCUWidth(int) - -Static method in class org.libjpegturbo.turbojpeg.TJ -
Returns the MCU block width for the given level of chrominance - subsampling. -
getNum() - -Method in class org.libjpegturbo.turbojpeg.TJScalingFactor -
Returns numerator -
getPixelSize(int) - -Static method in class org.libjpegturbo.turbojpeg.TJ -
Returns the pixel size (in bytes) for the given pixel format. -
getRedOffset(int) - -Static method in class org.libjpegturbo.turbojpeg.TJ -
For the given pixel format, returns the number of bytes that the red - component is offset from the start of the pixel. -
getScaled(int) - -Method in class org.libjpegturbo.turbojpeg.TJScalingFactor -
Returns the scaled value of dimension. -
getScaledHeight(int, int) - -Method in class org.libjpegturbo.turbojpeg.TJDecompressor -
Returns the height of the largest scaled-down image that the TurboJPEG + the underlying codec. +
+
FLAG_FORCEMMX - Static variable in class org.libjpegturbo.turbojpeg.TJ
+
+
Deprecated.
+
+
FLAG_FORCESSE - Static variable in class org.libjpegturbo.turbojpeg.TJ
+
+
Deprecated.
+
+
FLAG_FORCESSE2 - Static variable in class org.libjpegturbo.turbojpeg.TJ
+
+
Deprecated.
+
+
FLAG_FORCESSE3 - Static variable in class org.libjpegturbo.turbojpeg.TJ
+
+
Deprecated.
+
+
+ + + +

G

+
+
getBlueOffset(int) - Static method 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 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 + compress/encode operation.
+
+
getDenom() - Method in class org.libjpegturbo.turbojpeg.TJScalingFactor
+
+
Returns denominator
+
+
getGreenOffset(int) - Static method in class org.libjpegturbo.turbojpeg.TJ
+
+
For the given pixel format, returns the number of bytes that the green + component is offset from the start of the pixel.
+
+
getHeight() - Method in class org.libjpegturbo.turbojpeg.TJDecompressor
+
+
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
+
+
Deprecated. + +
+
+
getJPEGSize() - Method in class org.libjpegturbo.turbojpeg.TJDecompressor
+
+
Deprecated. + +
+
+
getMCUHeight(int) - Static method in class org.libjpegturbo.turbojpeg.TJ
+
+
Returns the MCU block height for the given level of chrominance + subsampling.
+
+
getMCUWidth(int) - Static method in class org.libjpegturbo.turbojpeg.TJ
+
+
Returns the MCU block width for the given level of chrominance + subsampling.
+
+
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.
+
+
getRedOffset(int) - Static method in class org.libjpegturbo.turbojpeg.TJ
+
+
For the given pixel format, returns the number of bytes that the red + component is offset from the start of the pixel.
+
+
getScaled(int) - Method in class org.libjpegturbo.turbojpeg.TJScalingFactor
+
+
Returns the scaled value of dimension.
+
+
getScaledHeight(int, int) - Method in class org.libjpegturbo.turbojpeg.TJDecompressor
+
+
Returns the height of the largest scaled-down image that the TurboJPEG decompressor can generate without exceeding the desired image width and - height. -
getScaledWidth(int, int) - -Method in class org.libjpegturbo.turbojpeg.TJDecompressor -
Returns the width of the largest scaled-down image that the TurboJPEG + height. +
+
getScaledWidth(int, int) - Method in class org.libjpegturbo.turbojpeg.TJDecompressor
+
+
Returns the width of the largest scaled-down image that the TurboJPEG decompressor can generate without exceeding the desired image width and - height. -
getScalingFactors() - -Static method in class org.libjpegturbo.turbojpeg.TJ -
Returns a list of fractional scaling factors that the JPEG decompressor in - this implementation of TurboJPEG supports. -
getSubsamp() - -Method in class org.libjpegturbo.turbojpeg.TJDecompressor -
Returns the level of chrominance subsampling used in the JPEG image - associated with this decompressor instance. -
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(). -
getWidth() - -Method in class org.libjpegturbo.turbojpeg.TJDecompressor -
Returns the width of the JPEG image associated with this decompressor - instance. -
-
-

-H

-
-
handle - -Variable in class org.libjpegturbo.turbojpeg.TJDecompressor -
  -
-
-

-I

-
-
isOne() - -Method in class org.libjpegturbo.turbojpeg.TJScalingFactor -
Returns true or false, depending on whether this instance is equal to - 1/1. -
-
-

-J

-
-
jpegBuf - -Variable in class org.libjpegturbo.turbojpeg.TJDecompressor -
  -
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 -
  -
-
-

-N

-
-
NUMCS - -Static variable in class org.libjpegturbo.turbojpeg.TJ -
The number of JPEG colorspaces -
NUMOP - -Static variable in class org.libjpegturbo.turbojpeg.TJTransform -
The number of lossless transform operations -
NUMPF - -Static variable in class org.libjpegturbo.turbojpeg.TJ -
The number of pixel formats -
NUMSAMP - -Static variable in class org.libjpegturbo.turbojpeg.TJ -
The number of chrominance subsampling options -
-
-

-O

-
-
op - -Variable in class org.libjpegturbo.turbojpeg.TJTransform -
Transform operation (one of OP_*) -
OP_HFLIP - -Static variable in class org.libjpegturbo.turbojpeg.TJTransform -
Flip (mirror) image horizontally. -
OP_NONE - -Static variable in class org.libjpegturbo.turbojpeg.TJTransform -
Do not transform the position of the image pixels. -
OP_ROT180 - -Static variable in class org.libjpegturbo.turbojpeg.TJTransform -
Rotate image 180 degrees. -
OP_ROT270 - -Static variable in class org.libjpegturbo.turbojpeg.TJTransform -
Rotate image counter-clockwise by 90 degrees. -
OP_ROT90 - -Static variable in class org.libjpegturbo.turbojpeg.TJTransform -
Rotate image clockwise by 90 degrees. -
OP_TRANSPOSE - -Static variable in class org.libjpegturbo.turbojpeg.TJTransform -
Transpose image (flip/mirror along upper left to lower right axis). -
OP_TRANSVERSE - -Static variable in class org.libjpegturbo.turbojpeg.TJTransform -
Transverse transpose image (flip/mirror along upper right to lower left - axis). -
OP_VFLIP - -Static variable in class org.libjpegturbo.turbojpeg.TJTransform -
Flip (mirror) image vertically. -
OPT_CROP - -Static variable in class org.libjpegturbo.turbojpeg.TJTransform -
This option will enable lossless cropping. -
OPT_GRAY - -Static variable in class org.libjpegturbo.turbojpeg.TJTransform -
This option will discard the color data in the input image and produce - a grayscale output image. -
OPT_NOOUTPUT - -Static variable in class org.libjpegturbo.turbojpeg.TJTransform -
This option will prevent TJTransformer.transform() from outputting a JPEG image for this - particular transform. -
OPT_PERFECT - -Static variable in class org.libjpegturbo.turbojpeg.TJTransform -
This option will cause TJTransformer.transform() to throw an exception if the transform is not - perfect. -
OPT_TRIM - -Static variable in class org.libjpegturbo.turbojpeg.TJTransform -
This option will discard any partial MCU blocks that cannot be - transformed. -
options - -Variable in class org.libjpegturbo.turbojpeg.TJTransform -
Transform options (bitwise OR of one or more of OPT_*) -
org.libjpegturbo.turbojpeg - package org.libjpegturbo.turbojpeg
 
-
-

-P

-
-
PF_ABGR - -Static variable in class org.libjpegturbo.turbojpeg.TJ -
ABGR pixel format. -
PF_ARGB - -Static variable in class org.libjpegturbo.turbojpeg.TJ -
ARGB pixel format. -
PF_BGR - -Static variable in class org.libjpegturbo.turbojpeg.TJ -
BGR pixel format. -
PF_BGRA - -Static variable in class org.libjpegturbo.turbojpeg.TJ -
BGRA pixel format. -
PF_BGRX - -Static variable in class org.libjpegturbo.turbojpeg.TJ -
BGRX pixel format. -
PF_CMYK - -Static variable in class org.libjpegturbo.turbojpeg.TJ -
CMYK pixel format. -
PF_GRAY - -Static variable in class org.libjpegturbo.turbojpeg.TJ -
Grayscale pixel format. -
PF_RGB - -Static variable in class org.libjpegturbo.turbojpeg.TJ -
RGB pixel format. -
PF_RGBA - -Static variable in class org.libjpegturbo.turbojpeg.TJ -
RGBA pixel format. -
PF_RGBX - -Static variable in class org.libjpegturbo.turbojpeg.TJ -
RGBX pixel format. -
PF_XBGR - -Static variable in class org.libjpegturbo.turbojpeg.TJ -
XBGR pixel format. -
PF_XRGB - -Static variable in class org.libjpegturbo.turbojpeg.TJ -
XRGB pixel format. -
-
-

-S

-
-
SAMP_411 - -Static variable in class org.libjpegturbo.turbojpeg.TJ -
4:1:1 chrominance subsampling. -
SAMP_420 - -Static variable in class org.libjpegturbo.turbojpeg.TJ -
4:2:0 chrominance subsampling. -
SAMP_422 - -Static variable in class org.libjpegturbo.turbojpeg.TJ -
4:2:2 chrominance subsampling. -
SAMP_440 - -Static variable in class org.libjpegturbo.turbojpeg.TJ -
4:4:0 chrominance subsampling. -
SAMP_444 - -Static variable in class org.libjpegturbo.turbojpeg.TJ -
4:4:4 chrominance subsampling (no chrominance subsampling). -
SAMP_GRAY - -Static variable in class org.libjpegturbo.turbojpeg.TJ -
Grayscale. -
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. -
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. -
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. -
setSourceImageYUV(byte[], int, int, int) - -Method in class org.libjpegturbo.turbojpeg.TJCompressor -
Associate an uncompressed YUV planar source image with this compressor - 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. -
-
-

-T

-
-
TJ - Class in org.libjpegturbo.turbojpeg
TurboJPEG utility class (cannot be instantiated)
TJ() - -Constructor for class org.libjpegturbo.turbojpeg.TJ -
  -
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 -
Create a TurboJPEG compressor instance and associate the uncompressed - source image stored in srcImage with the newly-created - instance. -
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 - 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. -
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. -
TJScalingFactor - Class in org.libjpegturbo.turbojpeg
Fractional scaling factor
TJScalingFactor(int, int) - -Constructor for class org.libjpegturbo.turbojpeg.TJScalingFactor -
  -
TJTransform - Class in org.libjpegturbo.turbojpeg
Lossless transform parameters
TJTransform() - -Constructor for class org.libjpegturbo.turbojpeg.TJTransform -
Create a new lossless transform instance. -
TJTransform(int, int, int, int, int, int, TJCustomFilter) - -Constructor for class org.libjpegturbo.turbojpeg.TJTransform -
Create a new lossless transform instance with the given parameters. -
TJTransform(Rectangle, int, int, TJCustomFilter) - -Constructor for class org.libjpegturbo.turbojpeg.TJTransform -
Create a new lossless transform instance with the given parameters. -
TJTransformer - Class in org.libjpegturbo.turbojpeg
TurboJPEG lossless transformer
TJTransformer() - -Constructor for class org.libjpegturbo.turbojpeg.TJTransformer -
Create a TurboJPEG lossless transformer instance. -
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. -
TJTransformer(byte[], int) - -Constructor for class org.libjpegturbo.turbojpeg.TJTransformer -
Create a TurboJPEG lossless transformer instance and associate the JPEG + height. +
+
getScalingFactors() - Static 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 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 + generated by the most recent transform operation.
+
+
getWidth() - Method in class org.libjpegturbo.turbojpeg.TJDecompressor
+
+
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.
+
+
+ + + +

H

+
+
handle - Variable in class org.libjpegturbo.turbojpeg.TJDecompressor
+
 
+
handle - Variable in class org.libjpegturbo.turbojpeg.YUVImage
+
 
+
+ + + +

I

+
+
isOne() - Method in class org.libjpegturbo.turbojpeg.TJScalingFactor
+
+
Returns true or false, depending on whether this instance is equal to + 1/1.
+
+
+ + + +

J

+
+
jpegBuf - Variable in class org.libjpegturbo.turbojpeg.TJDecompressor
+
 
+
jpegBufSize - Variable in class org.libjpegturbo.turbojpeg.TJDecompressor
+
 
+
+ + + +

N

+
+
NUMCS - Static variable in class org.libjpegturbo.turbojpeg.TJ
+
+
The number of JPEG colorspaces
+
+
NUMOP - Static variable in class org.libjpegturbo.turbojpeg.TJTransform
+
+
The number of lossless transform operations
+
+
NUMPF - Static variable in class org.libjpegturbo.turbojpeg.TJ
+
+
The number of pixel formats
+
+
NUMSAMP - Static variable in class org.libjpegturbo.turbojpeg.TJ
+
+
The number of chrominance subsampling options
+
+
+ + + +

O

+
+
op - Variable in class org.libjpegturbo.turbojpeg.TJTransform
+
+
Transform operation (one of OP_*)
+
+
OP_HFLIP - Static variable in class org.libjpegturbo.turbojpeg.TJTransform
+
+
Flip (mirror) image horizontally.
+
+
OP_NONE - Static variable in class org.libjpegturbo.turbojpeg.TJTransform
+
+
Do not transform the position of the image pixels.
+
+
OP_ROT180 - Static variable in class org.libjpegturbo.turbojpeg.TJTransform
+
+
Rotate image 180 degrees.
+
+
OP_ROT270 - Static variable in class org.libjpegturbo.turbojpeg.TJTransform
+
+
Rotate image counter-clockwise by 90 degrees.
+
+
OP_ROT90 - Static variable in class org.libjpegturbo.turbojpeg.TJTransform
+
+
Rotate image clockwise by 90 degrees.
+
+
OP_TRANSPOSE - Static variable in class org.libjpegturbo.turbojpeg.TJTransform
+
+
Transpose image (flip/mirror along upper left to lower right axis).
+
+
OP_TRANSVERSE - Static variable in class org.libjpegturbo.turbojpeg.TJTransform
+
+
Transverse transpose image (flip/mirror along upper right to lower left + axis).
+
+
OP_VFLIP - Static variable in class org.libjpegturbo.turbojpeg.TJTransform
+
+
Flip (mirror) image vertically.
+
+
OPT_CROP - Static variable in class org.libjpegturbo.turbojpeg.TJTransform
+
+
This option will enable lossless cropping.
+
+
OPT_GRAY - Static variable in class org.libjpegturbo.turbojpeg.TJTransform
+
+
This option will discard the color data in the input image and produce + a grayscale output image.
+
+
OPT_NOOUTPUT - Static variable in class org.libjpegturbo.turbojpeg.TJTransform
+
+
This option will prevent TJTransformer.transform() from outputting a JPEG image for this + particular transform.
+
+
OPT_PERFECT - Static variable in class org.libjpegturbo.turbojpeg.TJTransform
+
+
This option will cause TJTransformer.transform() to throw an exception if the transform is not + perfect.
+
+
OPT_TRIM - Static variable in class org.libjpegturbo.turbojpeg.TJTransform
+
+
This option will discard any partial MCU blocks that cannot be + transformed.
+
+
options - Variable in class org.libjpegturbo.turbojpeg.TJTransform
+
+
Transform options (bitwise OR of one or more of OPT_*)
+
+
org.libjpegturbo.turbojpeg - package org.libjpegturbo.turbojpeg
+
 
+
+ + + +

P

+
+
PF_ABGR - Static variable in class org.libjpegturbo.turbojpeg.TJ
+
+
ABGR pixel format.
+
+
PF_ARGB - Static variable in class org.libjpegturbo.turbojpeg.TJ
+
+
ARGB pixel format.
+
+
PF_BGR - Static variable in class org.libjpegturbo.turbojpeg.TJ
+
+
BGR pixel format.
+
+
PF_BGRA - Static variable in class org.libjpegturbo.turbojpeg.TJ
+
+
BGRA pixel format.
+
+
PF_BGRX - Static variable in class org.libjpegturbo.turbojpeg.TJ
+
+
BGRX pixel format.
+
+
PF_CMYK - Static variable in class org.libjpegturbo.turbojpeg.TJ
+
+
CMYK pixel format.
+
+
PF_GRAY - Static variable in class org.libjpegturbo.turbojpeg.TJ
+
+
Grayscale pixel format.
+
+
PF_RGB - Static variable in class org.libjpegturbo.turbojpeg.TJ
+
+
RGB pixel format.
+
+
PF_RGBA - Static variable in class org.libjpegturbo.turbojpeg.TJ
+
+
RGBA pixel format.
+
+
PF_RGBX - Static variable in class org.libjpegturbo.turbojpeg.TJ
+
+
RGBX pixel format.
+
+
PF_XBGR - Static variable in class org.libjpegturbo.turbojpeg.TJ
+
+
XBGR pixel format.
+
+
PF_XRGB - Static variable in class org.libjpegturbo.turbojpeg.TJ
+
+
XRGB pixel format.
+
+
+ + + +

S

+
+
SAMP_411 - Static variable in class org.libjpegturbo.turbojpeg.TJ
+
+
4:1:1 chrominance subsampling.
+
+
SAMP_420 - Static variable in class org.libjpegturbo.turbojpeg.TJ
+
+
4:2:0 chrominance subsampling.
+
+
SAMP_422 - Static variable in class org.libjpegturbo.turbojpeg.TJ
+
+
4:2:2 chrominance subsampling.
+
+
SAMP_440 - Static variable in class org.libjpegturbo.turbojpeg.TJ
+
+
4:4:0 chrominance subsampling.
+
+
SAMP_444 - Static variable in class org.libjpegturbo.turbojpeg.TJ
+
+
4:4:4 chrominance subsampling (no chrominance subsampling).
+
+
SAMP_GRAY - Static variable in class org.libjpegturbo.turbojpeg.TJ
+
+
Grayscale.
+
+
setBuf(byte[], int, int, int, int) - Method in class org.libjpegturbo.turbojpeg.YUVImage
+
+
Assign an existing YUV planar image buffer to this YUVImage + instance.
+
+
setJPEGImage(byte[], int) - Method in class org.libjpegturbo.turbojpeg.TJDecompressor
+
+
Deprecated. + +
+
+
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 RGB, grayscale, or CMYK source image with this + compressor instance.
+
+
setSourceImage(byte[], int, int, int, int) - Method in class org.libjpegturbo.turbojpeg.TJCompressor
+
+ +
+
setSourceImage(BufferedImage, int, int, int, int) - Method in class org.libjpegturbo.turbojpeg.TJCompressor
+
+
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.
+
+
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
+
 
+
+ + + +

T

+
+
TJ - Class in org.libjpegturbo.turbojpeg
+
+
TurboJPEG utility class (cannot be instantiated)
+
+
TJ() - Constructor for class org.libjpegturbo.turbojpeg.TJ
+
 
+
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, 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 + instance.
+
+
TJCompressor(byte[], int, int, int, int) - Constructor for class org.libjpegturbo.turbojpeg.TJCompressor
+
+ +
+
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 + 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 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 source image of length imageSize bytes stored in - 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 + 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
+
 
+
TJTransform - Class in org.libjpegturbo.turbojpeg
+
+
Lossless transform parameters
+
+
TJTransform() - Constructor for class org.libjpegturbo.turbojpeg.TJTransform
+
+
Create a new lossless transform instance.
+
+
TJTransform(int, int, int, int, int, int, TJCustomFilter) - Constructor for class org.libjpegturbo.turbojpeg.TJTransform
+
+
Create a new lossless transform instance with the given parameters.
+
+
TJTransform(Rectangle, int, int, TJCustomFilter) - Constructor for class org.libjpegturbo.turbojpeg.TJTransform
+
+
Create a new lossless transform instance with the given parameters.
+
+
TJTransformer - Class in org.libjpegturbo.turbojpeg
+
+
TurboJPEG lossless transformer
+
+
TJTransformer() - Constructor for class org.libjpegturbo.turbojpeg.TJTransformer
+
+
Create a TurboJPEG lossless transformer instance.
+
+
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.
+
+
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.
+
+
transform(byte[][], TJTransform[], int) - Method in class org.libjpegturbo.turbojpeg.TJTransformer
+
+
Losslessly transform the JPEG image associated with this transformer instance into one or more JPEG images stored in the given destination - buffers. -
transform(TJTransform[], int) - -Method in class org.libjpegturbo.turbojpeg.TJTransformer -
Losslessly transform the JPEG image associated with this transformer - instance and return an array of TJDecompressor instances, each of - which has a transformed JPEG image associated with it. -
-
-B C D E F G H I J N O P S T - + buffers. + +
transform(TJTransform[], int) - Method in class org.libjpegturbo.turbojpeg.TJTransformer
+
+
Losslessly transform the JPEG image associated with this transformer + instance and return an array of TJDecompressor instances, each of + which has a transformed JPEG image associated with it.
+
+ + + + +

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/index.html b/java/doc/index.html index 356cd1d9..25a639d4 100644 --- a/java/doc/index.html +++ b/java/doc/index.html @@ -1,11 +1,9 @@ - - - - -Generated Documentation (Untitled) - - - - - - - - -<H2> -Frame Alert</H2> - -<P> -This document is designed to be viewed using the frames feature. If you see this message, you are using a non-frame-capable web client. -<BR> -Link to<A HREF="org/libjpegturbo/turbojpeg/package-summary.html">Non-frame version.</A> - - - + + + + + + +<noscript> +<div>JavaScript is disabled on your browser.</div> +</noscript> +<h2>Frame Alert</h2> +<p>This document is designed to be viewed using the frames feature. If you see this message, you are using a non-frame-capable web client. Link to <a href="org/libjpegturbo/turbojpeg/package-summary.html">Non-frame version</a>.</p> + + + diff --git a/java/doc/org/libjpegturbo/turbojpeg/TJ.html b/java/doc/org/libjpegturbo/turbojpeg/TJ.html index bad022e1..ee22e763 100644 --- a/java/doc/org/libjpegturbo/turbojpeg/TJ.html +++ b/java/doc/org/libjpegturbo/turbojpeg/TJ.html @@ -1,809 +1,712 @@ - - - - -TJ - - - - - - - - - - - -
- - +//--> + + - - - - - - - - - - - - - - - - -
- -
- + + +
+ + +
+ + + - -
-

- -org.libjpegturbo.turbojpeg -
-Class TJ

-
-java.lang.Object
-  extended by org.libjpegturbo.turbojpeg.TJ
-
-
-
-
public final class TJ
extends java.lang.Object
- - -

-TurboJPEG utility class (cannot be instantiated) -

- -

-


- -

+

+
org.libjpegturbo.turbojpeg
+

Class TJ

+
+
+
    +
  • java.lang.Object
  • +
  • +
      +
    • org.libjpegturbo.turbojpeg.TJ
    • +
    +
  • +
+
+
    +
  • +
    +
    +
    public final class TJ
    +extends java.lang.Object
    +
    TurboJPEG utility class (cannot be instantiated)
    +
  • +
+
+
+
    +
  • - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    -Field Summary
    -static intCS_CMYK - -
    -          CMYK colorspace.
    -static intCS_GRAY - -
    -          Grayscale colorspace.
    -static intCS_RGB - -
    -          RGB colorspace.
    -static intCS_YCbCr - -
    -          YCbCr colorspace.
    -static intCS_YCCK - -
    -          YCCK colorspace.
    -static intFLAG_ACCURATEDCT - -
    -          Use the most accurate DCT/IDCT algorithm available in the underlying - codec.
    -static intFLAG_BOTTOMUP - -
    -          The uncompressed source/destination image is stored in bottom-up (Windows, - OpenGL) order, not top-down (X11) order.
    -static intFLAG_FASTDCT - -
    -          Use the fastest DCT/IDCT algorithm available in the underlying codec.
    -static intFLAG_FASTUPSAMPLE - -
    -          When decompressing an image that was compressed using chrominance +
      +
    • + + +

      Field Summary

      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      Fields 
      Modifier and TypeField and Description
      static intCS_CMYK +
      CMYK colorspace.
      +
      static intCS_GRAY +
      Grayscale colorspace.
      +
      static intCS_RGB +
      RGB colorspace.
      +
      static intCS_YCbCr +
      YCbCr colorspace.
      +
      static intCS_YCCK +
      YCCK colorspace.
      +
      static intFLAG_ACCURATEDCT +
      Use the most accurate DCT/IDCT algorithm available in the underlying + codec.
      +
      static intFLAG_BOTTOMUP +
      The uncompressed source/destination image is stored in bottom-up (Windows, + OpenGL) order, not top-down (X11) order.
      +
      static intFLAG_FASTDCT +
      Use the fastest DCT/IDCT algorithm available in the underlying codec.
      +
      static intFLAG_FASTUPSAMPLE +
      When decompressing an image that was compressed using chrominance subsampling, use the fastest chrominance upsampling algorithm available in - the underlying codec.
      -static intFLAG_FORCEMMX - -
      -          Deprecated. 
      -static intFLAG_FORCESSE - -
      -          Deprecated. 
      -static intFLAG_FORCESSE2 - -
      -          Deprecated. 
      -static intFLAG_FORCESSE3 - -
      -          Deprecated. 
      -static intNUMCS - -
      -          The number of JPEG colorspaces
      -static intNUMPF - -
      -          The number of pixel formats
      -static intNUMSAMP - -
      -          The number of chrominance subsampling options
      -static intPF_ABGR - -
      -          ABGR pixel format.
      -static intPF_ARGB - -
      -          ARGB pixel format.
      -static intPF_BGR - -
      -          BGR pixel format.
      -static intPF_BGRA - -
      -          BGRA pixel format.
      -static intPF_BGRX - -
      -          BGRX pixel format.
      -static intPF_CMYK - -
      -          CMYK pixel format.
      -static intPF_GRAY - -
      -          Grayscale pixel format.
      -static intPF_RGB - -
      -          RGB pixel format.
      -static intPF_RGBA - -
      -          RGBA pixel format.
      -static intPF_RGBX - -
      -          RGBX pixel format.
      -static intPF_XBGR - -
      -          XBGR pixel format.
      -static intPF_XRGB - -
      -          XRGB pixel format.
      -static intSAMP_411 - -
      -          4:1:1 chrominance subsampling.
      -static intSAMP_420 - -
      -          4:2:0 chrominance subsampling.
      -static intSAMP_422 - -
      -          4:2:2 chrominance subsampling.
      -static intSAMP_440 - -
      -          4:4:0 chrominance subsampling.
      -static intSAMP_444 - -
      -          4:4:4 chrominance subsampling (no chrominance subsampling).
      -static intSAMP_GRAY - -
      -          Grayscale.
      -  + the underlying codec. +
    static intFLAG_FORCEMMX +
    Deprecated. 
    +
    static intFLAG_FORCESSE +
    Deprecated. 
    +
    static intFLAG_FORCESSE2 +
    Deprecated. 
    +
    static intFLAG_FORCESSE3 +
    Deprecated. 
    +
    static intNUMCS +
    The number of JPEG colorspaces
    +
    static intNUMPF +
    The number of pixel formats
    +
    static intNUMSAMP +
    The number of chrominance subsampling options
    +
    static intPF_ABGR +
    ABGR pixel format.
    +
    static intPF_ARGB +
    ARGB pixel format.
    +
    static intPF_BGR +
    BGR pixel format.
    +
    static intPF_BGRA +
    BGRA pixel format.
    +
    static intPF_BGRX +
    BGRX pixel format.
    +
    static intPF_CMYK +
    CMYK pixel format.
    +
    static intPF_GRAY +
    Grayscale pixel format.
    +
    static intPF_RGB +
    RGB pixel format.
    +
    static intPF_RGBA +
    RGBA pixel format.
    +
    static intPF_RGBX +
    RGBX pixel format.
    +
    static intPF_XBGR +
    XBGR pixel format.
    +
    static intPF_XRGB +
    XRGB pixel format.
    +
    static intSAMP_411 +
    4:1:1 chrominance subsampling.
    +
    static intSAMP_420 +
    4:2:0 chrominance subsampling.
    +
    static intSAMP_422 +
    4:2:2 chrominance subsampling.
    +
    static intSAMP_440 +
    4:4:0 chrominance subsampling.
    +
    static intSAMP_444 +
    4:4:4 chrominance subsampling (no chrominance subsampling).
    +
    static intSAMP_GRAY +
    Grayscale.
    +
    +
  • +
- - - - - - - - - -
-Constructor Summary
TJ() - -
-           
-  +
    +
  • + + +

    Constructor Summary

    + + + + + + + + +
    Constructors 
    Constructor and Description
    TJ() 
    +
  • +
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-Method Summary
-static intbufSize(int width, - int height, - int jpegSubsamp) - -
-          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.
-static intbufSizeYUV(int width, - int height, - int subsamp) - -
-          Deprecated. Use bufSizeYUV(int, int, int, int) instead.
-static intbufSizeYUV(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.
-static intgetBlueOffset(int pixelFormat) - -
-          For the given pixel format, returns the number of bytes that the blue - component is offset from the start of the pixel.
-static intgetGreenOffset(int pixelFormat) - -
-          For the given pixel format, returns the number of bytes that the green - component is offset from the start of the pixel.
-static intgetMCUHeight(int subsamp) - -
-          Returns the MCU block height for the given level of chrominance - subsampling.
-static intgetMCUWidth(int subsamp) - -
-          Returns the MCU block width for the given level of chrominance - subsampling.
-static intgetPixelSize(int pixelFormat) - -
-          Returns the pixel size (in bytes) for the given pixel format.
-static intgetRedOffset(int pixelFormat) - -
-          For the given pixel format, returns the number of bytes that the red - component is offset from the start of the pixel.
-static TJScalingFactor[]getScalingFactors() - -
-          Returns a list of fractional scaling factors that the JPEG decompressor in - this implementation of TurboJPEG supports.
- - - - - - - -
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-  -

- +

    +
  • + + +

    Method Summary

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Methods 
    Modifier and TypeMethod and Description
    static intbufSize(int width, + int height, + int jpegSubsamp) +
    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.
    +
    static intbufSizeYUV(int width, + int height, + int subsamp) +
    Deprecated.  + +
    +
    static intbufSizeYUV(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.
    +
    static intgetBlueOffset(int pixelFormat) +
    For the given pixel format, returns the number of bytes that the blue + component is offset from the start of the pixel.
    +
    static intgetGreenOffset(int pixelFormat) +
    For the given pixel format, returns the number of bytes that the green + component is offset from the start of the pixel.
    +
    static intgetMCUHeight(int subsamp) +
    Returns the MCU block height for the given level of chrominance + subsampling.
    +
    static intgetMCUWidth(int subsamp) +
    Returns the MCU block width for the given level of chrominance + subsampling.
    +
    static intgetPixelSize(int pixelFormat) +
    Returns the pixel size (in bytes) for the given pixel format.
    +
    static intgetRedOffset(int pixelFormat) +
    For the given pixel format, returns the number of bytes that the red + component is offset from the start of the pixel.
    +
    static TJScalingFactor[]getScalingFactors() +
    Returns a list of fractional scaling factors that the JPEG decompressor in + this implementation of TurboJPEG supports.
    +
    +
      +
    • + + +

      Methods inherited from class java.lang.Object

      +clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • +
    +
  • +
+ + +
+
+
    +
  • - - - - - - -
    -Field Detail
    - -

    -NUMSAMP

    -
    -public static final int NUMSAMP
    -
    -
    The number of chrominance subsampling options -

    -

    -
    See Also:
    Constant Field Values
    -
    -
    - -

    -SAMP_444

    -
    -public static final int SAMP_444
    -
    -
    4:4:4 chrominance subsampling (no chrominance subsampling). The JPEG +
      +
    • + + +

      Field Detail

      + + + +
        +
      • +

        NUMSAMP

        +
        public static final int NUMSAMP
        +
        The number of chrominance subsampling options
        +
        See Also:
        Constant Field Values
        +
      • +
      + + + +
        +
      • +

        SAMP_444

        +
        public static final int SAMP_444
        +
        4:4:4 chrominance subsampling (no chrominance subsampling). The JPEG or YUV image will contain one chrominance component for every pixel in the - source image. -

        -

        -
        See Also:
        Constant Field Values
        -
    -
    - -

    -SAMP_422

    -
    -public static final int SAMP_422
    -
    -
    4:2:2 chrominance subsampling. The JPEG or YUV image will contain one - chrominance component for every 2x1 block of pixels in the source image. -

    -

    -
    See Also:
    Constant Field Values
    -
    -
    - -

    -SAMP_420

    -
    -public static final int SAMP_420
    -
    -
    4:2:0 chrominance subsampling. The JPEG or YUV image will contain one - chrominance component for every 2x2 block of pixels in the source image. -

    -

    -
    See Also:
    Constant Field Values
    -
    -
    - -

    -SAMP_GRAY

    -
    -public static final int SAMP_GRAY
    -
    -
    Grayscale. The JPEG or YUV image will contain no chrominance components. -

    -

    -
    See Also:
    Constant Field Values
    -
    -
    - -

    -SAMP_440

    -
    -public static final int SAMP_440
    -
    -
    4:4:0 chrominance subsampling. The JPEG or YUV image will contain one + source image.
+
See Also:
Constant Field Values
+ + + + + +
    +
  • +

    SAMP_422

    +
    public static final int SAMP_422
    +
    4:2:2 chrominance subsampling. The JPEG or YUV image will contain one + chrominance component for every 2x1 block of pixels in the source image.
    +
    See Also:
    Constant Field Values
    +
  • +
+ + + +
    +
  • +

    SAMP_420

    +
    public static final int SAMP_420
    +
    4:2:0 chrominance subsampling. The JPEG or YUV image will contain one + chrominance component for every 2x2 block of pixels in the source image.
    +
    See Also:
    Constant Field Values
    +
  • +
+ + + +
    +
  • +

    SAMP_GRAY

    +
    public static final int SAMP_GRAY
    +
    Grayscale. The JPEG or YUV image will contain no chrominance components.
    +
    See Also:
    Constant Field Values
    +
  • +
+ + + +
    +
  • +

    SAMP_440

    +
    public static final int SAMP_440
    +
    4:4:0 chrominance subsampling. The JPEG or YUV image will contain one chrominance component for every 1x2 block of pixels in the source image. - Note that 4:4:0 subsampling is not fully accelerated in libjpeg-turbo. -

    -

    -
    See Also:
    Constant Field Values
    - -
    - -

    -SAMP_411

    -
    -public static final int SAMP_411
    -
    -
    4:1:1 chrominance subsampling. The JPEG or YUV image will contain one + Note that 4:4:0 subsampling is not fully accelerated in libjpeg-turbo.
    +
    See Also:
    Constant Field Values
    +
  • +
+ + + +
    +
  • +

    SAMP_411

    +
    public static final int SAMP_411
    +
    4:1:1 chrominance subsampling. The JPEG or YUV image will contain one chrominance component for every 4x1 block of pixels in the source image. JPEG images compressed with 4:1:1 subsampling will be almost exactly the same size as those compressed with 4:2:0 subsampling, and in the aggregate, both subsampling methods produce approximately the same perceptual quality. However, 4:1:1 is better able to reproduce sharp horizontal features. Note that 4:1:1 subsampling is not fully accelerated - in libjpeg-turbo. -

    -

    -
    See Also:
    Constant Field Values
    - -
    - -

    -NUMPF

    -
    -public static final int NUMPF
    -
    -
    The number of pixel formats -

    -

    -
    See Also:
    Constant Field Values
    -
    -
    - -

    -PF_RGB

    -
    -public static final int PF_RGB
    -
    -
    RGB pixel format. The red, green, and blue components in the image are + in libjpeg-turbo.
    +
    See Also:
    Constant Field Values
    +
  • +
+ + + +
    +
  • +

    NUMPF

    +
    public static final int NUMPF
    +
    The number of pixel formats
    +
    See Also:
    Constant Field Values
    +
  • +
+ + + +
    +
  • +

    PF_RGB

    +
    public static final int PF_RGB
    +
    RGB pixel format. The red, green, and blue components in the image are stored in 3-byte pixels in the order R, G, B from lowest to highest byte - address within each pixel. -

    -

    -
    See Also:
    Constant Field Values
    - -
    - -

    -PF_BGR

    -
    -public static final int PF_BGR
    -
    -
    BGR pixel format. The red, green, and blue components in the image are + address within each pixel.
    +
    See Also:
    Constant Field Values
    +
  • +
+ + + +
    +
  • +

    PF_BGR

    +
    public static final int PF_BGR
    +
    BGR pixel format. The red, green, and blue components in the image are stored in 3-byte pixels in the order B, G, R from lowest to highest byte - address within each pixel. -

    -

    -
    See Also:
    Constant Field Values
    - -
    - -

    -PF_RGBX

    -
    -public static final int PF_RGBX
    -
    -
    RGBX pixel format. The red, green, and blue components in the image are + address within each pixel.
    +
    See Also:
    Constant Field Values
    +
  • +
+ + + +
    +
  • +

    PF_RGBX

    +
    public static final int PF_RGBX
    +
    RGBX pixel format. The red, green, and blue components in the image are stored in 4-byte pixels in the order R, G, B from lowest to highest byte address within each pixel. The X component is ignored when compressing - and undefined when decompressing. -

    -

    -
    See Also:
    Constant Field Values
    - -
    - -

    -PF_BGRX

    -
    -public static final int PF_BGRX
    -
    -
    BGRX pixel format. The red, green, and blue components in the image are + and undefined when decompressing.
    +
    See Also:
    Constant Field Values
    +
  • +
+ + + +
    +
  • +

    PF_BGRX

    +
    public static final int PF_BGRX
    +
    BGRX pixel format. The red, green, and blue components in the image are stored in 4-byte pixels in the order B, G, R from lowest to highest byte address within each pixel. The X component is ignored when compressing - and undefined when decompressing. -

    -

    -
    See Also:
    Constant Field Values
    - -
    - -

    -PF_XBGR

    -
    -public static final int PF_XBGR
    -
    -
    XBGR pixel format. The red, green, and blue components in the image are + and undefined when decompressing.
    +
    See Also:
    Constant Field Values
    +
  • +
+ + + +
    +
  • +

    PF_XBGR

    +
    public static final int PF_XBGR
    +
    XBGR pixel format. The red, green, and blue components in the image are stored in 4-byte pixels in the order R, G, B from highest to lowest byte address within each pixel. The X component is ignored when compressing - and undefined when decompressing. -

    -

    -
    See Also:
    Constant Field Values
    - -
    - -

    -PF_XRGB

    -
    -public static final int PF_XRGB
    -
    -
    XRGB pixel format. The red, green, and blue components in the image are + and undefined when decompressing.
    +
    See Also:
    Constant Field Values
    +
  • +
+ + + +
    +
  • +

    PF_XRGB

    +
    public static final int PF_XRGB
    +
    XRGB pixel format. The red, green, and blue components in the image are stored in 4-byte pixels in the order B, G, R from highest to lowest byte address within each pixel. The X component is ignored when compressing - and undefined when decompressing. -

    -

    -
    See Also:
    Constant Field Values
    - -
    - -

    -PF_GRAY

    -
    -public static final int PF_GRAY
    -
    -
    Grayscale pixel format. Each 1-byte pixel represents a luminance - (brightness) level from 0 to 255. -

    -

    -
    See Also:
    Constant Field Values
    -
    -
    - -

    -PF_RGBA

    -
    -public static final int PF_RGBA
    -
    -
    RGBA pixel format. This is the same as PF_RGBX, except that when + and undefined when decompressing.
    +
    See Also:
    Constant Field Values
    +
  • +
+ + + +
    +
  • +

    PF_GRAY

    +
    public static final int PF_GRAY
    +
    Grayscale pixel format. Each 1-byte pixel represents a luminance + (brightness) level from 0 to 255.
    +
    See Also:
    Constant Field Values
    +
  • +
+ + + +
    +
  • +

    PF_RGBA

    +
    public static final int PF_RGBA
    +
    RGBA pixel format. This is the same as PF_RGBX, except that when decompressing, the X byte is guaranteed to be 0xFF, which can be - interpreted as an opaque alpha channel. -

    -

    -
    See Also:
    Constant Field Values
    - -
    - -

    -PF_BGRA

    -
    -public static final int PF_BGRA
    -
    -
    BGRA pixel format. This is the same as PF_BGRX, except that when + interpreted as an opaque alpha channel.
    +
    See Also:
    Constant Field Values
    +
  • +
+ + + +
    +
  • +

    PF_BGRA

    +
    public static final int PF_BGRA
    +
    BGRA pixel format. This is the same as PF_BGRX, except that when decompressing, the X byte is guaranteed to be 0xFF, which can be - interpreted as an opaque alpha channel. -

    -

    -
    See Also:
    Constant Field Values
    - -
    - -

    -PF_ABGR

    -
    -public static final int PF_ABGR
    -
    -
    ABGR pixel format. This is the same as PF_XBGR, except that when + interpreted as an opaque alpha channel.
    +
    See Also:
    Constant Field Values
    +
  • +
+ + + +
    +
  • +

    PF_ABGR

    +
    public static final int PF_ABGR
    +
    ABGR pixel format. This is the same as PF_XBGR, except that when decompressing, the X byte is guaranteed to be 0xFF, which can be - interpreted as an opaque alpha channel. -

    -

    -
    See Also:
    Constant Field Values
    - -
    - -

    -PF_ARGB

    -
    -public static final int PF_ARGB
    -
    -
    ARGB pixel format. This is the same as PF_XRGB, except that when + interpreted as an opaque alpha channel.
    +
    See Also:
    Constant Field Values
    +
  • +
+ + + +
    +
  • +

    PF_ARGB

    +
    public static final int PF_ARGB
    +
    ARGB pixel format. This is the same as PF_XRGB, except that when decompressing, the X byte is guaranteed to be 0xFF, which can be - interpreted as an opaque alpha channel. -

    -

    -
    See Also:
    Constant Field Values
    - -
    - -

    -PF_CMYK

    -
    -public static final int PF_CMYK
    -
    -
    CMYK pixel format. Unlike RGB, which is an additive color model used + interpreted as an opaque alpha channel.
    +
    See Also:
    Constant Field Values
    +
  • +
+ + + +
    +
  • +

    PF_CMYK

    +
    public static final int PF_CMYK
    +
    CMYK pixel format. Unlike RGB, which is an additive color model used primarily for display, CMYK (Cyan/Magenta/Yellow/Key) is a subtractive color model used primarily for printing. In the CMYK color model, the value of each color component typically corresponds to an amount of cyan, @@ -814,48 +717,45 @@ public static final int PF_CMYK vice versa, but the mapping is typically not 1:1 or reversible, nor can it be defined with a simple formula. Thus, such a conversion is out of scope for a codec library. However, the TurboJPEG API allows for compressing - CMYK pixels into a YCCK JPEG image (see CS_YCCK) and - decompressing YCCK JPEG images into CMYK pixels. -

    -

    -
    See Also:
    Constant Field Values
    - -
    - -

    -NUMCS

    -
    -public static final int NUMCS
    -
    -
    The number of JPEG colorspaces -

    -

    -
    See Also:
    Constant Field Values
    -
    -
    - -

    -CS_RGB

    -
    -public static final int CS_RGB
    -
    -
    RGB colorspace. When compressing the JPEG image, the R, G, and B + CMYK pixels into a YCCK JPEG image (see CS_YCCK) and + decompressing YCCK JPEG images into CMYK pixels.
    +
    See Also:
    Constant Field Values
    +
  • +
+ + + +
    +
  • +

    NUMCS

    +
    public static final int NUMCS
    +
    The number of JPEG colorspaces
    +
    See Also:
    Constant Field Values
    +
  • +
+ + + +
    +
  • +

    CS_RGB

    +
    public static final int CS_RGB
    +
    RGB colorspace. When compressing the JPEG image, the R, G, and B components in the source image are reordered into image planes, but no colorspace conversion or subsampling is performed. RGB JPEG images can be decompressed to any of the extended RGB pixel formats or grayscale, but - they cannot be decompressed to YUV images. -

    -

    -
    See Also:
    Constant Field Values
    - -
    - -

    -CS_YCbCr

    -
    -public static final int CS_YCbCr
    -
    -
    YCbCr colorspace. YCbCr is not an absolute colorspace but rather a + they cannot be decompressed to YUV images.
    +
    See Also:
    Constant Field Values
    +
  • +
+ + + +
    +
  • +

    CS_YCbCr

    +
    public static final int CS_YCbCr
    +
    YCbCr colorspace. YCbCr is not an absolute colorspace but rather a mathematical transformation of RGB designed solely for storage and transmission. YCbCr images must be converted to RGB before they can actually be displayed. In the YCbCr colorspace, the Y (luminance) @@ -867,457 +767,435 @@ public static final int CS_YCbCr optionally subsampled for the purposes of reducing bandwidth or disk space. YCbCr is the most common JPEG colorspace, and YCbCr JPEG images can be compressed from and decompressed to any of the extended RGB pixel - formats or grayscale, or they can be decompressed to YUV planar images. -

    -

    -
    See Also:
    Constant Field Values
    - -
    - -

    -CS_GRAY

    -
    -public static final int CS_GRAY
    -
    -
    Grayscale colorspace. The JPEG image retains only the luminance data (Y + formats or grayscale, or they can be decompressed to YUV planar images.
    +
    See Also:
    Constant Field Values
    +
  • +
+ + + +
    +
  • +

    CS_GRAY

    +
    public static final int CS_GRAY
    +
    Grayscale colorspace. The JPEG image retains only the luminance data (Y component), and any color data from the source image is discarded. Grayscale JPEG images can be compressed from and decompressed to any of the extended RGB pixel formats or grayscale, or they can be decompressed - to YUV planar images. -

    -

    -
    See Also:
    Constant Field Values
    - -
    - -

    -CS_CMYK

    -
    -public static final int CS_CMYK
    -
    -
    CMYK colorspace. When compressing the JPEG image, the C, M, Y, and K + to YUV planar images.
    +
    See Also:
    Constant Field Values
    +
  • +
+ + + +
    +
  • +

    CS_CMYK

    +
    public static final int CS_CMYK
    +
    CMYK colorspace. When compressing the JPEG image, the C, M, Y, and K components in the source image are reordered into image planes, but no colorspace conversion or subsampling is performed. CMYK JPEG images can - only be decompressed to CMYK pixels. -

    -

    -
    See Also:
    Constant Field Values
    - -
    - -

    -CS_YCCK

    -
    -public static final int CS_YCCK
    -
    -
    YCCK colorspace. YCCK (AKA "YCbCrK") is not an absolute colorspace but + only be decompressed to CMYK pixels.
    +
    See Also:
    Constant Field Values
    +
  • +
+ + + +
    +
  • +

    CS_YCCK

    +
    public static final int CS_YCCK
    +
    YCCK colorspace. YCCK (AKA "YCbCrK") is not an absolute colorspace but rather a mathematical transformation of CMYK designed solely for storage and transmission. It is to CMYK as YCbCr is to RGB. CMYK pixels can be reversibly transformed into YCCK, and as with YCbCr, the chrominance components in the YCCK pixels can be subsampled without incurring major perceptual loss. YCCK JPEG images can only be compressed from and - decompressed to CMYK pixels. -

    -

    -
    See Also:
    Constant Field Values
    - -
    - -

    -FLAG_BOTTOMUP

    -
    -public static final int FLAG_BOTTOMUP
    -
    -
    The uncompressed source/destination image is stored in bottom-up (Windows, - OpenGL) order, not top-down (X11) order. -

    -

    -
    See Also:
    Constant Field Values
    -
    -
    - -

    -FLAG_FORCEMMX

    -
    -@Deprecated
    -public static final int FLAG_FORCEMMX
    -
    -
    Deprecated. 
    -
    See Also:
    Constant Field Values
    -
    -
    - -

    -FLAG_FORCESSE

    -
    -@Deprecated
    -public static final int FLAG_FORCESSE
    -
    -
    Deprecated. 
    -
    See Also:
    Constant Field Values
    -
    -
    - -

    -FLAG_FORCESSE2

    -
    -@Deprecated
    -public static final int FLAG_FORCESSE2
    -
    -
    Deprecated. 
    -
    See Also:
    Constant Field Values
    -
    -
    - -

    -FLAG_FORCESSE3

    -
    -@Deprecated
    -public static final int FLAG_FORCESSE3
    -
    -
    Deprecated. 
    -
    See Also:
    Constant Field Values
    -
    -
    - -

    -FLAG_FASTUPSAMPLE

    -
    -public static final int FLAG_FASTUPSAMPLE
    -
    -
    When decompressing an image that was compressed using chrominance + decompressed to CMYK pixels.
    +
    See Also:
    Constant Field Values
    +
  • +
+ + + +
    +
  • +

    FLAG_BOTTOMUP

    +
    public static final int FLAG_BOTTOMUP
    +
    The uncompressed source/destination image is stored in bottom-up (Windows, + OpenGL) order, not top-down (X11) order.
    +
    See Also:
    Constant Field Values
    +
  • +
+ + + +
    +
  • +

    FLAG_FORCEMMX

    +
    @Deprecated
    +public static final int FLAG_FORCEMMX
    +
    Deprecated. 
    +
    See Also:
    Constant Field Values
    +
  • +
+ + + +
    +
  • +

    FLAG_FORCESSE

    +
    @Deprecated
    +public static final int FLAG_FORCESSE
    +
    Deprecated. 
    +
    See Also:
    Constant Field Values
    +
  • +
+ + + +
    +
  • +

    FLAG_FORCESSE2

    +
    @Deprecated
    +public static final int FLAG_FORCESSE2
    +
    Deprecated. 
    +
    See Also:
    Constant Field Values
    +
  • +
+ + + +
    +
  • +

    FLAG_FORCESSE3

    +
    @Deprecated
    +public static final int FLAG_FORCESSE3
    +
    Deprecated. 
    +
    See Also:
    Constant Field Values
    +
  • +
+ + + +
    +
  • +

    FLAG_FASTUPSAMPLE

    +
    public static final int FLAG_FASTUPSAMPLE
    +
    When decompressing an image that was compressed using chrominance subsampling, use the fastest chrominance upsampling algorithm available in the underlying codec. The default is to use smooth upsampling, which creates a smooth transition between neighboring chrominance components in - order to reduce upsampling artifacts in the decompressed image. -

    -

    -
    See Also:
    Constant Field Values
    - -
    - -

    -FLAG_FASTDCT

    -
    -public static final int FLAG_FASTDCT
    -
    -
    Use the fastest DCT/IDCT algorithm available in the underlying codec. The + order to reduce upsampling artifacts in the decompressed image.
    +
    See Also:
    Constant Field Values
    +
  • +
+ + + +
    +
  • +

    FLAG_FASTDCT

    +
    public static final int FLAG_FASTDCT
    +
    Use the fastest DCT/IDCT algorithm available in the underlying codec. The default if this flag is not specified is implementation-specific. For example, the implementation of TurboJPEG for libjpeg[-turbo] uses the fast algorithm by default when compressing, because this has been shown to have only a very slight effect on accuracy, but it uses the accurate algorithm - when decompressing, because this has been shown to have a larger effect. -

    -

    -
    See Also:
    Constant Field Values
    - -
    - -

    -FLAG_ACCURATEDCT

    -
    -public static final int FLAG_ACCURATEDCT
    -
    -
    Use the most accurate DCT/IDCT algorithm available in the underlying + when decompressing, because this has been shown to have a larger effect.
    +
    See Also:
    Constant Field Values
    +
  • +
+ + + +
    +
  • +

    FLAG_ACCURATEDCT

    +
    public static final int FLAG_ACCURATEDCT
    +
    Use the most accurate DCT/IDCT algorithm available in the underlying codec. The default if this flag is not specified is implementation-specific. For example, the implementation of TurboJPEG for libjpeg[-turbo] uses the fast algorithm by default when compressing, because this has been shown to have only a very slight effect on accuracy, but it uses the accurate algorithm when decompressing, because this has - been shown to have a larger effect. -

    -

    -
    See Also:
    Constant Field Values
    - - + been shown to have a larger effect.
    +
    See Also:
    Constant Field Values
    +
  • +
+ + - - - - - - -
-Constructor Detail
- -

-TJ

-
-public TJ()
-
-
- +
    +
  • + + +

    Constructor Detail

    + + + +
      +
    • +

      TJ

      +
      public TJ()
      +
    • +
    +
  • +
- - - - - - -
-Method Detail
- -

-getMCUWidth

-
-public static int getMCUWidth(int subsamp)
-                       throws java.lang.Exception
-
-
Returns the MCU block width for the given level of chrominance - subsampling. -

-

-
Parameters:
subsamp - the level of chrominance subsampling (one of - SAMP_*) -
Returns:
the MCU block width for the given level of chrominance subsampling -
Throws: -
java.lang.Exception
-
-
-
- -

-getMCUHeight

-
-public static int getMCUHeight(int subsamp)
-                        throws java.lang.Exception
-
-
Returns the MCU block height for the given level of chrominance - subsampling. -

-

-
Parameters:
subsamp - the level of chrominance subsampling (one of - SAMP_*) -
Returns:
the MCU block height for the given level of chrominance - subsampling -
Throws: -
java.lang.Exception
-
-
-
- -

-getPixelSize

-
-public static int getPixelSize(int pixelFormat)
-                        throws java.lang.Exception
-
-
Returns the pixel size (in bytes) for the given pixel format. -

-

-
Parameters:
pixelFormat - the pixel format (one of PF_*) -
Returns:
the pixel size (in bytes) for the given pixel format -
Throws: -
java.lang.Exception
-
-
-
- -

-getRedOffset

-
-public static int getRedOffset(int pixelFormat)
-                        throws java.lang.Exception
-
-
For the given pixel format, returns the number of bytes that the red +
    +
  • + + +

    Method Detail

    + + + +
      +
    • +

      getMCUWidth

      +
      public static int getMCUWidth(int subsamp)
      +                       throws java.lang.Exception
      +
      Returns the MCU block width for the given level of chrominance + subsampling.
      +
      Parameters:
      subsamp - the level of chrominance subsampling (one of + SAMP_*)
      +
      Returns:
      the MCU block width for the given level of chrominance subsampling
      +
      Throws:
      +
      java.lang.Exception
      +
    • +
    + + + +
      +
    • +

      getMCUHeight

      +
      public static int getMCUHeight(int subsamp)
      +                        throws java.lang.Exception
      +
      Returns the MCU block height for the given level of chrominance + subsampling.
      +
      Parameters:
      subsamp - the level of chrominance subsampling (one of + SAMP_*)
      +
      Returns:
      the MCU block height for the given level of chrominance + subsampling
      +
      Throws:
      +
      java.lang.Exception
      +
    • +
    + + + +
      +
    • +

      getPixelSize

      +
      public static int getPixelSize(int pixelFormat)
      +                        throws java.lang.Exception
      +
      Returns the pixel size (in bytes) for the given pixel format.
      +
      Parameters:
      pixelFormat - the pixel format (one of PF_*)
      +
      Returns:
      the pixel size (in bytes) for the given pixel format
      +
      Throws:
      +
      java.lang.Exception
      +
    • +
    + + + +
      +
    • +

      getRedOffset

      +
      public static int getRedOffset(int pixelFormat)
      +                        throws java.lang.Exception
      +
      For the given pixel format, returns the number of bytes that the red component is offset from the start of the pixel. For instance, if a pixel of format TJ.PF_BGRX is stored in char pixel[], then the red component will be - pixel[TJ.getRedOffset(TJ.PF_BGRX)]. -

      -

      -
      Parameters:
      pixelFormat - the pixel format (one of PF_*) -
      Returns:
      the red offset for the given pixel format -
      Throws: -
      java.lang.Exception
      -
      -
-
- -

-getGreenOffset

-
-public static int getGreenOffset(int pixelFormat)
-                          throws java.lang.Exception
-
-
For the given pixel format, returns the number of bytes that the green + pixel[TJ.getRedOffset(TJ.PF_BGRX)].
+
Parameters:
pixelFormat - the pixel format (one of PF_*)
+
Returns:
the red offset for the given pixel format
+
Throws:
+
java.lang.Exception
+ + + + + +
    +
  • +

    getGreenOffset

    +
    public static int getGreenOffset(int pixelFormat)
    +                          throws java.lang.Exception
    +
    For the given pixel format, returns the number of bytes that the green component is offset from the start of the pixel. For instance, if a pixel of format TJ.PF_BGRX is stored in char pixel[], then the green component will be - pixel[TJ.getGreenOffset(TJ.PF_BGRX)]. -

    -

    -
    Parameters:
    pixelFormat - the pixel format (one of PF_*) -
    Returns:
    the green offset for the given pixel format -
    Throws: -
    java.lang.Exception
    -
    - -
    - -

    -getBlueOffset

    -
    -public static int getBlueOffset(int pixelFormat)
    -                         throws java.lang.Exception
    -
    -
    For the given pixel format, returns the number of bytes that the blue + pixel[TJ.getGreenOffset(TJ.PF_BGRX)].
    +
    Parameters:
    pixelFormat - the pixel format (one of PF_*)
    +
    Returns:
    the green offset for the given pixel format
    +
    Throws:
    +
    java.lang.Exception
    +
  • +
+ + + +
    +
  • +

    getBlueOffset

    +
    public static int getBlueOffset(int pixelFormat)
    +                         throws java.lang.Exception
    +
    For the given pixel format, returns the number of bytes that the blue component is offset from the start of the pixel. For instance, if a pixel of format TJ.PF_BGRX is stored in char pixel[], then the blue component will be - pixel[TJ.getBlueOffset(TJ.PF_BGRX)]. -

    -

    -
    Parameters:
    pixelFormat - the pixel format (one of PF_*) -
    Returns:
    the blue offset for the given pixel format -
    Throws: -
    java.lang.Exception
    -
    - -
    - -

    -bufSize

    -
    -public static int bufSize(int width,
    -                          int height,
    -                          int jpegSubsamp)
    -                   throws java.lang.Exception
    -
    -
    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. -

    -

    -
    Parameters:
    width - the width (in pixels) of the JPEG image
    height - the height (in pixels) of the JPEG image
    jpegSubsamp - the level of chrominance subsampling to be used when - generating the JPEG image (one of TJ.SAMP_*) -
    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 -
    Throws: -
    java.lang.Exception
    -
    -
    -
    - -

    -bufSizeYUV

    -
    -public static int bufSizeYUV(int width,
    -                             int pad,
    -                             int height,
    -                             int subsamp)
    -                      throws java.lang.Exception
    -
    -
    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. -

    -

    -
    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 + pixel[TJ.getBlueOffset(TJ.PF_BGRX)].
    +
    Parameters:
    pixelFormat - the pixel format (one of PF_*)
    +
    Returns:
    the blue offset for the given pixel format
    +
    Throws:
    +
    java.lang.Exception
    +
  • +
+ + + +
    +
  • +

    bufSize

    +
    public static int bufSize(int width,
    +          int height,
    +          int jpegSubsamp)
    +                   throws java.lang.Exception
    +
    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.
    +
    Parameters:
    width - the width (in pixels) of the JPEG image
    height - the height (in pixels) of the JPEG image
    jpegSubsamp - the level of chrominance subsampling to be used when + generating the JPEG image (one of TJ.SAMP_*)
    +
    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
    +
    Throws:
    +
    java.lang.Exception
    +
  • +
+ + + +
    +
  • +

    bufSizeYUV

    +
    public static int bufSizeYUV(int width,
    +             int pad,
    +             int height,
    +             int subsamp)
    +                      throws java.lang.Exception
    +
    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.
    +
    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 -
    Throws: -
    java.lang.Exception
    - - -
    - -

    -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

    -
    -public static TJScalingFactor[] getScalingFactors()
    -                                           throws java.lang.Exception
    -
    -
    Returns a list of fractional scaling factors that the JPEG decompressor in - this implementation of TurboJPEG supports. -

    -

    - -
    Returns:
    a list of fractional scaling factors that the JPEG decompressor in - this implementation of TurboJPEG supports -
    Throws: -
    java.lang.Exception
    -
    -
    + 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
    +
    Throws:
    +
    java.lang.Exception
    +
  • +
+ + + +
    +
  • +

    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

    +
    public static TJScalingFactor[] getScalingFactors()
    +                                           throws java.lang.Exception
    +
    Returns a list of fractional scaling factors that the JPEG decompressor in + this implementation of TurboJPEG supports.
    +
    Returns:
    a list of fractional scaling factors that the JPEG decompressor in + this implementation of TurboJPEG supports
    +
    Throws:
    +
    java.lang.Exception
    +
  • +
+ + + + + + -
- - - - - - - - - - - - - - - - - - -
- -
- + + +
+ + +
+ + + - -
- - - + + diff --git a/java/doc/org/libjpegturbo/turbojpeg/TJCompressor.html b/java/doc/org/libjpegturbo/turbojpeg/TJCompressor.html index 35114c70..6c367a70 100644 --- a/java/doc/org/libjpegturbo/turbojpeg/TJCompressor.html +++ b/java/doc/org/libjpegturbo/turbojpeg/TJCompressor.html @@ -1,860 +1,880 @@ - - - - -TJCompressor - - - - - - - - - - - -
- - +//--> + + - - - - - - - - - - - - - - - - -
- -
- + + +
+ + +
+ + + - -
-

- -org.libjpegturbo.turbojpeg -
-Class TJCompressor

-
-java.lang.Object
-  extended by org.libjpegturbo.turbojpeg.TJCompressor
-
-
-
-
public class TJCompressor
extends java.lang.Object
- - -

-TurboJPEG compressor -

- -

-


- -

- +

+
org.libjpegturbo.turbojpeg
+

Class TJCompressor

+
+
+
    +
  • java.lang.Object
  • +
  • +
      +
    • org.libjpegturbo.turbojpeg.TJCompressor
    • +
    +
  • +
+
+
    +
  • +
    +
    +
    public class TJCompressor
    +extends java.lang.Object
    +
    TurboJPEG compressor
    +
  • +
+
+
+
    +
  • - - - - - - - - - - - - - - - -
    -Constructor Summary
    TJCompressor() - -
    -          Create a TurboJPEG compressor instance.
    TJCompressor(byte[] srcImage, - int width, - int pitch, - int height, - int pixelFormat) - -
    -          Create a TurboJPEG compressor instance and associate the uncompressed - source image stored in srcImage with the newly-created - instance.
    TJCompressor(byte[] srcImage, - int x, - int y, - int width, - int pitch, - int height, - int pixelFormat) - -
    -          Create a TurboJPEG compressor instance and associate the uncompressed - source image stored in srcImage with the newly-created - instance.
    -  +
      +
    • + + +

      Constructor Summary

      + + + + + + + + + + + + + + + + + +
      Constructors 
      Constructor and Description
      TJCompressor() +
      Create a TurboJPEG compressor instance.
      +
      TJCompressor(java.awt.image.BufferedImage srcImage, + int x, + int y, + int width, + int height) +
      Create a TurboJPEG compressor instance and associate the uncompressed + source image stored in srcImage with the newly created + instance.
      +
      TJCompressor(byte[] srcImage, + int width, + int pitch, + int height, + int pixelFormat) + +
      TJCompressor(byte[] srcImage, + int x, + int y, + int width, + int pitch, + int height, + int pixelFormat) +
      Create a TurboJPEG compressor instance and associate the uncompressed + source image stored in srcImage with the newly created + instance.
      +
      +
    • +
    - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    -Method Summary
    - voidclose() - -
    -          Free the native structures associated with this compressor instance.
    - voidcompress(java.awt.image.BufferedImage srcImage, +
      +
    • + + +

      Method Summary

      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      Methods 
      Modifier and TypeMethod and Description
      voidclose() +
      Free the native structures associated with this compressor instance.
      +
      voidcompress(java.awt.image.BufferedImage srcImage, + byte[] dstBuf, + int flags) + +
      byte[]compress(java.awt.image.BufferedImage srcImage, + int flags) + +
      voidcompress(byte[] dstBuf, + int flags) +
      Compress the uncompressed source image associated with this compressor + instance and output a JPEG image to the given destination buffer.
      +
      byte[]compress(int flags) +
      Compress the uncompressed source image associated with this compressor + instance and return a buffer containing a JPEG image.
      +
      voidencodeYUV(java.awt.image.BufferedImage srcImage, byte[] dstBuf, - int flags) - -
      -          Compress the uncompressed source image stored in srcImage - and output a JPEG image to the given destination buffer.
      - byte[]compress(java.awt.image.BufferedImage srcImage, - int flags) - -
      -          Compress the uncompressed source image stored in srcImage - and return a buffer containing a JPEG image.
      - voidcompress(byte[] dstBuf, - int flags) - -
      -          Compress the uncompressed source image associated with this compressor - instance and output a JPEG image to the given destination buffer.
      - byte[]compress(int flags) - -
      -          Compress the uncompressed source image associated with this compressor - instance and return a buffer containing a JPEG image.
      - voidencodeYUV(java.awt.image.BufferedImage srcImage, - byte[] dstBuf, - int flags) - -
      -          Encode the uncompressed source image stored in srcImage - and output a YUV planar image to the given destination buffer.
      - byte[]encodeYUV(java.awt.image.BufferedImage srcImage, - int flags) - -
      -          Encode the uncompressed source image stored in srcImage - and return a buffer containing a YUV planar image.
      - voidencodeYUV(byte[] dstBuf, - int flags) - -
      -          Encode the uncompressed source image associated with this compressor - instance and output a YUV planar image to the given destination buffer.
      - byte[]encodeYUV(int flags) - -
      -          Encode the uncompressed source image associated with this compressor - instance and return a buffer containing a YUV planar image.
      -protected  voidfinalize() - -
      -           
      - intgetCompressedSize() - -
      -          Returns the size of the image (in bytes) generated by the most recent - compress/encode operation.
      - voidsetJPEGQuality(int quality) - -
      -          Set the JPEG image quality level for subsequent compress operations.
      - voidsetSourceImage(byte[] srcImage, - int width, - int pitch, - int height, - int pixelFormat) - -
      -          Deprecated. Use - setSourceImage(byte[], int, int, int, int, int, int) instead.
      - voidsetSourceImage(byte[] srcImage, - int x, - int y, - int width, - int pitch, - int height, - int pixelFormat) - -
      -          Associate an uncompressed source image with this compressor instance.
      - voidsetSourceImageYUV(byte[] srcImage, - int width, - int pad, - int height) - -
      -          Associate an uncompressed YUV planar source image with this compressor - instance.
      - voidsetSubsamp(int newSubsamp) - -
      -          Set the level of chrominance subsampling for subsequent compress/encode - operations.
      - voidsetYUVPad(int pad) - -
      -          Set the plane padding for subsequent YUV encode operations.
      - - - - - - - -
      Methods inherited from class java.lang.Object
      clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      -  -

      - + int flags) +

      +
    byte[]encodeYUV(java.awt.image.BufferedImage srcImage, + int flags) + +
    voidencodeYUV(byte[] dstBuf, + int flags) +
    Deprecated.  + +
    +
    byte[]encodeYUV(int flags) +
    Deprecated.  +
    Use encodeYUV(int, int) instead.
    +
    +
    YUVImageencodeYUV(int pad, + int flags) +
    Encode the uncompressed source image associated with this compressor + instance into a YUV planar image and return a YUVImage + instance containing the encoded image.
    +
    voidencodeYUV(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.
    +
    protected voidfinalize() 
    intgetCompressedSize() +
    Returns the size of the image (in bytes) generated by the most recent + compress/encode operation.
    +
    voidsetJPEGQuality(int quality) +
    Set the JPEG image quality level for subsequent compress operations.
    +
    voidsetSourceImage(java.awt.image.BufferedImage srcImage, + int x, + int y, + int width, + int height) +
    Associate an uncompressed RGB or grayscale source image with this + compressor instance.
    +
    voidsetSourceImage(byte[] srcImage, + int width, + int pitch, + int height, + int pixelFormat) + +
    voidsetSourceImage(byte[] srcImage, + int x, + int y, + int width, + int pitch, + int height, + int pixelFormat) +
    Associate an uncompressed RGB, grayscale, or CMYK source image with this + compressor instance.
    +
    voidsetSourceImage(YUVImage srcImage) +
    Associate an uncompressed YUV planar source image with this compressor + instance.
    +
    voidsetSubsamp(int newSubsamp) +
    Set the level of chrominance subsampling for subsequent compress/encode + operations.
    +
    +
      +
    • + + +

      Methods inherited from class java.lang.Object

      +clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • +
    +
  • +
+ + +
+
+
    +
  • - - - - - - -
    -Constructor Detail
    - -

    -TJCompressor

    -
    -public TJCompressor()
    -             throws java.lang.Exception
    -
    -
    Create a TurboJPEG compressor instance. -

    -

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

    -TJCompressor

    -
    -public TJCompressor(byte[] srcImage,
    -                    int width,
    -                    int pitch,
    -                    int height,
    -                    int pixelFormat)
    -             throws java.lang.Exception
    -
    -
    Create a TurboJPEG compressor instance and associate the uncompressed - source image stored in srcImage with the newly-created - instance. -

    -

    -
    Parameters:
    srcImage - 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_*) -
    Throws: -
    java.lang.Exception
    -
    -
    - -

    -TJCompressor

    -
    -public TJCompressor(byte[] srcImage,
    -                    int x,
    -                    int y,
    -                    int width,
    -                    int pitch,
    -                    int height,
    -                    int pixelFormat)
    -             throws java.lang.Exception
    -
    -
    Create a TurboJPEG compressor instance and associate the uncompressed - 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_*) -
    Throws: -
    java.lang.Exception
    -
    - + - - - - - - -
    -Method Detail
    - -

    -setSourceImage

    -
    -public void setSourceImage(byte[] srcImage,
    -                           int x,
    -                           int y,
    -                           int width,
    -                           int pitch,
    -                           int height,
    -                           int pixelFormat)
    -                    throws java.lang.Exception
    -
    -
    Associate an uncompressed 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 +
      +
    • + + +

      Method Detail

      + + + +
        +
      • +

        setSourceImage

        +
        public void setSourceImage(byte[] srcImage,
        +                  int x,
        +                  int y,
        +                  int width,
        +                  int pitch,
        +                  int height,
        +                  int pixelFormat)
        +                    throws java.lang.Exception
        +
        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 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_*) -
        Throws: -
        java.lang.Exception
        -
    -
    -
    - -

    -setSourceImage

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

    -

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

    -setSourceImageYUV

    -
    -public void setSourceImageYUV(byte[] srcImage,
    -                              int width,
    -                              int pad,
    -                              int height)
    -                       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 -
    Throws: -
    java.lang.Exception
    -
    -
    -
    - -

    -setSubsamp

    -
    -public void setSubsamp(int newSubsamp)
    -                throws java.lang.Exception
    -
    -
    Set the level of chrominance subsampling for subsequent compress/encode + 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
    +
  • +
+ + + +
    +
  • +

    setSourceImage

    +
    @Deprecated
    +public void setSourceImage(byte[] srcImage,
    +                             int width,
    +                             int pitch,
    +                             int height,
    +                             int pixelFormat)
    +                    throws java.lang.Exception
    + +
    Throws:
    +
    java.lang.Exception
    +
  • +
+ + + +
    +
  • +

    setSourceImage

    +
    public void setSourceImage(java.awt.image.BufferedImage srcImage,
    +                  int x,
    +                  int y,
    +                  int width,
    +                  int height)
    +                    throws java.lang.Exception
    +
    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 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
    +
  • +
+ + + +
    +
  • +

    setSourceImage

    +
    public void setSourceImage(YUVImage srcImage)
    +                    throws java.lang.Exception
    +
    Associate an uncompressed YUV planar source image with this compressor + instance.
    +
    Parameters:
    srcImage - YUV planar image to be compressed
    +
    Throws:
    +
    java.lang.Exception
    +
  • +
+ + + +
    +
  • +

    setSubsamp

    +
    public void setSubsamp(int newSubsamp)
    +                throws java.lang.Exception
    +
    Set the level of chrominance subsampling for subsequent compress/encode operations. When pixels are converted from RGB to YCbCr (see - TJ.CS_YCbCr) or from CMYK to YCCK (see TJ.CS_YCCK) as part + TJ.CS_YCbCr) or from CMYK to YCCK (see TJ.CS_YCCK) as part of the JPEG compression process, some of the Cb and Cr (chrominance) components can be discarded or averaged together to produce a smaller image with little perceptible loss of image clarity (the human eye is more 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. -

    -

    -
    Parameters:
    newSubsamp - the new level of chrominance subsampling (one of - TJ.SAMP_*) -
    Throws: -
    java.lang.Exception
    -
    - -
    - -

    -setJPEGQuality

    -
    -public void setJPEGQuality(int quality)
    -                    throws java.lang.Exception
    -
    -
    Set the JPEG image quality level for subsequent compress operations. -

    -

    -
    Parameters:
    quality - the new JPEG image quality level (1 to 100, 1 = worst, - 100 = best) -
    Throws: -
    java.lang.Exception
    -
    -
    -
    - -

    -compress

    -
    -public void compress(byte[] dstBuf,
    -                     int flags)
    -              throws java.lang.Exception
    -
    -
    Compress the uncompressed source image associated with this compressor - instance and output a JPEG image to the given destination buffer. -

    -

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

    -compress

    -
    -public byte[] compress(int flags)
    -                throws java.lang.Exception
    -
    -
    Compress the uncompressed source image associated with this compressor - instance and return a buffer containing a JPEG image. -

    -

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

    -compress

    -
    -public void compress(java.awt.image.BufferedImage srcImage,
    -                     byte[] dstBuf,
    -                     int flags)
    -              throws java.lang.Exception
    -
    -
    Compress the uncompressed source image stored in srcImage - and output a JPEG image to the given destination buffer. -

    -

    -
    Parameters:
    srcImage - a BufferedImage instance containing RGB or - grayscale pixels to be compressed
    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_* -
    Throws: -
    java.lang.Exception
    -
    -
    -
    - -

    -compress

    -
    -public byte[] compress(java.awt.image.BufferedImage srcImage,
    + 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 level of chrominance subsampling to use in + subsequent compress/encode oeprations (one of + TJ.SAMP_*)
    +
    Throws:
    +
    java.lang.Exception
    +
  • +
+ + + +
    +
  • +

    setJPEGQuality

    +
    public void setJPEGQuality(int quality)
    +                    throws java.lang.Exception
    +
    Set the JPEG image quality level for subsequent compress operations.
    +
    Parameters:
    quality - the new JPEG image quality level (1 to 100, 1 = worst, + 100 = best)
    +
    Throws:
    +
    java.lang.Exception
    +
  • +
+ + + +
    +
  • +

    compress

    +
    public void compress(byte[] dstBuf,
    +            int flags)
    +              throws java.lang.Exception
    +
    Compress the uncompressed source image associated with this compressor + instance and output a JPEG image to the given destination buffer.
    +
    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 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
    +
  • +
+ + + +
    +
  • +

    compress

    +
    public byte[] compress(int flags)
    +                throws java.lang.Exception
    +
    Compress the uncompressed source image associated with this compressor + instance and return a buffer containing a JPEG image.
    +
    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:
    +
    java.lang.Exception
    +
  • +
+ + + +
    +
  • +

    compress

    +
    @Deprecated
    +public void compress(java.awt.image.BufferedImage srcImage,
    +                       byte[] dstBuf,
                            int flags)
    -                throws java.lang.Exception
    -
    -
    Compress the uncompressed source image stored in srcImage - and return a buffer containing a JPEG image. -

    -

    -
    Parameters:
    srcImage - a BufferedImage instance containing RGB or - grayscale pixels to be compressed
    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: -
    java.lang.Exception
    -
    -
    -
    - -

    -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

    -
    -public void encodeYUV(byte[] dstBuf,
    -                      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. -

    -

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

    -encodeYUV

    -
    -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. -

    -

    -
    Parameters:
    flags - the bitwise OR of one or more of TJ.FLAG_* -
    Returns:
    a buffer containing a YUV planar image -
    Throws: -
    java.lang.Exception
    -
    -
    -
    - -

    -encodeYUV

    -
    -public void encodeYUV(java.awt.image.BufferedImage srcImage,
    -                      byte[] dstBuf,
    -                      int flags)
    -               throws java.lang.Exception
    -
    -
    Encode the uncompressed source image stored in srcImage - and output a YUV planar image to the given destination buffer. See - encodeYUV(byte[], int) for more detail. -

    -

    -
    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, 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
    -
    -
    -
    - -

    -encodeYUV

    -
    -public byte[] encodeYUV(java.awt.image.BufferedImage srcImage,
    +              throws java.lang.Exception
    + +
    Throws:
    +
    java.lang.Exception
    +
  • +
+ + + + + + + +
    +
  • +

    encodeYUV

    +
    public void encodeYUV(YUVImage dstImage,
    +             int flags)
    +               throws java.lang.Exception
    +
    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:
    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
    +
  • +
+ + + +
    +
  • +

    encodeYUV

    +
    @Deprecated
    +public void encodeYUV(byte[] dstBuf,
                             int flags)
    -                 throws java.lang.Exception
    -
    -
    Encode the uncompressed source image stored in srcImage - and return a buffer containing a YUV planar image. See - encodeYUV(byte[], int) for more detail. -

    -

    -
    Parameters:
    srcImage - a BufferedImage instance containing RGB or - grayscale pixels to be encoded
    flags - the bitwise OR of one or more of TJ.FLAG_* -
    Returns:
    a buffer containing a YUV planar image -
    Throws: -
    java.lang.Exception
    -
    -
    -
    - -

    -getCompressedSize

    -
    -public int getCompressedSize()
    -
    -
    Returns the size of the image (in bytes) generated by the most recent - compress/encode operation. -

    -

    - -
    Returns:
    the size of the image (in bytes) generated by the most recent - compress/encode operation
    -
    -
    -
    - -

    -close

    -
    -public void close()
    -           throws java.lang.Exception
    -
    -
    Free the native structures associated with this compressor instance. -

    -

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

    -finalize

    -
    -protected void finalize()
    -                 throws java.lang.Throwable
    -
    -
    -
    Overrides:
    finalize in class java.lang.Object
    -
    -
    - -
    Throws: -
    java.lang.Throwable
    -
    -
    + 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 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:
    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
    +
  • +
+ + + +
    +
  • +

    encodeYUV

    +
    @Deprecated
    +public byte[] encodeYUV(int flags)
    +                 throws java.lang.Exception
    +
    Deprecated. Use encodeYUV(int, int) instead.
    +
    Throws:
    +
    java.lang.Exception
    +
  • +
+ + + + + + + + + + + +
    +
  • +

    getCompressedSize

    +
    public int getCompressedSize()
    +
    Returns the size of the image (in bytes) generated by the most recent + compress/encode operation.
    +
    Returns:
    the size of the image (in bytes) generated by the most recent + compress/encode operation
    +
  • +
+ + + +
    +
  • +

    close

    +
    public void close()
    +           throws java.lang.Exception
    +
    Free the native structures associated with this compressor instance.
    +
    Throws:
    +
    java.lang.Exception
    +
  • +
+ + + +
    +
  • +

    finalize

    +
    protected void finalize()
    +                 throws java.lang.Throwable
    +
    +
    Overrides:
    +
    finalize in class java.lang.Object
    +
    Throws:
    +
    java.lang.Throwable
    +
  • +
+ + + + +
+
-
- - - - - - - - - - - - - - - - - - -
- -
- + + +
+ + +
+ + + - -
- - - + + diff --git a/java/doc/org/libjpegturbo/turbojpeg/TJCustomFilter.html b/java/doc/org/libjpegturbo/turbojpeg/TJCustomFilter.html index 3291c71f..bac519b9 100644 --- a/java/doc/org/libjpegturbo/turbojpeg/TJCustomFilter.html +++ b/java/doc/org/libjpegturbo/turbojpeg/TJCustomFilter.html @@ -1,238 +1,237 @@ - - - - -TJCustomFilter - - - - - - - - - - - -
- - +//--> + + - - - - - - - - - - - - - - - - -
- -
- + + +
+ + +
+ + + - -
-

- -org.libjpegturbo.turbojpeg -
-Interface TJCustomFilter

-
-
-
public interface TJCustomFilter
- - -

-Custom filter callback interface -

- -

-


- -

- +

+
org.libjpegturbo.turbojpeg
+

Interface TJCustomFilter

+
+
+
+
    +
  • +
    +
    +
    public interface TJCustomFilter
    +
    Custom filter callback interface
    +
  • +
+
+
+
    +
  • - - - - - - - - - + +
    -Method Summary
    - voidcustomFilter(java.nio.ShortBuffer coeffBuffer, - java.awt.Rectangle bufferRegion, - java.awt.Rectangle planeRegion, - int componentID, - int transformID, - TJTransform transform) - -
    -          A callback function that can be used to modify the DCT coefficients after +
      +
    • + + +

      Method Summary

      + + + + + + + + + - -
      Methods 
      Modifier and TypeMethod and Description
      voidcustomFilter(java.nio.ShortBuffer coeffBuffer, + java.awt.Rectangle bufferRegion, + java.awt.Rectangle planeRegion, + int componentID, + int transformID, + TJTransform transform) +
      A callback function that can be used to modify the DCT coefficients after they are losslessly transformed but before they are transcoded to a new - JPEG image.
      -  -

      - + JPEG image. +

    +
  • +
+ + +
+
+
    +
  • - - - - - - -
    -Method Detail
    - -

    -customFilter

    -
    -void customFilter(java.nio.ShortBuffer coeffBuffer,
    -                  java.awt.Rectangle bufferRegion,
    -                  java.awt.Rectangle planeRegion,
    -                  int componentID,
    -                  int transformID,
    -                  TJTransform transform)
    -                  throws java.lang.Exception
    -
    -
    A callback function that can be used to modify the DCT coefficients after +
      +
    • + + +

      Method Detail

      + + + +
        +
      • +

        customFilter

        +
        void customFilter(java.nio.ShortBuffer coeffBuffer,
        +                java.awt.Rectangle bufferRegion,
        +                java.awt.Rectangle planeRegion,
        +                int componentID,
        +                int transformID,
        +                TJTransform transform)
        +                  throws java.lang.Exception
        +
        A callback function that can be used to modify the DCT coefficients after they are losslessly transformed but before they are transcoded to a new JPEG image. This allows for custom filters or other transformations to be - applied in the frequency domain. -

        -

        -
        Parameters:
        coeffBuffer - a buffer containing transformed DCT coefficients. + applied in the frequency domain.
        +
        Parameters:
        coeffBuffer - a buffer containing transformed DCT coefficients. (NOTE: this buffer is not guaranteed to be valid once the callback returns, so applications wishing to hand off the DCT coefficients to another function or library should make a copy of them within the body of - the callback.)
        bufferRegion - rectangle containing the width and height of + the callback.)
        bufferRegion - rectangle containing the width and height of coeffBuffer as well as its offset relative to the component plane. TurboJPEG implementations may choose to split each component plane into multiple DCT coefficient buffers and call the callback function once - for each buffer.
        planeRegion - rectangle containing the width and height of the - component plane to which coeffBuffer belongs
        componentID - ID number of the component plane to which + for each buffer.
        planeRegion - rectangle containing the width and height of the + component plane to which coeffBuffer belongs
        componentID - ID number of the component plane to which coeffBuffer belongs (Y, Cb, and Cr have, respectively, ID's - of 0, 1, and 2 in typical JPEG images.)
        transformID - ID number of the transformed image to which + of 0, 1, and 2 in typical JPEG images.)
        transformID - ID number of the transformed image to which coeffBuffer belongs. This is the same as the index of the - transform in the transforms array that was passed to TJTransformer.transform().
        transform - a TJTransform instance that specifies the - parameters and/or cropping region for this transform -
        Throws: -
        java.lang.Exception
        -
    -
    + transform in the transforms array that was passed to TJTransformer.transform().
    transform - a TJTransform instance that specifies the + parameters and/or cropping region for this transform
    +
    Throws:
    +
    java.lang.Exception
    +
  • +
+ + + + +
+
-
- - - - - - - - - - - - - - - - - - -
- -
- + + +
+ + +
+ + + - -
- - - + + diff --git a/java/doc/org/libjpegturbo/turbojpeg/TJDecompressor.html b/java/doc/org/libjpegturbo/turbojpeg/TJDecompressor.html index 2dc3cc62..af6a9020 100644 --- a/java/doc/org/libjpegturbo/turbojpeg/TJDecompressor.html +++ b/java/doc/org/libjpegturbo/turbojpeg/TJDecompressor.html @@ -1,1200 +1,1244 @@ - - - - -TJDecompressor - - - - - - - - - - - -
- - +//--> + + - - - - - - - - - - - - - - - - -
- -
- + + +
+ + +
+ + + - -
-

- -org.libjpegturbo.turbojpeg -
-Class TJDecompressor

-
-java.lang.Object
-  extended by org.libjpegturbo.turbojpeg.TJDecompressor
-
-
-
Direct Known Subclasses:
TJTransformer
-
-
-
-
public class TJDecompressor
extends java.lang.Object
- - -

-TurboJPEG decompressor -

- -

-


- -

+

+
org.libjpegturbo.turbojpeg
+

Class TJDecompressor

+
+
+
    +
  • java.lang.Object
  • +
  • +
      +
    • org.libjpegturbo.turbojpeg.TJDecompressor
    • +
    +
  • +
+
+
    +
  • +
    +
    Direct Known Subclasses:
    +
    TJTransformer
    +
    +
    +
    +
    public class TJDecompressor
    +extends java.lang.Object
    +
    TurboJPEG decompressor
    +
  • +
+
+
+
    +
  • - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -Field Summary
    -protected  longhandle - -
    -           
    -protected  byte[]jpegBuf - -
    -           
    -protected  intjpegBufSize - -
    -           
    -protected  intjpegColorspace - -
    -           
    -protected  intjpegHeight - -
    -           
    -protected  intjpegSubsamp - -
    -           
    -protected  intjpegWidth - -
    -           
    -  + - - - - - - - - - - - - - - - -
    -Constructor Summary
    TJDecompressor() - -
    -          Create a TurboJPEG decompresssor instance.
    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.
    -  +
      +
    • + + +

      Constructor Summary

      + + + + + + + + + + + + + + + + + +
      Constructors 
      Constructor and Description
      TJDecompressor() +
      Create a TurboJPEG decompresssor instance.
      +
      TJDecompressor(byte[] jpegImage) +
      Create a TurboJPEG decompressor instance and associate the JPEG source + image stored in jpegImage with the newly created instance.
      +
      TJDecompressor(byte[] jpegImage, + int imageSize) +
      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 yuvImage) +
      Create a TurboJPEG decompressor instance and associate the YUV planar + source image stored in yuvImage with the newly created + instance.
      +
      +
    • +
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    -Method Summary
    - voidclose() - -
    -          Free the native structures associated with this decompressor instance.
    - voiddecompress(java.awt.image.BufferedImage dstImage, - int flags) - -
    -          Decompress the JPEG source image associated with this decompressor - instance and output a decompressed image to the given - BufferedImage instance.
    - voiddecompress(byte[] dstBuf, - int desiredWidth, - int pitch, - int desiredHeight, - int pixelFormat, - int flags) - -
    -          Deprecated. Use - decompress(byte[], int, int, int, int, int, int, int) instead.
    - voiddecompress(byte[] dstBuf, - int x, - int y, - int desiredWidth, - int pitch, - int desiredHeight, - int pixelFormat, - int flags) - -
    -          Decompress the JPEG source image associated with this decompressor - instance and output a decompressed image to the given destination buffer.
    - voiddecompress(int[] dstBuf, - int x, - int y, - int desiredWidth, - int stride, - int desiredHeight, - int pixelFormat, - int flags) - -
    -          Decompress the JPEG source image associated with this decompressor - instance and output a decompressed image to the given destination buffer.
    - java.awt.image.BufferedImagedecompress(int desiredWidth, - int desiredHeight, - int bufferedImageType, - int flags) - -
    -          Decompress the JPEG source image associated with this decompressor - instance and return a BufferedImage instance containing the - decompressed image.
    - byte[]decompress(int desiredWidth, - int pitch, - int desiredHeight, - int pixelFormat, - int flags) - -
    -          Decompress the JPEG source image associated with this decompressor - instance and return a buffer containing the decompressed image.
    - voiddecompressToYUV(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.
    - byte[]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.
    -protected  voidfinalize() - -
    -           
    - intgetColorspace() - -
    -          Returns the colorspace used in the JPEG image associated with this - decompressor instance.
    - intgetHeight() - -
    -          Returns the height of the JPEG image associated with this decompressor - instance.
    - byte[]getJPEGBuf() - -
    -          Returns the JPEG image buffer associated with this decompressor instance.
    - intgetJPEGSize() - -
    -          Returns the size of the JPEG image (in bytes) associated with this - decompressor instance.
    - intgetScaledHeight(int desiredWidth, - int desiredHeight) - -
    -          Returns the height of the largest scaled-down image that the TurboJPEG +
      +
    • + + +

      Method Summary

      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - + + + + - - - - - - - - - - - - - -
      Methods 
      Modifier and TypeMethod and Description
      voidclose() +
      Free the native structures associated with this decompressor instance.
      +
      voiddecompress(java.awt.image.BufferedImage dstImage, + int flags) +
      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.
      +
      voiddecompress(byte[] dstBuf, + int desiredWidth, + int pitch, + int desiredHeight, + int pixelFormat, + int flags) + +
      voiddecompress(byte[] dstBuf, + int x, + int y, + int desiredWidth, + int pitch, + int desiredHeight, + int pixelFormat, + int flags) +
      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.
      +
      voiddecompress(int[] dstBuf, + int x, + int y, + int desiredWidth, + int stride, + int desiredHeight, + int pixelFormat, + int flags) +
      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.
      +
      java.awt.image.BufferedImagedecompress(int desiredWidth, + int desiredHeight, + int bufferedImageType, + int flags) +
      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.
      +
      byte[]decompress(int desiredWidth, + int pitch, + int desiredHeight, + int pixelFormat, + int flags) +
      Decompress the JPEG source image associated with this decompressor + instance and return a buffer containing the decompressed image.
      +
      voiddecompressToYUV(byte[] dstBuf, + int flags) +
      Deprecated.  + +
      +
      byte[]decompressToYUV(int flags) +
      Deprecated.  + +
      +
      YUVImagedecompressToYUV(int desiredWidth, + int pad, + int desiredHeight, + int 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.
      +
      voiddecompressToYUV(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.
      +
      protected voidfinalize() 
      intgetColorspace() +
      Returns the colorspace used in the source image (JPEG or YUV) associated + with this decompressor instance.
      +
      intgetHeight() +
      Returns the height of the source image (JPEG or YUV) associated with this + decompressor instance.
      +
      byte[]getJPEGBuf() +
      Deprecated.  +
      Use getSourceBuf() instead.
      +
      +
      intgetJPEGSize() +
      Deprecated.  +
      Use getSourceSize() instead.
      +
      +
      intgetScaledHeight(int desiredWidth, + int desiredHeight) +
      Returns the height of the largest scaled-down image that the TurboJPEG decompressor can generate without exceeding the desired image width and - height.
      - intgetScaledWidth(int desiredWidth, - int desiredHeight) - -
      -          Returns the width of the largest scaled-down image that the TurboJPEG + height. +
      intgetScaledWidth(int desiredWidth, + int desiredHeight) +
      Returns the width of the largest scaled-down image that the TurboJPEG decompressor can generate without exceeding the desired image width and - height.
      - intgetSubsamp() - -
      -          Returns the level of chrominance subsampling used in the JPEG image - associated with this decompressor instance.
      - intgetWidth() - -
      -          Returns the width of the JPEG image associated with this decompressor - instance.
      - voidsetJPEGImage(byte[] jpegImage, - int imageSize) - -
      -          Associate the JPEG image of length imageSize bytes stored in - jpegImage with this decompressor instance.
      - - - - - - - -
      Methods inherited from class java.lang.Object
      clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      -  -

      - + height. +

    byte[]getSourceBuf() +
    Returns the source image buffer associated with this decompressor + instance.
    +
    intgetSourceSize() +
    Returns the size of the source image (in bytes) associated with this + decompressor instance.
    +
    intgetSubsamp() +
    Returns the level of chrominance subsampling used in the source image + (JPEG or YUV) associated with this decompressor instance.
    +
    intgetWidth() +
    Returns the width of the source image (JPEG or YUV) associated with this + decompressor instance.
    +
    voidsetJPEGImage(byte[] jpegImage, + int imageSize) +
    Deprecated.  + +
    +
    voidsetSourceImage(byte[] srcImage, + int imageSize) +
    Associate the JPEG image of length imageSize bytes stored in + srcImage with this decompressor instance.
    +
    voidsetSourceImage(YUVImage srcImage) +
    Associate the specified YUV planar source image with this decompressor + instance.
    +
    +
      +
    • + + +

      Methods inherited from class java.lang.Object

      +clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • +
    +
  • +
+ + +
+
+
    +
  • - - - - - - -
    -Field Detail
    - -

    -handle

    -
    -protected long handle
    -
    -
    -
    -
    -
    - -

    -jpegBuf

    -
    -protected byte[] jpegBuf
    -
    -
    -
    -
    -
    - -

    -jpegBufSize

    -
    -protected int jpegBufSize
    -
    -
    -
    -
    -
    - -

    -jpegWidth

    -
    -protected int jpegWidth
    -
    -
    -
    -
    -
    - -

    -jpegHeight

    -
    -protected int jpegHeight
    -
    -
    -
    -
    -
    - -

    -jpegSubsamp

    -
    -protected int jpegSubsamp
    -
    -
    -
    -
    -
    - -

    -jpegColorspace

    -
    -protected int jpegColorspace
    -
    -
    -
    -
    - +
      +
    • + + +

      Field Detail

      + + + +
        +
      • +

        handle

        +
        protected long handle
        +
      • +
      + + + +
        +
      • +

        jpegBuf

        +
        protected byte[] jpegBuf
        +
      • +
      + + + +
        +
      • +

        jpegBufSize

        +
        protected int jpegBufSize
        +
      • +
      + + + +
        +
      • +

        yuvImage

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

        srcWidth

        +
        protected int srcWidth
        +
      • +
      + + + +
        +
      • +

        srcHeight

        +
        protected int srcHeight
        +
      • +
      + + + +
        +
      • +

        srcSubsamp

        +
        protected int srcSubsamp
        +
      • +
      + + + +
        +
      • +

        srcColorspace

        +
        protected int srcColorspace
        +
      • +
      +
    • +
    - - - - - - -
    -Constructor Detail
    - -

    -TJDecompressor

    -
    -public TJDecompressor()
    -               throws java.lang.Exception
    -
    -
    Create a TurboJPEG decompresssor instance. -

    -

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

    -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. -

    -

    -
    Parameters:
    jpegImage - JPEG image buffer (size of the JPEG image is assumed to - be the length of the array) -
    Throws: -
    java.lang.Exception
    -
    -
    - -

    -TJDecompressor

    -
    -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. -

    -

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

      Constructor Detail

      + + + +
        +
      • +

        TJDecompressor

        +
        public TJDecompressor()
        +               throws java.lang.Exception
        +
        Create a TurboJPEG decompresssor instance.
        +
        Throws:
        +
        java.lang.Exception
        +
      • +
      + + + +
        +
      • +

        TJDecompressor

        +
        public TJDecompressor(byte[] jpegImage)
        +               throws java.lang.Exception
        +
        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 + be the length of the array)
        +
        Throws:
        +
        java.lang.Exception
        +
      • +
      + + + +
        +
      • +

        TJDecompressor

        +
        public TJDecompressor(byte[] jpegImage,
        +              int imageSize)
        +               throws java.lang.Exception
        +
        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
        +
      • +
      +
    • +
    - - - - - - -
    -Method Detail
    - -

    -setJPEGImage

    -
    -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. -

    -

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

    -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 JPEG image associated with this decompressor - instance -
    Throws: -
    java.lang.Exception
    -
    -
    -
    - -

    -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 JPEG image associated with this decompressor - instance -
    Throws: -
    java.lang.Exception
    -
    -
    -
    - -

    -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 JPEG image - associated with this decompressor instance -
    Throws: -
    java.lang.Exception
    -
    -
    -
    - -

    -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 JPEG image associated with this - decompressor instance -
    Throws: -
    java.lang.Exception
    -
    -
    -
    - -

    -getJPEGBuf

    -
    -public byte[] getJPEGBuf()
    -                  throws java.lang.Exception
    -
    -
    Returns the JPEG image buffer associated with this decompressor instance. -

    -

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

    -getJPEGSize

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

    -

    - -
    Returns:
    the size of the JPEG image (in bytes) associated with this - decompressor instance -
    Throws: -
    java.lang.Exception
    -
    -
    -
    - -

    -getScaledWidth

    -
    -public int getScaledWidth(int desiredWidth,
    -                          int desiredHeight)
    -                   throws java.lang.Exception
    -
    -
    Returns the width of the largest scaled-down image that the TurboJPEG +
      +
    • + + +

      Method Detail

      + + + +
        +
      • +

        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

        +
        @Deprecated
        +public void setJPEGImage(byte[] jpegImage,
        +                           int imageSize)
        +                  throws java.lang.Exception
        +
        Deprecated. Use setSourceImage(byte[], int) instead.
        +
        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
        +
      • +
      + + + +
        +
      • +

        getWidth

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

        getHeight

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

        getSubsamp

        +
        public int getSubsamp()
        +               throws java.lang.Exception
        +
        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 source image + (JPEG or YUV) associated with this decompressor instance
        +
        Throws:
        +
        java.lang.Exception
        +
      • +
      + + + +
        +
      • +

        getColorspace

        +
        public int getColorspace()
        +                  throws java.lang.Exception
        +
        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 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
        +
      • +
      + + + +
        +
      • +

        getJPEGBuf

        +
        @Deprecated
        +public byte[] getJPEGBuf()
        +                  throws java.lang.Exception
        +
        Deprecated. Use getSourceBuf() instead.
        +
        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
        +
      • +
      + + + +
        +
      • +

        getJPEGSize

        +
        @Deprecated
        +public int getJPEGSize()
        +                throws java.lang.Exception
        +
        Deprecated. Use getSourceSize() instead.
        +
        Throws:
        +
        java.lang.Exception
        +
      • +
      + + + +
        +
      • +

        getScaledWidth

        +
        public int getScaledWidth(int desiredWidth,
        +                 int desiredHeight)
        +                   throws java.lang.Exception
        +
        Returns the width of the largest scaled-down image that the TurboJPEG decompressor can generate without exceeding the desired image width and - height. -

        -

        -
        Parameters:
        desiredWidth - desired width (in pixels) of the decompressed image. + height.
        +
        Parameters:
        desiredWidth - desired width (in pixels) of the decompressed image. 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.)
        desiredHeight - desired height (in pixels) of the decompressed image. + scaled image size.)
        desiredHeight - desired height (in pixels) of the decompressed image. 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.) -
        Returns:
        the width of the largest scaled-down image that the TurboJPEG + the scaled image size.)
        +
        Returns:
        the width of the largest scaled-down image that the TurboJPEG decompressor can generate without exceeding the desired image width and - height -
        Throws: -
        java.lang.Exception
        -
    -
    -
    - -

    -getScaledHeight

    -
    -public int getScaledHeight(int desiredWidth,
    -                           int desiredHeight)
    -                    throws java.lang.Exception
    -
    -
    Returns the height of the largest scaled-down image that the TurboJPEG + height
    +
    Throws:
    +
    java.lang.Exception
    +
  • +
+ + + +
    +
  • +

    getScaledHeight

    +
    public int getScaledHeight(int desiredWidth,
    +                  int desiredHeight)
    +                    throws java.lang.Exception
    +
    Returns the height of the largest scaled-down image that the TurboJPEG decompressor can generate without exceeding the desired image width and - height. -

    -

    -
    Parameters:
    desiredWidth - desired width (in pixels) of the decompressed image. + height.
    +
    Parameters:
    desiredWidth - desired width (in pixels) of the decompressed image. 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.)
    desiredHeight - desired height (in pixels) of the decompressed image. + scaled image size.)
    desiredHeight - desired height (in pixels) of the decompressed image. 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.) -
    Returns:
    the height of the largest scaled-down image that the TurboJPEG + the scaled image size.)
    +
    Returns:
    the height of the largest scaled-down image that the TurboJPEG decompressor can generate without exceeding the desired image width and - height -
    Throws: -
    java.lang.Exception
    - - -
    - -

    -decompress

    -
    -public void decompress(byte[] dstBuf,
    -                       int x,
    -                       int y,
    -                       int desiredWidth,
    -                       int pitch,
    -                       int desiredHeight,
    -                       int pixelFormat,
    -                       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. -

    -

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

    decompress

    +
    public void decompress(byte[] dstBuf,
    +              int x,
    +              int y,
    +              int desiredWidth,
    +              int pitch,
    +              int desiredHeight,
    +              int pixelFormat,
    +              int flags)
    +                throws java.lang.Exception
    +
    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/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). 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 - 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_* -
    Throws: -
    java.lang.Exception
    - - -
    - -

    -decompress

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

    -

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

    -decompress

    -
    -public byte[] decompress(int desiredWidth,
    + 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).  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
    +
  • +
+ + + +
    +
  • +

    decompress

    +
    @Deprecated
    +public void decompress(byte[] dstBuf,
    +                         int desiredWidth,
                              int pitch,
                              int desiredHeight,
                              int pixelFormat,
                              int flags)
    -                  throws java.lang.Exception
    -
    -
    Decompress the JPEG source image associated with this decompressor - instance and return a buffer containing the decompressed image. -

    -

    -
    Parameters:
    desiredWidth - see - decompress(byte[], int, int, int, int, int, int, int) - for description
    pitch - 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
    pixelFormat - pixel format of the decompressed image (one of - TJ.PF_*)
    flags - the bitwise OR of one or more of TJ.FLAG_* -
    Returns:
    a buffer containing the decompressed image -
    Throws: -
    java.lang.Exception
    -
    -
    -
    - -

    -decompressToYUV

    -
    -public void decompressToYUV(byte[] dstBuf,
    -                            int desiredWidth,
    -                            int pad,
    -                            int desiredHeight,
    -                            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. -

    -

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

    decompressToYUV

    +
    public void decompressToYUV(YUVImage dstImage,
    +                   int flags)
    +                     throws java.lang.Exception
    +
    Decompress the JPEG source image associated with this decompressor + 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:
    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
    +
  • +
+ + + +
    +
  • +

    decompressToYUV

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

    decompressToYUV

    +
    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 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 - 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 + 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 + 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

    -
    -@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, int, int, int) for more detail. -

    -

    -
    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
    -
    -
    -
    - -

    -decompressToYUV

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

    -

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

    -decompress

    -
    -public void decompress(int[] dstBuf,
    -                       int x,
    -                       int y,
    -                       int desiredWidth,
    -                       int stride,
    -                       int desiredHeight,
    -                       int pixelFormat,
    -                       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. -

    -

    -
    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 - 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 + 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
    +
  • +
+ + + +
    +
  • +

    decompressToYUV

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

    decompress

    +
    public void decompress(int[] dstBuf,
    +              int x,
    +              int y,
    +              int desiredWidth,
    +              int stride,
    +              int desiredHeight,
    +              int pixelFormat,
    +              int flags)
    +                throws java.lang.Exception
    +
    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/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). 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 - 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_* -
    Throws: -
    java.lang.Exception
    - - -
    - -

    -decompress

    -
    -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. -

    -

    -
    Parameters:
    dstImage - a BufferedImage instance that will receive - the decompressed image
    flags - the bitwise OR of one or more of TJ.FLAG_* -
    Throws: -
    java.lang.Exception
    -
    -
    -
    - -

    -decompress

    -
    -public java.awt.image.BufferedImage decompress(int desiredWidth,
    -                                               int desiredHeight,
    -                                               int bufferedImageType,
    -                                               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. -

    -

    -
    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_* -
    Returns:
    a BufferedImage instance containing the - decompressed image -
    Throws: -
    java.lang.Exception
    -
    -
    -
    - -

    -close

    -
    -public void close()
    -           throws java.lang.Exception
    -
    -
    Free the native structures associated with this decompressor instance. -

    -

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

    -finalize

    -
    -protected void finalize()
    -                 throws java.lang.Throwable
    -
    -
    -
    Overrides:
    finalize in class java.lang.Object
    -
    -
    - -
    Throws: -
    java.lang.Throwable
    -
    -
    + 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). 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
    +
  • +
+ + + +
    +
  • +

    decompress

    +
    public void decompress(java.awt.image.BufferedImage dstImage,
    +              int flags)
    +                throws java.lang.Exception
    +
    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/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
    +
  • +
+ + + +
    +
  • +

    decompress

    +
    public java.awt.image.BufferedImage decompress(int desiredWidth,
    +                                      int desiredHeight,
    +                                      int bufferedImageType,
    +                                      int flags)
    +                                        throws java.lang.Exception
    +
    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 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/decoded image
    +
    Throws:
    +
    java.lang.Exception
    +
  • +
+ + + +
    +
  • +

    close

    +
    public void close()
    +           throws java.lang.Exception
    +
    Free the native structures associated with this decompressor instance.
    +
    Throws:
    +
    java.lang.Exception
    +
  • +
+ + + +
    +
  • +

    finalize

    +
    protected void finalize()
    +                 throws java.lang.Throwable
    +
    +
    Overrides:
    +
    finalize in class java.lang.Object
    +
    Throws:
    +
    java.lang.Throwable
    +
  • +
+ + + + +
+
-
- - - - - - - - - - - - - - - - - - -
- -
- + + +
+ + +
+ + + - -
- - - + + diff --git a/java/doc/org/libjpegturbo/turbojpeg/TJScalingFactor.html b/java/doc/org/libjpegturbo/turbojpeg/TJScalingFactor.html index af29fc56..1b901477 100644 --- a/java/doc/org/libjpegturbo/turbojpeg/TJScalingFactor.html +++ b/java/doc/org/libjpegturbo/turbojpeg/TJScalingFactor.html @@ -1,356 +1,336 @@ - - - - -TJScalingFactor - - - - - - - - - - - -
- - +//--> + + - - - - - - - - - - - - - - - - -
- -
- + + +
+ + +
+ + + - -
-

- -org.libjpegturbo.turbojpeg -
-Class TJScalingFactor

-
-java.lang.Object
-  extended by org.libjpegturbo.turbojpeg.TJScalingFactor
-
-
-
-
public class TJScalingFactor
extends java.lang.Object
- - -

-Fractional scaling factor -

- -

-


- -

- +

+
org.libjpegturbo.turbojpeg
+

Class TJScalingFactor

+
+
+
    +
  • java.lang.Object
  • +
  • +
      +
    • org.libjpegturbo.turbojpeg.TJScalingFactor
    • +
    +
  • +
+
+
    +
  • +
    +
    +
    public class TJScalingFactor
    +extends java.lang.Object
    +
    Fractional scaling factor
    +
  • +
+
+
+
    +
  • - - - - - - - - - -
    -Constructor Summary
    TJScalingFactor(int num, - int denom) - -
    -           
    -  +
      +
    • + + +

      Constructor Summary

      + + + + + + + + +
      Constructors 
      Constructor and Description
      TJScalingFactor(int num, + int denom) 
      +
    • +
    - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -Method Summary
    - booleanequals(TJScalingFactor other) - -
    -          Returns true or false, depending on whether this instance and - other have the same numerator and denominator.
    - intgetDenom() - -
    -          Returns denominator
    - intgetNum() - -
    -          Returns numerator
    - intgetScaled(int dimension) - -
    -          Returns the scaled value of dimension.
    - booleanisOne() - -
    -          Returns true or false, depending on whether this instance is equal to - 1/1.
    - - - - - - - -
    Methods inherited from class java.lang.Object
    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    -  -

    - +

      +
    • + + +

      Method Summary

      + + + + + + + + + + + + + + + + + + + + + + + + + + +
      Methods 
      Modifier and TypeMethod and Description
      booleanequals(TJScalingFactor other) +
      Returns true or false, depending on whether this instance and + other have the same numerator and denominator.
      +
      intgetDenom() +
      Returns denominator
      +
      intgetNum() +
      Returns numerator
      +
      intgetScaled(int dimension) +
      Returns the scaled value of dimension.
      +
      booleanisOne() +
      Returns true or false, depending on whether this instance is equal to + 1/1.
      +
      +
        +
      • + + +

        Methods inherited from class java.lang.Object

        +clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • +
      +
    • +
    +
  • +
+
+
+
    +
  • - - - - - - -
    -Constructor Detail
    - -

    -TJScalingFactor

    -
    -public TJScalingFactor(int num,
    -                       int denom)
    -                throws java.lang.Exception
    -
    -
    - -
    Throws: -
    java.lang.Exception
    -
    - +
      +
    • + + +

      Constructor Detail

      + + + +
        +
      • +

        TJScalingFactor

        +
        public TJScalingFactor(int num,
        +               int denom)
        +                throws java.lang.Exception
        +
        Throws:
        +
        java.lang.Exception
        +
      • +
      +
    • +
    - - - - - - -
    -Method Detail
    - -

    -getNum

    -
    -public int getNum()
    -
    -
    Returns numerator -

    -

    - -
    Returns:
    numerator
    -
    -
    -
    - -

    -getDenom

    -
    -public int getDenom()
    -
    -
    Returns denominator -

    -

    - -
    Returns:
    denominator
    -
    -
    -
    - -

    -getScaled

    -
    -public int getScaled(int dimension)
    -
    -
    Returns the scaled value of dimension. This function +
      +
    • + + +

      Method Detail

      + + + +
        +
      • +

        getNum

        +
        public int getNum()
        +
        Returns numerator
        +
        Returns:
        numerator
        +
      • +
      + + + +
        +
      • +

        getDenom

        +
        public int getDenom()
        +
        Returns denominator
        +
        Returns:
        denominator
        +
      • +
      + + + +
        +
      • +

        getScaled

        +
        public int getScaled(int dimension)
        +
        Returns the scaled value of dimension. This function performs the integer equivalent of - ceil(dimension * scalingFactor). -

        -

        - -
        Returns:
        the scaled value of dimension
        -
        -
    -
    - -

    -equals

    -
    -public boolean equals(TJScalingFactor other)
    -
    -
    Returns true or false, depending on whether this instance and - other have the same numerator and denominator. -

    -

    - -
    Returns:
    true or false, depending on whether this instance and - other have the same numerator and denominator
    -
    -
    -
    - -

    -isOne

    -
    -public boolean isOne()
    -
    -
    Returns true or false, depending on whether this instance is equal to - 1/1. -

    -

    - -
    Returns:
    true or false, depending on whether this instance is equal to - 1/1
    -
    -
    + ceil(dimension * scalingFactor).
+
Returns:
the scaled value of dimension
+ + + + + +
    +
  • +

    equals

    +
    public boolean equals(TJScalingFactor other)
    +
    Returns true or false, depending on whether this instance and + other have the same numerator and denominator.
    +
    Returns:
    true or false, depending on whether this instance and + other have the same numerator and denominator
    +
  • +
+ + + +
    +
  • +

    isOne

    +
    public boolean isOne()
    +
    Returns true or false, depending on whether this instance is equal to + 1/1.
    +
    Returns:
    true or false, depending on whether this instance is equal to + 1/1
    +
  • +
+ + + + +
+ -
- - - - - - - - - - - - - - - - - - -
- -
- + + +
+ + +
+ + + - -
- - - + + diff --git a/java/doc/org/libjpegturbo/turbojpeg/TJTransform.html b/java/doc/org/libjpegturbo/turbojpeg/TJTransform.html index 3a68c9f8..b4bd5cc7 100644 --- a/java/doc/org/libjpegturbo/turbojpeg/TJTransform.html +++ b/java/doc/org/libjpegturbo/turbojpeg/TJTransform.html @@ -1,767 +1,712 @@ - - - - -TJTransform - - - - - - - - - - - -
- - +//--> + + - - - - - - - - - - - - - - - - -
- -
- + + +
+ + +
+ + + - -
-

- -org.libjpegturbo.turbojpeg -
-Class TJTransform

-
-java.lang.Object
-  extended by java.awt.geom.RectangularShape
-      extended by java.awt.geom.Rectangle2D
-          extended by java.awt.Rectangle
-              extended by org.libjpegturbo.turbojpeg.TJTransform
-
-
-
All Implemented Interfaces:
java.awt.Shape, java.io.Serializable, java.lang.Cloneable
-
-
-
-
public class TJTransform
extends java.awt.Rectangle
- - -

-Lossless transform parameters -

- -

-

-
See Also:
Serialized Form
-
- -

+

+
org.libjpegturbo.turbojpeg
+

Class TJTransform

+
+
+
    +
  • java.lang.Object
  • +
  • +
      +
    • java.awt.geom.RectangularShape
    • +
    • +
        +
      • java.awt.geom.Rectangle2D
      • +
      • +
          +
        • java.awt.Rectangle
        • +
        • +
            +
          • org.libjpegturbo.turbojpeg.TJTransform
          • +
          +
        • +
        +
      • +
      +
    • +
    +
  • +
+
+
    +
  • +
    +
    All Implemented Interfaces:
    +
    java.awt.Shape, java.io.Serializable, java.lang.Cloneable
    +
    +
    +
    +
    public class TJTransform
    +extends java.awt.Rectangle
    +
    Lossless transform parameters
    +
    See Also:
    Serialized Form
    +
  • +
+
+
+
    +
  • - - - - - - -
    -Nested Class Summary
    - - - - - - - -
    Nested classes/interfaces inherited from class java.awt.geom.Rectangle2D
    java.awt.geom.Rectangle2D.Double, java.awt.geom.Rectangle2D.Float
    -  +
      +
    • + + +

      Nested Class Summary

      +
        +
      • + + +

        Nested classes/interfaces inherited from class java.awt.geom.Rectangle2D

        +java.awt.geom.Rectangle2D.Double, java.awt.geom.Rectangle2D.Float
      • +
      +
    • +
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -Field Summary
    - TJCustomFiltercf - -
    -          Custom filter instance
    -static intNUMOP - -
    -          The number of lossless transform operations
    - intop - -
    -          Transform operation (one of OP_*)
    -static intOP_HFLIP - -
    -          Flip (mirror) image horizontally.
    -static intOP_NONE - -
    -          Do not transform the position of the image pixels.
    -static intOP_ROT180 - -
    -          Rotate image 180 degrees.
    -static intOP_ROT270 - -
    -          Rotate image counter-clockwise by 90 degrees.
    -static intOP_ROT90 - -
    -          Rotate image clockwise by 90 degrees.
    -static intOP_TRANSPOSE - -
    -          Transpose image (flip/mirror along upper left to lower right axis).
    -static intOP_TRANSVERSE - -
    -          Transverse transpose image (flip/mirror along upper right to lower left - axis).
    -static intOP_VFLIP - -
    -          Flip (mirror) image vertically.
    -static intOPT_CROP - -
    -          This option will enable lossless cropping.
    -static intOPT_GRAY - -
    -          This option will discard the color data in the input image and produce - a grayscale output image.
    -static intOPT_NOOUTPUT - -
    -          This option will prevent TJTransformer.transform() from outputting a JPEG image for this - particular transform.
    -static intOPT_PERFECT - -
    -          This option will cause TJTransformer.transform() to throw an exception if the transform is not - perfect.
    -static intOPT_TRIM - -
    -          This option will discard any partial MCU blocks that cannot be - transformed.
    - intoptions - -
    -          Transform options (bitwise OR of one or more of OPT_*)
    - - - - - - - -
    Fields inherited from class java.awt.Rectangle
    height, width, x, y
    - - - - - - - -
    Fields inherited from class java.awt.geom.Rectangle2D
    OUT_BOTTOM, OUT_LEFT, OUT_RIGHT, OUT_TOP
    -  +
      +
    • + + +

      Field Summary

      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      Fields 
      Modifier and TypeField and Description
      TJCustomFiltercf +
      Custom filter instance
      +
      static intNUMOP +
      The number of lossless transform operations
      +
      intop +
      Transform operation (one of OP_*)
      +
      static intOP_HFLIP +
      Flip (mirror) image horizontally.
      +
      static intOP_NONE +
      Do not transform the position of the image pixels.
      +
      static intOP_ROT180 +
      Rotate image 180 degrees.
      +
      static intOP_ROT270 +
      Rotate image counter-clockwise by 90 degrees.
      +
      static intOP_ROT90 +
      Rotate image clockwise by 90 degrees.
      +
      static intOP_TRANSPOSE +
      Transpose image (flip/mirror along upper left to lower right axis).
      +
      static intOP_TRANSVERSE +
      Transverse transpose image (flip/mirror along upper right to lower left + axis).
      +
      static intOP_VFLIP +
      Flip (mirror) image vertically.
      +
      static intOPT_CROP +
      This option will enable lossless cropping.
      +
      static intOPT_GRAY +
      This option will discard the color data in the input image and produce + a grayscale output image.
      +
      static intOPT_NOOUTPUT +
      This option will prevent TJTransformer.transform() from outputting a JPEG image for this + particular transform.
      +
      static intOPT_PERFECT +
      This option will cause TJTransformer.transform() to throw an exception if the transform is not + perfect.
      +
      static intOPT_TRIM +
      This option will discard any partial MCU blocks that cannot be + transformed.
      +
      intoptions +
      Transform options (bitwise OR of one or more of OPT_*)
      +
      +
        +
      • + + +

        Fields inherited from class java.awt.Rectangle

        +height, width, x, y
      • +
      +
        +
      • + + +

        Fields inherited from class java.awt.geom.Rectangle2D

        +OUT_BOTTOM, OUT_LEFT, OUT_RIGHT, OUT_TOP
      • +
      +
    • +
    - - - - - - - - - - - - - - - -
    -Constructor Summary
    TJTransform() - -
    -          Create a new lossless transform instance.
    TJTransform(int x, - int y, - int w, - int h, - int op, - int options, - TJCustomFilter cf) - -
    -          Create a new lossless transform instance with the given parameters.
    TJTransform(java.awt.Rectangle r, - int op, - int options, - TJCustomFilter cf) - -
    -          Create a new lossless transform instance with the given parameters.
    -  +
      +
    • + + +

      Constructor Summary

      + + + + + + + + + + + + + + +
      Constructors 
      Constructor and Description
      TJTransform() +
      Create a new lossless transform instance.
      +
      TJTransform(int x, + int y, + int w, + int h, + int op, + int options, + TJCustomFilter cf) +
      Create a new lossless transform instance with the given parameters.
      +
      TJTransform(java.awt.Rectangle r, + int op, + int options, + TJCustomFilter cf) +
      Create a new lossless transform instance with the given parameters.
      +
      +
    • +
    - - - - - - -
    -Method Summary
    - - - - - - - -
    Methods inherited from class java.awt.Rectangle
    add, add, add, contains, contains, contains, contains, createIntersection, createUnion, equals, getBounds, getBounds2D, getHeight, getLocation, getSize, getWidth, getX, getY, grow, inside, intersection, intersects, isEmpty, move, outcode, reshape, resize, setBounds, setBounds, setLocation, setLocation, setRect, setSize, setSize, toString, translate, union
    - - - - - - - -
    Methods inherited from class java.awt.geom.Rectangle2D
    add, add, add, contains, contains, getPathIterator, getPathIterator, hashCode, intersect, intersects, intersectsLine, intersectsLine, outcode, setFrame, setRect, union
    - - - - - - - -
    Methods inherited from class java.awt.geom.RectangularShape
    clone, contains, contains, getCenterX, getCenterY, getFrame, getMaxX, getMaxY, getMinX, getMinY, intersects, setFrame, setFrame, setFrameFromCenter, setFrameFromCenter, setFrameFromDiagonal, setFrameFromDiagonal
    - - - - - - - -
    Methods inherited from class java.lang.Object
    finalize, getClass, notify, notifyAll, wait, wait, wait
    - - - - - - - -
    Methods inherited from interface java.awt.Shape
    contains, contains, contains, contains, getPathIterator, getPathIterator, intersects, intersects
    -  -

    - +

      +
    • + + +

      Method Summary

      +
        +
      • + + +

        Methods inherited from class java.awt.Rectangle

        +add, add, add, contains, contains, contains, contains, createIntersection, createUnion, equals, getBounds, getBounds2D, getHeight, getLocation, getSize, getWidth, getX, getY, grow, inside, intersection, intersects, isEmpty, move, outcode, reshape, resize, setBounds, setBounds, setLocation, setLocation, setRect, setSize, setSize, toString, translate, union
      • +
      +
        +
      • + + +

        Methods inherited from class java.awt.geom.Rectangle2D

        +add, add, add, contains, contains, getPathIterator, getPathIterator, hashCode, intersect, intersects, intersectsLine, intersectsLine, outcode, setFrame, setRect, union
      • +
      +
        +
      • + + +

        Methods inherited from class java.awt.geom.RectangularShape

        +clone, contains, contains, getCenterX, getCenterY, getFrame, getMaxX, getMaxY, getMinX, getMinY, intersects, setFrame, setFrame, setFrameFromCenter, setFrameFromCenter, setFrameFromDiagonal, setFrameFromDiagonal
      • +
      +
        +
      • + + +

        Methods inherited from class java.lang.Object

        +finalize, getClass, notify, notifyAll, wait, wait, wait
      • +
      +
        +
      • + + +

        Methods inherited from interface java.awt.Shape

        +contains, contains, contains, contains, getPathIterator, getPathIterator, intersects, intersects
      • +
      +
    • +
    +
  • +
+
+
+
    +
  • - - - - - - -
    -Field Detail
    - -

    -NUMOP

    -
    -public static final int NUMOP
    -
    -
    The number of lossless transform operations -

    -

    -
    See Also:
    Constant Field Values
    -
    -
    - -

    -OP_NONE

    -
    -public static final int OP_NONE
    -
    -
    Do not transform the position of the image pixels. -

    -

    -
    See Also:
    Constant Field Values
    -
    -
    - -

    -OP_HFLIP

    -
    -public static final int OP_HFLIP
    -
    -
    Flip (mirror) image horizontally. This transform is imperfect if there - are any partial MCU blocks on the right edge. -

    -

    -
    See Also:
    OPT_PERFECT, -Constant Field Values
    -
    -
    - -

    -OP_VFLIP

    -
    -public static final int OP_VFLIP
    -
    -
    Flip (mirror) image vertically. This transform is imperfect if there are - any partial MCU blocks on the bottom edge. -

    -

    -
    See Also:
    OPT_PERFECT, -Constant Field Values
    -
    -
    - -

    -OP_TRANSPOSE

    -
    -public static final int OP_TRANSPOSE
    -
    -
    Transpose image (flip/mirror along upper left to lower right axis). This - transform is always perfect. -

    -

    -
    See Also:
    OPT_PERFECT, -Constant Field Values
    -
    -
    - -

    -OP_TRANSVERSE

    -
    -public static final int OP_TRANSVERSE
    -
    -
    Transverse transpose image (flip/mirror along upper right to lower left +
      +
    • + + +

      Field Detail

      + + + +
        +
      • +

        NUMOP

        +
        public static final int NUMOP
        +
        The number of lossless transform operations
        +
        See Also:
        Constant Field Values
        +
      • +
      + + + +
        +
      • +

        OP_NONE

        +
        public static final int OP_NONE
        +
        Do not transform the position of the image pixels.
        +
        See Also:
        Constant Field Values
        +
      • +
      + + + +
        +
      • +

        OP_HFLIP

        +
        public static final int OP_HFLIP
        +
        Flip (mirror) image horizontally. This transform is imperfect if there + are any partial MCU blocks on the right edge.
        +
        See Also:
        OPT_PERFECT, +Constant Field Values
        +
      • +
      + + + +
        +
      • +

        OP_VFLIP

        +
        public static final int OP_VFLIP
        +
        Flip (mirror) image vertically. This transform is imperfect if there are + any partial MCU blocks on the bottom edge.
        +
        See Also:
        OPT_PERFECT, +Constant Field Values
        +
      • +
      + + + +
        +
      • +

        OP_TRANSPOSE

        +
        public static final int OP_TRANSPOSE
        +
        Transpose image (flip/mirror along upper left to lower right axis). This + transform is always perfect.
        +
        See Also:
        OPT_PERFECT, +Constant Field Values
        +
      • +
      + + + +
        +
      • +

        OP_TRANSVERSE

        +
        public static final int OP_TRANSVERSE
        +
        Transverse transpose image (flip/mirror along upper right to lower left axis). This transform is imperfect if there are any partial MCU blocks in - the image. -

        -

        -
        See Also:
        OPT_PERFECT, -Constant Field Values
        -
    -
    - -

    -OP_ROT90

    -
    -public static final int OP_ROT90
    -
    -
    Rotate image clockwise by 90 degrees. This transform is imperfect if - there are any partial MCU blocks on the bottom edge. -

    -

    -
    See Also:
    OPT_PERFECT, -Constant Field Values
    -
    -
    - -

    -OP_ROT180

    -
    -public static final int OP_ROT180
    -
    -
    Rotate image 180 degrees. This transform is imperfect if there are any - partial MCU blocks in the image. -

    -

    -
    See Also:
    OPT_PERFECT, -Constant Field Values
    -
    -
    - -

    -OP_ROT270

    -
    -public static final int OP_ROT270
    -
    -
    Rotate image counter-clockwise by 90 degrees. This transform is imperfect - if there are any partial MCU blocks on the right edge. -

    -

    -
    See Also:
    OPT_PERFECT, -Constant Field Values
    -
    -
    - -

    -OPT_PERFECT

    -
    -public static final int OPT_PERFECT
    -
    -
    This option will cause TJTransformer.transform() to throw an exception if the transform is not + the image.
+
See Also:
OPT_PERFECT, +Constant Field Values
+ + + + + +
    +
  • +

    OP_ROT90

    +
    public static final int OP_ROT90
    +
    Rotate image clockwise by 90 degrees. This transform is imperfect if + there are any partial MCU blocks on the bottom edge.
    +
    See Also:
    OPT_PERFECT, +Constant Field Values
    +
  • +
+ + + +
    +
  • +

    OP_ROT180

    +
    public static final int OP_ROT180
    +
    Rotate image 180 degrees. This transform is imperfect if there are any + partial MCU blocks in the image.
    +
    See Also:
    OPT_PERFECT, +Constant Field Values
    +
  • +
+ + + +
    +
  • +

    OP_ROT270

    +
    public static final int OP_ROT270
    +
    Rotate image counter-clockwise by 90 degrees. This transform is imperfect + if there are any partial MCU blocks on the right edge.
    +
    See Also:
    OPT_PERFECT, +Constant Field Values
    +
  • +
+ + + +
    +
  • +

    OPT_PERFECT

    +
    public static final int OPT_PERFECT
    +
    This option will cause TJTransformer.transform() to throw an exception if the transform is not perfect. Lossless transforms operate on MCU blocks, whose size depends on the level of chrominance subsampling used. If the image's width or height - is not evenly divisible by the MCU block size (see TJ.getMCUWidth(int) - and TJ.getMCUHeight(int)), then there will be partial MCU blocks on the + is not evenly divisible by the MCU block size (see TJ.getMCUWidth(int) + and TJ.getMCUHeight(int)), then there will be partial MCU blocks on the right and/or bottom edges. It is not possible to move these partial MCU blocks to the top or left of the image, so any transform that would require that is "imperfect." If this option is not specified, then any partial MCU blocks that cannot be transformed will be left in place, which - will create odd-looking strips on the right or bottom edge of the image. -

    -

    -
    See Also:
    Constant Field Values
    - -
    - -

    -OPT_TRIM

    -
    -public static final int OPT_TRIM
    -
    -
    This option will discard any partial MCU blocks that cannot be - transformed. -

    -

    -
    See Also:
    Constant Field Values
    -
    -
    - -

    -OPT_CROP

    -
    -public static final int OPT_CROP
    -
    -
    This option will enable lossless cropping. -

    -

    -
    See Also:
    Constant Field Values
    -
    -
    - -

    -OPT_GRAY

    -
    -public static final int OPT_GRAY
    -
    -
    This option will discard the color data in the input image and produce - a grayscale output image. -

    -

    -
    See Also:
    Constant Field Values
    -
    -
    - -

    -OPT_NOOUTPUT

    -
    -public static final int OPT_NOOUTPUT
    -
    -
    This option will prevent TJTransformer.transform() from outputting a JPEG image for this + will create odd-looking strips on the right or bottom edge of the image.
    +
    See Also:
    Constant Field Values
    +
  • +
+ + + +
    +
  • +

    OPT_TRIM

    +
    public static final int OPT_TRIM
    +
    This option will discard any partial MCU blocks that cannot be + transformed.
    +
    See Also:
    Constant Field Values
    +
  • +
+ + + +
    +
  • +

    OPT_CROP

    +
    public static final int OPT_CROP
    +
    This option will enable lossless cropping.
    +
    See Also:
    Constant Field Values
    +
  • +
+ + + +
    +
  • +

    OPT_GRAY

    +
    public static final int OPT_GRAY
    +
    This option will discard the color data in the input image and produce + a grayscale output image.
    +
    See Also:
    Constant Field Values
    +
  • +
+ + + +
    +
  • +

    OPT_NOOUTPUT

    +
    public static final int OPT_NOOUTPUT
    +
    This option will prevent TJTransformer.transform() from outputting a JPEG image for this particular transform. This can be used in conjunction with a custom filter to capture the transformed DCT coefficients without transcoding - them. -

    -

    -
    See Also:
    Constant Field Values
    - -
    - -

    -op

    -
    -public int op
    -
    -
    Transform operation (one of OP_*) -

    -

    -
    -
    -
    - -

    -options

    -
    -public int options
    -
    -
    Transform options (bitwise OR of one or more of OPT_*) -

    -

    -
    -
    -
    - -

    -cf

    -
    -public TJCustomFilter cf
    -
    -
    Custom filter instance -

    -

    -
    -
    - + them.
    +
    See Also:
    Constant Field Values
    +
  • +
+ + + +
    +
  • +

    op

    +
    public int op
    +
    Transform operation (one of OP_*)
    +
  • +
+ + + +
    +
  • +

    options

    +
    public int options
    +
    Transform options (bitwise OR of one or more of OPT_*)
    +
  • +
+ + + + + + - - - - - - -
-Constructor Detail
- -

-TJTransform

-
-public TJTransform()
-
-
Create a new lossless transform instance. -

-

-
- -

-TJTransform

-
-public TJTransform(int x,
-                   int y,
-                   int w,
-                   int h,
-                   int op,
-                   int options,
-                   TJCustomFilter cf)
-            throws java.lang.Exception
-
-
Create a new lossless transform instance with the given parameters. -

-

-
Parameters:
x - the left boundary of the cropping region. This must be evenly - divisible by the MCU block width (see TJ.getMCUWidth(int))
y - the upper boundary of the cropping region. This must be evenly - divisible by the MCU block height (see TJ.getMCUHeight(int))
w - the width of the cropping region. Setting this to 0 is the +
    +
  • + + +

    Constructor Detail

    + + + +
      +
    • +

      TJTransform

      +
      public TJTransform()
      +
      Create a new lossless transform instance.
      +
    • +
    + + + +
      +
    • +

      TJTransform

      +
      public TJTransform(int x,
      +           int y,
      +           int w,
      +           int h,
      +           int op,
      +           int options,
      +           TJCustomFilter cf)
      +            throws java.lang.Exception
      +
      Create a new lossless transform instance with the given parameters.
      +
      Parameters:
      x - the left boundary of the cropping region. This must be evenly + divisible by the MCU block width (see TJ.getMCUWidth(int))
      y - the upper boundary of the cropping region. This must be evenly + divisible by the MCU block height (see TJ.getMCUHeight(int))
      w - the width of the cropping region. Setting this to 0 is the equivalent of setting it to (width of the source JPEG image - - x).
      h - the height of the cropping region. Setting this to 0 is the + x).
      h - the height of the cropping region. Setting this to 0 is the equivalent of setting it to (height of the source JPEG image - - y).
      op - one of the transform operations (OP_*)
      options - the bitwise OR of one or more of the transform options - (OPT_*)
      cf - an instance of an object that implements the TJCustomFilter interface, or null if no custom filter is needed -
      Throws: -
      java.lang.Exception
      -
-
- -

-TJTransform

-
-public TJTransform(java.awt.Rectangle r,
-                   int op,
-                   int options,
-                   TJCustomFilter cf)
-            throws java.lang.Exception
-
-
Create a new lossless transform instance with the given parameters. -

-

-
Parameters:
r - a Rectangle instance that specifies the cropping - region. See TJTransform(int, int, int, int, int, int, TJCustomFilter) for more - detail.
op - one of the transform operations (OP_*)
options - the bitwise OR of one or more of the transform options - (OPT_*)
cf - an instance of an object that implements the TJCustomFilter interface, or null if no custom filter is needed -
Throws: -
java.lang.Exception
-
+ y).
op - one of the transform operations (OP_*)
options - the bitwise OR of one or more of the transform options + (OPT_*)
cf - an instance of an object that implements the TJCustomFilter interface, or null if no custom filter is needed
+
Throws:
+
java.lang.Exception
+ + + + + +
    +
  • +

    TJTransform

    +
    public TJTransform(java.awt.Rectangle r,
    +           int op,
    +           int options,
    +           TJCustomFilter cf)
    +            throws java.lang.Exception
    +
    Create a new lossless transform instance with the given parameters.
    +
    Parameters:
    r - a Rectangle instance that specifies the cropping + region. See TJTransform(int, int, int, int, int, int, TJCustomFilter) for more + detail.
    op - one of the transform operations (OP_*)
    options - the bitwise OR of one or more of the transform options + (OPT_*)
    cf - an instance of an object that implements the TJCustomFilter interface, or null if no custom filter is needed
    +
    Throws:
    +
    java.lang.Exception
    +
  • +
+ + + + +
+ -
- - - - - - - - - - - - - - - - - - -
- -
- + + +
+ + +
+ + + - -
- - - + + diff --git a/java/doc/org/libjpegturbo/turbojpeg/TJTransformer.html b/java/doc/org/libjpegturbo/turbojpeg/TJTransformer.html index 0811b51f..3be18ec6 100644 --- a/java/doc/org/libjpegturbo/turbojpeg/TJTransformer.html +++ b/java/doc/org/libjpegturbo/turbojpeg/TJTransformer.html @@ -1,301 +1,291 @@ - - - - -TJTransformer - - - - - - - - - - - -
- - +//--> + + - - - - - - - - - - - - - - - - -
- -
- + + +
+ + +
+ + + - -
-

- -org.libjpegturbo.turbojpeg -
-Class TJTransformer

-
-java.lang.Object
-  extended by org.libjpegturbo.turbojpeg.TJDecompressor
-      extended by org.libjpegturbo.turbojpeg.TJTransformer
-
-
-
-
public class TJTransformer
extends TJDecompressor
- - -

-TurboJPEG lossless transformer -

- -

-


- -

+

+
org.libjpegturbo.turbojpeg
+

Class TJTransformer

+
+
+ +
+
    +
  • +
    +
    +
    public class TJTransformer
    +extends TJDecompressor
    +
    TurboJPEG lossless transformer
    +
  • +
+
+
+
    +
  • - - - - - - -
    -Field Summary
    - - - - - - - -
    Fields inherited from class org.libjpegturbo.turbojpeg.TJDecompressor
    handle, jpegBuf, jpegBufSize, jpegColorspace, jpegHeight, jpegSubsamp, jpegWidth
    -  + - - - - - - - - - - - - - - + +
    -Constructor Summary
    TJTransformer() - -
    -          Create a TurboJPEG lossless transformer instance.
    TJTransformer(byte[] jpegImage) - -
    -          Create a TurboJPEG lossless transformer instance and associate the JPEG - image stored in jpegImage with the newly-created instance.
    TJTransformer(byte[] jpegImage, - int imageSize) - -
    -          Create a TurboJPEG lossless transformer instance and associate the JPEG +
      +
    • + + +

      Constructor Summary

      + + + + + + + + + + + + + - -
      Constructors 
      Constructor and Description
      TJTransformer() +
      Create a TurboJPEG lossless transformer instance.
      +
      TJTransformer(byte[] jpegImage) +
      Create a TurboJPEG lossless transformer instance and associate the JPEG + image stored in jpegImage with the newly created instance.
      +
      TJTransformer(byte[] jpegImage, + int imageSize) +
      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. +
    +
  • +
- - - - - - - - - - - - - + + + + + +
-Method Summary
- int[]getTransformedSizes() - -
-          Returns an array containing the sizes of the transformed JPEG images from - the most recent call to transform().
- voidtransform(byte[][] dstBufs, - TJTransform[] transforms, - int flags) - -
-          Losslessly transform the JPEG image associated with this transformer +
TJDecompressor[]transform(TJTransform[] transforms, + int flags) +
Losslessly transform the JPEG image associated with this transformer + instance and return an array of TJDecompressor instances, each of + which has a transformed JPEG image associated with it.
+
+ +
    +
  • + + +

    Methods inherited from class java.lang.Object

    +clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • +
+ + + + +
+
+
    +
  • - - - - - - -
    -Constructor Detail
    - -

    -TJTransformer

    -
    -public TJTransformer()
    -              throws java.lang.Exception
    -
    -
    Create a TurboJPEG lossless transformer instance. -

    -

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

    -TJTransformer

    -
    -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. -

    -

    -
    Parameters:
    jpegImage - JPEG image buffer (size of the JPEG image is assumed to - be the length of the array) -
    Throws: -
    java.lang.Exception
    -
    -
    - -

    -TJTransformer

    -
    -public TJTransformer(byte[] jpegImage,
    -                     int imageSize)
    -              throws java.lang.Exception
    -
    -
    Create a TurboJPEG lossless transformer instance and associate the JPEG +
      +
    • + + +

      Constructor Detail

      + + + +
        +
      • +

        TJTransformer

        +
        public TJTransformer()
        +              throws java.lang.Exception
        +
        Create a TurboJPEG lossless transformer instance.
        +
        Throws:
        +
        java.lang.Exception
        +
      • +
      + + + +
        +
      • +

        TJTransformer

        +
        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.
        +
        Parameters:
        jpegImage - JPEG image buffer (size of the JPEG image is assumed to + be the length of the array)
        +
        Throws:
        +
        java.lang.Exception
        +
      • +
      + + + +
        +
      • +

        TJTransformer

        +
        public TJTransformer(byte[] jpegImage,
        +             int imageSize)
        +              throws java.lang.Exception
        +
        Create a TurboJPEG lossless transformer instance and associate the JPEG 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
        -
    - + jpegImage with the newly created instance.
+
Parameters:
jpegImage - JPEG image buffer
imageSize - size of the JPEG image (in bytes)
+
Throws:
+
java.lang.Exception
+ + + + - - - - - - -
-Method Detail
- -

-transform

-
-public void transform(byte[][] dstBufs,
-                      TJTransform[] transforms,
-                      int flags)
-               throws java.lang.Exception
-
-
Losslessly transform the JPEG image associated with this transformer +
    +
  • + + +

    Method Detail

    + + + +
      +
    • +

      transform

      +
      public void transform(byte[][] dstBufs,
      +             TJTransform[] transforms,
      +             int flags)
      +               throws java.lang.Exception
      +
      Losslessly transform the JPEG image associated with this transformer instance into one or more JPEG images stored in the given destination buffers. Lossless transforms work by moving the raw coefficients from one JPEG image structure to another without altering the values of the @@ -306,121 +296,121 @@ public void transform(byte[][] dstBufs, size of the destination image. Thus, this method provides a means of generating multiple transformed images from the same source or of applying multiple transformations simultaneously, in order to eliminate the need to - read the source coefficients multiple times. -

      -

      -
      Parameters:
      dstBufs - an array of image buffers. dstbufs[i] will + read the source coefficients multiple times.
      +
      Parameters:
      dstBufs - an array of image buffers. dstbufs[i] will receive a JPEG image that has been transformed using the parameters in - transforms[i]. Use TJ.bufSize(int, int, int) to determine the + 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_* -
      Throws: -
      java.lang.Exception
      -
-
-
- -

-transform

-
-public TJDecompressor[] transform(TJTransform[] transforms,
-                                  int flags)
-                           throws java.lang.Exception
-
-
Losslessly transform the JPEG image associated with this transformer - instance and return an array of TJDecompressor instances, each of - which has a transformed JPEG image associated with it. -

-

-
Parameters:
transforms - an array of TJTransform instances, each of + corresponding transformed output image
flags - the bitwise OR of one or more of + TJ.FLAG_*
+
Throws:
+
java.lang.Exception
+ + + + + +
    +
  • +

    transform

    +
    public TJDecompressor[] transform(TJTransform[] transforms,
    +                         int flags)
    +                           throws java.lang.Exception
    +
    Losslessly transform the JPEG image associated with this transformer + instance and return an array of TJDecompressor instances, each of + which has a transformed JPEG image associated with it.
    +
    Parameters:
    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_* -
    Returns:
    an array of TJDecompressor instances, each of - which has a transformed JPEG image associated with it -
    Throws: -
    java.lang.Exception
    -
-
-
- -

-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 from - the most recent call to transform() -
Throws: -
java.lang.Exception
-
-
+ 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:
+
java.lang.Exception
+ + + + + +
    +
  • +

    getTransformedSizes

    +
    public int[] getTransformedSizes()
    +                          throws java.lang.Exception
    +
    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 + generated by the most recent transform operation
    +
    Throws:
    +
    java.lang.Exception
    +
  • +
+ + + + +
+ -
- - - - - - - - - - - - - - - - - - -
- -
- + + +
+ + +
+ + + - -
- - - + + diff --git a/java/doc/org/libjpegturbo/turbojpeg/YUVImage.html b/java/doc/org/libjpegturbo/turbojpeg/YUVImage.html new file mode 100644 index 00000000..13e6160c --- /dev/null +++ b/java/doc/org/libjpegturbo/turbojpeg/YUVImage.html @@ -0,0 +1,569 @@ + + + + +YUVImage + + + + + + + + + + +
+
org.libjpegturbo.turbojpeg
+

Class YUVImage

+
+
+
    +
  • java.lang.Object
  • +
  • +
      +
    • org.libjpegturbo.turbojpeg.YUVImage
    • +
    +
  • +
+
+
    +
  • +
    +
    +
    public class YUVImage
    +extends java.lang.Object
    +
    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.

    +
  • +
+
+
+
    +
  • + +
      +
    • + + +

      Field Summary

      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      Fields 
      Modifier and TypeField and Description
      protected longhandle 
      protected byte[]yuvBuf 
      protected intyuvHeight 
      protected intyuvPad 
      protected intyuvSubsamp 
      protected intyuvWidth 
      +
    • +
    + +
      +
    • + + +

      Constructor Summary

      + + + + + + + + + + + +
      Constructors 
      Constructor and Description
      YUVImage(byte[] yuvImage, + int width, + int pad, + int height, + int subsamp) +
      Create a YUVImage instance from an existing YUV planar image + buffer.
      +
      YUVImage(int width, + int pad, + int height, + int subsamp) +
      Create a YUVImage instance with a new image buffer.
      +
      +
    • +
    + +
      +
    • + + +

      Method Summary

      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      Methods 
      Modifier and TypeMethod and Description
      byte[]getBuf() +
      Returns the YUV image buffer
      +
      intgetHeight() +
      Returns the height of the YUV image.
      +
      intgetPad() +
      Returns the line padding used in the YUV image buffer.
      +
      intgetSize() +
      Returns the size (in bytes) of the YUV image buffer
      +
      intgetSubsamp() +
      Returns the level of chrominance subsampling used in the YUV image.
      +
      intgetWidth() +
      Returns the width of the YUV image.
      +
      voidsetBuf(byte[] yuvImage, + int width, + int pad, + int height, + int subsamp) +
      Assign an existing YUV planar image buffer to this YUVImage + instance.
      +
      +
        +
      • + + +

        Methods inherited from class java.lang.Object

        +clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • +
      +
    • +
    +
  • +
+
+
+
    +
  • + +
      +
    • + + +

      Field Detail

      + + + +
        +
      • +

        handle

        +
        protected long handle
        +
      • +
      + + + +
        +
      • +

        yuvBuf

        +
        protected byte[] yuvBuf
        +
      • +
      + + + +
        +
      • +

        yuvPad

        +
        protected int yuvPad
        +
      • +
      + + + +
        +
      • +

        yuvWidth

        +
        protected int yuvWidth
        +
      • +
      + + + +
        +
      • +

        yuvHeight

        +
        protected int yuvHeight
        +
      • +
      + + + +
        +
      • +

        yuvSubsamp

        +
        protected int yuvSubsamp
        +
      • +
      +
    • +
    + +
      +
    • + + +

      Constructor Detail

      + + + +
        +
      • +

        YUVImage

        +
        public YUVImage(int width,
        +        int pad,
        +        int height,
        +        int subsamp)
        +         throws java.lang.Exception
        +
        Create a YUVImage instance with a new image buffer.
        +
        Parameters:
        width - width (in pixels) of the YUV image
        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.)
        height - height (in pixels) of the YUV image
        subsamp - the level of chrominance subsampling to be used in the YUV + image (one of TJ.SAMP_*)
        +
        Throws:
        +
        java.lang.Exception
        +
      • +
      + + + +
        +
      • +

        YUVImage

        +
        public YUVImage(byte[] yuvImage,
        +        int width,
        +        int pad,
        +        int height,
        +        int subsamp)
        +         throws java.lang.Exception
        +
        Create a YUVImage instance from an existing YUV planar image + buffer.
        +
        Parameters:
        yuvImage - image buffer that contains or will contain YUV planar + image data. See above for a description of the image + format. Use TJ.bufSizeYUV(int, int, int, int) to determine the minimum size for this + buffer.
        width - width (in pixels) of the YUV image
        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.
        height - height (in pixels) of the YUV image
        subsamp - the level of chrominance subsampling used in the YUV + image (one of TJ.SAMP_*)
        +
        Throws:
        +
        java.lang.Exception
        +
      • +
      +
    • +
    + +
      +
    • + + +

      Method Detail

      + + + +
        +
      • +

        setBuf

        +
        public void setBuf(byte[] yuvImage,
        +          int width,
        +          int pad,
        +          int height,
        +          int subsamp)
        +            throws java.lang.Exception
        +
        Assign an existing YUV planar image buffer to this YUVImage + instance.
        +
        Parameters:
        yuvImage - image buffer that contains or will contain YUV planar + image data. See above for a description of the image + format. Use TJ.bufSizeYUV(int, int, int, int) to determine the minimum size for this + buffer.
        width - width (in pixels) of the YUV image
        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.
        height - height (in pixels) of the YUV image
        subsamp - the level of chrominance subsampling used in the YUV + image (one of TJ.SAMP_*)
        +
        Throws:
        +
        java.lang.Exception
        +
      • +
      + + + +
        +
      • +

        getWidth

        +
        public int getWidth()
        +             throws java.lang.Exception
        +
        Returns the width of the YUV image.
        +
        Returns:
        the width of the YUV image
        +
        Throws:
        +
        java.lang.Exception
        +
      • +
      + + + +
        +
      • +

        getHeight

        +
        public int getHeight()
        +              throws java.lang.Exception
        +
        Returns the height of the YUV image.
        +
        Returns:
        the height of the YUV image
        +
        Throws:
        +
        java.lang.Exception
        +
      • +
      + + + +
        +
      • +

        getPad

        +
        public int getPad()
        +           throws java.lang.Exception
        +
        Returns the line padding used in the YUV image buffer.
        +
        Returns:
        the line padding used in the YUV image buffer
        +
        Throws:
        +
        java.lang.Exception
        +
      • +
      + + + +
        +
      • +

        getSubsamp

        +
        public int getSubsamp()
        +               throws java.lang.Exception
        +
        Returns the level of chrominance subsampling used in the YUV image. See + TJ.SAMP_*.
        +
        Returns:
        the level of chrominance subsampling used in the YUV image
        +
        Throws:
        +
        java.lang.Exception
        +
      • +
      + + + +
        +
      • +

        getBuf

        +
        public byte[] getBuf()
        +              throws java.lang.Exception
        +
        Returns the YUV image buffer
        +
        Returns:
        the YUV image buffer
        +
        Throws:
        +
        java.lang.Exception
        +
      • +
      + + + +
        +
      • +

        getSize

        +
        public int getSize()
        +            throws java.lang.Exception
        +
        Returns the size (in bytes) of the YUV image buffer
        +
        Returns:
        the size (in bytes) of the YUV image buffer
        +
        Throws:
        +
        java.lang.Exception
        +
      • +
      +
    • +
    +
  • +
+
+
+ + + + + + + diff --git a/java/doc/org/libjpegturbo/turbojpeg/package-frame.html b/java/doc/org/libjpegturbo/turbojpeg/package-frame.html index f160418d..7cb8fa0b 100644 --- a/java/doc/org/libjpegturbo/turbojpeg/package-frame.html +++ b/java/doc/org/libjpegturbo/turbojpeg/package-frame.html @@ -1,51 +1,27 @@ - - - - -org.libjpegturbo.turbojpeg - - - - - - - - - - -org.libjpegturbo.turbojpeg - - - - -
-Interfaces  - -
-TJCustomFilter
- - - - - - -
-Classes  - -
-TJ -
-TJCompressor -
-TJDecompressor -
-TJScalingFactor -
-TJTransform -
-TJTransformer
- - - - + + + +org.libjpegturbo.turbojpeg + + + +

org.libjpegturbo.turbojpeg

+ + + diff --git a/java/doc/org/libjpegturbo/turbojpeg/package-summary.html b/java/doc/org/libjpegturbo/turbojpeg/package-summary.html index 505512c9..c5e2f7d8 100644 --- a/java/doc/org/libjpegturbo/turbojpeg/package-summary.html +++ b/java/doc/org/libjpegturbo/turbojpeg/package-summary.html @@ -1,185 +1,183 @@ - - - - -org.libjpegturbo.turbojpeg - - - - - - - - - - - -
- - +//--> + + - - - - - - - - - - - - -
- -
- + + + + + - -
-

-Package org.libjpegturbo.turbojpeg -

- - - - - - - - - -
-Interface Summary
TJCustomFilterCustom filter callback interface
-  - -

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-Class Summary
TJTurboJPEG utility class (cannot be instantiated)
TJCompressorTurboJPEG compressor
TJDecompressorTurboJPEG decompressor
TJScalingFactorFractional scaling factor
TJTransformLossless transform parameters
TJTransformerTurboJPEG lossless transformer
-  - -

-

-
-
- - +
+

Package org.libjpegturbo.turbojpeg

+
+
+
    +
  • + + + + + + + + + + + + +
    Interface Summary 
    InterfaceDescription
    TJCustomFilter +
    Custom filter callback interface
    +
    +
  • +
  • + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Class Summary 
    ClassDescription
    TJ +
    TurboJPEG utility class (cannot be instantiated)
    +
    TJCompressor +
    TurboJPEG compressor
    +
    TJDecompressor +
    TurboJPEG decompressor
    +
    TJScalingFactor +
    Fractional scaling factor
    +
    TJTransform +
    Lossless transform parameters
    +
    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 e13143d8..1033ee56 100644 --- a/java/doc/org/libjpegturbo/turbojpeg/package-tree.html +++ b/java/doc/org/libjpegturbo/turbojpeg/package-tree.html @@ -1,159 +1,143 @@ - - - - -org.libjpegturbo.turbojpeg Class Hierarchy - - - - - - - - - - - -
- - +//--> + + - - - - - - - - - - - - -
- -
- + + + + + - -
-
-

-Hierarchy For Package org.libjpegturbo.turbojpeg -

-
-

-Class Hierarchy -

-
    -
  • java.lang.Object
      -
    • java.awt.geom.RectangularShape (implements java.lang.Cloneable, java.awt.Shape) -
        -
      • java.awt.geom.Rectangle2D
          -
        • java.awt.Rectangle (implements java.io.Serializable, java.awt.Shape) - -
        -
      -
    • org.libjpegturbo.turbojpeg.TJ
    • org.libjpegturbo.turbojpeg.TJCompressor
    • org.libjpegturbo.turbojpeg.TJDecompressor -
    • org.libjpegturbo.turbojpeg.TJScalingFactor
    -
-

-Interface Hierarchy -

- -
- - +
+

Hierarchy For Package org.libjpegturbo.turbojpeg

+
+
+

Class Hierarchy

+
    +
  • java.lang.Object +
      +
    • java.awt.geom.RectangularShape (implements java.lang.Cloneable, java.awt.Shape) +
        +
      • java.awt.geom.Rectangle2D +
          +
        • java.awt.Rectangle (implements java.io.Serializable, java.awt.Shape) + +
        • +
        +
      • +
      +
    • +
    • org.libjpegturbo.turbojpeg.TJ
    • +
    • org.libjpegturbo.turbojpeg.TJCompressor
    • +
    • org.libjpegturbo.turbojpeg.TJDecompressor + +
    • +
    • 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 1c12b10e..eae18a13 100644 --- a/java/doc/overview-tree.html +++ b/java/doc/overview-tree.html @@ -1,161 +1,147 @@ - - - - -Class Hierarchy - - - - - - - - - - - -
- - +//--> + + - - - - - - - - - - - - -
- -
- + + + + + - -
-
-

-Hierarchy For All Packages

-
-
-
Package Hierarchies:
org.libjpegturbo.turbojpeg
-
-

-Class Hierarchy -

-
    -
  • java.lang.Object
      -
    • java.awt.geom.RectangularShape (implements java.lang.Cloneable, java.awt.Shape) -
        -
      • java.awt.geom.Rectangle2D
          -
        • java.awt.Rectangle (implements java.io.Serializable, java.awt.Shape) - -
        -
      -
    • org.libjpegturbo.turbojpeg.TJ
    • org.libjpegturbo.turbojpeg.TJCompressor
    • org.libjpegturbo.turbojpeg.TJDecompressor -
    • org.libjpegturbo.turbojpeg.TJScalingFactor
    -
-

-Interface Hierarchy -

- -
- - +
+

Hierarchy For All Packages

+Package Hierarchies: + +
+
+

Class Hierarchy

+
    +
  • java.lang.Object +
      +
    • java.awt.geom.RectangularShape (implements java.lang.Cloneable, java.awt.Shape) +
        +
      • java.awt.geom.Rectangle2D +
          +
        • java.awt.Rectangle (implements java.io.Serializable, java.awt.Shape) + +
        • +
        +
      • +
      +
    • +
    • org.libjpegturbo.turbojpeg.TJ
    • +
    • org.libjpegturbo.turbojpeg.TJCompressor
    • +
    • org.libjpegturbo.turbojpeg.TJDecompressor + +
    • +
    • org.libjpegturbo.turbojpeg.TJScalingFactor
    • +
    • org.libjpegturbo.turbojpeg.YUVImage
    • +
    +
  • +
+

Interface Hierarchy

+ +
- - - - - - - - - - - - -
- -
- + + + + + - -
- - - + + diff --git a/java/doc/resources/background.gif b/java/doc/resources/background.gif new file mode 100644 index 00000000..f471940f Binary files /dev/null and b/java/doc/resources/background.gif differ diff --git a/java/doc/resources/inherit.gif b/java/doc/resources/inherit.gif deleted file mode 100644 index c814867a..00000000 Binary files a/java/doc/resources/inherit.gif and /dev/null differ diff --git a/java/doc/resources/tab.gif b/java/doc/resources/tab.gif new file mode 100644 index 00000000..1a73a83b Binary files /dev/null and b/java/doc/resources/tab.gif differ diff --git a/java/doc/resources/titlebar.gif b/java/doc/resources/titlebar.gif new file mode 100644 index 00000000..17443b3e Binary files /dev/null and b/java/doc/resources/titlebar.gif differ diff --git a/java/doc/resources/titlebar_end.gif b/java/doc/resources/titlebar_end.gif new file mode 100644 index 00000000..3ad78d46 Binary files /dev/null and b/java/doc/resources/titlebar_end.gif differ diff --git a/java/doc/serialized-form.html b/java/doc/serialized-form.html index 8ba0661b..bbe18053 100644 --- a/java/doc/serialized-form.html +++ b/java/doc/serialized-form.html @@ -1,200 +1,150 @@ - - - - -Serialized Form - - - - - - - - - - - -
- - +//--> + + - - - - - - - - - - - - -
- -
- + + + + + - -
-
-

-Serialized Form

-
-
- - - - - -
-Package org.libjpegturbo.turbojpeg
- -

- - - - - -
-Class org.libjpegturbo.turbojpeg.TJTransform extends java.awt.Rectangle implements Serializable
- -

-serialVersionUID: -127367705761430371L - -

- - - - - -
-Serialized Fields
- -

-op

-
-int op
-
-
Transform operation (one of OP_*) -

-

-
-
-
-

-options

-
-int options
-
-
Transform options (bitwise OR of one or more of OPT_*) -

-

-
-
-
-

-cf

-
-TJCustomFilter cf
-
-
Custom filter instance -

-

-
-
- -

-


- - +
+

Serialized Form

+
+
+
    +
  • +

    Package org.libjpegturbo.turbojpeg

    +
      +
    • + + +

      Class org.libjpegturbo.turbojpeg.TJTransform extends java.awt.Rectangle implements Serializable

      +
      +
      serialVersionUID:
      +
      -127367705761430371L
      +
      +
        +
      • + + +

        Serialized Fields

        +
          +
        • +

          op

          +
          int op
          +
          Transform operation (one of OP_*)
          +
        • +
        • +

          options

          +
          int options
          +
          Transform options (bitwise OR of one or more of OPT_*)
          +
        • +
        • +

          cf

          +
          TJCustomFilter cf
          +
          Custom filter instance
          +
        • +
        +
      • +
      +
    • +
    +
  • +
+
- - - - - - - - - - - - -
- -
- + + + + + - -
- - - + + diff --git a/java/doc/stylesheet.css b/java/doc/stylesheet.css index 6ea9e516..0aeaa97f 100644 --- a/java/doc/stylesheet.css +++ b/java/doc/stylesheet.css @@ -1,29 +1,474 @@ /* Javadoc style sheet */ - -/* Define colors, fonts and other style attributes here to override the defaults */ - -/* Page background color */ -body { background-color: #FFFFFF; color:#000000 } - -/* Headings */ -h1 { font-size: 145% } - -/* Table colors */ -.TableHeadingColor { background: #CCCCFF; color:#000000 } /* Dark mauve */ -.TableSubHeadingColor { background: #EEEEFF; color:#000000 } /* Light mauve */ -.TableRowColor { background: #FFFFFF; color:#000000 } /* White */ - -/* Font used in left-hand frame lists */ -.FrameTitleFont { font-size: 100%; font-family: Helvetica, Arial, sans-serif; color:#000000 } -.FrameHeadingFont { font-size: 90%; font-family: Helvetica, Arial, sans-serif; color:#000000 } -.FrameItemFont { font-size: 90%; font-family: Helvetica, Arial, sans-serif; color:#000000 } - -/* Navigation bar fonts and colors */ -.NavBarCell1 { background-color:#EEEEFF; color:#000000} /* Light mauve */ -.NavBarCell1Rev { background-color:#00008B; color:#FFFFFF} /* Dark Blue */ -.NavBarFont1 { font-family: Arial, Helvetica, sans-serif; color:#000000;color:#000000;} -.NavBarFont1Rev { font-family: Arial, Helvetica, sans-serif; color:#FFFFFF;color:#FFFFFF;} - -.NavBarCell2 { font-family: Arial, Helvetica, sans-serif; background-color:#FFFFFF; color:#000000} -.NavBarCell3 { font-family: Arial, Helvetica, sans-serif; background-color:#FFFFFF; color:#000000} - +/* +Overall document style +*/ +body { + background-color:#ffffff; + color:#353833; + font-family:Arial, Helvetica, sans-serif; + font-size:76%; + margin:0; +} +a:link, a:visited { + text-decoration:none; + color:#4c6b87; +} +a:hover, a:focus { + text-decoration:none; + color:#bb7a2a; +} +a:active { + text-decoration:none; + color:#4c6b87; +} +a[name] { + color:#353833; +} +a[name]:hover { + text-decoration:none; + color:#353833; +} +pre { + font-size:1.3em; +} +h1 { + font-size:1.8em; +} +h2 { + font-size:1.5em; +} +h3 { + font-size:1.4em; +} +h4 { + font-size:1.3em; +} +h5 { + font-size:1.2em; +} +h6 { + font-size:1.1em; +} +ul { + list-style-type:disc; +} +code, tt { + font-size:1.2em; +} +dt code { + font-size:1.2em; +} +table tr td dt code { + font-size:1.2em; + vertical-align:top; +} +sup { + font-size:.6em; +} +/* +Document title and Copyright styles +*/ +.clear { + clear:both; + height:0px; + overflow:hidden; +} +.aboutLanguage { + float:right; + padding:0px 21px; + font-size:.8em; + z-index:200; + margin-top:-7px; +} +.legalCopy { + margin-left:.5em; +} +.bar a, .bar a:link, .bar a:visited, .bar a:active { + color:#FFFFFF; + text-decoration:none; +} +.bar a:hover, .bar a:focus { + color:#bb7a2a; +} +.tab { + background-color:#0066FF; + background-image:url(resources/titlebar.gif); + background-position:left top; + background-repeat:no-repeat; + color:#ffffff; + padding:8px; + width:5em; + font-weight:bold; +} +/* +Navigation bar styles +*/ +.bar { + background-image:url(resources/background.gif); + background-repeat:repeat-x; + color:#FFFFFF; + padding:.8em .5em .4em .8em; + height:auto;/*height:1.8em;*/ + font-size:1em; + margin:0; +} +.topNav { + background-image:url(resources/background.gif); + background-repeat:repeat-x; + color:#FFFFFF; + float:left; + padding:0; + width:100%; + clear:right; + height:2.8em; + padding-top:10px; + overflow:hidden; +} +.bottomNav { + margin-top:10px; + background-image:url(resources/background.gif); + background-repeat:repeat-x; + color:#FFFFFF; + float:left; + padding:0; + width:100%; + clear:right; + height:2.8em; + padding-top:10px; + overflow:hidden; +} +.subNav { + background-color:#dee3e9; + border-bottom:1px solid #9eadc0; + float:left; + width:100%; + overflow:hidden; +} +.subNav div { + clear:left; + float:left; + padding:0 0 5px 6px; +} +ul.navList, ul.subNavList { + float:left; + margin:0 25px 0 0; + padding:0; +} +ul.navList li{ + list-style:none; + float:left; + padding:3px 6px; +} +ul.subNavList li{ + list-style:none; + float:left; + font-size:90%; +} +.topNav a:link, .topNav a:active, .topNav a:visited, .bottomNav a:link, .bottomNav a:active, .bottomNav a:visited { + color:#FFFFFF; + text-decoration:none; +} +.topNav a:hover, .bottomNav a:hover { + text-decoration:none; + color:#bb7a2a; +} +.navBarCell1Rev { + background-image:url(resources/tab.gif); + background-color:#a88834; + color:#FFFFFF; + margin: auto 5px; + border:1px solid #c9aa44; +} +/* +Page header and footer styles +*/ +.header, .footer { + clear:both; + margin:0 20px; + padding:5px 0 0 0; +} +.indexHeader { + margin:10px; + position:relative; +} +.indexHeader h1 { + font-size:1.3em; +} +.title { + color:#2c4557; + margin:10px 0; +} +.subTitle { + margin:5px 0 0 0; +} +.header ul { + margin:0 0 25px 0; + padding:0; +} +.footer ul { + margin:20px 0 5px 0; +} +.header ul li, .footer ul li { + list-style:none; + font-size:1.2em; +} +/* +Heading styles +*/ +div.details ul.blockList ul.blockList ul.blockList li.blockList h4, div.details ul.blockList ul.blockList ul.blockListLast li.blockList h4 { + background-color:#dee3e9; + border-top:1px solid #9eadc0; + border-bottom:1px solid #9eadc0; + margin:0 0 6px -8px; + padding:2px 5px; +} +ul.blockList ul.blockList ul.blockList li.blockList h3 { + background-color:#dee3e9; + border-top:1px solid #9eadc0; + border-bottom:1px solid #9eadc0; + margin:0 0 6px -8px; + padding:2px 5px; +} +ul.blockList ul.blockList li.blockList h3 { + padding:0; + margin:15px 0; +} +ul.blockList li.blockList h2 { + padding:0px 0 20px 0; +} +/* +Page layout container styles +*/ +.contentContainer, .sourceContainer, .classUseContainer, .serializedFormContainer, .constantValuesContainer { + clear:both; + padding:10px 20px; + position:relative; +} +.indexContainer { + margin:10px; + position:relative; + font-size:1.0em; +} +.indexContainer h2 { + font-size:1.1em; + padding:0 0 3px 0; +} +.indexContainer ul { + margin:0; + padding:0; +} +.indexContainer ul li { + list-style:none; +} +.contentContainer .description dl dt, .contentContainer .details dl dt, .serializedFormContainer dl dt { + font-size:1.1em; + font-weight:bold; + margin:10px 0 0 0; + color:#4E4E4E; +} +.contentContainer .description dl dd, .contentContainer .details dl dd, .serializedFormContainer dl dd { + margin:10px 0 10px 20px; +} +.serializedFormContainer dl.nameValue dt { + margin-left:1px; + font-size:1.1em; + display:inline; + font-weight:bold; +} +.serializedFormContainer dl.nameValue dd { + margin:0 0 0 1px; + font-size:1.1em; + display:inline; +} +/* +List styles +*/ +ul.horizontal li { + display:inline; + font-size:0.9em; +} +ul.inheritance { + margin:0; + padding:0; +} +ul.inheritance li { + display:inline; + list-style:none; +} +ul.inheritance li ul.inheritance { + margin-left:15px; + padding-left:15px; + padding-top:1px; +} +ul.blockList, ul.blockListLast { + margin:10px 0 10px 0; + padding:0; +} +ul.blockList li.blockList, ul.blockListLast li.blockList { + list-style:none; + margin-bottom:25px; +} +ul.blockList ul.blockList li.blockList, ul.blockList ul.blockListLast li.blockList { + padding:0px 20px 5px 10px; + border:1px solid #9eadc0; + background-color:#f9f9f9; +} +ul.blockList ul.blockList ul.blockList li.blockList, ul.blockList ul.blockList ul.blockListLast li.blockList { + padding:0 0 5px 8px; + background-color:#ffffff; + border:1px solid #9eadc0; + border-top:none; +} +ul.blockList ul.blockList ul.blockList ul.blockList li.blockList { + margin-left:0; + padding-left:0; + padding-bottom:15px; + border:none; + border-bottom:1px solid #9eadc0; +} +ul.blockList ul.blockList ul.blockList ul.blockList li.blockListLast { + list-style:none; + border-bottom:none; + padding-bottom:0; +} +table tr td dl, table tr td dl dt, table tr td dl dd { + margin-top:0; + margin-bottom:1px; +} +/* +Table styles +*/ +.contentContainer table, .classUseContainer table, .constantValuesContainer table { + border-bottom:1px solid #9eadc0; + width:100%; +} +.contentContainer ul li table, .classUseContainer ul li table, .constantValuesContainer ul li table { + width:100%; +} +.contentContainer .description table, .contentContainer .details table { + border-bottom:none; +} +.contentContainer ul li table th.colOne, .contentContainer ul li table th.colFirst, .contentContainer ul li table th.colLast, .classUseContainer ul li table th, .constantValuesContainer ul li table th, .contentContainer ul li table td.colOne, .contentContainer ul li table td.colFirst, .contentContainer ul li table td.colLast, .classUseContainer ul li table td, .constantValuesContainer ul li table td{ + vertical-align:top; + padding-right:20px; +} +.contentContainer ul li table th.colLast, .classUseContainer ul li table th.colLast,.constantValuesContainer ul li table th.colLast, +.contentContainer ul li table td.colLast, .classUseContainer ul li table td.colLast,.constantValuesContainer ul li table td.colLast, +.contentContainer ul li table th.colOne, .classUseContainer ul li table th.colOne, +.contentContainer ul li table td.colOne, .classUseContainer ul li table td.colOne { + padding-right:3px; +} +.overviewSummary caption, .packageSummary caption, .contentContainer ul.blockList li.blockList caption, .summary caption, .classUseContainer caption, .constantValuesContainer caption { + position:relative; + text-align:left; + background-repeat:no-repeat; + color:#FFFFFF; + font-weight:bold; + clear:none; + overflow:hidden; + padding:0px; + margin:0px; +} +caption a:link, caption a:hover, caption a:active, caption a:visited { + color:#FFFFFF; +} +.overviewSummary caption span, .packageSummary caption span, .contentContainer ul.blockList li.blockList caption span, .summary caption span, .classUseContainer caption span, .constantValuesContainer caption span { + white-space:nowrap; + padding-top:8px; + padding-left:8px; + display:block; + float:left; + background-image:url(resources/titlebar.gif); + height:18px; +} +.overviewSummary .tabEnd, .packageSummary .tabEnd, .contentContainer ul.blockList li.blockList .tabEnd, .summary .tabEnd, .classUseContainer .tabEnd, .constantValuesContainer .tabEnd { + width:10px; + background-image:url(resources/titlebar_end.gif); + background-repeat:no-repeat; + background-position:top right; + position:relative; + float:left; +} +ul.blockList ul.blockList li.blockList table { + margin:0 0 12px 0px; + width:100%; +} +.tableSubHeadingColor { + background-color: #EEEEFF; +} +.altColor { + background-color:#eeeeef; +} +.rowColor { + background-color:#ffffff; +} +.overviewSummary td, .packageSummary td, .contentContainer ul.blockList li.blockList td, .summary td, .classUseContainer td, .constantValuesContainer td { + text-align:left; + padding:3px 3px 3px 7px; +} +th.colFirst, th.colLast, th.colOne, .constantValuesContainer th { + background:#dee3e9; + border-top:1px solid #9eadc0; + border-bottom:1px solid #9eadc0; + text-align:left; + padding:3px 3px 3px 7px; +} +td.colOne a:link, td.colOne a:active, td.colOne a:visited, td.colOne a:hover, td.colFirst a:link, td.colFirst a:active, td.colFirst a:visited, td.colFirst a:hover, td.colLast a:link, td.colLast a:active, td.colLast a:visited, td.colLast a:hover, .constantValuesContainer td a:link, .constantValuesContainer td a:active, .constantValuesContainer td a:visited, .constantValuesContainer td a:hover { + font-weight:bold; +} +td.colFirst, th.colFirst { + border-left:1px solid #9eadc0; + white-space:nowrap; +} +td.colLast, th.colLast { + border-right:1px solid #9eadc0; +} +td.colOne, th.colOne { + border-right:1px solid #9eadc0; + border-left:1px solid #9eadc0; +} +table.overviewSummary { + padding:0px; + margin-left:0px; +} +table.overviewSummary td.colFirst, table.overviewSummary th.colFirst, +table.overviewSummary td.colOne, table.overviewSummary th.colOne { + width:25%; + vertical-align:middle; +} +table.packageSummary td.colFirst, table.overviewSummary th.colFirst { + width:25%; + vertical-align:middle; +} +/* +Content styles +*/ +.description pre { + margin-top:0; +} +.deprecatedContent { + margin:0; + padding:10px 0; +} +.docSummary { + padding:0; +} +/* +Formatting effect styles +*/ +.sourceLineNo { + color:green; + padding:0 30px 0 0; +} +h1.hidden { + visibility:hidden; + overflow:hidden; + font-size:.9em; +} +.block { + display:block; + margin:3px 0 0 0; +} +.strong { + font-weight:bold; +} diff --git a/java/org/libjpegturbo/turbojpeg/TJCompressor.java b/java/org/libjpegturbo/turbojpeg/TJCompressor.java index 63a7fa5c..0debf53e 100644 --- a/java/org/libjpegturbo/turbojpeg/TJCompressor.java +++ b/java/org/libjpegturbo/turbojpeg/TJCompressor.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: @@ -48,28 +48,7 @@ public class TJCompressor { /** * Create a TurboJPEG compressor instance and associate the uncompressed - * source image stored in srcImage with the newly-created - * instance. - * - * @param srcImage see {@link #setSourceImage} for description - * - * @param width see {@link #setSourceImage} for description - * - * @param pitch see {@link #setSourceImage} for description - * - * @param height see {@link #setSourceImage} for description - * - * @param pixelFormat pixel format of the source image (one of - * {@link TJ TJ.PF_*}) - */ - 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 @@ -85,7 +64,7 @@ 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 { @@ -93,34 +72,70 @@ public class TJCompressor { } /** - * Associate an uncompressed source image with this compressor instance. + * @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 + * instance. + * + * @param srcImage see + * {@link #setSourceImage(BufferedImage, int, int, int, int)} for description + * + * @param x see + * {@link #setSourceImage(BufferedImage, int, int, int, int)} for description + * + * @param y see + * {@link #setSourceImage(BufferedImage, int, int, int, int)} for description + * + * @param width see + * {@link #setSourceImage(BufferedImage, int, int, int, int)} for description + * + * @param height see + * {@link #setSourceImage(BufferedImage, int, int, int, int)} for description + */ + public TJCompressor(BufferedImage srcImage, int x, int y, int width, + int height) throws Exception { + setSourceImage(srcImage, x, y, width, height); + } + + /** + * 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) @@ -139,7 +154,8 @@ public class TJCompressor { srcPixelFormat = pixelFormat; srcX = x; srcY = y; - srcIsYUV = false; + srcBufInt = null; + srcYUVImage = null; } /** @@ -154,147 +170,38 @@ public class TJCompressor { } /** - * 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 - */ - public void setSourceImageYUV(byte[] srcImage, int width, int pad, - int height) 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; - } - - /** - * Set the level of chrominance subsampling for subsequent compress/encode - * operations. When pixels are converted from RGB to YCbCr (see - * {@link TJ#CS_YCbCr}) or from CMYK to YCCK (see {@link TJ#CS_YCCK}) as part - * of the JPEG compression process, some of the Cb and Cr (chrominance) - * components can be discarded or averaged together to produce a smaller - * image with little perceptible loss of image clarity (the human eye is more - * 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_*}) - */ - public void setSubsamp(int newSubsamp) throws Exception { - if (newSubsamp < 0 || newSubsamp >= TJ.NUMSAMP) - throw new Exception("Invalid argument in setSubsamp()"); - subsamp = newSubsamp; - } - - /** - * Set the JPEG image quality level for subsequent compress operations. - * - * @param quality the new JPEG image quality level (1 to 100, 1 = worst, - * 100 = best) - */ - public void setJPEGQuality(int quality) throws Exception { - if (quality < 1 || quality > 100) - throw new Exception("Invalid argument in setJPEGQuality()"); - jpegQuality = quality; - } - - /** - * Compress the uncompressed source image associated with this compressor - * instance and output a JPEG image to the given destination buffer. - * - * @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. - * - * @param flags the bitwise OR of one or more of {@link TJ 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) - throw new Exception(NO_ASSOC_ERROR); - if (jpegQuality < 0) - throw new Exception("JPEG Quality not set"); - if (subsamp < 0) - throw new Exception("Subsampling level not set"); - if (srcIsYUV) - compressedSize = compressFromYUV(srcBuf, srcWidth, srcYUVPad, srcHeight, - subsamp, dstBuf, jpegQuality, flags); - else { - if (srcX >= 0 && srcY >= 0) - compressedSize = compress(srcBuf, srcX, srcY, srcWidth, srcPitch, - srcHeight, srcPixelFormat, dstBuf, subsamp, - jpegQuality, flags); - else - compressedSize = compress(srcBuf, srcWidth, srcPitch, srcHeight, - srcPixelFormat, dstBuf, subsamp, jpegQuality, - flags); - } - } - - /** - * 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_*} - * - * @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 - * #getCompressedSize} to obtain the size of the JPEG image. - */ - public byte[] compress(int flags) throws Exception { - if (srcWidth < 1 || srcHeight < 1) - throw new Exception(NO_ASSOC_ERROR); - byte[] buf = new byte[TJ.bufSize(srcWidth, srcHeight, subsamp)]; - compress(buf, flags); - return buf; - } - - /** - * Compress the uncompressed source image stored in srcImage - * and output a JPEG image to the given destination buffer. + * 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 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. + * @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 flags the bitwise OR of one or more of {@link TJ TJ.FLAG_*} + * @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 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 or YUV image should be compressed/encoded (0 = use the + * height of the source image) */ - public void compress(BufferedImage srcImage, byte[] dstBuf, int flags) - throws Exception { - if (srcImage == null || dstBuf == null || flags < 0) - throw new Exception("Invalid argument in compress()"); - int width = srcImage.getWidth(); - int height = srcImage.getHeight(); + public void setSourceImage(BufferedImage srcImage, int x, int y, int width, + int height) throws Exception { + if (handle == 0) init(); + if (srcImage == null || x < 0 || y < 0 || width < 0 || height < 0) + throw new Exception("Invalid argument in setSourceImage()"); + srcX = x; + srcY = y; + srcWidth = (width == 0) ? srcImage.getWidth(): width; + srcHeight = (height == 0) ? srcImage.getHeight() : height; + if (x + width > srcImage.getWidth() || y + height > srcImage.getHeight()) + throw new Exception("Compression region exceeds the bounds of the source image"); + int pixelFormat; boolean intPixels = false; if (byteOrder == null) @@ -324,227 +231,293 @@ public class TJCompressor { default: throw new Exception("Unsupported BufferedImage format"); } + srcPixelFormat = pixelFormat; + WritableRaster wr = srcImage.getRaster(); - if (jpegQuality < 0) - throw new Exception("JPEG Quality not set"); - if (subsamp < 0) - throw new Exception("Subsampling level not set"); if (intPixels) { SinglePixelPackedSampleModel sm = (SinglePixelPackedSampleModel)srcImage.getSampleModel(); - int stride = sm.getScanlineStride(); + srcStride = sm.getScanlineStride(); DataBufferInt db = (DataBufferInt)wr.getDataBuffer(); - int[] buf = db.getData(); - if (srcX >= 0 && srcY >= 0) - compressedSize = compress(buf, srcX, srcY, width, stride, height, - pixelFormat, dstBuf, subsamp, jpegQuality, - flags); - else - compressedSize = compress(buf, width, stride, height, pixelFormat, - dstBuf, subsamp, jpegQuality, flags); + srcBufInt = db.getData(); + srcBuf = null; } else { ComponentSampleModel sm = (ComponentSampleModel)srcImage.getSampleModel(); int pixelSize = sm.getPixelStride(); if (pixelSize != TJ.getPixelSize(pixelFormat)) throw new Exception("Inconsistency between pixel format and pixel size in BufferedImage"); - int pitch = sm.getScanlineStride(); + srcPitch = sm.getScanlineStride(); DataBufferByte db = (DataBufferByte)wr.getDataBuffer(); - byte[] buf = db.getData(); + srcBuf = db.getData(); + srcBufInt = null; + } + srcYUVImage = null; + } + + /** + * Associate an uncompressed YUV planar source image with this compressor + * instance. + * + * @param srcImage YUV planar image to be compressed + */ + public void setSourceImage(YUVImage srcImage) throws Exception { + if (handle == 0) init(); + if (srcImage == null) + throw new Exception("Invalid argument in setSourceImage()"); + srcYUVImage = srcImage; + srcBuf = null; + srcBufInt = null; + } + + /** + * Set the level of chrominance subsampling for subsequent compress/encode + * operations. When pixels are converted from RGB to YCbCr (see + * {@link TJ#CS_YCbCr}) or from CMYK to YCCK (see {@link TJ#CS_YCCK}) as part + * of the JPEG compression process, some of the Cb and Cr (chrominance) + * components can be discarded or averaged together to produce a smaller + * image with little perceptible loss of image clarity (the human eye is more + * sensitive to small changes in brightness than to small changes in color.) + * This is called "chrominance subsampling". + *

+ * 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) + throw new Exception("Invalid argument in setSubsamp()"); + subsamp = newSubsamp; + } + + /** + * Set the JPEG image quality level for subsequent compress operations. + * + * @param quality the new JPEG image quality level (1 to 100, 1 = worst, + * 100 = best) + */ + public void setJPEGQuality(int quality) throws Exception { + if (quality < 1 || quality > 100) + throw new Exception("Invalid argument in setJPEGQuality()"); + jpegQuality = quality; + } + + /** + * Compress the uncompressed source image associated with this compressor + * instance and output a JPEG image to the given destination buffer. + * + * @param dstBuf buffer that will receive the JPEG image. Use + * {@link TJ#bufSize} to determine the maximum size for this buffer based on + * 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#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 && srcYUVImage == null) + throw new Exception(NO_ASSOC_ERROR); + if (jpegQuality < 0) + throw new Exception("JPEG Quality not set"); + if (subsamp < 0 && srcYUVImage == null) + throw new Exception("Subsampling level not set"); + + 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(buf, srcX, srcY, width, pitch, height, - pixelFormat, dstBuf, subsamp, jpegQuality, - flags); + compressedSize = compress(srcBuf, srcX, srcY, srcWidth, srcPitch, + srcHeight, srcPixelFormat, dstBuf, subsamp, + jpegQuality, flags); else - compressedSize = compress(buf, width, pitch, height, pixelFormat, - dstBuf, subsamp, jpegQuality, flags); + compressedSize = compress(srcBuf, srcWidth, srcPitch, srcHeight, + srcPixelFormat, dstBuf, subsamp, jpegQuality, + flags); + } else if (srcBufInt != null) { + if (srcX >= 0 && srcY >= 0) + compressedSize = compress(srcBufInt, srcX, srcY, srcWidth, srcStride, + srcHeight, srcPixelFormat, dstBuf, subsamp, + jpegQuality, flags); + else + compressedSize = compress(srcBufInt, srcWidth, srcStride, srcHeight, + srcPixelFormat, dstBuf, subsamp, jpegQuality, + flags); } } /** - * Compress the uncompressed source image stored in srcImage - * and return a buffer containing a JPEG image. + * Compress the uncompressed source image associated with this compressor + * instance and return a buffer containing a JPEG image. * - * @param srcImage a BufferedImage instance containing RGB or - * grayscale pixels to be compressed - * - * @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 * #getCompressedSize} to obtain the size of the JPEG image. */ - public byte[] compress(BufferedImage srcImage, int flags) throws Exception { - int width = srcImage.getWidth(); - int height = srcImage.getHeight(); - byte[] buf = new byte[TJ.bufSize(width, height, subsamp)]; - compress(srcImage, buf, flags); + public byte[] compress(int flags) throws Exception { + if (srcWidth < 1 || srcHeight < 1) + throw new Exception(NO_ASSOC_ERROR); + byte[] buf = new byte[TJ.bufSize(srcWidth, srcHeight, subsamp)]; + compress(buf, flags); return buf; } + /** + * @deprecated Use + * {@link #setSourceImage(BufferedImage, int, int, int, int)} and + * {@link #compress(byte[], int)} instead. + */ + @Deprecated + public void compress(BufferedImage srcImage, byte[] dstBuf, int flags) + throws Exception { + setSourceImage(srcImage, 0, 0, 0, 0); + compress(dstBuf, 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. + * @deprecated Use + * {@link #setSourceImage(BufferedImage, int, int, int, int)} and + * {@link #compress(int)} instead. */ - public void setYUVPad(int pad) throws Exception { - if(pad < 1 || ((pad & (pad - 1)) != 0)) - throw new Exception("Invalid argument in setYUVPad()"); - yuvPad = pad; + @Deprecated + public byte[] compress(BufferedImage srcImage, int flags) throws Exception { + setSourceImage(srcImage, 0, 0, 0, 0); + return compress(flags); } /** * 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(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 (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, srcX, srcY, srcWidth, srcStride, srcHeight, + srcPixelFormat, dstImage.getBuf(), dstImage.getPad(), + dstImage.getSubsamp(), flags); + } else { + encodeYUV(srcBuf, srcX, srcY, srcWidth, srcPitch, srcHeight, + srcPixelFormat, dstImage.getBuf(), dstImage.getPad(), + dstImage.getSubsamp(), flags); + } + compressedSize = dstImage.getSize(); + } + + /** + * @deprecated Use {@link #encodeYUV(YUVImage, int)} instead. + */ + @Deprecated public void encodeYUV(byte[] dstBuf, int flags) throws Exception { - if (dstBuf == null || flags < 0) - throw new Exception("Invalid argument in compress()"); - if (srcBuf == null) + 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"); - encodeYUV(srcBuf, srcWidth, srcPitch, srcHeight, srcPixelFormat, dstBuf, - yuvPad, subsamp, flags); - compressedSize = TJ.bufSizeYUV(srcWidth, yuvPad, srcHeight, subsamp); + 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 flags the bitwise OR of one or more of {@link TJ TJ.FLAG_*} + * @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.) * - * @return a buffer containing a YUV planar image + * @param flags the bitwise OR of one or more of + * {@link TJ#FLAG_BOTTOMUP TJ.FLAG_*} + * + * @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(); } /** - * Encode the uncompressed source image stored in srcImage - * and output a YUV planar image to the given destination buffer. See - * {@link #encodeYUV(byte[], int)} for more detail. - * - * @param srcImage a BufferedImage instance containing RGB or - * grayscale pixels to be encoded - * - * @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 flags the bitwise OR of one or more of {@link TJ TJ.FLAG_*} + * @deprecated Use + * {@link #setSourceImage(BufferedImage, int, int, int, int)} and + * {@link #encodeYUV(byte[], int)} instead. */ + @Deprecated public void encodeYUV(BufferedImage srcImage, byte[] dstBuf, int flags) throws Exception { - if (srcImage == null || dstBuf == null || flags < 0) - throw new Exception("Invalid argument in encodeYUV()"); - int width = srcImage.getWidth(); - int height = srcImage.getHeight(); - int pixelFormat; boolean intPixels = false; - if (byteOrder == null) - byteOrder = ByteOrder.nativeOrder(); - switch(srcImage.getType()) { - case BufferedImage.TYPE_3BYTE_BGR: - pixelFormat = TJ.PF_BGR; break; - case BufferedImage.TYPE_4BYTE_ABGR: - case BufferedImage.TYPE_4BYTE_ABGR_PRE: - pixelFormat = TJ.PF_XBGR; break; - case BufferedImage.TYPE_BYTE_GRAY: - pixelFormat = TJ.PF_GRAY; break; - case BufferedImage.TYPE_INT_BGR: - if (byteOrder == ByteOrder.BIG_ENDIAN) - pixelFormat = TJ.PF_XBGR; - else - pixelFormat = TJ.PF_RGBX; - intPixels = true; break; - case BufferedImage.TYPE_INT_RGB: - case BufferedImage.TYPE_INT_ARGB: - case BufferedImage.TYPE_INT_ARGB_PRE: - if (byteOrder == ByteOrder.BIG_ENDIAN) - pixelFormat = TJ.PF_XRGB; - else - pixelFormat = TJ.PF_BGRX; - intPixels = true; break; - default: - throw new Exception("Unsupported BufferedImage format"); - } - WritableRaster wr = srcImage.getRaster(); - if (subsamp < 0) throw new Exception("Subsampling level not set"); - if (intPixels) { - SinglePixelPackedSampleModel sm = - (SinglePixelPackedSampleModel)srcImage.getSampleModel(); - int stride = sm.getScanlineStride(); - DataBufferInt db = (DataBufferInt)wr.getDataBuffer(); - int[] buf = db.getData(); - encodeYUV(buf, width, stride, height, pixelFormat, dstBuf, yuvPad, - subsamp, flags); - } else { - ComponentSampleModel sm = - (ComponentSampleModel)srcImage.getSampleModel(); - int pixelSize = sm.getPixelStride(); - if (pixelSize != TJ.getPixelSize(pixelFormat)) - throw new Exception("Inconsistency between pixel format and pixel size in BufferedImage"); - int pitch = sm.getScanlineStride(); - DataBufferByte db = (DataBufferByte)wr.getDataBuffer(); - byte[] buf = db.getData(); - encodeYUV(buf, width, pitch, height, pixelFormat, dstBuf, yuvPad, - subsamp, flags); - } - compressedSize = TJ.bufSizeYUV(width, yuvPad, height, subsamp); + setSourceImage(srcImage, 0, 0, 0, 0); + encodeYUV(dstBuf, flags); } /** - * Encode the uncompressed source image stored in srcImage - * and return a buffer containing a YUV planar image. See - * {@link #encodeYUV(byte[], int)} for more detail. - * - * @param srcImage a BufferedImage instance containing RGB or - * grayscale pixels to be encoded - * - * @param flags the bitwise OR of one or more of {@link TJ TJ.FLAG_*} - * - * @return a buffer containing a YUV planar image + * @deprecated Use + * {@link #setSourceImage(BufferedImage, int, int, int, int)} and + * {@link #encodeYUV(int)} instead. */ + @Deprecated public byte[] encodeYUV(BufferedImage srcImage, int flags) throws Exception { - if (subsamp < 0) - throw new Exception("Subsampling level not set"); - int width = srcImage.getWidth(); - int height = srcImage.getHeight(); - byte[] buf = new byte[TJ.bufSizeYUV(width, yuvPad, height, subsamp)]; - encodeYUV(srcImage, buf, flags); - return buf; + setSourceImage(srcImage, 0, 0, 0, 0); + return encodeYUV(flags); } /** @@ -603,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(); @@ -621,14 +594,15 @@ public class TJCompressor { private long handle = 0; private byte[] srcBuf = null; + private int[] srcBufInt = null; private int srcWidth = 0; private int srcHeight = 0; private int srcX = -1; private int srcY = -1; 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 d14a9892..83057212 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. - * - * @return the width of the JPEG image associated with this decompressor - * instance + * @deprecated Use {@link #setSourceImage(byte[], int)} instead. */ - public int getWidth() throws Exception { - if (jpegWidth < 1) - throw new Exception(NO_ASSOC_ERROR); - return jpegWidth; + @Deprecated + public void setJPEGImage(byte[] jpegImage, int imageSize) throws Exception { + setSourceImage(jpegImage, imageSize); } /** - * Returns the height of the JPEG image associated with this decompressor - * instance. + * 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. * - * @return the height of the JPEG image associated with this decompressor - * instance + * @param srcImage {@link YUVImage} instance containing a YUV planar image to + * be decoded */ - public int getHeight() throws Exception { - if (jpegHeight < 1) - throw new Exception(NO_ASSOC_ERROR); - return jpegHeight; + 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 level of chrominance subsampling used in the JPEG image - * associated with this decompressor instance. See {@link TJ TJ.SAMP_*}. - * - * @return the level of chrominance subsampling used in the JPEG image - * associated with this decompressor instance - */ - public int getSubsamp() throws Exception { - if (jpegSubsamp < 0) - throw new Exception(NO_ASSOC_ERROR); - if (jpegSubsamp >= TJ.NUMSAMP) - throw new Exception("JPEG header information is invalid"); - return jpegSubsamp; - } /** - * Returns the colorspace used in the JPEG image associated with this - * decompressor instance. See {@link TJ TJ.CS_*}. + * Returns the width of the source image (JPEG or YUV) associated with this + * decompressor instance. * - * @return the colorspace used in the JPEG image associated with this + * @return the width of the source image (JPEG or YUV) associated with this * decompressor instance */ - public int getColorspace() throws Exception { - if (jpegColorspace < 0) + public int getWidth() throws Exception { + if (yuvImage != null) + return yuvImage.getWidth(); + if (srcWidth < 1) throw new Exception(NO_ASSOC_ERROR); - if (jpegColorspace >= TJ.NUMCS) - throw new Exception("JPEG header information is invalid"); - return jpegColorspace; + return srcWidth; } /** - * Returns the JPEG image buffer associated with this decompressor instance. + * Returns the height of the source image (JPEG or YUV) associated with this + * decompressor instance. * - * @return the JPEG image buffer 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 (yuvImage != null) + return yuvImage.getHeight(); + if (srcHeight < 1) + throw new Exception(NO_ASSOC_ERROR); + return srcHeight; + } + + /** + * 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 source image + * (JPEG or YUV) associated with this decompressor instance + */ + public int getSubsamp() throws Exception { + if (yuvImage != null) + return yuvImage.getSubsamp(); + if (srcSubsamp < 0) + throw new Exception(NO_ASSOC_ERROR); + if (srcSubsamp >= TJ.NUMSAMP) + throw new Exception("JPEG header information is invalid"); + return srcSubsamp; + } + + /** + * 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 source image (JPEG or YUV) associated + * with this decompressor instance + */ + public int getColorspace() throws Exception { + if (yuvImage != null) + return TJ.CS_YCbCr; + if (srcColorspace < 0) + throw new Exception(NO_ASSOC_ERROR); + if (srcColorspace >= TJ.NUMCS) + throw new Exception("JPEG header information is invalid"); + return srcColorspace; + } + + /** + * Returns the source 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. + * 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 image. This - * buffer should normally be pitch * scaledHeight bytes in size, - * where scaledHeight can be determined by calling + * @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. + * 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 into which the JPEG image - * should be decompressed, relative to the start of dstBuf. + * @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 into which the JPEG image - * should be decompressed, relative to the start of dstBuf. + * @param y y offset (in pixels) of the region in the destination image into + * which the source image should be decompressed/decoded * - * @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.) + * @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). + * 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 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 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_*}) + * @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 TJ.FLAG_*} + * @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. + * 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 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. 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_*} + * @param flags the bitwise OR of one or more of + * {@link TJ#FLAG_BOTTOMUP TJ.FLAG_*} + * + * @return a YUV planar image */ - 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 TJ.FLAG_*} - * - * @return a buffer containing 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. + * 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 image. This - * buffer should normally be stride * scaledHeight pixels in - * size, where scaledHeight can be determined by calling + * @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. + * 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 into which the JPEG image - * should be decompressed, relative to the start of dstBuf. + * @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 into which the JPEG image - * should be decompressed, relative to the start of dstBuf. + * @param y y offset (in pixels) of the region in the destination image into + * which the source image should be decompressed/decoded * - * @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.) + * @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. + * 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 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 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 + * 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 TJ.FLAG_*} + * @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 f84eaa12..ee1f6071 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 00000000..619b0c31 --- /dev/null +++ b/java/org/libjpegturbo/turbojpeg/YUVImage.java @@ -0,0 +1,213 @@ +/* + * 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 { + setBuf(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. Use {@link TJ#bufSizeYUV} to determine the minimum 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 { + setBuf(yuvImage, width, pad, height, subsamp); + } + + /** + * Assign an existing YUV planar image buffer to this YUVImage + * instance. + * + * @param yuvImage image buffer that contains or will contain YUV planar + * image data. See {@link YUVImage above} for a description of the image + * format. Use {@link TJ#bufSizeYUV} to determine the minimum 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 void setBuf(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 not large enough"); + 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 TJ.bufSizeYUV(yuvWidth, yuvPad, yuvHeight, yuvSubsamp); + } + + 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 50070efa..edb23b4d 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 203f0048..1d8205c5 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/jchuff.c b/jchuff.c index 29bf3892..68e4e0e0 100644 --- a/jchuff.c +++ b/jchuff.c @@ -22,8 +22,36 @@ #include "jchuff.h" /* Declarations shared with jcphuff.c */ #include +/* + * NOTE: If USE_CLZ_INTRINSIC is defined, then clz/bsr instructions will be + * used for bit counting rather than the lookup table. This will reduce the + * memory footprint by 64k, which is important for some mobile applications + * that create many isolated instances of libjpeg-turbo (web browsers, for + * instance.) This may improve performance on some mobile platforms as well. + * This feature is enabled by default only on ARM processors, because some x86 + * chips have a slow implementation of bsr, and the use of clz/bsr cannot be + * shown to have a significant performance impact even on the x86 chips that + * have a fast implementation of it. When building for ARMv6, you can + * explicitly disable the use of clz/bsr by adding -mthumb to the compiler + * flags (this defines __thumb__). + */ + +/* NOTE: Both GCC and Clang define __GNUC__ */ +#if defined __GNUC__ && defined __arm__ +#if !defined __thumb__ || defined __thumb2__ +#define USE_CLZ_INTRINSIC +#endif +#endif + +#ifdef USE_CLZ_INTRINSIC +#define JPEG_NBITS_NONZERO(x) (32 - __builtin_clz(x)) +#define JPEG_NBITS(x) (x ? JPEG_NBITS_NONZERO(x) : 0) +#else static unsigned char jpeg_nbits_table[65536]; static int jpeg_nbits_table_init = 0; +#define JPEG_NBITS(x) (jpeg_nbits_table[x]) +#define JPEG_NBITS_NONZERO(x) JPEG_NBITS(x) +#endif #ifndef min #define min(a,b) ((a)<(b)?(a):(b)) @@ -272,6 +300,7 @@ jpeg_make_c_derived_tbl (j_compress_ptr cinfo, boolean isDC, int tblno, dtbl->ehufsi[i] = huffsize[p]; } +#ifndef USE_CLZ_INTRINSIC if(!jpeg_nbits_table_init) { for(i = 0; i < 65536; i++) { int nbits = 0, temp = i; @@ -280,6 +309,7 @@ jpeg_make_c_derived_tbl (j_compress_ptr cinfo, boolean isDC, int tblno, } jpeg_nbits_table_init = 1; } +#endif } @@ -482,7 +512,7 @@ encode_one_block (working_state * state, JCOEFPTR block, int last_dc_val, temp2 += temp3; /* Find the number of bits needed for the magnitude of the coefficient */ - nbits = jpeg_nbits_table[temp]; + nbits = JPEG_NBITS(temp); /* Emit the Huffman-coded symbol for the number of bits */ code = dctbl->ehufco[nbits]; @@ -516,7 +546,7 @@ encode_one_block (working_state * state, JCOEFPTR block, int last_dc_val, temp ^= temp3; \ temp -= temp3; \ temp2 += temp3; \ - nbits = jpeg_nbits_table[temp]; \ + nbits = JPEG_NBITS_NONZERO(temp); \ /* if run length > 15, must emit special run-length-16 codes (0xF0) */ \ while (r > 15) { \ EMIT_BITS(code_0xf0, size_0xf0) \ diff --git a/jcparam.c b/jcparam.c index 4151bbe0..3121e6d3 100644 --- a/jcparam.c +++ b/jcparam.c @@ -18,6 +18,7 @@ #define JPEG_INTERNALS #include "jinclude.h" #include "jpeglib.h" +#include "jstdhuff.c" /* @@ -191,116 +192,6 @@ jpeg_set_quality (j_compress_ptr cinfo, int quality, boolean force_baseline) } -/* - * Huffman table setup routines - */ - -LOCAL(void) -add_huff_table (j_compress_ptr cinfo, - JHUFF_TBL **htblptr, const UINT8 *bits, const UINT8 *val) -/* Define a Huffman table */ -{ - int nsymbols, len; - - if (*htblptr == NULL) - *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo); - - /* Copy the number-of-symbols-of-each-code-length counts */ - MEMCOPY((*htblptr)->bits, bits, SIZEOF((*htblptr)->bits)); - - /* Validate the counts. We do this here mainly so we can copy the right - * number of symbols from the val[] array, without risking marching off - * the end of memory. jchuff.c will do a more thorough test later. - */ - nsymbols = 0; - for (len = 1; len <= 16; len++) - nsymbols += bits[len]; - if (nsymbols < 1 || nsymbols > 256) - ERREXIT(cinfo, JERR_BAD_HUFF_TABLE); - - MEMCOPY((*htblptr)->huffval, val, nsymbols * SIZEOF(UINT8)); - - /* Initialize sent_table FALSE so table will be written to JPEG file. */ - (*htblptr)->sent_table = FALSE; -} - - -LOCAL(void) -std_huff_tables (j_compress_ptr cinfo) -/* Set up the standard Huffman tables (cf. JPEG standard section K.3) */ -/* IMPORTANT: these are only valid for 8-bit data precision! */ -{ - static const UINT8 bits_dc_luminance[17] = - { /* 0-base */ 0, 0, 1, 5, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0 }; - static const UINT8 val_dc_luminance[] = - { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 }; - - static const UINT8 bits_dc_chrominance[17] = - { /* 0-base */ 0, 0, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 }; - static const UINT8 val_dc_chrominance[] = - { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 }; - - static const UINT8 bits_ac_luminance[17] = - { /* 0-base */ 0, 0, 2, 1, 3, 3, 2, 4, 3, 5, 5, 4, 4, 0, 0, 1, 0x7d }; - static const UINT8 val_ac_luminance[] = - { 0x01, 0x02, 0x03, 0x00, 0x04, 0x11, 0x05, 0x12, - 0x21, 0x31, 0x41, 0x06, 0x13, 0x51, 0x61, 0x07, - 0x22, 0x71, 0x14, 0x32, 0x81, 0x91, 0xa1, 0x08, - 0x23, 0x42, 0xb1, 0xc1, 0x15, 0x52, 0xd1, 0xf0, - 0x24, 0x33, 0x62, 0x72, 0x82, 0x09, 0x0a, 0x16, - 0x17, 0x18, 0x19, 0x1a, 0x25, 0x26, 0x27, 0x28, - 0x29, 0x2a, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, - 0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, - 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, - 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, - 0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, - 0x7a, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, - 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, - 0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, - 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, - 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3, 0xc4, 0xc5, - 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2, 0xd3, 0xd4, - 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xe1, 0xe2, - 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, - 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, - 0xf9, 0xfa }; - - static const UINT8 bits_ac_chrominance[17] = - { /* 0-base */ 0, 0, 2, 1, 2, 4, 4, 3, 4, 7, 5, 4, 4, 0, 1, 2, 0x77 }; - static const UINT8 val_ac_chrominance[] = - { 0x00, 0x01, 0x02, 0x03, 0x11, 0x04, 0x05, 0x21, - 0x31, 0x06, 0x12, 0x41, 0x51, 0x07, 0x61, 0x71, - 0x13, 0x22, 0x32, 0x81, 0x08, 0x14, 0x42, 0x91, - 0xa1, 0xb1, 0xc1, 0x09, 0x23, 0x33, 0x52, 0xf0, - 0x15, 0x62, 0x72, 0xd1, 0x0a, 0x16, 0x24, 0x34, - 0xe1, 0x25, 0xf1, 0x17, 0x18, 0x19, 0x1a, 0x26, - 0x27, 0x28, 0x29, 0x2a, 0x35, 0x36, 0x37, 0x38, - 0x39, 0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, - 0x49, 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, - 0x59, 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, - 0x69, 0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, - 0x79, 0x7a, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, - 0x88, 0x89, 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96, - 0x97, 0x98, 0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5, - 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4, - 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3, - 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2, - 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, - 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, - 0xea, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, - 0xf9, 0xfa }; - - add_huff_table(cinfo, &cinfo->dc_huff_tbl_ptrs[0], - bits_dc_luminance, val_dc_luminance); - add_huff_table(cinfo, &cinfo->ac_huff_tbl_ptrs[0], - bits_ac_luminance, val_ac_luminance); - add_huff_table(cinfo, &cinfo->dc_huff_tbl_ptrs[1], - bits_dc_chrominance, val_dc_chrominance); - add_huff_table(cinfo, &cinfo->ac_huff_tbl_ptrs[1], - bits_ac_chrominance, val_ac_chrominance); -} - - /* * Default parameter setup for compression. * @@ -339,7 +230,7 @@ jpeg_set_defaults (j_compress_ptr cinfo) /* Set up two quantization tables using default quality of 75 */ jpeg_set_quality(cinfo, 75, TRUE); /* Set up two Huffman tables */ - std_huff_tables(cinfo); + std_huff_tables((j_common_ptr) cinfo); /* Initialize default arithmetic coding conditioning */ for (i = 0; i < NUM_ARITH_TBLS; i++) { diff --git a/jcstest.c b/jcstest.c index 08a12adc..c0eec6e7 100644 --- a/jcstest.c +++ b/jcstest.c @@ -80,7 +80,7 @@ int main(void) jerr.pub.output_message = my_output_message; if(setjmp(jerr.jb)) { - // this will execute if libjpeg has an error + /* this will execute if libjpeg has an error */ jcs_valid = 0; goto done; } @@ -108,7 +108,7 @@ int main(void) #endif if(setjmp(jerr.jb)) { - // this will execute if libjpeg has an error + /* this will execute if libjpeg has an error */ jcs_alpha_valid = 0; goto done2; } diff --git a/jdhuff.c b/jdhuff.c index dba5f18a..d21d3992 100644 --- a/jdhuff.c +++ b/jdhuff.c @@ -21,6 +21,7 @@ #include "jpeglib.h" #include "jdhuff.h" /* Declarations shared with jdphuff.c */ #include "jpegcomp.h" +#include "jstdhuff.c" /* @@ -795,6 +796,12 @@ jinit_huff_decoder (j_decompress_ptr cinfo) huff_entropy_ptr entropy; int i; + /* Motion JPEG frames typically do not include the Huffman tables if they + are the default tables. Thus, if the tables are not set by the time + the Huffman decoder is initialized (usually within the body of + jpeg_start_decompress()), we set them to default values. */ + std_huff_tables((j_common_ptr) cinfo); + entropy = (huff_entropy_ptr) (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, SIZEOF(huff_entropy_decoder)); diff --git a/jdmarker.c b/jdmarker.c index a19219fa..c8771bc0 100644 --- a/jdmarker.c +++ b/jdmarker.c @@ -478,14 +478,15 @@ get_dht (j_decompress_ptr cinfo) if (index & 0x10) { /* AC table definition */ index -= 0x10; + if (index < 0 || index >= NUM_HUFF_TBLS) + ERREXIT1(cinfo, JERR_DHT_INDEX, index); htblptr = &cinfo->ac_huff_tbl_ptrs[index]; } else { /* DC table definition */ + if (index < 0 || index >= NUM_HUFF_TBLS) + ERREXIT1(cinfo, JERR_DHT_INDEX, index); htblptr = &cinfo->dc_huff_tbl_ptrs[index]; } - if (index < 0 || index >= NUM_HUFF_TBLS) - ERREXIT1(cinfo, JERR_DHT_INDEX, index); - if (*htblptr == NULL) *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo); diff --git a/jdphuff.c b/jdphuff.c index 22678099..fa97aab6 100644 --- a/jdphuff.c +++ b/jdphuff.c @@ -198,6 +198,7 @@ start_pass_phuff_decoder (j_decompress_ptr cinfo) * On some machines, a shift and add will be faster than a table lookup. */ +#define AVOID_TABLES #ifdef AVOID_TABLES #define HUFF_EXTEND(x,s) ((x) < (1<<((s)-1)) ? (x) + (((-1)<<(s)) + 1) : (x)) diff --git a/jstdhuff.c b/jstdhuff.c new file mode 100644 index 00000000..7fec6caf --- /dev/null +++ b/jstdhuff.c @@ -0,0 +1,133 @@ +/* +* jstdhuff.c +* +* This file was part of the Independent JPEG Group's software: +* Copyright (C) 1991-1998, Thomas G. Lane. +* libjpeg-turbo Modifications: +* Copyright (C) 2013, D. R. Commander. +* For conditions of distribution and use, see the accompanying README file. +* +* This file contains routines to set the default Huffman tables, if they are +* not already set. +*/ + +/* + * Huffman table setup routines + */ + +LOCAL(void) +add_huff_table (j_common_ptr cinfo, + JHUFF_TBL **htblptr, const UINT8 *bits, const UINT8 *val) +/* Define a Huffman table */ +{ + int nsymbols, len; + + if (*htblptr == NULL) + *htblptr = jpeg_alloc_huff_table(cinfo); + else + return; + + /* Copy the number-of-symbols-of-each-code-length counts */ + MEMCOPY((*htblptr)->bits, bits, SIZEOF((*htblptr)->bits)); + + /* Validate the counts. We do this here mainly so we can copy the right + * number of symbols from the val[] array, without risking marching off + * the end of memory. jchuff.c will do a more thorough test later. + */ + nsymbols = 0; + for (len = 1; len <= 16; len++) + nsymbols += bits[len]; + if (nsymbols < 1 || nsymbols > 256) + ERREXIT(cinfo, JERR_BAD_HUFF_TABLE); + + MEMCOPY((*htblptr)->huffval, val, nsymbols * SIZEOF(UINT8)); + + /* Initialize sent_table FALSE so table will be written to JPEG file. */ + (*htblptr)->sent_table = FALSE; +} + + +LOCAL(void) +std_huff_tables (j_common_ptr cinfo) +/* Set up the standard Huffman tables (cf. JPEG standard section K.3) */ +/* IMPORTANT: these are only valid for 8-bit data precision! */ +{ + JHUFF_TBL **dc_huff_tbl_ptrs, **ac_huff_tbl_ptrs; + + static const UINT8 bits_dc_luminance[17] = + { /* 0-base */ 0, 0, 1, 5, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0 }; + static const UINT8 val_dc_luminance[] = + { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 }; + + static const UINT8 bits_dc_chrominance[17] = + { /* 0-base */ 0, 0, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 }; + static const UINT8 val_dc_chrominance[] = + { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 }; + + static const UINT8 bits_ac_luminance[17] = + { /* 0-base */ 0, 0, 2, 1, 3, 3, 2, 4, 3, 5, 5, 4, 4, 0, 0, 1, 0x7d }; + static const UINT8 val_ac_luminance[] = + { 0x01, 0x02, 0x03, 0x00, 0x04, 0x11, 0x05, 0x12, + 0x21, 0x31, 0x41, 0x06, 0x13, 0x51, 0x61, 0x07, + 0x22, 0x71, 0x14, 0x32, 0x81, 0x91, 0xa1, 0x08, + 0x23, 0x42, 0xb1, 0xc1, 0x15, 0x52, 0xd1, 0xf0, + 0x24, 0x33, 0x62, 0x72, 0x82, 0x09, 0x0a, 0x16, + 0x17, 0x18, 0x19, 0x1a, 0x25, 0x26, 0x27, 0x28, + 0x29, 0x2a, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, + 0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, + 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, + 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, + 0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, + 0x7a, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, + 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, + 0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, + 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, + 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3, 0xc4, 0xc5, + 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2, 0xd3, 0xd4, + 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xe1, 0xe2, + 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, + 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, + 0xf9, 0xfa }; + + static const UINT8 bits_ac_chrominance[17] = + { /* 0-base */ 0, 0, 2, 1, 2, 4, 4, 3, 4, 7, 5, 4, 4, 0, 1, 2, 0x77 }; + static const UINT8 val_ac_chrominance[] = + { 0x00, 0x01, 0x02, 0x03, 0x11, 0x04, 0x05, 0x21, + 0x31, 0x06, 0x12, 0x41, 0x51, 0x07, 0x61, 0x71, + 0x13, 0x22, 0x32, 0x81, 0x08, 0x14, 0x42, 0x91, + 0xa1, 0xb1, 0xc1, 0x09, 0x23, 0x33, 0x52, 0xf0, + 0x15, 0x62, 0x72, 0xd1, 0x0a, 0x16, 0x24, 0x34, + 0xe1, 0x25, 0xf1, 0x17, 0x18, 0x19, 0x1a, 0x26, + 0x27, 0x28, 0x29, 0x2a, 0x35, 0x36, 0x37, 0x38, + 0x39, 0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, + 0x49, 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, + 0x59, 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, + 0x69, 0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, + 0x79, 0x7a, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, + 0x88, 0x89, 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96, + 0x97, 0x98, 0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5, + 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4, + 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3, + 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2, + 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, + 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, + 0xea, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, + 0xf9, 0xfa }; + + if (cinfo->is_decompressor) { + dc_huff_tbl_ptrs = ((j_decompress_ptr)cinfo)->dc_huff_tbl_ptrs; + ac_huff_tbl_ptrs = ((j_decompress_ptr)cinfo)->ac_huff_tbl_ptrs; + } else { + dc_huff_tbl_ptrs = ((j_compress_ptr)cinfo)->dc_huff_tbl_ptrs; + ac_huff_tbl_ptrs = ((j_compress_ptr)cinfo)->ac_huff_tbl_ptrs; + } + + add_huff_table(cinfo, &dc_huff_tbl_ptrs[0], bits_dc_luminance, + val_dc_luminance); + add_huff_table(cinfo, &ac_huff_tbl_ptrs[0], bits_ac_luminance, + val_ac_luminance); + add_huff_table(cinfo, &dc_huff_tbl_ptrs[1], bits_dc_chrominance, + val_dc_chrominance); + add_huff_table(cinfo, &ac_huff_tbl_ptrs[1], bits_ac_chrominance, + val_ac_chrominance); +} diff --git a/jversion.h b/jversion.h index 437b1712..9327a293 100644 --- a/jversion.h +++ b/jversion.h @@ -4,7 +4,7 @@ * This file was part of the Independent JPEG Group's software: * Copyright (C) 1991-2012, Thomas G. Lane, Guido Vollbeding. * Modifications: - * Copyright (C) 2010, 2012-2013, D. R. Commander. + * Copyright (C) 2010, 2012-2014, D. R. Commander. * mozjpeg Modifications: * Copyright (C) 2014, Mozilla Corporation. * For conditions of distribution and use, see the accompanying README file. @@ -30,7 +30,8 @@ #define JCOPYRIGHT "Copyright (C) 1991-2012 Thomas G. Lane, Guido Vollbeding\n" \ "Copyright (C) 1999-2006 MIYASAKA Masaru\n" \ "Copyright (C) 2009 Pierre Ossman for Cendio AB\n" \ - "Copyright (C) 2009-2013 D. R. Commander\n" \ + "Copyright (C) 2009-2014 D. R. Commander\n" \ "Copyright (C) 2009-2011 Nokia Corporation and/or its subsidiary(-ies)\n" \ - "Copyright (C) 2014 Mozilla Corporation\n" - + "Copyright (C) 2014 Mozilla Corporation\n" \ + "Copyright (C) 2013 MIPS Technologies, Inc.\n" \ + "Copyright (C) 2013 Linaro Limited" diff --git a/release/Description.plist.in b/release/Description.plist.in deleted file mode 100644 index 46a5bceb..00000000 --- a/release/Description.plist.in +++ /dev/null @@ -1,12 +0,0 @@ - - - - - IFPkgDescriptionDescription - A SIMD-accelerated JPEG codec that provides both the libjpeg and TurboJPEG APIs - IFPkgDescriptionTitle - @PACKAGE_NAME@ - IFPkgDescriptionVersion - @VERSION@ - - diff --git a/release/Distribution.xml b/release/Distribution.xml new file mode 100644 index 00000000..ee73ab00 --- /dev/null +++ b/release/Distribution.xml @@ -0,0 +1,24 @@ + + + libjpeg-turbo + + + + + + + + + + + + + + + libjpeg-turbo.pkg + diff --git a/release/Info.plist.in b/release/Info.plist.in deleted file mode 100755 index 99aad9d7..00000000 --- a/release/Info.plist.in +++ /dev/null @@ -1,44 +0,0 @@ - - - - - CFBundleGetInfoString - @VERSION@, The libmozjpeg Project - CFBundleIdentifier - com.libmozjpeg.libmozjpeg - CFBundleShortVersionString - @VERSION@ - IFMajorVersion - 1 - IFMinorVersion - @BUILD@ - IFPkgFlagAllowBackRev - - IFPkgFlagAuthorizationAction - AdminAuthorization - IFPkgFlagBackgroundAlignment - topleft - IFPkgFlagBackgroundScaling - none - IFPkgFlagDefaultLocation - / - IFPkgFlagFollowLinks - - IFPkgFlagInstallFat - - IFPkgFlagIsRequired - - IFPkgFlagOverwritePermissions - - IFPkgFlagRelocatable - - IFPkgFlagRestartAction - NoRestart - IFPkgFlagRootVolumeOnly - - IFPkgFlagUpdateInstalledLanguages - - IFPkgFormatVersion - 0.10000000149011612 - - diff --git a/release/ReadMe.rtf b/release/ReadMe.rtf deleted file mode 100644 index 46e738d6..00000000 --- a/release/ReadMe.rtf +++ /dev/null @@ -1,13 +0,0 @@ -{\rtf1\ansi\ansicpg1252\cocoartf1265\cocoasubrtf190 -\cocoascreenfonts1{\fonttbl\f0\fswiss\fcharset0 Helvetica;} -{\colortbl;\red255\green255\blue255;} -\margl1440\margr1440\vieww13560\viewh16600\viewkind0 -\deftab720 -\pard\pardeftab720 - -\f0\fs24 \cf0 libmozjpeg is a JPEG image codec that uses SIMD instructions (MMX, SSE2, NEON) to accelerate baseline JPEG compression and decompression on x86, x86-64, and ARM systems. On such systems, libmozjpeg is generally 2-4x as fast as libjpeg, all else being equal. On other types of systems, libmozjpeg can still outperform libjpeg by a significant amount, by virtue of its highly-optimized Huffman coding routines. In many cases, the performance of libmozjpeg rivals that of proprietary high-speed JPEG codecs.\ -\ -libmozjpeg implements both the traditional libjpeg API as well as the less powerful but more straightforward TurboJPEG API. libmozjpeg also features colorspace extensions that allow it to compress from/decompress to 32-bit and big-endian pixel buffers (RGBX, XBGR, etc.), as well as a full-featured Java interface.\ -\ -libmozjpeg was forked from libjpeg-turbo. libjpeg-turbo was originally based on libjpeg/SIMD, an MMX-accelerated derivative of libjpeg v6b developed by Miyasaka Masaru. The TigerVNC and VirtualGL projects made numerous enhancements to the codec in 2009, and in early 2010, libjpeg-turbo spun off into an independent project, with the goal of making high-speed JPEG compression/decompression technology available to a broader range of users and developers.\ -} \ No newline at end of file diff --git a/release/ReadMe.txt b/release/ReadMe.txt new file mode 100644 index 00000000..b9f6ca57 --- /dev/null +++ b/release/ReadMe.txt @@ -0,0 +1,5 @@ +libjpeg-turbo is a JPEG image codec that uses SIMD instructions (MMX, SSE2, NEON) to accelerate baseline JPEG compression and decompression on x86, x86-64, and ARM systems. On such systems, libjpeg-turbo is generally 2-4x as fast as libjpeg, all else being equal. On other types of systems, libjpeg-turbo can still outperform libjpeg by a significant amount, by virtue of its highly-optimized Huffman coding routines. In many cases, the performance of libjpeg-turbo rivals that of proprietary high-speed JPEG codecs. + +libjpeg-turbo implements both the traditional libjpeg API as well as the less powerful but more straightforward TurboJPEG API. libjpeg-turbo also features colorspace extensions that allow it to compress from/decompress to 32-bit and big-endian pixel buffers (RGBX, XBGR, etc.), as well as a full-featured Java interface. + +libjpeg-turbo was originally based on libjpeg/SIMD, an MMX-accelerated derivative of libjpeg v6b developed by Miyasaka Masaru. The TigerVNC and VirtualGL projects made numerous enhancements to the codec in 2009, and in early 2010, libjpeg-turbo spun off into an independent project, with the goal of making high-speed JPEG compression/decompression technology available to a broader range of users and developers. diff --git a/release/libmozjpeg.spec.in b/release/libmozjpeg.spec.in index 51ffd112..7678ca37 100644 --- a/release/libmozjpeg.spec.in +++ b/release/libmozjpeg.spec.in @@ -8,7 +8,7 @@ %define _datadir %{__datadir} # Path under which docs should be installed -%define _docdir %{_defaultdocdir}/%{name}-%{version} +%define _docdir /usr/share/doc/%{name}-%{version} # Path under which headers should be installed %define _includedir %{__includedir} diff --git a/release/makecygwinpkg.in b/release/makecygwinpkg.in index 9c798e63..ac3ca982 100755 --- a/release/makecygwinpkg.in +++ b/release/makecygwinpkg.in @@ -17,19 +17,15 @@ onexit() PACKAGE_NAME=@PKGNAME@ VERSION=@VERSION@ +BUILD=@BUILD@ SRCDIR=@abs_top_srcdir@ -RPMARCH=@RPMARCH@ -PLATFORM=cygwin PREFIX=%{__prefix} DOCDIR=%{__docdir} LIBDIR=%{__libdir} umask 022 -if [ "$RPMARCH" = "x86_64" ]; then - PLATFORM=cygwin64 -fi -rm -f $PACKAGE_NAME-$VERSION-$PLATFORM.tar.bz2 +rm -f $PACKAGE_NAME-$VERSION-$BUILD.tar.bz2 TMPDIR=`mktemp -d /tmp/ljtbuild.XXXXXX` __PWD=`pwd` make install DESTDIR=$TMPDIR/pkg docdir=/usr/share/doc/$PACKAGE_NAME-$VERSION \ @@ -39,7 +35,7 @@ if [ "$PREFIX" = "/opt/libmozjpeg" -a "$DOCDIR" = "/opt/libmozjpeg/doc" ]; then ln -fs /usr/share/doc/$PACKAGE_NAME-$VERSION $TMPDIR/pkg$DOCDIR fi cd $TMPDIR/pkg -tar cfj ../$PACKAGE_NAME-$VERSION-$PLATFORM.tar.bz2 * +tar cfj ../$PACKAGE_NAME-$VERSION-$BUILD.tar.bz2 * cd $__PWD mv $TMPDIR/*.tar.bz2 . diff --git a/release/makemacpkg.in b/release/makemacpkg.in index 2ccba9c8..8b887949 100644 --- a/release/makemacpkg.in +++ b/release/makemacpkg.in @@ -11,7 +11,7 @@ TMPDIR= onexit() { if [ ! "$TMPDIR" = "" ]; then - sudo rm -rf $TMPDIR + rm -rf $TMPDIR fi } @@ -78,7 +78,6 @@ while [ $# -gt 0 ]; do esac shift done -PACKAGEMAKER=/Developer/Applications/Utilities/PackageMaker.app/Contents/MacOS/PackageMaker if [ -f $PACKAGE_NAME-$VERSION.dmg ]; then rm -f $PACKAGE_NAME-$VERSION.dmg @@ -245,21 +244,20 @@ if [ "$PREFIX" = "/opt/libmozjpeg" -a "$LIBDIR" = "/opt/libmozjpeg/lib" ]; then fi fi -chmod 1775 $PKGROOT/Library -chmod 775 $PKGROOT/Library/Documentation -mkdir -p $TMPDIR/pkg/Resources +mkdir -p $TMPDIR/pkg -cp pkgscripts/Description.plist $TMPDIR/pkg/ -cp pkgscripts/Info.plist $TMPDIR/pkg/ install -m 755 pkgscripts/uninstall $PKGROOT/$BINDIR/ -sudo chown -R root:admin $PKGROOT -cp $SRCDIR/release/License.rtf $SRCDIR/release/Welcome.rtf $SRCDIR/release/ReadMe.rtf $TMPDIR/pkg/Resources/ +find $PKGROOT -type f | while read file; do xattr -c $file; done + +cp $SRCDIR/release/License.rtf $SRCDIR/release/Welcome.rtf $SRCDIR/release/ReadMe.txt $TMPDIR/pkg/ mkdir $TMPDIR/dmg -$PACKAGEMAKER -build -v -p $TMPDIR/dmg/$PACKAGE_NAME.pkg \ - -f $PKGROOT -r $TMPDIR/pkg/Resources \ - -i $TMPDIR/pkg/Info.plist -d $TMPDIR/pkg/Description.plist +pkgbuild --root $PKGROOT --version $VERSION.$BUILD \ + --identifier com.libjpeg-turbo.libjpeg-turbo $TMPDIR/pkg/$PACKAGE_NAME.pkg +productbuild --distribution $SRCDIR/release/Distribution.xml \ + --package-path $TMPDIR/pkg/ --resources $TMPDIR/pkg/ \ + $TMPDIR/dmg/$PACKAGE_NAME.pkg hdiutil create -fs HFS+ -volname $PACKAGE_NAME-$VERSION \ -srcfolder "$TMPDIR/dmg" $TMPDIR/$PACKAGE_NAME-$VERSION.dmg cp $TMPDIR/$PACKAGE_NAME-$VERSION.dmg . diff --git a/simd/Makefile.am b/simd/Makefile.am index a4f116e7..f301c0a9 100644 --- a/simd/Makefile.am +++ b/simd/Makefile.am @@ -58,6 +58,12 @@ libsimd_la_SOURCES = jsimd_arm.c jsimd_arm_neon.S endif +if SIMD_ARM_64 + +libsimd_la_SOURCES = jsimd_arm64.c jsimd_arm_neon_64.S + +endif + if SIMD_MIPSEL libsimd_la_SOURCES = jsimd_mips.c jsimd_mips_dspr2_asm.h jsimd_mips_dspr2.S diff --git a/simd/jsimd_arm.c b/simd/jsimd_arm.c index a70db7eb..c6fa4caa 100644 --- a/simd/jsimd_arm.c +++ b/simd/jsimd_arm.c @@ -3,7 +3,7 @@ * * Copyright 2009 Pierre Ossman for Cendio AB * Copyright 2009-2011, 2013 D. R. Commander - * + * * Based on the x86 SIMD extension for IJG JPEG library, * Copyright (C) 1999-2006, MIYASAKA Masaru. * For conditions of distribution and use, see copyright notice in jsimdext.inc diff --git a/simd/jsimd_arm64.c b/simd/jsimd_arm64.c new file mode 100644 index 00000000..d280d621 --- /dev/null +++ b/simd/jsimd_arm64.c @@ -0,0 +1,586 @@ +/* + * jsimd_arm64.c + * + * Copyright 2009 Pierre Ossman for Cendio AB + * Copyright 2009-2011, 2013-2014 D. R. Commander + * + * Based on the x86 SIMD extension for IJG JPEG library, + * Copyright (C) 1999-2006, MIYASAKA Masaru. + * For conditions of distribution and use, see copyright notice in jsimdext.inc + * + * This file contains the interface between the "normal" portions + * of the library and the SIMD implementations when running on + * ARM architecture. + * + * Based on the stubs from 'jsimd_none.c' + */ + +#define JPEG_INTERNALS +#include "../jinclude.h" +#include "../jpeglib.h" +#include "../jsimd.h" +#include "../jdct.h" +#include "../jsimddct.h" +#include "jsimd.h" + +#include +#include +#include + +static unsigned int simd_support = ~0; + +#if defined(__linux__) || defined(ANDROID) || defined(__ANDROID__) + +#define SOMEWHAT_SANE_PROC_CPUINFO_SIZE_LIMIT (1024 * 1024) + +LOCAL(int) +check_feature (char *buffer, char *feature) +{ + char *p; + if (*feature == 0) + return 0; + if (strncmp(buffer, "Features", 8) != 0) + return 0; + buffer += 8; + while (isspace(*buffer)) + buffer++; + + /* Check if 'feature' is present in the buffer as a separate word */ + while ((p = strstr(buffer, feature))) { + if (p > buffer && !isspace(*(p - 1))) { + buffer++; + continue; + } + p += strlen(feature); + if (*p != 0 && !isspace(*p)) { + buffer++; + continue; + } + return 1; + } + return 0; +} + +LOCAL(int) +parse_proc_cpuinfo (int bufsize) +{ + char *buffer = (char *)malloc(bufsize); + FILE *fd; + simd_support = 0; + + if (!buffer) + return 0; + + fd = fopen("/proc/cpuinfo", "r"); + if (fd) { + while (fgets(buffer, bufsize, fd)) { + if (!strchr(buffer, '\n') && !feof(fd)) { + /* "impossible" happened - insufficient size of the buffer! */ + fclose(fd); + free(buffer); + return 0; + } + if (check_feature(buffer, "neon")) + simd_support |= JSIMD_ARM_NEON; + } + fclose(fd); + } + free(buffer); + return 1; +} + +#endif + +/* + * Check what SIMD accelerations are supported. + * + * FIXME: This code is racy under a multi-threaded environment. + */ +LOCAL(void) +init_simd (void) +{ + char *env = NULL; +#if !defined(__ARM_NEON__) && defined(__linux__) || defined(ANDROID) || defined(__ANDROID__) + int bufsize = 1024; /* an initial guess for the line buffer size limit */ +#endif + + if (simd_support != ~0U) + return; + + simd_support = 0; + +#if defined(__ARM_NEON__) + simd_support |= JSIMD_ARM_NEON; +#elif defined(__linux__) || defined(ANDROID) || defined(__ANDROID__) + /* We still have a chance to use NEON regardless of globally used + * -mcpu/-mfpu options passed to gcc by performing runtime detection via + * /proc/cpuinfo parsing on linux/android */ + while (!parse_proc_cpuinfo(bufsize)) { + bufsize *= 2; + if (bufsize > SOMEWHAT_SANE_PROC_CPUINFO_SIZE_LIMIT) + break; + } +#endif + + /* Force different settings through environment variables */ + env = getenv("JSIMD_FORCENEON"); + if ((env != NULL) && (strcmp(env, "1") == 0)) + simd_support &= JSIMD_ARM_NEON; + env = getenv("JSIMD_FORCENONE"); + if ((env != NULL) && (strcmp(env, "1") == 0)) + simd_support = 0; +} + +GLOBAL(int) +jsimd_can_rgb_ycc (void) +{ + init_simd(); + + return 0; +} + +GLOBAL(int) +jsimd_can_rgb_gray (void) +{ + init_simd(); + + return 0; +} + +GLOBAL(int) +jsimd_can_ycc_rgb (void) +{ + init_simd(); + + /* The code is optimised for these values only */ + if (BITS_IN_JSAMPLE != 8) + return 0; + if (sizeof(JDIMENSION) != 4) + return 0; + if ((RGB_PIXELSIZE != 3) && (RGB_PIXELSIZE != 4)) + return 0; + if (simd_support & JSIMD_ARM_NEON) + return 1; + + return 0; +} + +GLOBAL(void) +jsimd_rgb_ycc_convert (j_compress_ptr cinfo, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows) +{ +} + +GLOBAL(void) +jsimd_rgb_gray_convert (j_compress_ptr cinfo, + JSAMPARRAY input_buf, JSAMPIMAGE output_buf, + JDIMENSION output_row, int num_rows) +{ +} + +GLOBAL(void) +jsimd_ycc_rgb_convert (j_decompress_ptr cinfo, + JSAMPIMAGE input_buf, JDIMENSION input_row, + JSAMPARRAY output_buf, int num_rows) +{ + void (*neonfct)(JDIMENSION, JSAMPIMAGE, JDIMENSION, JSAMPARRAY, int); + + switch(cinfo->out_color_space) + { + case JCS_EXT_RGB: + neonfct=jsimd_ycc_extrgb_convert_neon; + break; + case JCS_EXT_RGBX: + case JCS_EXT_RGBA: + neonfct=jsimd_ycc_extrgbx_convert_neon; + break; + case JCS_EXT_BGR: + neonfct=jsimd_ycc_extbgr_convert_neon; + break; + case JCS_EXT_BGRX: + case JCS_EXT_BGRA: + neonfct=jsimd_ycc_extbgrx_convert_neon; + break; + case JCS_EXT_XBGR: + case JCS_EXT_ABGR: + neonfct=jsimd_ycc_extxbgr_convert_neon; + break; + case JCS_EXT_XRGB: + case JCS_EXT_ARGB: + neonfct=jsimd_ycc_extxrgb_convert_neon; + break; + default: + neonfct=jsimd_ycc_extrgb_convert_neon; + break; + } + + if (simd_support & JSIMD_ARM_NEON) + neonfct(cinfo->output_width, input_buf, + input_row, output_buf, num_rows); +} + +GLOBAL(int) +jsimd_can_h2v2_downsample (void) +{ + init_simd(); + + return 0; +} + +GLOBAL(int) +jsimd_can_h2v1_downsample (void) +{ + init_simd(); + + return 0; +} + +GLOBAL(void) +jsimd_h2v2_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr, + JSAMPARRAY input_data, JSAMPARRAY output_data) +{ +} + +GLOBAL(void) +jsimd_h2v1_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr, + JSAMPARRAY input_data, JSAMPARRAY output_data) +{ +} + +GLOBAL(int) +jsimd_can_h2v2_upsample (void) +{ + init_simd(); + + return 0; +} + +GLOBAL(int) +jsimd_can_h2v1_upsample (void) +{ + init_simd(); + + return 0; +} + +GLOBAL(void) +jsimd_h2v2_upsample (j_decompress_ptr cinfo, + jpeg_component_info * compptr, + JSAMPARRAY input_data, + JSAMPARRAY * output_data_ptr) +{ +} + +GLOBAL(void) +jsimd_h2v1_upsample (j_decompress_ptr cinfo, + jpeg_component_info * compptr, + JSAMPARRAY input_data, + JSAMPARRAY * output_data_ptr) +{ +} + +GLOBAL(int) +jsimd_can_h2v2_fancy_upsample (void) +{ + init_simd(); + + return 0; +} + +GLOBAL(int) +jsimd_can_h2v1_fancy_upsample (void) +{ + init_simd(); + + return 0; +} + +GLOBAL(void) +jsimd_h2v2_fancy_upsample (j_decompress_ptr cinfo, + jpeg_component_info * compptr, + JSAMPARRAY input_data, + JSAMPARRAY * output_data_ptr) +{ +} + +GLOBAL(void) +jsimd_h2v1_fancy_upsample (j_decompress_ptr cinfo, + jpeg_component_info * compptr, + JSAMPARRAY input_data, + JSAMPARRAY * output_data_ptr) +{ +} + +GLOBAL(int) +jsimd_can_h2v2_merged_upsample (void) +{ + init_simd(); + + return 0; +} + +GLOBAL(int) +jsimd_can_h2v1_merged_upsample (void) +{ + init_simd(); + + return 0; +} + +GLOBAL(void) +jsimd_h2v2_merged_upsample (j_decompress_ptr cinfo, + JSAMPIMAGE input_buf, + JDIMENSION in_row_group_ctr, + JSAMPARRAY output_buf) +{ +} + +GLOBAL(void) +jsimd_h2v1_merged_upsample (j_decompress_ptr cinfo, + JSAMPIMAGE input_buf, + JDIMENSION in_row_group_ctr, + JSAMPARRAY output_buf) +{ +} + +GLOBAL(int) +jsimd_can_convsamp (void) +{ + init_simd(); + + return 0; +} + +GLOBAL(int) +jsimd_can_convsamp_float (void) +{ + init_simd(); + + return 0; +} + +GLOBAL(void) +jsimd_convsamp (JSAMPARRAY sample_data, JDIMENSION start_col, + DCTELEM * workspace) +{ +} + +GLOBAL(void) +jsimd_convsamp_float (JSAMPARRAY sample_data, JDIMENSION start_col, + FAST_FLOAT * workspace) +{ +} + +GLOBAL(int) +jsimd_can_fdct_islow (void) +{ + init_simd(); + + return 0; +} + +GLOBAL(int) +jsimd_can_fdct_ifast (void) +{ + init_simd(); + + return 0; +} + +GLOBAL(int) +jsimd_can_fdct_float (void) +{ + init_simd(); + + return 0; +} + +GLOBAL(void) +jsimd_fdct_islow (DCTELEM * data) +{ +} + +GLOBAL(void) +jsimd_fdct_ifast (DCTELEM * data) +{ +} + +GLOBAL(void) +jsimd_fdct_float (FAST_FLOAT * data) +{ +} + +GLOBAL(int) +jsimd_can_quantize (void) +{ + init_simd(); + + return 0; +} + +GLOBAL(int) +jsimd_can_quantize_float (void) +{ + init_simd(); + + return 0; +} + +GLOBAL(void) +jsimd_quantize (JCOEFPTR coef_block, DCTELEM * divisors, + DCTELEM * workspace) +{ +} + +GLOBAL(void) +jsimd_quantize_float (JCOEFPTR coef_block, FAST_FLOAT * divisors, + FAST_FLOAT * workspace) +{ +} + +GLOBAL(int) +jsimd_can_idct_2x2 (void) +{ + init_simd(); + + /* The code is optimised for these values only */ + if (DCTSIZE != 8) + return 0; + if (sizeof(JCOEF) != 2) + return 0; + if (BITS_IN_JSAMPLE != 8) + return 0; + if (sizeof(JDIMENSION) != 4) + return 0; + if (sizeof(ISLOW_MULT_TYPE) != 2) + return 0; + + if ((simd_support & JSIMD_ARM_NEON)) + return 1; + + return 0; +} + +GLOBAL(int) +jsimd_can_idct_4x4 (void) +{ + init_simd(); + + /* The code is optimised for these values only */ + if (DCTSIZE != 8) + return 0; + if (sizeof(JCOEF) != 2) + return 0; + if (BITS_IN_JSAMPLE != 8) + return 0; + if (sizeof(JDIMENSION) != 4) + return 0; + if (sizeof(ISLOW_MULT_TYPE) != 2) + return 0; + + if ((simd_support & JSIMD_ARM_NEON)) + return 1; + + return 0; +} + +GLOBAL(void) +jsimd_idct_2x2 (j_decompress_ptr cinfo, jpeg_component_info * compptr, + JCOEFPTR coef_block, JSAMPARRAY output_buf, + JDIMENSION output_col) +{ + if ((simd_support & JSIMD_ARM_NEON)) + jsimd_idct_2x2_neon(compptr->dct_table, coef_block, output_buf, output_col); +} + +GLOBAL(void) +jsimd_idct_4x4 (j_decompress_ptr cinfo, jpeg_component_info * compptr, + JCOEFPTR coef_block, JSAMPARRAY output_buf, + JDIMENSION output_col) +{ + if ((simd_support & JSIMD_ARM_NEON)) + jsimd_idct_4x4_neon(compptr->dct_table, coef_block, output_buf, output_col); +} + +GLOBAL(int) +jsimd_can_idct_islow (void) +{ + init_simd(); + + /* The code is optimised for these values only */ + if (DCTSIZE != 8) + return 0; + if (sizeof(JCOEF) != 2) + return 0; + if (BITS_IN_JSAMPLE != 8) + return 0; + if (sizeof(JDIMENSION) != 4) + return 0; + if (sizeof(ISLOW_MULT_TYPE) != 2) + return 0; + + if (simd_support & JSIMD_ARM_NEON) + return 1; + + return 0; +} + +GLOBAL(int) +jsimd_can_idct_ifast (void) +{ + init_simd(); + + /* The code is optimised for these values only */ + if (DCTSIZE != 8) + return 0; + if (sizeof(JCOEF) != 2) + return 0; + if (BITS_IN_JSAMPLE != 8) + return 0; + if (sizeof(JDIMENSION) != 4) + return 0; + if (sizeof(IFAST_MULT_TYPE) != 2) + return 0; + if (IFAST_SCALE_BITS != 2) + return 0; + + if ((simd_support & JSIMD_ARM_NEON)) + return 1; + + return 0; +} + +GLOBAL(int) +jsimd_can_idct_float (void) +{ + init_simd(); + + return 0; +} + +GLOBAL(void) +jsimd_idct_islow (j_decompress_ptr cinfo, jpeg_component_info * compptr, + JCOEFPTR coef_block, JSAMPARRAY output_buf, + JDIMENSION output_col) +{ + if ((simd_support & JSIMD_ARM_NEON)) + jsimd_idct_islow_neon(compptr->dct_table, coef_block, output_buf, output_col); +} + +GLOBAL(void) +jsimd_idct_ifast (j_decompress_ptr cinfo, jpeg_component_info * compptr, + JCOEFPTR coef_block, JSAMPARRAY output_buf, + JDIMENSION output_col) +{ + if ((simd_support & JSIMD_ARM_NEON)) + jsimd_idct_ifast_neon(compptr->dct_table, coef_block, output_buf, output_col); +} + +GLOBAL(void) +jsimd_idct_float (j_decompress_ptr cinfo, jpeg_component_info * compptr, + JCOEFPTR coef_block, JSAMPARRAY output_buf, + JDIMENSION output_col) +{ +} + diff --git a/simd/jsimd_arm_neon.S b/simd/jsimd_arm_neon.S index 9962b8a1..ac6c8607 100644 --- a/simd/jsimd_arm_neon.S +++ b/simd/jsimd_arm_neon.S @@ -1,5 +1,5 @@ /* - * ARM NEON optimizations for libjpeg-turbo + * ARMv7 NEON optimizations for libjpeg-turbo * * Copyright (C) 2009-2011 Nokia Corporation and/or its subsidiary(-ies). * All rights reserved. @@ -35,6 +35,7 @@ #define RESPECT_STRICT_ALIGNMENT 1 + /*****************************************************************************/ /* Supplementary macro for setting function attributes */ @@ -62,6 +63,7 @@ _\fname: vtrn.32 \x1, \x3 .endm + #define CENTERJSAMPLE 128 /*****************************************************************************/ @@ -670,6 +672,7 @@ asm_function jsimd_idct_islow_neon .unreq ROW7R .endfunc + /*****************************************************************************/ /* @@ -894,6 +897,7 @@ asm_function jsimd_idct_ifast_neon .unreq TMP4 .endfunc + /*****************************************************************************/ /* @@ -1108,6 +1112,7 @@ asm_function jsimd_idct_4x4_neon .purgem idct_helper + /*****************************************************************************/ /* @@ -1262,6 +1267,7 @@ asm_function jsimd_idct_2x2_neon .purgem idct_helper + /*****************************************************************************/ /* @@ -1561,6 +1567,7 @@ generate_jsimd_ycc_rgb_convert_neon extxrgb, 32, 1, 2, 3 .purgem do_load .purgem do_store + /*****************************************************************************/ /* @@ -1871,6 +1878,7 @@ generate_jsimd_rgb_ycc_convert_neon extxrgb, 32, 1, 2, 3 .purgem do_load .purgem do_store + /*****************************************************************************/ /* @@ -1934,6 +1942,7 @@ asm_function jsimd_convsamp_neon .unreq TMP4 .endfunc + /*****************************************************************************/ /* @@ -2057,6 +2066,7 @@ asm_function jsimd_fdct_ifast_neon .unreq TMP .endfunc + /*****************************************************************************/ /* @@ -2158,6 +2168,7 @@ asm_function jsimd_quantize_neon .unreq LOOP_COUNT .endfunc + /*****************************************************************************/ /* diff --git a/simd/jsimd_arm_neon_64.S b/simd/jsimd_arm_neon_64.S new file mode 100644 index 00000000..2d9e95ef --- /dev/null +++ b/simd/jsimd_arm_neon_64.S @@ -0,0 +1,1832 @@ +/* + * ARMv8 NEON optimizations for libjpeg-turbo + * + * Copyright (C) 2009-2011 Nokia Corporation and/or its subsidiary(-ies). + * All rights reserved. + * Author: Siarhei Siamashka + * Copyright (C) 2013, Linaro Limited + * Author: Ragesh Radhakrishnan + * + * This software is provided 'as-is', without any express or implied + * warranty. In no event will the authors be held liable for any damages + * arising from the use of this software. + * + * Permission is granted to anyone to use this software for any purpose, + * including commercial applications, and to alter it and redistribute it + * freely, subject to the following restrictions: + * + * 1. The origin of this software must not be misrepresented; you must not + * claim that you wrote the original software. If you use this software + * in a product, an acknowledgment in the product documentation would be + * appreciated but is not required. + * 2. Altered source versions must be plainly marked as such, and must not be + * misrepresented as being the original software. + * 3. This notice may not be removed or altered from any source distribution. + */ + +#if defined(__linux__) && defined(__ELF__) +.section .note.GNU-stack,"",%progbits /* mark stack as non-executable */ +#endif + +.text +.arch armv8-a+fp+simd + + +#define RESPECT_STRICT_ALIGNMENT 1 + +#define RTSM_SQSHRN_SIM_ISSUE + + +/*****************************************************************************/ + +/* Supplementary macro for setting function attributes */ +.macro asm_function fname +#ifdef __APPLE__ + .func _\fname + .globl _\fname +_\fname: +#else + .func \fname + .global \fname +#ifdef __ELF__ + .hidden \fname + .type \fname, %function +#endif +\fname: +#endif +.endm + +/* Transpose elements of single 128 bit registers */ +.macro transpose_single x0,x1,xi,xilen,literal + ins \xi\xilen[0], \x0\xilen[0] + ins \x1\xilen[0], \x0\xilen[1] + trn1 \x0\literal, \x0\literal, \x1\literal + trn2 \x1\literal, \xi\literal, \x1\literal +.endm + +/* Transpose elements of 2 differnet registers */ +.macro transpose x0,x1,xi,xilen,literal + mov \xi\xilen, \x0\xilen + trn1 \x0\literal, \x0\literal, \x1\literal + trn2 \x1\literal, \xi\literal, \x1\literal +.endm + +/* Transpose a block of 4x4 coefficients in four 64-bit registers */ +.macro transpose_4x4_32 x0,x0len x1,x1len x2,x2len x3,x3len,xi,xilen + mov \xi\xilen, \x0\xilen + trn1 \x0\x0len, \x0\x0len, \x2\x2len + trn2 \x2\x2len, \xi\x0len, \x2\x2len + mov \xi\xilen, \x1\xilen + trn1 \x1\x1len, \x1\x1len, \x3\x3len + trn2 \x3\x3len, \xi\x1len, \x3\x3len +.endm + +.macro transpose_4x4_16 x0,x0len x1,x1len, x2,x2len, x3,x3len,xi,xilen + mov \xi\xilen, \x0\xilen + trn1 \x0\x0len, \x0\x0len, \x1\x1len + trn2 \x1\x2len, \xi\x0len, \x1\x2len + mov \xi\xilen, \x2\xilen + trn1 \x2\x2len, \x2\x2len, \x3\x3len + trn2 \x3\x2len, \xi\x1len, \x3\x3len +.endm + +.macro transpose_4x4 x0, x1, x2, x3,x5 + transpose_4x4_16 \x0,.4h, \x1,.4h, \x2,.4h,\x3,.4h,\x5,.16b + transpose_4x4_32 \x0,.2s, \x1,.2s, \x2,.2s,\x3,.2s,\x5,.16b +.endm + + +#define CENTERJSAMPLE 128 + +/*****************************************************************************/ + +/* + * Perform dequantization and inverse DCT on one block of coefficients. + * + * GLOBAL(void) + * jsimd_idct_islow_neon (void * dct_table, JCOEFPTR coef_block, + * JSAMPARRAY output_buf, JDIMENSION output_col) + */ + +#define FIX_0_298631336 (2446) +#define FIX_0_390180644 (3196) +#define FIX_0_541196100 (4433) +#define FIX_0_765366865 (6270) +#define FIX_0_899976223 (7373) +#define FIX_1_175875602 (9633) +#define FIX_1_501321110 (12299) +#define FIX_1_847759065 (15137) +#define FIX_1_961570560 (16069) +#define FIX_2_053119869 (16819) +#define FIX_2_562915447 (20995) +#define FIX_3_072711026 (25172) + +#define FIX_1_175875602_MINUS_1_961570560 (FIX_1_175875602 - FIX_1_961570560) +#define FIX_1_175875602_MINUS_0_390180644 (FIX_1_175875602 - FIX_0_390180644) +#define FIX_0_541196100_MINUS_1_847759065 (FIX_0_541196100 - FIX_1_847759065) +#define FIX_3_072711026_MINUS_2_562915447 (FIX_3_072711026 - FIX_2_562915447) +#define FIX_0_298631336_MINUS_0_899976223 (FIX_0_298631336 - FIX_0_899976223) +#define FIX_1_501321110_MINUS_0_899976223 (FIX_1_501321110 - FIX_0_899976223) +#define FIX_2_053119869_MINUS_2_562915447 (FIX_2_053119869 - FIX_2_562915447) +#define FIX_0_541196100_PLUS_0_765366865 (FIX_0_541196100 + FIX_0_765366865) + +/* + * Reference SIMD-friendly 1-D ISLOW iDCT C implementation. + * Uses some ideas from the comments in 'simd/jiss2int-64.asm' + */ +#define REF_1D_IDCT(xrow0, xrow1, xrow2, xrow3, xrow4, xrow5, xrow6, xrow7) \ +{ \ + DCTELEM row0, row1, row2, row3, row4, row5, row6, row7; \ + INT32 q1, q2, q3, q4, q5, q6, q7; \ + INT32 tmp11_plus_tmp2, tmp11_minus_tmp2; \ + \ + /* 1-D iDCT input data */ \ + row0 = xrow0; \ + row1 = xrow1; \ + row2 = xrow2; \ + row3 = xrow3; \ + row4 = xrow4; \ + row5 = xrow5; \ + row6 = xrow6; \ + row7 = xrow7; \ + \ + q5 = row7 + row3; \ + q4 = row5 + row1; \ + q6 = MULTIPLY(q5, FIX_1_175875602_MINUS_1_961570560) + \ + MULTIPLY(q4, FIX_1_175875602); \ + q7 = MULTIPLY(q5, FIX_1_175875602) + \ + MULTIPLY(q4, FIX_1_175875602_MINUS_0_390180644); \ + q2 = MULTIPLY(row2, FIX_0_541196100) + \ + MULTIPLY(row6, FIX_0_541196100_MINUS_1_847759065); \ + q4 = q6; \ + q3 = ((INT32) row0 - (INT32) row4) << 13; \ + q6 += MULTIPLY(row5, -FIX_2_562915447) + \ + MULTIPLY(row3, FIX_3_072711026_MINUS_2_562915447); \ + /* now we can use q1 (reloadable constants have been used up) */ \ + q1 = q3 + q2; \ + q4 += MULTIPLY(row7, FIX_0_298631336_MINUS_0_899976223) + \ + MULTIPLY(row1, -FIX_0_899976223); \ + q5 = q7; \ + q1 = q1 + q6; \ + q7 += MULTIPLY(row7, -FIX_0_899976223) + \ + MULTIPLY(row1, FIX_1_501321110_MINUS_0_899976223); \ + \ + /* (tmp11 + tmp2) has been calculated (out_row1 before descale) */ \ + tmp11_plus_tmp2 = q1; \ + row1 = 0; \ + \ + q1 = q1 - q6; \ + q5 += MULTIPLY(row5, FIX_2_053119869_MINUS_2_562915447) + \ + MULTIPLY(row3, -FIX_2_562915447); \ + q1 = q1 - q6; \ + q6 = MULTIPLY(row2, FIX_0_541196100_PLUS_0_765366865) + \ + MULTIPLY(row6, FIX_0_541196100); \ + q3 = q3 - q2; \ + \ + /* (tmp11 - tmp2) has been calculated (out_row6 before descale) */ \ + tmp11_minus_tmp2 = q1; \ + \ + q1 = ((INT32) row0 + (INT32) row4) << 13; \ + q2 = q1 + q6; \ + q1 = q1 - q6; \ + \ + /* pick up the results */ \ + tmp0 = q4; \ + tmp1 = q5; \ + tmp2 = (tmp11_plus_tmp2 - tmp11_minus_tmp2) / 2; \ + tmp3 = q7; \ + tmp10 = q2; \ + tmp11 = (tmp11_plus_tmp2 + tmp11_minus_tmp2) / 2; \ + tmp12 = q3; \ + tmp13 = q1; \ +} + +#define XFIX_0_899976223 v0.4h[0] +#define XFIX_0_541196100 v0.4h[1] +#define XFIX_2_562915447 v0.4h[2] +#define XFIX_0_298631336_MINUS_0_899976223 v0.4h[3] +#define XFIX_1_501321110_MINUS_0_899976223 v1.4h[0] +#define XFIX_2_053119869_MINUS_2_562915447 v1.4h[1] +#define XFIX_0_541196100_PLUS_0_765366865 v1.4h[2] +#define XFIX_1_175875602 v1.4h[3] +#define XFIX_1_175875602_MINUS_0_390180644 v2.4h[0] +#define XFIX_0_541196100_MINUS_1_847759065 v2.4h[1] +#define XFIX_3_072711026_MINUS_2_562915447 v2.4h[2] +#define XFIX_1_175875602_MINUS_1_961570560 v2.4h[3] + +.balign 16 +jsimd_idct_islow_neon_consts: + .short FIX_0_899976223 /* d0[0] */ + .short FIX_0_541196100 /* d0[1] */ + .short FIX_2_562915447 /* d0[2] */ + .short FIX_0_298631336_MINUS_0_899976223 /* d0[3] */ + .short FIX_1_501321110_MINUS_0_899976223 /* d1[0] */ + .short FIX_2_053119869_MINUS_2_562915447 /* d1[1] */ + .short FIX_0_541196100_PLUS_0_765366865 /* d1[2] */ + .short FIX_1_175875602 /* d1[3] */ + /* reloadable constants */ + .short FIX_1_175875602_MINUS_0_390180644 /* d2[0] */ + .short FIX_0_541196100_MINUS_1_847759065 /* d2[1] */ + .short FIX_3_072711026_MINUS_2_562915447 /* d2[2] */ + .short FIX_1_175875602_MINUS_1_961570560 /* d2[3] */ + +asm_function jsimd_idct_islow_neon + + DCT_TABLE .req x0 + COEF_BLOCK .req x1 + OUTPUT_BUF .req x2 + OUTPUT_COL .req x3 + TMP1 .req x0 + TMP2 .req x1 + TMP3 .req x2 + TMP4 .req x15 + + ROW0L .req v16 + ROW0R .req v17 + ROW1L .req v18 + ROW1R .req v19 + ROW2L .req v20 + ROW2R .req v21 + ROW3L .req v22 + ROW3R .req v23 + ROW4L .req v24 + ROW4R .req v25 + ROW5L .req v26 + ROW5R .req v27 + ROW6L .req v28 + ROW6R .req v29 + ROW7L .req v30 + ROW7R .req v31 + + adr x15, jsimd_idct_islow_neon_consts + ld1 {v16.4h, v17.4h, v18.4h, v19.4h}, [COEF_BLOCK], 32 + ld1 {v0.4h, v1.4h, v2.4h, v3.4h}, [DCT_TABLE], 32 + ld1 {v20.4h, v21.4h, v22.4h, v23.4h}, [COEF_BLOCK], 32 + mul v16.4h, v16.4h, v0.4h + mul v17.4h, v17.4h, v1.4h + ins v16.2d[1], v17.2d[0] /* 128 bit q8 */ + ld1 {v4.4h, v5.4h, v6.4h, v7.4h}, [DCT_TABLE], 32 + mul v18.4h, v18.4h, v2.4h + mul v19.4h, v19.4h, v3.4h + ins v18.2d[1], v19.2d[0] /* 128 bit q9 */ + ld1 {v24.4h, v25.4h, v26.4h, v27.4h}, [COEF_BLOCK], 32 + mul v20.4h, v20.4h, v4.4h + mul v21.4h, v21.4h, v5.4h + ins v20.2d[1], v21.2d[0] /* 128 bit q10 */ + ld1 {v0.4h, v1.4h, v2.4h, v3.4h}, [DCT_TABLE], 32 + mul v22.4h, v22.4h, v6.4h + mul v23.4h, v23.4h, v7.4h + ins v22.2d[1], v23.2d[0] /* 128 bit q11 */ + ld1 {v28.4h, v29.4h, v30.4h, v31.4h}, [COEF_BLOCK], 32 + mul v24.4h, v24.4h, v0.4h + mul v25.4h, v25.4h, v1.4h + ins v24.2d[1], v25.2d[0] /* 128 bit q12 */ + ld1 {v4.4h, v5.4h, v6.4h, v7.4h}, [DCT_TABLE], 32 + mul v28.4h, v28.4h, v4.4h + mul v29.4h, v29.4h, v5.4h + ins v28.2d[1], v29.2d[0] /* 128 bit q14 */ + mul v26.4h, v26.4h, v2.4h + mul v27.4h, v27.4h, v3.4h + ins v26.2d[1], v27.2d[0] /* 128 bit q13 */ + ld1 {v0.4h, v1.4h, v2.4h, v3.4h}, [x15] /* load constants */ + add x15, x15, #16 + mul v30.4h, v30.4h, v6.4h + mul v31.4h, v31.4h, v7.4h + ins v30.2d[1], v31.2d[0] /* 128 bit q15 */ + sub sp, sp, #32 + st1 {v8.4h-v11.4h}, [sp] /* save NEON registers */ + sub sp, sp, #32 + st1 {v12.4h-v15.4h}, [sp] + /* 1-D IDCT, pass 1, left 4x8 half */ + add v4.4h, ROW7L.4h, ROW3L.4h + add v5.4h, ROW5L.4h, ROW1L.4h + smull v12.4s, v4.4h, XFIX_1_175875602_MINUS_1_961570560 + smlal v12.4s, v5.4h, XFIX_1_175875602 + smull v14.4s, v4.4h, XFIX_1_175875602 + /* Check for the zero coefficients in the right 4x8 half */ + /* push {x4, x5} */ + stp x4, x5, [sp, -16]! + mov x5, #0 + smlal v14.4s, v5.4h, XFIX_1_175875602_MINUS_0_390180644 + ssubl v6.4s, ROW0L.4h, ROW4L.4h + ldr x4, [COEF_BLOCK, #(-96 + 2 * (4 + 1 * 8))] + smull v4.4s, ROW2L.4h, XFIX_0_541196100 + smlal v4.4s, ROW6L.4h, XFIX_0_541196100_MINUS_1_847759065 + orr x0, x4, x5 + mov v8.16b, v12.16b + smlsl v12.4s, ROW5L.4h, XFIX_2_562915447 + ldr x4, [COEF_BLOCK, #(-96 + 2 * (4 + 2 * 8))] + smlal v12.4s, ROW3L.4h, XFIX_3_072711026_MINUS_2_562915447 + shl v6.4s, v6.4s, #13 + orr x0, x0, x4 + smlsl v8.4s, ROW1L.4h, XFIX_0_899976223 + orr x0, x0 , x5 + add v2.4s, v6.4s, v4.4s + ldr x4, [COEF_BLOCK, #(-96 + 2 * (4 + 3 * 8))] + mov v10.16b, v14.16b + add v2.4s, v2.4s, v12.4s + orr x0, x0, x4 + smlsl v14.4s, ROW7L.4h, XFIX_0_899976223 + orr x0, x0, x5 + smlal v14.4s, ROW1L.4h, XFIX_1_501321110_MINUS_0_899976223 + rshrn ROW1L.4h, v2.4s, #11 + ldr x4, [COEF_BLOCK, #(-96 + 2 * (4 + 4 * 8))] + sub v2.4s, v2.4s, v12.4s + smlal v10.4s, ROW5L.4h, XFIX_2_053119869_MINUS_2_562915447 + orr x0, x0, x4 + smlsl v10.4s, ROW3L.4h, XFIX_2_562915447 + orr x0, x0, x5 + sub v2.4s, v2.4s, v12.4s + smull v12.4s, ROW2L.4h, XFIX_0_541196100_PLUS_0_765366865 + ldr x4, [COEF_BLOCK, #(-96 + 2 * (4 + 5 * 8))] + smlal v12.4s, ROW6L.4h, XFIX_0_541196100 + sub v6.4s, v6.4s, v4.4s + orr x0, x0, x4 + rshrn ROW6L.4h, v2.4s, #11 + orr x0, x0, x5 + add v2.4s, v6.4s, v10.4s + ldr x4, [COEF_BLOCK, #(-96 + 2 * (4 + 6 * 8))] + sub v6.4s, v6.4s, v10.4s + saddl v10.4s, ROW0L.4h, ROW4L.4h + orr x0, x0, x4 + rshrn ROW2L.4h, v2.4s, #11 + orr x0, x0, x5 + rshrn ROW5L.4h, v6.4s, #11 + ldr x4, [COEF_BLOCK, #(-96 + 2 * (4 + 7 * 8))] + shl v10.4s, v10.4s, #13 + smlal v8.4s, ROW7L.4h, XFIX_0_298631336_MINUS_0_899976223 + orr x0, x0, x4 + add v4.4s, v10.4s, v12.4s + orr x0, x0, x5 + sub v2.4s, v10.4s, v12.4s + add v12.4s, v4.4s, v14.4s + ldr x4, [COEF_BLOCK, #(-96 + 2 * (4 + 0 * 8))] + sub v4.4s, v4.4s, v14.4s + add v10.4s, v2.4s, v8.4s + orr x0, x4, x5 + sub v6.4s, v2.4s, v8.4s + /* pop {x4, x5} */ + ldp x4, x5, [sp], 16 + rshrn ROW7L.4h, v4.4s, #11 + rshrn ROW3L.4h, v10.4s, #11 + rshrn ROW0L.4h, v12.4s, #11 + rshrn ROW4L.4h, v6.4s, #11 + cmp x0, #0 /* orrs instruction removed */ + + beq 3f /* Go to do some special handling for the sparse right 4x8 half */ + + /* 1-D IDCT, pass 1, right 4x8 half */ + ld1 {v2.4h}, [x15] /* reload constants */ + add v10.4h, ROW7R.4h, ROW3R.4h + add v8.4h, ROW5R.4h, ROW1R.4h + /* Transpose ROW6L <-> ROW7L (v3 available free register) */ + transpose ROW6L, ROW7L, v3, .16b, .4h + smull v12.4s, v10.4h, XFIX_1_175875602_MINUS_1_961570560 + smlal v12.4s, v8.4h, XFIX_1_175875602 + /* Transpose ROW2L <-> ROW3L (v3 available free register) */ + transpose ROW2L, ROW3L, v3, .16b, .4h + smull v14.4s, v10.4h, XFIX_1_175875602 + smlal v14.4s, v8.4h, XFIX_1_175875602_MINUS_0_390180644 + /* Transpose ROW0L <-> ROW1L (v3 available free register) */ + transpose ROW0L, ROW1L, v3, .16b, .4h + ssubl v6.4s, ROW0R.4h, ROW4R.4h + smull v4.4s, ROW2R.4h, XFIX_0_541196100 + smlal v4.4s, ROW6R.4h, XFIX_0_541196100_MINUS_1_847759065 + /* Transpose ROW4L <-> ROW5L (v3 available free register) */ + transpose ROW4L, ROW5L, v3, .16b, .4h + mov v8.16b, v12.16b + smlsl v12.4s, ROW5R.4h, XFIX_2_562915447 + smlal v12.4s, ROW3R.4h, XFIX_3_072711026_MINUS_2_562915447 + /* Transpose ROW1L <-> ROW3L (v3 available free register) */ + transpose ROW1L, ROW3L, v3, .16b, .2s + shl v6.4s, v6.4s, #13 + smlsl v8.4s, ROW1R.4h, XFIX_0_899976223 + /* Transpose ROW4L <-> ROW6L (v3 available free register) */ + transpose ROW4L, ROW6L, v3, .16b, .2s + add v2.4s, v6.4s, v4.4s + mov v10.16b, v14.16b + add v2.4s, v2.4s, v12.4s + /* Transpose ROW0L <-> ROW2L (v3 available free register) */ + transpose ROW0L, ROW2L, v3, .16b, .2s + smlsl v14.4s, ROW7R.4h, XFIX_0_899976223 + smlal v14.4s, ROW1R.4h, XFIX_1_501321110_MINUS_0_899976223 + rshrn ROW1R.4h, v2.4s, #11 + /* Transpose ROW5L <-> ROW7L (v3 available free register) */ + transpose ROW5L, ROW7L, v3, .16b, .2s + sub v2.4s, v2.4s, v12.4s + smlal v10.4s, ROW5R.4h, XFIX_2_053119869_MINUS_2_562915447 + smlsl v10.4s, ROW3R.4h, XFIX_2_562915447 + sub v2.4s, v2.4s, v12.4s + smull v12.4s, ROW2R.4h, XFIX_0_541196100_PLUS_0_765366865 + smlal v12.4s, ROW6R.4h, XFIX_0_541196100 + sub v6.4s, v6.4s, v4.4s + rshrn ROW6R.4h, v2.4s, #11 + add v2.4s, v6.4s, v10.4s + sub v6.4s, v6.4s, v10.4s + saddl v10.4s, ROW0R.4h, ROW4R.4h + rshrn ROW2R.4h, v2.4s, #11 + rshrn ROW5R.4h, v6.4s, #11 + shl v10.4s, v10.4s, #13 + smlal v8.4s, ROW7R.4h, XFIX_0_298631336_MINUS_0_899976223 + add v4.4s, v10.4s, v12.4s + sub v2.4s, v10.4s, v12.4s + add v12.4s, v4.4s, v14.4s + sub v4.4s, v4.4s, v14.4s + add v10.4s, v2.4s, v8.4s + sub v12.4s, v2.4s, v8.4s + rshrn ROW7R.4h, v4.4s, #11 + rshrn ROW3R.4h, v10.4s, #11 + rshrn ROW0R.4h, v12.4s, #11 + rshrn ROW4R.4h, v6.4s, #11 + /* Transpose right 4x8 half */ + transpose ROW6R, ROW7R, v3, .16b, .4h + transpose ROW2R, ROW3R, v3, .16b, .4h + transpose ROW0R, ROW1R, v3, .16b, .4h + transpose ROW4R, ROW5R, v3, .16b, .4h + transpose ROW1R, ROW3R, v3, .16b, .2s + transpose ROW4R, ROW6R, v3, .16b, .2s + transpose ROW0R, ROW2R, v3, .16b, .2s + transpose ROW5R, ROW7R, v3, .16b, .2s + +1: /* 1-D IDCT, pass 2 (normal variant), left 4x8 half */ + ld1 {v2.4h}, [x15] /* reload constants */ + smull v12.4S, ROW1R.4h, XFIX_1_175875602 /* ROW5L.4h <-> ROW1R.4h */ + smlal v12.4s, ROW1L.4h, XFIX_1_175875602 + smlal v12.4s, ROW3R.4h, XFIX_1_175875602_MINUS_1_961570560 /* ROW7L.4h <-> ROW3R.4h */ + smlal v12.4s, ROW3L.4h, XFIX_1_175875602_MINUS_1_961570560 + smull v14.4s, ROW3R.4h, XFIX_1_175875602 /* ROW7L.4h <-> ROW3R.4h */ + smlal v14.4s, ROW3L.4h, XFIX_1_175875602 + smlal v14.4s, ROW1R.4h, XFIX_1_175875602_MINUS_0_390180644 /* ROW5L.4h <-> ROW1R.4h */ + smlal v14.4s, ROW1L.4h, XFIX_1_175875602_MINUS_0_390180644 + ssubl v6.4s, ROW0L.4h, ROW0R.4h /* ROW4L.4h <-> ROW0R.4h */ + smull v4.4s, ROW2L.4h, XFIX_0_541196100 + smlal v4.4s, ROW2R.4h, XFIX_0_541196100_MINUS_1_847759065 /* ROW6L.4h <-> ROW2R.4h */ + mov v8.16b, v12.16b + smlsl v12.4s, ROW1R.4h, XFIX_2_562915447 /* ROW5L.4h <-> ROW1R.4h */ + smlal v12.4s, ROW3L.4h, XFIX_3_072711026_MINUS_2_562915447 + shl v6.4s, v6.4s, #13 + smlsl v8.4s, ROW1L.4h, XFIX_0_899976223 + add v2.4s, v6.4s, v4.4s + mov v10.16b, v14.16b + add v2.4s, v2.4s, v12.4s + smlsl v14.4s, ROW3R.4h, XFIX_0_899976223 /* ROW7L.4h <-> ROW3R.4h */ + smlal v14.4s, ROW1L.4h, XFIX_1_501321110_MINUS_0_899976223 + shrn ROW1L.4h, v2.4s, #16 + sub v2.4s, v2.4s, v12.4s + smlal v10.4s, ROW1R.4h, XFIX_2_053119869_MINUS_2_562915447 /* ROW5L.4h <-> ROW1R.4h */ + smlsl v10.4s, ROW3L.4h, XFIX_2_562915447 + sub v2.4s, v2.4s, v12.4s + smull v12.4s, ROW2L.4h, XFIX_0_541196100_PLUS_0_765366865 + smlal v12.4s, ROW2R.4h, XFIX_0_541196100 /* ROW6L.4h <-> ROW2R.4h */ + sub v6.4s, v6.4s, v4.4s + shrn ROW2R.4h, v2.4s, #16 /* ROW6L.4h <-> ROW2R.4h */ + add v2.4s, v6.4s, v10.4s + sub v6.4s, v6.4s, v10.4s + saddl v10.4s, ROW0L.4h, ROW0R.4h /* ROW4L.4h <-> ROW0R.4h */ + shrn ROW2L.4h, v2.4s, #16 + shrn ROW1R.4h, v6.4s, #16 /* ROW5L.4h <-> ROW1R.4h */ + shl v10.4s, v10.4s, #13 + smlal v8.4s, ROW3R.4h, XFIX_0_298631336_MINUS_0_899976223 /* ROW7L.4h <-> ROW3R.4h */ + add v4.4s, v10.4s, v12.4s + sub v2.4s, v10.4s, v12.4s + add v12.4s, v4.4s, v14.4s + sub v4.4s, v4.4s, v14.4s + add v10.4s, v2.4s, v8.4s + sub v6.4s, v2.4s, v8.4s + shrn ROW3R.4h, v4.4s, #16 /* ROW7L.4h <-> ROW3R.4h */ + shrn ROW3L.4h, v10.4s, #16 + shrn ROW0L.4h, v12.4s, #16 + shrn ROW0R.4h, v6.4s, #16 /* ROW4L.4h <-> ROW0R.4h */ + /* 1-D IDCT, pass 2, right 4x8 half */ + ld1 {v2.4h}, [x15] /* reload constants */ + smull v12.4s, ROW5R.4h, XFIX_1_175875602 + smlal v12.4s, ROW5L.4h, XFIX_1_175875602 /* ROW5L.4h <-> ROW1R.4h */ + smlal v12.4s, ROW7R.4h, XFIX_1_175875602_MINUS_1_961570560 + smlal v12.4s, ROW7L.4h, XFIX_1_175875602_MINUS_1_961570560 /* ROW7L.4h <-> ROW3R.4h */ + smull v14.4s, ROW7R.4h, XFIX_1_175875602 + smlal v14.4s, ROW7L.4h, XFIX_1_175875602 /* ROW7L.4h <-> ROW3R.4h */ + smlal v14.4s, ROW5R.4h, XFIX_1_175875602_MINUS_0_390180644 + smlal v14.4s, ROW5L.4h, XFIX_1_175875602_MINUS_0_390180644 /* ROW5L.4h <-> ROW1R.4h */ + ssubl v6.4s, ROW4L.4h, ROW4R.4h /* ROW4L.4h <-> ROW0R.4h */ + smull v4.4s, ROW6L.4h, XFIX_0_541196100 /* ROW6L.4h <-> ROW2R.4h */ + smlal v4.4s, ROW6R.4h, XFIX_0_541196100_MINUS_1_847759065 + mov v8.16b, v12.16b + smlsl v12.4s, ROW5R.4h, XFIX_2_562915447 + smlal v12.4s, ROW7L.4h, XFIX_3_072711026_MINUS_2_562915447 /* ROW7L.4h <-> ROW3R.4h */ + shl v6.4s, v6.4s, #13 + smlsl v8.4s, ROW5L.4h, XFIX_0_899976223 /* ROW5L.4h <-> ROW1R.4h */ + add v2.4s, v6.4s, v4.4s + mov v10.16b, v14.16b + add v2.4s, v2.4s, v12.4s + smlsl v14.4s, ROW7R.4h, XFIX_0_899976223 + smlal v14.4s, ROW5L.4h, XFIX_1_501321110_MINUS_0_899976223 /* ROW5L.4h <-> ROW1R.4h */ + shrn ROW5L.4h, v2.4s, #16 /* ROW5L.4h <-> ROW1R.4h */ + sub v2.4s, v2.4s, v12.4s + smlal v10.4s, ROW5R.4h, XFIX_2_053119869_MINUS_2_562915447 + smlsl v10.4s, ROW7L.4h, XFIX_2_562915447 /* ROW7L.4h <-> ROW3R.4h */ + sub v2.4s, v2.4s, v12.4s + smull v12.4s, ROW6L.4h, XFIX_0_541196100_PLUS_0_765366865 /* ROW6L.4h <-> ROW2R.4h */ + smlal v12.4s, ROW6R.4h, XFIX_0_541196100 + sub v6.4s, v6.4s, v4.4s + shrn ROW6R.4h, v2.4s, #16 + add v2.4s, v6.4s, v10.4s + sub v6.4s, v6.4s, v10.4s + saddl v10.4s, ROW4L.4h, ROW4R.4h /* ROW4L.4h <-> ROW0R.4h */ + shrn ROW6L.4h, v2.4s, #16 /* ROW6L.4h <-> ROW2R.4h */ + shrn ROW5R.4h, v6.4s, #16 + shl v10.4s, v10.4s, #13 + smlal v8.4s, ROW7R.4h, XFIX_0_298631336_MINUS_0_899976223 + add v4.4s, v10.4s, v12.4s + sub v2.4s, v10.4s, v12.4s + add v12.4s, v4.4s, v14.4s + sub v4.4s, v4.4s, v14.4s + add v10.4s, v2.4s, v8.4s + sub v6.4s, v2.4s, v8.4s + shrn ROW7R.4h, v4.4s, #16 + shrn ROW7L.4h, v10.4s, #16 /* ROW7L.4h <-> ROW3R.4h */ + shrn ROW4L.4h, v12.4s, #16 /* ROW4L.4h <-> ROW0R.4h */ + shrn ROW4R.4h, v6.4s, #16 + +2: /* Descale to 8-bit and range limit */ + ins v16.2d[1], v17.2d[0] + ins v18.2d[1], v19.2d[0] + ins v20.2d[1], v21.2d[0] + ins v22.2d[1], v23.2d[0] +#ifdef RTSM_SQSHRN_SIM_ISSUE + sqrshrn v16.8b, v16.8h, #2 + sqrshrn2 v16.16b, v18.8h, #2 + sqrshrn v18.8b, v20.8h, #2 + sqrshrn2 v18.16b, v22.8h, #2 +#else + sqrshrn v16.4h, v16.4s, #2 + sqrshrn2 v16.8h, v18.4s, #2 + sqrshrn v18.4h, v20.4s, #2 + sqrshrn2 v18.8h, v22.4s, #2 +#endif + /* vpop {v8.4h-d15.4h} */ /* restore NEON registers */ + + ld1 {v12.4h-v15.4h}, [sp], 32 + ld1 {v8.4h-v11.4h}, [sp], 32 + ins v24.2d[1], v25.2d[0] +#ifdef RTSM_SQSHRN_SIM_ISSUE + + sqrshrn v20.8b, v24.8h, #2 +#else + + sqrshrn v20.4h, v24.4s, #2 +#endif + /* Transpose the final 8-bit samples and do signed->unsigned conversion */ + /* trn1 v16.8h, v16.8h, v18.8h */ + transpose v16, v18, v3, .16b, .8h + ins v26.2d[1], v27.2d[0] + ins v28.2d[1], v29.2d[0] + ins v30.2d[1], v31.2d[0] +#ifdef RTSM_SQSHRN_SIM_ISSUE + sqrshrn2 v20.16b, v26.8h, #2 + sqrshrn v22.8b, v28.8h, #2 +#else + sqrshrn2 v20.8h, v26.4s, #2 + sqrshrn v22.4h, v28.4s, #2 +#endif + movi v0.16b, #(CENTERJSAMPLE) +#ifdef RTSM_SQSHRN_SIM_ISSUE + sqrshrn2 v22.16b, v30.8h, #2 +#else + sqrshrn2 v22.8h, v30.4s, #2 +#endif + transpose_single v16, v17, v3, .2d, .8b + transpose_single v18, v19, v3, .2d, .8b + add v16.8b, v16.8b, v0.8b + add v17.8b, v17.8b, v0.8b + add v18.8b, v18.8b, v0.8b + add v19.8b, v19.8b, v0.8b + transpose v20, v22, v3, .16b, .8h + /* Store results to the output buffer */ + ldp TMP1, TMP2, [OUTPUT_BUF], 16 + add TMP1, TMP1, OUTPUT_COL + add TMP2, TMP2, OUTPUT_COL + st1 {v16.8b}, [TMP1] + transpose_single v20, v21, v3, .2d, .8b + st1 {v17.8b}, [TMP2] + ldp TMP1, TMP2, [OUTPUT_BUF], 16 + add TMP1, TMP1, OUTPUT_COL + add TMP2, TMP2, OUTPUT_COL + st1 {v18.8b}, [TMP1] + add v20.8b, v20.8b, v0.8b + add v21.8b, v21.8b, v0.8b + st1 {v19.8b}, [TMP2] + ldp TMP1, TMP2, [OUTPUT_BUF], 16 + ldp TMP3, TMP4, [OUTPUT_BUF] + add TMP1, TMP1, OUTPUT_COL + add TMP2, TMP2, OUTPUT_COL + add TMP3, TMP3, OUTPUT_COL + add TMP4, TMP4, OUTPUT_COL + transpose_single v22, v23, v3, .2d, .8b + st1 {v20.8b}, [TMP1] + add v22.8b, v22.8b, v0.8b + add v23.8b, v23.8b, v0.8b + st1 {v21.8b}, [TMP2] + st1 {v22.8b}, [TMP3] + st1 {v23.8b}, [TMP4] + blr x30 + +3: /* Left 4x8 half is done, right 4x8 half contains mostly zeros */ + + /* Transpose left 4x8 half */ + transpose ROW6L, ROW7L, v3, .16b, .4h + transpose ROW2L, ROW3L, v3, .16b, .4h + transpose ROW0L, ROW1L, v3, .16b, .4h + transpose ROW4L, ROW5L, v3, .16b, .4h + shl ROW0R.4h, ROW0R.4h, #2 /* PASS1_BITS */ + transpose ROW1L, ROW3L, v3, .16b, .2s + transpose ROW4L, ROW6L, v3, .16b, .2s + transpose ROW0L, ROW2L, v3, .16b, .2s + transpose ROW5L, ROW7L, v3, .16b, .2s + cmp x0, #0 + beq 4f /* Right 4x8 half has all zeros, go to 'sparse' second pass */ + + /* Only row 0 is non-zero for the right 4x8 half */ + dup ROW1R.4h, ROW0R.4h[1] + dup ROW2R.4h, ROW0R.4h[2] + dup ROW3R.4h, ROW0R.4h[3] + dup ROW4R.4h, ROW0R.4h[0] + dup ROW5R.4h, ROW0R.4h[1] + dup ROW6R.4h, ROW0R.4h[2] + dup ROW7R.4h, ROW0R.4h[3] + dup ROW0R.4h, ROW0R.4h[0] + b 1b /* Go to 'normal' second pass */ + +4: /* 1-D IDCT, pass 2 (sparse variant with zero rows 4-7), left 4x8 half */ + ld1 {v2.4h}, [x15] /* reload constants */ + smull v12.4s, ROW1L.4h, XFIX_1_175875602 + smlal v12.4s, ROW3L.4h, XFIX_1_175875602_MINUS_1_961570560 + smull v14.4s, ROW3L.4h, XFIX_1_175875602 + smlal v14.4s, ROW1L.4h, XFIX_1_175875602_MINUS_0_390180644 + smull v4.4s, ROW2L.4h, XFIX_0_541196100 + sshll v6.4s, ROW0L.4h, #13 + mov v8.16b, v12.16b + smlal v12.4s, ROW3L.4h, XFIX_3_072711026_MINUS_2_562915447 + smlsl v8.4s, ROW1L.4h, XFIX_0_899976223 + add v2.4s, v6.4s, v4.4s + mov v10.16b, v14.16b + smlal v14.4s, ROW1L.4h, XFIX_1_501321110_MINUS_0_899976223 + add v2.4s, v2.4s, v12.4s + add v12.4s, v12.4s, v12.4s + smlsl v10.4s, ROW3L.4h, XFIX_2_562915447 + shrn ROW1L.4h, v2.4s, #16 + sub v2.4s, v2.4s, v12.4s + smull v12.4s, ROW2L.4h, XFIX_0_541196100_PLUS_0_765366865 + sub v6.4s, v6.4s, v4.4s + shrn ROW2R.4h, v2.4s, #16 /* ROW6L.4h <-> ROW2R.4h */ + add v2.4s, v6.4s, v10.4s + sub v6.4s, v6.4s, v10.4s + sshll v10.4s, ROW0L.4h, #13 + shrn ROW2L.4h, v2.4s, #16 + shrn ROW1R.4h, v6.4s, #16 /* ROW5L.4h <-> ROW1R.4h */ + add v4.4s, v10.4s, v12.4s + sub v2.4s, v10.4s, v12.4s + add v12.4s, v4.4s, v14.4s + sub v4.4s, v4.4s, v14.4s + add v10.4s, v2.4s, v8.4s + sub v6.4s, v2.4s, v8.4s + shrn ROW3R.4h, v4.4s, #16 /* ROW7L.4h <-> ROW3R.4h */ + shrn ROW3L.4h, v10.4s, #16 + shrn ROW0L.4h, v12.4s, #16 + shrn ROW0R.4h, v6.4s, #16 /* ROW4L.4h <-> ROW0R.4h */ + /* 1-D IDCT, pass 2 (sparse variant with zero rows 4-7), right 4x8 half */ + ld1 {v2.4h}, [x15] /* reload constants */ + smull v12.4s, ROW5L.4h, XFIX_1_175875602 + smlal v12.4s, ROW7L.4h, XFIX_1_175875602_MINUS_1_961570560 + smull v14.4s, ROW7L.4h, XFIX_1_175875602 + smlal v14.4s, ROW5L.4h, XFIX_1_175875602_MINUS_0_390180644 + smull v4.4s, ROW6L.4h, XFIX_0_541196100 + sshll v6.4s, ROW4L.4h, #13 + mov v8.16b, v12.16b + smlal v12.4s, ROW7L.4h, XFIX_3_072711026_MINUS_2_562915447 + smlsl v8.4s, ROW5L.4h, XFIX_0_899976223 + add v2.4s, v6.4s, v4.4s + mov v10.16b, v14.16b + smlal v14.4s, ROW5L.4h, XFIX_1_501321110_MINUS_0_899976223 + add v2.4s, v2.4s, v12.4s + add v12.4s, v12.4s, v12.4s + smlsl v10.4s, ROW7L.4h, XFIX_2_562915447 + shrn ROW5L.4h, v2.4s, #16 /* ROW5L.4h <-> ROW1R.4h */ + sub v2.4s, v2.4s, v12.4s + smull v12.4s, ROW6L.4h, XFIX_0_541196100_PLUS_0_765366865 + sub v6.4s, v6.4s, v4.4s + shrn ROW6R.4h, v2.4s, #16 + add v2.4s, v6.4s, v10.4s + sub v6.4s, v6.4s, v10.4s + sshll v10.4s, ROW4L.4h, #13 + shrn ROW6L.4h, v2.4s, #16 /* ROW6L.4h <-> ROW2R.4h */ + shrn ROW5R.4h, v6.4s, #16 + add v4.4s, v10.4s, v12.4s + sub v2.4s, v10.4s, v12.4s + add v12.4s, v4.4s, v14.4s + sub v4.4s, v4.4s, v14.4s + add v10.4s, v2.4s, v8.4s + sub v6.4s, v2.4s, v8.4s + shrn ROW7R.4h, v4.4s, #16 + shrn ROW7L.4h, v10.4s, #16 /* ROW7L.4h <-> ROW3R.4h */ + shrn ROW4L.4h, v12.4s, #16 /* ROW4L.4h <-> ROW0R.4h */ + shrn ROW4R.4h, v6.4s, #16 + b 2b /* Go to epilogue */ + + .unreq DCT_TABLE + .unreq COEF_BLOCK + .unreq OUTPUT_BUF + .unreq OUTPUT_COL + .unreq TMP1 + .unreq TMP2 + .unreq TMP3 + .unreq TMP4 + + .unreq ROW0L + .unreq ROW0R + .unreq ROW1L + .unreq ROW1R + .unreq ROW2L + .unreq ROW2R + .unreq ROW3L + .unreq ROW3R + .unreq ROW4L + .unreq ROW4R + .unreq ROW5L + .unreq ROW5R + .unreq ROW6L + .unreq ROW6R + .unreq ROW7L + .unreq ROW7R +.endfunc + + +/*****************************************************************************/ + +/* + * jsimd_idct_ifast_neon + * + * This function contains a fast, not so accurate integer implementation of + * the inverse DCT (Discrete Cosine Transform). It uses the same calculations + * and produces exactly the same output as IJG's original 'jpeg_idct_ifast' + * function from jidctfst.c + * + * Normally 1-D AAN DCT needs 5 multiplications and 29 additions. + * But in ARM NEON case some extra additions are required because VQDMULH + * instruction can't handle the constants larger than 1. So the expressions + * like "x * 1.082392200" have to be converted to "x * 0.082392200 + x", + * which introduces an extra addition. Overall, there are 6 extra additions + * per 1-D IDCT pass, totalling to 5 VQDMULH and 35 VADD/VSUB instructions. + */ + +#define XFIX_1_082392200 v0.4h[0] +#define XFIX_1_414213562 v0.4h[1] +#define XFIX_1_847759065 v0.4h[2] +#define XFIX_2_613125930 v0.4h[3] + +.balign 16 +jsimd_idct_ifast_neon_consts: + .short (277 * 128 - 256 * 128) /* XFIX_1_082392200 */ + .short (362 * 128 - 256 * 128) /* XFIX_1_414213562 */ + .short (473 * 128 - 256 * 128) /* XFIX_1_847759065 */ + .short (669 * 128 - 512 * 128) /* XFIX_2_613125930 */ + +asm_function jsimd_idct_ifast_neon + + DCT_TABLE .req x0 + COEF_BLOCK .req x1 + OUTPUT_BUF .req x2 + OUTPUT_COL .req x3 + TMP1 .req x0 + TMP2 .req x1 + TMP3 .req x2 + TMP4 .req x15 + + /* Load and dequantize coefficients into NEON registers + * with the following allocation: + * 0 1 2 3 | 4 5 6 7 + * ---------+-------- + * 0 | d16 | d17 ( v8.8h ) + * 1 | d18 | d19 ( v9.8h ) + * 2 | d20 | d21 ( v10.8h ) + * 3 | d22 | d23 ( v11.8h ) + * 4 | d24 | d25 ( v12.8h ) + * 5 | d26 | d27 ( v13.8h ) + * 6 | d28 | d29 ( v14.8h ) + * 7 | d30 | d31 ( v15.8h ) + */ + adr x15, jsimd_idct_ifast_neon_consts + ld1 {v8.8h, v9.8h}, [COEF_BLOCK], 32 + ld1 {v0.8h, v1.8h}, [DCT_TABLE], 32 + ld1 {v10.8h, v11.8h}, [COEF_BLOCK], 32 + mul v8.8h, v8.8h, v0.8h + ld1 {v2.8h, v3.8h}, [DCT_TABLE], 32 + mul v9.8h, v9.8h, v1.8h + ld1 {v12.8h, v13.8h}, [COEF_BLOCK], 32 + mul v10.8h, v10.8h, v2.8h + ld1 {v0.8h, v1.8h}, [DCT_TABLE], 32 + mul v11.8h, v11.8h, v3.8h + ld1 {v14.8h, v15.8h}, [COEF_BLOCK], 32 + mul v12.8h, v12.8h, v0.8h + ld1 {v2.8h, v3.8h}, [DCT_TABLE], 32 + mul v14.8h, v14.8h, v2.8h + mul v13.8h, v13.8h, v1.8h + ld1 {v0.4h}, [x15] /* load constants */ + mul v15.8h, v15.8h, v3.8h + + /* vpush {v4.8h-v6.8h} */ /* save NEON registers */ + sub sp, sp, #32 + st1 {v4.8h-v5.8h}, [sp] /* save NEON registers */ + sub sp, sp, #16 + st1 {v6.8h}, [sp] + /* 1-D IDCT, pass 1 */ + sub v2.8h, v10.8h, v14.8h + add v14.8h, v10.8h, v14.8h + sub v1.8h, v11.8h, v13.8h + add v13.8h, v11.8h, v13.8h + sub v5.8h, v9.8h, v15.8h + add v15.8h, v9.8h, v15.8h + sqdmulh v4.8h, v2.8h, XFIX_1_414213562 + sqdmulh v6.8h, v1.8h, XFIX_2_613125930 + add v3.8h, v1.8h, v1.8h + sub v1.8h, v5.8h, v1.8h + add v10.8h, v2.8h, v4.8h + sqdmulh v4.8h, v1.8h, XFIX_1_847759065 + sub v2.8h, v15.8h, v13.8h + add v3.8h, v3.8h, v6.8h + sqdmulh v6.8h, v2.8h, XFIX_1_414213562 + add v1.8h, v1.8h, v4.8h + sqdmulh v4.8h, v5.8h, XFIX_1_082392200 + sub v10.8h, v10.8h, v14.8h + add v2.8h, v2.8h, v6.8h + sub v6.8h, v8.8h, v12.8h + add v12.8h, v8.8h, v12.8h + add v9.8h, v5.8h, v4.8h + add v5.8h, v6.8h, v10.8h + sub v10.8h, v6.8h, v10.8h + add v6.8h, v15.8h, v13.8h + add v8.8h, v12.8h, v14.8h + sub v3.8h, v6.8h, v3.8h + sub v12.8h, v12.8h, v14.8h + sub v3.8h, v3.8h, v1.8h + sub v1.8h, v9.8h, v1.8h + add v2.8h, v3.8h, v2.8h + sub v15.8h, v8.8h, v6.8h + add v1.8h, v1.8h, v2.8h + add v8.8h, v8.8h, v6.8h + add v14.8h, v5.8h, v3.8h + sub v9.8h, v5.8h, v3.8h + sub v13.8h, v10.8h, v2.8h + add v10.8h, v10.8h, v2.8h + /* Transpose q8-q9 */ + mov v18.16b, v8.16b + trn1 v8.8h, v8.8h, v9.8h + trn2 v9.8h, v18.8h, v9.8h + sub v11.8h, v12.8h, v1.8h + /* Transpose q14-q15 */ + mov v18.16b, v14.16b + trn1 v14.8h, v14.8h, v15.8h + trn2 v15.8h, v18.8h, v15.8h + add v12.8h, v12.8h, v1.8h + /* Transpose q10-q11 */ + mov v18.16b, v10.16b + trn1 v10.8h, v10.8h, v11.8h + trn2 v11.8h, v18.8h, v11.8h + /* Transpose q12-q13 */ + mov v18.16b, v12.16b + trn1 v12.8h, v12.8h, v13.8h + trn2 v13.8h, v18.8h, v13.8h + /* Transpose q9-q11 */ + mov v18.16b, v9.16b + trn1 v9.4s, v9.4s, v11.4s + trn2 v11.4s, v18.4s, v11.4s + /* Transpose q12-q14 */ + mov v18.16b, v12.16b + trn1 v12.4s, v12.4s, v14.4s + trn2 v14.4s, v18.4s, v14.4s + /* Transpose q8-q10 */ + mov v18.16b, v8.16b + trn1 v8.4s, v8.4s, v10.4s + trn2 v10.4s, v18.4s, v10.4s + /* Transpose q13-q15 */ + mov v18.16b, v13.16b + trn1 v13.4s, v13.4s, v15.4s + trn2 v15.4s, v18.4s, v15.4s + /* vswp v14.4h, v10-MSB.4h */ + umov x10, v14.d[0] + ins v14.2d[0], v10.2d[1] + ins v10.2d[1], x10 + /* vswp v13.4h, v9MSB.4h */ + + umov x10, v13.d[0] + ins v13.2d[0], v9.2d[1] + ins v9.2d[1], x10 + /* 1-D IDCT, pass 2 */ + sub v2.8h, v10.8h, v14.8h + /* vswp v15.4h, v11MSB.4h */ + umov x10, v15.d[0] + ins v15.2d[0], v11.2d[1] + ins v11.2d[1], x10 + add v14.8h, v10.8h, v14.8h + /* vswp v12.4h, v8-MSB.4h */ + umov x10, v12.d[0] + ins v12.2d[0], v8.2d[1] + ins v8.2d[1], x10 + sub v1.8h, v11.8h, v13.8h + add v13.8h, v11.8h, v13.8h + sub v5.8h, v9.8h, v15.8h + add v15.8h, v9.8h, v15.8h + sqdmulh v4.8h, v2.8h, XFIX_1_414213562 + sqdmulh v6.8h, v1.8h, XFIX_2_613125930 + add v3.8h, v1.8h, v1.8h + sub v1.8h, v5.8h, v1.8h + add v10.8h, v2.8h, v4.8h + sqdmulh v4.8h, v1.8h, XFIX_1_847759065 + sub v2.8h, v15.8h, v13.8h + add v3.8h, v3.8h, v6.8h + sqdmulh v6.8h, v2.8h, XFIX_1_414213562 + add v1.8h, v1.8h, v4.8h + sqdmulh v4.8h, v5.8h, XFIX_1_082392200 + sub v10.8h, v10.8h, v14.8h + add v2.8h, v2.8h, v6.8h + sub v6.8h, v8.8h, v12.8h + add v12.8h, v8.8h, v12.8h + add v9.8h, v5.8h, v4.8h + add v5.8h, v6.8h, v10.8h + sub v10.8h, v6.8h, v10.8h + add v6.8h, v15.8h, v13.8h + add v8.8h, v12.8h, v14.8h + sub v3.8h, v6.8h, v3.8h + sub v12.8h, v12.8h, v14.8h + sub v3.8h, v3.8h, v1.8h + sub v1.8h, v9.8h, v1.8h + add v2.8h, v3.8h, v2.8h + sub v15.8h, v8.8h, v6.8h + add v1.8h, v1.8h, v2.8h + add v8.8h, v8.8h, v6.8h + add v14.8h, v5.8h, v3.8h + sub v9.8h, v5.8h, v3.8h + sub v13.8h, v10.8h, v2.8h + /* vpop {v4.8h-v7.4h} */ /* restore NEON registers...not available */ + ld1 {v6.8h}, [sp], 16 + ld1 {v4.8h-v5.8h}, [sp], 32 + add v10.8h, v10.8h, v2.8h + sub v11.8h, v12.8h, v1.8h + add v12.8h, v12.8h, v1.8h + /* Descale to 8-bit and range limit */ + movi v0.16b, #0x80 +#ifdef RTSM_SQSHRN_SIM_ISSUE + sqshrn v8.8b, v8.8h, #5 + sqshrn2 v8.16b, v9.8h, #5 + sqshrn v9.8b, v10.8h, #5 + sqshrn2 v9.16b, v11.8h, #5 + sqshrn v10.8b, v12.8h, #5 + sqshrn2 v10.16b, v13.8h, #5 + sqshrn v11.8b, v14.8h, #5 + sqshrn2 v11.16b, v15.8h, #5 +#else + sqshrn v8.4h, v8.4s, #5 + sqshrn2 v8.8h, v9.4s, #5 + sqshrn v9.4h, v10.4s, #5 + sqshrn2 v9.8h, v11.4s, #5 + sqshrn v10.4h, v12.4s, #5 + sqshrn2 v10.8h, v13.4s, #5 + sqshrn v11.4h, v14.4s, #5 + sqshrn2 v11.8h, v15.4s, #5 +#endif + add v8.16b, v8.16b, v0.16b + add v9.16b, v9.16b, v0.16b + add v10.16b, v10.16b, v0.16b + add v11.16b, v11.16b, v0.16b + /* Transpose the final 8-bit samples */ + /* Transpose q8-q9 */ + mov v18.16b, v8.16b + trn1 v8.8h, v8.8h, v9.8h + trn2 v9.8h, v18.8h, v9.8h + /* Transpose q10-q11 */ + mov v18.16b, v10.16b + trn1 v10.8h, v10.8h, v11.8h + trn2 v11.8h, v18.8h, v11.8h + /* Transpose q8-q10 */ + mov v18.16b, v8.16b + trn1 v8.4s, v8.4s, v10.4s + trn2 v10.4s, v18.4s, v10.4s + /* Transpose q9-q11 */ + mov v18.16b, v9.16b + trn1 v9.4s, v9.4s, v11.4s + trn2 v11.4s, v18.4s, v11.4s + /* make copy */ + ins v17.2d[0], v8.2d[1] + /* Transpose d16-d17-msb */ + mov v18.16b, v8.16b + trn1 v8.8b, v8.8b, v17.8b + trn2 v17.8b, v18.8b, v17.8b + /* make copy */ + ins v19.2d[0], v9.2d[1] + mov v18.16b, v9.16b + trn1 v9.8b, v9.8b, v19.8b + trn2 v19.8b, v18.8b, v19.8b + /* Store results to the output buffer */ + ldp TMP1, TMP2, [OUTPUT_BUF], 16 + add TMP1, TMP1, OUTPUT_COL + add TMP2, TMP2, OUTPUT_COL + st1 {v8.8b}, [TMP1] + st1 {v17.8b}, [TMP2] + ldp TMP1, TMP2, [OUTPUT_BUF], 16 + add TMP1, TMP1, OUTPUT_COL + add TMP2, TMP2, OUTPUT_COL + st1 {v9.8b}, [TMP1] + /* make copy */ + ins v21.2d[0], v10.2d[1] + mov v18.16b, v10.16b + trn1 v10.8b, v10.8b, v21.8b + trn2 v21.8b, v18.8b, v21.8b + st1 {v19.8b}, [TMP2] + ldp TMP1, TMP2, [OUTPUT_BUF], 16 + ldp TMP3, TMP4, [OUTPUT_BUF] + add TMP1, TMP1, OUTPUT_COL + add TMP2, TMP2, OUTPUT_COL + add TMP3, TMP3, OUTPUT_COL + add TMP4, TMP4, OUTPUT_COL + st1 {v10.8b}, [TMP1] + /* make copy */ + ins v23.2d[0], v11.2d[1] + mov v18.16b, v11.16b + trn1 v11.8b, v11.8b, v23.8b + trn2 v23.8b, v18.8b, v23.8b + st1 {v21.8b}, [TMP2] + st1 {v11.8b}, [TMP3] + st1 {v23.8b}, [TMP4] + blr x30 + + .unreq DCT_TABLE + .unreq COEF_BLOCK + .unreq OUTPUT_BUF + .unreq OUTPUT_COL + .unreq TMP1 + .unreq TMP2 + .unreq TMP3 + .unreq TMP4 +.endfunc + + +/*****************************************************************************/ + +/* + * jsimd_idct_4x4_neon + * + * This function contains inverse-DCT code for getting reduced-size + * 4x4 pixels output from an 8x8 DCT block. It uses the same calculations + * and produces exactly the same output as IJG's original 'jpeg_idct_4x4' + * function from jpeg-6b (jidctred.c). + * + * NOTE: jpeg-8 has an improved implementation of 4x4 inverse-DCT, which + * requires much less arithmetic operations and hence should be faster. + * The primary purpose of this particular NEON optimized function is + * bit exact compatibility with jpeg-6b. + * + * TODO: a bit better instructions scheduling can be achieved by expanding + * idct_helper/transpose_4x4 macros and reordering instructions, + * but readability will suffer somewhat. + */ + +#define CONST_BITS 13 + +#define FIX_0_211164243 (1730) /* FIX(0.211164243) */ +#define FIX_0_509795579 (4176) /* FIX(0.509795579) */ +#define FIX_0_601344887 (4926) /* FIX(0.601344887) */ +#define FIX_0_720959822 (5906) /* FIX(0.720959822) */ +#define FIX_0_765366865 (6270) /* FIX(0.765366865) */ +#define FIX_0_850430095 (6967) /* FIX(0.850430095) */ +#define FIX_0_899976223 (7373) /* FIX(0.899976223) */ +#define FIX_1_061594337 (8697) /* FIX(1.061594337) */ +#define FIX_1_272758580 (10426) /* FIX(1.272758580) */ +#define FIX_1_451774981 (11893) /* FIX(1.451774981) */ +#define FIX_1_847759065 (15137) /* FIX(1.847759065) */ +#define FIX_2_172734803 (17799) /* FIX(2.172734803) */ +#define FIX_2_562915447 (20995) /* FIX(2.562915447) */ +#define FIX_3_624509785 (29692) /* FIX(3.624509785) */ + +.balign 16 +jsimd_idct_4x4_neon_consts: + .short FIX_1_847759065 /* v0.4h[0] */ + .short -FIX_0_765366865 /* v0.4h[1] */ + .short -FIX_0_211164243 /* v0.4h[2] */ + .short FIX_1_451774981 /* v0.4h[3] */ + .short -FIX_2_172734803 /* d1[0] */ + .short FIX_1_061594337 /* d1[1] */ + .short -FIX_0_509795579 /* d1[2] */ + .short -FIX_0_601344887 /* d1[3] */ + .short FIX_0_899976223 /* v2.4h[0] */ + .short FIX_2_562915447 /* v2.4h[1] */ + .short 1 << (CONST_BITS+1) /* v2.4h[2] */ + .short 0 /* v2.4h[3] */ + +.macro idct_helper x4, x6, x8, x10, x12, x14, x16, shift, y26, y27, y28, y29 + smull v28.4s, \x4, v2.4h[2] + smlal v28.4s, \x8, v0.4h[0] + smlal v28.4s, \x14, v0.4h[1] + + smull v26.4s, \x16, v1.4h[2] + smlal v26.4s, \x12, v1.4h[3] + smlal v26.4s, \x10, v2.4h[0] + smlal v26.4s, \x6, v2.4h[1] + + smull v30.4s, \x4, v2.4h[2] + smlsl v30.4s, \x8, v0.4h[0] + smlsl v30.4s, \x14, v0.4h[1] + + smull v24.4s, \x16, v0.4h[2] + smlal v24.4s, \x12, v0.4h[3] + smlal v24.4s, \x10, v1.4h[0] + smlal v24.4s, \x6, v1.4h[1] + + add v20.4s, v28.4s, v26.4s + sub v28.4s, v28.4s, v26.4s + +.if \shift > 16 + srshr v20.4s, v20.4s, #\shift + srshr v28.4s, v28.4s, #\shift + xtn \y26, v20.4s + xtn \y29, v28.4s +.else + rshrn \y26, v20.4s, #\shift + rshrn \y29, v28.4s, #\shift +.endif + + add v20.4s, v30.4s, v24.4s + sub v30.4s, v30.4s, v24.4s + +.if \shift > 16 + srshr v20.4s, v20.4s, #\shift + srshr v30.4s, v30.4s, #\shift + xtn \y27, v20.4s + xtn \y28, v30.4s +.else + rshrn \y27, v20.4s, #\shift + rshrn \y28, v30.4s, #\shift +.endif + +.endm + +asm_function jsimd_idct_4x4_neon + + DCT_TABLE .req x0 + COEF_BLOCK .req x1 + OUTPUT_BUF .req x2 + OUTPUT_COL .req x3 + TMP1 .req x0 + TMP2 .req x1 + TMP3 .req x2 + TMP4 .req x15 + + /* vpush {v8.4h-v15.4h} */ + sub sp, sp, #32 + st1 {v8.4h-v11.4h}, [sp] /* save NEON registers */ + sub sp, sp, #32 + st1 {v12.4h-v15.4h}, [sp] + + /* Load constants (v3.4h is just used for padding) */ + adr TMP4, jsimd_idct_4x4_neon_consts + ld1 {v0.4h, v1.4h, v2.4h, v3.4h}, [TMP4] + + /* Load all COEF_BLOCK into NEON registers with the following allocation: + * 0 1 2 3 | 4 5 6 7 + * ---------+-------- + * 0 | v4.4h | v5.4h + * 1 | v6.4h | v7.4h + * 2 | v8.4h | v9.4h + * 3 | v10.4h | v11.4h + * 4 | - | - + * 5 | v12.4h | v13.4h + * 6 | v14.4h | v15.4h + * 7 | v16.4h | v17.4h + */ + ld1 {v4.4h, v5.4h, v6.4h, v7.4h}, [COEF_BLOCK], 32 + ld1 {v8.4h, v9.4h, v10.4h, v11.4h}, [COEF_BLOCK], 32 + add COEF_BLOCK, COEF_BLOCK, #16 + ld1 {v12.4h, v13.4h, v14.4h, v15.4h}, [COEF_BLOCK], 32 + ld1 {v16.4h, v17.4h}, [COEF_BLOCK], 16 + /* dequantize */ + ld1 {v18.4h, v19.4h, v20.4h, v21.4h}, [DCT_TABLE], 32 + mul v4.4h, v4.4h, v18.4h + mul v5.4h, v5.4h, v19.4h + ins v4.2d[1], v5.2d[0] /* 128 bit q4 */ + ld1 {v22.4h, v23.4h, v24.4h, v25.4h}, [DCT_TABLE], 32 + mul v6.4h, v6.4h, v20.4h + mul v7.4h, v7.4h, v21.4h + ins v6.2d[1], v7.2d[0] /* 128 bit q6 */ + mul v8.4h, v8.4h, v22.4h + mul v9.4h, v9.4h, v23.4h + ins v8.2d[1], v9.2d[0] /* 128 bit q8 */ + add DCT_TABLE, DCT_TABLE, #16 + ld1 {v26.4h, v27.4h, v28.4h, v29.4h}, [DCT_TABLE], 32 + mul v10.4h, v10.4h, v24.4h + mul v11.4h, v11.4h, v25.4h + ins v10.2d[1], v11.2d[0] /* 128 bit q10 */ + mul v12.4h, v12.4h, v26.4h + mul v13.4h, v13.4h, v27.4h + ins v12.2d[1], v13.2d[0] /* 128 bit q12 */ + ld1 {v30.8h}, [DCT_TABLE], 16 + mul v14.4h, v14.4h, v28.4h + mul v15.4h, v15.4h, v29.4h + ins v14.2d[1], v15.2d[0] /* 128 bit q14 */ + mul v16.4h, v16.4h, v30.4h + mul v17.4h, v17.4h, v31.4h + ins v16.2d[1], v17.2d[0] /* 128 bit q16 */ + + /* Pass 1 */ + idct_helper v4.4h, v6.4h, v8.4h, v10.4h, v12.4h, v14.4h, v16.4h, 12, v4.4h, v6.4h, v8.4h, v10.4h + transpose_4x4 v4, v6, v8, v10, v3 + ins v10.2d[1], v11.2d[0] + idct_helper v5.4h, v7.4h, v9.4h, v11.4h, v13.4h, v15.4h, v17.4h, 12, v5.4h, v7.4h, v9.4h, v11.4h + transpose_4x4 v5, v7, v9, v11, v3 + ins v10.2d[1], v11.2d[0] + /* Pass 2 */ + idct_helper v4.4h, v6.4h, v8.4h, v10.4h, v7.4h, v9.4h, v11.4h, 19, v26.4h, v27.4h, v28.4h, v29.4h + transpose_4x4 v26, v27, v28, v29, v3 + + /* Range limit */ + movi v30.8h, #0x80 + ins v26.2d[1], v27.2d[0] + ins v28.2d[1], v29.2d[0] + add v26.8h, v26.8h, v30.8h + add v28.8h, v28.8h, v30.8h + sqxtun v26.8b, v26.8h + sqxtun v27.8b, v28.8h + + /* Store results to the output buffer */ + ldp TMP1, TMP2, [OUTPUT_BUF], 16 + ldp TMP3, TMP4, [OUTPUT_BUF] + add TMP1, TMP1, OUTPUT_COL + add TMP2, TMP2, OUTPUT_COL + add TMP3, TMP3, OUTPUT_COL + add TMP4, TMP4, OUTPUT_COL + +#if defined(__ARMEL__) && !RESPECT_STRICT_ALIGNMENT + /* We can use much less instructions on little endian systems if the + * OS kernel is not configured to trap unaligned memory accesses + */ + st1 {v26.s}[0], [TMP1], 4 + st1 {v27.s}[0], [TMP3], 4 + st1 {v26.s}[1], [TMP2], 4 + st1 {v27.s}[1], [TMP4], 4 +#else + st1 {v26.b}[0], [TMP1], 1 + st1 {v27.b}[0], [TMP3], 1 + st1 {v26.b}[1], [TMP1], 1 + st1 {v27.b}[1], [TMP3], 1 + st1 {v26.b}[2], [TMP1], 1 + st1 {v27.b}[2], [TMP3], 1 + st1 {v26.b}[3], [TMP1], 1 + st1 {v27.b}[3], [TMP3], 1 + + st1 {v26.b}[4], [TMP2], 1 + st1 {v27.b}[4], [TMP4], 1 + st1 {v26.b}[5], [TMP2], 1 + st1 {v27.b}[5], [TMP4], 1 + st1 {v26.b}[6], [TMP2], 1 + st1 {v27.b}[6], [TMP4], 1 + st1 {v26.b}[7], [TMP2], 1 + st1 {v27.b}[7], [TMP4], 1 +#endif + + /* vpop {v8.4h-v15.4h} ;not available */ + ld1 {v12.4h-v15.4h}, [sp], 32 + ld1 {v8.4h-v11.4h}, [sp], 32 + + blr x30 + + .unreq DCT_TABLE + .unreq COEF_BLOCK + .unreq OUTPUT_BUF + .unreq OUTPUT_COL + .unreq TMP1 + .unreq TMP2 + .unreq TMP3 + .unreq TMP4 +.endfunc + +.purgem idct_helper + + +/*****************************************************************************/ + +/* + * jsimd_idct_2x2_neon + * + * This function contains inverse-DCT code for getting reduced-size + * 2x2 pixels output from an 8x8 DCT block. It uses the same calculations + * and produces exactly the same output as IJG's original 'jpeg_idct_2x2' + * function from jpeg-6b (jidctred.c). + * + * NOTE: jpeg-8 has an improved implementation of 2x2 inverse-DCT, which + * requires much less arithmetic operations and hence should be faster. + * The primary purpose of this particular NEON optimized function is + * bit exact compatibility with jpeg-6b. + */ + +.balign 8 +jsimd_idct_2x2_neon_consts: + .short -FIX_0_720959822 /* d0[0] */ + .short FIX_0_850430095 /* d0[1] */ + .short -FIX_1_272758580 /* d0[2] */ + .short FIX_3_624509785 /* d0[3] */ + +.macro idct_helper x4, x6, x10, x12, x16, shift, y26, y27 + sshll v28.4s, \x4, #15 + smull v26.4s, \x6, v0.4h[3] + smlal v26.4s, \x10, v0.4h[2] + smlal v26.4s, \x12, v0.4h[1] + smlal v26.4s, \x16, v0.4h[0] + + add v20.4s, v28.4s, v26.4s + sub v28.4s, v28.4s, v26.4s + +.if \shift > 16 + srshr v20.4s, v20.4s, #\shift + srshr v28.4s, v28.4s, #\shift + xtn \y26, v20.4s + xtn \y27, v28.4s +.else + rshrn \y26, v20.4s, #\shift + rshrn \y27, v28.4s, #\shift +.endif + +.endm + +asm_function jsimd_idct_2x2_neon + + DCT_TABLE .req x0 + COEF_BLOCK .req x1 + OUTPUT_BUF .req x2 + OUTPUT_COL .req x3 + TMP1 .req x0 + TMP2 .req x15 + + /* vpush {v8.4h-v15.4h} ; not available */ + sub sp, sp, #32 + st1 {v8.4h-v11.4h}, [sp] /* save NEON registers */ + sub sp, sp, #32 + st1 {v12.4h-v15.4h}, [sp] + + /* Load constants */ + adr TMP2, jsimd_idct_2x2_neon_consts + ld1 {v0.4h}, [TMP2] + + /* Load all COEF_BLOCK into NEON registers with the following allocation: + * 0 1 2 3 | 4 5 6 7 + * ---------+-------- + * 0 | v4.4h | v5.4h + * 1 | v6.4h | v7.4h + * 2 | - | - + * 3 | v10.4h | v11.4h + * 4 | - | - + * 5 | v12.4h | v13.4h + * 6 | - | - + * 7 | v16.4h | v17.4h + */ + ld1 {v4.4h, v5.4h, v6.4h, v7.4h}, [COEF_BLOCK], 32 + add COEF_BLOCK, COEF_BLOCK, #16 + ld1 {v10.4h, v11.4h}, [COEF_BLOCK], 16 + add COEF_BLOCK, COEF_BLOCK, #16 + ld1 {v12.4h, v13.4h}, [COEF_BLOCK], 16 + add COEF_BLOCK, COEF_BLOCK, #16 + ld1 {v16.4h, v17.4h}, [COEF_BLOCK], 16 + /* Dequantize */ + ld1 {v18.4h, v19.4h, v20.4h, v21.4h}, [DCT_TABLE], 32 + mul v4.8h, v4.8h, v18.8h + mul v5.8h, v5.8h, v18.8h + ins v4.2d[1], v5.2d[0] + mul v6.8h, v6.8h, v20.8h + mul v7.8h, v7.8h, v21.8h + ins v6.2d[1], v7.2d[0] + add DCT_TABLE, DCT_TABLE, #16 + ld1 {v24.4h, v25.4h}, [DCT_TABLE], 16 + mul v10.8h, v10.8h, v24.8h + mul v11.8h, v11.8h, v25.8h + ins v10.2d[1], v11.2d[0] + add DCT_TABLE, DCT_TABLE, #16 + ld1 {v26.4h, v27.4h}, [DCT_TABLE], 16 + mul v12.8h, v12.8h, v26.8h + mul v13.8h, v13.8h, v27.8h + ins v12.2d[1], v13.2d[0] + add DCT_TABLE, DCT_TABLE, #16 + ld1 {v30.4h, v31.4h}, [DCT_TABLE], 16 + mul v16.8h, v16.8h, v30.8h + mul v17.8h, v17.8h, v31.8h + ins v16.2d[1], v17.2d[0] + + /* Pass 1 */ +#if 0 + idct_helper v4.4h, v6.4h, v10.4h, v12.4h, v16.4h, 13, v4.4h, v6.4h + transpose_4x4 v4.4h, v6.4h, v8.4h, v10.4h + idct_helper v5.4h, v7.4h, v11.4h, v13.4h, v17.4h, 13, v5.4h, v7.4h + transpose_4x4 v5.4h, v7.4h, v9.4h, v11.4h +#else + smull v26.4s, v6.4h, v0.4h[3] + smlal v26.4s, v10.4h, v0.4h[2] + smlal v26.4s, v12.4h, v0.4h[1] + smlal v26.4s, v16.4h, v0.4h[0] + smull v24.4s, v7.4h, v0.4h[3] + smlal v24.4s, v11.4h, v0.4h[2] + smlal v24.4s, v13.4h, v0.4h[1] + smlal v24.4s, v17.4h, v0.4h[0] + sshll v28.4s, v4.4h, #15 + sshll v30.4s, v5.4h, #15 + add v20.4s, v28.4s, v26.4s + sub v28.4s, v28.4s, v26.4s + rshrn v4.4h, v20.4s, #13 + rshrn v6.4h, v28.4s, #13 + add v20.4s, v30.4s, v24.4s + sub v28.4s, v30.4s, v24.4s + rshrn v5.4h, v20.4s, #13 + rshrn v7.4h, v28.4s, #13 + transpose v4, v6, v3, .16b, .8h + transpose v6, v10, v3, .16b, .4s +#endif + + /* Pass 2 */ + idct_helper v4.4h, v6.4h, v10.4h, v7.4h, v11.4h, 20, v26.4h, v27.4h + + /* Range limit */ + movi v30.8h, #0x80 + ins v26.2d[1], v27.2d[0] + add v26.8h, v26.8h, v30.8h + sqxtun v30.8b, v26.8h + ins v26.2d[0], v30.2d[0] + sqxtun v27.8b, v26.8h + + /* Store results to the output buffer */ + ldp TMP1, TMP2, [OUTPUT_BUF] + add TMP1, TMP1, OUTPUT_COL + add TMP2, TMP2, OUTPUT_COL + + st1 {v26.b}[0], [TMP1], 1 + st1 {v27.b}[4], [TMP1], 1 + st1 {v26.b}[1], [TMP2], 1 + st1 {v27.b}[5], [TMP2], 1 + + /* vpop {v8.4h-v15.4h} ;not available */ + + ld1 {v12.4h-v15.4h}, [sp], 32 + ld1 {v8.4h-v11.4h}, [sp], 32 + + blr x30 + + .unreq DCT_TABLE + .unreq COEF_BLOCK + .unreq OUTPUT_BUF + .unreq OUTPUT_COL + .unreq TMP1 + .unreq TMP2 +.endfunc + +.purgem idct_helper + + +/*****************************************************************************/ + +/* + * jsimd_ycc_extrgb_convert_neon + * jsimd_ycc_extbgr_convert_neon + * jsimd_ycc_extrgbx_convert_neon + * jsimd_ycc_extbgrx_convert_neon + * jsimd_ycc_extxbgr_convert_neon + * jsimd_ycc_extxrgb_convert_neon + * + * Colorspace conversion YCbCr -> RGB + */ + + +.macro do_load size + .if \size == 8 + ld1 {v4.8b}, [U], 8 + ld1 {v5.8b}, [V], 8 + ld1 {v0.8b}, [Y], 8 + prfm PLDL1KEEP, [U, #64] + prfm PLDL1KEEP, [V, #64] + prfm PLDL1KEEP, [Y, #64] + .elseif \size == 4 + ld1 {v4.b}[0], [U] + ld1 {v4.b}[1], [U] + ld1 {v4.b}[2], [U] + ld1 {v4.b}[3], [U] + ld1 {v5.b}[0], [V] + ld1 {v5.b}[1], [V], 1 + ld1 {v5.b}[2], [V], 1 + ld1 {v5.b}[3], [V], 1 + ld1 {v0.b}[0], [Y], 1 + ld1 {v0.b}[1], [Y], 1 + ld1 {v0.b}[2], [Y], 1 + ld1 {v0.b}[3], [Y], 1 + .elseif \size == 2 + ld1 {v4.b}[4], [U], 1 + ld1 {v4.b}[5], [U], 1 + ld1 {v5.b}[4], [V], 1 + ld1 {v5.b}[5], [V], 1 + ld1 {v0.b}[4], [Y], 1 + ld1 {v0.b}[5], [Y], 1 + .elseif \size == 1 + ld1 {v4.b}[6], [U], 1 + ld1 {v5.b}[6], [V], 1 + ld1 {v0.b}[6], [Y], 1 + .else + .error unsupported macroblock size + .endif +.endm + +.macro do_store bpp, size + .if \bpp == 24 + .if \size == 8 + st3 {v10.8b, v11.8b, v12.8b}, [RGB], 24 + .elseif \size == 4 + st3 {v10.b, v11.b, v12.b}[0], [RGB], 3 + st3 {v10.b, v11.b, v12.b}[1], [RGB], 3 + st3 {v10.b, v11.b, v12.b}[2], [RGB], 3 + st3 {v10.b, v11.b, v12.b}[3], [RGB], 3 + .elseif \size == 2 + st3 {v10.b, v11.b, v12.b}[4], [RGB], 3 + st3 {v10.b, v11.b, v12.b}[4], [RGB], 3 + .elseif \size == 1 + st3 {v10.b, v11.b, v12.b}[6], [RGB], 3 + .else + .error unsupported macroblock size + .endif + .elseif \bpp == 32 + .if \size == 8 + st4 {v10.8b, v11.8b, v12.8b, v13.8b}, [RGB], 32 + .elseif \size == 4 + st4 {v10.b, v11.b, v12.b, v13.b}[0], [RGB], 4 + st4 {v10.b, v11.b, v12.b, v13.b}[1], [RGB], 4 + st4 {v10.b, v11.b, v12.b, v13.b}[2], [RGB], 4 + st4 {v10.b, v11.b, v12.b, v13.b}[3], [RGB], 4 + .elseif \size == 2 + st4 {v10.b, v11.b, v12.b, v13.b}[4], [RGB], 4 + st4 {v10.b, v11.b, v12.b, v13.b}[5], [RGB], 4 + .elseif \size == 1 + st4 {v10.b, v11.b, v12.b, v13.b}[6], [RGB], 4 + .else + .error unsupported macroblock size + .endif + .else + .error unsupported bpp + .endif +.endm +#ifdef RTSM_SQSHRN_SIM_ISSUE +.macro generate_jsimd_ycc_rgb_convert_neon colorid, bpp, r_offs, rsize, g_offs, gsize, b_offs, bsize, defsize +#else +.macro generate_jsimd_ycc_rgb_convert_neon colorid, bpp, r_offs, rsize, g_offs, gsize, b_offs, bsize +#endif +/* + * 2 stage pipelined YCbCr->RGB conversion + */ + +.macro do_yuv_to_rgb_stage1 + uaddw v6.8h, v2.8h, v4.8b /* q3 = u - 128 */ + uaddw v8.8h, v2.8h, v5.8b /* q2 = v - 128 */ + smull v20.4s, v6.4h, v1.4h[1] /* multiply by -11277 */ + smlal v20.4s, v8.4h, v1.4h[2] /* multiply by -23401 */ + smull2 v22.4s, v6.8h, v1.4h[1] /* multiply by -11277 */ + smlal2 v22.4s, v8.8h, v1.4h[2] /* multiply by -23401 */ + smull v24.4s, v8.4h, v1.4h[0] /* multiply by 22971 */ + smull2 v26.4s, v8.8h, v1.4h[0] /* multiply by 22971 */ + smull v28.4s, v6.4h, v1.4h[3] /* multiply by 29033 */ + smull2 v30.4s, v6.8h, v1.4h[3] /* multiply by 29033 */ +.endm + +.macro do_yuv_to_rgb_stage2 + rshrn v20.4h, v20.4s, #15 + rshrn2 v20.8h, v22.4s, #15 + rshrn v24.4h, v24.4s, #14 + rshrn2 v24.8h, v26.4s, #14 + rshrn v28.4h, v28.4s, #14 + rshrn2 v28.8h, v30.4s, #14 + uaddw v20.8h, v20.8h, v0.8b + uaddw v24.8h, v24.8h, v0.8b + uaddw v28.8h, v28.8h, v0.8b +#ifdef RTSM_SQSHRN_SIM_ISSUE + sqxtun v1\g_offs\defsize, v20.8h + sqxtun v1\r_offs\defsize, v24.8h + sqxtun v1\b_offs\defsize, v28.8h + +#else + sqxtun v1\g_offs\gsize, v20.4s + sqxtun v1\r_offs\rsize, v24.4s + sqxtun v1\b_offs\bsize, v28.4s +#endif +.endm + +.macro do_yuv_to_rgb_stage2_store_load_stage1 + ld1 {v4.8b}, [U], 8 + rshrn v20.4h, v20.4s, #15 + rshrn2 v20.8h, v22.4s, #15 + rshrn v24.4h, v24.4s, #14 + rshrn2 v24.8h, v26.4s, #14 + rshrn v28.4h, v28.4s, #14 + ld1 {v5.8b}, [V], 8 + rshrn2 v28.8h, v30.4s, #14 + uaddw v20.8h, v20.8h, v0.8b + uaddw v24.8h, v24.8h, v0.8b + uaddw v28.8h, v28.8h, v0.8b +#ifdef RTSM_SQSHRN_SIM_ISSUE + sqxtun v1\g_offs\defsize, v20.8h +#else + sqxtun v1\g_offs\gsize, v20.4s +#endif + ld1 {v0.8b}, [Y], 8 +#ifdef RTSM_SQSHRN_SIM_ISSUE + sqxtun v1\r_offs\defsize, v24.8h +#else + sqxtun v1\r_offs\rsize, v24.4s +#endif + prfm PLDL1KEEP, [U, #64] + prfm PLDL1KEEP, [V, #64] + prfm PLDL1KEEP, [Y, #64] +#ifdef RTSM_SQSHRN_SIM_ISSUE + sqxtun v1\b_offs\defsize, v28.8h +#else + sqxtun v1\b_offs\gsize, v28.4s +#endif + uaddw v6.8h, v2.8h, v4.8b /* v6.16b = u - 128 */ + uaddw v8.8h, v2.8h, v5.8b /* q2 = v - 128 */ + do_store \bpp, 8 + smull v20.4s, v6.4h, v1.4h[1] /* multiply by -11277 */ + smlal v20.4s, v8.4h, v1.4h[2] /* multiply by -23401 */ + smull2 v22.4s, v6.8h, v1.4h[1] /* multiply by -11277 */ + smlal2 v22.4s, v8.8h, v1.4h[2] /* multiply by -23401 */ + smull v24.4s, v8.4h, v1.4h[0] /* multiply by 22971 */ + smull2 v26.4s, v8.8h, v1.4h[0] /* multiply by 22971 */ + smull v28.4s, v6.4h, v1.4h[3] /* multiply by 29033 */ + smull2 v30.4s, v6.8h, v1.4h[3] /* multiply by 29033 */ +.endm + +.macro do_yuv_to_rgb + do_yuv_to_rgb_stage1 + do_yuv_to_rgb_stage2 +.endm + +/* Apple gas crashes on adrl, work around that by using adr. + * But this requires a copy of these constants for each function. + */ + +.balign 16 +jsimd_ycc_\colorid\()_neon_consts: + .short 0, 0, 0, 0 + .short 22971, -11277, -23401, 29033 + .short -128, -128, -128, -128 + .short -128, -128, -128, -128 + +asm_function jsimd_ycc_\colorid\()_convert_neon + OUTPUT_WIDTH .req x0 + INPUT_BUF .req x1 + INPUT_ROW .req x2 + OUTPUT_BUF .req x3 + NUM_ROWS .req x4 + + INPUT_BUF0 .req x5 + INPUT_BUF1 .req x6 + INPUT_BUF2 .req INPUT_BUF + + RGB .req x7 + Y .req x8 + U .req x9 + V .req x10 + N .req x15 + + /* Load constants to d1, d2, d3 (v0.4h is just used for padding) */ + adr x15, jsimd_ycc_\colorid\()_neon_consts + ld1 {v0.4h, v1.4h}, [x15], 16 + ld1 {v2.8h}, [x15] + + /* Save ARM registers and handle input arguments */ + /* push {x4, x5, x6, x7, x8, x9, x10, x30} */ + stp x4, x5, [sp,-16]! + stp x6, x7, [sp,-16]! + stp x8, x9, [sp,-16]! + stp x10, x30, [sp,-16]! + ldr INPUT_BUF0, [INPUT_BUF] + ldr INPUT_BUF1, [INPUT_BUF, 8] + ldr INPUT_BUF2, [INPUT_BUF, 16] + .unreq INPUT_BUF + + /* Save NEON registers */ + /* vpush {v8.4h-v15.4h} */ + sub sp, sp, #32 + st1 {v8.4h-v11.4h}, [sp] + sub sp, sp, #32 + st1 {v12.4h-v15.4h}, [sp] + + /* Initially set v10, v11.4h, v12.8b, d13 to 0xFF */ + movi v10.16b, #255 + movi v12.16b, #255 + + /* Outer loop over scanlines */ + cmp NUM_ROWS, #1 + blt 9f +0: + lsl x16, INPUT_ROW, #3 + ldr Y, [INPUT_BUF0, x16] + ldr U, [INPUT_BUF1, x16] + mov N, OUTPUT_WIDTH + ldr V, [INPUT_BUF2, x16] + add INPUT_ROW, INPUT_ROW, #1 + ldr RGB, [OUTPUT_BUF], #8 + + /* Inner loop over pixels */ + subs N, N, #8 + blt 3f + do_load 8 + do_yuv_to_rgb_stage1 + subs N, N, #8 + blt 2f +1: + do_yuv_to_rgb_stage2_store_load_stage1 + subs N, N, #8 + bge 1b +2: + do_yuv_to_rgb_stage2 + do_store \bpp, 8 + tst N, #7 + beq 8f +3: + tst N, #4 + beq 3f + do_load 4 +3: + tst N, #2 + beq 4f + do_load 2 +4: + tst N, #1 + beq 5f + do_load 1 +5: + do_yuv_to_rgb + tst N, #4 + beq 6f + do_store \bpp, 4 +6: + tst N, #2 + beq 7f + do_store \bpp, 2 +7: + tst N, #1 + beq 8f + do_store \bpp, 1 +8: + subs NUM_ROWS, NUM_ROWS, #1 + bgt 0b +9: + /* Restore all registers and return */ + /* vpop {v8.4h-v15.4h} */ + ld1 {v12.4h-v15.4h}, [sp], #32 + ld1 {v8.4h-v11.4h}, [sp], #32 + /* pop {r4, r5, r6, r7, r8, r9, r10, pc} */ + ldp x10, x30, [sp], #16 + ldp x8, x9, [sp], #16 + ldp x6, x5, [sp], #16 + ldp x4, x5, [sp], #16 + br x30 + .unreq OUTPUT_WIDTH + .unreq INPUT_ROW + .unreq OUTPUT_BUF + .unreq NUM_ROWS + .unreq INPUT_BUF0 + .unreq INPUT_BUF1 + .unreq INPUT_BUF2 + .unreq RGB + .unreq Y + .unreq U + .unreq V + .unreq N +.endfunc + +.purgem do_yuv_to_rgb +.purgem do_yuv_to_rgb_stage1 +.purgem do_yuv_to_rgb_stage2 +.purgem do_yuv_to_rgb_stage2_store_load_stage1 +.endm + +/* RTSM simulator fix integer saturation works on 8b boundry add a new parameter + * as a workaround for the simulator fix + */ +#ifdef RTSM_SQSHRN_SIM_ISSUE +/*--------------------------------- id ----- bpp R rsize G gsize B bsize defsize */ +generate_jsimd_ycc_rgb_convert_neon extrgb, 24, 0, .4h, 1, .4h, 2, .4h, .8b +generate_jsimd_ycc_rgb_convert_neon extbgr, 24, 2, .4h, 1, .4h, 0, .4h, .8b +generate_jsimd_ycc_rgb_convert_neon extrgbx, 32, 0, .4h, 1, .4h, 2, .4h, .8b +generate_jsimd_ycc_rgb_convert_neon extbgrx, 32, 2, .4h, 1, .4h, 0, .4h, .8b +generate_jsimd_ycc_rgb_convert_neon extxbgr, 32, 3, .4h, 2, .4h, 1, .4h, .8b +generate_jsimd_ycc_rgb_convert_neon extxrgb, 32, 1, .4h, 2, .4h, 3, .4h, .8b +#else +/*--------------------------------- id ----- bpp R rsize G gsize B bsize */ +generate_jsimd_ycc_rgb_convert_neon extrgb, 24, 0, .4h, 1, .4h, 2, .4h +generate_jsimd_ycc_rgb_convert_neon extbgr, 24, 2, .4h, 1, .4h, 0, .4h +generate_jsimd_ycc_rgb_convert_neon extrgbx, 32, 0, .4h, 1, .4h, 2, .4h +generate_jsimd_ycc_rgb_convert_neon extbgrx, 32, 2, .4h, 1, .4h, 0, .4h +generate_jsimd_ycc_rgb_convert_neon extxbgr, 32, 3, .4h, 2, .4h, 1, .4h +generate_jsimd_ycc_rgb_convert_neon extxrgb, 32, 1, .4h, 2, .4h, 3, .4h +#endif + +.purgem do_load +.purgem do_store diff --git a/tjbench.c b/tjbench.c index 9fe8d050..44270487 100644 --- a/tjbench.c +++ b/tjbench.c @@ -1,5 +1,5 @@ /* - * Copyright (C)2009-2013 D. R. Commander. All Rights Reserved. + * Copyright (C)2009-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: @@ -45,9 +45,8 @@ #define _throwtj(m) _throw(m, tjGetErrorStr()) #define _throwbmp(m) _throw(m, bmpgeterr()) -enum {YUVENCODE=1, YUVDECODE, YUVCOMPRESS}; -int flags=TJFLAG_NOREALLOC, componly=0, decomponly=0, yuv=0, quiet=0, dotile=0, - pf=TJPF_BGR, yuvpad=1; +int flags=TJFLAG_NOREALLOC, componly=0, decomponly=0, doyuv=0, quiet=0, + dotile=0, pf=TJPF_BGR, yuvpad=1, warmup=1; char *ext="ppm"; const char *pixFormatStr[TJ_NUMPF]= { @@ -102,21 +101,20 @@ int dummyDCTFilter(short *coeffs, tjregion arrayRegion, tjregion planeRegion, /* Decompression test */ -int decomptest(unsigned char *srcbuf, unsigned char **jpegbuf, +int decomp(unsigned char *srcbuf, unsigned char **jpegbuf, unsigned long *jpegsize, unsigned char *dstbuf, int w, int h, int subsamp, int jpegqual, char *filename, int tilew, int tileh) { char tempstr[1024], sizestr[20]="\0", qualstr[6]="\0", *ptr; FILE *file=NULL; tjhandle handle=NULL; - int row, col, i, dstbufalloc=0, retval=0; - double start, elapsed; + int row, col, iter=0, dstbufalloc=0, retval=0; + double elapsed, elapsedDecode; int ps=tjPixelSize[pf]; int scaledw=TJSCALED(w, sf); int scaledh=TJSCALED(h, sf); - int yuvsize=tjBufSizeYUV2(scaledw, yuvpad, scaledh, subsamp), bufsize; int pitch=scaledw*ps; int ntilesw=(w+tilew-1)/tilew, ntilesh=(h+tileh-1)/tileh; - unsigned char *dstptr, *dstptr2; + unsigned char *dstptr, *dstptr2, *yuvbuf=NULL; if(jpegqual>0) { @@ -127,64 +125,93 @@ int decomptest(unsigned char *srcbuf, unsigned char **jpegbuf, if((handle=tjInitDecompress())==NULL) _throwtj("executing tjInitDecompress()"); - bufsize=(yuv==YUVDECODE? yuvsize:pitch*scaledh); if(dstbuf==NULL) { - if((dstbuf=(unsigned char *)malloc(bufsize)) == NULL) - _throwunix("allocating image buffer"); + if((dstbuf=(unsigned char *)malloc(pitch*scaledh))==NULL) + _throwunix("allocating destination buffer"); dstbufalloc=1; } /* Set the destination buffer to gray so we know whether the decompressor attempted to write to it */ - memset(dstbuf, 127, bufsize); + memset(dstbuf, 127, pitch*scaledh); - /* Execute once to preload cache */ - if(yuv==YUVDECODE) + if(doyuv) { - if(tjDecompressToYUV2(handle, jpegbuf[0], jpegsize[0], dstbuf, scaledw, - yuvpad, scaledh, flags)==-1) - _throwtj("executing tjDecompressToYUV2()"); + int width=dotile? tilew:scaledw; + int height=dotile? tileh:scaledh; + int yuvsize=tjBufSizeYUV2(width, yuvpad, height, subsamp); + if((yuvbuf=(unsigned char *)malloc(yuvsize))==NULL) + _throwunix("allocating YUV buffer"); + memset(yuvbuf, 127, yuvsize); } - else if(tjDecompress2(handle, jpegbuf[0], jpegsize[0], dstbuf, scaledw, - pitch, scaledh, pf, flags)==-1) - _throwtj("executing tjDecompress2()"); /* Benchmark */ - for(i=0, start=gettime(); (elapsed=gettime()-start)=0) elapsedDecode+=gettime()-startDecode; + } + else + if(tjDecompress2(handle, jpegbuf[tile], jpegsize[tile], dstptr2, + width, pitch, height, pf, flags)==-1) + _throwtj("executing tjDecompress2()"); } } + iter++; + if(iter>=1) + { + elapsed+=gettime()-start; + if(elapsed>=benchtime) break; + } } + if(doyuv) elapsed-=elapsedDecode; if(tjDestroy(handle)==-1) _throwtj("executing tjDestroy()"); handle=NULL; if(quiet) { - printf("%s\n", - sigfig((double)(w*h)/1000000.*(double)i/elapsed, 4, tempstr, 1024)); + printf("%-6s%s", + sigfig((double)(w*h)/1000000.*(double)iter/elapsed, 4, tempstr, 1024), + quiet==2? "\n":" "); + if(doyuv) + printf("%s\n", + sigfig((double)(w*h)/1000000.*(double)iter/elapsedDecode, 4, tempstr, + 1024)); + else if(quiet!=2) printf("\n"); } else { - printf("D--> Frame rate: %f fps\n", (double)i/elapsed); - printf(" Dest. throughput: %f Megapixels/sec\n", - (double)(w*h)/1000000.*(double)i/elapsed); + printf("%s --> Frame rate: %f fps\n", + doyuv? "Decomp to YUV":"Decompress ", (double)iter/elapsed); + printf(" Throughput: %f Megapixels/sec\n", + (double)(w*h)/1000000.*(double)iter/elapsed); + if(doyuv) + { + printf("YUV Decode --> Frame rate:  %f fps\n", + (double)iter/elapsedDecode); + printf(" Throughput: %f Megapixels/sec\n", + (double)(w*h)/1000000.*(double)iter/elapsedDecode); + } } if(sf.num!=1 || sf.denom!=1) snprintf(sizestr, 20, "%d_%d", sf.num, sf.denom); @@ -197,61 +224,51 @@ int decomptest(unsigned char *srcbuf, unsigned char **jpegbuf, snprintf(tempstr, 1024, "%s_%s%s_%s.%s", filename, subName[subsamp], qualstr, sizestr, ext); - if(yuv==YUVDECODE) + if(savebmp(tempstr, dstbuf, scaledw, scaledh, pf, + (flags&TJFLAG_BOTTOMUP)!=0)==-1) + _throwbmp("saving bitmap"); + ptr=strrchr(tempstr, '.'); + snprintf(ptr, 1024-(ptr-tempstr), "-err.%s", ext); + if(srcbuf && sf.num==1 && sf.denom==1) { - if((file=fopen(tempstr, "wb"))==NULL) - _throwunix("opening YUV image for output"); - if(fwrite(dstbuf, yuvsize, 1, file)!=1) - _throwunix("writing YUV image"); - fclose(file); file=NULL; - } - else - { - if(savebmp(tempstr, dstbuf, scaledw, scaledh, pf, + if(!quiet) printf("Compression error written to %s.\n", tempstr); + if(subsamp==TJ_GRAYSCALE) + { + int index, index2; + for(row=0, index=0; row255) y=255; if(y<0) y=0; + dstbuf[rindex]=abs(dstbuf[rindex]-y); + dstbuf[gindex]=abs(dstbuf[gindex]-y); + dstbuf[bindex]=abs(dstbuf[bindex]-y); + } + } + } + else + { + for(row=0; row255) y=255; if(y<0) y=0; - dstbuf[rindex]=abs(dstbuf[rindex]-y); - dstbuf[gindex]=abs(dstbuf[gindex]-y); - dstbuf[bindex]=abs(dstbuf[bindex]-y); - } - } - } - else - { - for(row=0; row=0) elapsedEncode+=gettime()-startEncode; + if(tjCompressFromYUV(handle, yuvbuf, width, yuvpad, height, subsamp, &jpegbuf[tile], &jpegsize[tile], jpegqual, flags)==-1) _throwtj("executing tjCompressFromYUV()"); } @@ -428,32 +445,58 @@ int dotest(unsigned char *srcbuf, int w, int h, int subsamp, int jpegqual, totaljpegsize+=jpegsize[tile]; } } + iter++; + if(iter>=1) + { + elapsed+=gettime()-start; + if(elapsed>=benchtime) break; + } } + if(doyuv) elapsed-=elapsedEncode; if(tjDestroy(handle)==-1) _throwtj("executing tjDestroy()"); handle=NULL; - if(quiet==1) printf("%-4d %-4d\t", tilew, tileh); + if(quiet==1) printf("%-5d %-5d ", tilew, tileh); if(quiet) { - printf("%s%c%s%c", - sigfig((double)(w*h)/1000000.*(double)i/elapsed, 4, tempstr, 1024), - quiet==2? '\n':'\t', + if(doyuv) + printf("%-6s%s", + sigfig((double)(w*h)/1000000.*(double)iter/elapsedEncode, 4, tempstr, + 1024), quiet==2? "\n":" "); + printf("%-6s%s", + sigfig((double)(w*h)/1000000.*(double)iter/elapsed, 4, tempstr, 1024), + quiet==2? "\n":" "); + printf("%-6s%s", sigfig((double)(w*h*ps)/(double)totaljpegsize, 4, tempstr2, 80), - quiet==2? '\n':'\t'); + quiet==2? "\n":" "); } else { printf("\n%s size: %d x %d\n", dotile? "Tile":"Image", tilew, tileh); - printf("C--> Frame rate: %f fps\n", (double)i/elapsed); - printf(" Output image size: %d bytes\n", totaljpegsize); - printf(" Compression ratio: %f:1\n", + if(doyuv) + { + printf("Encode YUV --> Frame rate: %f fps\n", + (double)iter/elapsedEncode); + printf(" Output image size: %d bytes\n", yuvsize); + printf(" Compression ratio: %f:1\n", + (double)(w*h*ps)/(double)yuvsize); + printf(" Throughput: %f Megapixels/sec\n", + (double)(w*h)/1000000.*(double)iter/elapsedEncode); + printf(" Output bit stream: %f Megabits/sec\n", + (double)yuvsize*8./1000000.*(double)iter/elapsedEncode); + } + printf("%s --> Frame rate: %f fps\n", + doyuv? "Comp from YUV":"Compress ", (double)iter/elapsed); + printf(" Output image size: %d bytes\n", + totaljpegsize); + printf(" Compression ratio: %f:1\n", (double)(w*h*ps)/(double)totaljpegsize); - printf(" Source throughput: %f Megapixels/sec\n", - (double)(w*h)/1000000.*(double)i/elapsed); - printf(" Output bit stream: %f Megabits/sec\n", - (double)totaljpegsize*8./1000000.*(double)i/elapsed); + printf(" Throughput: %f Megapixels/sec\n", + (double)(w*h)/1000000.*(double)iter/elapsed); + printf(" Output bit stream: %f Megabits/sec\n", + (double)totaljpegsize*8./1000000.*(double)iter/elapsed); } if(tilew==w && tileh==h) { @@ -470,7 +513,7 @@ int dotest(unsigned char *srcbuf, int w, int h, int subsamp, int jpegqual, /* Decompression test */ if(!componly) { - if(decomptest(srcbuf, jpegbuf, jpegsize, tmpbuf, w, h, subsamp, jpegqual, + if(decomp(srcbuf, jpegbuf, jpegsize, tmpbuf, w, h, subsamp, jpegqual, filename, tilew, tileh)==-1) goto bailout; } @@ -481,6 +524,10 @@ int dotest(unsigned char *srcbuf, int w, int h, int subsamp, int jpegqual, } free(jpegbuf); jpegbuf=NULL; free(jpegsize); jpegsize=NULL; + if(doyuv) + { + free(yuvbuf); yuvbuf=NULL; + } if(tilew==w && tileh==h) break; } @@ -495,14 +542,15 @@ int dotest(unsigned char *srcbuf, int w, int h, int subsamp, int jpegqual, } free(jpegbuf); jpegbuf=NULL; } + if(yuvbuf) {free(yuvbuf); yuvbuf=NULL;} if(jpegsize) {free(jpegsize); jpegsize=NULL;} if(tmpbuf) {free(tmpbuf); tmpbuf=NULL;} if(handle) {tjDestroy(handle); handle=NULL;} - return retval; + return; } -int dodecomptest(char *filename) +void decompTest(char *filename) { FILE *file=NULL; tjhandle handle=NULL; unsigned char **jpegbuf=NULL, *srcbuf=NULL; @@ -511,7 +559,7 @@ int dodecomptest(char *filename) int w=0, h=0, subsamp=-1, cs=-1, _w, _h, _tilew, _tileh, _ntilesw, _ntilesh, _subsamp; char *temp=NULL, tempstr[80], tempstr2[80]; - int row, col, i, tilew, tileh, ntilesw=1, ntilesh=1, retval=0; + int row, col, i, iter, tilew, tileh, ntilesw=1, ntilesh=1, retval=0; double start, elapsed; int ps=tjPixelSize[pf], tile; @@ -538,20 +586,18 @@ int dodecomptest(char *filename) if(quiet==1) { printf("All performance values in Mpixels/sec\n\n"); - printf("Bitmap\tBitmap\tJPEG\tJPEG\t%s %s \tXform\tComp\tDecomp\n", + printf("Bitmap JPEG JPEG %s %s Xform Comp Decomp ", dotile? "Tile ":"Image", dotile? "Tile ":"Image"); - printf("Format\tOrder\tCS\tSubsamp\tWidth Height\tPerf \tRatio\tPerf\n\n"); + if(doyuv) printf("Decode"); + printf("\n"); + printf("Format CS Subsamp Width Height Perf Ratio Perf "); + if(doyuv) printf("Perf"); + printf("\n\n"); } else if(!quiet) - { - if(yuv==YUVDECODE) - printf(">>>>> JPEG %s --> YUV <<<<<\n", - formatName(subsamp, cs, tempstr)); - else - printf(">>>>> JPEG %s --> %s (%s) <<<<<\n", - formatName(subsamp, cs, tempstr), pixFormatStr[pf], - (flags&TJFLAG_BOTTOMUP)? "Bottom-up":"Top-down"); - } + printf(">>>>> JPEG %s --> %s (%s) <<<<<\n", + formatName(subsamp, cs, tempstr), pixFormatStr[pf], + (flags&TJFLAG_BOTTOMUP)? "Bottom-up":"Top-down"); for(tilew=dotile? 16:w, tileh=dotile? 16:h; ; tilew*=2, tileh*=2) { @@ -567,7 +613,7 @@ int dodecomptest(char *filename) _throwunix("allocating JPEG size array"); memset(jpegsize, 0, sizeof(unsigned long)*ntilesw*ntilesh); - if((flags&TJFLAG_NOREALLOC)!=0) + if((flags&TJFLAG_NOREALLOC)!=0 || !dotile) for(i=0; i=1) + { + elapsed+=gettime()-start; + if(elapsed>=benchtime) break; + } + } free(t); t=NULL; @@ -647,27 +710,27 @@ int dodecomptest(char *filename) if(quiet) { - printf("%s%c%s%c", + printf("%-6s%s%-6s%s", sigfig((double)(w*h)/1000000./elapsed, 4, tempstr, 80), - quiet==2? '\n':'\t', + quiet==2? "\n":" ", sigfig((double)(w*h*ps)/(double)totaljpegsize, 4, tempstr2, 80), - quiet==2? '\n':'\t'); + quiet==2? "\n":" "); } else if(!quiet) { - printf("X--> Frame rate: %f fps\n", 1.0/elapsed); - printf(" Output image size: %lu bytes\n", totaljpegsize); - printf(" Compression ratio: %f:1\n", + printf("Transform --> Frame rate: %f fps\n", 1.0/elapsed); + printf(" Output image size: %lu bytes\n", totaljpegsize); + printf(" Compression ratio: %f:1\n", (double)(w*h*ps)/(double)totaljpegsize); - printf(" Source throughput: %f Megapixels/sec\n", + printf(" Throughput: %f Megapixels/sec\n", (double)(w*h)/1000000./elapsed); - printf(" Output bit stream: %f Megabits/sec\n", + printf(" Output bit stream: %f Megabits/sec\n", (double)totaljpegsize*8./1000000./elapsed); } } else { - if(quiet==1) printf("N/A\tN/A\t"); + if(quiet==1) printf("N/A N/A "); jpegsize[0]=srcsize; memcpy(jpegbuf[0], srcbuf, srcsize); } @@ -676,7 +739,7 @@ int dodecomptest(char *filename) if(h==tileh) _tileh=_h; if(!(xformopt&TJXOPT_NOOUTPUT)) { - if(decomptest(NULL, jpegbuf, jpegsize, NULL, _w, _h, _subsamp, 0, + if(decomp(NULL, jpegbuf, jpegsize, NULL, _w, _h, _subsamp, 0, filename, _tilew, _tileh)==-1) goto bailout; } @@ -706,7 +769,7 @@ int dodecomptest(char *filename) if(srcbuf) {free(srcbuf); srcbuf=NULL;} if(t) {free(t); t=NULL;} if(handle) {tjDestroy(handle); handle=NULL;} - return retval; + return; } @@ -714,39 +777,33 @@ void usage(char *progname) { int i; printf("USAGE: %s\n", progname); - printf(" [options]\n\n"); + printf(" [options]\n\n"); printf(" %s\n", progname); printf(" [options]\n\n"); printf("Options:\n\n"); printf("-alloc = Dynamically allocate JPEG image buffers\n"); - printf("-bmp = Generate output images in Windows Bitmap format (default=PPM)\n"); + printf("-bmp = Generate output images in Windows Bitmap format (default = PPM)\n"); printf("-bottomup = Test bottom-up compression/decompression\n"); printf("-tile = Test performance of the codec when the image is encoded as separate\n"); printf(" tiles of varying sizes.\n"); printf("-rgb, -bgr, -rgbx, -bgrx, -xbgr, -xrgb =\n"); - printf(" Test the specified color conversion path in the codec (default: BGR)\n"); + printf(" Test the specified color conversion path in the codec (default = BGR)\n"); printf("-fastupsample = Use the fastest chrominance upsampling algorithm available in\n"); printf(" the underlying codec\n"); printf("-fastdct = Use the fastest DCT/IDCT algorithms available in the underlying\n"); printf(" codec\n"); printf("-accuratedct = Use the most accurate DCT/IDCT algorithms available in the\n"); printf(" underlying codec\n"); - printf("-subsamp = if compressing a JPEG image from a YUV planar source image,\n"); - printf(" this specifies the level of chrominance subsampling used in the source\n"); - printf(" image. Otherwise, this specifies the level of chrominance subsampling\n"); - printf(" to use in the JPEG destination image. = 444, 422, 440, 420, 411,\n"); - printf(" or GRAY\n"); + printf("-subsamp = When testing JPEG compression, this option specifies the level\n"); + printf(" of chrominance subsampling to use ( = 444, 422, 440, 420, 411, or\n"); + printf(" GRAY). The default is to test Grayscale, 4:2:0, 4:2:2, and 4:4:4 in\n"); + printf(" sequence.\n"); printf("-quiet = Output results in tabular rather than verbose format\n"); - printf("-yuvencode = Encode RGB input as planar YUV rather than compressing as JPEG\n"); - printf("-yuvdecode = Decode JPEG image to planar YUV rather than RGB\n"); - printf("-yuvsize WxH = if compressing a JPEG image from a YUV planar source image, this\n"); - printf(" specifies the width and height of the source image.\n"); - printf("-yuvpad

= if compressing a JPEG image from a YUV planar source image, this\n"); - printf(" specifies the number of bytes to which each row of each plane in the\n"); - printf(" source image is padded. If decompressing a JPEG image to a YUV planar\n"); - printf(" destination image, this specifies the row padding for each plane of the\n"); - printf(" destination image. (default=1)\n"); - printf("-scale M/N = scale down the width/height of the decompressed JPEG image by a\n"); + printf("-yuv = Test YUV encoding/decoding functions\n"); + printf("-yuvpad

= If testing YUV encoding/decoding, this specifies the number of\n"); + printf(" bytes to which each row of each plane in the intermediate YUV image is\n"); + printf(" padded (default = 1)\n"); + printf("-scale M/N = Scale down the width/height of the decompressed JPEG image by a\n"); printf(" factor of M/N (M/N = "); for(i=0; i = Run each benchmark for at least seconds (default = 5.0)\n"); + printf("-warmup = Execute each benchmark times to prime the cache before\n"); + printf(" taking performance measurements (default = 1)\n"); printf("-componly = Stop after running compression tests. Do not test decompression.\n\n"); printf("NOTE: If the quality is specified as a range (e.g. 90-100), a separate\n"); printf("test will be performed for all quality values in the range.\n\n"); @@ -789,29 +848,11 @@ int main(int argc, char *argv[]) { if(!strcasecmp(temp, ".bmp")) ext="bmp"; if(!strcasecmp(temp, ".jpg") || !strcasecmp(temp, ".jpeg")) decomponly=1; - if(!strcasecmp(temp, ".yuv")) yuv=YUVCOMPRESS; } printf("\n"); - if(argc>minarg) - { - for(i=minarg; i0.0) benchtime=temp; else usage(argv[0]); } + if(!strcasecmp(argv[i], "-warmup") && i=0) + { + warmup=temp; + printf("Warmup runs = %d\n\n", warmup); + } + else usage(argv[0]); + } if(!strcmp(argv[i], "-?")) usage(argv[0]); if(!strcasecmp(argv[i], "-alloc")) flags&=(~TJFLAG_NOREALLOC); if(!strcasecmp(argv[i], "-bmp")) ext="bmp"; - if(!strcasecmp(argv[i], "-yuvsize") && i=1 - && temp2>=1) - { - w=temp1; h=temp2; - } - else usage(argv[0]); + printf("Testing YUV planar encoding/decoding\n\n"); + doyuv=1; } if(!strcasecmp(argv[i], "-yuvpad") && i=TJ_NUMSAMP) - _throw("opening YUV image file", - "YUV image size and/or subsampling not specified"); - if((file=fopen(argv[1], "rb"))==NULL) - _throwunix("opening YUV image file"); - if(fseek(file, 0, SEEK_END)<0 || - (srcsize=ftell(file))==(unsigned long)-1) - _throwunix("determining YUV image file size"); - if(srcsize!=tjBufSizeYUV2(w, yuvpad, h, subsamp)) - _throw("opening YUV image file", "YUV image file is the wrong size"); - if((srcbuf=(unsigned char *)malloc(srcsize))==NULL) - _throwunix("allocating memory for YUV image"); - if(fseek(file, 0, SEEK_SET)<0) - _throwunix("setting YUV image file position"); - if(fread(srcbuf, srcsize, 1, file)<1) - _throwunix("reading YUV data"); - fclose(file); file=NULL; - } - else - { - if(loadbmp(argv[1], &srcbuf, &w, &h, pf, (flags&TJFLAG_BOTTOMUP)!=0)==-1) - _throwbmp("loading bitmap"); - } + if(loadbmp(argv[1], &srcbuf, &w, &h, pf, (flags&TJFLAG_BOTTOMUP)!=0)==-1) + _throwbmp("loading bitmap"); temp=strrchr(argv[1], '.'); if(temp!=NULL) *temp='\0'; } @@ -982,36 +995,44 @@ int main(int argc, char *argv[]) if(quiet==1 && !decomponly) { printf("All performance values in Mpixels/sec\n\n"); - printf("Bitmap\tBitmap\tJPEG\tJPEG\t%s %s \tComp\tComp\tDecomp\n", + printf("Bitmap JPEG JPEG %s %s ", dotile? "Tile ":"Image", dotile? "Tile ":"Image"); - printf("Format\tOrder\tSubsamp\tQual\tWidth Height\tPerf \tRatio\tPerf\n\n"); + if(doyuv) printf("Encode "); + printf("Comp Comp Decomp "); + if(doyuv) printf("Decode"); + printf("\n"); + printf("Format Subsamp Qual Width Height "); + if(doyuv) printf("Perf "); + printf("Perf Ratio Perf "); + if(doyuv) printf("Perf"); + printf("\n\n"); } if(decomponly) { - dodecomptest(argv[1]); + decompTest(argv[1]); printf("\n"); goto bailout; } - if(yuv==YUVCOMPRESS || (subsamp>=0 && subsamp=0 && subsamp=minqual; i--) - dotest(srcbuf, w, h, subsamp, i, argv[1]); + fullTest(srcbuf, w, h, subsamp, i, argv[1]); printf("\n"); } else { for(i=maxqual; i>=minqual; i--) - dotest(srcbuf, w, h, TJSAMP_GRAY, i, argv[1]); + fullTest(srcbuf, w, h, TJSAMP_GRAY, i, argv[1]); printf("\n"); for(i=maxqual; i>=minqual; i--) - dotest(srcbuf, w, h, TJSAMP_420, i, argv[1]); + fullTest(srcbuf, w, h, TJSAMP_420, i, argv[1]); printf("\n"); for(i=maxqual; i>=minqual; i--) - dotest(srcbuf, w, h, TJSAMP_422, i, argv[1]); + fullTest(srcbuf, w, h, TJSAMP_422, i, argv[1]); printf("\n"); for(i=maxqual; i>=minqual; i--) - dotest(srcbuf, w, h, TJSAMP_444, i, argv[1]); + fullTest(srcbuf, w, h, TJSAMP_444, i, argv[1]); printf("\n"); } diff --git a/tjbenchtest.in b/tjbenchtest.in index 72b93f8e..5e08c9b3 100755 --- a/tjbenchtest.in +++ b/tjbenchtest.in @@ -25,6 +25,8 @@ IMGDIR=@srcdir@/testimages OUTDIR=__tjbenchtest_output EXEDIR=. BMPARG= +NSARG= +YUVARG= if [ "$EXT" = "bmp" ]; then BMPARG=-bmp; fi if [ -d $OUTDIR ]; then @@ -34,33 +36,58 @@ mkdir -p $OUTDIR exec >$EXEDIR/tjbenchtest.log +if [ $# -gt 0 ]; then + if [ "$1" = "-yuv" ]; then + NSARG=-nosmooth + YUVARG=-yuv + +# NOTE: The combination of tjEncodeYUV*() and tjCompressFromYUV*() does not +# always produce bitwise-identical results to tjCompress*() if subsampling is +# enabled. In both cases, if the image width or height are not evenly +# divisible by the MCU width/height, then the bottom and/or right edge are +# expanded. However, the libjpeg code performs this expansion prior to +# downsampling, and TurboJPEG performs it in tjCompressFromYUV*(), which is +# after downsampling. Thus, the two will agree only if the width/height along +# each downsampled dimension is an odd number or is evenly divisible by the MCU +# width/height. This disagreement basically amounts to a round-off error, but +# there is no easy way around it, so for now, we just test the only image that +# works. (NOTE: nightshot_iso_100 does not suffer from the above issue, but +# it suffers from an unrelated problem whereby the combination of +# tjDecompressToYUV*() and tjDecodeYUV*() do not produce bitwise-identical +# results to tjDecompress*() if decompression scaling is enabled. This latter +# phenomenon is not yet fully understood but is also believed to be some sort +# of round-off error.) + IMAGES="vgl_6548_0026a.${EXT}" + fi +fi + # Standard tests for image in $IMAGES; do cp $IMGDIR/$image $OUTDIR basename=`basename $image .${EXT}` - $EXEDIR/cjpeg -quality 95 -dct fast -grayscale $IMGDIR/${basename}.${EXT} >$OUTDIR/${basename}_GRAY_fast_cjpeg.jpg - $EXEDIR/cjpeg -quality 95 -dct fast -sample 2x2 $IMGDIR/${basename}.${EXT} >$OUTDIR/${basename}_420_fast_cjpeg.jpg - $EXEDIR/cjpeg -quality 95 -dct fast -sample 2x1 $IMGDIR/${basename}.${EXT} >$OUTDIR/${basename}_422_fast_cjpeg.jpg - $EXEDIR/cjpeg -quality 95 -dct fast -sample 1x1 $IMGDIR/${basename}.${EXT} >$OUTDIR/${basename}_444_fast_cjpeg.jpg - $EXEDIR/cjpeg -quality 95 -dct int -grayscale $IMGDIR/${basename}.${EXT} >$OUTDIR/${basename}_GRAY_accurate_cjpeg.jpg - $EXEDIR/cjpeg -quality 95 -dct int -sample 2x2 $IMGDIR/${basename}.${EXT} >$OUTDIR/${basename}_420_accurate_cjpeg.jpg - $EXEDIR/cjpeg -quality 95 -dct int -sample 2x1 $IMGDIR/${basename}.${EXT} >$OUTDIR/${basename}_422_accurate_cjpeg.jpg - $EXEDIR/cjpeg -quality 95 -dct int -sample 1x1 $IMGDIR/${basename}.${EXT} >$OUTDIR/${basename}_444_accurate_cjpeg.jpg + runme $EXEDIR/cjpeg -quality 95 -dct fast -grayscale -outfile $OUTDIR/${basename}_GRAY_fast_cjpeg.jpg $IMGDIR/${basename}.${EXT} + runme $EXEDIR/cjpeg -quality 95 -dct fast -sample 2x2 -outfile $OUTDIR/${basename}_420_fast_cjpeg.jpg $IMGDIR/${basename}.${EXT} + runme $EXEDIR/cjpeg -quality 95 -dct fast -sample 2x1 -outfile $OUTDIR/${basename}_422_fast_cjpeg.jpg $IMGDIR/${basename}.${EXT} + runme $EXEDIR/cjpeg -quality 95 -dct fast -sample 1x1 -outfile $OUTDIR/${basename}_444_fast_cjpeg.jpg $IMGDIR/${basename}.${EXT} + runme $EXEDIR/cjpeg -quality 95 -dct int -grayscale -outfile $OUTDIR/${basename}_GRAY_accurate_cjpeg.jpg $IMGDIR/${basename}.${EXT} + runme $EXEDIR/cjpeg -quality 95 -dct int -sample 2x2 -outfile $OUTDIR/${basename}_420_accurate_cjpeg.jpg $IMGDIR/${basename}.${EXT} + runme $EXEDIR/cjpeg -quality 95 -dct int -sample 2x1 -outfile $OUTDIR/${basename}_422_accurate_cjpeg.jpg $IMGDIR/${basename}.${EXT} + runme $EXEDIR/cjpeg -quality 95 -dct int -sample 1x1 -outfile $OUTDIR/${basename}_444_accurate_cjpeg.jpg $IMGDIR/${basename}.${EXT} for samp in GRAY 420 422 444; do - $EXEDIR/djpeg -rgb $BMPARG $OUTDIR/${basename}_${samp}_fast_cjpeg.jpg >$OUTDIR/${basename}_${samp}_default_djpeg.${EXT} - $EXEDIR/djpeg -dct fast -rgb $BMPARG $OUTDIR/${basename}_${samp}_fast_cjpeg.jpg >$OUTDIR/${basename}_${samp}_fast_djpeg.${EXT} - $EXEDIR/djpeg -dct int -rgb $BMPARG $OUTDIR/${basename}_${samp}_accurate_cjpeg.jpg >$OUTDIR/${basename}_${samp}_accurate_djpeg.${EXT} + runme $EXEDIR/djpeg -rgb $NSARG $BMPARG -outfile $OUTDIR/${basename}_${samp}_default_djpeg.${EXT} $OUTDIR/${basename}_${samp}_fast_cjpeg.jpg + runme $EXEDIR/djpeg -dct fast -rgb $NSARG $BMPARG -outfile $OUTDIR/${basename}_${samp}_fast_djpeg.${EXT} $OUTDIR/${basename}_${samp}_fast_cjpeg.jpg + runme $EXEDIR/djpeg -dct int -rgb $NSARG $BMPARG -outfile $OUTDIR/${basename}_${samp}_accurate_djpeg.${EXT} $OUTDIR/${basename}_${samp}_accurate_cjpeg.jpg done for samp in 420 422; do - $EXEDIR/djpeg -nosmooth $BMPARG $OUTDIR/${basename}_${samp}_fast_cjpeg.jpg >$OUTDIR/${basename}_${samp}_default_nosmooth_djpeg.${EXT} - $EXEDIR/djpeg -dct fast -nosmooth $BMPARG $OUTDIR/${basename}_${samp}_fast_cjpeg.jpg >$OUTDIR/${basename}_${samp}_fast_nosmooth_djpeg.${EXT} - $EXEDIR/djpeg -dct int -nosmooth $BMPARG $OUTDIR/${basename}_${samp}_accurate_cjpeg.jpg >$OUTDIR/${basename}_${samp}_accurate_nosmooth_djpeg.${EXT} + runme $EXEDIR/djpeg -nosmooth $BMPARG -outfile $OUTDIR/${basename}_${samp}_default_nosmooth_djpeg.${EXT} $OUTDIR/${basename}_${samp}_fast_cjpeg.jpg + runme $EXEDIR/djpeg -dct fast -nosmooth $BMPARG -outfile $OUTDIR/${basename}_${samp}_fast_nosmooth_djpeg.${EXT} $OUTDIR/${basename}_${samp}_fast_cjpeg.jpg + runme $EXEDIR/djpeg -dct int -nosmooth $BMPARG -outfile $OUTDIR/${basename}_${samp}_accurate_nosmooth_djpeg.${EXT} $OUTDIR/${basename}_${samp}_accurate_cjpeg.jpg done # Compression for dct in accurate fast; do - runme $EXEDIR/tjbench $OUTDIR/$image 95 -rgb -quiet -benchtime 0.01 -${dct}dct + runme $EXEDIR/tjbench $OUTDIR/$image 95 -rgb -quiet -benchtime 0.01 -warmup 0 -${dct}dct $YUVARG for samp in GRAY 420 422 444; do runme cmp $OUTDIR/${basename}_${samp}_Q95.jpg $OUTDIR/${basename}_${samp}_${dct}_cjpeg.jpg done @@ -73,7 +100,7 @@ for image in $IMAGES; do fi # Tiled compression & decompression - runme $EXEDIR/tjbench $OUTDIR/$image 95 -rgb -tile -quiet -benchtime 0.01 ${dctarg} + runme $EXEDIR/tjbench $OUTDIR/$image 95 -rgb -tile -quiet -benchtime 0.01 -warmup 0 ${dctarg} $YUVARG for samp in GRAY 444; do for i in $OUTDIR/${basename}_${samp}_Q95_[0-9]*[0-9]x[0-9]*[0-9].${EXT} \ $OUTDIR/${basename}_${samp}_Q95_full.${EXT}; do @@ -81,7 +108,7 @@ for image in $IMAGES; do rm $i done done - runme $EXEDIR/tjbench $OUTDIR/$image 95 -rgb -tile -quiet -benchtime 0.01 -fastupsample ${dctarg} + runme $EXEDIR/tjbench $OUTDIR/$image 95 -rgb -tile -quiet -benchtime 0.01 -warmup 0 -fastupsample ${dctarg} $YUVARG for samp in 420 422; do for i in $OUTDIR/${basename}_${samp}_Q95_[0-9]*[0-9]x[0-9]*[0-9].${EXT} \ $OUTDIR/${basename}_${samp}_Q95_full.${EXT}; do @@ -92,7 +119,7 @@ for image in $IMAGES; do # Tiled decompression for samp in GRAY 444; do - runme $EXEDIR/tjbench $OUTDIR/${basename}_${samp}_Q95.jpg $BMPARG -tile -quiet -benchtime 0.01 ${dctarg} + runme $EXEDIR/tjbench $OUTDIR/${basename}_${samp}_Q95.jpg $BMPARG -tile -quiet -benchtime 0.01 -warmup 0 ${dctarg} $YUVARG for i in $OUTDIR/${basename}_${samp}_Q95_[0-9]*[0-9]x[0-9]*[0-9].${EXT} \ $OUTDIR/${basename}_${samp}_Q95_full.${EXT}; do runme cmp $i $OUTDIR/${basename}_${samp}_${dct}_djpeg.${EXT} @@ -100,7 +127,7 @@ for image in $IMAGES; do done done for samp in 420 422; do - runme $EXEDIR/tjbench $OUTDIR/${basename}_${samp}_Q95.jpg $BMPARG -tile -quiet -benchtime 0.01 -fastupsample ${dctarg} + runme $EXEDIR/tjbench $OUTDIR/${basename}_${samp}_Q95.jpg $BMPARG -tile -quiet -benchtime 0.01 -warmup 0 -fastupsample ${dctarg} $YUVARG for i in $OUTDIR/${basename}_${samp}_Q95_[0-9]*[0-9]x[0-9]*[0-9].${EXT} \ $OUTDIR/${basename}_${samp}_Q95_full.${EXT}; do runme cmp $i $OUTDIR/${basename}_${samp}_${dct}_nosmooth_djpeg.${EXT} @@ -113,8 +140,8 @@ for image in $IMAGES; do for scale in 2_1 15_8 7_4 13_8 3_2 11_8 5_4 9_8 7_8 3_4 5_8 1_2 3_8 1_4 1_8; do scalearg=`echo $scale | sed s@_@/@g` for samp in GRAY 420 422 444; do - $EXEDIR/djpeg -rgb -scale ${scalearg} $BMPARG $OUTDIR/${basename}_${samp}_fast_cjpeg.jpg >$OUTDIR/${basename}_${samp}_${scale}_djpeg.${EXT} - runme $EXEDIR/tjbench $OUTDIR/${basename}_${samp}_Q95.jpg $BMPARG -scale ${scalearg} -quiet -benchtime 0.01 + runme $EXEDIR/djpeg -rgb -scale ${scalearg} $NSARG $BMPARG -outfile $OUTDIR/${basename}_${samp}_${scale}_djpeg.${EXT} $OUTDIR/${basename}_${samp}_fast_cjpeg.jpg + runme $EXEDIR/tjbench $OUTDIR/${basename}_${samp}_Q95.jpg $BMPARG -scale ${scalearg} -quiet -benchtime 0.01 -warmup 0 $YUVARG runme cmp $OUTDIR/${basename}_${samp}_Q95_${scale}.${EXT} $OUTDIR/${basename}_${samp}_${scale}_djpeg.${EXT} rm $OUTDIR/${basename}_${samp}_Q95_${scale}.${EXT} done @@ -122,18 +149,18 @@ for image in $IMAGES; do # Transforms for samp in GRAY 420 422 444; do - $EXEDIR/jpegtran -flip horizontal -trim $OUTDIR/${basename}_${samp}_Q95.jpg >$OUTDIR/${basename}_${samp}_hflip_jpegtran.jpg - $EXEDIR/jpegtran -flip vertical -trim $OUTDIR/${basename}_${samp}_Q95.jpg >$OUTDIR/${basename}_${samp}_vflip_jpegtran.jpg - $EXEDIR/jpegtran -transpose -trim $OUTDIR/${basename}_${samp}_Q95.jpg >$OUTDIR/${basename}_${samp}_transpose_jpegtran.jpg - $EXEDIR/jpegtran -transverse -trim $OUTDIR/${basename}_${samp}_Q95.jpg >$OUTDIR/${basename}_${samp}_transverse_jpegtran.jpg - $EXEDIR/jpegtran -rotate 90 -trim $OUTDIR/${basename}_${samp}_Q95.jpg >$OUTDIR/${basename}_${samp}_rot90_jpegtran.jpg - $EXEDIR/jpegtran -rotate 180 -trim $OUTDIR/${basename}_${samp}_Q95.jpg >$OUTDIR/${basename}_${samp}_rot180_jpegtran.jpg - $EXEDIR/jpegtran -rotate 270 -trim $OUTDIR/${basename}_${samp}_Q95.jpg >$OUTDIR/${basename}_${samp}_rot270_jpegtran.jpg + runme $EXEDIR/jpegtran -flip horizontal -trim -outfile $OUTDIR/${basename}_${samp}_hflip_jpegtran.jpg $OUTDIR/${basename}_${samp}_Q95.jpg + runme $EXEDIR/jpegtran -flip vertical -trim -outfile $OUTDIR/${basename}_${samp}_vflip_jpegtran.jpg $OUTDIR/${basename}_${samp}_Q95.jpg + runme $EXEDIR/jpegtran -transpose -trim -outfile $OUTDIR/${basename}_${samp}_transpose_jpegtran.jpg $OUTDIR/${basename}_${samp}_Q95.jpg + runme $EXEDIR/jpegtran -transverse -trim -outfile $OUTDIR/${basename}_${samp}_transverse_jpegtran.jpg $OUTDIR/${basename}_${samp}_Q95.jpg + runme $EXEDIR/jpegtran -rotate 90 -trim -outfile $OUTDIR/${basename}_${samp}_rot90_jpegtran.jpg $OUTDIR/${basename}_${samp}_Q95.jpg + runme $EXEDIR/jpegtran -rotate 180 -trim -outfile $OUTDIR/${basename}_${samp}_rot180_jpegtran.jpg $OUTDIR/${basename}_${samp}_Q95.jpg + runme $EXEDIR/jpegtran -rotate 270 -trim -outfile $OUTDIR/${basename}_${samp}_rot270_jpegtran.jpg $OUTDIR/${basename}_${samp}_Q95.jpg done for xform in hflip vflip transpose transverse rot90 rot180 rot270; do for samp in GRAY 444; do - $EXEDIR/djpeg -rgb $BMPARG $OUTDIR/${basename}_${samp}_${xform}_jpegtran.jpg >$OUTDIR/${basename}_${samp}_${xform}_jpegtran.${EXT} - runme $EXEDIR/tjbench $OUTDIR/${basename}_${samp}_Q95.jpg $BMPARG -$xform -tile -quiet -benchtime 0.01 + runme $EXEDIR/djpeg -rgb $BMPARG -outfile $OUTDIR/${basename}_${samp}_${xform}_jpegtran.${EXT} $OUTDIR/${basename}_${samp}_${xform}_jpegtran.jpg + runme $EXEDIR/tjbench $OUTDIR/${basename}_${samp}_Q95.jpg $BMPARG -$xform -tile -quiet -benchtime 0.01 -warmup 0 $YUVARG for i in $OUTDIR/${basename}_${samp}_Q95_[0-9]*[0-9]x[0-9]*[0-9].${EXT} \ $OUTDIR/${basename}_${samp}_Q95_full.${EXT}; do runme cmp $i $OUTDIR/${basename}_${samp}_${xform}_jpegtran.${EXT} @@ -141,8 +168,8 @@ for image in $IMAGES; do done done for samp in 420 422; do - $EXEDIR/djpeg -nosmooth -rgb $BMPARG $OUTDIR/${basename}_${samp}_${xform}_jpegtran.jpg >$OUTDIR/${basename}_${samp}_${xform}_jpegtran.${EXT} - runme $EXEDIR/tjbench $OUTDIR/${basename}_${samp}_Q95.jpg $BMPARG -$xform -tile -quiet -benchtime 0.01 -fastupsample + runme $EXEDIR/djpeg -nosmooth -rgb $BMPARG -outfile $OUTDIR/${basename}_${samp}_${xform}_jpegtran.${EXT} $OUTDIR/${basename}_${samp}_${xform}_jpegtran.jpg + runme $EXEDIR/tjbench $OUTDIR/${basename}_${samp}_Q95.jpg $BMPARG -$xform -tile -quiet -benchtime 0.01 -warmup 0 -fastupsample $YUVARG for i in $OUTDIR/${basename}_${samp}_Q95_[0-9]*[0-9]x[0-9]*[0-9].${EXT} \ $OUTDIR/${basename}_${samp}_Q95_full.${EXT}; do runme cmp $i $OUTDIR/${basename}_${samp}_${xform}_jpegtran.${EXT} @@ -154,7 +181,7 @@ for image in $IMAGES; do # Grayscale transform for xform in hflip vflip transpose transverse rot90 rot180 rot270; do for samp in GRAY 444 422 420; do - runme $EXEDIR/tjbench $OUTDIR/${basename}_${samp}_Q95.jpg $BMPARG -$xform -tile -quiet -benchtime 0.01 -grayscale + runme $EXEDIR/tjbench $OUTDIR/${basename}_${samp}_Q95.jpg $BMPARG -$xform -tile -quiet -benchtime 0.01 -warmup 0 -grayscale $YUVARG for i in $OUTDIR/${basename}_${samp}_Q95_[0-9]*[0-9]x[0-9]*[0-9].${EXT} \ $OUTDIR/${basename}_${samp}_Q95_full.${EXT}; do runme cmp $i $OUTDIR/${basename}_GRAY_${xform}_jpegtran.${EXT} @@ -168,8 +195,8 @@ for image in $IMAGES; do for samp in GRAY 444 422 420; do for scale in 2_1 15_8 7_4 13_8 3_2 11_8 5_4 9_8 7_8 3_4 5_8 1_2 3_8 1_4 1_8; do scalearg=`echo $scale | sed s@_@/@g` - $EXEDIR/djpeg -rgb -scale ${scalearg} $BMPARG $OUTDIR/${basename}_${samp}_${xform}_jpegtran.jpg >$OUTDIR/${basename}_${samp}_${xform}_${scale}_jpegtran.${EXT} - runme $EXEDIR/tjbench $OUTDIR/${basename}_${samp}_Q95.jpg $BMPARG -$xform -scale ${scalearg} -quiet -benchtime 0.01 + runme $EXEDIR/djpeg -rgb -scale ${scalearg} $NSARG $BMPARG -outfile $OUTDIR/${basename}_${samp}_${xform}_${scale}_jpegtran.${EXT} $OUTDIR/${basename}_${samp}_${xform}_jpegtran.jpg + runme $EXEDIR/tjbench $OUTDIR/${basename}_${samp}_Q95.jpg $BMPARG -$xform -scale ${scalearg} -quiet -benchtime 0.01 -warmup 0 $YUVARG runme cmp $OUTDIR/${basename}_${samp}_Q95_${scale}.${EXT} $OUTDIR/${basename}_${samp}_${xform}_${scale}_jpegtran.${EXT} rm $OUTDIR/${basename}_${samp}_Q95_${scale}.${EXT} done diff --git a/tjbenchtest.java.in b/tjbenchtest.java.in index ebff9c84..1869bca6 100755 --- a/tjbenchtest.java.in +++ b/tjbenchtest.java.in @@ -24,6 +24,9 @@ IMGDIR=@srcdir@/testimages OUTDIR=__tjbenchtest_java_output EXEDIR=. JAVA="@JAVA@ -cp java/turbojpeg.jar -Djava.library.path=.libs" +BMPARG= +NSARG= +YUVARG= if [ -d $OUTDIR ]; then rm -rf $OUTDIR @@ -32,33 +35,58 @@ mkdir -p $OUTDIR exec >$EXEDIR/tjbenchtest-java.log +if [ $# -gt 0 ]; then + if [ "$1" = "-yuv" ]; then + NSARG=-nosmooth + YUVARG=-yuv + +# NOTE: The combination of tjEncodeYUV*() and tjCompressFromYUV*() does not +# always produce bitwise-identical results to tjCompress*() if subsampling is +# enabled. In both cases, if the image width or height are not evenly +# divisible by the MCU width/height, then the bottom and/or right edge are +# expanded. However, the libjpeg code performs this expansion prior to +# downsampling, and TurboJPEG performs it in tjCompressFromYUV*(), which is +# after downsampling. Thus, the two will agree only if the width/height along +# each downsampled dimension is an odd number or is evenly divisible by the MCU +# width/height. This disagreement basically amounts to a round-off error, but +# there is no easy way around it, so for now, we just test the only image that +# works. (NOTE: nightshot_iso_100 does not suffer from the above issue, but +# it suffers from an unrelated problem whereby the combination of +# tjDecompressToYUV*() and tjDecodeYUV*() do not produce bitwise-identical +# results to tjDecompress*() if decompression scaling is enabled. This latter +# phenomenon is not yet fully understood but is also believed to be some sort +# of round-off error.) + IMAGES="vgl_6548_0026a.bmp" + fi +fi + # Standard tests for image in $IMAGES; do cp $IMGDIR/$image $OUTDIR basename=`basename $image .bmp` - $EXEDIR/cjpeg -quality 95 -dct fast -grayscale $IMGDIR/${basename}.bmp >$OUTDIR/${basename}_GRAY_fast_cjpeg.jpg - $EXEDIR/cjpeg -quality 95 -dct fast -sample 2x2 $IMGDIR/${basename}.bmp >$OUTDIR/${basename}_420_fast_cjpeg.jpg - $EXEDIR/cjpeg -quality 95 -dct fast -sample 2x1 $IMGDIR/${basename}.bmp >$OUTDIR/${basename}_422_fast_cjpeg.jpg - $EXEDIR/cjpeg -quality 95 -dct fast -sample 1x1 $IMGDIR/${basename}.bmp >$OUTDIR/${basename}_444_fast_cjpeg.jpg - $EXEDIR/cjpeg -quality 95 -dct int -grayscale $IMGDIR/${basename}.bmp >$OUTDIR/${basename}_GRAY_accurate_cjpeg.jpg - $EXEDIR/cjpeg -quality 95 -dct int -sample 2x2 $IMGDIR/${basename}.bmp >$OUTDIR/${basename}_420_accurate_cjpeg.jpg - $EXEDIR/cjpeg -quality 95 -dct int -sample 2x1 $IMGDIR/${basename}.bmp >$OUTDIR/${basename}_422_accurate_cjpeg.jpg - $EXEDIR/cjpeg -quality 95 -dct int -sample 1x1 $IMGDIR/${basename}.bmp >$OUTDIR/${basename}_444_accurate_cjpeg.jpg + runme $EXEDIR/cjpeg -quality 95 -dct fast -grayscale -outfile $OUTDIR/${basename}_GRAY_fast_cjpeg.jpg $IMGDIR/${basename}.bmp + runme $EXEDIR/cjpeg -quality 95 -dct fast -sample 2x2 -outfile $OUTDIR/${basename}_420_fast_cjpeg.jpg $IMGDIR/${basename}.bmp + runme $EXEDIR/cjpeg -quality 95 -dct fast -sample 2x1 -outfile $OUTDIR/${basename}_422_fast_cjpeg.jpg $IMGDIR/${basename}.bmp + runme $EXEDIR/cjpeg -quality 95 -dct fast -sample 1x1 -outfile $OUTDIR/${basename}_444_fast_cjpeg.jpg $IMGDIR/${basename}.bmp + runme $EXEDIR/cjpeg -quality 95 -dct int -grayscale -outfile $OUTDIR/${basename}_GRAY_accurate_cjpeg.jpg $IMGDIR/${basename}.bmp + runme $EXEDIR/cjpeg -quality 95 -dct int -sample 2x2 -outfile $OUTDIR/${basename}_420_accurate_cjpeg.jpg $IMGDIR/${basename}.bmp + runme $EXEDIR/cjpeg -quality 95 -dct int -sample 2x1 -outfile $OUTDIR/${basename}_422_accurate_cjpeg.jpg $IMGDIR/${basename}.bmp + runme $EXEDIR/cjpeg -quality 95 -dct int -sample 1x1 -outfile $OUTDIR/${basename}_444_accurate_cjpeg.jpg $IMGDIR/${basename}.bmp for samp in GRAY 420 422 444; do - $EXEDIR/djpeg -rgb -bmp $OUTDIR/${basename}_${samp}_fast_cjpeg.jpg >$OUTDIR/${basename}_${samp}_default_djpeg.bmp - $EXEDIR/djpeg -dct fast -rgb -bmp $OUTDIR/${basename}_${samp}_fast_cjpeg.jpg >$OUTDIR/${basename}_${samp}_fast_djpeg.bmp - $EXEDIR/djpeg -dct int -rgb -bmp $OUTDIR/${basename}_${samp}_accurate_cjpeg.jpg >$OUTDIR/${basename}_${samp}_accurate_djpeg.bmp + runme $EXEDIR/djpeg -rgb -bmp -outfile $OUTDIR/${basename}_${samp}_default_djpeg.bmp $OUTDIR/${basename}_${samp}_fast_cjpeg.jpg + runme $EXEDIR/djpeg -dct fast -rgb -bmp -outfile $OUTDIR/${basename}_${samp}_fast_djpeg.bmp $OUTDIR/${basename}_${samp}_fast_cjpeg.jpg + runme $EXEDIR/djpeg -dct int -rgb -bmp -outfile $OUTDIR/${basename}_${samp}_accurate_djpeg.bmp $OUTDIR/${basename}_${samp}_accurate_cjpeg.jpg done for samp in 420 422; do - $EXEDIR/djpeg -nosmooth -bmp $OUTDIR/${basename}_${samp}_fast_cjpeg.jpg >$OUTDIR/${basename}_${samp}_default_nosmooth_djpeg.bmp - $EXEDIR/djpeg -dct fast -nosmooth -bmp $OUTDIR/${basename}_${samp}_fast_cjpeg.jpg >$OUTDIR/${basename}_${samp}_fast_nosmooth_djpeg.bmp - $EXEDIR/djpeg -dct int -nosmooth -bmp $OUTDIR/${basename}_${samp}_accurate_cjpeg.jpg >$OUTDIR/${basename}_${samp}_accurate_nosmooth_djpeg.bmp + runme $EXEDIR/djpeg -nosmooth -bmp -outfile $OUTDIR/${basename}_${samp}_default_nosmooth_djpeg.bmp $OUTDIR/${basename}_${samp}_fast_cjpeg.jpg + runme $EXEDIR/djpeg -dct fast -nosmooth -bmp -outfile $OUTDIR/${basename}_${samp}_fast_nosmooth_djpeg.bmp $OUTDIR/${basename}_${samp}_fast_cjpeg.jpg + runme $EXEDIR/djpeg -dct int -nosmooth -bmp -outfile $OUTDIR/${basename}_${samp}_accurate_nosmooth_djpeg.bmp $OUTDIR/${basename}_${samp}_accurate_cjpeg.jpg done # Compression for dct in accurate fast; do - runme $JAVA TJBench $OUTDIR/$image 95 -rgb -quiet -benchtime 0.01 -${dct}dct + runme $JAVA TJBench $OUTDIR/$image 95 -rgb -quiet -benchtime 0.01 -warmup 0 -${dct}dct $YUVARG for samp in GRAY 420 422 444; do runme cmp $OUTDIR/${basename}_${samp}_Q95.jpg $OUTDIR/${basename}_${samp}_${dct}_cjpeg.jpg done @@ -71,7 +99,7 @@ for image in $IMAGES; do fi # Tiled compression & decompression - runme $JAVA TJBench $OUTDIR/$image 95 -rgb -tile -quiet -benchtime 0.01 ${dctarg} + runme $JAVA TJBench $OUTDIR/$image 95 -rgb -tile -quiet -benchtime 0.01 -warmup 0 ${dctarg} $YUVARG for samp in GRAY 444; do for i in $OUTDIR/${basename}_${samp}_Q95_[0-9]*[0-9]x[0-9]*[0-9].bmp \ $OUTDIR/${basename}_${samp}_Q95_full.bmp; do @@ -79,7 +107,7 @@ for image in $IMAGES; do rm $i done done - runme $JAVA TJBench $OUTDIR/$image 95 -rgb -tile -quiet -benchtime 0.01 -fastupsample ${dctarg} + runme $JAVA TJBench $OUTDIR/$image 95 -rgb -tile -quiet -benchtime 0.01 -warmup 0 -fastupsample ${dctarg} $YUVARG for samp in 420 422; do for i in $OUTDIR/${basename}_${samp}_Q95_[0-9]*[0-9]x[0-9]*[0-9].bmp \ $OUTDIR/${basename}_${samp}_Q95_full.bmp; do @@ -90,7 +118,7 @@ for image in $IMAGES; do # Tiled decompression for samp in GRAY 444; do - runme $JAVA TJBench $OUTDIR/${basename}_${samp}_Q95.jpg -tile -quiet -benchtime 0.01 ${dctarg} + runme $JAVA TJBench $OUTDIR/${basename}_${samp}_Q95.jpg -tile -quiet -benchtime 0.01 -warmup 0 ${dctarg} $YUVARG for i in $OUTDIR/${basename}_${samp}_Q95_[0-9]*[0-9]x[0-9]*[0-9].bmp \ $OUTDIR/${basename}_${samp}_Q95_full.bmp; do runme cmp -i 54:54 $i $OUTDIR/${basename}_${samp}_${dct}_djpeg.bmp @@ -98,7 +126,7 @@ for image in $IMAGES; do done done for samp in 420 422; do - runme $JAVA TJBench $OUTDIR/${basename}_${samp}_Q95.jpg -tile -quiet -benchtime 0.01 -fastupsample ${dctarg} + runme $JAVA TJBench $OUTDIR/${basename}_${samp}_Q95.jpg -tile -quiet -benchtime 0.01 -warmup 0 -fastupsample ${dctarg} $YUVARG for i in $OUTDIR/${basename}_${samp}_Q95_[0-9]*[0-9]x[0-9]*[0-9].bmp \ $OUTDIR/${basename}_${samp}_Q95_full.bmp; do runme cmp $i -i 54:54 $OUTDIR/${basename}_${samp}_${dct}_nosmooth_djpeg.bmp @@ -111,8 +139,8 @@ for image in $IMAGES; do for scale in 2_1 15_8 7_4 13_8 3_2 11_8 5_4 9_8 7_8 3_4 5_8 1_2 3_8 1_4 1_8; do scalearg=`echo $scale | sed s@_@/@g` for samp in GRAY 420 422 444; do - $EXEDIR/djpeg -rgb -scale ${scalearg} -bmp $OUTDIR/${basename}_${samp}_fast_cjpeg.jpg >$OUTDIR/${basename}_${samp}_${scale}_djpeg.bmp - runme $JAVA TJBench $OUTDIR/${basename}_${samp}_Q95.jpg -scale ${scalearg} -quiet -benchtime 0.01 + runme $EXEDIR/djpeg -rgb -scale ${scalearg} $NSARG -bmp -outfile $OUTDIR/${basename}_${samp}_${scale}_djpeg.bmp $OUTDIR/${basename}_${samp}_fast_cjpeg.jpg + runme $JAVA TJBench $OUTDIR/${basename}_${samp}_Q95.jpg -scale ${scalearg} -quiet -benchtime 0.01 -warmup 0 $YUVARG runme cmp -i 54:54 $OUTDIR/${basename}_${samp}_Q95_${scale}.bmp $OUTDIR/${basename}_${samp}_${scale}_djpeg.bmp rm $OUTDIR/${basename}_${samp}_Q95_${scale}.bmp done @@ -120,18 +148,18 @@ for image in $IMAGES; do # Transforms for samp in GRAY 420 422 444; do - $EXEDIR/jpegtran -flip horizontal -trim $OUTDIR/${basename}_${samp}_Q95.jpg >$OUTDIR/${basename}_${samp}_hflip_jpegtran.jpg - $EXEDIR/jpegtran -flip vertical -trim $OUTDIR/${basename}_${samp}_Q95.jpg >$OUTDIR/${basename}_${samp}_vflip_jpegtran.jpg - $EXEDIR/jpegtran -transpose -trim $OUTDIR/${basename}_${samp}_Q95.jpg >$OUTDIR/${basename}_${samp}_transpose_jpegtran.jpg - $EXEDIR/jpegtran -transverse -trim $OUTDIR/${basename}_${samp}_Q95.jpg >$OUTDIR/${basename}_${samp}_transverse_jpegtran.jpg - $EXEDIR/jpegtran -rotate 90 -trim $OUTDIR/${basename}_${samp}_Q95.jpg >$OUTDIR/${basename}_${samp}_rot90_jpegtran.jpg - $EXEDIR/jpegtran -rotate 180 -trim $OUTDIR/${basename}_${samp}_Q95.jpg >$OUTDIR/${basename}_${samp}_rot180_jpegtran.jpg - $EXEDIR/jpegtran -rotate 270 -trim $OUTDIR/${basename}_${samp}_Q95.jpg >$OUTDIR/${basename}_${samp}_rot270_jpegtran.jpg + runme $EXEDIR/jpegtran -flip horizontal -trim -outfile $OUTDIR/${basename}_${samp}_hflip_jpegtran.jpg $OUTDIR/${basename}_${samp}_Q95.jpg + runme $EXEDIR/jpegtran -flip vertical -trim -outfile $OUTDIR/${basename}_${samp}_vflip_jpegtran.jpg $OUTDIR/${basename}_${samp}_Q95.jpg + runme $EXEDIR/jpegtran -transpose -trim -outfile $OUTDIR/${basename}_${samp}_transpose_jpegtran.jpg $OUTDIR/${basename}_${samp}_Q95.jpg + runme $EXEDIR/jpegtran -transverse -trim -outfile $OUTDIR/${basename}_${samp}_transverse_jpegtran.jpg $OUTDIR/${basename}_${samp}_Q95.jpg + runme $EXEDIR/jpegtran -rotate 90 -trim -outfile $OUTDIR/${basename}_${samp}_rot90_jpegtran.jpg $OUTDIR/${basename}_${samp}_Q95.jpg + runme $EXEDIR/jpegtran -rotate 180 -trim -outfile $OUTDIR/${basename}_${samp}_rot180_jpegtran.jpg $OUTDIR/${basename}_${samp}_Q95.jpg + runme $EXEDIR/jpegtran -rotate 270 -trim -outfile $OUTDIR/${basename}_${samp}_rot270_jpegtran.jpg $OUTDIR/${basename}_${samp}_Q95.jpg done for xform in hflip vflip transpose transverse rot90 rot180 rot270; do for samp in GRAY 444; do - $EXEDIR/djpeg -rgb -bmp $OUTDIR/${basename}_${samp}_${xform}_jpegtran.jpg >$OUTDIR/${basename}_${samp}_${xform}_jpegtran.bmp - runme $JAVA TJBench $OUTDIR/${basename}_${samp}_Q95.jpg -$xform -tile -quiet -benchtime 0.01 + runme $EXEDIR/djpeg -rgb -bmp -outfile $OUTDIR/${basename}_${samp}_${xform}_jpegtran.bmp $OUTDIR/${basename}_${samp}_${xform}_jpegtran.jpg + runme $JAVA TJBench $OUTDIR/${basename}_${samp}_Q95.jpg -$xform -tile -quiet -benchtime 0.01 -warmup 0 $YUVARG for i in $OUTDIR/${basename}_${samp}_Q95_[0-9]*[0-9]x[0-9]*[0-9].bmp \ $OUTDIR/${basename}_${samp}_Q95_full.bmp; do runme cmp -i 54:54 $i $OUTDIR/${basename}_${samp}_${xform}_jpegtran.bmp @@ -139,8 +167,8 @@ for image in $IMAGES; do done done for samp in 420 422; do - $EXEDIR/djpeg -nosmooth -rgb -bmp $OUTDIR/${basename}_${samp}_${xform}_jpegtran.jpg >$OUTDIR/${basename}_${samp}_${xform}_jpegtran.bmp - runme $JAVA TJBench $OUTDIR/${basename}_${samp}_Q95.jpg -$xform -tile -quiet -benchtime 0.01 -fastupsample + runme $EXEDIR/djpeg -nosmooth -rgb -bmp -outfile $OUTDIR/${basename}_${samp}_${xform}_jpegtran.bmp $OUTDIR/${basename}_${samp}_${xform}_jpegtran.jpg + runme $JAVA TJBench $OUTDIR/${basename}_${samp}_Q95.jpg -$xform -tile -quiet -benchtime 0.01 -warmup 0 -fastupsample $YUVARG for i in $OUTDIR/${basename}_${samp}_Q95_[0-9]*[0-9]x[0-9]*[0-9].bmp \ $OUTDIR/${basename}_${samp}_Q95_full.bmp; do runme cmp -i 54:54 $i $OUTDIR/${basename}_${samp}_${xform}_jpegtran.bmp @@ -152,7 +180,7 @@ for image in $IMAGES; do # Grayscale transform for xform in hflip vflip transpose transverse rot90 rot180 rot270; do for samp in GRAY 444 422 420; do - runme $JAVA TJBench $OUTDIR/${basename}_${samp}_Q95.jpg -$xform -tile -quiet -benchtime 0.01 -grayscale + runme $JAVA TJBench $OUTDIR/${basename}_${samp}_Q95.jpg -$xform -tile -quiet -benchtime 0.01 -warmup 0 -grayscale $YUVARG for i in $OUTDIR/${basename}_${samp}_Q95_[0-9]*[0-9]x[0-9]*[0-9].bmp \ $OUTDIR/${basename}_${samp}_Q95_full.bmp; do runme cmp -i 54:54 $i $OUTDIR/${basename}_GRAY_${xform}_jpegtran.bmp @@ -166,8 +194,8 @@ for image in $IMAGES; do for samp in GRAY 444 422 420; do for scale in 2_1 15_8 7_4 13_8 3_2 11_8 5_4 9_8 7_8 3_4 5_8 1_2 3_8 1_4 1_8; do scalearg=`echo $scale | sed s@_@/@g` - $EXEDIR/djpeg -rgb -scale ${scalearg} -bmp $OUTDIR/${basename}_${samp}_${xform}_jpegtran.jpg >$OUTDIR/${basename}_${samp}_${xform}_${scale}_jpegtran.bmp - runme $JAVA TJBench $OUTDIR/${basename}_${samp}_Q95.jpg -$xform -scale ${scalearg} -quiet -benchtime 0.01 + runme $EXEDIR/djpeg -rgb -scale ${scalearg} $NSARG -bmp -outfile $OUTDIR/${basename}_${samp}_${xform}_${scale}_jpegtran.bmp $OUTDIR/${basename}_${samp}_${xform}_jpegtran.jpg + runme $JAVA TJBench $OUTDIR/${basename}_${samp}_Q95.jpg -$xform -scale ${scalearg} -quiet -benchtime 0.01 -warmup 0 $YUVARG runme cmp -i 54:54 $OUTDIR/${basename}_${samp}_Q95_${scale}.bmp $OUTDIR/${basename}_${samp}_${xform}_${scale}_jpegtran.bmp rm $OUTDIR/${basename}_${samp}_Q95_${scale}.bmp done diff --git a/tjunittest.c b/tjunittest.c index 519686fc..dc84bbaa 100644 --- a/tjunittest.c +++ b/tjunittest.c @@ -1,5 +1,5 @@ /* - * Copyright (C)2009-2013 D. R. Commander. All Rights Reserved. + * Copyright (C)2009-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: @@ -79,8 +79,7 @@ const int _4byteFormats[]={TJPF_RGBX, TJPF_BGRX, TJPF_XBGR, TJPF_XRGB, const int _onlyGray[]={TJPF_GRAY}; const int _onlyRGB[]={TJPF_RGB}; -enum {YUVENCODE=1, YUVDECODE}; -int yuv=0, alloc=0, pad=4; +int doyuv=0, alloc=0, pad=4; int exitStatus=0; #define bailout() {exitStatus=-1; goto bailout;} @@ -295,60 +294,6 @@ int checkBuf(unsigned char *buf, int w, int h, int pf, int subsamp, #define PAD(v, p) ((v+(p)-1)&(~((p)-1))) -void initBufYUV(unsigned char *buf, int w, int pad, int h, int subsamp) -{ - int row, col; - int hsf=tjMCUWidth[subsamp]/8, vsf=tjMCUHeight[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; - - memset(buf, 0, tjBufSizeYUV2(w, pad, h, subsamp)); - - for(row=0; row JPEG Q%d ... ", subNameLong[subsamp], buStrLong, - jpegQual); - if((srcBuf=(unsigned char *)malloc(tjBufSizeYUV2(w, pad, h, subsamp))) - ==NULL) - _throw("Memory allocation failure"); - initBufYUV(srcBuf, w, pad, h, subsamp); - } - else - { - if(yuv==YUVENCODE) - printf("%s %s -> %s YUV ... ", pfStr, buStrLong, subNameLong[subsamp]); - else - printf("%s %s -> %s Q%d ... ", pfStr, buStrLong, subNameLong[subsamp], - jpegQual); - if((srcBuf=(unsigned char *)malloc(w*h*tjPixelSize[pf]))==NULL) - _throw("Memory allocation failure"); - initBuf(srcBuf, w, h, pf, flags); - } + if((srcBuf=(unsigned char *)malloc(w*h*tjPixelSize[pf]))==NULL) + _throw("Memory allocation failure"); + initBuf(srcBuf, w, h, pf, flags); if(*dstBuf && *dstSize>0) memset(*dstBuf, 0, *dstSize); - t=gettime(); - if(yuv==YUVENCODE) - { - _tj(tjEncodeYUV3(handle, srcBuf, w, 0, h, pf, *dstBuf, pad, subsamp, - flags)); - } - else - { - if(!alloc) flags|=TJFLAG_NOREALLOC; - if(yuv==YUVDECODE) - { - _tj(tjCompressFromYUV(handle, srcBuf, w, pad, h, subsamp, dstBuf, - dstSize, jpegQual, flags)); - } - else - { - _tj(tjCompress2(handle, srcBuf, w, 0, h, pf, dstBuf, dstSize, subsamp, - jpegQual, flags)); - } - } - t=gettime()-t; - if(yuv==YUVENCODE) - snprintf(tempStr, 1024, "%s_enc_%s_%s_%s.yuv", basename, pfStr, buStr, - subName[subsamp]); - else - snprintf(tempStr, 1024, "%s_enc_%s_%s_%s_Q%d.jpg", basename, pfStr, buStr, - subName[subsamp], jpegQual); - writeJPEG(*dstBuf, *dstSize, tempStr); - if(yuv==YUVENCODE) + if(!alloc) flags|=TJFLAG_NOREALLOC; + if(doyuv) { + unsigned long yuvSize=tjBufSizeYUV2(w, pad, h, subsamp); tjscalingfactor sf={1, 1}; - if(checkBufYUV(*dstBuf, w, h, subsamp, sf)) printf("Passed."); - else printf("FAILED!"); + tjhandle handle2=tjInitCompress(); + if(!handle2) _throwtj(); + + if((yuvBuf=(unsigned char *)malloc(yuvSize))==NULL) + _throw("Memory allocation failure"); + memset(yuvBuf, 0, yuvSize); + + printf("%s %s -> YUV %s ... ", pfStr, buStrLong, subNameLong[subsamp]); + _tj(tjEncodeYUV3(handle2, srcBuf, w, 0, h, pf, yuvBuf, pad, subsamp, + flags)); + tjDestroy(handle2); + if(checkBufYUV(yuvBuf, w, h, subsamp, sf)) printf("Passed.\n"); + else printf("FAILED!\n"); + + printf("YUV %s %s -> JPEG Q%d ... ", subNameLong[subsamp], buStrLong, + jpegQual); + _tj(tjCompressFromYUV(handle, yuvBuf, w, pad, h, subsamp, dstBuf, + dstSize, jpegQual, flags)); } - else printf("Done."); - printf(" %f ms\n Result in %s\n", t*1000., tempStr); + else + { + printf("%s %s -> %s Q%d ... ", pfStr, buStrLong, subNameLong[subsamp], + jpegQual); + _tj(tjCompress2(handle, srcBuf, w, 0, h, pf, dstBuf, dstSize, subsamp, + jpegQual, flags)); + } + + snprintf(tempStr, 1024, "%s_enc_%s_%s_%s_Q%d.jpg", basename, pfStr, buStr, + subName[subsamp], jpegQual); + writeJPEG(*dstBuf, *dstSize, tempStr); + printf("Done.\n Result in %s\n", tempStr); bailout: + if(yuvBuf) free(yuvBuf); if(srcBuf) free(srcBuf); } @@ -527,63 +455,67 @@ void _decompTest(tjhandle handle, unsigned char *jpegBuf, unsigned long jpegSize, int w, int h, int pf, char *basename, int subsamp, int flags, tjscalingfactor sf) { - unsigned char *dstBuf=NULL; - int _hdrw=0, _hdrh=0, _hdrsubsamp=-1; double t; + unsigned char *dstBuf=NULL, *yuvBuf=NULL; + int _hdrw=0, _hdrh=0, _hdrsubsamp=-1; int scaledWidth=TJSCALED(w, sf); int scaledHeight=TJSCALED(h, sf); unsigned long dstSize=0; - if(yuv==YUVENCODE) return; - - if(yuv==YUVDECODE) - printf("JPEG -> YUV %s ", subNameLong[subsamp]); - else - printf("JPEG -> %s %s ", pixFormatStr[pf], - (flags&TJFLAG_BOTTOMUP)? "Bottom-Up":"Top-Down "); - if(sf.num!=1 || sf.denom!=1) - printf("%d/%d ... ", sf.num, sf.denom); - else printf("... "); - _tj(tjDecompressHeader2(handle, jpegBuf, jpegSize, &_hdrw, &_hdrh, &_hdrsubsamp)); if(_hdrw!=w || _hdrh!=h || _hdrsubsamp!=subsamp) _throw("Incorrect JPEG header"); - if(yuv==YUVDECODE) - dstSize=tjBufSizeYUV2(scaledWidth, pad, scaledHeight, subsamp); - else dstSize=scaledWidth*scaledHeight*tjPixelSize[pf]; + dstSize=scaledWidth*scaledHeight*tjPixelSize[pf]; if((dstBuf=(unsigned char *)malloc(dstSize))==NULL) _throw("Memory allocation failure"); memset(dstBuf, 0, dstSize); - t=gettime(); - if(yuv==YUVDECODE) + if(doyuv) { - _tj(tjDecompressToYUV2(handle, jpegBuf, jpegSize, dstBuf, scaledWidth, + unsigned long yuvSize=tjBufSizeYUV2(scaledWidth, pad, scaledHeight, + subsamp); + tjhandle handle2=tjInitDecompress(); + if(!handle2) _throwtj(); + + if((yuvBuf=(unsigned char *)malloc(yuvSize))==NULL) + _throw("Memory allocation failure"); + memset(yuvBuf, 0, yuvSize); + + printf("JPEG -> YUV %s ", subNameLong[subsamp]); + if(sf.num!=1 || sf.denom!=1) + printf("%d/%d ... ", sf.num, sf.denom); + else printf("... "); + _tj(tjDecompressToYUV2(handle, jpegBuf, jpegSize, yuvBuf, scaledWidth, pad, scaledHeight, flags)); + if(checkBufYUV(yuvBuf, scaledWidth, scaledHeight, subsamp, sf)) + printf("Passed.\n"); + else printf("FAILED!\n"); + + printf("YUV %s -> %s %s ... ", subNameLong[subsamp], pixFormatStr[pf], + (flags&TJFLAG_BOTTOMUP)? "Bottom-Up":"Top-Down "); + _tj(tjDecodeYUV(handle2, yuvBuf, pad, subsamp, dstBuf, scaledWidth, 0, + scaledHeight, pf, flags)); + tjDestroy(handle2); } else { + printf("JPEG -> %s %s ", pixFormatStr[pf], + (flags&TJFLAG_BOTTOMUP)? "Bottom-Up":"Top-Down "); + if(sf.num!=1 || sf.denom!=1) + printf("%d/%d ... ", sf.num, sf.denom); + else printf("... "); _tj(tjDecompress2(handle, jpegBuf, jpegSize, dstBuf, scaledWidth, 0, scaledHeight, pf, flags)); } - t=gettime()-t; - if(yuv==YUVDECODE) - { - if(checkBufYUV(dstBuf, scaledWidth, scaledHeight, subsamp, sf)) - printf("Passed."); - else printf("FAILED!"); - } - else - { - if(checkBuf(dstBuf, scaledWidth, scaledHeight, pf, subsamp, sf, flags)) - printf("Passed."); - else printf("FAILED!"); - } - printf(" %f ms\n", t*1000.); + if(checkBuf(dstBuf, scaledWidth, scaledHeight, pf, subsamp, sf, flags)) + printf("Passed."); + else printf("FAILED!"); + printf("\n"); bailout: + if(yuvBuf) free(yuvBuf); if(dstBuf) free(dstBuf); } @@ -619,9 +551,7 @@ void doTest(int w, int h, const int *formats, int nformats, int subsamp, unsigned char *dstBuf=NULL; unsigned long size=0; int pfi, pf, i; - if(yuv==YUVENCODE) - size=tjBufSizeYUV2(w, pad, h, subsamp); - else if(!alloc) + if(!alloc) size=tjBufSize(w, h, subsamp); if(size!=0) if((dstBuf=(unsigned char *)tjAlloc(size))==NULL) @@ -638,19 +568,18 @@ void doTest(int w, int h, const int *formats, int nformats, int subsamp, if(subsamp==TJSAMP_422 || subsamp==TJSAMP_420 || subsamp==TJSAMP_440 || subsamp==TJSAMP_411) flags|=TJFLAG_FASTUPSAMPLE; - if(i==1) - { - if(yuv==YUVDECODE) goto bailout; - else flags|=TJFLAG_BOTTOMUP; - } + if(i==1) flags|=TJFLAG_BOTTOMUP; pf=formats[pfi]; compTest(chandle, &dstBuf, &size, w, h, pf, basename, subsamp, 100, flags); decompTest(dhandle, dstBuf, size, w, h, pf, basename, subsamp, flags); if(pf>=TJPF_RGBX && pf<=TJPF_XRGB) + { + printf("\n"); decompTest(dhandle, dstBuf, size, w, h, pf+(TJPF_RGBA-TJPF_RGBX), basename, subsamp, flags); + } printf("\n"); } } @@ -667,9 +596,9 @@ void doTest(int w, int h, const int *formats, int nformats, int subsamp, void bufSizeTest(void) { int w, h, i, subsamp; - unsigned char *srcBuf=NULL, *jpegBuf=NULL; + unsigned char *srcBuf=NULL, *dstBuf=NULL; tjhandle handle=NULL; - unsigned long jpegSize=0; + unsigned long dstSize=0; if((handle=tjInitCompress())==NULL) _throwtj(); @@ -684,12 +613,12 @@ void bufSizeTest(void) if(h%100==0) printf("%.4d x %.4d\b\b\b\b\b\b\b\b\b\b\b", w, h); if((srcBuf=(unsigned char *)malloc(w*h*4))==NULL) _throw("Memory allocation failure"); - if(!alloc) + if(!alloc || doyuv) { - if((jpegBuf=(unsigned char *)tjAlloc(tjBufSize(w, h, subsamp))) - ==NULL) + if(doyuv) dstSize=tjBufSizeYUV2(w, pad, h, subsamp); + else dstSize=tjBufSize(w, h, subsamp); + if((dstBuf=(unsigned char *)tjAlloc(dstSize))==NULL) _throw("Memory allocation failure"); - jpegSize=tjBufSize(w, h, subsamp); } for(i=0; iGetArrayLength(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 b/turbojpeg-mapfile index d8cf41c3..7d174ca8 100755 --- a/turbojpeg-mapfile +++ b/turbojpeg-mapfile @@ -42,6 +42,7 @@ TURBOJPEG_1.4 global: tjBufSizeYUV2; tjCompressFromYUV; + tjDecodeYUV; tjDecompressHeader3; tjDecompressToYUV2; tjEncodeYUV3; diff --git a/turbojpeg-mapfile.jni b/turbojpeg-mapfile.jni index f90f9434..283e01f8 100755 --- a/turbojpeg-mapfile.jni +++ b/turbojpeg-mapfile.jni @@ -68,12 +68,15 @@ TURBOJPEG_1.4 global: tjBufSizeYUV2; tjCompressFromYUV; + tjDecodeYUV; tjDecompressHeader3; tjDecompressToYUV2; 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; diff --git a/turbojpeg.c b/turbojpeg.c index 694e558e..acb12090 100644 --- a/turbojpeg.c +++ b/turbojpeg.c @@ -1,5 +1,5 @@ /* - * Copyright (C)2009-2013 D. R. Commander. All Rights Reserved. + * Copyright (C)2009-2014 D. R. Commander. All Rights Reserved. * mozjpeg Modifications: * Copyright (C) 2014, Mozilla Corporation. * @@ -548,9 +548,9 @@ DLLEXPORT unsigned long DLLCALL tjBufSize(int width, int height, if(width<1 || height<1 || jpegSubsamp<0 || jpegSubsamp>=NUMSUBOPT) _throw("tjBufSize(): Invalid argument"); - // This allows for rare corner cases in which a JPEG image can actually be - // larger than the uncompressed input (we wouldn't mention it if it hadn't - // happened before.) + /* This allows for rare corner cases in which a JPEG image can actually be + larger than the uncompressed input (we wouldn't mention it if it hadn't + happened before.) */ mcuw=tjMCUWidth[jpegSubsamp]; mcuh=tjMCUHeight[jpegSubsamp]; chromasf=jpegSubsamp==TJSAMP_GRAY? 0: 4*64/(mcuw*mcuh); @@ -566,9 +566,9 @@ DLLEXPORT unsigned long DLLCALL TJBUFSIZE(int width, int height) if(width<1 || height<1) _throw("TJBUFSIZE(): Invalid argument"); - // This allows for rare corner cases in which a JPEG image can actually be - // larger than the uncompressed input (we wouldn't mention it if it hadn't - // happened before.) + /* This allows for rare corner cases in which a JPEG image can actually be + larger than the uncompressed input (we wouldn't mention it if it hadn't + happened before.) */ retval=PAD(width, 16) * PAD(height, 16) * 6 + 2048; bailout: @@ -766,10 +766,20 @@ DLLEXPORT int DLLCALL tjEncodeYUV3(tjhandle handle, unsigned char *srcBuf, else if(flags&TJFLAG_FORCESSE2) putenv("JSIMD_FORCESSE2=1"); yuvsize=tjBufSizeYUV2(width, pad, height, subsamp); - jpeg_mem_dest_tj(cinfo, &dstBuf, &yuvsize, 0); if(setCompDefaults(cinfo, pixelFormat, subsamp, -1, flags)==-1) return -1; - jpeg_start_compress(cinfo, TRUE); + /* Execute only the parts of jpeg_start_compress() that we need. If we + were to call the whole jpeg_start_compress() function, then it would try + to write the file headers, which could overflow the output buffer if the + YUV image were very small. */ + if(cinfo->global_state!=CSTATE_START) + _throw("tjEncodeYUV3(): libjpeg API is in the wrong state"); + (*cinfo->err->reset_error_mgr)((j_common_ptr)cinfo); + jinit_c_master_control(cinfo, FALSE); + jinit_color_converter(cinfo); + jinit_downsampler(cinfo); + (*cinfo->cconvert->start_pass)(cinfo); + pw=PAD(width, cinfo->max_h_samp_factor); ph=PAD(height, cinfo->max_v_samp_factor); @@ -973,10 +983,10 @@ DLLEXPORT int DLLCALL tjCompressFromYUV(tjhandle handle, unsigned char *srcBuf, for(j=0; jscale_num=dinfo->scale_denom=1; + + if(subsamp==TJSAMP_GRAY) + { + dinfo->num_components=dinfo->comps_in_scan=1; + dinfo->jpeg_color_space=JCS_GRAYSCALE; + } + else + { + dinfo->num_components=dinfo->comps_in_scan=3; + dinfo->jpeg_color_space=JCS_YCbCr; + } + + dinfo->comp_info=(jpeg_component_info *) + (*dinfo->mem->alloc_small)((j_common_ptr)dinfo, JPOOL_IMAGE, + dinfo->num_components*SIZEOF(jpeg_component_info)); + + for(i=0; inum_components; i++) + { + jpeg_component_info *compptr=&dinfo->comp_info[i]; + compptr->h_samp_factor=(i==0)? tjMCUWidth[subsamp]/8:1; + compptr->v_samp_factor=(i==0)? tjMCUHeight[subsamp]/8:1; + compptr->component_index=i; + compptr->component_id=i+1; + compptr->quant_tbl_no=compptr->dc_tbl_no=compptr->ac_tbl_no= + (i==0)? 0:1; + dinfo->cur_comp_info[i]=compptr; + } + dinfo->data_precision=8; + for(i=0; i<2; i++) + { + if(dinfo->quant_tbl_ptrs[i]==NULL) + dinfo->quant_tbl_ptrs[i]=jpeg_alloc_quant_table((j_common_ptr)dinfo); + } + + return 0; +} + + +int my_read_markers(j_decompress_ptr dinfo) +{ + return JPEG_REACHED_SOS; +} + +void my_reset_marker_reader(j_decompress_ptr dinfo) +{ +} + +DLLEXPORT int DLLCALL tjDecodeYUV(tjhandle handle, unsigned char *srcBuf, + int pad, int subsamp, unsigned char *dstBuf, int width, int pitch, + int height, int pixelFormat, int flags) +{ + int i, retval=0; JSAMPROW *row_pointer=NULL; + JSAMPLE *_tmpbuf[MAX_COMPONENTS]; + JSAMPROW *tmpbuf[MAX_COMPONENTS], *inbuf[MAX_COMPONENTS]; + int row, pw, ph, cw[MAX_COMPONENTS], ch[MAX_COMPONENTS]; + JSAMPLE *ptr=srcBuf; + unsigned long yuvsize=0; + jpeg_component_info *compptr; + #ifndef JCS_EXTENSIONS + unsigned char *rgbBuf=NULL; + #endif + JMETHOD(int, old_read_markers, (j_decompress_ptr)); + JMETHOD(void, old_reset_marker_reader, (j_decompress_ptr)); + + getinstance(handle); + + for(i=0; iinit&DECOMPRESS)==0) + _throw("tjDecodeYUV(): Instance has not been initialized for compression"); + + if(srcBuf==NULL || pad<0 || !isPow2(pad) || subsamp<0 || subsamp>=NUMSUBOPT + || dstBuf==NULL || width<=0 || pitch<0 || height<=0 || pixelFormat<0 + || pixelFormat>=TJ_NUMPF) + _throw("tjDecodeYUV(): Invalid argument"); + + if(setjmp(this->jerr.setjmp_buffer)) + { + /* If we get here, the JPEG code has signaled an error. */ + retval=-1; + goto bailout; + } + + if(pixelFormat==TJPF_CMYK) + _throw("tjDecodeYUV(): Cannot decode YUV images into CMYK pixels."); + + if(pitch==0) pitch=width*tjPixelSize[pixelFormat]; + + #ifndef JCS_EXTENSIONS + if(pixelFormat!=TJPF_GRAY) + { + rgbBuf=(unsigned char *)malloc(width*height*RGB_PIXELSIZE); + if(!rgbBuf) _throw("tjDecodeYUV(): Memory allocation failure"); + srcBuf=toRGB(srcBuf, width, pitch, height, pixelFormat, rgbBuf); + pitch=width*RGB_PIXELSIZE; + } + #endif + + dinfo->image_width=width; + dinfo->image_height=height; + + if(flags&TJFLAG_FORCEMMX) putenv("JSIMD_FORCEMMX=1"); + else if(flags&TJFLAG_FORCESSE) putenv("JSIMD_FORCESSE=1"); + else if(flags&TJFLAG_FORCESSE2) putenv("JSIMD_FORCESSE2=1"); + + yuvsize=tjBufSizeYUV2(width, pad, height, subsamp); + if(setDecodeDefaults(dinfo, pixelFormat, subsamp, flags)==-1) + { + retval=-1; goto bailout; + } + old_read_markers=dinfo->marker->read_markers; + dinfo->marker->read_markers=my_read_markers; + old_reset_marker_reader=dinfo->marker->reset_marker_reader; + dinfo->marker->reset_marker_reader=my_reset_marker_reader; + jpeg_read_header(dinfo, TRUE); + dinfo->marker->read_markers=old_read_markers; + dinfo->marker->reset_marker_reader=old_reset_marker_reader; + + if(setDecompDefaults(dinfo, pixelFormat, flags)==-1) + { + retval=-1; goto bailout; + } + dinfo->do_fancy_upsampling=FALSE; + jinit_master_decompress(dinfo); + (*dinfo->upsample->start_pass)(dinfo); + + pw=PAD(width, dinfo->max_h_samp_factor); + ph=PAD(height, dinfo->max_v_samp_factor); + + if(pitch==0) pitch=dinfo->output_width*tjPixelSize[pixelFormat]; + + if((row_pointer=(JSAMPROW *)malloc(sizeof(JSAMPROW)*ph))==NULL) + _throw("tjDecodeYUV(): Memory allocation failure"); + for(i=0; inum_components; i++) + { + compptr=&dinfo->comp_info[i]; + _tmpbuf[i]=(JSAMPLE *)malloc(PAD(compptr->width_in_blocks*DCTSIZE, 16) + * compptr->v_samp_factor + 16); + if(!_tmpbuf[i]) _throw("tjDecodeYUV(): Memory allocation failure"); + tmpbuf[i]=(JSAMPROW *)malloc(sizeof(JSAMPROW)*compptr->v_samp_factor); + if(!tmpbuf[i]) _throw("tjDecodeYUV(): Memory allocation failure"); + for(row=0; rowv_samp_factor; row++) + { + unsigned char *_tmpbuf_aligned= + (unsigned char *)PAD((size_t)_tmpbuf[i], 16); + tmpbuf[i][row]=&_tmpbuf_aligned[ + PAD(compptr->width_in_blocks*DCTSIZE, 16) * row]; + } + cw[i]=pw*compptr->h_samp_factor/dinfo->max_h_samp_factor; + ch[i]=ph*compptr->v_samp_factor/dinfo->max_v_samp_factor; + inbuf[i]=(JSAMPROW *)malloc(sizeof(JSAMPROW)*ch[i]); + if(!inbuf[i]) _throw("tjDecodeYUV(): Memory allocation failure"); + for(row=0; rowmax_v_samp_factor) + { + JDIMENSION inrow=0, outrow=0; + for(i=0, compptr=dinfo->comp_info; inum_components; i++, compptr++) + jcopy_sample_rows(inbuf[i], + row*compptr->v_samp_factor/dinfo->max_v_samp_factor, tmpbuf[i], 0, + compptr->v_samp_factor, cw[i]); + (dinfo->upsample->upsample)(dinfo, tmpbuf, &inrow, + dinfo->max_v_samp_factor, &row_pointer[row], &outrow, + dinfo->max_v_samp_factor); + } + jpeg_abort_decompress(dinfo); + + bailout: + if(dinfo->global_state>DSTATE_START) jpeg_abort_decompress(dinfo); + #ifndef JCS_EXTENSIONS + if(rgbBuf) free(rgbBuf); + #endif + if(row_pointer) free(row_pointer); + for(i=0; i + * 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 handle a handle to a TurboJPEG decompressor or transformer instance + * @param srcBuf pointer to an image buffer containing a YUV planar image to be + * decoded. The size of this buffer should match the value returned + * by #tjBufSizeYUV2() for the given image width, height, padding, and + * level of chrominance subsampling. + * @param pad Use this parameter to specify that the width of each line in each + * plane of the YUV source image is padded to the nearest multiple of + * this number of bytes (must be a power of 2.) + * @param subsamp the level of chrominance subsampling used in the YUV source + * image (see @ref TJSAMP "Chrominance subsampling options".) + * @param dstBuf pointer to an image buffer that will receive the decoded + * image. This buffer should normally be pitch * height + * bytes in size, but the dstBuf pointer can also be used to + * decode into a specific region of a larger buffer. + * @param width width (in pixels) of the source and destination images + * @param pitch bytes per line of the destination image. Normally, this should + * be width * #tjPixelSize[pixelFormat] if the destination + * image is unpadded, or #TJPAD(width * + * #tjPixelSize[pixelFormat]) if each line of the destination + * image should be padded to the nearest 32-bit boundary, as is the case + * for Windows bitmaps. You can also be clever and use the pitch + * parameter to skip lines, etc. Setting this parameter to 0 is the + * equivalent of setting it to width * + * #tjPixelSize[pixelFormat]. + * @param height height (in pixels) of the source and destination images + * @param pixelFormat pixel format of the destination image (see @ref TJPF + * "Pixel formats".) + * @param flags the bitwise OR of one or more of the @ref TJFLAG_BOTTOMUP + * "flags". + * + * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr().) + */ +DLLEXPORT int DLLCALL tjDecodeYUV(tjhandle handle, unsigned char *srcBuf, + int pad, int subsamp, unsigned char *dstBuf, int width, int pitch, + int height, int pixelFormat, int flags); + + /** * Create a new TurboJPEG transformer instance. *