Christian Heimes avatar Christian Heimes committed 737bc48 Draft

Added rest of libjpeg-turbo

Comments (0)

Files changed (57)

Source/LibJPEGTurbo/java/CMakeLists.txt

+set(JAR_FILE turbojpeg.jar)
+set(MANIFEST_FILE ${CMAKE_CURRENT_SOURCE_DIR}/MANIFEST.MF)
+
+set(JAVA_CLASSNAMES org/libjpegturbo/turbojpeg/TJ
+  org/libjpegturbo/turbojpeg/TJCompressor
+  org/libjpegturbo/turbojpeg/TJCustomFilter
+  org/libjpegturbo/turbojpeg/TJDecompressor
+  org/libjpegturbo/turbojpeg/TJScalingFactor
+  org/libjpegturbo/turbojpeg/TJTransform
+  org/libjpegturbo/turbojpeg/TJTransformer
+  TJUnitTest
+  TJExample)
+
+if(MSVC_IDE)
+  set(OBJDIR "${CMAKE_CURRENT_BINARY_DIR}/$(OutDir)")
+else()
+  set(OBJDIR ${CMAKE_CURRENT_BINARY_DIR})
+endif()
+
+set(TURBOJPEG_DLL_NAME "turbojpeg")
+if(MINGW)
+  set(TURBOJPEG_DLL_NAME "libturbojpeg")
+endif()
+configure_file(org/libjpegturbo/turbojpeg/TJLoader.java.in
+  ${CMAKE_CURRENT_BINARY_DIR}/org/libjpegturbo/turbojpeg/TJLoader.java)
+
+set(JAVA_SOURCES "")
+set(JAVA_CLASSES "")
+set(JAVA_CLASSES_FULL "")
+foreach(class ${JAVA_CLASSNAMES})
+  set(JAVA_SOURCES ${JAVA_SOURCES} ${CMAKE_CURRENT_SOURCE_DIR}/${class}.java)
+  set(JAVA_CLASSES ${JAVA_CLASSES} ${class}.class)
+  set(JAVA_CLASSES_FULL ${JAVA_CLASSES_FULL} ${OBJDIR}/${class}.class)
+endforeach()
+
+set(JAVA_SOURCES ${JAVA_SOURCES}
+  ${CMAKE_CURRENT_BINARY_DIR}/org/libjpegturbo/turbojpeg/TJLoader.java)
+set(JAVA_CLASSES ${JAVA_CLASSES}
+  org/libjpegturbo/turbojpeg/TJLoader.class)
+set(JAVA_CLASSES_FULL ${JAVA_CLASSES_FULL}
+  ${OBJDIR}/org/libjpegturbo/turbojpeg/TJLoader.class)
+
+string(REGEX REPLACE " " ";" JAVACFLAGS "${JAVACFLAGS}")
+add_custom_command(OUTPUT ${JAVA_CLASSES_FULL} DEPENDS ${JAVA_SOURCES}
+  COMMAND ${JAVA_COMPILE} ARGS ${JAVACFLAGS} -d ${OBJDIR} ${JAVA_SOURCES})
+
+add_custom_command(OUTPUT ${JAR_FILE} DEPENDS ${JAVA_CLASSES_FULL}
+  ${MANIFEST_FILE}
+  COMMAND ${JAVA_ARCHIVE} cfm ${JAR_FILE} ${MANIFEST_FILE} ${JAVA_CLASSES}
+  WORKING_DIRECTORY ${OBJDIR})
+
+add_custom_target(java ALL DEPENDS ${JAR_FILE})
+
+install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${JAR_FILE} DESTINATION classes)

Source/LibJPEGTurbo/java/MANIFEST.MF

+Manifest-Version: 1.0
+Main-Class: TJExample

Source/LibJPEGTurbo/java/Makefile.am

+JAVAROOT = .
+
+JAVASOURCES = org/libjpegturbo/turbojpeg/TJ.java \
+	org/libjpegturbo/turbojpeg/TJCompressor.java \
+	org/libjpegturbo/turbojpeg/TJCustomFilter.java \
+	org/libjpegturbo/turbojpeg/TJDecompressor.java \
+	org/libjpegturbo/turbojpeg/TJLoader.java \
+	org/libjpegturbo/turbojpeg/TJScalingFactor.java \
+	org/libjpegturbo/turbojpeg/TJTransform.java \
+	org/libjpegturbo/turbojpeg/TJTransformer.java \
+	TJExample.java \
+	TJUnitTest.java
+
+JNIHEADERS = org_libjpegturbo_turbojpeg_TJ.h \
+	org_libjpegturbo_turbojpeg_TJCompressor.h \
+	org_libjpegturbo_turbojpeg_TJDecompressor.h \
+	org_libjpegturbo_turbojpeg_TJTransformer.h
+
+if WITH_JAVA
+
+dist_noinst_JAVA = ${JAVASOURCES}
+
+JAVA_CLASSES = org/libjpegturbo/turbojpeg/TJ.class \
+	org/libjpegturbo/turbojpeg/TJCompressor.class \
+	org/libjpegturbo/turbojpeg/TJCustomFilter.class \
+	org/libjpegturbo/turbojpeg/TJDecompressor.class \
+	org/libjpegturbo/turbojpeg/TJLoader.class \
+	org/libjpegturbo/turbojpeg/TJScalingFactor.class \
+	org/libjpegturbo/turbojpeg/TJTransform.class \
+	org/libjpegturbo/turbojpeg/TJTransformer.class \
+	TJExample.class \
+	TJUnitTest.class
+
+all: all-am turbojpeg.jar
+
+turbojpeg.jar: $(JAVA_CLASSES) ${srcdir}/MANIFEST.MF
+	$(JAR) cfm turbojpeg.jar ${srcdir}/MANIFEST.MF $(JAVA_CLASSES)
+
+clean-local:
+	rm -f turbojpeg.jar
+
+install-exec-local: turbojpeg.jar
+	mkdir -p $(DESTDIR)/$(prefix)/classes
+	$(INSTALL) -m 644 turbojpeg.jar $(DESTDIR)/$(prefix)/classes/
+
+uninstall-local:
+	rm -f $(DESTDIR)/$(prefix)/classes/turbojpeg.jar
+	if [ -d $(DESTDIR)/$(prefix)/classes ]; then rmdir $(DESTDIR)/$(prefix)/classes; fi
+
+headers: all
+	javah -d ${srcdir} org.libjpegturbo.turbojpeg.TJ; \
+	javah -d ${srcdir} org.libjpegturbo.turbojpeg.TJCompressor; \
+	javah -d ${srcdir} org.libjpegturbo.turbojpeg.TJDecompressor; \
+	javah -d ${srcdir} org.libjpegturbo.turbojpeg.TJTransformer
+
+docs: all
+	mkdir -p ${srcdir}/doc; \
+	javadoc -d ${srcdir}/doc -sourcepath ${srcdir} org.libjpegturbo.turbojpeg
+
+endif
+
+EXTRA_DIST = MANIFEST.MF ${JAVASOURCES} ${JNIHEADERS} doc CMakeLists.txt \
+	org/libjpegturbo/turbojpeg/TJLoader.java.in

Source/LibJPEGTurbo/java/Makefile.in

+# Makefile.in generated by automake 1.9.2 from Makefile.am.
+# @configure_input@
+
+# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
+# 2003, 2004  Free Software Foundation, Inc.
+# This Makefile.in is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
+# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE.
+
+@SET_MAKE@
+srcdir = @srcdir@
+top_srcdir = @top_srcdir@
+VPATH = @srcdir@
+pkgdatadir = $(datadir)/@PACKAGE@
+pkglibdir = $(libdir)/@PACKAGE@
+pkgincludedir = $(includedir)/@PACKAGE@
+top_builddir = ..
+am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
+INSTALL = @INSTALL@
+install_sh_DATA = $(install_sh) -c -m 644
+install_sh_PROGRAM = $(install_sh) -c
+install_sh_SCRIPT = $(install_sh) -c
+INSTALL_HEADER = $(INSTALL_DATA)
+transform = $(program_transform_name)
+NORMAL_INSTALL = :
+PRE_INSTALL = :
+POST_INSTALL = :
+NORMAL_UNINSTALL = :
+PRE_UNINSTALL = :
+POST_UNINSTALL = :
+build_triplet = @build@
+host_triplet = @host@
+subdir = java
+DIST_COMMON = README $(am__dist_noinst_JAVA_DIST) \
+	$(srcdir)/Makefile.am $(srcdir)/Makefile.in
+ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
+am__aclocal_m4_deps = $(top_srcdir)/acinclude.m4 \
+	$(top_srcdir)/configure.ac
+am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
+	$(ACLOCAL_M4)
+mkinstalldirs = $(install_sh) -d
+CONFIG_HEADER = $(top_builddir)/config.h $(top_builddir)/jconfig.h
+CONFIG_CLEAN_FILES =
+SOURCES =
+DIST_SOURCES =
+am__dist_noinst_JAVA_DIST = org/libjpegturbo/turbojpeg/TJ.java \
+	org/libjpegturbo/turbojpeg/TJCompressor.java \
+	org/libjpegturbo/turbojpeg/TJCustomFilter.java \
+	org/libjpegturbo/turbojpeg/TJDecompressor.java \
+	org/libjpegturbo/turbojpeg/TJLoader.java \
+	org/libjpegturbo/turbojpeg/TJScalingFactor.java \
+	org/libjpegturbo/turbojpeg/TJTransform.java \
+	org/libjpegturbo/turbojpeg/TJTransformer.java TJExample.java \
+	TJUnitTest.java
+CLASSPATH_ENV = CLASSPATH=$(JAVAROOT):$(srcdir)/$(JAVAROOT):$$CLASSPATH
+DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
+ACLOCAL = @ACLOCAL@
+AMDEP_FALSE = @AMDEP_FALSE@
+AMDEP_TRUE = @AMDEP_TRUE@
+AMTAR = @AMTAR@
+AR = @AR@
+AUTOCONF = @AUTOCONF@
+AUTOHEADER = @AUTOHEADER@
+AUTOMAKE = @AUTOMAKE@
+AWK = @AWK@
+BUILD = @BUILD@
+CC = @CC@
+CCAS = @CCAS@
+CCASFLAGS = @CCASFLAGS@
+CCDEPMODE = @CCDEPMODE@
+CFLAGS = @CFLAGS@
+CPP = @CPP@
+CPPFLAGS = @CPPFLAGS@
+CXX = @CXX@
+CXXCPP = @CXXCPP@
+CXXDEPMODE = @CXXDEPMODE@
+CXXFLAGS = @CXXFLAGS@
+CYGPATH_W = @CYGPATH_W@
+DEBARCH = @DEBARCH@
+DEFS = @DEFS@
+DEPDIR = @DEPDIR@
+ECHO = @ECHO@
+ECHO_C = @ECHO_C@
+ECHO_N = @ECHO_N@
+ECHO_T = @ECHO_T@
+EGREP = @EGREP@
+EXEEXT = @EXEEXT@
+F77 = @F77@
+FFLAGS = @FFLAGS@
+INSTALL_DATA = @INSTALL_DATA@
+INSTALL_PROGRAM = @INSTALL_PROGRAM@
+INSTALL_SCRIPT = @INSTALL_SCRIPT@
+INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
+JAR = @JAR@
+JAVA = @JAVA@
+JAVAC = @JAVAC@
+JAVACFLAGS = @JAVACFLAGS@
+JAVA_RPM_CONTENTS_1 = @JAVA_RPM_CONTENTS_1@
+JAVA_RPM_CONTENTS_2 = @JAVA_RPM_CONTENTS_2@
+JNI_CFLAGS = @JNI_CFLAGS@
+JPEG_LIB_VERSION = @JPEG_LIB_VERSION@
+JPEG_LIB_VERSION_DECIMAL = @JPEG_LIB_VERSION_DECIMAL@
+LDFLAGS = @LDFLAGS@
+LIBOBJS = @LIBOBJS@
+LIBS = @LIBS@
+LIBTOOL = @LIBTOOL@
+LN_S = @LN_S@
+LTLIBOBJS = @LTLIBOBJS@
+MAKEINFO = @MAKEINFO@
+NAFLAGS = @NAFLAGS@
+NASM = @NASM@
+OBJEXT = @OBJEXT@
+PACKAGE = @PACKAGE@
+PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
+PACKAGE_NAME = @PACKAGE_NAME@
+PACKAGE_STRING = @PACKAGE_STRING@
+PACKAGE_TARNAME = @PACKAGE_TARNAME@
+PACKAGE_VERSION = @PACKAGE_VERSION@
+PATH_SEPARATOR = @PATH_SEPARATOR@
+RANLIB = @RANLIB@
+RPMARCH = @RPMARCH@
+RPM_CONFIG_ARGS = @RPM_CONFIG_ARGS@
+SET_MAKE = @SET_MAKE@
+SHELL = @SHELL@
+SIMD_ARM_FALSE = @SIMD_ARM_FALSE@
+SIMD_ARM_TRUE = @SIMD_ARM_TRUE@
+SIMD_I386_FALSE = @SIMD_I386_FALSE@
+SIMD_I386_TRUE = @SIMD_I386_TRUE@
+SIMD_X86_64_FALSE = @SIMD_X86_64_FALSE@
+SIMD_X86_64_TRUE = @SIMD_X86_64_TRUE@
+SO_MAJOR_VERSION = @SO_MAJOR_VERSION@
+SO_MINOR_VERSION = @SO_MINOR_VERSION@
+STRIP = @STRIP@
+VERSION = @VERSION@
+VERSION_SCRIPT_FALSE = @VERSION_SCRIPT_FALSE@
+VERSION_SCRIPT_FLAG = @VERSION_SCRIPT_FLAG@
+VERSION_SCRIPT_TRUE = @VERSION_SCRIPT_TRUE@
+WITH_ARITH_DEC_FALSE = @WITH_ARITH_DEC_FALSE@
+WITH_ARITH_DEC_TRUE = @WITH_ARITH_DEC_TRUE@
+WITH_ARITH_ENC_FALSE = @WITH_ARITH_ENC_FALSE@
+WITH_ARITH_ENC_TRUE = @WITH_ARITH_ENC_TRUE@
+WITH_ARITH_FALSE = @WITH_ARITH_FALSE@
+WITH_ARITH_TRUE = @WITH_ARITH_TRUE@
+WITH_JAVA = @WITH_JAVA@
+WITH_JAVA_FALSE = @WITH_JAVA_FALSE@
+WITH_JAVA_TRUE = @WITH_JAVA_TRUE@
+WITH_SIMD_FALSE = @WITH_SIMD_FALSE@
+WITH_SIMD_TRUE = @WITH_SIMD_TRUE@
+WITH_SSE_FLOAT_DCT_FALSE = @WITH_SSE_FLOAT_DCT_FALSE@
+WITH_SSE_FLOAT_DCT_TRUE = @WITH_SSE_FLOAT_DCT_TRUE@
+X86_64_FALSE = @X86_64_FALSE@
+X86_64_TRUE = @X86_64_TRUE@
+ac_ct_AR = @ac_ct_AR@
+ac_ct_CC = @ac_ct_CC@
+ac_ct_CXX = @ac_ct_CXX@
+ac_ct_F77 = @ac_ct_F77@
+ac_ct_RANLIB = @ac_ct_RANLIB@
+ac_ct_STRIP = @ac_ct_STRIP@
+am__fastdepCC_FALSE = @am__fastdepCC_FALSE@
+am__fastdepCC_TRUE = @am__fastdepCC_TRUE@
+am__fastdepCXX_FALSE = @am__fastdepCXX_FALSE@
+am__fastdepCXX_TRUE = @am__fastdepCXX_TRUE@
+am__include = @am__include@
+am__leading_dot = @am__leading_dot@
+am__quote = @am__quote@
+am__tar = @am__tar@
+am__untar = @am__untar@
+bindir = @bindir@
+build = @build@
+build_alias = @build_alias@
+build_cpu = @build_cpu@
+build_os = @build_os@
+build_vendor = @build_vendor@
+datadir = @datadir@
+exec_prefix = @exec_prefix@
+host = @host@
+host_alias = @host_alias@
+host_cpu = @host_cpu@
+host_os = @host_os@
+host_vendor = @host_vendor@
+includedir = @includedir@
+infodir = @infodir@
+install_sh = @install_sh@
+libdir = @libdir@
+libexecdir = @libexecdir@
+localstatedir = @localstatedir@
+mandir = @mandir@
+mkdir_p = @mkdir_p@
+oldincludedir = @oldincludedir@
+prefix = @prefix@
+program_transform_name = @program_transform_name@
+sbindir = @sbindir@
+sharedstatedir = @sharedstatedir@
+sysconfdir = @sysconfdir@
+target_alias = @target_alias@
+JAVAROOT = .
+JAVASOURCES = org/libjpegturbo/turbojpeg/TJ.java \
+	org/libjpegturbo/turbojpeg/TJCompressor.java \
+	org/libjpegturbo/turbojpeg/TJCustomFilter.java \
+	org/libjpegturbo/turbojpeg/TJDecompressor.java \
+	org/libjpegturbo/turbojpeg/TJLoader.java \
+	org/libjpegturbo/turbojpeg/TJScalingFactor.java \
+	org/libjpegturbo/turbojpeg/TJTransform.java \
+	org/libjpegturbo/turbojpeg/TJTransformer.java \
+	TJExample.java \
+	TJUnitTest.java
+
+JNIHEADERS = org_libjpegturbo_turbojpeg_TJ.h \
+	org_libjpegturbo_turbojpeg_TJCompressor.h \
+	org_libjpegturbo_turbojpeg_TJDecompressor.h \
+	org_libjpegturbo_turbojpeg_TJTransformer.h
+
+@WITH_JAVA_TRUE@dist_noinst_JAVA = ${JAVASOURCES}
+@WITH_JAVA_TRUE@JAVA_CLASSES = org/libjpegturbo/turbojpeg/TJ.class \
+@WITH_JAVA_TRUE@	org/libjpegturbo/turbojpeg/TJCompressor.class \
+@WITH_JAVA_TRUE@	org/libjpegturbo/turbojpeg/TJCustomFilter.class \
+@WITH_JAVA_TRUE@	org/libjpegturbo/turbojpeg/TJDecompressor.class \
+@WITH_JAVA_TRUE@	org/libjpegturbo/turbojpeg/TJLoader.class \
+@WITH_JAVA_TRUE@	org/libjpegturbo/turbojpeg/TJScalingFactor.class \
+@WITH_JAVA_TRUE@	org/libjpegturbo/turbojpeg/TJTransform.class \
+@WITH_JAVA_TRUE@	org/libjpegturbo/turbojpeg/TJTransformer.class \
+@WITH_JAVA_TRUE@	TJExample.class \
+@WITH_JAVA_TRUE@	TJUnitTest.class
+
+EXTRA_DIST = MANIFEST.MF ${JAVASOURCES} ${JNIHEADERS} doc CMakeLists.txt \
+	org/libjpegturbo/turbojpeg/TJLoader.java.in
+
+all: all-am
+
+.SUFFIXES:
+$(srcdir)/Makefile.in:  $(srcdir)/Makefile.am  $(am__configure_deps)
+	@for dep in $?; do \
+	  case '$(am__configure_deps)' in \
+	    *$$dep*) \
+	      cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \
+		&& exit 0; \
+	      exit 1;; \
+	  esac; \
+	done; \
+	echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign  java/Makefile'; \
+	cd $(top_srcdir) && \
+	  $(AUTOMAKE) --foreign  java/Makefile
+.PRECIOUS: Makefile
+Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
+	@case '$?' in \
+	  *config.status*) \
+	    cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
+	  *) \
+	    echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
+	    cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
+	esac;
+
+$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
+	cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+
+$(top_srcdir)/configure:  $(am__configure_deps)
+	cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+$(ACLOCAL_M4):  $(am__aclocal_m4_deps)
+	cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+
+mostlyclean-libtool:
+	-rm -f *.lo
+
+clean-libtool:
+	-rm -rf .libs _libs
+
+distclean-libtool:
+	-rm -f libtool
+uninstall-info-am:
+
+classdist_noinst.stamp: $(dist_noinst_JAVA)
+	@if test -n "$?"; then \
+	  echo '$(CLASSPATH_ENV) $(JAVAC) -d $(JAVAROOT) $(AM_JAVACFLAGS) $(JAVACFLAGS) $?' ; \
+	  $(CLASSPATH_ENV) $(JAVAC) -d $(JAVAROOT) \
+	    $(AM_JAVACFLAGS) $(JAVACFLAGS) $?; \
+	else :; fi
+	echo timestamp > classdist_noinst.stamp
+
+clean-dist_noinstJAVA:
+	-rm -f *.class classdist_noinst.stamp
+tags: TAGS
+TAGS:
+
+ctags: CTAGS
+CTAGS:
+
+
+distdir: $(DISTFILES)
+	$(mkdir_p) $(distdir)/org/libjpegturbo/turbojpeg
+	@srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; \
+	topsrcdirstrip=`echo "$(top_srcdir)" | sed 's|.|.|g'`; \
+	list='$(DISTFILES)'; for file in $$list; do \
+	  case $$file in \
+	    $(srcdir)/*) file=`echo "$$file" | sed "s|^$$srcdirstrip/||"`;; \
+	    $(top_srcdir)/*) file=`echo "$$file" | sed "s|^$$topsrcdirstrip/|$(top_builddir)/|"`;; \
+	  esac; \
+	  if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
+	  dir=`echo "$$file" | sed -e 's,/[^/]*$$,,'`; \
+	  if test "$$dir" != "$$file" && test "$$dir" != "."; then \
+	    dir="/$$dir"; \
+	    $(mkdir_p) "$(distdir)$$dir"; \
+	  else \
+	    dir=''; \
+	  fi; \
+	  if test -d $$d/$$file; then \
+	    if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
+	      cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \
+	    fi; \
+	    cp -pR $$d/$$file $(distdir)$$dir || exit 1; \
+	  else \
+	    test -f $(distdir)/$$file \
+	    || cp -p $$d/$$file $(distdir)/$$file \
+	    || exit 1; \
+	  fi; \
+	done
+check-am: all-am
+check: check-am
+all-am: Makefile classdist_noinst.stamp
+installdirs:
+install: install-am
+install-exec: install-exec-am
+install-data: install-data-am
+uninstall: uninstall-am
+
+install-am: all-am
+	@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
+
+installcheck: installcheck-am
+install-strip:
+	$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+	  install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+	  `test -z '$(STRIP)' || \
+	    echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
+mostlyclean-generic:
+
+clean-generic:
+
+distclean-generic:
+	-test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
+
+maintainer-clean-generic:
+	@echo "This command is intended for maintainers to use"
+	@echo "it deletes files that may require special tools to rebuild."
+@WITH_JAVA_FALSE@uninstall-local:
+@WITH_JAVA_FALSE@install-exec-local:
+@WITH_JAVA_FALSE@clean-local:
+clean: clean-am
+
+clean-am: clean-dist_noinstJAVA clean-generic clean-libtool \
+	clean-local mostlyclean-am
+
+distclean: distclean-am
+	-rm -f Makefile
+distclean-am: clean-am distclean-generic distclean-libtool
+
+dvi: dvi-am
+
+dvi-am:
+
+html: html-am
+
+info: info-am
+
+info-am:
+
+install-data-am:
+
+install-exec-am: install-exec-local
+
+install-info: install-info-am
+
+install-man:
+
+installcheck-am:
+
+maintainer-clean: maintainer-clean-am
+	-rm -f Makefile
+maintainer-clean-am: distclean-am maintainer-clean-generic
+
+mostlyclean: mostlyclean-am
+
+mostlyclean-am: mostlyclean-generic mostlyclean-libtool
+
+pdf: pdf-am
+
+pdf-am:
+
+ps: ps-am
+
+ps-am:
+
+uninstall-am: uninstall-info-am uninstall-local
+
+.PHONY: all all-am check check-am clean clean-dist_noinstJAVA \
+	clean-generic clean-libtool clean-local distclean \
+	distclean-generic distclean-libtool distdir dvi dvi-am html \
+	html-am info info-am install install-am install-data \
+	install-data-am install-exec install-exec-am \
+	install-exec-local install-info install-info-am install-man \
+	install-strip installcheck installcheck-am installdirs \
+	maintainer-clean maintainer-clean-generic mostlyclean \
+	mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \
+	uninstall uninstall-am uninstall-info-am uninstall-local
+
+
+@WITH_JAVA_TRUE@all: all-am turbojpeg.jar
+
+@WITH_JAVA_TRUE@turbojpeg.jar: $(JAVA_CLASSES) ${srcdir}/MANIFEST.MF
+@WITH_JAVA_TRUE@	$(JAR) cfm turbojpeg.jar ${srcdir}/MANIFEST.MF $(JAVA_CLASSES)
+
+@WITH_JAVA_TRUE@clean-local:
+@WITH_JAVA_TRUE@	rm -f turbojpeg.jar
+
+@WITH_JAVA_TRUE@install-exec-local: turbojpeg.jar
+@WITH_JAVA_TRUE@	mkdir -p $(DESTDIR)/$(prefix)/classes
+@WITH_JAVA_TRUE@	$(INSTALL) -m 644 turbojpeg.jar $(DESTDIR)/$(prefix)/classes/
+
+@WITH_JAVA_TRUE@uninstall-local:
+@WITH_JAVA_TRUE@	rm -f $(DESTDIR)/$(prefix)/classes/turbojpeg.jar
+@WITH_JAVA_TRUE@	if [ -d $(DESTDIR)/$(prefix)/classes ]; then rmdir $(DESTDIR)/$(prefix)/classes; fi
+
+@WITH_JAVA_TRUE@headers: all
+@WITH_JAVA_TRUE@	javah -d ${srcdir} org.libjpegturbo.turbojpeg.TJ; \
+@WITH_JAVA_TRUE@	javah -d ${srcdir} org.libjpegturbo.turbojpeg.TJCompressor; \
+@WITH_JAVA_TRUE@	javah -d ${srcdir} org.libjpegturbo.turbojpeg.TJDecompressor; \
+@WITH_JAVA_TRUE@	javah -d ${srcdir} org.libjpegturbo.turbojpeg.TJTransformer
+
+@WITH_JAVA_TRUE@docs: all
+@WITH_JAVA_TRUE@	mkdir -p ${srcdir}/doc; \
+@WITH_JAVA_TRUE@	javadoc -d ${srcdir}/doc -sourcepath ${srcdir} org.libjpegturbo.turbojpeg
+# Tell versions [3.59,3.63) of GNU make to not export all variables.
+# Otherwise a system limit (for SysV at least) may be exceeded.
+.NOEXPORT:

Source/LibJPEGTurbo/java/README

+TurboJPEG/OSS Java Wrapper
+==========================
+
+TurboJPEG/OSS can optionally be built with a Java Native Interface wrapper,
+which allows the TurboJPEG/OSS dynamic library to be loaded and used directly
+from Java applications.  The Java front end for this is defined in several
+classes located under org/libjpegturbo/turbojpeg.  The source code for these
+Java classes is licensed under a BSD-style license, so the files can be
+incorporated directly into both open source and proprietary projects without
+restriction.  A Java archive (JAR) file containing these classes is also
+shipped with the "official" distribution packages of libjpeg-turbo.
+
+TJExample.java, which should also be located in the same directory as this
+README file, demonstrates how to use the TurboJPEG/OSS Java front end to
+compress and decompress JPEG images in memory.
+
+
+Performance Pitfalls
+--------------------
+
+The TurboJPEG Java front end defines several convenience methods that can
+allocate image buffers or instantiate classes to hold the result of compress,
+decompress, or transform operations.  However, if you use these methods, then
+be mindful of the amount of new data you are creating on the heap.  It may be
+necessary to manually invoke the garbage collector to prevent heap exhaustion
+or to prevent performance degradation.  Background garbage collection can kill
+performance, particularly in a multi-threaded environment (Java pauses all
+threads when the GC runs.)
+
+The Java front end always gives you the option of pre-allocating your own
+source and destination buffers, which allows you to re-use these buffers for
+compressing/decompressing multiple images.  If the image sequence you are
+compressing or decompressing consists of images of the same size, then
+pre-allocating the buffers is recommended.
+
+
+Note for OS X users
+-------------------
+
+/usr/lib, the directory under which libturbojpeg.dylib is installed on Mac
+systems, is not part of the normal Java library path.  Thus, when running a
+Java application that uses TurboJPEG/OSS on Mac systems, you will need to pass
+an argument of -Djava.library.path=/usr/lib to java.
+
+
+Note for Solaris users
+----------------------
+
+/opt/libjpeg-turbo/lib, the directory under which libturbojpeg.so is installed
+on Solaris systems, is not part of the normal Java library path.  Thus, when
+running a Java application that uses TurboJPEG/OSS on Solaris systems, you will
+need to pass an argument of -Djava.library.path=/opt/libjpeg-turbo/lib to java.
+If using a 64-bit data model, then instead pass an argument of
+-Djava.library.path=/opt/libjpeg-turbo/lib/amd64 to use the 64-bit version of
+libturbojpeg.so.

Source/LibJPEGTurbo/java/TJExample.java

+/*
+ * Copyright (C)2011-2012 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.
+ */
+
+/*
+ * This program demonstrates how to compress and decompress JPEG files using
+ * the TurboJPEG JNI wrapper
+ */
+
+import java.io.*;
+import java.awt.*;
+import java.awt.image.*;
+import java.nio.*;
+import javax.imageio.*;
+import javax.swing.*;
+import org.libjpegturbo.turbojpeg.*;
+
+public class TJExample implements TJCustomFilter {
+
+  public static final String classname = new TJExample().getClass().getName();
+
+  private static void usage() throws Exception {
+    System.out.println("\nUSAGE: java " + classname + " <Input file> <Output file> [options]\n");
+    System.out.println("Input and output files can be any image format that the Java Image I/O");
+    System.out.println("extensions understand.  If either filename ends in a .jpg extension, then");
+    System.out.println("TurboJPEG will be used to compress or decompress the file.\n");
+    System.out.println("Options:\n");
+    System.out.println("-scale M/N = if the input image is a JPEG file, scale the width/height of the");
+    System.out.print("             output image by a factor of M/N (M/N = ");
+    for(int i = 0; i < sf.length; i++) {
+      System.out.print(sf[i].getNum() + "/" + sf[i].getDenom());
+      if(sf.length == 2 && i != sf.length - 1) System.out.print(" or ");
+      else if(sf.length > 2) {
+        if(i != sf.length - 1) System.out.print(", ");
+        if(i == sf.length - 2) System.out.print("or ");
+      }
+    }
+    System.out.println(")\n");
+    System.out.println("-samp <444|422|420|gray> = If the output image is a JPEG file, this specifies");
+    System.out.println("                           the level of chrominance subsampling to use when");
+    System.out.println("                           recompressing it.  Default is to use the same level");
+    System.out.println("                           of subsampling as the input, if the input is a JPEG");
+    System.out.println("                           file, or 4:4:4 otherwise.\n");
+    System.out.println("-q <1-100> = If the output image is a JPEG file, this specifies the JPEG");
+    System.out.println("             quality to use when recompressing it (default = 95).\n");
+    System.out.println("-hflip, -vflip, -transpose, -transverse, -rot90, -rot180, -rot270 =");
+    System.out.println("     If the input image is a JPEG file, perform the corresponding lossless");
+    System.out.println("     transform prior to decompression (these options are mutually exclusive)\n");
+    System.out.println("-grayscale = If the input image is a JPEG file, perform lossless grayscale");
+    System.out.println("     conversion prior to decompression (can be combined with the other");
+    System.out.println("     transforms above)\n");
+    System.out.println("-crop X,Y,WxH = If the input image is a JPEG file, perform lossless cropping");
+    System.out.println("     prior to decompression.  X,Y specifies the upper left corner of the");
+    System.out.println("     cropping region, and WxH specifies its width and height.  X,Y must be");
+    System.out.println("     evenly divible by the MCU block size (8x8 if the source image was");
+    System.out.println("     compressed using no subsampling or grayscale, or 16x8 for 4:2:2 or 16x16");
+    System.out.println("     for 4:2:0.)\n");
+    System.out.println("-display = Display output image (Output file need not be specified in this");
+    System.out.println("     case.)\n");
+    System.out.println("-fastupsample = Use the fastest chrominance upsampling algorithm available in");
+    System.out.println("     the underlying codec\n");
+    System.out.println("-fastdct = Use the fastest DCT/IDCT algorithms available in the underlying");
+    System.out.println("     codec\n");
+    System.out.println("-accuratedct = Use the most accurate DCT/IDCT algorithms available in the");
+    System.out.println("     underlying codec\n");
+    System.exit(1);
+  }
+
+  private final static String sampName[] = {
+    "4:4:4", "4:2:2", "4:2:0", "Grayscale", "4:4:0"
+  };
+
+  public static void main(String argv[]) {
+
+    BufferedImage img = null;  byte[] bmpBuf = null;
+    TJTransform xform = new TJTransform();
+    int flags = 0;
+
+    try {
+
+      sf = TJ.getScalingFactors();
+
+      if(argv.length < 2) {
+        usage();
+      }
+
+      TJScalingFactor scaleFactor = new TJScalingFactor(1, 1);
+      String inFormat = "jpg", outFormat = "jpg";
+      int outSubsamp = -1, outQual = 95;
+      boolean display = false;
+
+      if(argv.length > 1) {
+        for(int i = 1; i < argv.length; i++) {
+          if(argv[i].length() < 2) continue;
+          if(argv[i].length() > 2
+            && argv[i].substring(0, 3).equalsIgnoreCase("-sc")) {
+            int match = 0;
+            if(i < argv.length - 1) {
+              String[] scaleArg = argv[++i].split("/");
+              if(scaleArg.length == 2) {
+                TJScalingFactor tempsf =
+                  new TJScalingFactor(Integer.parseInt(scaleArg[0]),
+                    Integer.parseInt(scaleArg[1]));
+                for(int j = 0; j < sf.length; j++) {
+                  if(tempsf.equals(sf[j])) {
+                    scaleFactor = sf[j];
+                    match = 1;  break;
+                  }
+                }
+              }
+            }
+            if(match != 1) usage();
+          }
+          if(argv[i].equalsIgnoreCase("-h") || argv[i].equalsIgnoreCase("-?"))
+            usage();
+          if(argv[i].length() > 2
+            && argv[i].substring(0, 3).equalsIgnoreCase("-sa")) {
+            if(i < argv.length - 1) {
+              i++;
+              if(argv[i].substring(0, 1).equalsIgnoreCase("g"))
+                outSubsamp = TJ.SAMP_GRAY;
+              else if(argv[i].equals("444")) outSubsamp = TJ.SAMP_444;
+              else if(argv[i].equals("422")) outSubsamp = TJ.SAMP_422;
+              else if(argv[i].equals("420")) outSubsamp = TJ.SAMP_420;
+              else usage();
+            }
+            else usage();
+          }
+          if(argv[i].substring(0, 2).equalsIgnoreCase("-q")) {
+            if(i < argv.length - 1) {
+              int qual = Integer.parseInt(argv[++i]);
+              if(qual >= 1 && qual <= 100) outQual = qual;
+              else usage();
+            }
+            else usage();
+          }
+          if(argv[i].substring(0, 2).equalsIgnoreCase("-g"))
+            xform.options |= TJTransform.OPT_GRAY;
+          if(argv[i].equalsIgnoreCase("-hflip"))
+            xform.op = TJTransform.OP_HFLIP;
+          if(argv[i].equalsIgnoreCase("-vflip"))
+            xform.op = TJTransform.OP_VFLIP;
+          if(argv[i].equalsIgnoreCase("-transpose"))
+            xform.op = TJTransform.OP_TRANSPOSE;
+          if(argv[i].equalsIgnoreCase("-transverse"))
+            xform.op = TJTransform.OP_TRANSVERSE;
+          if(argv[i].equalsIgnoreCase("-rot90"))
+            xform.op = TJTransform.OP_ROT90;
+          if(argv[i].equalsIgnoreCase("-rot180"))
+            xform.op = TJTransform.OP_ROT180;
+          if(argv[i].equalsIgnoreCase("-rot270"))
+            xform.op = TJTransform.OP_ROT270;
+          if(argv[i].equalsIgnoreCase("-custom"))
+            xform.cf = new TJExample();
+          else if(argv[i].length() > 2
+            && argv[i].substring(0, 2).equalsIgnoreCase("-c")) {
+            if(i >= argv.length - 1) usage();
+            String[] cropArg = argv[++i].split(",");
+            if(cropArg.length != 3) usage();
+            String[] dimArg = cropArg[2].split("[xX]");
+            if(dimArg.length != 2) usage();
+            int tempx = Integer.parseInt(cropArg[0]);
+            int tempy = Integer.parseInt(cropArg[1]);
+            int tempw = Integer.parseInt(dimArg[0]);
+            int temph = Integer.parseInt(dimArg[1]);
+            if(tempx < 0 || tempy < 0 || tempw < 0 || temph < 0) usage();
+            xform.x = tempx;  xform.y = tempy;
+            xform.width = tempw;  xform.height = temph;
+            xform.options |= TJTransform.OPT_CROP;
+          }
+          if(argv[i].substring(0, 2).equalsIgnoreCase("-d"))
+            display = true;
+          if(argv[i].equalsIgnoreCase("-fastupsample")) {
+            System.out.println("Using fast upsampling code");
+            flags |= TJ.FLAG_FASTUPSAMPLE;
+          }
+          if(argv[i].equalsIgnoreCase("-fastdct")) {
+            System.out.println("Using fastest DCT/IDCT algorithm");
+            flags |= TJ.FLAG_FASTDCT;
+          }
+          if(argv[i].equalsIgnoreCase("-accuratedct")) {
+            System.out.println("Using most accurate DCT/IDCT algorithm");
+            flags |= TJ.FLAG_ACCURATEDCT;
+          }
+        }
+      }
+      String[] inFileTokens = argv[0].split("\\.");
+      if(inFileTokens.length > 1)
+        inFormat = inFileTokens[inFileTokens.length - 1];
+      String[] outFileTokens;
+      if(display) outFormat = "bmp";
+      else {
+        outFileTokens = argv[1].split("\\.");
+        if(outFileTokens.length > 1)
+          outFormat = outFileTokens[outFileTokens.length - 1];
+      }
+
+      File file = new File(argv[0]);
+      int width, height;
+
+      if(inFormat.equalsIgnoreCase("jpg")) {
+        FileInputStream fis = new FileInputStream(file);
+        int inputSize = fis.available();
+        if(inputSize < 1) {
+          System.out.println("Input file contains no data");
+          System.exit(1);
+        }
+        byte[] inputBuf = new byte[inputSize];
+        fis.read(inputBuf);
+        fis.close();
+
+        TJDecompressor tjd;
+        if(xform.op != TJTransform.OP_NONE || xform.options != 0
+          || xform.cf != null) {
+          TJTransformer tjt = new TJTransformer(inputBuf);
+          TJTransform t[] = new TJTransform[1];
+          t[0] = xform;
+          t[0].options |= TJTransform.OPT_TRIM;
+          TJDecompressor[] tjdx = tjt.transform(t, 0);
+          tjd = tjdx[0];
+        }
+        else tjd = new TJDecompressor(inputBuf);
+
+        width = tjd.getWidth();
+        height = tjd.getHeight();
+        int inSubsamp = tjd.getSubsamp();
+        System.out.println("Source Image: " + width + " x " + height
+          + " pixels, " + sampName[inSubsamp] + " subsampling");
+        if(outSubsamp < 0) outSubsamp = inSubsamp;
+
+        if(outFormat.equalsIgnoreCase("jpg")
+          && (xform.op != TJTransform.OP_NONE || xform.options != 0)
+          && scaleFactor.isOne()) {
+          file = new File(argv[1]);
+          FileOutputStream fos = new FileOutputStream(file);
+          fos.write(tjd.getJPEGBuf(), 0, tjd.getJPEGSize());
+          fos.close();
+          System.exit(0);
+        }
+
+        width = scaleFactor.getScaled(width);
+        height = scaleFactor.getScaled(height);
+
+        if(!outFormat.equalsIgnoreCase("jpg"))
+          img = tjd.decompress(width, height, BufferedImage.TYPE_INT_RGB,
+                               flags);
+        else bmpBuf = tjd.decompress(width, 0, height, TJ.PF_BGRX, flags);
+        tjd.close();
+      }
+      else {
+        img = ImageIO.read(file);
+        width = img.getWidth();
+        height = img.getHeight();
+        if(outSubsamp < 0) {
+          if(img.getType() == BufferedImage.TYPE_BYTE_GRAY)
+            outSubsamp = TJ.SAMP_GRAY;
+          else outSubsamp = TJ.SAMP_444;
+        }
+      }
+      System.gc();
+      if(!display)
+        System.out.print("Dest. Image (" + outFormat + "):  " + width + " x "
+          + height + " pixels");
+
+      if(display) {
+        ImageIcon icon = new ImageIcon(img);
+        JLabel label = new JLabel(icon, JLabel.CENTER);
+        JOptionPane.showMessageDialog(null, label, "Output Image",
+          JOptionPane.PLAIN_MESSAGE);
+      }
+      else if(outFormat.equalsIgnoreCase("jpg")) {
+        System.out.println(", " + sampName[outSubsamp]
+          + " subsampling, quality = " + outQual);
+        TJCompressor tjc = new TJCompressor();
+        int jpegSize;
+        byte[] jpegBuf;
+
+        tjc.setSubsamp(outSubsamp);
+        tjc.setJPEGQuality(outQual);
+        if(img != null)
+          jpegBuf = tjc.compress(img, flags);
+        else {
+          tjc.setSourceImage(bmpBuf, width, 0, height, TJ.PF_BGRX);
+          jpegBuf = tjc.compress(flags);
+        }
+        jpegSize = tjc.getCompressedSize();
+        tjc.close();
+
+        file = new File(argv[1]);
+        FileOutputStream fos = new FileOutputStream(file);
+        fos.write(jpegBuf, 0, jpegSize);
+        fos.close();
+      }
+      else {
+        System.out.print("\n");
+        file = new File(argv[1]);
+        ImageIO.write(img, outFormat, file);
+      }
+
+    }
+    catch(Exception e) {
+      e.printStackTrace();
+      System.exit(-1);
+    }
+  }
+
+  public void customFilter(ShortBuffer coeffBuffer, Rectangle bufferRegion,
+    Rectangle planeRegion, int componentIndex, int transformIndex,
+    TJTransform transform) throws Exception {
+    for(int i=0; i<bufferRegion.width*bufferRegion.height; i++) {
+	    coeffBuffer.put(i, (short)(-coeffBuffer.get(i)));
+    }
+  }
+
+  static TJScalingFactor sf [] = null;
+};

Source/LibJPEGTurbo/java/TJUnitTest.java

+/*
+ * Copyright (C)2011-2012 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.
+ */
+
+/*
+ * This program tests the various code paths in the TurboJPEG JNI Wrapper
+ */
+
+import java.io.*;
+import java.util.*;
+import java.awt.image.*;
+import javax.imageio.*;
+import java.nio.*;
+import org.libjpegturbo.turbojpeg.*;
+
+public class TJUnitTest {
+
+  private static final String classname =
+    new TJUnitTest().getClass().getName();
+
+  private static void usage() {
+    System.out.println("\nUSAGE: java " + classname + " [options]\n");
+    System.out.println("Options:\n");
+    System.out.println("-yuv = test YUV encoding/decoding support\n");
+    System.out.println("-bi = test BufferedImage support\n");
+    System.exit(1);
+  }
+
+  private final static String subNameLong[] = {
+    "4:4:4", "4:2:2", "4:2:0", "GRAY", "4:4:0"
+  };
+  private final static String subName[] = {
+    "444", "422", "420", "GRAY", "440"
+  };
+
+  private final static String pixFormatStr[] = {
+    "RGB", "BGR", "RGBX", "BGRX", "XBGR", "XRGB", "Grayscale",
+    "RGBA", "BGRA", "ABGR", "ARGB"
+  };
+
+  private final static int alphaOffset[] = {
+    -1, -1, -1, -1, -1, -1, -1, 3, 3, 0, 0
+  };
+
+  private final static int _3byteFormats[] = {
+    TJ.PF_RGB, TJ.PF_BGR
+  };
+  private final static int _3byteFormatsBI[] = {
+    BufferedImage.TYPE_3BYTE_BGR
+  };
+  private final static int _4byteFormats[] = {
+    TJ.PF_RGBX, TJ.PF_BGRX, TJ.PF_XBGR, TJ.PF_XRGB
+  };
+  private final static int _4byteFormatsBI[] = {
+    BufferedImage.TYPE_INT_BGR, BufferedImage.TYPE_INT_RGB,
+    BufferedImage.TYPE_4BYTE_ABGR, BufferedImage.TYPE_4BYTE_ABGR_PRE,
+    BufferedImage.TYPE_INT_ARGB, BufferedImage.TYPE_INT_ARGB_PRE
+  };
+  private final static int onlyGray[] = {
+    TJ.PF_GRAY
+  };
+  private final static int onlyGrayBI[] = {
+    BufferedImage.TYPE_BYTE_GRAY
+  };
+  private final static int onlyRGB[] = {
+    TJ.PF_RGB
+  };
+
+  private final static int YUVENCODE = 1;
+  private final static int YUVDECODE = 2;
+  private static int yuv = 0;
+  private static boolean bi = false;
+
+  private static int exitStatus = 0;
+
+  private static int biTypePF(int biType) {
+    ByteOrder byteOrder = ByteOrder.nativeOrder();
+    switch(biType) {
+      case BufferedImage.TYPE_3BYTE_BGR:
+        return TJ.PF_BGR;
+      case BufferedImage.TYPE_4BYTE_ABGR:
+      case BufferedImage.TYPE_4BYTE_ABGR_PRE:
+        return TJ.PF_XBGR;
+      case BufferedImage.TYPE_BYTE_GRAY:
+        return TJ.PF_GRAY;
+      case BufferedImage.TYPE_INT_BGR:
+        if(byteOrder == ByteOrder.BIG_ENDIAN)
+          return TJ.PF_XBGR;
+        else
+          return TJ.PF_RGBX;
+      case BufferedImage.TYPE_INT_RGB:
+        if(byteOrder == ByteOrder.BIG_ENDIAN)
+          return TJ.PF_XRGB;
+        else
+          return TJ.PF_BGRX;
+      case BufferedImage.TYPE_INT_ARGB:
+      case BufferedImage.TYPE_INT_ARGB_PRE:
+        if(byteOrder == ByteOrder.BIG_ENDIAN)
+          return TJ.PF_ARGB;
+        else
+          return TJ.PF_BGRA;
+    }
+    return 0;
+  }
+
+  private static String biTypeStr(int biType) {
+    switch(biType) {
+      case BufferedImage.TYPE_3BYTE_BGR:
+        return "3BYTE_BGR";
+      case BufferedImage.TYPE_4BYTE_ABGR:
+        return "4BYTE_ABGR";
+      case BufferedImage.TYPE_4BYTE_ABGR_PRE:
+        return "4BYTE_ABGR_PRE";
+      case BufferedImage.TYPE_BYTE_GRAY:
+        return "BYTE_GRAY";
+      case BufferedImage.TYPE_INT_BGR:
+        return "INT_BGR";
+      case BufferedImage.TYPE_INT_RGB:
+        return "INT_RGB";
+      case BufferedImage.TYPE_INT_ARGB:
+        return "INT_ARGB";
+      case BufferedImage.TYPE_INT_ARGB_PRE:
+        return "INT_ARGB_PRE";
+    }
+    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);
+    int goffset = TJ.getGreenOffset(pf);
+    int boffset = TJ.getBlueOffset(pf);
+    int aoffset = alphaOffset[pf];
+    int ps = TJ.getPixelSize(pf);
+    int index, row, col, halfway = 16;
+
+    Arrays.fill(buf, (byte)0);
+    if(pf == TJ.PF_GRAY) {
+      for(row = 0; row < h; row++) {
+        for(col = 0; col < w; col++) {
+          if((flags & TJ.FLAG_BOTTOMUP) != 0)
+            index = pitch * (h - row - 1) + col;
+          else index = pitch * row + col;
+          if(((row / 8) + (col / 8)) % 2 == 0)
+            buf[index] = (row < halfway) ? (byte)255 : 0;
+          else buf[index] = (row < halfway) ? 76 : (byte)226;
+        }
+      }
+      return;
+    }
+    for(row = 0; row < h; row++) {
+      for(col = 0; col < w; col++) {
+        if((flags & TJ.FLAG_BOTTOMUP) != 0)
+          index = pitch * (h - row - 1) + col * ps;
+        else index = pitch * row + col * ps;
+        if(((row / 8) + (col / 8)) % 2 == 0) {
+          if(row < halfway) {
+            buf[index + roffset] = (byte)255;
+            buf[index + goffset] = (byte)255;
+            buf[index + boffset] = (byte)255;
+          }
+        }
+        else {
+          buf[index + roffset] = (byte)255;
+          if(row >= halfway) buf[index + goffset] = (byte)255;
+        }
+        if (aoffset >= 0) buf[index + aoffset] = (byte)255;
+      }
+    }
+  }
+
+  private static void initIntBuf(int[] buf, int w, int pitch, int h, int pf,
+    int flags) throws Exception {
+    int rshift = TJ.getRedOffset(pf) * 8;
+    int gshift = TJ.getGreenOffset(pf) * 8;
+    int bshift = TJ.getBlueOffset(pf) * 8;
+    int ashift = alphaOffset[pf] * 8;
+    int index, row, col, halfway = 16;
+
+    Arrays.fill(buf, 0);
+    for(row = 0; row < h; row++) {
+      for(col = 0; col < w; col++) {
+        if((flags & TJ.FLAG_BOTTOMUP) != 0)
+          index = pitch * (h - row - 1) + col;
+        else index = pitch * row + col;
+        if(((row / 8) + (col / 8)) % 2 == 0) {
+          if(row < halfway) {
+            buf[index] |= (255 << rshift);
+            buf[index] |= (255 << gshift);
+            buf[index] |= (255 << bshift);
+          }
+        }
+        else {
+          buf[index] |= (255 << rshift);
+          if(row >= halfway) buf[index] |= (255 << gshift);
+        }
+        if (ashift >= 0) buf[index] |= (255 << ashift);
+      }
+    }
+  }
+
+  private static void initImg(BufferedImage img, int pf, int flags)
+    throws Exception {
+    WritableRaster wr = img.getRaster();
+    int imgType = img.getType();
+    if(imgType == BufferedImage.TYPE_INT_RGB
+      || imgType == BufferedImage.TYPE_INT_BGR
+      || imgType == BufferedImage.TYPE_INT_ARGB
+      || imgType == BufferedImage.TYPE_INT_ARGB_PRE) {
+      SinglePixelPackedSampleModel sm =
+        (SinglePixelPackedSampleModel)img.getSampleModel();
+      int pitch = sm.getScanlineStride();
+      DataBufferInt db = (DataBufferInt)wr.getDataBuffer();
+      int[] buf = db.getData();
+      initIntBuf(buf, img.getWidth(), pitch, img.getHeight(), pf, flags);
+    }
+    else {
+      ComponentSampleModel sm = (ComponentSampleModel)img.getSampleModel();
+      int pitch = sm.getScanlineStride();
+      DataBufferByte db = (DataBufferByte)wr.getDataBuffer();
+      byte[] buf = db.getData();
+      initBuf(buf, img.getWidth(), pitch, img.getHeight(), pf, flags);
+    }
+  }
+
+  private static void checkVal(int row, int col, int v, String vname, int cv)
+    throws Exception {
+    v = (v < 0) ? v + 256 : v;
+    if(v < cv - 1 || v > cv + 1) {
+      throw new Exception("\nComp. " + vname + " at " + row + "," + col
+        + " should be " + cv + ", not " + v + "\n");
+    }
+  }
+
+  private static void checkVal0(int row, int col, int v, String vname)
+    throws Exception {
+    v = (v < 0) ? v + 256 : v;
+    if(v > 1) {
+      throw new Exception("\nComp. " + vname + " at " + row + "," + col
+        + " should be 0, not " + v + "\n");
+    }
+  }
+
+  private static void checkVal255(int row, int col, int v, String vname)
+    throws Exception {
+    v = (v < 0) ? v + 256 : v;
+    if(v < 254) {
+      throw new Exception("\nComp. " + vname + " at " + row + "," + col
+        + " should be 255, not " + v + "\n");
+    }
+  }
+
+  private static int checkBuf(byte[] buf, int w, int pitch, int h, int pf,
+    int subsamp, TJScalingFactor sf, int flags) throws Exception {
+    int roffset = TJ.getRedOffset(pf);
+    int goffset = TJ.getGreenOffset(pf);
+    int boffset = TJ.getBlueOffset(pf);
+    int aoffset = alphaOffset[pf];
+    int ps = TJ.getPixelSize(pf);
+    int index, row, col, retval = 1;
+    int halfway = 16 * sf.getNum() / sf.getDenom();
+    int blockSize = 8 * sf.getNum() / sf.getDenom();
+
+    try {
+      for(row = 0; row < halfway; row++) {
+        for(col = 0; col < w; col++) {
+          if((flags & TJ.FLAG_BOTTOMUP) != 0)
+            index = pitch * (h - row - 1) + col * ps;
+          else index = pitch * row + col * ps;
+          byte r = buf[index + roffset];
+          byte g = buf[index + goffset];
+          byte b = buf[index + boffset];
+          byte a = aoffset >= 0 ? buf[index + aoffset] : (byte)255;
+          if(((row / blockSize) + (col / blockSize)) % 2 == 0) {
+            if(row < halfway) {
+              checkVal255(row, col, r, "R");
+              checkVal255(row, col, g, "G");
+              checkVal255(row, col, b, "B");
+            }
+            else {
+              checkVal0(row, col, r, "R");
+              checkVal0(row, col, g, "G");
+              checkVal0(row, col, b, "B");
+            }
+          }
+          else {
+            if(subsamp == TJ.SAMP_GRAY) {
+              if(row < halfway) {
+                checkVal(row, col, r, "R", 76);
+                checkVal(row, col, g, "G", 76);
+                checkVal(row, col, b, "B", 76);
+              }
+              else {
+                checkVal(row, col, r, "R", 226);
+                checkVal(row, col, g, "G", 226);
+                checkVal(row, col, b, "B", 226);
+              }
+            }
+            else {
+              checkVal255(row, col, r, "R");
+              if(row < halfway) {
+                checkVal0(row, col, g, "G");
+              }
+              else {
+                checkVal255(row, col, g, "G");
+              }
+              checkVal0(row, col, b, "B");							
+            }
+          }
+          checkVal255(row, col, a, "A");
+        }
+      }
+    }
+    catch(Exception e) {
+      System.out.println(e);
+      retval = 0;
+    }
+
+    if(retval == 0) {
+      System.out.print("\n");
+      for(row = 0; row < h; row++) {
+        for(col = 0; col < w; col++) {
+          int r = buf[pitch * row + col * ps + roffset];
+          int g = buf[pitch * row + col * ps + goffset];
+          int b = buf[pitch * row + col * ps + boffset];
+          if(r < 0) r += 256;  if(g < 0) g += 256;  if(b < 0) b += 256;
+          System.out.format("%3d/%3d/%3d ", r, g, b);
+        }
+        System.out.print("\n");
+      }
+    }
+    return retval;
+  }
+
+  private static int checkIntBuf(int[] buf, int w, int pitch, int h, int pf,
+    int subsamp, TJScalingFactor sf, int flags) throws Exception {
+    int rshift = TJ.getRedOffset(pf) * 8;
+    int gshift = TJ.getGreenOffset(pf) * 8;
+    int bshift = TJ.getBlueOffset(pf) * 8;
+    int ashift = alphaOffset[pf] * 8;
+    int index, row, col, retval = 1;
+    int halfway = 16 * sf.getNum() / sf.getDenom();
+    int blockSize = 8 * sf.getNum() / sf.getDenom();
+
+    try {
+      for(row = 0; row < halfway; row++) {
+        for(col = 0; col < w; col++) {
+          if((flags & TJ.FLAG_BOTTOMUP) != 0)
+            index = pitch * (h - row - 1) + col;
+          else index = pitch * row + col;
+          int r = (buf[index] >> rshift) & 0xFF;
+          int g = (buf[index] >> gshift) & 0xFF;
+          int b = (buf[index] >> bshift) & 0xFF;
+          int a = ashift >= 0 ? (buf[index] >> ashift) & 0xFF : 255;
+          if(((row / blockSize) + (col / blockSize)) % 2 == 0) {
+            if(row < halfway) {
+              checkVal255(row, col, r, "R");
+              checkVal255(row, col, g, "G");
+              checkVal255(row, col, b, "B");
+            }
+            else {
+              checkVal0(row, col, r, "R");
+              checkVal0(row, col, g, "G");
+              checkVal0(row, col, b, "B");
+            }
+          }
+          else {
+            if(subsamp == TJ.SAMP_GRAY) {
+              if(row < halfway) {
+                checkVal(row, col, r, "R", 76);
+                checkVal(row, col, g, "G", 76);
+                checkVal(row, col, b, "B", 76);
+              }
+              else {
+                checkVal(row, col, r, "R", 226);
+                checkVal(row, col, g, "G", 226);
+                checkVal(row, col, b, "B", 226);
+              }
+            }
+            else {
+              checkVal255(row, col, r, "R");
+              if(row < halfway) {
+                checkVal0(row, col, g, "G");
+              }
+              else {
+                checkVal255(row, col, g, "G");
+              }
+              checkVal0(row, col, b, "B");
+            }
+          }
+          checkVal255(row, col, a, "A");
+        }
+      }
+    }
+    catch(Exception e) {
+      System.out.println(e);
+      retval = 0;
+    }
+
+    if(retval == 0) {
+      System.out.print("\n");
+      for(row = 0; row < h; row++) {
+        for(col = 0; col < w; col++) {
+          int r = (buf[pitch * row + col] >> rshift) & 0xFF;
+          int g = (buf[pitch * row + col] >> gshift) & 0xFF;
+          int b = (buf[pitch * row + col] >> bshift) & 0xFF;
+          if(r < 0) r += 256;  if(g < 0) g += 256;  if(b < 0) b += 256;
+          System.out.format("%3d/%3d/%3d ", r, g, b);
+        }
+        System.out.print("\n");
+      }
+    }
+    return retval;
+  }
+
+  private static int checkImg(BufferedImage img, int pf,
+    int subsamp, TJScalingFactor sf, int flags) throws Exception {
+    WritableRaster wr = img.getRaster();
+    int imgType = img.getType();
+    if(imgType == BufferedImage.TYPE_INT_RGB
+      || imgType == BufferedImage.TYPE_INT_BGR
+      || imgType == BufferedImage.TYPE_INT_ARGB
+      || imgType == BufferedImage.TYPE_INT_ARGB_PRE) {
+       SinglePixelPackedSampleModel sm =
+        (SinglePixelPackedSampleModel)img.getSampleModel();
+      int pitch = sm.getScanlineStride();
+      DataBufferInt db = (DataBufferInt)wr.getDataBuffer();
+      int[] buf = db.getData();
+      return checkIntBuf(buf, img.getWidth(), pitch, img.getHeight(), pf,
+        subsamp, sf, flags);
+    }
+    else {
+      ComponentSampleModel sm = (ComponentSampleModel)img.getSampleModel();
+      int pitch = sm.getScanlineStride();
+      DataBufferByte db = (DataBufferByte)wr.getDataBuffer();
+      byte[] buf = db.getData();
+      return checkBuf(buf, img.getWidth(), pitch, img.getHeight(), pf, subsamp,
+        sf, flags);
+    }
+  }
+
+  private static int PAD(int v, int p) {
+    return ((v + (p) - 1) & (~((p) - 1)));
+  }
+
+  private static int checkBufYUV(byte[] buf, int size, int w, 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, 4), uvpitch = PAD(cw, 4);
+    int retval = 1;
+    int correctsize = ypitch * ph
+      + (subsamp == TJ.SAMP_GRAY ? 0 : uvpitch * ch * 2);
+    int halfway = 16;
+
+    try {
+      if(size != correctsize)
+        throw new Exception("\nIncorrect size " + size + ".  Should be "
+          + correctsize);
+
+      for(row = 0; row < ph; row++) {
+        for(col = 0; col < pw; col++) {
+          byte y = buf[ypitch * row + col];
+          if(((row / 8) + (col / 8)) % 2 == 0) {
+            if(row < halfway) checkVal255(row, col, y, "Y");
+            else checkVal0(row, col, y, "Y");
+          }
+          else {
+            if(row < halfway) checkVal(row, col, y, "Y", 76);
+            else checkVal(row, col, y, "Y", 226);
+          }
+        }
+      }
+      if(subsamp != TJ.SAMP_GRAY) {
+        halfway = 16 / vsf;
+        for(row = 0; row < ch; row++) {
+          for(col = 0; col < cw; col++) {
+            byte u = buf[ypitch * ph + (uvpitch * row + col)],
+              v = buf[ypitch * ph + uvpitch * ch + (uvpitch * row + col)];
+            if(((row * vsf / 8) + (col * hsf / 8)) % 2 == 0) {
+              checkVal(row, col, u, "U", 128);
+              checkVal(row, col, v, "V", 128);
+            }
+            else {
+              if(row < halfway) {
+                checkVal(row, col, u, "U", 85);
+                checkVal255(row, col, v, "V");
+              }
+              else {
+                checkVal0(row, col, u, "U");
+                checkVal(row, col, v, "V", 149);
+              }
+            }
+          }
+        }
+      }
+    }
+    catch(Exception e) {
+      System.out.println(e);
+      retval = 0;
+    }
+
+    if(retval == 0) {
+      for(row = 0; row < ph; row++) {
+        for(col = 0; col < pw; col++) {
+          int y = buf[ypitch * row + col];
+          if(y < 0) y += 256;
+          System.out.format("%3d ", y);
+        }
+        System.out.print("\n");
+      }
+      System.out.print("\n");
+      for(row = 0; row < ch; row++) {
+        for(col = 0; col < cw; col++) {
+          int u = buf[ypitch * ph + (uvpitch * row + col)];
+          if(u < 0) u += 256;
+          System.out.format("%3d ", u);
+        }
+        System.out.print("\n");
+      }
+      System.out.print("\n");
+      for(row = 0; row < ch; row++) {
+        for(col = 0; col < cw; col++) {
+          int v = buf[ypitch * ph + uvpitch * ch + (uvpitch * row + col)];
+          if(v < 0) v += 256;
+          System.out.format("%3d ", v);
+        }
+        System.out.print("\n");
+      }
+      System.out.print("\n");
+    }
+
+    return retval;
+  }
+
+  private static void writeJPEG(byte[] jpegBuf, int jpegBufSize,
+    String filename) throws Exception {
+    File file = new File(filename);
+    FileOutputStream fos = new FileOutputStream(file);
+    fos.write(jpegBuf, 0, jpegBufSize);
+    fos.close();
+  }
+
+  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;
+    byte[] srcBuf = null;
+    BufferedImage img = null;
+    String pfStr;
+    double t;
+    int size = 0, ps, imgType = pf;
+
+    if (bi) {
+      pf = biTypePF(imgType);
+      pfStr = biTypeStr(imgType);
+    }
+    else pfStr = pixFormatStr[pf];
+    ps =  TJ.getPixelSize(pf);
+
+    System.out.print(pfStr + " ");
+    if(bi) System.out.print("(" + pixFormatStr[pf] + ") ");
+    if((flags & TJ.FLAG_BOTTOMUP) != 0) System.out.print("Bottom-Up");
+    else System.out.print("Top-Down ");
+    System.out.print(" -> " + subNameLong[subsamp] + " ");
+    if(yuv == YUVENCODE) System.out.print("YUV ... ");
+    else System.out.print("Q" + jpegQual + " ... ");
+
+    if(bi) {
+      img = new BufferedImage(w, h, imgType);
+      initImg(img, pf, flags);
+      tempstr = baseName + "_enc_" + pfStr + "_"
+        + (((flags & TJ.FLAG_BOTTOMUP) != 0) ? "BU" : "TD") + "_"
+        + 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);
+    }
+    Arrays.fill(dstBuf, (byte)0);
+
+    t = getTime();
+    tjc.setSubsamp(subsamp);
+    tjc.setJPEGQuality(jpegQual);
+    if(bi) {
+      if(yuv == YUVENCODE) tjc.encodeYUV(img, dstBuf, flags);
+      else tjc.compress(img, dstBuf, flags);
+    }
+    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 + "_"
+        + (((flags & TJ.FLAG_BOTTOMUP) != 0) ? "BU" : "TD") + "_"
+        + subName[subsamp] + ".yuv";
+    else
+      tempstr = baseName + "_enc_" + pfStr + "_"
+        + (((flags & TJ.FLAG_BOTTOMUP) != 0) ? "BU" : "TD") + "_"
+        + subName[subsamp] + "_Q" + jpegQual + ".jpg";
+    writeJPEG(dstBuf, size, tempstr);
+
+    if(yuv == YUVENCODE) {
+      if(checkBufYUV(dstBuf, size, w, h, subsamp) == 1)
+        System.out.print("Passed.");
+      else {
+        System.out.print("FAILED!");  exitStatus = -1;
+      }
+    }
+    else System.out.print("Done.");
+    System.out.format("  %.6f ms\n", t * 1000.);
+    System.out.println("  Result in " + tempstr);
+
+    return size;
+  }
+
+  private static void decompTest(TJDecompressor tjd, byte[] jpegBuf,
+    int jpegSize, int w, int h, int pf, String baseName, int subsamp,
+    int flags, TJScalingFactor sf) throws Exception {
+    String pfStr, tempstr;
+    double t;
+    int scaledWidth = sf.getScaled(w);
+    int scaledHeight = sf.getScaled(h);
+    int temp1, temp2, imgType = pf;
+    BufferedImage img = null;
+    byte[] dstBuf = null;
+
+    if(yuv == YUVENCODE) return;
+
+    if (bi) {
+      pf = biTypePF(imgType);
+      pfStr = biTypeStr(imgType);
+    }
+    else pfStr = pixFormatStr[pf];
+
+    System.out.print("JPEG -> ");
+    if(yuv == YUVDECODE)
+      System.out.print("YUV " + subName[subsamp] + " ... ");
+    else {
+      System.out.print(pfStr + " ");
+      if(bi) System.out.print("(" + pixFormatStr[pf] + ") ");
+      if((flags & TJ.FLAG_BOTTOMUP) != 0) System.out.print("Bottom-Up ");
+      else System.out.print("Top-Down  ");
+      if(!sf.isOne())
+        System.out.print(sf.getNum() + "/" + sf.getDenom() + " ... ");
+      else System.out.print("... ");
+    }
+
+    t = getTime();
+    tjd.setJPEGImage(jpegBuf, jpegSize);
+    if(tjd.getWidth() != w || tjd.getHeight() != h
+      || tjd.getSubsamp() != subsamp)
+      throw new Exception("Incorrect JPEG header");
+
+    temp1 = scaledWidth;
+    temp2 = scaledHeight;
+    temp1 = tjd.getScaledWidth(temp1, temp2);
+    temp2 = tjd.getScaledHeight(temp1, temp2);
+    if(temp1 != scaledWidth || temp2 != scaledHeight)
+      throw new Exception("Scaled size mismatch");
+
+    if(yuv == YUVDECODE) dstBuf = tjd.decompressToYUV(flags);
+    else {
+      if(bi)
+        img = tjd.decompress(scaledWidth, scaledHeight, imgType, flags);
+      else dstBuf = tjd.decompress(scaledWidth, 0, scaledHeight, pf, flags);
+    }
+    t = getTime() - t;
+
+    if(bi) {
+      tempstr = baseName + "_dec_" + pfStr + "_"
+        + (((flags & TJ.FLAG_BOTTOMUP) != 0) ? "BU" : "TD") + "_"
+        + subName[subsamp] + "_" + (double)sf.getNum() / (double)sf.getDenom()
+        + "x" + ".png";
+      File file = new File(tempstr);
+      ImageIO.write(img, "png", file);
+    }
+
+    if(yuv == YUVDECODE) {
+      if(checkBufYUV(dstBuf, dstBuf.length, w, h, subsamp) == 1)
+        System.out.print("Passed.");
+      else {
+        System.out.print("FAILED!");  exitStatus = -1;
+      }
+    }
+    else {
+      if((bi && checkImg(img, pf, subsamp, sf, flags) == 1)
+        || (!bi && checkBuf(dstBuf, scaledWidth, scaledWidth
+          * TJ.getPixelSize(pf), scaledHeight, pf, subsamp, sf, flags) == 1))
+        System.out.print("Passed.");
+      else {
+        System.out.print("FAILED!");  exitStatus = -1;
+      }
+    }
+    System.out.format("  %.6f ms\n", t * 1000.);
+  }
+
+  private static void decompTest(TJDecompressor tjd, byte[] jpegBuf,
+    int jpegSize, int w, int h, int pf, String baseName, int subsamp,
+    int flags) throws Exception {
+    int i;
+    if((subsamp == TJ.SAMP_444 || subsamp == TJ.SAMP_GRAY) && yuv == 0) {
+      TJScalingFactor sf[] = TJ.getScalingFactors();
+      for(i = 0; i < sf.length; i++)
+        decompTest(tjd, jpegBuf, jpegSize, w, h, pf, baseName, subsamp,
+          flags, sf[i]);
+    }
+    else
+      decompTest(tjd, jpegBuf, jpegSize, w, h, pf, baseName, subsamp,
+        flags, new TJScalingFactor(1, 1));
+    System.out.print("\n");
+  }
+
+  private static void doTest(int w, int h, int[] formats, int subsamp,
+    String baseName) throws Exception {
+    TJCompressor tjc = null;
+    TJDecompressor tjd = null;
+    int size;
+    byte[] dstBuf;
+
+    if(yuv == YUVENCODE) dstBuf = new byte[TJ.bufSizeYUV(w, h, subsamp)];
+    else dstBuf = new byte[TJ.bufSize(w, h, subsamp)];
+
+    try {
+      tjc = new TJCompressor();
+      tjd = new TJDecompressor();  
+
+      for(int pf : formats) {
+        for(int i = 0; i < 2; i++) {
+          int flags = 0;
+          if (subsamp == TJ.SAMP_422 || subsamp == TJ.SAMP_420
+            || subsamp == TJ.SAMP_440)
+            flags |= TJ.FLAG_FASTUPSAMPLE;
+          if(i == 1) {
+            if(yuv == YUVDECODE) {
+              tjc.close();  tjd.close();  return;
+            }
+            else 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)
+            decompTest(tjd, dstBuf, size, w, h, pf + (TJ.PF_RGBA - TJ.PF_RGBX),
+              baseName, subsamp, flags);
+        }
+      }
+    }
+    catch(Exception e) {
+      if(tjc != null) tjc.close();
+      if(tjd != null) tjd.close();
+      throw e;
+    }
+    if(tjc != null) tjc.close();
+    if(tjd != null) tjd.close();
+  }
+
+  private static void bufSizeTest() throws Exception {
+    int w, h, i, subsamp;
+    byte[] srcBuf, jpegBuf;
+    TJCompressor tjc = null;
+    Random r = new Random();
+
+    try {
+      tjc = new TJCompressor();
+      System.out.println("Buffer size regression test");
+      for(subsamp = 0; subsamp < TJ.NUMSAMP; subsamp++) {
+        for(w = 1; w < 48; w++) {
+          int maxh = (w == 1) ? 2048 : 48;
+          for(h = 1; h < maxh; h++) {
+            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)];
+            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.setSubsamp(subsamp);
+            tjc.setJPEGQuality(100);
+            tjc.compress(jpegBuf, 0);
+
+            srcBuf = new byte[h * w * 4];
+            jpegBuf = 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);
+          }
+        }
+      }
+      System.out.println("Done.      ");
+    }
+    catch(Exception e) {
+      if(tjc != null) tjc.close();
+      throw e;
+    }
+    if(tjc != null) tjc.close();
+  }
+
+  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;
+        if(argv[i].substring(0, 1).equalsIgnoreCase("-h")
+          || argv[i].equalsIgnoreCase("-?"))
+          usage();
+        if(argv[i].equalsIgnoreCase("-bi")) {
+          bi = true;
+          testName = "javabitest";
+        }
+      }
+      if(doyuv) yuv = YUVENCODE;
+      doTest(35, 39, bi ? _3byteFormatsBI : _3byteFormats, TJ.SAMP_444, testName);
+      doTest(39, 41, bi ? _4byteFormatsBI : _4byteFormats, TJ.SAMP_444, testName);
+      doTest(41, 35, bi ? _3byteFormatsBI : _3byteFormats, TJ.SAMP_422,
+        testName);
+      doTest(35, 39, bi ? _4byteFormatsBI : _4byteFormats, TJ.SAMP_422,
+        testName);
+      doTest(39, 41, bi ? _3byteFormatsBI : _3byteFormats, TJ.SAMP_420,
+        testName);
+      doTest(41, 35, bi ? _4byteFormatsBI : _4byteFormats, TJ.SAMP_420,
+        testName);
+      doTest(35, 39, bi ? _3byteFormatsBI : _3byteFormats, TJ.SAMP_440,
+        testName);
+      doTest(39, 41, bi ? _4byteFormatsBI : _4byteFormats, TJ.SAMP_440,
+        testName);
+      doTest(35, 39, bi ? onlyGrayBI : onlyGray, TJ.SAMP_GRAY, testName);
+      doTest(39, 41, bi ? _3byteFormatsBI : _3byteFormats, TJ.SAMP_GRAY,
+        testName);
+      doTest(41, 35, bi ? _4byteFormatsBI : _4byteFormats, TJ.SAMP_GRAY,
+        testName);
+      if(!doyuv && !bi) bufSizeTest();
+      if(doyuv && !bi) {
+        yuv = YUVDECODE;
+        doTest(48, 48, onlyRGB, TJ.SAMP_444, "javatest_yuv0");
+        doTest(35, 39, onlyRGB, TJ.SAMP_444, "javatest_yuv1");
+        doTest(48, 48, onlyRGB, TJ.SAMP_422, "javatest_yuv0");
+        doTest(39, 41, onlyRGB, TJ.SAMP_422, "javatest_yuv1");
+        doTest(48, 48, onlyRGB, TJ.SAMP_420, "javatest_yuv0");
+        doTest(41, 35, onlyRGB, TJ.SAMP_420, "javatest_yuv1");
+        doTest(48, 48, onlyRGB, TJ.SAMP_440, "javatest_yuv0");
+        doTest(35, 39, onlyRGB, TJ.SAMP_440, "javatest_yuv1");
+        doTest(48, 48, onlyRGB, TJ.SAMP_GRAY, "javatest_yuv0");
+        doTest(35, 39, onlyRGB, TJ.SAMP_GRAY, "javatest_yuv1");
+        doTest(48, 48, onlyGray, TJ.SAMP_GRAY, "javatest_yuv0");
+        doTest(39, 41, onlyGray, TJ.SAMP_GRAY, "javatest_yuv1");
+      }
+    }
+    catch(Exception e) {
+      e.printStackTrace();
+      exitStatus = -1;
+    }
+    System.exit(exitStatus);
+  }
+}

Source/LibJPEGTurbo/java/doc/allclasses-frame.html

+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+<!--NewPage-->
+<HTML>
+<HEAD>
+<!-- Generated by javadoc (build 1.6.0_33) on Fri Jun 29 14:29:14 CDT 2012 -->
+<TITLE>
+All Classes
+</TITLE>
+
+<META NAME="date" CONTENT="2012-06-29">
+
+<LINK REL ="stylesheet" TYPE="text/css" HREF="stylesheet.css" TITLE="Style">
+
+
+</HEAD>
+
+<BODY BGCOLOR="white">
+<FONT size="+1" CLASS="FrameHeadingFont">
+<B>All Classes</B></FONT>
+<BR>
+
+<TABLE BORDER="0" WIDTH="100%" SUMMARY="">
+<TR>
+<TD NOWRAP><FONT CLASS="FrameItemFont"><A HREF="org/libjpegturbo/turbojpeg/TJ.html" title="class in org.libjpegturbo.turbojpeg" target="classFrame">TJ</A>
+<BR>
+<A HREF="org/libjpegturbo/turbojpeg/TJCompressor.html" title="class in org.libjpegturbo.turbojpeg" target="classFrame">TJCompressor</A>
+<BR>
+<A HREF="org/libjpegturbo/turbojpeg/TJCustomFilter.html" title="interface in org.libjpegturbo.turbojpeg" target="classFrame"><I>TJCustomFilter</I></A>
+<BR>
+<A HREF="org/libjpegturbo/turbojpeg/TJDecompressor.html" title="class in org.libjpegturbo.turbojpeg" target="classFrame">TJDecompressor</A>
+<BR>
+<A HREF="org/libjpegturbo/turbojpeg/TJScalingFactor.html" title="class in org.libjpegturbo.turbojpeg" target="classFrame">TJScalingFactor</A>
+<BR>
+<A HREF="org/libjpegturbo/turbojpeg/TJTransform.html" title="class in org.libjpegturbo.turbojpeg" target="classFrame">TJTransform</A>
+<BR>
+<A HREF="org/libjpegturbo/turbojpeg/TJTransformer.html" title="class in org.libjpegturbo.turbojpeg" target="classFrame">TJTransformer</A>
+<BR>
+</FONT></TD>
+</TR>
+</TABLE>
+
+</BODY>
+</HTML>

Source/LibJPEGTurbo/java/doc/allclasses-noframe.html

+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+<!--NewPage-->
+<HTML>
+<HEAD>
+<!-- Generated by javadoc (build 1.6.0_33) on Fri Jun 29 14:29:14 CDT 2012 -->
+<TITLE>
+All Classes
+</TITLE>
+
+<META NAME="date" CONTENT="2012-06-29">
+
+<LINK REL ="stylesheet" TYPE="text/css" HREF="stylesheet.css" TITLE="Style">
+
+
+</HEAD>
+
+<BODY BGCOLOR="white">
+<FONT size="+1" CLASS="FrameHeadingFont">
+<B>All Classes</B></FONT>
+<BR>
+
+<TABLE BORDER="0" WIDTH="100%" SUMMARY="">
+<TR>
+<TD NOWRAP><FONT CLASS="FrameItemFont"><A HREF="org/libjpegturbo/turbojpeg/TJ.html" title="class in org.libjpegturbo.turbojpeg">TJ</A>
+<BR>
+<A HREF="org/libjpegturbo/turbojpeg/TJCompressor.html" title="class in org.libjpegturbo.turbojpeg">TJCompressor</A>
+<BR>
+<A HREF="org/libjpegturbo/turbojpeg/TJCustomFilter.html" title="interface in org.libjpegturbo.turbojpeg"><I>TJCustomFilter</I></A>
+<BR>
+<A HREF="org/libjpegturbo/turbojpeg/TJDecompressor.html" title="class in org.libjpegturbo.turbojpeg">TJDecompressor</A>
+<BR>
+<A HREF="org/libjpegturbo/turbojpeg/TJScalingFactor.html" title="class in org.libjpegturbo.turbojpeg">TJScalingFactor</A>
+<BR>
+<A HREF="org/libjpegturbo/turbojpeg/TJTransform.html" title="class in org.libjpegturbo.turbojpeg">TJTransform</A>
+<BR>
+<A HREF="org/libjpegturbo/turbojpeg/TJTransformer.html" title="class in org.libjpegturbo.turbojpeg">TJTransformer</A>
+<BR>
+</FONT></TD>
+</TR>
+</TABLE>
+
+</BODY>
+</HTML>

Source/LibJPEGTurbo/java/doc/constant-values.html

+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+<!--NewPage-->
+<HTML>
+<HEAD>
+<!-- Generated by javadoc (build 1.6.0_33) on Fri Jun 29 14:29:14 CDT 2012 -->
+<TITLE>
+Constant Field Values
+</TITLE>
+
+<META NAME="date" CONTENT="2012-06-29">
+
+<LINK REL ="stylesheet" TYPE="text/css" HREF="stylesheet.css" TITLE="Style">
+
+<SCRIPT type="text/javascript">
+function windowTitle()
+{
+    if (location.href.indexOf('is-external=true') == -1) {
+        parent.document.title="Constant Field Values";
+    }
+}
+</SCRIPT>
+<NOSCRIPT>
+</NOSCRIPT>
+
+</HEAD>
+
+<BODY BGCOLOR="white" onload="windowTitle();">
+<HR>
+
+
+<!-- ========= START OF TOP NAVBAR ======= -->
+<A NAME="navbar_top"><!-- --></A>
+<A HREF="#skip-navbar_top" title="Skip navigation links"></A>
+<TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0" SUMMARY="">
+<TR>
+<TD COLSPAN=2 BGCOLOR="#EEEEFF" CLASS="NavBarCell1">
+<A NAME="navbar_top_firstrow"><!-- --></A>
+<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3" SUMMARY="">
+  <TR ALIGN="center" VALIGN="top">
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="org/libjpegturbo/turbojpeg/package-summary.html"><FONT CLASS="NavBarFont1"><B>Package</B></FONT></A>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <FONT CLASS="NavBarFont1">Class</FONT>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="org/libjpegturbo/turbojpeg/package-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="index-all.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A>&nbsp;</TD>
+  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A>&nbsp;</TD>
+  </TR>
+</TABLE>
+</TD>
+<TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM>
+</EM>
+</TD>
+</TR>
+
+<TR>
+<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
+&nbsp;PREV&nbsp;
+&nbsp;NEXT</FONT></TD>