Mozilla Home
Privacy
Cookies
Legal
Bugzilla
Browse
Advanced Search
New Bug
Reports
Documentation
Log In
Log In with GitHub
or
Remember me
Browse
Advanced Search
New Bug
Reports
Documentation
Attachment 522449 Details for
Bug 573948
Interdiff v1.3.1 -> v2.0 part 1
interdiff (text/plain), 869.19 KB, created by
Justin Lebar (not reading bugmail)
(
hide
)
Description:
Interdiff v1.3.1 -> v2.0 part 1
Filename:
MIME Type:
Creator:
Justin Lebar (not reading bugmail)
Size:
869.19 KB
patch
obsolete
>--- b/jpeg/BUILDING.txt >+++ /dev/null >@@ -1,328 +0,0 @@ >-******************************************************************************* >-** Building on Unix Platforms, Cygwin, and MinGW >-******************************************************************************* >- >-================== >-Build Requirements >-================== >- >--- autoconf 2.56 or later >--- automake 1.7 or later >--- libtool 1.4 or later >- * If using MinGW, these can be obtained by installing the MSYS DTK >- >--- NASM >- * 0.98 or later is required for a 32-bit build >- * NASM 2.05 or later is required for a 64-bit build >- * NASM 2.07 or later is required for a 64-bit build on OS/X. This can be >- obtained from MacPorts (http://www.macports.org/). >- >- The NASM 2.05 RPMs do not work on older Linux systems, such as Enterprise >- Linux 4. On such systems, you can easily build and install NASM 2.05 >- from the source RPM by executing the following as root: >- >- ARCH=`uname -m` >- wget http://www.nasm.us/pub/nasm/releasebuilds/2.05.01/nasm-2.05.01-1.src.rpm >- rpmbuild --rebuild nasm-2.05.01-1.src.rpm >- rpm -Uvh /usr/src/redhat/RPMS/$ARCH/nasm-2.05.01-1.$ARCH.rpm >- >- NOTE: NASM build will fail if texinfo is not installed. >- >--- GCC v4.1 or later recommended for best performance >- >-====================== >-Building libjpeg-turbo >-====================== >- >-The following procedure will build libjpeg-turbo on Linux, FreeBSD, 32-bit >-OS X, and Solaris/x86 systems (on Solaris, this generates a 32-bit library. >-See below for 64-bit build instructions.) >- >- cd libjpeg-turbo >- autoreconf -fiv >- sh ./configure >- make >- >-NOTE: Running autoreconf is only necessary if building libjpeg-turbo from the >-SVN repository. >- >-This will generate the following files under .libs/ >- >- libjpeg.a >- Static link library for libjpeg-turbo >- >- libjpeg.so.62.0.0 (Linux, Solaris) >- libjpeg.62.dylib (OS X) >- libjpeg-62.dll (MinGW) >- cygjpeg-62.dll (Cygwin) >- Shared library for libjpeg-turbo >- >- libjpeg.so (Linux, Solaris) >- libjpeg.dylib (OS X) >- libjpeg.dll.a (Cygwin, MinGW) >- Development stub for libjpeg-turbo shared library >- >- libturbojpeg.a >- Static link library for TurboJPEG/OSS >- >- libturbojpeg.so (Linux, Solaris) >- libturbojpeg.dylib (OS X) >- Shared library and development stub for TurboJPEG/OSS >- >- libturbojpeg.dll (MinGW) >- cygturbojpeg.dll (Cygwin) >- Shared library for TurboJPEG/OSS >- >- libturbojpeg.dll.a (Cygwin, MinGW) >- Development stub for TurboJPEG/OSS shared library >- >-======================== >-Installing libjpeg-turbo >-======================== >- >-If you intend to install these libraries and the associated header files, then >-replace 'make' in the instructions above with >- >- make install prefix={base dir} libdir={library directory} >- >-For example, >- >- make install prefix=/usr/local libdir=/usr/local/lib64 >- >-will install the header files in /usr/local/include and the library files in >-/usr/local/lib64. If 'prefix' and 'libdir' are not specified, then the default >-is to install the header files in /opt/libjpeg-turbo/include and the library >-files in /opt/libjpeg-turbo/lib. >- >-NOTE: You can specify a prefix of /usr and a libdir of, for instance, >-/usr/lib64 to overwrite the system's version of libjpeg. If you do this, >-however, then be sure to BACK UP YOUR SYSTEM'S INSTALLATION OF LIBJPEG before >-overwriting it. It is recommended that you instead install libjpeg-turbo into >-a non-system directory and manipulate the LD_LIBRARY_PATH or create sym links >-to force applications to use libjpeg-turbo instead of libjpeg. See >-README-turbo.txt for more information. >- >-============= >-Build Recipes >-============= >- >-32-bit Library Build on 64-bit Linux >------------------------------------- >- >-Add >- >- --host i686-pc-linux-gnu CFLAGS='-O3 -m32' CXXFLAGS='-O3 -m32' LDFLAGS=-m32 >- >-to the configure command line. >- >- >-64-bit Library Build on 64-bit OS/X >------------------------------------ >- >-Add >- >- --host x86_64-apple-darwin NASM=/opt/local/bin/nasm >- >-to the configure command line. NASM 2.07 or later from MacPorts must be >-installed. >- >- >-32-bit Library Build on 64-bit OS/X >------------------------------------ >- >-Add >- >- CFLAGS='-O3 -m32' CXXFLAGS='-O3 -m32' LDFLAGS=-m32 >- >-to the configure command line. >- >- >-64-bit Backward-Compatible Library Build on 64-bit OS/X >-------------------------------------------------------- >- >-Add >- >- --host x86_64-apple-darwin NASM=/opt/local/bin/nasm \ >- CFLAGS='-isysroot /Developer/SDKs/MacOSX10.4u.sdk \ >- -mmacosx-version-min=10.4 -O3' \ >- CXXFLAGS='-isysroot /Developer/SDKs/MacOSX10.4u.sdk \ >- -mmacosx-version-min=10.4 -O3' \ >- LDFLAGS='-isysroot /Developer/SDKs/MacOSX10.4u.sdk \ >- -mmacosx-version-min=10.4' >- >-to the configure command line. The OS X 10.4 SDK, and NASM 2.07 or later from >-MacPorts, must be installed. >- >- >-32-bit Backward-Compatible Library Build on OS/X >------------------------------------------------- >- >-Add >- >- CFLAGS='-isysroot /Developer/SDKs/MacOSX10.4u.sdk \ >- -mmacosx-version-min=10.4 -O3 -m32' \ >- CXXFLAGS='-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' >- >-to the configure command line. The OS X 10.4 SDK must be installed. >- >- >-64-bit Library Build on 64-bit Solaris >--------------------------------------- >- >-Add >- >- --host x86_64-pc-solaris CFLAGS='-O3 -m64' CXXFLAGS='-O3 -m64' LDFLAGS=-m64 >- >-to the configure command line. >- >- >-32-bit Library Build on 64-bit FreeBSD >--------------------------------------- >- >-Add >- >- --host i386-unknown-freebsd CC='gcc -B /usr/lib32' CXX='g++ -B/usr/lib32' \ >- CFLAGS='-O3 -m32' CXXFLAGS='-O3 -m32' LDFLAGS='-B/usr/lib32' >- >-to the configure command line. NASM 2.07 or later from FreeBSD ports must be >-installed. >- >- >-MinGW Build on Cygwin >---------------------- >- >-Add >- >- --host mingw32 >- >-to the configure command line. This will produce libraries which do not >-depend on cygwin1.dll or other Cygwin DLL's. >- >- >-Sun Studio >----------- >- >-Add >- >- CC=cc CXX=CC >- >-to the configure command line. libjpeg-turbo will automatically be built with >-the maximum optimization level (-xO5) unless you override CFLAGS and CXXFLAGS. >- >-To build a 64-bit version of libjpeg-turbo using Sun Studio, add >- >- --host x86_64-pc-solaris CC=cc CXX=CC CFLAGS='-xO5 -m64' \ >- CXXFLAGS='-xO5 -m64' LDFLAGS=-m64 >- >-to the configure command line. >- >- >-******************************************************************************* >-** Building on Windows (Visual C++) >-******************************************************************************* >- >-================== >-Build Requirements >-================== >- >--- GNU Make v3.7 or later >- * Can be found in MSYS (http://www.mingw.org/download.shtml) or >- Cygwin (http://www.cygwin.com/) >- >--- Windows SDK for Windows Server 2008 and .NET Framework 3.5 (or a later >- version) >- >- http://msdn.microsoft.com/en-us/windows/dd146047.aspx >- >- * The Windows SDK includes both 32-bit and 64-bit Visual C++ compilers and >- everything necessary to build libjpeg-turbo. If you do not already have >- Visual C++ installed, then this is the recommended solution. Also tested >- with Microsoft Visual C++ 2008 Express Edition (both are free downloads.) >- * Add the compiler and SDK binary directories (for instance, >- c:\Program Files\Microsoft Visual Studio 9.0\VC\BIN; >- c:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE; >- c:\Program Files\Microsoft SDKs\Windows\v6.1\bin) >- to the system or user PATH environment variable prior to building >- libjpeg-turbo. >- * Add the compiler and SDK include directories (for instance, >- c:\Program Files\Microsoft Visual Studio 9.0\VC\INCLUDE; >- c:\Program Files\Microsoft SDKs\Windows\v6.1\include) >- to the system or user INCLUDE environment variable prior to building >- libjpeg-turbo. >- * Add the compiler library directory (for instance, >- c:\Program Files\Microsoft Visual Studio 9.0\VC\LIB; >- c:\Program Files\Microsoft SDKs\Windows\v6.1\lib) >- to the system or user LIB environment variable prior to building >- libjpeg-turbo. >- >--- NASM (http://www.nasm.us/) 0.98 or later (NASM 2.05 or later is required for >- a 64-bit build) >- >-====================== >-Building libjpeg-turbo >-====================== >- >- cd libjpeg-turbo >- make -f win/Makefile >- >-This will generate the following files under libjpeg-turbo\windows\: >- >- jpeg-static.lib Static link library for libjpeg-turbo >- jpeg62.dll Shared library for libjpeg-turbo >- jpeg.lib Development stub for libjpeg-turbo shared library >- turbojpeg-static.lib Static link library for TurboJPEG/OSS >- turbojpeg.dll Shared library for TurboJPEG/OSS >- turbojpeg.lib Development stub for TurboJPEG/OSS shared library >- >-If a 64-bit Windows platform is detected, then the build system will attempt >-to build a 64-bit version of libjpeg-turbo. You can override this by running >- >- make -f win/Makefile WIN64=no >- >- >-******************************************************************************* >-** Creating Release Packages >-******************************************************************************* >- >-The following commands can be used to create various types of release packages: >- >-make rpm >- >- Create RedHat-style binary RPM package. Requires RPM v4 or later. >- >-make srpm >- >- This runs 'make dist' to create a pristine source tarball, then creates a >- RedHat-style source RPM package from the tarball. Requires RPM v4 or later. >- >-make deb >- >- Create Debian-style binary package. Requires dpkg. >- >-make dmg >- >- Create Macintosh package/disk image. This requires the PackageMaker >- application, which must be installed in /Developer/Applications/Utilities. >- >-make udmg >- >- On 64-bit OS X systems, this creates a version of the Macintosh package and >- disk image which contains universal i386/x86-64 binaries. The 32-bit fork of >- these binaries is backward compatible with OS X 10.4 and later. The 64-bit >- fork can be made backward compatible as well by using the instructions in >- the "Build Recipes" section. OS X 10.4 compatibility SDK required. >- >-make nsi >- >- When using MinGW, this creates a Win32 installer for the GCC version of the >- libjpeg-turbo SDK. This requires the Nullsoft Install System >- (http://nsis.sourceforge.net/.) makensis.exe should be in your PATH. >- >-make -f win/Makefile nsi >- >- This creates a Win32 installer for the Visual C++ version of the >- libjpeg-turbo SDK. This requires the Nullsoft Install System >- (http://nsis.sourceforge.net/.) makensis.exe should be in your PATH. >--- b/jpeg/ChangeLog.txt >+++ /dev/null >@@ -1,51 +0,0 @@ >-Significant changes since 1.0.0 >-=============================== >- >-[1] The Huffman decoder will now handle erroneous Huffman codes (for instance, >-from a corrupt JPEG image.) Previously, these would cause libjpeg-turbo to >-crash under certain circumstances. >- >-[2] Fixed typo in SIMD dispatch routines which was causing 4:2:2 upsampling to >-be used instead of 4:2:0 when decompressing JPEG images using SSE2 code. >- >- >-Significant changes since 0.0.93 >-================================ >- >-[1] 2983700: Further FreeBSD build tweaks (no longer necessary to specify >---host when configuring on a 64-bit system) >- >-[2] Created sym. links in the Unix/Linux packages so that the TurboJPEG >-include file can always be found in /opt/libjpeg-turbo/include, the 32-bit >-static libraries can always be found in /opt/libjpeg-turbo/lib32, and the >-64-bit static libraries can always be found in /opt/libjpeg-turbo/lib64. >- >-[3] The Unix/Linux distribution packages now include the libjpeg run-time >-programs (cjpeg, etc.) and man pages. >- >-[4] Created a 32-bit supplementary package for amd64 Debian systems which >-contains just the 32-bit libjpeg-turbo libraries. >- >-[5] Moved the libraries from */lib32 to */lib in the i386 Debian package. >- >-[6] Include distribution package for Cygwin >- >-[7] No longer necessary to specify --without-simd on non-x86 architectures, and >-unit tests now work on those architectures. >- >- >-Significant changes since 0.0.91 >-================================ >- >-[1] 2982659, Fixed x86-64 build on FreeBSD systems >- >-[2] 2988188: Added support for Windows 64-bit systems >- >- >-Significant changes since 0.0.90 >-================================ >- >-[1] Added documentation to .deb packages >- >-[2] 2968313: Fixed data corruption issues when decompressing large JPEG images >-and/or using buffered I/O with the libjpeg-turbo decompressor >diff -U8 b/jpeg/MOZCHANGES b/jpeg/MOZCHANGES >--- b/jpeg/MOZCHANGES >+++ b/jpeg/MOZCHANGES >@@ -9,34 +9,59 @@ >- rm -rf jpeg >- svn export --ignore-externals /path/to/libjpeg-turbo jpeg >- cd jpeg >+ $ rm -rf jpeg >+ $ svn export --ignore-externals /path/to/libjpeg-turbo jpeg >+ $ cd jpeg > >- # Remove packaging files, Windows-specific config, test images, >- # wxWindows-licensed files, and unneeded license files. >- rm -rf release win >- rm *.jpg *.ppm *.bmp bmp.c bmp.h jpegut.c jpgtest.cxx rrtimer.h rrutil.h turbojpeg.h turbojpegl.c LICENSE.txt LGPL.txt >+* Now look through the new files and rm any which are npotb. When I upgraded >+ to libjpeg-turbo 1.1.0, the only files I kept which didn't match > >- # Restore files >- hg revert --no-backup Makefile.in jconfig.h jmorecfg.h simd/Makefile.in simd/jsimdcfg.inc jchuff.c jdhuff.c jdhuff.h MOZCHANGES >+ *.c *.h *.asm *.inc > >- # Add or remove other files to sync us with the SVN repository. >- hg addremove >+ were README and README-turbo. > >+ You can easily look for all non *.c, *.h, *.asm, and *.inc files by running > >-== 8/4/2010 (initial commit, SVN r225 2010-08-07) == >+ $ hg status -nu | grep -v '\(c\|h\|asm\|inc\)$' >+ >+ Once you're comfortable that you're only deleting files you want to delete >+ (and you've hg add'ed the files you want to keep), you can nuke the remaining >+ files with >+ >+ $ hg status -nu | grep -v '\(c\|h\|asm\|inc\)$' | xargs rm >+ >+ A helpful command for finding the *.c files which aren't *currently* part of >+ the build is >+ >+ diff <(ls *.c | sort) <(grep -o '\w*\.c' Makefile.in | sort) >+ >+ of course, libjpeg-turbo might have added some new source files, so you'll >+ have to look though and figure out which of these files to keep. >+ >+* Restore files modified in the Mozilla repository. >+ >+ $ hg revert --no-backup Makefile.in jconfig.h jmorecfg.h simd/Makefile.in \ >+ simd/jsimdcfg.inc jchuff.c jdhuff.c jdhuff.h MOZCHANGES >+ >+* Update Makefile.in to build any new files. >+ >+* Finally, tell hg that we've added or removed some files: >+ >+ $ hg addremove >+ >+ >+== March 28, 2011 (initial commit, libjpeg-turbo v1.1.0 r469 2011-02-27) == > > * Modified jmorecfg.h to define UINT8, UINT16, INT16, and INT32 in terms of > prtypes to fix a build error on Windows. > > * Removed the following files which are licensed under the wxWindows license: > > bmp.c, bmp.h, jpegut.c, jpgtest.cxx, rrtimer.h, rrutil.h, turbojpeg.h, > turbojpegl.c > > * Reverted the following files to what was previously in Mozilla's tree > (nominally libjpeg 6.2): > > jchuff.c, jdhuff.c, jdhuff.h > > since the versions of these files in libjpeg-turbo are also under the > wxWindows license. (It would have been nicer to revert them to the new >- libjepg-8b code, but that doesn't easily integrate with libjepg-turbo.) >+ libjpeg-8b code, but that doesn't easily integrate with libjpeg-turbo.) >--- b/jpeg/Makefile.am >+++ /dev/null >@@ -1,211 +0,0 @@ >-lib_LTLIBRARIES = libjpeg.la libturbojpeg.la >-libjpeg_la_LDFLAGS = -version-number 62:0:0 -no-undefined >-libturbojpeg_la_LDFLAGS = -avoid-version -no-undefined >-include_HEADERS = jerror.h jmorecfg.h jpeglib.h turbojpeg.h >-nodist_include_HEADERS = jconfig.h >- >-HDRS = jchuff.h jdct.h jdhuff.h jerror.h jinclude.h jmemsys.h jmorecfg.h \ >- jpegint.h jpeglib.h jversion.h jsimd.h jsimddct.h >- >-libjpeg_la_SOURCES = $(HDRS) jcapimin.c jcapistd.c jccoefct.c jccolor.c \ >- jcdctmgr.c jchuff.c jcinit.c jcmainct.c jcmarker.c jcmaster.c \ >- jcomapi.c jcparam.c jcphuff.c jcprepct.c jcsample.c jctrans.c \ >- jdapimin.c jdapistd.c jdatadst.c jdatasrc.c jdcoefct.c jdcolor.c \ >- jddctmgr.c jdhuff.c jdinput.c jdmainct.c jdmarker.c jdmaster.c \ >- jdmerge.c jdphuff.c jdpostct.c jdsample.c jdtrans.c jerror.c \ >- jfdctflt.c jfdctfst.c jfdctint.c jidctflt.c jidctfst.c jidctint.c \ >- jidctred.c jquant1.c jquant2.c jutils.c jmemmgr.c jmemnobs.c >- >-libturbojpeg_la_SOURCES = $(libjpeg_la_SOURCES) turbojpegl.c turbojpeg.h \ >- turbojpeg-mapfile >- >-if VERSION_SCRIPT >- >-libturbojpeg_la_LDFLAGS += $(VERSION_SCRIPT_FLAG)$(srcdir)/turbojpeg-mapfile >- >-endif >- >-if WITH_SIMD >- >-SUBDIRS = simd >-libjpeg_la_LIBADD = simd/libsimd.la >-libturbojpeg_la_LIBADD = simd/libsimd.la >- >-else >- >-libjpeg_la_SOURCES += jsimd_none.c >- >-endif >- >-TSTHDRS = rrutil.h rrtimer.h >- >-bin_PROGRAMS = cjpeg djpeg jpegtran rdjpgcom wrjpgcom >-noinst_PROGRAMS = jpgtest jpegut >- >-jpgtest_SOURCES = $(TSTHDRS) jpgtest.cxx bmp.h bmp.c >- >-jpgtest_LDADD = libturbojpeg.la >- >-jpegut_SOURCES = $(TSTHDRS) jpegut.c bmp.h bmp.c >- >-jpegut_LDADD = libturbojpeg.la >- >-cjpeg_SOURCES = cdjpeg.h cderror.h cdjpeg.c cjpeg.c rdbmp.c rdgif.c \ >- rdppm.c rdswitch.c rdtarga.c >- >-cjpeg_LDADD = libjpeg.la >- >-cjpeg_CFLAGS = -DBMP_SUPPORTED -DGIF_SUPPORTED -DPPM_SUPPORTED \ >- -DTARGA_SUPPORTED >- >-djpeg_SOURCES = cdjpeg.h cderror.h cdjpeg.c djpeg.c rdcolmap.c rdswitch.c \ >- wrbmp.c wrgif.c wrppm.c wrtarga.c >- >-djpeg_LDADD = libjpeg.la >- >-djpeg_CFLAGS = -DBMP_SUPPORTED -DGIF_SUPPORTED -DPPM_SUPPORTED \ >- -DTARGA_SUPPORTED >- >-jpegtran_SOURCES = jpegtran.c rdswitch.c cdjpeg.c transupp.c transupp.h >- >-jpegtran_LDADD = libjpeg.la >- >-rdjpgcom_SOURCES = rdjpgcom.c >- >-rdjpgcom_LDADD = libjpeg.la >- >-wrjpgcom_SOURCES = wrjpgcom.c >- >-wrjpgcom_LDADD = libjpeg.la >- >- >-dist_man1_MANS = cjpeg.1 djpeg.1 jpegtran.1 rdjpgcom.1 wrjpgcom.1 >- >-DOCS= README install.doc usage.doc wizard.doc example.c libjpeg.doc \ >- structure.doc coderules.doc filelist.doc jconfig.doc change.log \ >- README-turbo.txt rdrle.c wrrle.c LICENSE.txt LGPL.txt BUILDING.txt \ >- ChangeLog.txt >- >-TESTFILES= testorig.jpg testorig.ppm testimg.bmp testimgflt.jpg \ >- testimgfst.jpg testimgint.jpg testimgp.jpg testimgfst.ppm testimgint.ppm \ >- testimg-nosimd.bmp testimgfst-nosimd.ppm testorig-nosimd.ppm \ >- testimgflt-nosimd.jpg testimgint-nosimd.jpg testimgfst-nosimd.jpg \ >- testimgp-nosimd.jpg >- >-EXTRA_DIST = win release $(DOCS) $(TESTFILES) >- >-dist-hook: >- rm -rf `find $(distdir) -name .svn` >- >- >-if WITH_SIMD >- >-test: testclean cjpeg djpeg jpegtran jpegut >- ./jpegut >- ./cjpeg -dct int -outfile testoutint.jpg $(srcdir)/testorig.ppm >- ./cjpeg -dct fast -opt -outfile testoutfst.jpg $(srcdir)/testorig.ppm >- ./cjpeg -dct float -outfile testoutflt.jpg $(srcdir)/testorig.ppm >- cmp $(srcdir)/testimgint.jpg testoutint.jpg >- cmp $(srcdir)/testimgfst.jpg testoutfst.jpg >- cmp $(srcdir)/testimgflt.jpg testoutflt.jpg >- ./djpeg -dct int -fast -ppm -outfile testoutint.ppm $(srcdir)/testorig.jpg >- ./djpeg -dct fast -ppm -outfile testoutfst.ppm $(srcdir)/testorig.jpg >- ./djpeg -dct float -ppm -outfile testoutflt.ppm $(srcdir)/testorig.jpg >- cmp $(srcdir)/testimgint.ppm testoutint.ppm >- cmp $(srcdir)/testimgfst.ppm testoutfst.ppm >- cmp $(srcdir)/testimgflt.ppm testoutflt.ppm >- ./djpeg -dct int -bmp -colors 256 -outfile testout.bmp $(srcdir)/testorig.jpg >- cmp $(srcdir)/testimg.bmp testout.bmp >- ./cjpeg -dct int -progressive -outfile testoutp.jpg $(srcdir)/testorig.ppm >- cmp $(srcdir)/testimgp.jpg testoutp.jpg >- ./jpegtran -outfile testoutt.jpg testoutp.jpg >- cmp $(srcdir)/testimgint.jpg testoutt.jpg >- >-else >- >-test: testclean cjpeg djpeg jpegtran jpegut >- ./jpegut >- ./cjpeg -dct int -outfile testoutint.jpg $(srcdir)/testorig.ppm >- ./cjpeg -dct fast -opt -outfile testoutfst.jpg $(srcdir)/testorig.ppm >- ./cjpeg -dct float -outfile testoutflt.jpg $(srcdir)/testorig.ppm >- cmp $(srcdir)/testimgint.jpg testoutint.jpg >- cmp $(srcdir)/testimgfst.jpg testoutfst.jpg >- cmp $(srcdir)/testimgflt-nosimd.jpg testoutflt.jpg >- ./djpeg -dct int -fast -ppm -outfile testoutint.ppm $(srcdir)/testorig.jpg >- ./djpeg -dct fast -ppm -outfile testoutfst.ppm $(srcdir)/testorig.jpg >- ./djpeg -dct float -ppm -outfile testoutflt.ppm $(srcdir)/testorig.jpg >- cmp $(srcdir)/testimgint.ppm testoutint.ppm >- cmp $(srcdir)/testimgfst.ppm testoutfst.ppm >- cmp $(srcdir)/testorig.ppm testoutflt.ppm >- ./djpeg -dct int -bmp -colors 256 -outfile testout.bmp $(srcdir)/testorig.jpg >- cmp $(srcdir)/testimg.bmp testout.bmp >- ./cjpeg -dct int -progressive -outfile testoutp.jpg $(srcdir)/testorig.ppm >- cmp $(srcdir)/testimgp.jpg testoutp.jpg >- ./jpegtran -outfile testoutt.jpg testoutp.jpg >- cmp $(srcdir)/testimgint.jpg testoutt.jpg >- >-endif >- >-testclean: >- rm -f testout* >- rm -f *_GRAYQ[0-9]*.bmp >- rm -f *_GRAYQ[0-9]*.ppm >- rm -f *_GRAYQ[0-9]*.jpg >- rm -f *_420Q[0-9]*.bmp >- rm -f *_420Q[0-9]*.ppm >- rm -f *_420Q[0-9]*.jpg >- rm -f *_422Q[0-9]*.bmp >- rm -f *_422Q[0-9]*.ppm >- rm -f *_422Q[0-9]*.jpg >- rm -f *_444Q[0-9]*.bmp >- rm -f *_444Q[0-9]*.ppm >- rm -f *_444Q[0-9]*.jpg >- >-rpm: all >- sh $(srcdir)/release/makerpm ${PACKAGE_NAME} ${VERSION} ${BUILD} \ >- ${RPMARCH} ${srcdir} >- >-srpm: dist-gzip >- sh $(srcdir)/release/makesrpm ${PACKAGE_NAME} ${VERSION} ${BUILD} ${srcdir} >- >-deb: all >- sh $(srcdir)/release/makedpkg ${PACKAGE_NAME} ${VERSION} ${BUILD} \ >- ${DEBARCH} ${srcdir} >- >-if X86_64 >- >-udmg: all >- sh $(srcdir)/release/makemacpkg ${PACKAGE_NAME} ${VERSION} ${BUILD} \ >- ${srcdir} universal >- >-endif >- >-dmg: all >- sh $(srcdir)/release/makemacpkg ${PACKAGE_NAME} ${VERSION} ${BUILD} ${srcdir} >- >-if X86_64 >- >-sunpkg: all >- sh $(srcdir)/release/makesunpkg ${PACKAGE_NAME} ${VERSION} ${BUILD} \ >- ${DEBARCH} ${srcdir} $(CC) $(CXX) combined >- >-nsi: all >- makensis -nocd -DVERSION=$(VERSION) -DAPPNAME=libjpeg-turbo-gcc64 \ >- -DWLIBDIR=.libs -DWSRCDIR=$(srcdir) -DWBLDDIR=. -DWHDRDIR=. -DWIN64 \ >- -DPLATFORM="GCC 64-bit" -DGCC $(srcdir)/release/libjpeg-turbo.nsi >- >-else >- >-sunpkg: all >- sh $(srcdir)/release/makesunpkg ${PACKAGE_NAME} ${VERSION} ${BUILD} \ >- ${DEBARCH} ${srcdir} $(CC) $(CXX) >- >-nsi: all >- makensis -nocd -DVERSION=$(VERSION) -DAPPNAME=libjpeg-turbo-gcc \ >- -DWLIBDIR=.libs -DWSRCDIR=$(srcdir) -DWBLDDIR=. -DWHDRDIR=. \ >- -DPLATFORM="GCC" -DGCC $(srcdir)/release/libjpeg-turbo.nsi >- >-endif >- >-cygwinpkg: all >- sh $(srcdir)/release/makecygwinpkg ${PACKAGE_NAME} ${VERSION} ${srcdir} >diff -U8 b/jpeg/Makefile.in b/jpeg/Makefile.in >--- b/jpeg/Makefile.in >+++ b/jpeg/Makefile.in >@@ -83,25 +83,22 @@ > jfdctfst.c \ > jfdctint.c \ > jidctflt.c \ > jidctfst.c \ > jidctint.c \ > jidctred.c \ > jmemmgr.c \ > jmemnobs.c \ >- jpegtran.c \ > jquant1.c \ > jquant2.c \ > jutils.c \ > $(NULL) > > # These files enable support for writing JPEGs >-# (on certain platforms, or if JPEG image encoder support is required) >-ifneq (,$(filter os2 windows,$(MOZ_WIDGET_TOOLKIT))$(filter jpeg,$(MOZ_IMG_ENCODERS))) > CSRCS += \ > jcapimin.c \ > jcapistd.c \ > jccoefct.c \ > jccolor.c \ > jcdctmgr.c \ > jchuff.c \ > jcinit.c \ >@@ -109,18 +106,16 @@ > jcmarker.c \ > jcmaster.c \ > jcparam.c \ > jcphuff.c \ > jcprepct.c \ > jcsample.c \ > $(NULL) > >-endif >- > AS=$(LIBJPEG_TURBO_AS) > ASM_SUFFIX=asm > ASFLAGS=$(LIBJPEG_TURBO_ASFLAGS) -I$(topsrcdir)/modules/libjpeg-turbo/simd/ > > ifeq ($(AS),yasm) > # yasm doesn't like -c > AS_DASH_C_FLAG= > endif >diff -U8 b/jpeg/README b/jpeg/README >--- b/jpeg/README >+++ b/jpeg/README >@@ -1,112 +1,106 @@ >-libjpeg-turbo note: This is the legacy document from the original libjpeg v6b >-release, which is included for reference. The Internet addresses given below >-are likely non-functional. For more information about the libjpeg project, >-please see http://www.ijg.org. For more information about libjpeg-turbo, >-please see http://libjpeg-turbo.virtualgl.org. >+libjpeg-turbo note: This file is mostly taken from the libjpeg v8b README >+file, and it is included only for reference. Some parts of it may not apply to >+libjpeg-turbo. Please see README-turbo.txt for information specific to the >+turbo version. > > > The Independent JPEG Group's JPEG software > ========================================== > >-README for release 6b of 27-Mar-1998 >-==================================== >- >-This distribution contains the sixth public release of the Independent JPEG >-Group's free JPEG software. You are welcome to redistribute this software and >-to use it for any purpose, subject to the conditions under LEGAL ISSUES, below. >- >-Serious users of this software (particularly those incorporating it into >-larger programs) should contact IJG at jpeg-info@uunet.uu.net to be added to >-our electronic mailing list. Mailing list members are notified of updates >-and have a chance to participate in technical discussions, etc. >- >-This software is the work of Tom Lane, Philip Gladstone, Jim Boucher, >-Lee Crocker, Julian Minguillon, Luis Ortiz, George Phillips, Davide Rossi, >-Guido Vollbeding, Ge' Weijers, and other members of the Independent JPEG >-Group. >+This distribution contains a release of the Independent JPEG Group's free JPEG >+software. You are welcome to redistribute this software and to use it for any >+purpose, subject to the conditions under LEGAL ISSUES, below. >+ >+This software is the work of Tom Lane, Guido Vollbeding, Philip Gladstone, >+Bill Allombert, Jim Boucher, Lee Crocker, Bob Friesenhahn, Ben Jackson, >+Julian Minguillon, Luis Ortiz, George Phillips, Davide Rossi, Ge' Weijers, >+and other members of the Independent JPEG Group. > > IJG is not affiliated with the official ISO JPEG standards committee. > > > DOCUMENTATION ROADMAP > ===================== > > This file contains the following sections: > > OVERVIEW General description of JPEG and the IJG software. > LEGAL ISSUES Copyright, lack of warranty, terms of distribution. > REFERENCES Where to learn more about JPEG. > ARCHIVE LOCATIONS Where to find newer versions of this software. >-RELATED SOFTWARE Other stuff you should get. > FILE FORMAT WARS Software *not* to get. > TO DO Plans for future IJG releases. > > Other documentation files in the distribution are: > > User documentation: >- install.doc How to configure and install the IJG software. >- usage.doc Usage instructions for cjpeg, djpeg, jpegtran, >+ install.txt How to configure and install the IJG software. >+ usage.txt Usage instructions for cjpeg, djpeg, jpegtran, > rdjpgcom, and wrjpgcom. >- *.1 Unix-style man pages for programs (same info as usage.doc). >- wizard.doc Advanced usage instructions for JPEG wizards only. >+ *.1 Unix-style man pages for programs (same info as usage.txt). >+ wizard.txt Advanced usage instructions for JPEG wizards only. > change.log Version-to-version change highlights. > Programmer and internal documentation: >- libjpeg.doc How to use the JPEG library in your own programs. >+ libjpeg.txt How to use the JPEG library in your own programs. > example.c Sample code for calling the JPEG library. >- structure.doc Overview of the JPEG library's internal structure. >- filelist.doc Road map of IJG files. >- coderules.doc Coding style rules --- please read if you contribute code. >+ structure.txt Overview of the JPEG library's internal structure. >+ filelist.txt Road map of IJG files. >+ coderules.txt Coding style rules --- please read if you contribute code. > >-Please read at least the files install.doc and usage.doc. Useful information >+Please read at least the files install.txt and usage.txt. Some information > can also be found in the JPEG FAQ (Frequently Asked Questions) article. See > ARCHIVE LOCATIONS below to find out where to obtain the FAQ article. > > If you want to understand how the JPEG code works, we suggest reading one or > more of the REFERENCES, then looking at the documentation files (in roughly > the order listed) before diving into the code. > > > OVERVIEW > ======== > >-This package contains C software to implement JPEG image compression and >-decompression. JPEG (pronounced "jay-peg") is a standardized compression >-method for full-color and gray-scale images. JPEG is intended for compressing >-"real-world" scenes; line drawings, cartoons and other non-realistic images >-are not its strong suit. JPEG is lossy, meaning that the output image is not >-exactly identical to the input image. Hence you must not use JPEG if you >-have to have identical output bits. However, on typical photographic images, >-very good compression levels can be obtained with no visible change, and >-remarkably high compression levels are possible if you can tolerate a >-low-quality image. For more details, see the references, or just experiment >-with various compression settings. >+This package contains C software to implement JPEG image encoding, decoding, >+and transcoding. JPEG (pronounced "jay-peg") is a standardized compression >+method for full-color and gray-scale images. JPEG's strong suit is compressing >+photographic images or other types of images which have smooth color and >+brightness transitions between neighboring pixels. Images with sharp lines or >+other abrupt features may not compress well with JPEG, and a higher JPEG >+quality may have to be used to avoid visible compression artifacts with such >+images. >+ >+JPEG is lossy, meaning that the output pixels are not necessarily identical to >+the input pixels. However, on photographic content and other "smooth" images, >+very good compression ratios can be obtained with no visible compression >+artifacts, and extremely high compression ratios are possible if you are >+willing to sacrifice image quality (by reducing the "quality" setting in the >+compressor.) > > This software implements JPEG baseline, extended-sequential, and progressive > compression processes. Provision is made for supporting all variants of these > processes, although some uncommon parameter settings aren't implemented yet. >-For legal reasons, we are not distributing code for the arithmetic-coding >-variants of JPEG; see LEGAL ISSUES. We have made no provision for supporting >-the hierarchical or lossless processes defined in the standard. >+We have made no provision for supporting the hierarchical or lossless >+processes defined in the standard. > > We provide a set of library routines for reading and writing JPEG image files, > plus two sample applications "cjpeg" and "djpeg", which use the library to > perform conversion between JPEG and some other popular image file formats. > The library is intended to be reused in other applications. > > In order to support file conversion and viewing software, we have included > considerable functionality beyond the bare JPEG coding/decoding capability; > for example, the color quantization modules are not strictly part of JPEG > decoding, but they are essential for output to colormapped file formats or > colormapped displays. These extra functions can be compiled out of the >-library if not required for a particular application. We have also included >-"jpegtran", a utility for lossless transcoding between different JPEG >-processes, and "rdjpgcom" and "wrjpgcom", two simple applications for >-inserting and extracting textual comments in JFIF files. >+library if not required for a particular application. >+ >+We have also included "jpegtran", a utility for lossless transcoding between >+different JPEG processes, and "rdjpgcom" and "wrjpgcom", two simple >+applications for inserting and extracting textual comments in JFIF files. > > The emphasis in designing this software has been on achieving portability and > flexibility, while also making it fast enough to be useful. In particular, > the software is not intended to be read as a tutorial on JPEG. (See the > REFERENCES section for introductory material.) Rather, it is intended to > be reliable, portable, industrial-strength code. We do not claim to have > achieved that goal in every aspect of the software, but we strive for it. > >@@ -129,17 +123,17 @@ > > In legalese: > > The authors make NO WARRANTY or representation, either express or implied, > with respect to this software, its quality, accuracy, merchantability, or > fitness for a particular purpose. This software is provided "AS IS", and you, > its user, assume the entire risk as to its quality and accuracy. > >-This software is copyright (C) 1991-1998, Thomas G. Lane. >+This software is copyright (C) 1991-2010, Thomas G. Lane, Guido Vollbeding. > All Rights Reserved except as specified below. > > Permission is hereby granted to use, copy, modify, and distribute this > software (or portions thereof) for any purpose, without fee, subject to these > conditions: > (1) If any part of the source code for this software is distributed, then this > README file must be included, with this copyright and no-warranty notice > unaltered; and any additions, deletions, or changes to the original files >@@ -172,27 +166,18 @@ > that you must include source code if you redistribute it. (See the file > ansi2knr.c for full details.) However, since ansi2knr.c is not needed as part > of any program generated from the IJG code, this does not limit you more than > the foregoing paragraphs do. > > The Unix configuration script "configure" was produced with GNU Autoconf. > It is copyright by the Free Software Foundation but is freely distributable. > The same holds for its supporting scripts (config.guess, config.sub, >-ltconfig, ltmain.sh). Another support script, install-sh, is copyright >-by M.I.T. but is also freely distributable. >- >-It appears that the arithmetic coding option of the JPEG spec is covered by >-patents owned by IBM, AT&T, and Mitsubishi. Hence arithmetic coding cannot >-legally be used without obtaining one or more licenses. For this reason, >-support for arithmetic coding has been removed from the free JPEG software. >-(Since arithmetic coding provides only a marginal gain over the unpatented >-Huffman mode, it is unlikely that very many implementations will support it.) >-So far as we are aware, there are no patent restrictions on the remaining >-code. >+ltmain.sh). Another support script, install-sh, is copyright by X Consortium >+but is also freely distributable. > > The IJG distribution formerly included code to read and write GIF files. > To avoid entanglement with the Unisys LZW patent, GIF reading support has > been removed altogether, and the GIF writer has been simplified to produce > "uncompressed GIFs". This technique does not use the LZW algorithm; the > resulting GIF files are larger than usual, but are readable by all standard > GIF decoders. > >@@ -208,185 +193,97 @@ >-We highly recommend reading one or more of these references before trying to >+We recommend reading one or more of these references before trying to > understand the innards of the JPEG software. > > The best short technical introduction to the JPEG compression algorithm is > Wallace, Gregory K. "The JPEG Still Picture Compression Standard", > Communications of the ACM, April 1991 (vol. 34 no. 4), pp. 30-44. > (Adjacent articles in that issue discuss MPEG motion picture compression, > applications of JPEG, and related topics.) If you don't have the CACM issue > handy, a PostScript file containing a revised version of Wallace's article is >-available at ftp://ftp.uu.net/graphics/jpeg/wallace.ps.gz. The file (actually >+available at http://www.ijg.org/files/wallace.ps.gz. The file (actually > a preprint for an article that appeared in IEEE Trans. Consumer Electronics) > omits the sample images that appeared in CACM, but it includes corrections > and some added material. Note: the Wallace article is copyright ACM and IEEE, > and it may not be used for commercial purposes. > > A somewhat less technical, more leisurely introduction to JPEG can be found in > "The Data Compression Book" by Mark Nelson and Jean-loup Gailly, published by > M&T Books (New York), 2nd ed. 1996, ISBN 1-55851-434-1. This book provides > good explanations and example C code for a multitude of compression methods > including JPEG. It is an excellent source if you are comfortable reading C > code but don't know much about data compression in general. The book's JPEG > sample code is far from industrial-strength, but when you are ready to look > at a full implementation, you've got one here... > >-The best full description of JPEG is the textbook "JPEG Still Image Data >-Compression Standard" by William B. Pennebaker and Joan L. Mitchell, published >-by Van Nostrand Reinhold, 1993, ISBN 0-442-01272-1. Price US$59.95, 638 pp. >-The book includes the complete text of the ISO JPEG standards (DIS 10918-1 >-and draft DIS 10918-2). This is by far the most complete exposition of JPEG >-in existence, and we highly recommend it. >- >-The JPEG standard itself is not available electronically; you must order a >-paper copy through ISO or ITU. (Unless you feel a need to own a certified >-official copy, we recommend buying the Pennebaker and Mitchell book instead; >-it's much cheaper and includes a great deal of useful explanatory material.) >-In the USA, copies of the standard may be ordered from ANSI Sales at (212) >-642-4900, or from Global Engineering Documents at (800) 854-7179. (ANSI >-doesn't take credit card orders, but Global does.) It's not cheap: as of >-1992, ANSI was charging $95 for Part 1 and $47 for Part 2, plus 7% >-shipping/handling. The standard is divided into two parts, Part 1 being the >-actual specification, while Part 2 covers compliance testing methods. Part 1 >-is titled "Digital Compression and Coding of Continuous-tone Still Images, >+The best currently available description of JPEG is the textbook "JPEG Still >+Image Data Compression Standard" by William B. Pennebaker and Joan L. >+Mitchell, published by Van Nostrand Reinhold, 1993, ISBN 0-442-01272-1. >+Price US$59.95, 638 pp. The book includes the complete text of the ISO JPEG >+standards (DIS 10918-1 and draft DIS 10918-2). >+ >+The original JPEG standard is divided into two parts, Part 1 being the actual >+specification, while Part 2 covers compliance testing methods. Part 1 is >+titled "Digital Compression and Coding of Continuous-tone Still Images, > Part 1: Requirements and guidelines" and has document numbers ISO/IEC IS > 10918-1, ITU-T T.81. Part 2 is titled "Digital Compression and Coding of > Continuous-tone Still Images, Part 2: Compliance testing" and has document > numbers ISO/IEC IS 10918-2, ITU-T T.83. > >-Some extensions to the original JPEG standard are defined in JPEG Part 3, >-a newer ISO standard numbered ISO/IEC IS 10918-3 and ITU-T T.84. IJG >-currently does not support any Part 3 extensions. >- > The JPEG standard does not specify all details of an interchangeable file > format. For the omitted details we follow the "JFIF" conventions, revision >-1.02. A copy of the JFIF spec is available from: >- Literature Department >- C-Cube Microsystems, Inc. >- 1778 McCarthy Blvd. >- Milpitas, CA 95035 >- phone (408) 944-6300, fax (408) 944-6314 >-A PostScript version of this document is available by FTP at >-ftp://ftp.uu.net/graphics/jpeg/jfif.ps.gz. There is also a plain text >-version at ftp://ftp.uu.net/graphics/jpeg/jfif.txt.gz, but it is missing >-the figures. >+1.02. JFIF 1.02 has been adopted as an Ecma International Technical Report >+and thus received a formal publication status. It is available as a free >+download in PDF format from >+http://www.ecma-international.org/publications/techreports/E-TR-098.htm. >+A PostScript version of the JFIF document is available at >+http://www.ijg.org/files/jfif.ps.gz. There is also a plain text version at >+http://www.ijg.org/files/jfif.txt.gz, but it is missing the figures. > > The TIFF 6.0 file format specification can be obtained by FTP from > ftp://ftp.sgi.com/graphics/tiff/TIFF6.ps.gz. The JPEG incorporation scheme > found in the TIFF 6.0 spec of 3-June-92 has a number of serious problems. > IJG does not recommend use of the TIFF 6.0 design (TIFF Compression tag 6). > Instead, we recommend the JPEG design proposed by TIFF Technical Note #2 >-(Compression tag 7). Copies of this Note can be obtained from ftp.sgi.com or >-from ftp://ftp.uu.net/graphics/jpeg/. It is expected that the next revision >+(Compression tag 7). Copies of this Note can be obtained from >+http://www.ijg.org/files/. It is expected that the next revision > of the TIFF spec will replace the 6.0 JPEG design with the Note's design. > Although IJG's own code does not support TIFF/JPEG, the free libtiff library >-uses our library to implement TIFF/JPEG per the Note. libtiff is available >-from ftp://ftp.sgi.com/graphics/tiff/. >+uses our library to implement TIFF/JPEG per the Note. > > > ARCHIVE LOCATIONS > ================= > >-The "official" archive site for this software is ftp.uu.net (Internet >-address 192.48.96.9). The most recent released version can always be found >-there in directory graphics/jpeg. This particular version will be archived >-as ftp://ftp.uu.net/graphics/jpeg/jpegsrc.v6b.tar.gz. If you don't have >-direct Internet access, UUNET's archives are also available via UUCP; contact >-help@uunet.uu.net for information on retrieving files that way. >- >-Numerous Internet sites maintain copies of the UUNET files. However, only >-ftp.uu.net is guaranteed to have the latest official version. >- >-You can also obtain this software in DOS-compatible "zip" archive format from >-the SimTel archives (ftp://ftp.simtel.net/pub/simtelnet/msdos/graphics/), or >-on CompuServe in the Graphics Support forum (GO CIS:GRAPHSUP), library 12 >-"JPEG Tools". Again, these versions may sometimes lag behind the ftp.uu.net >-release. >- >-The JPEG FAQ (Frequently Asked Questions) article is a useful source of >-general information about JPEG. It is updated constantly and therefore is >-not included in this distribution. The FAQ is posted every two weeks to >-Usenet newsgroups comp.graphics.misc, news.answers, and other groups. >+The "official" archive site for this software is www.ijg.org. >+The most recent released version can always be found there in >+directory "files". This particular version will be archived as >+http://www.ijg.org/files/jpegsrc.v8b.tar.gz, and in Windows-compatible >+"zip" archive format as http://www.ijg.org/files/jpegsr8b.zip. >+ >+The JPEG FAQ (Frequently Asked Questions) article is a source of some >+general information about JPEG. > It is available on the World Wide Web at http://www.faqs.org/faqs/jpeg-faq/ > and other news.answers archive sites, including the official news.answers > archive at rtfm.mit.edu: ftp://rtfm.mit.edu/pub/usenet/news.answers/jpeg-faq/. > If you don't have Web or FTP access, send e-mail to mail-server@rtfm.mit.edu > with body > send usenet/news.answers/jpeg-faq/part1 > send usenet/news.answers/jpeg-faq/part2 > > >-RELATED SOFTWARE >-================ >- >-Numerous viewing and image manipulation programs now support JPEG. (Quite a >-few of them use this library to do so.) The JPEG FAQ described above lists >-some of the more popular free and shareware viewers, and tells where to >-obtain them on Internet. >- >-If you are on a Unix machine, we highly recommend Jef Poskanzer's free >-PBMPLUS software, which provides many useful operations on PPM-format image >-files. In particular, it can convert PPM images to and from a wide range of >-other formats, thus making cjpeg/djpeg considerably more useful. The latest >-version is distributed by the NetPBM group, and is available from numerous >-sites, notably ftp://wuarchive.wustl.edu/graphics/graphics/packages/NetPBM/. >-Unfortunately PBMPLUS/NETPBM is not nearly as portable as the IJG software is; >-you are likely to have difficulty making it work on any non-Unix machine. >- >-A different free JPEG implementation, written by the PVRG group at Stanford, >-is available from ftp://havefun.stanford.edu/pub/jpeg/. This program >-is designed for research and experimentation rather than production use; >-it is slower, harder to use, and less portable than the IJG code, but it >-is easier to read and modify. Also, the PVRG code supports lossless JPEG, >-which we do not. (On the other hand, it doesn't do progressive JPEG.) >- >- > FILE FORMAT WARS > ================ > >-Some JPEG programs produce files that are not compatible with our library. >-The root of the problem is that the ISO JPEG committee failed to specify a >-concrete file format. Some vendors "filled in the blanks" on their own, >-creating proprietary formats that no one else could read. (For example, none >-of the early commercial JPEG implementations for the Macintosh were able to >-exchange compressed files.) >- >-The file format we have adopted is called JFIF (see REFERENCES). This format >-has been agreed to by a number of major commercial JPEG vendors, and it has >-become the de facto standard. JFIF is a minimal or "low end" representation. >-We recommend the use of TIFF/JPEG (TIFF revision 6.0 as modified by TIFF >-Technical Note #2) for "high end" applications that need to record a lot of >-additional data about an image. TIFF/JPEG is fairly new and not yet widely >-supported, unfortunately. >- >-The upcoming JPEG Part 3 standard defines a file format called SPIFF. >-SPIFF is interoperable with JFIF, in the sense that most JFIF decoders should >-be able to read the most common variant of SPIFF. SPIFF has some technical >-advantages over JFIF, but its major claim to fame is simply that it is an >-official standard rather than an informal one. At this point it is unclear >-whether SPIFF will supersede JFIF or whether JFIF will remain the de-facto >-standard. IJG intends to support SPIFF once the standard is frozen, but we >-have not decided whether it should become our default output format or not. >-(In any case, our decoder will remain capable of reading JFIF indefinitely.) >- >-Various proprietary file formats incorporating JPEG compression also exist. >-We have little or no sympathy for the existence of these formats. Indeed, >+The ISO JPEG standards committee actually promotes different formats like >+"JPEG 2000" or "JPEG XR" which are incompatible with original DCT-based >+JPEG. IJG therefore does not support these formats (see REFERENCES). Indeed, > one of the original reasons for developing this free software was to help >-force convergence on common, open format standards for JPEG files. Don't >-use a proprietary file format! >+force convergence on common, interoperable format standards for JPEG files. >+Don't use an incompatible file format! >+(In any case, our decoder will remain capable of reading existing JPEG >+image files indefinitely.) > > > TO DO > ===== > >-The major thrust for v7 will probably be improvement of visual quality. >-The current method for scaling the quantization tables is known not to be >-very good at low Q values. We also intend to investigate block boundary >-smoothing, "poor man's variable quantization", and other means of improving >-quality-vs-file-size performance without sacrificing compatibility. >- >-In future versions, we are considering supporting some of the upcoming JPEG >-Part 3 extensions --- principally, variable quantization and the SPIFF file >-format. >- >-As always, speeding things up is of great interest. >- >-Please send bug reports, offers of help, etc. to jpeg-info@uunet.uu.net. >+Please send bug reports, offers of help, etc. to jpeg-info@uc.ag. >diff -U8 b/jpeg/README-turbo.txt b/jpeg/README-turbo.txt >--- b/jpeg/README-turbo.txt >+++ b/jpeg/README-turbo.txt >@@ -1,57 +1,63 @@ > ******************************************************************************* > ** Background > ******************************************************************************* > >-libjpeg-turbo is a high-speed version of libjpeg for x86 and x86-64 processors >-which uses SIMD instructions (MMX, SSE2, etc.) to accelerate baseline JPEG >-compression and decompression. libjpeg-turbo is generally 2-4x as fast >+libjpeg-turbo is a derivative of libjpeg which uses SIMD instructions (MMX, >+SSE2, etc.) to accelerate baseline JPEG compression and decompression on x86 >+and x86-64 systems. On such systems, libjpeg-turbo is generally 2-4x as fast > as the unmodified version of libjpeg, all else being equal. > > libjpeg-turbo was originally based on libjpeg/SIMD by Miyasaka Masaru, but >-the TigerVNC and VirtualGL projects made numerous enhancements to the codec, >-including improved support for Mac OS X, 64-bit support, support for 32-bit >-and big endian pixel formats, accelerated Huffman encoding/decoding, and >-various bug fixes. The goal was to produce a fully open source codec that >-could replace the partially closed source TurboJPEG/IPP codec used by VirtualGL >-and TurboVNC. libjpeg-turbo generally performs in the range of 80-120% of >-TurboJPEG/IPP. It is faster in some areas but slower in others. >- >-It was decided to split libjpeg-turbo into a separate SDK so that other >-projects could take advantage of this technology. The libjpeg-turbo shared >+the TigerVNC and VirtualGL projects made numerous enhancements to the codec in >+2009, including improved support for Mac OS X, 64-bit support, support for >+32-bit and big endian pixel formats (RGBX, XBGR, etc.), accelerated Huffman >+encoding/decoding, and various bug fixes. The goal was to produce a fully open >+source codec that could replace the partially closed source TurboJPEG/IPP codec >+used by VirtualGL and TurboVNC. libjpeg-turbo generally performs in the range >+of 80-120% of TurboJPEG/IPP. It is faster in some areas but slower in others. >+ >+In early 2010, libjpeg-turbo spun off into its own independent project, with >+the goal of making high-speed JPEG compression/decompression technology >+available to a broader range of users and developers. The libjpeg-turbo shared > libraries can be used as drop-in replacements for libjpeg on most systems. > > > ******************************************************************************* > ** License > ******************************************************************************* > >-Some of the optimizations to the Huffman encoder/decoder were borrowed from >-VirtualGL, and thus the libjpeg-turbo distribution, as a whole, falls under the >-wxWindows Library Licence, Version 3.1. A copy of this license can be found in >-this directory under LICENSE.txt. The wxWindows Library License is based on >-the LGPL but includes provisions which allow the Library to be statically >-linked into proprietary libraries and applications without requiring the >-resulting binaries to be distributed under the terms of the LGPL. >- >-The rest of the source code, apart from these modifications, falls under a less >-restrictive, BSD-style license (see README.) >+The TurboJPEG/OSS wrapper, as well as some of the optimizations to the Huffman >+encoder (jchuff.c) and decoder (jdhuff.c), were borrowed from VirtualGL, and >+thus any distribution of libjpeg-turbo which includes those files must, as a >+whole, be subject to the terms of the wxWindows Library Licence, Version 3.1. >+A copy of this license can be found in this directory under LICENSE.txt. The >+wxWindows Library License is based on the LGPL but includes provisions which >+allow the Library to be statically linked into proprietary libraries and >+applications without requiring the resulting binaries to be distributed under >+the terms of the LGPL. >+ >+The rest of the source code, apart from TurboJPEG/OSS and the Huffman codec >+optimizations, falls under a less restrictive, BSD-style license (see README.) >+You can choose to distribute libjpeg-turbo, as a whole, under this BSD-style >+license by simply removing TurboJPEG/OSS and replacing the optimized jchuff.c >+and jdhuff.c with their unoptimized counterparts from the libjpeg v6b source. > > > ******************************************************************************* > ** Using libjpeg-turbo > ******************************************************************************* > > ============================= > Replacing libjpeg at Run Time > ============================= > > If a Unix application is dynamically linked with libjpeg, then you can replace >-libjpeg with libjpeg-turbo at run time by manipulating the LD_LIBRARY_PATH. >+libjpeg with libjpeg-turbo at run time by manipulating LD_LIBRARY_PATH. > For instance: > > [Using libjpeg] > > time cjpeg <vgl_5674_0098.ppm >vgl_5674_0098.jpg > real 0m0.392s > user 0m0.074s > sys 0m0.020s > >@@ -65,125 +71,122 @@ > NOTE: {lib} can be lib, lib32, lib64, or lib/64, depending on the O/S and > architecture. > > System administrators can also replace the libjpeg sym links in /usr/{lib} with > links to the libjpeg dynamic library located in /opt/libjpeg-turbo/{lib}. This > will effectively accelerate every dynamically linked libjpeg application on the > system. > >-The Windows distribution of the libjpeg-turbo SDK installs jpeg62.dll into >-c:\libjpeg-turbo\bin, and the PATH environment variable can be modified such >-that this directory is searched before any others that might contain >-jpeg62.dll. However, if jpeg62.dll also exists in an application's install >-directory, then Windows will load the application's version of it first. Thus, >-if an application ships with jpeg62.dll, then back up the application's version >-of jpeg62.dll and copy c:\libjpeg-turbo\bin\jpeg62.dll into the application's >-install directory to accelerate it. >- >-The version of jpeg62.dll distributed in the libjpeg-turbo SDK requires the >-Visual C++ 2008 C run time DLL (msvcr90.dll). This library ships with more >-recent versions of Windows, but users of older versions can obtain it from the >-Visual C++ 2008 Redistributable Package, which is available as a free download >-from Microsoft's web site. >+The libjpeg-turbo SDK for Visual C++ installs the libjpeg-turbo DLL >+(jpeg62.dll, jpeg7.dll, or jpeg8.dll, depending on whether libjpeg v6b, v7, or >+v8 emulation is enabled) into c:\libjpeg-turbo[64]\bin, and the PATH >+environment variable can be modified such that this directory is searched >+before any others that might contain a libjpeg DLL. However, if a libjpeg >+DLL exists in an application's install directory, then Windows will load this >+DLL first whenever the application is launched. Thus, if an application ships >+with jpeg62.dll, jpeg7.dll, or jpeg8.dll, then back up the application's >+version of this DLL and copy c:\libjpeg-turbo[64]\bin\jpeg*.dll into the >+application's install directory to accelerate it. >+ >+The version of the libjpeg-turbo DLL distributed in the libjpeg-turbo SDK for >+Visual C++ 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. > > NOTE: Features of libjpeg which require passing a C run time structure, such > as a file handle, from an application to libjpeg will probably not work with >-the distributed version of 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(). >+the version of the libjpeg-turbo DLL distributed in the libjpeg-turbo SDK for >+Visual C++, 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 applications typically embed their own copies of libjpeg.62.dylib inside >+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. If an application uses a shared library version of > libjpeg, then it may be possible to replace the application's version of it. >-This would generally involve copying libjpeg.62.dylib into the appropriate >-place in the application bundle and using install_name_tool to repoint the >-dylib to the 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. >+This 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 dylib to the 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. > > ======================= > Replacing TurboJPEG/IPP > ======================= > > libjpeg-turbo is a drop-in replacement for the TurboJPEG/IPP SDK used by > VirtualGL 2.1.x and TurboVNC 0.6 (and prior.) libjpeg-turbo contains a wrapper > library (TurboJPEG/OSS) that emulates the TurboJPEG API using libjpeg-turbo > instead of the closed source Intel Performance Primitives. You can replace the > TurboJPEG/IPP package on Linux systems with the libjpeg-turbo package in order >-to make existing releases of VirtualGL 2.1.x and TurboVNC use the new codec at >-run time. Note that the 64-bit libjpeg-turbo packages contain only 64-bit >+to make existing releases of VirtualGL 2.1.x and TurboVNC 0.x use the new codec >+at run time. Note that the 64-bit libjpeg-turbo packages contain only 64-bit > binaries, whereas the TurboJPEG/IPP 64-bit packages contained both 64-bit and > 32-bit binaries. Thus, to replace a TurboJPEG/IPP 64-bit package, install > both the 64-bit and 32-bit versions of libjpeg-turbo. > > You can also build the VirtualGL 2.1.x and TurboVNC 0.6 source code with > the libjpeg-turbo SDK instead of TurboJPEG/IPP. It should work identically. > libjpeg-turbo also includes static library versions of TurboJPEG/OSS, which > are used to build TurboVNC 1.0 and later. > > ======================================== > 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 Unix systems, you can build against libjpeg-turbo instead >-of libjpeg by setting >+libjpeg-turbo. On Unix systems (including 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 Cygwin, then set >- >- CPATH=/cygdrive/c/libjpeg-turbo-gcc[64]/include >- and >- LIBRARY_PATH=/cygdrive/c/libjpeg-turbo-gcc[64]/lib >- > 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 Linux and Solaris systems, you would still need to manipulate the >-LD_LIBRARY_PATH or sym links appropriately 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 >+On Linux and Solaris systems, you would still need to manipulate >+LD_LIBRARY_PATH or create appropriate sym links 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 Linux, Solaris, 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 (this also works on Linux and Solaris.) > > To build Visual C++ applications using libjpeg-turbo, add >-c:\libjpeg-turbo[64]\include to your system or user INCLUDE environment >-variable and c:\libjpeg-turbo[64]\lib to your system or user LIB environment >-variable, and then link against either jpeg.lib (to use jpeg62.dll) or >-jpeg-static.lib (to use the static version of libjpeg-turbo.) >+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 > ===================== > > libjpeg-turbo includes extensions which allow JPEG images to be compressed >-directly from (and decompressed directly to) buffers which use BGR, BGRA, >-RGBA, ABGR, and ARGB pixel ordering. This is implemented with six new >+directly from (and decompressed directly to) buffers which use BGR, BGRX, >+RGBX, XBGR, and XRGB pixel ordering. This is implemented with six new > colorspace constants: > > JCS_EXT_RGB /* red/green/blue */ > JCS_EXT_RGBX /* red/green/blue/x */ > JCS_EXT_BGR /* blue/green/red */ > JCS_EXT_BGRX /* blue/green/red/x */ > JCS_EXT_XBGR /* x/blue/green/red */ > JCS_EXT_XRGB /* x/red/green/blue */ >@@ -202,0 +206,99 @@ >+ >+================================= >+libjpeg v7 and v8 API/ABI support >+================================= >+ >+libjpeg v7 and v8 added new features to the API/ABI, and, unfortunately, the >+compression and decompression structures were extended in a backward- >+incompatible manner to accommodate these features. Thus, programs which are >+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 >+as widely used as v6b, enough programs (including a few Linux distros) have >+made the switch that it was desirable to provide support for the libjpeg v7/v8 >+API/ABI in libjpeg-turbo. >+ >+Some of the libjpeg v7 and v8 features -- DCT scaling, to name one -- involve >+deep modifications to the code which cannot be accommodated by libjpeg-turbo >+without either breaking compatibility with libjpeg v6b or producing an >+unsupportable mess. In order to fully support libjpeg v8 with all of its >+features, we would have to essentially port the SIMD extensions to the libjpeg >+v8 code base and maintain two separate code trees. We are hesitant to do this >+until/unless the newer libjpeg code bases garner more community support and >+involvement and until/unless we have some notion of whether future libjpeg >+releases will also be backward-incompatible. >+ >+By passing an argument of --with-jpeg7 or --with-jpeg8 to configure, or an >+argument of -DWITH_JPEG7=1 or -DWITH_JPEG8=1 to cmake, you can build a version >+of libjpeg-turbo which emulates the libjpeg v7 or v8 API/ABI, so that programs >+which are built against libjpeg v7 or v8 can be run with libjpeg-turbo. The >+following section describes which libjpeg v7+ features are supported and which >+aren't. >+ >+libjpeg v7 and v8 Features: >+--------------------------- >+ >+Fully supported: >+ >+-- cjpeg: Separate quality settings for luminance and chrominance >+ Note that the libpjeg v7+ API was extended to accommodate this feature only >+ for convenience purposes. It has always been possible to implement this >+ feature with libjpeg v6b (see rdswitch.c for an example.) >+ >+-- cjpeg: 32-bit BMP support >+ >+-- jpegtran: lossless cropping >+ >+-- jpegtran: -perfect option >+ >+-- rdjpgcom: -raw option >+ >+-- rdjpgcom: locale awareness >+ >+ >+Fully supported when using libjpeg v7/v8 emulation: >+ >+-- libjpeg: In-memory source and destination managers >+ >+ >+Not supported: >+ >+-- libjpeg: DCT scaling in compressor >+ cinfo.scale_num and cinfo.scale_denom are silently ignored. >+ >+-- libjpeg: IDCT scaling extensions in decompressor >+ libjpeg-turbo still supports IDCT scaling with scaling factors of 1/2, 1/4, >+ and 1/8 (same as libjpeg v6b.) >+ >+-- libjpeg: Fancy downsampling in compressor >+ cinfo.do_fancy_downsampling is silently ignored. >+ >+-- jpegtran: Scaling >+ Seems to depend on the DCT scaling feature, which isn't supported. >+ >+ >+******************************************************************************* >+** Performance pitfalls >+******************************************************************************* >+ >+=============== >+Restart Markers >+=============== >+ >+The optimized Huffman decoder in libjpeg-turbo does not handle restart markers >+in a way that makes libjpeg happy, so it is necessary to use the slow Huffman >+decoder when decompressing a JPEG image that has restart markers. This can >+cause the decompression performance to drop by as much as 20%, but the >+performance will still be much much greater than that of libjpeg v6b. Many >+consumer packages, such as PhotoShop, use restart markers when generating JPEG >+images, so images generated by those programs will experience this issue. >+ >+=============================================== >+Fast Integer Forward DCT at High Quality Levels >+=============================================== >+ >+The algorithm used by the SIMD-accelerated quantization function cannot produce >+correct results whenever the fast integer forward DCT is used along with a JPEG >+quality of 98-100. Thus, libjpeg-turbo must use the non-SIMD quantization >+function in those cases. This causes performance to drop by as much as 40%. >+It is therefore strongly advised that you use the slow integer forward DCT >+whenever encoding images with a JPEG quality of 98 or higher. >--- b/jpeg/acinclude.m4 >+++ /dev/null >@@ -1,136 +0,0 @@ >-# AC_PROG_NASM >-# -------------------------- >-# Check that NASM exists and determine flags >-AC_DEFUN([AC_PROG_NASM],[ >- >-AC_CHECK_PROGS(NASM, [nasm nasmw]) >-test -z "$NASM" && AC_MSG_ERROR([no nasm (Netwide Assembler) found]) >- >-AC_MSG_CHECKING([for object file format of host system]) >-case "$host_os" in >- cygwin* | mingw* | pw32* | interix*) >- case "$host_cpu" in >- x86_64) >- objfmt='Win64-COFF' >- ;; >- *) >- objfmt='Win32-COFF' >- ;; >- esac >- ;; >- msdosdjgpp* | go32*) >- objfmt='COFF' >- ;; >- os2-emx*) # not tested >- objfmt='MSOMF' # obj >- ;; >- linux*coff* | linux*oldld*) >- objfmt='COFF' # ??? >- ;; >- linux*aout*) >- objfmt='a.out' >- ;; >- linux*) >- case "$host_cpu" in >- x86_64) >- objfmt='ELF64' >- ;; >- *) >- objfmt='ELF' >- ;; >- esac >- ;; >- freebsd* | netbsd* | openbsd*) >- if echo __ELF__ | $CC -E - | grep __ELF__ > /dev/null; then >- objfmt='BSD-a.out' >- else >- case "$host_cpu" in >- x86_64 | amd64) >- objfmt='ELF64' >- ;; >- *) >- objfmt='ELF' >- ;; >- esac >- fi >- ;; >- solaris* | sunos* | sysv* | sco*) >- case "$host_cpu" in >- x86_64) >- objfmt='ELF64' >- ;; >- *) >- objfmt='ELF' >- ;; >- esac >- ;; >- darwin* | rhapsody* | nextstep* | openstep* | macos*) >- case "$host_cpu" in >- x86_64) >- objfmt='Mach-O64' >- ;; >- *) >- objfmt='Mach-O' >- ;; >- esac >- ;; >- *) >- objfmt='ELF ?' >- ;; >-esac >- >-AC_MSG_RESULT([$objfmt]) >-if test "$objfmt" = 'ELF ?'; then >- objfmt='ELF' >- AC_MSG_WARN([unexpected host system. assumed that the format is $objfmt.]) >-fi >- >-AC_MSG_CHECKING([for object file format specifier (NAFLAGS) ]) >-case "$objfmt" in >- MSOMF) NAFLAGS='-fobj -DOBJ32';; >- Win32-COFF) NAFLAGS='-fwin32 -DWIN32';; >- Win64-COFF) NAFLAGS='-fwin64 -DWIN64 -D__x86_64__';; >- COFF) NAFLAGS='-fcoff -DCOFF';; >- a.out) NAFLAGS='-faout -DAOUT';; >- BSD-a.out) NAFLAGS='-faoutb -DAOUT';; >- ELF) NAFLAGS='-felf -DELF';; >- ELF64) NAFLAGS='-felf64 -DELF -D__x86_64__';; >- RDF) NAFLAGS='-frdf -DRDF';; >- Mach-O) NAFLAGS='-fmacho -DMACHO';; >- Mach-O64) NAFLAGS='-fmacho64 -DMACHO -D__x86_64__';; >-esac >-AC_MSG_RESULT([$NAFLAGS]) >-AC_SUBST([NAFLAGS]) >- >-AC_MSG_CHECKING([whether the assembler ($NASM $NAFLAGS) works]) >-cat > conftest.asm <<EOF >-[%line __oline__ "configure" >- section .text >- global _main,main >-_main: >-main: xor eax,eax >- ret >-]EOF >-try_nasm='$NASM $NAFLAGS -o conftest.o conftest.asm' >-if AC_TRY_EVAL(try_nasm) && test -s conftest.o; then >- AC_MSG_RESULT(yes) >-else >- echo "configure: failed program was:" >&AC_FD_CC >- cat conftest.asm >&AC_FD_CC >- rm -rf conftest* >- AC_MSG_RESULT(no) >- AC_MSG_ERROR([installation or configuration problem: assembler cannot create object files.]) >-fi >- >-AC_MSG_CHECKING([whether the linker accepts assembler output]) >-try_nasm='${CC-cc} -o conftest${ac_exeext} $LDFLAGS conftest.o $LIBS 1>&AC_FD_CC' >-if AC_TRY_EVAL(try_nasm) && test -s conftest${ac_exeext}; then >- rm -rf conftest* >- AC_MSG_RESULT(yes) >-else >- rm -rf conftest* >- AC_MSG_RESULT(no) >- AC_MSG_ERROR([configuration problem: maybe object file format mismatch.]) >-fi >- >-]) >--- b/jpeg/cjpeg.1 >+++ /dev/null >@@ -1,292 +0,0 @@ >-.TH CJPEG 1 "20 March 1998" >-.SH NAME >-cjpeg \- compress an image file to a JPEG file >-.SH SYNOPSIS >-.B cjpeg >-[ >-.I options >-] >-[ >-.I filename >-] >-.LP >-.SH DESCRIPTION >-.LP >-.B cjpeg >-compresses the named image file, or the standard input if no file is >-named, and produces a JPEG/JFIF file on the standard output. >-The currently supported input file formats are: PPM (PBMPLUS color >-format), PGM (PBMPLUS gray-scale format), BMP, Targa, and RLE (Utah Raster >-Toolkit format). (RLE is supported only if the URT library is available.) >-.SH OPTIONS >-All switch names may be abbreviated; for example, >-.B \-grayscale >-may be written >-.B \-gray >-or >-.BR \-gr . >-Most of the "basic" switches can be abbreviated to as little as one letter. >-Upper and lower case are equivalent (thus >-.B \-BMP >-is the same as >-.BR \-bmp ). >-British spellings are also accepted (e.g., >-.BR \-greyscale ), >-though for brevity these are not mentioned below. >-.PP >-The basic switches are: >-.TP >-.BI \-quality " N" >-Scale quantization tables to adjust image quality. Quality is 0 (worst) to >-100 (best); default is 75. (See below for more info.) >-.TP >-.B \-grayscale >-Create monochrome JPEG file from color input. Be sure to use this switch when >-compressing a grayscale BMP file, because >-.B cjpeg >-isn't bright enough to notice whether a BMP file uses only shades of gray. >-By saying >-.BR \-grayscale , >-you'll get a smaller JPEG file that takes less time to process. >-.TP >-.B \-optimize >-Perform optimization of entropy encoding parameters. Without this, default >-encoding parameters are used. >-.B \-optimize >-usually makes the JPEG file a little smaller, but >-.B cjpeg >-runs somewhat slower and needs much more memory. Image quality and speed of >-decompression are unaffected by >-.BR \-optimize . >-.TP >-.B \-progressive >-Create progressive JPEG file (see below). >-.TP >-.B \-targa >-Input file is Targa format. Targa files that contain an "identification" >-field will not be automatically recognized by >-.BR cjpeg ; >-for such files you must specify >-.B \-targa >-to make >-.B cjpeg >-treat the input as Targa format. >-For most Targa files, you won't need this switch. >-.PP >-The >-.B \-quality >-switch lets you trade off compressed file size against quality of the >-reconstructed image: the higher the quality setting, the larger the JPEG file, >-and the closer the output image will be to the original input. Normally you >-want to use the lowest quality setting (smallest file) that decompresses into >-something visually indistinguishable from the original image. For this >-purpose the quality setting should be between 50 and 95; the default of 75 is >-often about right. If you see defects at >-.B \-quality >-75, then go up 5 or 10 counts at a time until you are happy with the output >-image. (The optimal setting will vary from one image to another.) >-.PP >-.B \-quality >-100 will generate a quantization table of all 1's, minimizing loss in the >-quantization step (but there is still information loss in subsampling, as well >-as roundoff error). This setting is mainly of interest for experimental >-purposes. Quality values above about 95 are >-.B not >-recommended for normal use; the compressed file size goes up dramatically for >-hardly any gain in output image quality. >-.PP >-In the other direction, quality values below 50 will produce very small files >-of low image quality. Settings around 5 to 10 might be useful in preparing an >-index of a large image library, for example. Try >-.B \-quality >-2 (or so) for some amusing Cubist effects. (Note: quality >-values below about 25 generate 2-byte quantization tables, which are >-considered optional in the JPEG standard. >-.B cjpeg >-emits a warning message when you give such a quality value, because some >-other JPEG programs may be unable to decode the resulting file. Use >-.B \-baseline >-if you need to ensure compatibility at low quality values.) >-.PP >-The >-.B \-progressive >-switch creates a "progressive JPEG" file. In this type of JPEG file, the data >-is stored in multiple scans of increasing quality. If the file is being >-transmitted over a slow communications link, the decoder can use the first >-scan to display a low-quality image very quickly, and can then improve the >-display with each subsequent scan. The final image is exactly equivalent to a >-standard JPEG file of the same quality setting, and the total file size is >-about the same --- often a little smaller. >-.B Caution: >-progressive JPEG is not yet widely implemented, so many decoders will be >-unable to view a progressive JPEG file at all. >-.PP >-Switches for advanced users: >-.TP >-.B \-dct int >-Use integer DCT method (default). >-.TP >-.B \-dct fast >-Use fast integer DCT (less accurate). >-.TP >-.B \-dct float >-Use floating-point DCT method. >-The float method is very slightly more accurate than the int method, but is >-much slower unless your machine has very fast floating-point hardware. Also >-note that results of the floating-point method may vary slightly across >-machines, while the integer methods should give the same results everywhere. >-The fast integer method is much less accurate than the other two. >-.TP >-.BI \-restart " N" >-Emit a JPEG restart marker every N MCU rows, or every N MCU blocks if "B" is >-attached to the number. >-.B \-restart 0 >-(the default) means no restart markers. >-.TP >-.BI \-smooth " N" >-Smooth the input image to eliminate dithering noise. N, ranging from 1 to >-100, indicates the strength of smoothing. 0 (the default) means no smoothing. >-.TP >-.BI \-maxmemory " N" >-Set limit for amount of memory to use in processing large images. Value is >-in thousands of bytes, or millions of bytes if "M" is attached to the >-number. For example, >-.B \-max 4m >-selects 4000000 bytes. If more space is needed, temporary files will be used. >-.TP >-.BI \-outfile " name" >-Send output image to the named file, not to standard output. >-.TP >-.B \-verbose >-Enable debug printout. More >-.BR \-v 's >-give more output. Also, version information is printed at startup. >-.TP >-.B \-debug >-Same as >-.BR \-verbose . >-.PP >-The >-.B \-restart >-option inserts extra markers that allow a JPEG decoder to resynchronize after >-a transmission error. Without restart markers, any damage to a compressed >-file will usually ruin the image from the point of the error to the end of the >-image; with restart markers, the damage is usually confined to the portion of >-the image up to the next restart marker. Of course, the restart markers >-occupy extra space. We recommend >-.B \-restart 1 >-for images that will be transmitted across unreliable networks such as Usenet. >-.PP >-The >-.B \-smooth >-option filters the input to eliminate fine-scale noise. This is often useful >-when converting dithered images to JPEG: a moderate smoothing factor of 10 to >-50 gets rid of dithering patterns in the input file, resulting in a smaller >-JPEG file and a better-looking image. Too large a smoothing factor will >-visibly blur the image, however. >-.PP >-Switches for wizards: >-.TP >-.B \-baseline >-Force baseline-compatible quantization tables to be generated. This clamps >-quantization values to 8 bits even at low quality settings. (This switch is >-poorly named, since it does not ensure that the output is actually baseline >-JPEG. For example, you can use >-.B \-baseline >-and >-.B \-progressive >-together.) >-.TP >-.BI \-qtables " file" >-Use the quantization tables given in the specified text file. >-.TP >-.BI \-qslots " N[,...]" >-Select which quantization table to use for each color component. >-.TP >-.BI \-sample " HxV[,...]" >-Set JPEG sampling factors for each color component. >-.TP >-.BI \-scans " file" >-Use the scan script given in the specified text file. >-.PP >-The "wizard" switches are intended for experimentation with JPEG. If you >-don't know what you are doing, \fBdon't use them\fR. These switches are >-documented further in the file wizard.doc. >-.SH EXAMPLES >-.LP >-This example compresses the PPM file foo.ppm with a quality factor of >-60 and saves the output as foo.jpg: >-.IP >-.B cjpeg \-quality >-.I 60 foo.ppm >-.B > >-.I foo.jpg >-.SH HINTS >-Color GIF files are not the ideal input for JPEG; JPEG is really intended for >-compressing full-color (24-bit) images. In particular, don't try to convert >-cartoons, line drawings, and other images that have only a few distinct >-colors. GIF works great on these, JPEG does not. If you want to convert a >-GIF to JPEG, you should experiment with >-.BR cjpeg 's >-.B \-quality >-and >-.B \-smooth >-options to get a satisfactory conversion. >-.B \-smooth 10 >-or so is often helpful. >-.PP >-Avoid running an image through a series of JPEG compression/decompression >-cycles. Image quality loss will accumulate; after ten or so cycles the image >-may be noticeably worse than it was after one cycle. It's best to use a >-lossless format while manipulating an image, then convert to JPEG format when >-you are ready to file the image away. >-.PP >-The >-.B \-optimize >-option to >-.B cjpeg >-is worth using when you are making a "final" version for posting or archiving. >-It's also a win when you are using low quality settings to make very small >-JPEG files; the percentage improvement is often a lot more than it is on >-larger files. (At present, >-.B \-optimize >-mode is always selected when generating progressive JPEG files.) >-.SH ENVIRONMENT >-.TP >-.B JPEGMEM >-If this environment variable is set, its value is the default memory limit. >-The value is specified as described for the >-.B \-maxmemory >-switch. >-.B JPEGMEM >-overrides the default value specified when the program was compiled, and >-itself is overridden by an explicit >-.BR \-maxmemory . >-.SH SEE ALSO >-.BR djpeg (1), >-.BR jpegtran (1), >-.BR rdjpgcom (1), >-.BR wrjpgcom (1) >-.br >-.BR ppm (5), >-.BR pgm (5) >-.br >-Wallace, Gregory K. "The JPEG Still Picture Compression Standard", >-Communications of the ACM, April 1991 (vol. 34, no. 4), pp. 30-44. >-.SH AUTHOR >-Independent JPEG Group >-.SH BUGS >-Arithmetic coding is not supported for legal reasons. >-.PP >-GIF input files are no longer supported, to avoid the Unisys LZW patent. >-Use a Unisys-licensed program if you need to read a GIF file. (Conversion >-of GIF files to JPEG is usually a bad idea anyway.) >-.PP >-Not all variants of BMP and Targa file formats are supported. >-.PP >-The >-.B \-targa >-switch is not a bug, it's a feature. (It would be a bug if the Targa format >-designers had not been clueless.) >-.PP >-Still not as fast as we'd like. >--- b/jpeg/configure.ac >+++ /dev/null >@@ -1,185 +0,0 @@ >-# -*- Autoconf -*- >-# Process this file with autoconf to produce a configure script. >- >-AC_PREREQ([2.56]) >-AC_INIT([libjpeg-turbo], [1.0.1]) >-BUILD=`date +%Y%m%d` >- >-AM_INIT_AUTOMAKE([-Wall foreign dist-bzip2]) >-AC_PREFIX_DEFAULT(/opt/libjpeg-turbo) >- >-# Always build with prototypes >-AC_DEFINE([HAVE_PROTOTYPES], 1, [Define if your compiler supports prototypes]) >-# Don't use undefined types >-AC_DEFINE([INCOMPLETE_TYPES_BROKEN], 1, [Define if you want use complete types]) >- >-# Checks for programs. >-SAVED_CFLAGS=${CFLAGS} >-SAVED_CXXFLAGS=${CXXFLAGS} >-AC_PROG_CPP >-AC_PROG_CC >-AC_PROG_CXX >-AC_PROG_INSTALL >-AC_PROG_LIBTOOL >-AC_PROG_LN_S >- >-AC_MSG_CHECKING([whether the linker supports version scripts]) >-VERSION_SCRIPT=no >-LDVER=`$LD --help </dev/null 2>&1 | grep "\-\-version-script"` >-if test "$LDVER"; then >- VERSION_SCRIPT=yes >- VERSION_SCRIPT_FLAG=-Wl,--version-script, >- AC_MSG_RESULT(yes) >-else >- LDVER=`$LD --help </dev/null 2>&1 | grep "\-M"` >- if test "$LDVER"; then >- VERSION_SCRIPT=yes >- VERSION_SCRIPT_FLAG=-Wl,-M, >- AC_MSG_RESULT(yes) >- else >- AC_MSG_RESULT(no) >- fi >-fi >- >-AM_CONDITIONAL(VERSION_SCRIPT, test "x$VERSION_SCRIPT" = "xyes") >-AC_SUBST(VERSION_SCRIPT_FLAG) >- >-if test "x${GCC}" = "xyes"; then >- if test "x${SAVED_CFLAGS}" = "x"; then >- CFLAGS=-O3 >- fi >- if test "x${SAVED_CXXFLAGS}" = "x"; then >- CXXFLAGS=-O3 >- fi >-fi >- >-AC_CHECK_DECL([__SUNPRO_C], [SUNCC="yes"], [SUNCC="no"]) >-if test "x${SUNCC}" = "xyes"; then >- if test "x${SAVED_CFLAGS}" = "x"; then >- CFLAGS=-xO5 >- fi >- if test "x${SAVED_CXXFLAGS}" = "x"; then >- CXXFLAGS=-xO5 >- fi >-fi >- >-# Checks for libraries. >- >-# Checks for header files. >-AC_HEADER_STDC >-AC_CHECK_HEADERS([stddef.h stdlib.h string.h]) >-AC_CHECK_HEADER([sys/types.h], AC_DEFINE([NEED_SYS_TYPES_H], 1, [Define if you have sys/types.h])) >- >-# Checks for typedefs, structures, and compiler characteristics. >-AC_C_CONST >-AC_C_CHAR_UNSIGNED >-AC_C_INLINE >-AC_TYPE_SIZE_T >-AC_CHECK_TYPES([unsigned char, unsigned short]) >- >-AC_MSG_CHECKING([if right shift is signed]) >-AC_TRY_RUN( >- [#include <stdio.h> >- int is_shifting_signed (long arg) { >- long res = arg >> 4; >- >- if (res == -0x7F7E80CL) >- return 1; /* right shift is signed */ >- >- /* see if unsigned-shift hack will fix it. */ >- /* we can't just test exact value since it depends on width of long... */ >- res |= (~0L) << (32-4); >- if (res == -0x7F7E80CL) >- return 0; /* right shift is unsigned */ >- >- printf("Right shift isn't acting as I expect it to.\n"); >- printf("I fear the JPEG software will not work at all.\n\n"); >- return 0; /* try it with unsigned anyway */ >- } >- int main (void) { >- exit(is_shifting_signed(-0x7F7E80B1L)); >- }], >- [AC_MSG_RESULT(no) >- AC_DEFINE([RIGHT_SHIFT_IS_UNSIGNED], 1, [Define if shift is unsigned])], >- [AC_MSG_RESULT(yes)], >- [AC_MSG_RESULT(Assuming that right shift is signed on target machine.)]) >- >-# test whether global names are unique to at least 15 chars >-AC_MSG_CHECKING([for short external names]) >-AC_TRY_LINK( >- [int possibly_duplicate_function () { return 0; } >- int possibly_dupli_function () { return 1; }], [ ], >- [AC_MSG_RESULT(ok)], >- [AC_MSG_RESULT(short) >- AC_DEFINE([NEED_SHORT_EXTERNAL_NAMES], 1, [Define if you need short function names])]) >- >-# Checks for library functions. >-AC_CHECK_FUNCS([memset memcpy], [], >- [AC_DEFINE([NEED_BSD_STRINGS], 1, >- [Define if you have BSD-like bzero and bcopy])]) >- >-# Set flags to indicate platform >-case "$host_os" in >- cygwin* | mingw* | pw32* | interix*) >- is_win32=1 >- ;; >-esac >-AM_CONDITIONAL([IS_WIN32], [test "x$is_win32" = "x1"]) >- >-# SIMD is optional >-AC_ARG_WITH([simd], >- AC_HELP_STRING([--without-simd],[Omit accelerated SIMD routines.])) >-if test "x${with_simd}" != "xno"; then >- # Check if we're on a supported CPU >- AC_MSG_CHECKING([if we have SIMD optimisations for cpu type]) >- case "$host_cpu" in >- x86_64 | amd64) >- AC_MSG_RESULT([yes (x86_64)]) >- AC_PROG_NASM >- simd_arch=x86_64 >- ;; >- i*86 | x86 | ia32) >- AC_MSG_RESULT([yes (i386)]) >- AC_PROG_NASM >- simd_arch=i386 >- ;; >- *) >- AC_MSG_RESULT([no ("$host_cpu")]) >- AC_MSG_WARN([SIMD support not available for this CPU. Performance will suffer.]) >- with_simd=no; >- ;; >- esac >- >- if test "x${with_simd}" != "xno"; then >- AC_DEFINE([WITH_SIMD], [1], [Use accelerated SIMD routines.]) >- fi >-fi >- >-AM_CONDITIONAL([WITH_SIMD], [test "x$with_simd" != "xno"]) >-AM_CONDITIONAL([SIMD_I386], [test "x$simd_arch" = "xi386"]) >-AM_CONDITIONAL([SIMD_X86_64], [test "x$simd_arch" = "xx86_64"]) >-AM_CONDITIONAL([X86_64], [test "x$host_cpu" = "xx86_64" -o "x$host_cpu" = "xamd64"]) >- >-case "$host_cpu" in >- x86_64) >- RPMARCH=x86_64 >- DEBARCH=amd64 >- ;; >- i*86 | x86 | ia32) >- RPMARCH=i386 >- DEBARCH=i386 >- ;; >-esac >- >-AC_SUBST(RPMARCH) >-AC_SUBST(DEBARCH) >-AC_SUBST(BUILD) >- >-# jconfig.h is the file we use, but we have another before that to >-# fool autoheader. the reason is that we include this header in our >-# API headers, which can screw things up for users of the lib. >-# jconfig.h is a minimal version that allows this package to be built >-AC_CONFIG_HEADERS([config.h]) >-AC_CONFIG_HEADERS([jconfig.h]) >-AC_CONFIG_FILES([Makefile simd/Makefile]) >-AC_OUTPUT >--- b/jpeg/djpeg.1 >+++ /dev/null >@@ -1,253 +0,0 @@ >-.TH DJPEG 1 "22 August 1997" >-.SH NAME >-djpeg \- decompress a JPEG file to an image file >-.SH SYNOPSIS >-.B djpeg >-[ >-.I options >-] >-[ >-.I filename >-] >-.LP >-.SH DESCRIPTION >-.LP >-.B djpeg >-decompresses the named JPEG file, or the standard input if no file is named, >-and produces an image file on the standard output. PBMPLUS (PPM/PGM), BMP, >-GIF, Targa, or RLE (Utah Raster Toolkit) output format can be selected. >-(RLE is supported only if the URT library is available.) >-.SH OPTIONS >-All switch names may be abbreviated; for example, >-.B \-grayscale >-may be written >-.B \-gray >-or >-.BR \-gr . >-Most of the "basic" switches can be abbreviated to as little as one letter. >-Upper and lower case are equivalent (thus >-.B \-BMP >-is the same as >-.BR \-bmp ). >-British spellings are also accepted (e.g., >-.BR \-greyscale ), >-though for brevity these are not mentioned below. >-.PP >-The basic switches are: >-.TP >-.BI \-colors " N" >-Reduce image to at most N colors. This reduces the number of colors used in >-the output image, so that it can be displayed on a colormapped display or >-stored in a colormapped file format. For example, if you have an 8-bit >-display, you'd need to reduce to 256 or fewer colors. >-.TP >-.BI \-quantize " N" >-Same as >-.BR \-colors . >-.B \-colors >-is the recommended name, >-.B \-quantize >-is provided only for backwards compatibility. >-.TP >-.B \-fast >-Select recommended processing options for fast, low quality output. (The >-default options are chosen for highest quality output.) Currently, this is >-equivalent to \fB\-dct fast \-nosmooth \-onepass \-dither ordered\fR. >-.TP >-.B \-grayscale >-Force gray-scale output even if JPEG file is color. Useful for viewing on >-monochrome displays; also, >-.B djpeg >-runs noticeably faster in this mode. >-.TP >-.BI \-scale " M/N" >-Scale the output image by a factor M/N. Currently the scale factor must be >-1/1, 1/2, 1/4, or 1/8. Scaling is handy if the image is larger than your >-screen; also, >-.B djpeg >-runs much faster when scaling down the output. >-.TP >-.B \-bmp >-Select BMP output format (Windows flavor). 8-bit colormapped format is >-emitted if >-.B \-colors >-or >-.B \-grayscale >-is specified, or if the JPEG file is gray-scale; otherwise, 24-bit full-color >-format is emitted. >-.TP >-.B \-gif >-Select GIF output format. Since GIF does not support more than 256 colors, >-.B \-colors 256 >-is assumed (unless you specify a smaller number of colors). >-.TP >-.B \-os2 >-Select BMP output format (OS/2 1.x flavor). 8-bit colormapped format is >-emitted if >-.B \-colors >-or >-.B \-grayscale >-is specified, or if the JPEG file is gray-scale; otherwise, 24-bit full-color >-format is emitted. >-.TP >-.B \-pnm >-Select PBMPLUS (PPM/PGM) output format (this is the default format). >-PGM is emitted if the JPEG file is gray-scale or if >-.B \-grayscale >-is specified; otherwise PPM is emitted. >-.TP >-.B \-rle >-Select RLE output format. (Requires URT library.) >-.TP >-.B \-targa >-Select Targa output format. Gray-scale format is emitted if the JPEG file is >-gray-scale or if >-.B \-grayscale >-is specified; otherwise, colormapped format is emitted if >-.B \-colors >-is specified; otherwise, 24-bit full-color format is emitted. >-.PP >-Switches for advanced users: >-.TP >-.B \-dct int >-Use integer DCT method (default). >-.TP >-.B \-dct fast >-Use fast integer DCT (less accurate). >-.TP >-.B \-dct float >-Use floating-point DCT method. >-The float method is very slightly more accurate than the int method, but is >-much slower unless your machine has very fast floating-point hardware. Also >-note that results of the floating-point method may vary slightly across >-machines, while the integer methods should give the same results everywhere. >-The fast integer method is much less accurate than the other two. >-.TP >-.B \-dither fs >-Use Floyd-Steinberg dithering in color quantization. >-.TP >-.B \-dither ordered >-Use ordered dithering in color quantization. >-.TP >-.B \-dither none >-Do not use dithering in color quantization. >-By default, Floyd-Steinberg dithering is applied when quantizing colors; this >-is slow but usually produces the best results. Ordered dither is a compromise >-between speed and quality; no dithering is fast but usually looks awful. Note >-that these switches have no effect unless color quantization is being done. >-Ordered dither is only available in >-.B \-onepass >-mode. >-.TP >-.BI \-map " file" >-Quantize to the colors used in the specified image file. This is useful for >-producing multiple files with identical color maps, or for forcing a >-predefined set of colors to be used. The >-.I file >-must be a GIF or PPM file. This option overrides >-.B \-colors >-and >-.BR \-onepass . >-.TP >-.B \-nosmooth >-Use a faster, lower-quality upsampling routine. >-.TP >-.B \-onepass >-Use one-pass instead of two-pass color quantization. The one-pass method is >-faster and needs less memory, but it produces a lower-quality image. >-.B \-onepass >-is ignored unless you also say >-.B \-colors >-.IR N . >-Also, the one-pass method is always used for gray-scale output (the two-pass >-method is no improvement then). >-.TP >-.BI \-maxmemory " N" >-Set limit for amount of memory to use in processing large images. Value is >-in thousands of bytes, or millions of bytes if "M" is attached to the >-number. For example, >-.B \-max 4m >-selects 4000000 bytes. If more space is needed, temporary files will be used. >-.TP >-.BI \-outfile " name" >-Send output image to the named file, not to standard output. >-.TP >-.B \-verbose >-Enable debug printout. More >-.BR \-v 's >-give more output. Also, version information is printed at startup. >-.TP >-.B \-debug >-Same as >-.BR \-verbose . >-.SH EXAMPLES >-.LP >-This example decompresses the JPEG file foo.jpg, quantizes it to >-256 colors, and saves the output in 8-bit BMP format in foo.bmp: >-.IP >-.B djpeg \-colors 256 \-bmp >-.I foo.jpg >-.B > >-.I foo.bmp >-.SH HINTS >-To get a quick preview of an image, use the >-.B \-grayscale >-and/or >-.B \-scale >-switches. >-.B \-grayscale \-scale 1/8 >-is the fastest case. >-.PP >-Several options are available that trade off image quality to gain speed. >-.B \-fast >-turns on the recommended settings. >-.PP >-.B \-dct fast >-and/or >-.B \-nosmooth >-gain speed at a small sacrifice in quality. >-When producing a color-quantized image, >-.B \-onepass \-dither ordered >-is fast but much lower quality than the default behavior. >-.B \-dither none >-may give acceptable results in two-pass mode, but is seldom tolerable in >-one-pass mode. >-.PP >-If you are fortunate enough to have very fast floating point hardware, >-\fB\-dct float\fR may be even faster than \fB\-dct fast\fR. But on most >-machines \fB\-dct float\fR is slower than \fB\-dct int\fR; in this case it is >-not worth using, because its theoretical accuracy advantage is too small to be >-significant in practice. >-.SH ENVIRONMENT >-.TP >-.B JPEGMEM >-If this environment variable is set, its value is the default memory limit. >-The value is specified as described for the >-.B \-maxmemory >-switch. >-.B JPEGMEM >-overrides the default value specified when the program was compiled, and >-itself is overridden by an explicit >-.BR \-maxmemory . >-.SH SEE ALSO >-.BR cjpeg (1), >-.BR jpegtran (1), >-.BR rdjpgcom (1), >-.BR wrjpgcom (1) >-.br >-.BR ppm (5), >-.BR pgm (5) >-.br >-Wallace, Gregory K. "The JPEG Still Picture Compression Standard", >-Communications of the ACM, April 1991 (vol. 34, no. 4), pp. 30-44. >-.SH AUTHOR >-Independent JPEG Group >-.SH BUGS >-Arithmetic coding is not supported for legal reasons. >-.PP >-To avoid the Unisys LZW patent, >-.B djpeg >-produces uncompressed GIF files. These are larger than they should be, but >-are readable by standard GIF decoders. >-.PP >-Still not as fast as we'd like. >diff -U8 b/jpeg/jccolor.c b/jpeg/jccolor.c >--- b/jpeg/jccolor.c >+++ b/jpeg/jccolor.c >@@ -78,17 +78,17 @@ > #define R_CR_OFF B_CB_OFF /* B=>Cb, R=>Cr are the same */ > #define G_CR_OFF (6*(MAXJSAMPLE+1)) > #define B_CR_OFF (7*(MAXJSAMPLE+1)) > #define TABLE_SIZE (8*(MAXJSAMPLE+1)) > > > #if BITS_IN_JSAMPLE == 8 > >-const unsigned char red_lut[256] = { >+static const unsigned char red_lut[256] = { > 0 , 0 , 1 , 1 , 1 , 1 , 2 , 2 , 2 , 3 , 3 , 3 , 4 , 4 , 4 , 4 , > 5 , 5 , 5 , 6 , 6 , 6 , 7 , 7 , 7 , 7 , 8 , 8 , 8 , 9 , 9 , 9 , > 10, 10, 10, 10, 11, 11, 11, 12, 12, 12, 13, 13, 13, 13, 14, 14, > 14, 15, 15, 15, 16, 16, 16, 16, 17, 17, 17, 18, 18, 18, 19, 19, > 19, 19, 20, 20, 20, 21, 21, 21, 22, 22, 22, 22, 23, 23, 23, 24, > 24, 24, 25, 25, 25, 25, 26, 26, 26, 27, 27, 27, 28, 28, 28, 28, > 29, 29, 29, 30, 30, 30, 30, 31, 31, 31, 32, 32, 32, 33, 33, 33, > 33, 34, 34, 34, 35, 35, 35, 36, 36, 36, 36, 37, 37, 37, 38, 38, >@@ -97,17 +97,17 @@ > 48, 48, 48, 49, 49, 49, 50, 50, 50, 51, 51, 51, 51, 52, 52, 52, > 53, 53, 53, 54, 54, 54, 54, 55, 55, 55, 56, 56, 56, 57, 57, 57, > 57, 58, 58, 58, 59, 59, 59, 60, 60, 60, 60, 61, 61, 61, 62, 62, > 62, 62, 63, 63, 63, 64, 64, 64, 65, 65, 65, 65, 66, 66, 66, 67, > 67, 67, 68, 68, 68, 68, 69, 69, 69, 70, 70, 70, 71, 71, 71, 71, > 72, 72, 72, 73, 73, 73, 74, 74, 74, 74, 75, 75, 75, 76, 76, 76 > }; > >-const unsigned char green_lut[256] = { >+static const unsigned char green_lut[256] = { > 0 , 1 , 1 , 2 , 2 , 3 , 4 , 4 , 5 , 5 , 6 , 6 , > 7 , 8 , 8 , 9 , 9 , 10 , 11 , 11 , 12 , 12 , 13 , 14 , > 14 , 15 , 15 , 16 , 16 , 17 , 18 , 18 , 19 , 19 , 20 , 21 , > 21 , 22 , 22 , 23 , 23 , 24 , 25 , 25 , 26 , 26 , 27 , 28 , > 28 , 29 , 29 , 30 , 31 , 31 , 32 , 32 , 33 , 33 , 34 , 35 , > 35 , 36 , 36 , 37 , 38 , 38 , 39 , 39 , 40 , 41 , 41 , 42 , > 42 , 43 , 43 , 44 , 45 , 45 , 46 , 46 , 47 , 48 , 48 , 49 , > 49 , 50 , 50 , 51 , 52 , 52 , 53 , 53 , 54 , 55 , 55 , 56 , >@@ -117,22 +117,22 @@ > 77 , 78 , 79 , 79 , 80 , 80 , 81 , 82 , 82 , 83 , 83 , 84 , > 85 , 85 , 86 , 86 , 87 , 87 , 88 , 89 , 89 , 90 , 90 , 91 , > 92 , 92 , 93 , 93 , 94 , 95 , 95 , 96 , 96 , 97 , 97 , 98 , > 99 , 99 , 100, 100, 101, 102, 102, 103, 103, 104, 104, 105, > 106, 106, 107, 107, 108, 109, 109, 110, 110, 111, 112, 112, > 113, 113, 114, 114, 115, 116, 116, 117, 117, 118, 119, 119, > 120, 120, 121, 122, 122, 123, 123, 124, 124, 125, 126, 126, > 127, 127, 128, 129, 129, 130, 130, 131, 131, 132, 133, 133, >- 34, 134, 135, 136, 136, 137, 137, 138, 139, 139, 140, 140, >+ 134, 134, 135, 136, 136, 137, 137, 138, 139, 139, 140, 140, > 141, 141, 142, 143, 143, 144, 144, 145, 146, 146, 147, 147, > 148, 149, 149, 150 > }; > >-const unsigned char blue_lut[256] = { >+static const unsigned char blue_lut[256] = { > 0 , 0 , 0 , 0 , 0 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 2 , 2 , > 2 , 2 , 2 , 2 , 2 , 2 , 3 , 3 , 3 , 3 , 3 , 3 , 3 , 3 , 3 , 4 , > 4 , 4 , 4 , 4 , 4 , 4 , 4 , 4 , 5 , 5 , 5 , 5 , 5 , 5 , 5 , 5 , > 5 , 6 , 6 , 6 , 6 , 6 , 6 , 6 , 6 , 6 , 7 , 7 , 7 , 7 , 7 , 7 , > 7 , 7 , 8 , 8 , 8 , 8 , 8 , 8 , 8 , 8 , 8 , 9 , 9 , 9 , 9 , 9 , > 9 , 9 , 9 , 9 , 10, 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, > 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, > 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, >@@ -253,24 +253,22 @@ > * We assume rgb_ycc_start has been called (we only use the Y tables). > */ > > METHODDEF(void) > rgb_gray_convert (j_compress_ptr cinfo, > JSAMPARRAY input_buf, JSAMPIMAGE output_buf, > JDIMENSION output_row, int num_rows) > { >- my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert; > #if BITS_IN_JSAMPLE != 8 > register INT32 * ctab = cconvert->rgb_ycc_tab; > #endif > register JSAMPROW inptr; > register JSAMPROW outptr; > JSAMPLE *maxoutptr; >- register JDIMENSION col; > JDIMENSION num_cols = cinfo->image_width; > int rindex = rgb_red[cinfo->in_color_space]; > int gindex = rgb_green[cinfo->in_color_space]; > int bindex = rgb_blue[cinfo->in_color_space]; > int rgbstride = rgb_pixelsize[cinfo->in_color_space]; > > while (--num_rows >= 0) { > inptr = *input_buf++; >diff -U8 b/jpeg/jcdctmgr.c b/jpeg/jcdctmgr.c >--- b/jpeg/jcdctmgr.c >+++ b/jpeg/jcdctmgr.c >@@ -1,14 +1,15 @@ > /* > * jcdctmgr.c > * > * Copyright (C) 1994-1996, Thomas G. Lane. > * Copyright (C) 1999-2006, MIYASAKA Masaru. > * Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB >+ * Copyright (C) 2011 D. R. Commander > * This file is part of the Independent JPEG Group's software. > * For conditions of distribution and use, see the accompanying README file. > * > * This file contains the forward-DCT management logic. > * This code selects a particular DCT implementation to be used, > * and it performs related housekeeping chores including coefficient > * quantization. > */ >@@ -34,16 +35,18 @@ > > typedef JMETHOD(void, quantize_method_ptr, > (JCOEFPTR coef_block, DCTELEM * divisors, > DCTELEM * workspace)); > typedef JMETHOD(void, float_quantize_method_ptr, > (JCOEFPTR coef_block, FAST_FLOAT * divisors, > FAST_FLOAT * workspace)); > >+METHODDEF(void) quantize (JCOEFPTR, DCTELEM *, DCTELEM *); >+ > typedef struct { > struct jpeg_forward_dct pub; /* public fields */ > > /* Pointer to the DCT routine actually in use */ > forward_DCT_method_ptr dct; > convsamp_method_ptr convsamp; > quantize_method_ptr quantize; > >@@ -155,17 +158,17 @@ > * The reason dctbl[2] and dctbl[3] reduce the shift with (word size) > * is that most SIMD implementations have a "multiply and store top > * half" operation. > * > * Lastly, we store each of the values in their own table instead > * of in a consecutive manner, yet again in order to allow SIMD > * routines. > */ >-LOCAL(void) >+LOCAL(int) > compute_reciprocal (UINT16 divisor, DCTELEM * dtbl) > { > UDCTELEM2 fq, fr; > UDCTELEM c; > int b, r; > > b = flss(divisor) - 1; > r = sizeof(DCTELEM) * 8 + b; >@@ -184,16 +187,19 @@ > } else { /* fractional part is > 0.5 */ > fq++; > } > > dtbl[DCTSIZE2 * 0] = (DCTELEM) fq; /* reciprocal */ > dtbl[DCTSIZE2 * 1] = (DCTELEM) c; /* correction + roundfactor */ > dtbl[DCTSIZE2 * 2] = (DCTELEM) (1 << (sizeof(DCTELEM)*8*2 - r)); /* scale */ > dtbl[DCTSIZE2 * 3] = (DCTELEM) r - sizeof(DCTELEM)*8; /* shift */ >+ >+ if(r <= 16) return 0; >+ else return 1; > } > > /* > * Initialize for a processing pass. > * Verify that all referenced Q-tables are present, and set up > * the divisor table for each one. > * In the current implementation, DCT of all components is done during > * the first pass, even if only some components will be output in the >@@ -227,17 +233,19 @@ > */ > if (fdct->divisors[qtblno] == NULL) { > fdct->divisors[qtblno] = (DCTELEM *) > (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, > (DCTSIZE2 * 4) * SIZEOF(DCTELEM)); > } > dtbl = fdct->divisors[qtblno]; > for (i = 0; i < DCTSIZE2; i++) { >- compute_reciprocal(qtbl->quantval[i] << 3, &dtbl[i]); >+ if(!compute_reciprocal(qtbl->quantval[i] << 3, &dtbl[i]) >+ && fdct->quantize == jsimd_quantize) >+ fdct->quantize = quantize; > } > break; > #endif > #ifdef DCT_IFAST_SUPPORTED > case JDCT_IFAST: > { > /* For AA&N IDCT method, divisors are equal to quantization > * coefficients scaled by scalefactor[row]*scalefactor[col], where >@@ -261,20 +269,22 @@ > > if (fdct->divisors[qtblno] == NULL) { > fdct->divisors[qtblno] = (DCTELEM *) > (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, > (DCTSIZE2 * 4) * SIZEOF(DCTELEM)); > } > dtbl = fdct->divisors[qtblno]; > for (i = 0; i < DCTSIZE2; i++) { >- compute_reciprocal( >+ if(!compute_reciprocal( > DESCALE(MULTIPLY16V16((INT32) qtbl->quantval[i], > (INT32) aanscales[i]), >- CONST_BITS-3), &dtbl[i]); >+ CONST_BITS-3), &dtbl[i]) >+ && fdct->quantize == jsimd_quantize) >+ fdct->quantize = quantize; > } > } > break; > #endif > #ifdef DCT_FLOAT_SUPPORTED > case JDCT_FLOAT: > { > /* For float AA&N IDCT method, divisors are equal to quantization >diff -U8 b/jpeg/jcmarker.c b/jpeg/jcmarker.c >--- b/jpeg/jcmarker.c >+++ b/jpeg/jcmarker.c >@@ -1,21 +1,23 @@ > /* > * jcmarker.c > * > * Copyright (C) 1991-1998, Thomas G. Lane. >+ * Copyright (C) 2010, D. R. Commander. > * This file is part of the Independent JPEG Group's software. > * For conditions of distribution and use, see the accompanying README file. > * > * This file contains routines to write JPEG datastream markers. > */ > > #define JPEG_INTERNALS > #include "jinclude.h" > #include "jpeglib.h" >+#include "jpegcomp.h" > > > typedef enum { /* JPEG marker codes */ > M_SOF0 = 0xc0, > M_SOF1 = 0xc1, > M_SOF2 = 0xc2, > M_SOF3 = 0xc3, > >@@ -280,23 +282,23 @@ > int ci; > jpeg_component_info *compptr; > > emit_marker(cinfo, code); > > emit_2bytes(cinfo, 3 * cinfo->num_components + 2 + 5 + 1); /* length */ > > /* Make sure image isn't bigger than SOF field can handle */ >- if ((long) cinfo->image_height > 65535L || >- (long) cinfo->image_width > 65535L) >+ if ((long) cinfo->_jpeg_height > 65535L || >+ (long) cinfo->_jpeg_width > 65535L) > ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) 65535); > > emit_byte(cinfo, cinfo->data_precision); >- emit_2bytes(cinfo, (int) cinfo->image_height); >- emit_2bytes(cinfo, (int) cinfo->image_width); >+ emit_2bytes(cinfo, (int) cinfo->_jpeg_height); >+ emit_2bytes(cinfo, (int) cinfo->_jpeg_width); > > emit_byte(cinfo, cinfo->num_components); > > for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; > ci++, compptr++) { > emit_byte(cinfo, compptr->component_id); > emit_byte(cinfo, (compptr->h_samp_factor << 4) + compptr->v_samp_factor); > emit_byte(cinfo, compptr->quant_tbl_no); >diff -U8 b/jpeg/jconfig.h b/jpeg/jconfig.h >--- b/jpeg/jconfig.h >+++ b/jpeg/jconfig.h >@@ -1,9 +1,14 @@ >-/* jconfig.h. Generated from jconfig.h.in by configure. */ >+/* jconfig.h. Generated from jconfig.h.in by configure, then manually edited >+ for Mozilla. */ >+ >+/* Export libjpeg v6.2's ABI. */ >+#define JPEG_LIB_VERSION 62 >+ > /* Define if your compiler supports prototypes */ > #define HAVE_PROTOTYPES 1 > > /* Define to 1 if you have the <stddef.h> header file. */ > #define HAVE_STDDEF_H 1 > > /* Define to 1 if you have the <stdlib.h> header file. */ > #define HAVE_STDLIB_H 1 >diff -U8 b/jpeg/jconfig.h.in b/jpeg/jconfig.h.in >--- b/jpeg/jconfig.h.in >+++ b/jpeg/jconfig.h.in >@@ -1,8 +1,19 @@ >+/* Version ID for the JPEG library. >+ * Might be useful for tests like "#if JPEG_LIB_VERSION >= 60". >+ */ >+#define JPEG_LIB_VERSION 62 /* Version 6b */ >+ >+/* Support arithmetic encoding */ >+#undef C_ARITH_CODING_SUPPORTED >+ >+/* Support arithmetic decoding */ >+#undef D_ARITH_CODING_SUPPORTED >+ > /* Define if your compiler supports prototypes */ > #undef HAVE_PROTOTYPES > > /* Define to 1 if you have the <stddef.h> header file. */ > #undef HAVE_STDDEF_H > > /* Define to 1 if you have the <stdlib.h> header file. */ > #undef HAVE_STDLIB_H >diff -U8 b/jpeg/jcparam.c b/jpeg/jcparam.c >--- b/jpeg/jcparam.c >+++ b/jpeg/jcparam.c >@@ -1,13 +1,14 @@ > /* > * jcparam.c > * > * Copyright (C) 1991-1998, Thomas G. Lane. >- * Copyright (C) 2009, D. R. Commander. >+ * Modified 2003-2008 by Guido Vollbeding. >+ * Copyright (C) 2009-2010, D. R. Commander. > * This file is part of the Independent JPEG Group's software. > * For conditions of distribution and use, see the accompanying README file. > * > * This file contains optional default-setting code for the JPEG compressor. > * Applications do not have to use this file, but those that don't use it > * must know a lot more about the innards of the JPEG code. > */ > >@@ -56,50 +57,68 @@ > (*qtblptr)->quantval[i] = (UINT16) temp; > } > > /* Initialize sent_table FALSE so table will be written to JPEG file. */ > (*qtblptr)->sent_table = FALSE; > } > > >+/* These are the sample quantization tables given in JPEG spec section K.1. >+ * The spec says that the values given produce "good" quality, and >+ * when divided by 2, "very good" quality. >+ */ >+static const unsigned int std_luminance_quant_tbl[DCTSIZE2] = { >+ 16, 11, 10, 16, 24, 40, 51, 61, >+ 12, 12, 14, 19, 26, 58, 60, 55, >+ 14, 13, 16, 24, 40, 57, 69, 56, >+ 14, 17, 22, 29, 51, 87, 80, 62, >+ 18, 22, 37, 56, 68, 109, 103, 77, >+ 24, 35, 55, 64, 81, 104, 113, 92, >+ 49, 64, 78, 87, 103, 121, 120, 101, >+ 72, 92, 95, 98, 112, 100, 103, 99 >+}; >+static const unsigned int std_chrominance_quant_tbl[DCTSIZE2] = { >+ 17, 18, 24, 47, 99, 99, 99, 99, >+ 18, 21, 26, 66, 99, 99, 99, 99, >+ 24, 26, 56, 99, 99, 99, 99, 99, >+ 47, 66, 99, 99, 99, 99, 99, 99, >+ 99, 99, 99, 99, 99, 99, 99, 99, >+ 99, 99, 99, 99, 99, 99, 99, 99, >+ 99, 99, 99, 99, 99, 99, 99, 99, >+ 99, 99, 99, 99, 99, 99, 99, 99 >+}; >+ >+ >+#if JPEG_LIB_VERSION >= 70 >+GLOBAL(void) >+jpeg_default_qtables (j_compress_ptr cinfo, boolean force_baseline) >+/* Set or change the 'quality' (quantization) setting, using default tables >+ * and straight percentage-scaling quality scales. >+ * This entry point allows different scalings for luminance and chrominance. >+ */ >+{ >+ /* Set up two quantization tables using the specified scaling */ >+ jpeg_add_quant_table(cinfo, 0, std_luminance_quant_tbl, >+ cinfo->q_scale_factor[0], force_baseline); >+ jpeg_add_quant_table(cinfo, 1, std_chrominance_quant_tbl, >+ cinfo->q_scale_factor[1], force_baseline); >+} >+#endif >+ >+ > GLOBAL(void) > jpeg_set_linear_quality (j_compress_ptr cinfo, int scale_factor, > boolean force_baseline) > /* Set or change the 'quality' (quantization) setting, using default tables > * and a straight percentage-scaling quality scale. In most cases it's better > * to use jpeg_set_quality (below); this entry point is provided for > * applications that insist on a linear percentage scaling. > */ > { >- /* These are the sample quantization tables given in JPEG spec section K.1. >- * The spec says that the values given produce "good" quality, and >- * when divided by 2, "very good" quality. >- */ >- static const unsigned int std_luminance_quant_tbl[DCTSIZE2] = { >- 16, 11, 10, 16, 24, 40, 51, 61, >- 12, 12, 14, 19, 26, 58, 60, 55, >- 14, 13, 16, 24, 40, 57, 69, 56, >- 14, 17, 22, 29, 51, 87, 80, 62, >- 18, 22, 37, 56, 68, 109, 103, 77, >- 24, 35, 55, 64, 81, 104, 113, 92, >- 49, 64, 78, 87, 103, 121, 120, 101, >- 72, 92, 95, 98, 112, 100, 103, 99 >- }; >- static const unsigned int std_chrominance_quant_tbl[DCTSIZE2] = { >- 17, 18, 24, 47, 99, 99, 99, 99, >- 18, 21, 26, 66, 99, 99, 99, 99, >- 24, 26, 56, 99, 99, 99, 99, 99, >- 47, 66, 99, 99, 99, 99, 99, 99, >- 99, 99, 99, 99, 99, 99, 99, 99, >- 99, 99, 99, 99, 99, 99, 99, 99, >- 99, 99, 99, 99, 99, 99, 99, 99, >- 99, 99, 99, 99, 99, 99, 99, 99 >- }; >- > /* Set up two quantization tables using the specified scaling */ > jpeg_add_quant_table(cinfo, 0, std_luminance_quant_tbl, > scale_factor, force_baseline); > jpeg_add_quant_table(cinfo, 1, std_chrominance_quant_tbl, > scale_factor, force_baseline); > } > > >@@ -280,16 +299,20 @@ > */ > if (cinfo->comp_info == NULL) > cinfo->comp_info = (jpeg_component_info *) > (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT, > MAX_COMPONENTS * SIZEOF(jpeg_component_info)); > > /* Initialize everything not dependent on the color space */ > >+#if JPEG_LIB_VERSION >= 70 >+ cinfo->scale_num = 1; /* 1:1 scaling */ >+ cinfo->scale_denom = 1; >+#endif > cinfo->data_precision = BITS_IN_JSAMPLE; > /* 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); > > /* Initialize default arithmetic coding conditioning */ > for (i = 0; i < NUM_ARITH_TBLS; i++) { >@@ -316,16 +339,21 @@ > * are supplied that are valid for the desired precision. > */ > if (cinfo->data_precision > 8) > cinfo->optimize_coding = TRUE; > > /* By default, use the simpler non-cosited sampling alignment */ > cinfo->CCIR601_sampling = FALSE; > >+#if JPEG_LIB_VERSION >= 70 >+ /* By default, apply fancy downsampling */ >+ cinfo->do_fancy_downsampling = TRUE; >+#endif >+ > /* No input smoothing */ > cinfo->smoothing_factor = 0; > > /* DCT algorithm preference */ > cinfo->dct_method = JDCT_DEFAULT; > > /* No restart markers */ > cinfo->restart_interval = 0; >--- b/jpeg/jctrans.c >+++ /dev/null >@@ -1,388 +0,0 @@ >-/* >- * jctrans.c >- * >- * Copyright (C) 1995-1998, Thomas G. Lane. >- * This file is part of the Independent JPEG Group's software. >- * For conditions of distribution and use, see the accompanying README file. >- * >- * This file contains library routines for transcoding compression, >- * that is, writing raw DCT coefficient arrays to an output JPEG file. >- * The routines in jcapimin.c will also be needed by a transcoder. >- */ >- >-#define JPEG_INTERNALS >-#include "jinclude.h" >-#include "jpeglib.h" >- >- >-/* Forward declarations */ >-LOCAL(void) transencode_master_selection >- JPP((j_compress_ptr cinfo, jvirt_barray_ptr * coef_arrays)); >-LOCAL(void) transencode_coef_controller >- JPP((j_compress_ptr cinfo, jvirt_barray_ptr * coef_arrays)); >- >- >-/* >- * Compression initialization for writing raw-coefficient data. >- * Before calling this, all parameters and a data destination must be set up. >- * Call jpeg_finish_compress() to actually write the data. >- * >- * The number of passed virtual arrays must match cinfo->num_components. >- * Note that the virtual arrays need not be filled or even realized at >- * the time write_coefficients is called; indeed, if the virtual arrays >- * were requested from this compression object's memory manager, they >- * typically will be realized during this routine and filled afterwards. >- */ >- >-GLOBAL(void) >-jpeg_write_coefficients (j_compress_ptr cinfo, jvirt_barray_ptr * coef_arrays) >-{ >- if (cinfo->global_state != CSTATE_START) >- ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); >- /* Mark all tables to be written */ >- jpeg_suppress_tables(cinfo, FALSE); >- /* (Re)initialize error mgr and destination modules */ >- (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo); >- (*cinfo->dest->init_destination) (cinfo); >- /* Perform master selection of active modules */ >- transencode_master_selection(cinfo, coef_arrays); >- /* Wait for jpeg_finish_compress() call */ >- cinfo->next_scanline = 0; /* so jpeg_write_marker works */ >- cinfo->global_state = CSTATE_WRCOEFS; >-} >- >- >-/* >- * Initialize the compression object with default parameters, >- * then copy from the source object all parameters needed for lossless >- * transcoding. Parameters that can be varied without loss (such as >- * scan script and Huffman optimization) are left in their default states. >- */ >- >-GLOBAL(void) >-jpeg_copy_critical_parameters (j_decompress_ptr srcinfo, >- j_compress_ptr dstinfo) >-{ >- JQUANT_TBL ** qtblptr; >- jpeg_component_info *incomp, *outcomp; >- JQUANT_TBL *c_quant, *slot_quant; >- int tblno, ci, coefi; >- >- /* Safety check to ensure start_compress not called yet. */ >- if (dstinfo->global_state != CSTATE_START) >- ERREXIT1(dstinfo, JERR_BAD_STATE, dstinfo->global_state); >- /* Copy fundamental image dimensions */ >- dstinfo->image_width = srcinfo->image_width; >- dstinfo->image_height = srcinfo->image_height; >- dstinfo->input_components = srcinfo->num_components; >- dstinfo->in_color_space = srcinfo->jpeg_color_space; >- /* Initialize all parameters to default values */ >- jpeg_set_defaults(dstinfo); >- /* jpeg_set_defaults may choose wrong colorspace, eg YCbCr if input is RGB. >- * Fix it to get the right header markers for the image colorspace. >- */ >- jpeg_set_colorspace(dstinfo, srcinfo->jpeg_color_space); >- dstinfo->data_precision = srcinfo->data_precision; >- dstinfo->CCIR601_sampling = srcinfo->CCIR601_sampling; >- /* Copy the source's quantization tables. */ >- for (tblno = 0; tblno < NUM_QUANT_TBLS; tblno++) { >- if (srcinfo->quant_tbl_ptrs[tblno] != NULL) { >- qtblptr = & dstinfo->quant_tbl_ptrs[tblno]; >- if (*qtblptr == NULL) >- *qtblptr = jpeg_alloc_quant_table((j_common_ptr) dstinfo); >- MEMCOPY((*qtblptr)->quantval, >- srcinfo->quant_tbl_ptrs[tblno]->quantval, >- SIZEOF((*qtblptr)->quantval)); >- (*qtblptr)->sent_table = FALSE; >- } >- } >- /* Copy the source's per-component info. >- * Note we assume jpeg_set_defaults has allocated the dest comp_info array. >- */ >- dstinfo->num_components = srcinfo->num_components; >- if (dstinfo->num_components < 1 || dstinfo->num_components > MAX_COMPONENTS) >- ERREXIT2(dstinfo, JERR_COMPONENT_COUNT, dstinfo->num_components, >- MAX_COMPONENTS); >- for (ci = 0, incomp = srcinfo->comp_info, outcomp = dstinfo->comp_info; >- ci < dstinfo->num_components; ci++, incomp++, outcomp++) { >- outcomp->component_id = incomp->component_id; >- outcomp->h_samp_factor = incomp->h_samp_factor; >- outcomp->v_samp_factor = incomp->v_samp_factor; >- outcomp->quant_tbl_no = incomp->quant_tbl_no; >- /* Make sure saved quantization table for component matches the qtable >- * slot. If not, the input file re-used this qtable slot. >- * IJG encoder currently cannot duplicate this. >- */ >- tblno = outcomp->quant_tbl_no; >- if (tblno < 0 || tblno >= NUM_QUANT_TBLS || >- srcinfo->quant_tbl_ptrs[tblno] == NULL) >- ERREXIT1(dstinfo, JERR_NO_QUANT_TABLE, tblno); >- slot_quant = srcinfo->quant_tbl_ptrs[tblno]; >- c_quant = incomp->quant_table; >- if (c_quant != NULL) { >- for (coefi = 0; coefi < DCTSIZE2; coefi++) { >- if (c_quant->quantval[coefi] != slot_quant->quantval[coefi]) >- ERREXIT1(dstinfo, JERR_MISMATCHED_QUANT_TABLE, tblno); >- } >- } >- /* Note: we do not copy the source's Huffman table assignments; >- * instead we rely on jpeg_set_colorspace to have made a suitable choice. >- */ >- } >- /* Also copy JFIF version and resolution information, if available. >- * Strictly speaking this isn't "critical" info, but it's nearly >- * always appropriate to copy it if available. In particular, >- * if the application chooses to copy JFIF 1.02 extension markers from >- * the source file, we need to copy the version to make sure we don't >- * emit a file that has 1.02 extensions but a claimed version of 1.01. >- * We will *not*, however, copy version info from mislabeled "2.01" files. >- */ >- if (srcinfo->saw_JFIF_marker) { >- if (srcinfo->JFIF_major_version == 1) { >- dstinfo->JFIF_major_version = srcinfo->JFIF_major_version; >- dstinfo->JFIF_minor_version = srcinfo->JFIF_minor_version; >- } >- dstinfo->density_unit = srcinfo->density_unit; >- dstinfo->X_density = srcinfo->X_density; >- dstinfo->Y_density = srcinfo->Y_density; >- } >-} >- >- >-/* >- * Master selection of compression modules for transcoding. >- * This substitutes for jcinit.c's initialization of the full compressor. >- */ >- >-LOCAL(void) >-transencode_master_selection (j_compress_ptr cinfo, >- jvirt_barray_ptr * coef_arrays) >-{ >- /* Although we don't actually use input_components for transcoding, >- * jcmaster.c's initial_setup will complain if input_components is 0. >- */ >- cinfo->input_components = 1; >- /* Initialize master control (includes parameter checking/processing) */ >- jinit_c_master_control(cinfo, TRUE /* transcode only */); >- >- /* Entropy encoding: either Huffman or arithmetic coding. */ >- if (cinfo->arith_code) { >- ERREXIT(cinfo, JERR_ARITH_NOTIMPL); >- } else { >- if (cinfo->progressive_mode) { >-#ifdef C_PROGRESSIVE_SUPPORTED >- jinit_phuff_encoder(cinfo); >-#else >- ERREXIT(cinfo, JERR_NOT_COMPILED); >-#endif >- } else >- jinit_huff_encoder(cinfo); >- } >- >- /* We need a special coefficient buffer controller. */ >- transencode_coef_controller(cinfo, coef_arrays); >- >- jinit_marker_writer(cinfo); >- >- /* We can now tell the memory manager to allocate virtual arrays. */ >- (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo); >- >- /* Write the datastream header (SOI, JFIF) immediately. >- * Frame and scan headers are postponed till later. >- * This lets application insert special markers after the SOI. >- */ >- (*cinfo->marker->write_file_header) (cinfo); >-} >- >- >-/* >- * The rest of this file is a special implementation of the coefficient >- * buffer controller. This is similar to jccoefct.c, but it handles only >- * output from presupplied virtual arrays. Furthermore, we generate any >- * dummy padding blocks on-the-fly rather than expecting them to be present >- * in the arrays. >- */ >- >-/* Private buffer controller object */ >- >-typedef struct { >- struct jpeg_c_coef_controller pub; /* public fields */ >- >- JDIMENSION iMCU_row_num; /* iMCU row # within image */ >- JDIMENSION mcu_ctr; /* counts MCUs processed in current row */ >- int MCU_vert_offset; /* counts MCU rows within iMCU row */ >- int MCU_rows_per_iMCU_row; /* number of such rows needed */ >- >- /* Virtual block array for each component. */ >- jvirt_barray_ptr * whole_image; >- >- /* Workspace for constructing dummy blocks at right/bottom edges. */ >- JBLOCKROW dummy_buffer[C_MAX_BLOCKS_IN_MCU]; >-} my_coef_controller; >- >-typedef my_coef_controller * my_coef_ptr; >- >- >-LOCAL(void) >-start_iMCU_row (j_compress_ptr cinfo) >-/* Reset within-iMCU-row counters for a new row */ >-{ >- my_coef_ptr coef = (my_coef_ptr) cinfo->coef; >- >- /* In an interleaved scan, an MCU row is the same as an iMCU row. >- * In a noninterleaved scan, an iMCU row has v_samp_factor MCU rows. >- * But at the bottom of the image, process only what's left. >- */ >- if (cinfo->comps_in_scan > 1) { >- coef->MCU_rows_per_iMCU_row = 1; >- } else { >- if (coef->iMCU_row_num < (cinfo->total_iMCU_rows-1)) >- coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor; >- else >- coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height; >- } >- >- coef->mcu_ctr = 0; >- coef->MCU_vert_offset = 0; >-} >- >- >-/* >- * Initialize for a processing pass. >- */ >- >-METHODDEF(void) >-start_pass_coef (j_compress_ptr cinfo, J_BUF_MODE pass_mode) >-{ >- my_coef_ptr coef = (my_coef_ptr) cinfo->coef; >- >- if (pass_mode != JBUF_CRANK_DEST) >- ERREXIT(cinfo, JERR_BAD_BUFFER_MODE); >- >- coef->iMCU_row_num = 0; >- start_iMCU_row(cinfo); >-} >- >- >-/* >- * Process some data. >- * We process the equivalent of one fully interleaved MCU row ("iMCU" row) >- * per call, ie, v_samp_factor block rows for each component in the scan. >- * The data is obtained from the virtual arrays and fed to the entropy coder. >- * Returns TRUE if the iMCU row is completed, FALSE if suspended. >- * >- * NB: input_buf is ignored; it is likely to be a NULL pointer. >- */ >- >-METHODDEF(boolean) >-compress_output (j_compress_ptr cinfo, JSAMPIMAGE input_buf) >-{ >- my_coef_ptr coef = (my_coef_ptr) cinfo->coef; >- JDIMENSION MCU_col_num; /* index of current MCU within row */ >- JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1; >- JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1; >- int blkn, ci, xindex, yindex, yoffset, blockcnt; >- JDIMENSION start_col; >- JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN]; >- JBLOCKROW MCU_buffer[C_MAX_BLOCKS_IN_MCU]; >- JBLOCKROW buffer_ptr; >- jpeg_component_info *compptr; >- >- /* Align the virtual buffers for the components used in this scan. */ >- for (ci = 0; ci < cinfo->comps_in_scan; ci++) { >- compptr = cinfo->cur_comp_info[ci]; >- buffer[ci] = (*cinfo->mem->access_virt_barray) >- ((j_common_ptr) cinfo, coef->whole_image[compptr->component_index], >- coef->iMCU_row_num * compptr->v_samp_factor, >- (JDIMENSION) compptr->v_samp_factor, FALSE); >- } >- >- /* Loop to process one whole iMCU row */ >- for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row; >- yoffset++) { >- for (MCU_col_num = coef->mcu_ctr; MCU_col_num < cinfo->MCUs_per_row; >- MCU_col_num++) { >- /* Construct list of pointers to DCT blocks belonging to this MCU */ >- blkn = 0; /* index of current DCT block within MCU */ >- for (ci = 0; ci < cinfo->comps_in_scan; ci++) { >- compptr = cinfo->cur_comp_info[ci]; >- start_col = MCU_col_num * compptr->MCU_width; >- blockcnt = (MCU_col_num < last_MCU_col) ? compptr->MCU_width >- : compptr->last_col_width; >- for (yindex = 0; yindex < compptr->MCU_height; yindex++) { >- if (coef->iMCU_row_num < last_iMCU_row || >- yindex+yoffset < compptr->last_row_height) { >- /* Fill in pointers to real blocks in this row */ >- buffer_ptr = buffer[ci][yindex+yoffset] + start_col; >- for (xindex = 0; xindex < blockcnt; xindex++) >- MCU_buffer[blkn++] = buffer_ptr++; >- } else { >- /* At bottom of image, need a whole row of dummy blocks */ >- xindex = 0; >- } >- /* Fill in any dummy blocks needed in this row. >- * Dummy blocks are filled in the same way as in jccoefct.c: >- * all zeroes in the AC entries, DC entries equal to previous >- * block's DC value. The init routine has already zeroed the >- * AC entries, so we need only set the DC entries correctly. >- */ >- for (; xindex < compptr->MCU_width; xindex++) { >- MCU_buffer[blkn] = coef->dummy_buffer[blkn]; >- MCU_buffer[blkn][0][0] = MCU_buffer[blkn-1][0][0]; >- blkn++; >- } >- } >- } >- /* Try to write the MCU. */ >- if (! (*cinfo->entropy->encode_mcu) (cinfo, MCU_buffer)) { >- /* Suspension forced; update state counters and exit */ >- coef->MCU_vert_offset = yoffset; >- coef->mcu_ctr = MCU_col_num; >- return FALSE; >- } >- } >- /* Completed an MCU row, but perhaps not an iMCU row */ >- coef->mcu_ctr = 0; >- } >- /* Completed the iMCU row, advance counters for next one */ >- coef->iMCU_row_num++; >- start_iMCU_row(cinfo); >- return TRUE; >-} >- >- >-/* >- * Initialize coefficient buffer controller. >- * >- * Each passed coefficient array must be the right size for that >- * coefficient: width_in_blocks wide and height_in_blocks high, >- * with unitheight at least v_samp_factor. >- */ >- >-LOCAL(void) >-transencode_coef_controller (j_compress_ptr cinfo, >- jvirt_barray_ptr * coef_arrays) >-{ >- my_coef_ptr coef; >- JBLOCKROW buffer; >- int i; >- >- coef = (my_coef_ptr) >- (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, >- SIZEOF(my_coef_controller)); >- cinfo->coef = (struct jpeg_c_coef_controller *) coef; >- coef->pub.start_pass = start_pass_coef; >- coef->pub.compress_data = compress_output; >- >- /* Save pointer to virtual arrays */ >- coef->whole_image = coef_arrays; >- >- /* Allocate and pre-zero space for dummy DCT blocks. */ >- buffer = (JBLOCKROW) >- (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE, >- C_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK)); >- jzero_far((void FAR *) buffer, C_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK)); >- for (i = 0; i < C_MAX_BLOCKS_IN_MCU; i++) { >- coef->dummy_buffer[i] = buffer + i; >- } >-} >diff -U8 b/jpeg/jdatadst.c b/jpeg/jdatadst.c >--- b/jpeg/jdatadst.c >+++ b/jpeg/jdatadst.c >@@ -1,44 +1,67 @@ > /* > * jdatadst.c > * > * Copyright (C) 1994-1996, Thomas G. Lane. >+ * Modified 2009 by Guido Vollbeding. > * This file is part of the Independent JPEG Group's software. > * For conditions of distribution and use, see the accompanying README file. > * > * This file contains compression data destination routines for the case of >- * emitting JPEG data to a file (or any stdio stream). While these routines >- * are sufficient for most applications, some will want to use a different >- * destination manager. >+ * emitting JPEG data to memory or to a file (or any stdio stream). >+ * While these routines are sufficient for most applications, >+ * some will want to use a different destination manager. > * IMPORTANT: we assume that fwrite() will correctly transcribe an array of > * JOCTETs into 8-bit-wide elements on external storage. If char is wider > * than 8 bits on your machine, you may need to do some tweaking. > */ > > /* this is not a core library module, so it doesn't define JPEG_INTERNALS */ > #include "jinclude.h" > #include "jpeglib.h" > #include "jerror.h" > >+#ifndef HAVE_STDLIB_H /* <stdlib.h> should declare malloc(),free() */ >+extern void * malloc JPP((size_t size)); >+extern void free JPP((void *ptr)); >+#endif >+ > > /* Expanded data destination object for stdio output */ > > typedef struct { > struct jpeg_destination_mgr pub; /* public fields */ > > FILE * outfile; /* target stream */ > JOCTET * buffer; /* start of buffer */ > } my_destination_mgr; > > typedef my_destination_mgr * my_dest_ptr; > > #define OUTPUT_BUF_SIZE 4096 /* choose an efficiently fwrite'able size */ > > >+#if JPEG_LIB_VERSION >= 80 >+/* Expanded data destination object for memory output */ >+ >+typedef struct { >+ struct jpeg_destination_mgr pub; /* public fields */ >+ >+ unsigned char ** outbuffer; /* target buffer */ >+ unsigned long * outsize; >+ unsigned char * newbuffer; /* newly allocated buffer */ >+ JOCTET * buffer; /* start of buffer */ >+ size_t bufsize; >+} my_mem_destination_mgr; >+ >+typedef my_mem_destination_mgr * my_mem_dest_ptr; >+#endif >+ >+ > /* > * Initialize destination --- called by jpeg_start_compress > * before any data is actually written. > */ > > METHODDEF(void) > init_destination (j_compress_ptr cinfo) > { >@@ -48,16 +71,24 @@ > dest->buffer = (JOCTET *) > (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, > OUTPUT_BUF_SIZE * SIZEOF(JOCTET)); > > dest->pub.next_output_byte = dest->buffer; > dest->pub.free_in_buffer = OUTPUT_BUF_SIZE; > } > >+#if JPEG_LIB_VERSION >= 80 >+METHODDEF(void) >+init_mem_destination (j_compress_ptr cinfo) >+{ >+ /* no work necessary here */ >+} >+#endif >+ > > /* > * Empty the output buffer --- called whenever buffer fills up. > * > * In typical applications, this should write the entire output buffer > * (ignoring the current state of next_output_byte & free_in_buffer), > * reset the pointer & count to the start of the buffer, and return TRUE > * indicating that the buffer has been dumped. >@@ -87,16 +118,48 @@ > ERREXIT(cinfo, JERR_FILE_WRITE); > > dest->pub.next_output_byte = dest->buffer; > dest->pub.free_in_buffer = OUTPUT_BUF_SIZE; > > return TRUE; > } > >+#if JPEG_LIB_VERSION >= 80 >+METHODDEF(boolean) >+empty_mem_output_buffer (j_compress_ptr cinfo) >+{ >+ size_t nextsize; >+ JOCTET * nextbuffer; >+ my_mem_dest_ptr dest = (my_mem_dest_ptr) cinfo->dest; >+ >+ /* Try to allocate new buffer with double size */ >+ nextsize = dest->bufsize * 2; >+ nextbuffer = malloc(nextsize); >+ >+ if (nextbuffer == NULL) >+ ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, 10); >+ >+ MEMCOPY(nextbuffer, dest->buffer, dest->bufsize); >+ >+ if (dest->newbuffer != NULL) >+ free(dest->newbuffer); >+ >+ dest->newbuffer = nextbuffer; >+ >+ dest->pub.next_output_byte = nextbuffer + dest->bufsize; >+ dest->pub.free_in_buffer = dest->bufsize; >+ >+ dest->buffer = nextbuffer; >+ dest->bufsize = nextsize; >+ >+ return TRUE; >+} >+#endif >+ > > /* > * Terminate destination --- called by jpeg_finish_compress > * after all data has been written. Usually needs to flush buffer. > * > * NB: *not* called by jpeg_abort or jpeg_destroy; surrounding > * application must deal with any cleanup that should happen even > * for error exit. >@@ -114,16 +177,27 @@ > ERREXIT(cinfo, JERR_FILE_WRITE); > } > fflush(dest->outfile); > /* Make sure we wrote the output file OK */ > if (ferror(dest->outfile)) > ERREXIT(cinfo, JERR_FILE_WRITE); > } > >+#if JPEG_LIB_VERSION >= 80 >+METHODDEF(void) >+term_mem_destination (j_compress_ptr cinfo) >+{ >+ my_mem_dest_ptr dest = (my_mem_dest_ptr) cinfo->dest; >+ >+ *dest->outbuffer = dest->buffer; >+ *dest->outsize = dest->bufsize - dest->pub.free_in_buffer; >+} >+#endif >+ > > /* > * Prepare for output to a stdio stream. > * The caller must have already opened the stream, and is responsible > * for closing it after finishing compression. > */ > > GLOBAL(void) >@@ -151,0 +226,52 @@ >+ >+ >+#if JPEG_LIB_VERSION >= 80 >+/* >+ * Prepare for output to a memory buffer. >+ * The caller may supply an own initial buffer with appropriate size. >+ * Otherwise, or when the actual data output exceeds the given size, >+ * the library adapts the buffer size as necessary. >+ * The standard library functions malloc/free are used for allocating >+ * larger memory, so the buffer is available to the application after >+ * finishing compression, and then the application is responsible for >+ * freeing the requested memory. >+ */ >+ >+GLOBAL(void) >+jpeg_mem_dest (j_compress_ptr cinfo, >+ unsigned char ** outbuffer, unsigned long * outsize) >+{ >+ my_mem_dest_ptr dest; >+ >+ if (outbuffer == NULL || outsize == NULL) /* sanity check */ >+ ERREXIT(cinfo, JERR_BUFFER_SIZE); >+ >+ /* The destination object is made permanent so that multiple JPEG images >+ * can be written to the same buffer without re-executing jpeg_mem_dest. >+ */ >+ if (cinfo->dest == NULL) { /* first time for this JPEG object? */ >+ cinfo->dest = (struct jpeg_destination_mgr *) >+ (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT, >+ SIZEOF(my_mem_destination_mgr)); >+ } >+ >+ dest = (my_mem_dest_ptr) cinfo->dest; >+ dest->pub.init_destination = init_mem_destination; >+ dest->pub.empty_output_buffer = empty_mem_output_buffer; >+ dest->pub.term_destination = term_mem_destination; >+ dest->outbuffer = outbuffer; >+ dest->outsize = outsize; >+ dest->newbuffer = NULL; >+ >+ if (*outbuffer == NULL || *outsize == 0) { >+ /* Allocate initial buffer */ >+ dest->newbuffer = *outbuffer = malloc(OUTPUT_BUF_SIZE); >+ if (dest->newbuffer == NULL) >+ ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, 10); >+ *outsize = OUTPUT_BUF_SIZE; >+ } >+ >+ dest->pub.next_output_byte = dest->buffer = *outbuffer; >+ dest->pub.free_in_buffer = dest->bufsize = *outsize; >+} >+#endif >diff -U8 b/jpeg/jdcoefct.c b/jpeg/jdcoefct.c >--- b/jpeg/jdcoefct.c >+++ b/jpeg/jdcoefct.c >@@ -1,27 +1,29 @@ > /* > * jdcoefct.c > * > * Copyright (C) 1994-1997, Thomas G. Lane. >+ * Copyright (C) 2010, D. R. Commander. > * This file is part of the Independent JPEG Group's software. > * For conditions of distribution and use, see the accompanying README file. > * > * This file contains the coefficient buffer controller for decompression. > * This controller is the top level of the JPEG decompressor proper. > * The coefficient buffer lies between entropy decoding and inverse-DCT steps. > * > * In buffered-image mode, this controller is the interface between > * input-oriented processing and output-oriented processing. > * Also, the input side (only) is used when reading a file for transcoding. > */ > > #define JPEG_INTERNALS > #include "jinclude.h" > #include "jpeglib.h" >+#include "jpegcomp.h" > > /* Block smoothing is only applicable for progressive JPEG, so: */ > #ifndef D_PROGRESSIVE_SUPPORTED > #undef BLOCK_SMOOTHING_SUPPORTED > #endif > > /* Private buffer controller object */ > >@@ -185,31 +187,31 @@ > if (! compptr->component_needed) { > blkn += compptr->MCU_blocks; > continue; > } > inverse_DCT = cinfo->idct->inverse_DCT[compptr->component_index]; > useful_width = (MCU_col_num < last_MCU_col) ? compptr->MCU_width > : compptr->last_col_width; > output_ptr = output_buf[compptr->component_index] + >- yoffset * compptr->DCT_scaled_size; >+ yoffset * compptr->_DCT_scaled_size; > start_col = MCU_col_num * compptr->MCU_sample_width; > for (yindex = 0; yindex < compptr->MCU_height; yindex++) { > if (cinfo->input_iMCU_row < last_iMCU_row || > yoffset+yindex < compptr->last_row_height) { > output_col = start_col; > for (xindex = 0; xindex < useful_width; xindex++) { > (*inverse_DCT) (cinfo, compptr, > (JCOEFPTR) coef->MCU_buffer[blkn+xindex], > output_ptr, output_col); >- output_col += compptr->DCT_scaled_size; >+ output_col += compptr->_DCT_scaled_size; > } > } > blkn += compptr->MCU_width; >- output_ptr += compptr->DCT_scaled_size; >+ output_ptr += compptr->_DCT_scaled_size; > } > } > } > /* Completed an MCU row, but perhaps not an iMCU row */ > coef->MCU_ctr = 0; > } > /* Completed the iMCU row, advance counters for next one */ > cinfo->output_iMCU_row++; >@@ -360,19 +362,19 @@ > /* Loop over all DCT blocks to be processed. */ > for (block_row = 0; block_row < block_rows; block_row++) { > buffer_ptr = buffer[block_row]; > output_col = 0; > for (block_num = 0; block_num < compptr->width_in_blocks; block_num++) { > (*inverse_DCT) (cinfo, compptr, (JCOEFPTR) buffer_ptr, > output_ptr, output_col); > buffer_ptr++; >- output_col += compptr->DCT_scaled_size; >+ output_col += compptr->_DCT_scaled_size; > } >- output_ptr += compptr->DCT_scaled_size; >+ output_ptr += compptr->_DCT_scaled_size; > } > } > > if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows) > return JPEG_ROW_COMPLETED; > return JPEG_SCAN_COMPLETED; > } > >@@ -655,19 +657,19 @@ > /* OK, do the IDCT */ > (*inverse_DCT) (cinfo, compptr, (JCOEFPTR) workspace, > output_ptr, output_col); > /* Advance for next column */ > DC1 = DC2; DC2 = DC3; > DC4 = DC5; DC5 = DC6; > DC7 = DC8; DC8 = DC9; > buffer_ptr++, prev_block_row++, next_block_row++; >- output_col += compptr->DCT_scaled_size; >+ output_col += compptr->_DCT_scaled_size; > } >- output_ptr += compptr->DCT_scaled_size; >+ output_ptr += compptr->_DCT_scaled_size; > } > } > > if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows) > return JPEG_ROW_COMPLETED; > return JPEG_SCAN_COMPLETED; > } > >diff -U8 b/jpeg/jdcolor.c b/jpeg/jdcolor.c >--- b/jpeg/jdcolor.c >+++ b/jpeg/jdcolor.c >@@ -218,17 +218,16 @@ > > METHODDEF(void) > gray_rgb_convert (j_decompress_ptr cinfo, > JSAMPIMAGE input_buf, JDIMENSION input_row, > JSAMPARRAY output_buf, int num_rows) > { > register JSAMPROW inptr, outptr; > JSAMPLE *maxinptr; >- register JDIMENSION col; > JDIMENSION num_cols = cinfo->output_width; > int rindex = rgb_red[cinfo->out_color_space]; > int gindex = rgb_green[cinfo->out_color_space]; > int bindex = rgb_blue[cinfo->out_color_space]; > int rgbstride = rgb_pixelsize[cinfo->out_color_space]; > > while (--num_rows >= 0) { > inptr = input_buf[0][input_row++]; >diff -U8 b/jpeg/jddctmgr.c b/jpeg/jddctmgr.c >--- b/jpeg/jddctmgr.c >+++ b/jpeg/jddctmgr.c >@@ -1,13 +1,14 @@ > /* > * jddctmgr.c > * > * Copyright (C) 1994-1996, Thomas G. Lane. > * Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB >+ * Copyright (C) 2010, D. R. Commander. > * This file is part of the Independent JPEG Group's software. > * For conditions of distribution and use, see the accompanying README file. > * > * This file contains the inverse-DCT management logic. > * This code selects a particular IDCT implementation to be used, > * and it performs related housekeeping chores. No code in this file > * is executed per IDCT step, only during output pass setup. > * >@@ -16,16 +17,17 @@ > * dequantization multiplier table needed by the IDCT routine. > */ > > #define JPEG_INTERNALS > #include "jinclude.h" > #include "jpeglib.h" > #include "jdct.h" /* Private declarations for DCT subsystem */ > #include "jsimddct.h" >+#include "jpegcomp.h" > > > /* > * The decompressor input side (jdinput.c) saves away the appropriate > * quantization table for each component at the start of the first scan > * involving that component. (This is necessary in order to correctly > * decode files that reuse Q-table slots.) > * When we are ready to make an output pass, the saved Q-table is converted >@@ -95,17 +97,17 @@ > jpeg_component_info *compptr; > int method = 0; > inverse_DCT_method_ptr method_ptr = NULL; > JQUANT_TBL * qtbl; > > for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; > ci++, compptr++) { > /* Select the proper IDCT routine for this component's scaling */ >- switch (compptr->DCT_scaled_size) { >+ switch (compptr->_DCT_scaled_size) { > #ifdef IDCT_SCALING_SUPPORTED > case 1: > method_ptr = jpeg_idct_1x1; > method = JDCT_ISLOW; /* jidctred uses islow-style table */ > break; > case 2: > if (jsimd_can_idct_2x2()) > method_ptr = jsimd_idct_2x2; >@@ -151,17 +153,17 @@ > break; > #endif > default: > ERREXIT(cinfo, JERR_NOT_COMPILED); > break; > } > break; > default: >- ERREXIT1(cinfo, JERR_BAD_DCTSIZE, compptr->DCT_scaled_size); >+ ERREXIT1(cinfo, JERR_BAD_DCTSIZE, compptr->_DCT_scaled_size); > break; > } > idct->pub.inverse_DCT[ci] = method_ptr; > /* Create multiplier table from quant table. > * However, we can skip this if the component is uninteresting > * or if we already built the table. Also, if no quant table > * has yet been saved for the component, we leave the > * multiplier table all-zero; we'll be reading zeroes from the >diff -U8 b/jpeg/jdmaster.c b/jpeg/jdmaster.c >--- b/jpeg/jdmaster.c >+++ b/jpeg/jdmaster.c >@@ -1,25 +1,26 @@ > /* > * jdmaster.c > * > * Copyright (C) 1991-1997, Thomas G. Lane. >- * Copyright (C) 2009, D. R. Commander. >+ * Copyright (C) 2009-2010, D. R. Commander. > * This file is part of the Independent JPEG Group's software. > * For conditions of distribution and use, see the accompanying README file. > * > * This file contains master control logic for the JPEG decompressor. > * These routines are concerned with selecting the modules to be executed > * and with determining the number of passes and the work to be done in each > * pass. > */ > > #define JPEG_INTERNALS > #include "jinclude.h" > #include "jpeglib.h" >+#include "jpegcomp.h" > > > /* Private state */ > > typedef struct { > struct jpeg_decomp_master pub; /* public fields */ > > int pass_number; /* # of passes completed */ >@@ -63,19 +64,19 @@ > if (cinfo->comp_info[0].h_samp_factor != 2 || > cinfo->comp_info[1].h_samp_factor != 1 || > cinfo->comp_info[2].h_samp_factor != 1 || > cinfo->comp_info[0].v_samp_factor > 2 || > cinfo->comp_info[1].v_samp_factor != 1 || > cinfo->comp_info[2].v_samp_factor != 1) > return FALSE; > /* furthermore, it doesn't work if we've scaled the IDCTs differently */ >- if (cinfo->comp_info[0].DCT_scaled_size != cinfo->min_DCT_scaled_size || >- cinfo->comp_info[1].DCT_scaled_size != cinfo->min_DCT_scaled_size || >- cinfo->comp_info[2].DCT_scaled_size != cinfo->min_DCT_scaled_size) >+ if (cinfo->comp_info[0]._DCT_scaled_size != cinfo->_min_DCT_scaled_size || >+ cinfo->comp_info[1]._DCT_scaled_size != cinfo->_min_DCT_scaled_size || >+ cinfo->comp_info[2]._DCT_scaled_size != cinfo->_min_DCT_scaled_size) > return FALSE; > /* ??? also need to test for upsample-time rescaling, when & if supported */ > return TRUE; /* by golly, it'll work... */ > #else > return FALSE; > #endif > } > >@@ -104,68 +105,88 @@ > > /* Compute actual output image dimensions and DCT scaling choices. */ > if (cinfo->scale_num * 8 <= cinfo->scale_denom) { > /* Provide 1/8 scaling */ > cinfo->output_width = (JDIMENSION) > jdiv_round_up((long) cinfo->image_width, 8L); > cinfo->output_height = (JDIMENSION) > jdiv_round_up((long) cinfo->image_height, 8L); >+#if JPEG_LIB_VERSION >= 70 >+ cinfo->min_DCT_h_scaled_size = cinfo->min_DCT_v_scaled_size = 1; >+#else > cinfo->min_DCT_scaled_size = 1; >+#endif > } else if (cinfo->scale_num * 4 <= cinfo->scale_denom) { > /* Provide 1/4 scaling */ > cinfo->output_width = (JDIMENSION) > jdiv_round_up((long) cinfo->image_width, 4L); > cinfo->output_height = (JDIMENSION) > jdiv_round_up((long) cinfo->image_height, 4L); >+#if JPEG_LIB_VERSION >= 70 >+ cinfo->min_DCT_h_scaled_size = cinfo->min_DCT_v_scaled_size = 2; >+#else > cinfo->min_DCT_scaled_size = 2; >+#endif > } else if (cinfo->scale_num * 2 <= cinfo->scale_denom) { > /* Provide 1/2 scaling */ > cinfo->output_width = (JDIMENSION) > jdiv_round_up((long) cinfo->image_width, 2L); > cinfo->output_height = (JDIMENSION) > jdiv_round_up((long) cinfo->image_height, 2L); >+#if JPEG_LIB_VERSION >= 70 >+ cinfo->min_DCT_h_scaled_size = cinfo->min_DCT_v_scaled_size = 4; >+#else > cinfo->min_DCT_scaled_size = 4; >+#endif > } else { > /* Provide 1/1 scaling */ > cinfo->output_width = cinfo->image_width; > cinfo->output_height = cinfo->image_height; >+#if JPEG_LIB_VERSION >= 70 >+ cinfo->min_DCT_h_scaled_size = cinfo->min_DCT_v_scaled_size = DCTSIZE; >+#else > cinfo->min_DCT_scaled_size = DCTSIZE; >+#endif > } > /* In selecting the actual DCT scaling for each component, we try to > * scale up the chroma components via IDCT scaling rather than upsampling. > * This saves time if the upsampler gets to use 1:1 scaling. > * Note this code assumes that the supported DCT scalings are powers of 2. > */ > for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; > ci++, compptr++) { >- int ssize = cinfo->min_DCT_scaled_size; >+ int ssize = cinfo->_min_DCT_scaled_size; > while (ssize < DCTSIZE && > (compptr->h_samp_factor * ssize * 2 <= >- cinfo->max_h_samp_factor * cinfo->min_DCT_scaled_size) && >+ cinfo->max_h_samp_factor * cinfo->_min_DCT_scaled_size) && > (compptr->v_samp_factor * ssize * 2 <= >- cinfo->max_v_samp_factor * cinfo->min_DCT_scaled_size)) { >+ cinfo->max_v_samp_factor * cinfo->_min_DCT_scaled_size)) { > ssize = ssize * 2; > } >+#if JPEG_LIB_VERSION >= 70 >+ compptr->DCT_h_scaled_size = compptr->DCT_v_scaled_size = ssize; >+#else > compptr->DCT_scaled_size = ssize; >+#endif > } > > /* Recompute downsampled dimensions of components; > * application needs to know these if using raw downsampled data. > */ > for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; > ci++, compptr++) { > /* Size in samples, after IDCT scaling */ > compptr->downsampled_width = (JDIMENSION) > jdiv_round_up((long) cinfo->image_width * >- (long) (compptr->h_samp_factor * compptr->DCT_scaled_size), >+ (long) (compptr->h_samp_factor * compptr->_DCT_scaled_size), > (long) (cinfo->max_h_samp_factor * DCTSIZE)); > compptr->downsampled_height = (JDIMENSION) > jdiv_round_up((long) cinfo->image_height * >- (long) (compptr->v_samp_factor * compptr->DCT_scaled_size), >+ (long) (compptr->v_samp_factor * compptr->_DCT_scaled_size), > (long) (cinfo->max_v_samp_factor * DCTSIZE)); > } > > #else /* !IDCT_SCALING_SUPPORTED */ > > /* Hardwire it to "no scaling" */ > cinfo->output_width = cinfo->image_width; > cinfo->output_height = cinfo->image_height; >@@ -379,17 +400,21 @@ > jinit_upsampler(cinfo); > } > jinit_d_post_controller(cinfo, cinfo->enable_2pass_quant); > } > /* Inverse DCT */ > jinit_inverse_dct(cinfo); > /* Entropy decoding: either Huffman or arithmetic coding. */ > if (cinfo->arith_code) { >+#ifdef D_ARITH_CODING_SUPPORTED >+ jinit_arith_decoder(cinfo); >+#else > ERREXIT(cinfo, JERR_ARITH_NOTIMPL); >+#endif > } else { > if (cinfo->progressive_mode) { > #ifdef D_PROGRESSIVE_SUPPORTED > jinit_phuff_decoder(cinfo); > #else > ERREXIT(cinfo, JERR_NOT_COMPILED); > #endif > } else >diff -U8 b/jpeg/jdsample.c b/jpeg/jdsample.c >--- b/jpeg/jdsample.c >+++ b/jpeg/jdsample.c >@@ -1,13 +1,14 @@ > /* > * jdsample.c > * > * Copyright (C) 1991-1996, Thomas G. Lane. > * Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB >+ * Copyright (C) 2010, D. R. Commander. > * This file is part of the Independent JPEG Group's software. > * For conditions of distribution and use, see the accompanying README file. > * > * This file contains upsampling routines. > * > * Upsampling input data is counted in "row groups". A row group > * is defined to be (v_samp_factor * DCT_scaled_size / min_DCT_scaled_size) > * sample rows of each component. Upsampling will normally produce >@@ -18,16 +19,17 @@ > * Digital Image Warping, George Wolberg, 1990. > * Pub. by IEEE Computer Society Press, Los Alamitos, CA. ISBN 0-8186-8944-7. > */ > > #define JPEG_INTERNALS > #include "jinclude.h" > #include "jpeglib.h" > #include "jsimd.h" >+#include "jpegcomp.h" > > > /* Pointer to routine to upsample a single component */ > typedef JMETHOD(void, upsample1_ptr, > (j_decompress_ptr cinfo, jpeg_component_info * compptr, > JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)); > > /* Private subobject */ >@@ -415,30 +417,30 @@ > upsample->pub.need_context_rows = FALSE; /* until we find out differently */ > > if (cinfo->CCIR601_sampling) /* this isn't supported */ > ERREXIT(cinfo, JERR_CCIR601_NOTIMPL); > > /* jdmainct.c doesn't support context rows when min_DCT_scaled_size = 1, > * so don't ask for it. > */ >- do_fancy = cinfo->do_fancy_upsampling && cinfo->min_DCT_scaled_size > 1; >+ do_fancy = cinfo->do_fancy_upsampling && cinfo->_min_DCT_scaled_size > 1; > > /* Verify we can handle the sampling factors, select per-component methods, > * and create storage as needed. > */ > for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; > ci++, compptr++) { > /* Compute size of an "input group" after IDCT scaling. This many samples > * are to be converted to max_h_samp_factor * max_v_samp_factor pixels. > */ >- h_in_group = (compptr->h_samp_factor * compptr->DCT_scaled_size) / >- cinfo->min_DCT_scaled_size; >- v_in_group = (compptr->v_samp_factor * compptr->DCT_scaled_size) / >- cinfo->min_DCT_scaled_size; >+ h_in_group = (compptr->h_samp_factor * compptr->_DCT_scaled_size) / >+ cinfo->_min_DCT_scaled_size; >+ v_in_group = (compptr->v_samp_factor * compptr->_DCT_scaled_size) / >+ cinfo->_min_DCT_scaled_size; > h_out_group = cinfo->max_h_samp_factor; > v_out_group = cinfo->max_v_samp_factor; > upsample->rowgroup_height[ci] = v_in_group; /* save for use later */ > need_buffer = TRUE; > if (! compptr->component_needed) { > /* Don't bother to upsample an uninteresting component. */ > upsample->methods[ci] = noop_upsample; > need_buffer = FALSE; >diff -U8 b/jpeg/jdtrans.c b/jpeg/jdtrans.c >--- b/jpeg/jdtrans.c >+++ b/jpeg/jdtrans.c >@@ -96,17 +96,21 @@ > LOCAL(void) > transdecode_master_selection (j_decompress_ptr cinfo) > { > /* This is effectively a buffered-image operation. */ > cinfo->buffered_image = TRUE; > > /* Entropy decoding: either Huffman or arithmetic coding. */ > if (cinfo->arith_code) { >+#ifdef D_ARITH_CODING_SUPPORTED >+ jinit_arith_decoder(cinfo); >+#else > ERREXIT(cinfo, JERR_ARITH_NOTIMPL); >+#endif > } else { > if (cinfo->progressive_mode) { > #ifdef D_PROGRESSIVE_SUPPORTED > jinit_phuff_decoder(cinfo); > #else > ERREXIT(cinfo, JERR_NOT_COMPILED); > #endif > } else >diff -U8 b/jpeg/jpegint.h b/jpeg/jpegint.h >--- b/jpeg/jpegint.h >+++ b/jpeg/jpegint.h >@@ -1,12 +1,13 @@ > /* > * jpegint.h > * > * Copyright (C) 1991-1997, Thomas G. Lane. >+ * Modified 1997-2009 by Guido Vollbeding. > * This file is part of the Independent JPEG Group's software. > * For conditions of distribution and use, see the accompanying README file. > * > * This file provides common declarations for the various JPEG modules. > * These declarations are considered internal to the JPEG library; most > * applications using the library shouldn't need to include this file. > */ > >@@ -299,39 +300,42 @@ > #define jinit_c_main_controller jICMainC > #define jinit_c_prep_controller jICPrepC > #define jinit_c_coef_controller jICCoefC > #define jinit_color_converter jICColor > #define jinit_downsampler jIDownsampler > #define jinit_forward_dct jIFDCT > #define jinit_huff_encoder jIHEncoder > #define jinit_phuff_encoder jIPHEncoder >+#define jinit_arith_encoder jIAEncoder > #define jinit_marker_writer jIMWriter > #define jinit_master_decompress jIDMaster > #define jinit_d_main_controller jIDMainC > #define jinit_d_coef_controller jIDCoefC > #define jinit_d_post_controller jIDPostC > #define jinit_input_controller jIInCtlr > #define jinit_marker_reader jIMReader > #define jinit_huff_decoder jIHDecoder > #define jinit_phuff_decoder jIPHDecoder >+#define jinit_arith_decoder jIADecoder > #define jinit_inverse_dct jIIDCT > #define jinit_upsampler jIUpsampler > #define jinit_color_deconverter jIDColor > #define jinit_1pass_quantizer jI1Quant > #define jinit_2pass_quantizer jI2Quant > #define jinit_merged_upsampler jIMUpsampler > #define jinit_memory_mgr jIMemMgr > #define jdiv_round_up jDivRound > #define jround_up jRound > #define jcopy_sample_rows jCopySamples > #define jcopy_block_row jCopyBlocks > #define jzero_far jZeroFar > #define jpeg_zigzag_order jZIGTable > #define jpeg_natural_order jZAGTable >+#define jpeg_aritab jAriTab > #endif /* NEED_SHORT_EXTERNAL_NAMES */ > > > /* Compression module initialization routines */ > EXTERN(void) jinit_compress_master JPP((j_compress_ptr cinfo)); > EXTERN(void) jinit_c_master_control JPP((j_compress_ptr cinfo, > boolean transcode_only)); > EXTERN(void) jinit_c_main_controller JPP((j_compress_ptr cinfo, >@@ -340,29 +344,31 @@ > boolean need_full_buffer)); > EXTERN(void) jinit_c_coef_controller JPP((j_compress_ptr cinfo, > boolean need_full_buffer)); > EXTERN(void) jinit_color_converter JPP((j_compress_ptr cinfo)); > EXTERN(void) jinit_downsampler JPP((j_compress_ptr cinfo)); > EXTERN(void) jinit_forward_dct JPP((j_compress_ptr cinfo)); > EXTERN(void) jinit_huff_encoder JPP((j_compress_ptr cinfo)); > EXTERN(void) jinit_phuff_encoder JPP((j_compress_ptr cinfo)); >+EXTERN(void) jinit_arith_encoder JPP((j_compress_ptr cinfo)); > EXTERN(void) jinit_marker_writer JPP((j_compress_ptr cinfo)); > /* Decompression module initialization routines */ > EXTERN(void) jinit_master_decompress JPP((j_decompress_ptr cinfo)); > EXTERN(void) jinit_d_main_controller JPP((j_decompress_ptr cinfo, > boolean need_full_buffer)); > EXTERN(void) jinit_d_coef_controller JPP((j_decompress_ptr cinfo, > boolean need_full_buffer)); > EXTERN(void) jinit_d_post_controller JPP((j_decompress_ptr cinfo, > boolean need_full_buffer)); > EXTERN(void) jinit_input_controller JPP((j_decompress_ptr cinfo)); > EXTERN(void) jinit_marker_reader JPP((j_decompress_ptr cinfo)); > EXTERN(void) jinit_huff_decoder JPP((j_decompress_ptr cinfo)); > EXTERN(void) jinit_phuff_decoder JPP((j_decompress_ptr cinfo)); >+EXTERN(void) jinit_arith_decoder JPP((j_decompress_ptr cinfo)); > EXTERN(void) jinit_inverse_dct JPP((j_decompress_ptr cinfo)); > EXTERN(void) jinit_upsampler JPP((j_decompress_ptr cinfo)); > EXTERN(void) jinit_color_deconverter JPP((j_decompress_ptr cinfo)); > EXTERN(void) jinit_1pass_quantizer JPP((j_decompress_ptr cinfo)); > EXTERN(void) jinit_2pass_quantizer JPP((j_decompress_ptr cinfo)); > EXTERN(void) jinit_merged_upsampler JPP((j_decompress_ptr cinfo)); > /* Memory manager initialization */ > EXTERN(void) jinit_memory_mgr JPP((j_common_ptr cinfo)); >@@ -377,16 +383,19 @@ > JDIMENSION num_blocks)); > EXTERN(void) jzero_far JPP((void FAR * target, size_t bytestozero)); > /* Constant tables in jutils.c */ > #if 0 /* This table is not actually needed in v6a */ > extern const int jpeg_zigzag_order[]; /* natural coef order to zigzag order */ > #endif > extern const int jpeg_natural_order[]; /* zigzag coef order to natural order */ > >+/* Arithmetic coding probability estimation tables in jaricom.c */ >+extern const INT32 jpeg_aritab[]; >+ > /* Suppress undefined-structure complaints if necessary. */ > > #ifdef INCOMPLETE_TYPES_BROKEN > #ifndef AM_MEMORY_MANAGER /* only jmemmgr.c defines these */ > struct jvirt_sarray_control { long dummy; }; > struct jvirt_barray_control { long dummy; }; > #endif > #endif /* INCOMPLETE_TYPES_BROKEN */ >diff -U8 b/jpeg/jpeglib.h b/jpeg/jpeglib.h >--- b/jpeg/jpeglib.h >+++ b/jpeg/jpeglib.h >@@ -1,46 +1,43 @@ > /* > * jpeglib.h > * > * Copyright (C) 1991-1998, Thomas G. Lane. >- * Copyright (C) 2009, D. R. Commander. >+ * Modified 2002-2009 by Guido Vollbeding. >+ * Copyright (C) 2009-2010, D. R. Commander. > * This file is part of the Independent JPEG Group's software. > * For conditions of distribution and use, see the accompanying README file. > * > * This file defines the application interface for the JPEG library. > * Most applications using the library need only include this file, > * and perhaps jerror.h if they want to know the exact error codes. > */ > > #ifndef JPEGLIB_H > #define JPEGLIB_H > >-#ifdef __cplusplus >-extern "C" { >-#endif >- > /* > * First we include the configuration files that record how this > * installation of the JPEG library is set up. jconfig.h can be > * generated automatically for many systems. jmorecfg.h contains > * manual configuration options that most people need not worry about. > */ > > #ifndef JCONFIG_INCLUDED /* in case jinclude.h already did */ > #include "jconfig.h" /* widely used configuration options */ > #endif > #include "jmorecfg.h" /* seldom changed options */ > > >-/* Version ID for the JPEG library. >- * Might be useful for tests like "#if JPEG_LIB_VERSION >= 60". >- */ >- >-#define JPEG_LIB_VERSION 62 /* Version 6b */ >+#ifdef __cplusplus >+#ifndef DONT_USE_EXTERN_C >+extern "C" { >+#endif >+#endif > > > /* Various constants determining the sizes of things. > * All of these are specified by the JPEG standard, so don't change them > * if you want to be compatible. > */ > > #define DCTSIZE 8 /* The basic DCT block is 8x8 samples */ >@@ -144,37 +141,42 @@ > JDIMENSION width_in_blocks; > JDIMENSION height_in_blocks; > /* Size of a DCT block in samples. Always DCTSIZE for compression. > * For decompression this is the size of the output from one DCT block, > * reflecting any scaling we choose to apply during the IDCT step. > * Values of 1,2,4,8 are likely to be supported. Note that different > * components may receive different IDCT scalings. > */ >+#if JPEG_LIB_VERSION >= 70 >+ int DCT_h_scaled_size; >+ int DCT_v_scaled_size; >+#else > int DCT_scaled_size; >+#endif > /* The downsampled dimensions are the component's actual, unpadded number > * of samples at the main buffer (preprocessing/compression interface), thus > * downsampled_width = ceil(image_width * Hi/Hmax) > * and similarly for height. For decompression, IDCT scaling is included, so >- * downsampled_width = ceil(image_width * Hi/Hmax * DCT_scaled_size/DCTSIZE) >+ * downsampled_width = ceil(image_width * Hi/Hmax * DCT_[h_]scaled_size/DCTSIZE) > */ > JDIMENSION downsampled_width; /* actual width in samples */ > JDIMENSION downsampled_height; /* actual height in samples */ > /* This flag is used only for decompression. In cases where some of the > * components will be ignored (eg grayscale output from YCbCr image), > * we can skip most computations for the unused components. > */ > boolean component_needed; /* do we need the value of this component? */ > > /* These values are computed before starting a scan of the component. */ > /* The decompressor output side may not use these variables. */ > int MCU_width; /* number of blocks per MCU, horizontally */ > int MCU_height; /* number of blocks per MCU, vertically */ > int MCU_blocks; /* MCU_width * MCU_height */ >- int MCU_sample_width; /* MCU width in samples, MCU_width*DCT_scaled_size */ >+ int MCU_sample_width; /* MCU width in samples, MCU_width*DCT_[h_]scaled_size */ > int last_col_width; /* # of non-dummy blocks across in last MCU */ > int last_row_height; /* # of non-dummy blocks down in last MCU */ > > /* Saved quantization table for component; NULL if none yet saved. > * See jdinput.c comments about the need for this information. > * This field is currently used only for decompression. > */ > JQUANT_TBL * quant_table; >@@ -300,46 +302,67 @@ > /* Compression parameters --- these fields must be set before calling > * jpeg_start_compress(). We recommend calling jpeg_set_defaults() to > * initialize everything to reasonable defaults, then changing anything > * the application specifically wants to change. That way you won't get > * burnt when new parameters are added. Also note that there are several > * helper routines to simplify changing parameters. > */ > >+#if JPEG_LIB_VERSION >= 70 >+ unsigned int scale_num, scale_denom; /* fraction by which to scale image */ >+ >+ JDIMENSION jpeg_width; /* scaled JPEG image width */ >+ JDIMENSION jpeg_height; /* scaled JPEG image height */ >+ /* Dimensions of actual JPEG image that will be written to file, >+ * derived from input dimensions by scaling factors above. >+ * These fields are computed by jpeg_start_compress(). >+ * You can also use jpeg_calc_jpeg_dimensions() to determine these values >+ * in advance of calling jpeg_start_compress(). >+ */ >+#endif >+ > int data_precision; /* bits of precision in image data */ > > int num_components; /* # of color components in JPEG image */ > J_COLOR_SPACE jpeg_color_space; /* colorspace of JPEG image */ > > jpeg_component_info * comp_info; > /* comp_info[i] describes component that appears i'th in SOF */ >- >+ > JQUANT_TBL * quant_tbl_ptrs[NUM_QUANT_TBLS]; >- /* ptrs to coefficient quantization tables, or NULL if not defined */ >- >+#if JPEG_LIB_VERSION >= 70 >+ int q_scale_factor[NUM_QUANT_TBLS]; >+#endif >+ /* ptrs to coefficient quantization tables, or NULL if not defined, >+ * and corresponding scale factors (percentage, initialized 100). >+ */ >+ > JHUFF_TBL * dc_huff_tbl_ptrs[NUM_HUFF_TBLS]; > JHUFF_TBL * ac_huff_tbl_ptrs[NUM_HUFF_TBLS]; > /* ptrs to Huffman coding tables, or NULL if not defined */ >- >+ > UINT8 arith_dc_L[NUM_ARITH_TBLS]; /* L values for DC arith-coding tables */ > UINT8 arith_dc_U[NUM_ARITH_TBLS]; /* U values for DC arith-coding tables */ > UINT8 arith_ac_K[NUM_ARITH_TBLS]; /* Kx values for AC arith-coding tables */ > > int num_scans; /* # of entries in scan_info array */ > const jpeg_scan_info * scan_info; /* script for multi-scan file, or NULL */ > /* The default value of scan_info is NULL, which causes a single-scan > * sequential JPEG file to be emitted. To create a multi-scan file, > * set num_scans and scan_info to point to an array of scan definitions. > */ > > boolean raw_data_in; /* TRUE=caller supplies downsampled data */ > boolean arith_code; /* TRUE=arithmetic coding, FALSE=Huffman */ > boolean optimize_coding; /* TRUE=optimize entropy encoding parms */ > boolean CCIR601_sampling; /* TRUE=first samples are cosited */ >+#if JPEG_LIB_VERSION >= 70 >+ boolean do_fancy_downsampling; /* TRUE=apply fancy downsampling */ >+#endif > int smoothing_factor; /* 1..100, or 0 for no input smoothing */ > J_DCT_METHOD dct_method; /* DCT algorithm selector */ > > /* The restart interval can be specified in absolute MCUs by setting > * restart_interval, or in MCU rows by setting restart_in_rows > * (in which case the correct restart_interval will be figured > * for each scan). > */ >@@ -373,16 +396,21 @@ > > /* > * These fields are computed during compression startup > */ > boolean progressive_mode; /* TRUE if scan script uses progressive mode */ > int max_h_samp_factor; /* largest h_samp_factor */ > int max_v_samp_factor; /* largest v_samp_factor */ > >+#if JPEG_LIB_VERSION >= 70 >+ int min_DCT_h_scaled_size; /* smallest DCT_h_scaled_size of any component */ >+ int min_DCT_v_scaled_size; /* smallest DCT_v_scaled_size of any component */ >+#endif >+ > JDIMENSION total_iMCU_rows; /* # of iMCU rows to be input to coef ctlr */ > /* The coefficient controller receives data in units of MCU rows as defined > * for fully interleaved scans (whether the JPEG file is interleaved or not). > * There are v_samp_factor * DCTSIZE sample rows of each component in an > * "iMCU" (interleaved MCU) row. > */ > > /* >@@ -398,16 +426,22 @@ > > int blocks_in_MCU; /* # of DCT blocks per MCU */ > int MCU_membership[C_MAX_BLOCKS_IN_MCU]; > /* MCU_membership[i] is index in cur_comp_info of component owning */ > /* i'th block in an MCU */ > > int Ss, Se, Ah, Al; /* progressive JPEG parameters for scan */ > >+#if JPEG_LIB_VERSION >= 80 >+ int block_size; /* the basic DCT block size: 1..16 */ >+ const int * natural_order; /* natural-order position array */ >+ int lim_Se; /* min( Se, DCTSIZE2-1 ) */ >+#endif >+ > /* > * Links to compression subobjects (methods and private variables of modules) > */ > struct jpeg_comp_master * master; > struct jpeg_c_main_controller * main; > struct jpeg_c_prep_controller * prep; > struct jpeg_c_coef_controller * coef; > struct jpeg_marker_writer * marker; >@@ -544,16 +578,19 @@ > * are given in SOF/SOS markers or defined to be reset by SOI. > */ > > int data_precision; /* bits of precision in image data */ > > jpeg_component_info * comp_info; > /* comp_info[i] describes component that appears i'th in SOF */ > >+#if JPEG_LIB_VERSION >= 80 >+ boolean is_baseline; /* TRUE if Baseline SOF0 encountered */ >+#endif > boolean progressive_mode; /* TRUE if SOFn specifies progressive mode */ > boolean arith_code; /* TRUE=arithmetic coding, FALSE=Huffman */ > > UINT8 arith_dc_L[NUM_ARITH_TBLS]; /* L values for DC arith-coding tables */ > UINT8 arith_dc_U[NUM_ARITH_TBLS]; /* U values for DC arith-coding tables */ > UINT8 arith_ac_K[NUM_ARITH_TBLS]; /* Kx values for AC arith-coding tables */ > > unsigned int restart_interval; /* MCUs per restart interval, or 0 for no restart */ >@@ -584,25 +621,30 @@ > */ > > /* > * These fields are computed during decompression startup > */ > int max_h_samp_factor; /* largest h_samp_factor */ > int max_v_samp_factor; /* largest v_samp_factor */ > >+#if JPEG_LIB_VERSION >= 70 >+ int min_DCT_h_scaled_size; /* smallest DCT_h_scaled_size of any component */ >+ int min_DCT_v_scaled_size; /* smallest DCT_v_scaled_size of any component */ >+#else > int min_DCT_scaled_size; /* smallest DCT_scaled_size of any component */ >+#endif > > JDIMENSION total_iMCU_rows; /* # of iMCU rows in image */ > /* The coefficient controller's input and output progress is measured in > * units of "iMCU" (interleaved MCU) rows. These are the same as MCU rows > * in fully interleaved JPEG scans, but are used whether the scan is > * interleaved or not. We define an iMCU row as v_samp_factor DCT block > * rows of each component. Therefore, the IDCT output contains >- * v_samp_factor*DCT_scaled_size sample rows of a component per iMCU row. >+ * v_samp_factor*DCT_[v_]scaled_size sample rows of a component per iMCU row. > */ > > JSAMPLE * sample_range_limit; /* table for fast range-limiting */ > > /* > * These fields are valid during any one scan. > * They describe the components and MCUs actually appearing in the scan. > * Note that the decompressor output side must not use these fields. >@@ -616,16 +658,24 @@ > > int blocks_in_MCU; /* # of DCT blocks per MCU */ > int MCU_membership[D_MAX_BLOCKS_IN_MCU]; > /* MCU_membership[i] is index in cur_comp_info of component owning */ > /* i'th block in an MCU */ > > int Ss, Se, Ah, Al; /* progressive JPEG parameters for scan */ > >+#if JPEG_LIB_VERSION >= 80 >+ /* These fields are derived from Se of first SOS marker. >+ */ >+ int block_size; /* the basic DCT block size: 1..16 */ >+ const int * natural_order; /* natural-order position array for entropy decode */ >+ int lim_Se; /* min( Se, DCTSIZE2-1 ) for entropy decode */ >+#endif >+ > /* This field is shared between entropy decoder and marker parser. > * It is either zero or the code of a JPEG marker that has been > * read from the data source, but has not yet been processed. > */ > int unread_marker; > > /* > * Links to decompression subobjects (methods, private variables of modules) >@@ -845,46 +895,59 @@ > #ifdef NEED_SHORT_EXTERNAL_NAMES > #define jpeg_std_error jStdError > #define jpeg_CreateCompress jCreaCompress > #define jpeg_CreateDecompress jCreaDecompress > #define jpeg_destroy_compress jDestCompress > #define jpeg_destroy_decompress jDestDecompress > #define jpeg_stdio_dest jStdDest > #define jpeg_stdio_src jStdSrc >+#if JPEG_LIB_VERSION >= 80 >+#define jpeg_mem_dest jMemDest >+#define jpeg_mem_src jMemSrc >+#endif > #define jpeg_set_defaults jSetDefaults > #define jpeg_set_colorspace jSetColorspace > #define jpeg_default_colorspace jDefColorspace > #define jpeg_set_quality jSetQuality > #define jpeg_set_linear_quality jSetLQuality >+#if JPEG_LIB_VERSION >= 70 >+#define jpeg_default_qtables jDefQTables >+#endif > #define jpeg_add_quant_table jAddQuantTable > #define jpeg_quality_scaling jQualityScaling > #define jpeg_simple_progression jSimProgress > #define jpeg_suppress_tables jSuppressTables > #define jpeg_alloc_quant_table jAlcQTable > #define jpeg_alloc_huff_table jAlcHTable > #define jpeg_start_compress jStrtCompress > #define jpeg_write_scanlines jWrtScanlines > #define jpeg_finish_compress jFinCompress >+#if JPEG_LIB_VERSION >= 70 >+#define jpeg_calc_jpeg_dimensions jCjpegDimensions >+#endif > #define jpeg_write_raw_data jWrtRawData > #define jpeg_write_marker jWrtMarker > #define jpeg_write_m_header jWrtMHeader > #define jpeg_write_m_byte jWrtMByte > #define jpeg_write_tables jWrtTables > #define jpeg_read_header jReadHeader > #define jpeg_start_decompress jStrtDecompress > #define jpeg_read_scanlines jReadScanlines > #define jpeg_finish_decompress jFinDecompress > #define jpeg_read_raw_data jReadRawData > #define jpeg_has_multiple_scans jHasMultScn > #define jpeg_start_output jStrtOutput > #define jpeg_finish_output jFinOutput > #define jpeg_input_complete jInComplete > #define jpeg_new_colormap jNewCMap > #define jpeg_consume_input jConsumeInput >+#if JPEG_LIB_VERSION >= 80 >+#define jpeg_core_output_dimensions jCoreDimensions >+#endif > #define jpeg_calc_output_dimensions jCalcDimensions > #define jpeg_save_markers jSaveMarkers > #define jpeg_set_marker_processor jSetMarker > #define jpeg_read_coefficients jReadCoefs > #define jpeg_write_coefficients jWrtCoefs > #define jpeg_copy_critical_parameters jCopyCrit > #define jpeg_abort_compress jAbrtCompress > #define jpeg_abort_decompress jAbrtDecompress >@@ -919,27 +982,41 @@ > EXTERN(void) jpeg_destroy_compress JPP((j_compress_ptr cinfo)); > EXTERN(void) jpeg_destroy_decompress JPP((j_decompress_ptr cinfo)); > > /* Standard data source and destination managers: stdio streams. */ > /* Caller is responsible for opening the file before and closing after. */ > EXTERN(void) jpeg_stdio_dest JPP((j_compress_ptr cinfo, FILE * outfile)); > EXTERN(void) jpeg_stdio_src JPP((j_decompress_ptr cinfo, FILE * infile)); > >+#if JPEG_LIB_VERSION >= 80 >+/* Data source and destination managers: memory buffers. */ >+EXTERN(void) jpeg_mem_dest JPP((j_compress_ptr cinfo, >+ unsigned char ** outbuffer, >+ unsigned long * outsize)); >+EXTERN(void) jpeg_mem_src JPP((j_decompress_ptr cinfo, >+ unsigned char * inbuffer, >+ unsigned long insize)); >+#endif >+ > /* Default parameter setup for compression */ > EXTERN(void) jpeg_set_defaults JPP((j_compress_ptr cinfo)); > /* Compression parameter setup aids */ > EXTERN(void) jpeg_set_colorspace JPP((j_compress_ptr cinfo, > J_COLOR_SPACE colorspace)); > EXTERN(void) jpeg_default_colorspace JPP((j_compress_ptr cinfo)); > EXTERN(void) jpeg_set_quality JPP((j_compress_ptr cinfo, int quality, > boolean force_baseline)); > EXTERN(void) jpeg_set_linear_quality JPP((j_compress_ptr cinfo, > int scale_factor, > boolean force_baseline)); >+#if JPEG_LIB_VERSION >= 70 >+EXTERN(void) jpeg_default_qtables JPP((j_compress_ptr cinfo, >+ boolean force_baseline)); >+#endif > EXTERN(void) jpeg_add_quant_table JPP((j_compress_ptr cinfo, int which_tbl, > const unsigned int *basic_table, > int scale_factor, > boolean force_baseline)); > EXTERN(int) jpeg_quality_scaling JPP((int quality)); > EXTERN(void) jpeg_simple_progression JPP((j_compress_ptr cinfo)); > EXTERN(void) jpeg_suppress_tables JPP((j_compress_ptr cinfo, > boolean suppress)); >@@ -949,22 +1026,27 @@ > /* Main entry points for compression */ > EXTERN(void) jpeg_start_compress JPP((j_compress_ptr cinfo, > boolean write_all_tables)); > EXTERN(JDIMENSION) jpeg_write_scanlines JPP((j_compress_ptr cinfo, > JSAMPARRAY scanlines, > JDIMENSION num_lines)); > EXTERN(void) jpeg_finish_compress JPP((j_compress_ptr cinfo)); > >+#if JPEG_LIB_VERSION >= 70 >+/* Precalculate JPEG dimensions for current compression parameters. */ >+EXTERN(void) jpeg_calc_jpeg_dimensions JPP((j_compress_ptr cinfo)); >+#endif >+ > /* Replaces jpeg_write_scanlines when writing raw downsampled data. */ > EXTERN(JDIMENSION) jpeg_write_raw_data JPP((j_compress_ptr cinfo, > JSAMPIMAGE data, > JDIMENSION num_lines)); > >-/* Write a special marker. See libjpeg.doc concerning safe usage. */ >+/* Write a special marker. See libjpeg.txt concerning safe usage. */ > EXTERN(void) jpeg_write_marker > JPP((j_compress_ptr cinfo, int marker, > const JOCTET * dataptr, unsigned int datalen)); > /* Same, but piecemeal. */ > EXTERN(void) jpeg_write_m_header > JPP((j_compress_ptr cinfo, int marker, unsigned int datalen)); > EXTERN(void) jpeg_write_m_byte > JPP((j_compress_ptr cinfo, int val)); >@@ -1008,16 +1090,19 @@ > /* Return value is one of: */ > /* #define JPEG_SUSPENDED 0 Suspended due to lack of input data */ > #define JPEG_REACHED_SOS 1 /* Reached start of new scan */ > #define JPEG_REACHED_EOI 2 /* Reached end of image */ > #define JPEG_ROW_COMPLETED 3 /* Completed one iMCU row */ > #define JPEG_SCAN_COMPLETED 4 /* Completed last iMCU row of a scan */ > > /* Precalculate output dimensions for current decompression parameters. */ >+#if JPEG_LIB_VERSION >= 80 >+EXTERN(void) jpeg_core_output_dimensions JPP((j_decompress_ptr cinfo)); >+#endif > EXTERN(void) jpeg_calc_output_dimensions JPP((j_decompress_ptr cinfo)); > > /* Control saving of COM and APPn markers into marker_list. */ > EXTERN(void) jpeg_save_markers > JPP((j_decompress_ptr cinfo, int marker_code, > unsigned int length_limit)); > > /* Install a special processing method for COM or APPn markers. */ >@@ -1109,6 +1194,8 @@ > > #ifdef __cplusplus >+#ifndef DONT_USE_EXTERN_C > } > #endif >+#endif > > #endif /* JPEGLIB_H */ >--- b/jpeg/jpegtran.1 >+++ /dev/null >@@ -1,238 +0,0 @@ >-.TH JPEGTRAN 1 "3 August 1997" >-.SH NAME >-jpegtran \- lossless transformation of JPEG files >-.SH SYNOPSIS >-.B jpegtran >-[ >-.I options >-] >-[ >-.I filename >-] >-.LP >-.SH DESCRIPTION >-.LP >-.B jpegtran >-performs various useful transformations of JPEG files. >-It can translate the coded representation from one variant of JPEG to another, >-for example from baseline JPEG to progressive JPEG or vice versa. It can also >-perform some rearrangements of the image data, for example turning an image >-from landscape to portrait format by rotation. >-.PP >-.B jpegtran >-works by rearranging the compressed data (DCT coefficients), without >-ever fully decoding the image. Therefore, its transformations are lossless: >-there is no image degradation at all, which would not be true if you used >-.B djpeg >-followed by >-.B cjpeg >-to accomplish the same conversion. But by the same token, >-.B jpegtran >-cannot perform lossy operations such as changing the image quality. >-.PP >-.B jpegtran >-reads the named JPEG/JFIF file, or the standard input if no file is >-named, and produces a JPEG/JFIF file on the standard output. >-.SH OPTIONS >-All switch names may be abbreviated; for example, >-.B \-optimize >-may be written >-.B \-opt >-or >-.BR \-o . >-Upper and lower case are equivalent. >-British spellings are also accepted (e.g., >-.BR \-optimise ), >-though for brevity these are not mentioned below. >-.PP >-To specify the coded JPEG representation used in the output file, >-.B jpegtran >-accepts a subset of the switches recognized by >-.BR cjpeg : >-.TP >-.B \-optimize >-Perform optimization of entropy encoding parameters. >-.TP >-.B \-progressive >-Create progressive JPEG file. >-.TP >-.BI \-restart " N" >-Emit a JPEG restart marker every N MCU rows, or every N MCU blocks if "B" is >-attached to the number. >-.TP >-.BI \-scans " file" >-Use the scan script given in the specified text file. >-.PP >-See >-.BR cjpeg (1) >-for more details about these switches. >-If you specify none of these switches, you get a plain baseline-JPEG output >-file. The quality setting and so forth are determined by the input file. >-.PP >-The image can be losslessly transformed by giving one of these switches: >-.TP >-.B \-flip horizontal >-Mirror image horizontally (left-right). >-.TP >-.B \-flip vertical >-Mirror image vertically (top-bottom). >-.TP >-.B \-rotate 90 >-Rotate image 90 degrees clockwise. >-.TP >-.B \-rotate 180 >-Rotate image 180 degrees. >-.TP >-.B \-rotate 270 >-Rotate image 270 degrees clockwise (or 90 ccw). >-.TP >-.B \-transpose >-Transpose image (across UL-to-LR axis). >-.TP >-.B \-transverse >-Transverse transpose (across UR-to-LL axis). >-.PP >-The transpose transformation has no restrictions regarding image dimensions. >-The other transformations operate rather oddly if the image dimensions are not >-a multiple of the iMCU size (usually 8 or 16 pixels), because they can only >-transform complete blocks of DCT coefficient data in the desired way. >-.PP >-.BR jpegtran 's >-default behavior when transforming an odd-size image is designed >-to preserve exact reversibility and mathematical consistency of the >-transformation set. As stated, transpose is able to flip the entire image >-area. Horizontal mirroring leaves any partial iMCU column at the right edge >-untouched, but is able to flip all rows of the image. Similarly, vertical >-mirroring leaves any partial iMCU row at the bottom edge untouched, but is >-able to flip all columns. The other transforms can be built up as sequences >-of transpose and flip operations; for consistency, their actions on edge >-pixels are defined to be the same as the end result of the corresponding >-transpose-and-flip sequence. >-.PP >-For practical use, you may prefer to discard any untransformable edge pixels >-rather than having a strange-looking strip along the right and/or bottom edges >-of a transformed image. To do this, add the >-.B \-trim >-switch: >-.TP >-.B \-trim >-Drop non-transformable edge blocks. >-.PP >-Obviously, a transformation with >-.B \-trim >-is not reversible, so strictly speaking >-.B jpegtran >-with this switch is not lossless. Also, the expected mathematical >-equivalences between the transformations no longer hold. For example, >-.B \-rot 270 -trim >-trims only the bottom edge, but >-.B \-rot 90 -trim >-followed by >-.B \-rot 180 -trim >-trims both edges. >-.PP >-Another not-strictly-lossless transformation switch is: >-.TP >-.B \-grayscale >-Force grayscale output. >-.PP >-This option discards the chrominance channels if the input image is YCbCr >-(ie, a standard color JPEG), resulting in a grayscale JPEG file. The >-luminance channel is preserved exactly, so this is a better method of reducing >-to grayscale than decompression, conversion, and recompression. This switch >-is particularly handy for fixing a monochrome picture that was mistakenly >-encoded as a color JPEG. (In such a case, the space savings from getting rid >-of the near-empty chroma channels won't be large; but the decoding time for >-a grayscale JPEG is substantially less than that for a color JPEG.) >-.PP >-.B jpegtran >-also recognizes these switches that control what to do with "extra" markers, >-such as comment blocks: >-.TP >-.B \-copy none >-Copy no extra markers from source file. This setting suppresses all >-comments and other excess baggage present in the source file. >-.TP >-.B \-copy comments >-Copy only comment markers. This setting copies comments from the source file, >-but discards any other inessential data. >-.TP >-.B \-copy all >-Copy all extra markers. This setting preserves miscellaneous markers >-found in the source file, such as JFIF thumbnails and Photoshop settings. >-In some files these extra markers can be sizable. >-.PP >-The default behavior is >-.BR "\-copy comments" . >-(Note: in IJG releases v6 and v6a, >-.B jpegtran >-always did the equivalent of >-.BR "\-copy none" .) >-.PP >-Additional switches recognized by jpegtran are: >-.TP >-.BI \-maxmemory " N" >-Set limit for amount of memory to use in processing large images. Value is >-in thousands of bytes, or millions of bytes if "M" is attached to the >-number. For example, >-.B \-max 4m >-selects 4000000 bytes. If more space is needed, temporary files will be used. >-.TP >-.BI \-outfile " name" >-Send output image to the named file, not to standard output. >-.TP >-.B \-verbose >-Enable debug printout. More >-.BR \-v 's >-give more output. Also, version information is printed at startup. >-.TP >-.B \-debug >-Same as >-.BR \-verbose . >-.SH EXAMPLES >-.LP >-This example converts a baseline JPEG file to progressive form: >-.IP >-.B jpegtran \-progressive >-.I foo.jpg >-.B > >-.I fooprog.jpg >-.PP >-This example rotates an image 90 degrees clockwise, discarding any >-unrotatable edge pixels: >-.IP >-.B jpegtran \-rot 90 -trim >-.I foo.jpg >-.B > >-.I foo90.jpg >-.SH ENVIRONMENT >-.TP >-.B JPEGMEM >-If this environment variable is set, its value is the default memory limit. >-The value is specified as described for the >-.B \-maxmemory >-switch. >-.B JPEGMEM >-overrides the default value specified when the program was compiled, and >-itself is overridden by an explicit >-.BR \-maxmemory . >-.SH SEE ALSO >-.BR cjpeg (1), >-.BR djpeg (1), >-.BR rdjpgcom (1), >-.BR wrjpgcom (1) >-.br >-Wallace, Gregory K. "The JPEG Still Picture Compression Standard", >-Communications of the ACM, April 1991 (vol. 34, no. 4), pp. 30-44. >-.SH AUTHOR >-Independent JPEG Group >-.SH BUGS >-Arithmetic coding is not supported for legal reasons. >-.PP >-The transform options can't transform odd-size images perfectly. Use >-.B \-trim >-if you don't like the results without it. >-.PP >-The entire image is read into memory and then written out again, even in >-cases where this isn't really necessary. Expect swapping on large images, >-especially when using the more complex transform options. >--- b/jpeg/jpegtran.c >+++ /dev/null >@@ -1,504 +0,0 @@ >-/* >- * jpegtran.c >- * >- * Copyright (C) 1995-1997, Thomas G. Lane. >- * This file is part of the Independent JPEG Group's software. >- * For conditions of distribution and use, see the accompanying README file. >- * >- * This file contains a command-line user interface for JPEG transcoding. >- * It is very similar to cjpeg.c, but provides lossless transcoding between >- * different JPEG file formats. It also provides some lossless and sort-of- >- * lossless transformations of JPEG data. >- */ >- >-#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */ >-#include "transupp.h" /* Support routines for jpegtran */ >-#include "jversion.h" /* for version message */ >- >-#ifdef USE_CCOMMAND /* command-line reader for Macintosh */ >-#ifdef __MWERKS__ >-#include <SIOUX.h> /* Metrowerks needs this */ >-#include <console.h> /* ... and this */ >-#endif >-#ifdef THINK_C >-#include <console.h> /* Think declares it here */ >-#endif >-#endif >- >- >-/* >- * Argument-parsing code. >- * The switch parser is designed to be useful with DOS-style command line >- * syntax, ie, intermixed switches and file names, where only the switches >- * to the left of a given file name affect processing of that file. >- * The main program in this file doesn't actually use this capability... >- */ >- >- >-static const char * progname; /* program name for error messages */ >-static char * outfilename; /* for -outfile switch */ >-static JCOPY_OPTION copyoption; /* -copy switch */ >-static jpeg_transform_info transformoption; /* image transformation options */ >- >- >-LOCAL(void) >-usage (void) >-/* complain about bad command line */ >-{ >- fprintf(stderr, "usage: %s [switches] ", progname); >-#ifdef TWO_FILE_COMMANDLINE >- fprintf(stderr, "inputfile outputfile\n"); >-#else >- fprintf(stderr, "[inputfile]\n"); >-#endif >- >- fprintf(stderr, "Switches (names may be abbreviated):\n"); >- fprintf(stderr, " -copy none Copy no extra markers from source file\n"); >- fprintf(stderr, " -copy comments Copy only comment markers (default)\n"); >- fprintf(stderr, " -copy all Copy all extra markers\n"); >-#ifdef ENTROPY_OPT_SUPPORTED >- fprintf(stderr, " -optimize Optimize Huffman table (smaller file, but slow compression)\n"); >-#endif >-#ifdef C_PROGRESSIVE_SUPPORTED >- fprintf(stderr, " -progressive Create progressive JPEG file\n"); >-#endif >-#if TRANSFORMS_SUPPORTED >- fprintf(stderr, "Switches for modifying the image:\n"); >- fprintf(stderr, " -grayscale Reduce to grayscale (omit color data)\n"); >- fprintf(stderr, " -flip [horizontal|vertical] Mirror image (left-right or top-bottom)\n"); >- fprintf(stderr, " -rotate [90|180|270] Rotate image (degrees clockwise)\n"); >- fprintf(stderr, " -transpose Transpose image\n"); >- fprintf(stderr, " -transverse Transverse transpose image\n"); >- fprintf(stderr, " -trim Drop non-transformable edge blocks\n"); >-#endif /* TRANSFORMS_SUPPORTED */ >- fprintf(stderr, "Switches for advanced users:\n"); >- fprintf(stderr, " -restart N Set restart interval in rows, or in blocks with B\n"); >- fprintf(stderr, " -maxmemory N Maximum memory to use (in kbytes)\n"); >- fprintf(stderr, " -outfile name Specify name for output file\n"); >- fprintf(stderr, " -verbose or -debug Emit debug output\n"); >- fprintf(stderr, "Switches for wizards:\n"); >-#ifdef C_ARITH_CODING_SUPPORTED >- fprintf(stderr, " -arithmetic Use arithmetic coding\n"); >-#endif >-#ifdef C_MULTISCAN_FILES_SUPPORTED >- fprintf(stderr, " -scans file Create multi-scan JPEG per script file\n"); >-#endif >- exit(EXIT_FAILURE); >-} >- >- >-LOCAL(void) >-select_transform (JXFORM_CODE transform) >-/* Silly little routine to detect multiple transform options, >- * which we can't handle. >- */ >-{ >-#if TRANSFORMS_SUPPORTED >- if (transformoption.transform == JXFORM_NONE || >- transformoption.transform == transform) { >- transformoption.transform = transform; >- } else { >- fprintf(stderr, "%s: can only do one image transformation at a time\n", >- progname); >- usage(); >- } >-#else >- fprintf(stderr, "%s: sorry, image transformation was not compiled\n", >- progname); >- exit(EXIT_FAILURE); >-#endif >-} >- >- >-LOCAL(int) >-parse_switches (j_compress_ptr cinfo, int argc, char **argv, >- int last_file_arg_seen, boolean for_real) >-/* Parse optional switches. >- * Returns argv[] index of first file-name argument (== argc if none). >- * Any file names with indexes <= last_file_arg_seen are ignored; >- * they have presumably been processed in a previous iteration. >- * (Pass 0 for last_file_arg_seen on the first or only iteration.) >- * for_real is FALSE on the first (dummy) pass; we may skip any expensive >- * processing. >- */ >-{ >- int argn; >- char * arg; >- boolean simple_progressive; >- char * scansarg = NULL; /* saves -scans parm if any */ >- >- /* Set up default JPEG parameters. */ >- simple_progressive = FALSE; >- outfilename = NULL; >- copyoption = JCOPYOPT_DEFAULT; >- transformoption.transform = JXFORM_NONE; >- transformoption.trim = FALSE; >- transformoption.force_grayscale = FALSE; >- cinfo->err->trace_level = 0; >- >- /* Scan command line options, adjust parameters */ >- >- for (argn = 1; argn < argc; argn++) { >- arg = argv[argn]; >- if (*arg != '-') { >- /* Not a switch, must be a file name argument */ >- if (argn <= last_file_arg_seen) { >- outfilename = NULL; /* -outfile applies to just one input file */ >- continue; /* ignore this name if previously processed */ >- } >- break; /* else done parsing switches */ >- } >- arg++; /* advance past switch marker character */ >- >- if (keymatch(arg, "arithmetic", 1)) { >- /* Use arithmetic coding. */ >-#ifdef C_ARITH_CODING_SUPPORTED >- cinfo->arith_code = TRUE; >-#else >- fprintf(stderr, "%s: sorry, arithmetic coding not supported\n", >- progname); >- exit(EXIT_FAILURE); >-#endif >- >- } else if (keymatch(arg, "copy", 1)) { >- /* Select which extra markers to copy. */ >- if (++argn >= argc) /* advance to next argument */ >- usage(); >- if (keymatch(argv[argn], "none", 1)) { >- copyoption = JCOPYOPT_NONE; >- } else if (keymatch(argv[argn], "comments", 1)) { >- copyoption = JCOPYOPT_COMMENTS; >- } else if (keymatch(argv[argn], "all", 1)) { >- copyoption = JCOPYOPT_ALL; >- } else >- usage(); >- >- } else if (keymatch(arg, "debug", 1) || keymatch(arg, "verbose", 1)) { >- /* Enable debug printouts. */ >- /* On first -d, print version identification */ >- static boolean printed_version = FALSE; >- >- if (! printed_version) { >- fprintf(stderr, "Independent JPEG Group's JPEGTRAN, version %s\n%s\n", >- JVERSION, JCOPYRIGHT); >- printed_version = TRUE; >- } >- cinfo->err->trace_level++; >- >- } else if (keymatch(arg, "flip", 1)) { >- /* Mirror left-right or top-bottom. */ >- if (++argn >= argc) /* advance to next argument */ >- usage(); >- if (keymatch(argv[argn], "horizontal", 1)) >- select_transform(JXFORM_FLIP_H); >- else if (keymatch(argv[argn], "vertical", 1)) >- select_transform(JXFORM_FLIP_V); >- else >- usage(); >- >- } else if (keymatch(arg, "grayscale", 1) || keymatch(arg, "greyscale",1)) { >- /* Force to grayscale. */ >-#if TRANSFORMS_SUPPORTED >- transformoption.force_grayscale = TRUE; >-#else >- select_transform(JXFORM_NONE); /* force an error */ >-#endif >- >- } else if (keymatch(arg, "maxmemory", 3)) { >- /* Maximum memory in Kb (or Mb with 'm'). */ >- long lval; >- char ch = 'x'; >- >- if (++argn >= argc) /* advance to next argument */ >- usage(); >- if (sscanf(argv[argn], "%ld%c", &lval, &ch) < 1) >- usage(); >- if (ch == 'm' || ch == 'M') >- lval *= 1000L; >- cinfo->mem->max_memory_to_use = lval * 1000L; >- >- } else if (keymatch(arg, "optimize", 1) || keymatch(arg, "optimise", 1)) { >- /* Enable entropy parm optimization. */ >-#ifdef ENTROPY_OPT_SUPPORTED >- cinfo->optimize_coding = TRUE; >-#else >- fprintf(stderr, "%s: sorry, entropy optimization was not compiled\n", >- progname); >- exit(EXIT_FAILURE); >-#endif >- >- } else if (keymatch(arg, "outfile", 4)) { >- /* Set output file name. */ >- if (++argn >= argc) /* advance to next argument */ >- usage(); >- outfilename = argv[argn]; /* save it away for later use */ >- >- } else if (keymatch(arg, "progressive", 1)) { >- /* Select simple progressive mode. */ >-#ifdef C_PROGRESSIVE_SUPPORTED >- simple_progressive = TRUE; >- /* We must postpone execution until num_components is known. */ >-#else >- fprintf(stderr, "%s: sorry, progressive output was not compiled\n", >- progname); >- exit(EXIT_FAILURE); >-#endif >- >- } else if (keymatch(arg, "restart", 1)) { >- /* Restart interval in MCU rows (or in MCUs with 'b'). */ >- long lval; >- char ch = 'x'; >- >- if (++argn >= argc) /* advance to next argument */ >- usage(); >- if (sscanf(argv[argn], "%ld%c", &lval, &ch) < 1) >- usage(); >- if (lval < 0 || lval > 65535L) >- usage(); >- if (ch == 'b' || ch == 'B') { >- cinfo->restart_interval = (unsigned int) lval; >- cinfo->restart_in_rows = 0; /* else prior '-restart n' overrides me */ >- } else { >- cinfo->restart_in_rows = (int) lval; >- /* restart_interval will be computed during startup */ >- } >- >- } else if (keymatch(arg, "rotate", 2)) { >- /* Rotate 90, 180, or 270 degrees (measured clockwise). */ >- if (++argn >= argc) /* advance to next argument */ >- usage(); >- if (keymatch(argv[argn], "90", 2)) >- select_transform(JXFORM_ROT_90); >- else if (keymatch(argv[argn], "180", 3)) >- select_transform(JXFORM_ROT_180); >- else if (keymatch(argv[argn], "270", 3)) >- select_transform(JXFORM_ROT_270); >- else >- usage(); >- >- } else if (keymatch(arg, "scans", 1)) { >- /* Set scan script. */ >-#ifdef C_MULTISCAN_FILES_SUPPORTED >- if (++argn >= argc) /* advance to next argument */ >- usage(); >- scansarg = argv[argn]; >- /* We must postpone reading the file in case -progressive appears. */ >-#else >- fprintf(stderr, "%s: sorry, multi-scan output was not compiled\n", >- progname); >- exit(EXIT_FAILURE); >-#endif >- >- } else if (keymatch(arg, "transpose", 1)) { >- /* Transpose (across UL-to-LR axis). */ >- select_transform(JXFORM_TRANSPOSE); >- >- } else if (keymatch(arg, "transverse", 6)) { >- /* Transverse transpose (across UR-to-LL axis). */ >- select_transform(JXFORM_TRANSVERSE); >- >- } else if (keymatch(arg, "trim", 3)) { >- /* Trim off any partial edge MCUs that the transform can't handle. */ >- transformoption.trim = TRUE; >- >- } else { >- usage(); /* bogus switch */ >- } >- } >- >- /* Post-switch-scanning cleanup */ >- >- if (for_real) { >- >-#ifdef C_PROGRESSIVE_SUPPORTED >- if (simple_progressive) /* process -progressive; -scans can override */ >- jpeg_simple_progression(cinfo); >-#endif >- >-#ifdef C_MULTISCAN_FILES_SUPPORTED >- if (scansarg != NULL) /* process -scans if it was present */ >- if (! read_scan_script(cinfo, scansarg)) >- usage(); >-#endif >- } >- >- return argn; /* return index of next arg (file name) */ >-} >- >- >-/* >- * The main program. >- */ >- >-int >-main (int argc, char **argv) >-{ >- struct jpeg_decompress_struct srcinfo; >- struct jpeg_compress_struct dstinfo; >- struct jpeg_error_mgr jsrcerr, jdsterr; >-#ifdef PROGRESS_REPORT >- struct cdjpeg_progress_mgr progress; >-#endif >- jvirt_barray_ptr * src_coef_arrays; >- jvirt_barray_ptr * dst_coef_arrays; >- int file_index; >- FILE * input_file; >- FILE * output_file; >- >- /* On Mac, fetch a command line. */ >-#ifdef USE_CCOMMAND >- argc = ccommand(&argv); >-#endif >- >- progname = argv[0]; >- if (progname == NULL || progname[0] == 0) >- progname = "jpegtran"; /* in case C library doesn't provide it */ >- >- /* Initialize the JPEG decompression object with default error handling. */ >- srcinfo.err = jpeg_std_error(&jsrcerr); >- jpeg_create_decompress(&srcinfo); >- /* Initialize the JPEG compression object with default error handling. */ >- dstinfo.err = jpeg_std_error(&jdsterr); >- jpeg_create_compress(&dstinfo); >- >- /* Now safe to enable signal catcher. >- * Note: we assume only the decompression object will have virtual arrays. >- */ >-#ifdef NEED_SIGNAL_CATCHER >- enable_signal_catcher((j_common_ptr) &srcinfo); >-#endif >- >- /* Scan command line to find file names. >- * It is convenient to use just one switch-parsing routine, but the switch >- * values read here are mostly ignored; we will rescan the switches after >- * opening the input file. Also note that most of the switches affect the >- * destination JPEG object, so we parse into that and then copy over what >- * needs to affects the source too. >- */ >- >- file_index = parse_switches(&dstinfo, argc, argv, 0, FALSE); >- jsrcerr.trace_level = jdsterr.trace_level; >- srcinfo.mem->max_memory_to_use = dstinfo.mem->max_memory_to_use; >- >-#ifdef TWO_FILE_COMMANDLINE >- /* Must have either -outfile switch or explicit output file name */ >- if (outfilename == NULL) { >- if (file_index != argc-2) { >- fprintf(stderr, "%s: must name one input and one output file\n", >- progname); >- usage(); >- } >- outfilename = argv[file_index+1]; >- } else { >- if (file_index != argc-1) { >- fprintf(stderr, "%s: must name one input and one output file\n", >- progname); >- usage(); >- } >- } >-#else >- /* Unix style: expect zero or one file name */ >- if (file_index < argc-1) { >- fprintf(stderr, "%s: only one input file\n", progname); >- usage(); >- } >-#endif /* TWO_FILE_COMMANDLINE */ >- >- /* Open the input file. */ >- if (file_index < argc) { >- if ((input_file = fopen(argv[file_index], READ_BINARY)) == NULL) { >- fprintf(stderr, "%s: can't open %s\n", progname, argv[file_index]); >- exit(EXIT_FAILURE); >- } >- } else { >- /* default input file is stdin */ >- input_file = read_stdin(); >- } >- >- /* Open the output file. */ >- if (outfilename != NULL) { >- if ((output_file = fopen(outfilename, WRITE_BINARY)) == NULL) { >- fprintf(stderr, "%s: can't open %s\n", progname, outfilename); >- exit(EXIT_FAILURE); >- } >- } else { >- /* default output file is stdout */ >- output_file = write_stdout(); >- } >- >-#ifdef PROGRESS_REPORT >- start_progress_monitor((j_common_ptr) &dstinfo, &progress); >-#endif >- >- /* Specify data source for decompression */ >- jpeg_stdio_src(&srcinfo, input_file); >- >- /* Enable saving of extra markers that we want to copy */ >- jcopy_markers_setup(&srcinfo, copyoption); >- >- /* Read file header */ >- (void) jpeg_read_header(&srcinfo, TRUE); >- >- /* Any space needed by a transform option must be requested before >- * jpeg_read_coefficients so that memory allocation will be done right. >- */ >-#if TRANSFORMS_SUPPORTED >- jtransform_request_workspace(&srcinfo, &transformoption); >-#endif >- >- /* Read source file as DCT coefficients */ >- src_coef_arrays = jpeg_read_coefficients(&srcinfo); >- >- /* Initialize destination compression parameters from source values */ >- jpeg_copy_critical_parameters(&srcinfo, &dstinfo); >- >- /* Adjust destination parameters if required by transform options; >- * also find out which set of coefficient arrays will hold the output. >- */ >-#if TRANSFORMS_SUPPORTED >- dst_coef_arrays = jtransform_adjust_parameters(&srcinfo, &dstinfo, >- src_coef_arrays, >- &transformoption); >-#else >- dst_coef_arrays = src_coef_arrays; >-#endif >- >- /* Adjust default compression parameters by re-parsing the options */ >- file_index = parse_switches(&dstinfo, argc, argv, 0, TRUE); >- >- /* Specify data destination for compression */ >- jpeg_stdio_dest(&dstinfo, output_file); >- >- /* Start compressor (note no image data is actually written here) */ >- jpeg_write_coefficients(&dstinfo, dst_coef_arrays); >- >- /* Copy to the output file any extra markers that we want to preserve */ >- jcopy_markers_execute(&srcinfo, &dstinfo, copyoption); >- >- /* Execute image transformation, if any */ >-#if TRANSFORMS_SUPPORTED >- jtransform_execute_transformation(&srcinfo, &dstinfo, >- src_coef_arrays, >- &transformoption); >-#endif >- >- /* Finish compression and release memory */ >- jpeg_finish_compress(&dstinfo); >- jpeg_destroy_compress(&dstinfo); >- (void) jpeg_finish_decompress(&srcinfo); >- jpeg_destroy_decompress(&srcinfo); >- >- /* Close files, if we opened them */ >- if (input_file != stdin) >- fclose(input_file); >- if (output_file != stdout) >- fclose(output_file); >- >-#ifdef PROGRESS_REPORT >- end_progress_monitor((j_common_ptr) &dstinfo); >-#endif >- >- /* All done. */ >- exit(jsrcerr.num_warnings + jdsterr.num_warnings ?EXIT_WARNING:EXIT_SUCCESS); >- return 0; /* suppress no-return-value warnings */ >-} >diff -U8 b/jpeg/jsimd.h b/jpeg/jsimd.h >--- b/jpeg/jsimd.h >+++ b/jpeg/jsimd.h >@@ -1,15 +1,16 @@ > /* > * jsimd.h > * > * Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB > * > * 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 > * > */ > > /* Short forms of external names for systems with brain-damaged linkers. */ > > #ifdef NEED_SHORT_EXTERNAL_NAMES > #define jsimd_can_rgb_ycc jSCanRgbYcc > #define jsimd_can_ycc_rgb jSCanYccRgb >diff -U8 b/jpeg/jsimd_none.c b/jpeg/jsimd_none.c >--- b/jpeg/jsimd_none.c >+++ b/jpeg/jsimd_none.c >@@ -1,16 +1,17 @@ > /* > * jsimd_none.c > * > * Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB > * Copyright 2009 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 stubs for when there is no SIMD support available. > */ > > #define JPEG_INTERNALS > #include "jinclude.h" > #include "jpeglib.h" > #include "jsimd.h" >diff -U8 b/jpeg/jsimddct.h b/jpeg/jsimddct.h >--- b/jpeg/jsimddct.h >+++ b/jpeg/jsimddct.h >@@ -1,15 +1,16 @@ > /* > * jsimddct.h > * > * Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB > * > * 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 > * > */ > > /* Short forms of external names for systems with brain-damaged linkers. */ > > #ifdef NEED_SHORT_EXTERNAL_NAMES > #define jsimd_can_convsamp jSCanConv > #define jsimd_can_convsamp_float jSCanConvF >--- b/jpeg/rdbmp.c >+++ /dev/null >@@ -1,439 +0,0 @@ >-/* >- * rdbmp.c >- * >- * Copyright (C) 1994-1996, Thomas G. Lane. >- * This file is part of the Independent JPEG Group's software. >- * For conditions of distribution and use, see the accompanying README file. >- * >- * This file contains routines to read input images in Microsoft "BMP" >- * format (MS Windows 3.x, OS/2 1.x, and OS/2 2.x flavors). >- * Currently, only 8-bit and 24-bit images are supported, not 1-bit or >- * 4-bit (feeding such low-depth images into JPEG would be silly anyway). >- * Also, we don't support RLE-compressed files. >- * >- * These routines may need modification for non-Unix environments or >- * specialized applications. As they stand, they assume input from >- * an ordinary stdio stream. They further assume that reading begins >- * at the start of the file; start_input may need work if the >- * user interface has already read some data (e.g., to determine that >- * the file is indeed BMP format). >- * >- * This code contributed by James Arthur Boucher. >- */ >- >-#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */ >- >-#ifdef BMP_SUPPORTED >- >- >-/* Macros to deal with unsigned chars as efficiently as compiler allows */ >- >-#ifdef HAVE_UNSIGNED_CHAR >-typedef unsigned char U_CHAR; >-#define UCH(x) ((int) (x)) >-#else /* !HAVE_UNSIGNED_CHAR */ >-#ifdef CHAR_IS_UNSIGNED >-typedef char U_CHAR; >-#define UCH(x) ((int) (x)) >-#else >-typedef char U_CHAR; >-#define UCH(x) ((int) (x) & 0xFF) >-#endif >-#endif /* HAVE_UNSIGNED_CHAR */ >- >- >-#define ReadOK(file,buffer,len) (JFREAD(file,buffer,len) == ((size_t) (len))) >- >- >-/* Private version of data source object */ >- >-typedef struct _bmp_source_struct * bmp_source_ptr; >- >-typedef struct _bmp_source_struct { >- struct cjpeg_source_struct pub; /* public fields */ >- >- j_compress_ptr cinfo; /* back link saves passing separate parm */ >- >- JSAMPARRAY colormap; /* BMP colormap (converted to my format) */ >- >- jvirt_sarray_ptr whole_image; /* Needed to reverse row order */ >- JDIMENSION source_row; /* Current source row number */ >- JDIMENSION row_width; /* Physical width of scanlines in file */ >- >- int bits_per_pixel; /* remembers 8- or 24-bit format */ >-} bmp_source_struct; >- >- >-LOCAL(int) >-read_byte (bmp_source_ptr sinfo) >-/* Read next byte from BMP file */ >-{ >- register FILE *infile = sinfo->pub.input_file; >- register int c; >- >- if ((c = getc(infile)) == EOF) >- ERREXIT(sinfo->cinfo, JERR_INPUT_EOF); >- return c; >-} >- >- >-LOCAL(void) >-read_colormap (bmp_source_ptr sinfo, int cmaplen, int mapentrysize) >-/* Read the colormap from a BMP file */ >-{ >- int i; >- >- switch (mapentrysize) { >- case 3: >- /* BGR format (occurs in OS/2 files) */ >- for (i = 0; i < cmaplen; i++) { >- sinfo->colormap[2][i] = (JSAMPLE) read_byte(sinfo); >- sinfo->colormap[1][i] = (JSAMPLE) read_byte(sinfo); >- sinfo->colormap[0][i] = (JSAMPLE) read_byte(sinfo); >- } >- break; >- case 4: >- /* BGR0 format (occurs in MS Windows files) */ >- for (i = 0; i < cmaplen; i++) { >- sinfo->colormap[2][i] = (JSAMPLE) read_byte(sinfo); >- sinfo->colormap[1][i] = (JSAMPLE) read_byte(sinfo); >- sinfo->colormap[0][i] = (JSAMPLE) read_byte(sinfo); >- (void) read_byte(sinfo); >- } >- break; >- default: >- ERREXIT(sinfo->cinfo, JERR_BMP_BADCMAP); >- break; >- } >-} >- >- >-/* >- * Read one row of pixels. >- * The image has been read into the whole_image array, but is otherwise >- * unprocessed. We must read it out in top-to-bottom row order, and if >- * it is an 8-bit image, we must expand colormapped pixels to 24bit format. >- */ >- >-METHODDEF(JDIMENSION) >-get_8bit_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo) >-/* This version is for reading 8-bit colormap indexes */ >-{ >- bmp_source_ptr source = (bmp_source_ptr) sinfo; >- register JSAMPARRAY colormap = source->colormap; >- JSAMPARRAY image_ptr; >- register int t; >- register JSAMPROW inptr, outptr; >- register JDIMENSION col; >- >- /* Fetch next row from virtual array */ >- source->source_row--; >- image_ptr = (*cinfo->mem->access_virt_sarray) >- ((j_common_ptr) cinfo, source->whole_image, >- source->source_row, (JDIMENSION) 1, FALSE); >- >- /* Expand the colormap indexes to real data */ >- inptr = image_ptr[0]; >- outptr = source->pub.buffer[0]; >- for (col = cinfo->image_width; col > 0; col--) { >- t = GETJSAMPLE(*inptr++); >- *outptr++ = colormap[0][t]; /* can omit GETJSAMPLE() safely */ >- *outptr++ = colormap[1][t]; >- *outptr++ = colormap[2][t]; >- } >- >- return 1; >-} >- >- >-METHODDEF(JDIMENSION) >-get_24bit_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo) >-/* This version is for reading 24-bit pixels */ >-{ >- bmp_source_ptr source = (bmp_source_ptr) sinfo; >- JSAMPARRAY image_ptr; >- register JSAMPROW inptr, outptr; >- register JDIMENSION col; >- >- /* Fetch next row from virtual array */ >- source->source_row--; >- image_ptr = (*cinfo->mem->access_virt_sarray) >- ((j_common_ptr) cinfo, source->whole_image, >- source->source_row, (JDIMENSION) 1, FALSE); >- >- /* Transfer data. Note source values are in BGR order >- * (even though Microsoft's own documents say the opposite). >- */ >- inptr = image_ptr[0]; >- outptr = source->pub.buffer[0]; >- for (col = cinfo->image_width; col > 0; col--) { >- outptr[2] = *inptr++; /* can omit GETJSAMPLE() safely */ >- outptr[1] = *inptr++; >- outptr[0] = *inptr++; >- outptr += 3; >- } >- >- return 1; >-} >- >- >-/* >- * This method loads the image into whole_image during the first call on >- * get_pixel_rows. The get_pixel_rows pointer is then adjusted to call >- * get_8bit_row or get_24bit_row on subsequent calls. >- */ >- >-METHODDEF(JDIMENSION) >-preload_image (j_compress_ptr cinfo, cjpeg_source_ptr sinfo) >-{ >- bmp_source_ptr source = (bmp_source_ptr) sinfo; >- register FILE *infile = source->pub.input_file; >- register int c; >- register JSAMPROW out_ptr; >- JSAMPARRAY image_ptr; >- JDIMENSION row, col; >- cd_progress_ptr progress = (cd_progress_ptr) cinfo->progress; >- >- /* Read the data into a virtual array in input-file row order. */ >- for (row = 0; row < cinfo->image_height; row++) { >- if (progress != NULL) { >- progress->pub.pass_counter = (long) row; >- progress->pub.pass_limit = (long) cinfo->image_height; >- (*progress->pub.progress_monitor) ((j_common_ptr) cinfo); >- } >- image_ptr = (*cinfo->mem->access_virt_sarray) >- ((j_common_ptr) cinfo, source->whole_image, >- row, (JDIMENSION) 1, TRUE); >- out_ptr = image_ptr[0]; >- for (col = source->row_width; col > 0; col--) { >- /* inline copy of read_byte() for speed */ >- if ((c = getc(infile)) == EOF) >- ERREXIT(cinfo, JERR_INPUT_EOF); >- *out_ptr++ = (JSAMPLE) c; >- } >- } >- if (progress != NULL) >- progress->completed_extra_passes++; >- >- /* Set up to read from the virtual array in top-to-bottom order */ >- switch (source->bits_per_pixel) { >- case 8: >- source->pub.get_pixel_rows = get_8bit_row; >- break; >- case 24: >- source->pub.get_pixel_rows = get_24bit_row; >- break; >- default: >- ERREXIT(cinfo, JERR_BMP_BADDEPTH); >- } >- source->source_row = cinfo->image_height; >- >- /* And read the first row */ >- return (*source->pub.get_pixel_rows) (cinfo, sinfo); >-} >- >- >-/* >- * Read the file header; return image size and component count. >- */ >- >-METHODDEF(void) >-start_input_bmp (j_compress_ptr cinfo, cjpeg_source_ptr sinfo) >-{ >- bmp_source_ptr source = (bmp_source_ptr) sinfo; >- U_CHAR bmpfileheader[14]; >- U_CHAR bmpinfoheader[64]; >-#define GET_2B(array,offset) ((unsigned int) UCH(array[offset]) + \ >- (((unsigned int) UCH(array[offset+1])) << 8)) >-#define GET_4B(array,offset) ((INT32) UCH(array[offset]) + \ >- (((INT32) UCH(array[offset+1])) << 8) + \ >- (((INT32) UCH(array[offset+2])) << 16) + \ >- (((INT32) UCH(array[offset+3])) << 24)) >- INT32 bfOffBits; >- INT32 headerSize; >- INT32 biWidth = 0; /* initialize to avoid compiler warning */ >- INT32 biHeight = 0; >- unsigned int biPlanes; >- INT32 biCompression; >- INT32 biXPelsPerMeter,biYPelsPerMeter; >- INT32 biClrUsed = 0; >- int mapentrysize = 0; /* 0 indicates no colormap */ >- INT32 bPad; >- JDIMENSION row_width; >- >- /* Read and verify the bitmap file header */ >- if (! ReadOK(source->pub.input_file, bmpfileheader, 14)) >- ERREXIT(cinfo, JERR_INPUT_EOF); >- if (GET_2B(bmpfileheader,0) != 0x4D42) /* 'BM' */ >- ERREXIT(cinfo, JERR_BMP_NOT); >- bfOffBits = (INT32) GET_4B(bmpfileheader,10); >- /* We ignore the remaining fileheader fields */ >- >- /* The infoheader might be 12 bytes (OS/2 1.x), 40 bytes (Windows), >- * or 64 bytes (OS/2 2.x). Check the first 4 bytes to find out which. >- */ >- if (! ReadOK(source->pub.input_file, bmpinfoheader, 4)) >- ERREXIT(cinfo, JERR_INPUT_EOF); >- headerSize = (INT32) GET_4B(bmpinfoheader,0); >- if (headerSize < 12 || headerSize > 64) >- ERREXIT(cinfo, JERR_BMP_BADHEADER); >- if (! ReadOK(source->pub.input_file, bmpinfoheader+4, headerSize-4)) >- ERREXIT(cinfo, JERR_INPUT_EOF); >- >- switch ((int) headerSize) { >- case 12: >- /* Decode OS/2 1.x header (Microsoft calls this a BITMAPCOREHEADER) */ >- biWidth = (INT32) GET_2B(bmpinfoheader,4); >- biHeight = (INT32) GET_2B(bmpinfoheader,6); >- biPlanes = GET_2B(bmpinfoheader,8); >- source->bits_per_pixel = (int) GET_2B(bmpinfoheader,10); >- >- switch (source->bits_per_pixel) { >- case 8: /* colormapped image */ >- mapentrysize = 3; /* OS/2 uses RGBTRIPLE colormap */ >- TRACEMS2(cinfo, 1, JTRC_BMP_OS2_MAPPED, (int) biWidth, (int) biHeight); >- break; >- case 24: /* RGB image */ >- TRACEMS2(cinfo, 1, JTRC_BMP_OS2, (int) biWidth, (int) biHeight); >- break; >- default: >- ERREXIT(cinfo, JERR_BMP_BADDEPTH); >- break; >- } >- if (biPlanes != 1) >- ERREXIT(cinfo, JERR_BMP_BADPLANES); >- break; >- case 40: >- case 64: >- /* Decode Windows 3.x header (Microsoft calls this a BITMAPINFOHEADER) */ >- /* or OS/2 2.x header, which has additional fields that we ignore */ >- biWidth = GET_4B(bmpinfoheader,4); >- biHeight = GET_4B(bmpinfoheader,8); >- biPlanes = GET_2B(bmpinfoheader,12); >- source->bits_per_pixel = (int) GET_2B(bmpinfoheader,14); >- biCompression = GET_4B(bmpinfoheader,16); >- biXPelsPerMeter = GET_4B(bmpinfoheader,24); >- biYPelsPerMeter = GET_4B(bmpinfoheader,28); >- biClrUsed = GET_4B(bmpinfoheader,32); >- /* biSizeImage, biClrImportant fields are ignored */ >- >- switch (source->bits_per_pixel) { >- case 8: /* colormapped image */ >- mapentrysize = 4; /* Windows uses RGBQUAD colormap */ >- TRACEMS2(cinfo, 1, JTRC_BMP_MAPPED, (int) biWidth, (int) biHeight); >- break; >- case 24: /* RGB image */ >- TRACEMS2(cinfo, 1, JTRC_BMP, (int) biWidth, (int) biHeight); >- break; >- default: >- ERREXIT(cinfo, JERR_BMP_BADDEPTH); >- break; >- } >- if (biPlanes != 1) >- ERREXIT(cinfo, JERR_BMP_BADPLANES); >- if (biCompression != 0) >- ERREXIT(cinfo, JERR_BMP_COMPRESSED); >- >- if (biXPelsPerMeter > 0 && biYPelsPerMeter > 0) { >- /* Set JFIF density parameters from the BMP data */ >- cinfo->X_density = (UINT16) (biXPelsPerMeter/100); /* 100 cm per meter */ >- cinfo->Y_density = (UINT16) (biYPelsPerMeter/100); >- cinfo->density_unit = 2; /* dots/cm */ >- } >- break; >- default: >- ERREXIT(cinfo, JERR_BMP_BADHEADER); >- break; >- } >- >- /* Compute distance to bitmap data --- will adjust for colormap below */ >- bPad = bfOffBits - (headerSize + 14); >- >- /* Read the colormap, if any */ >- if (mapentrysize > 0) { >- if (biClrUsed <= 0) >- biClrUsed = 256; /* assume it's 256 */ >- else if (biClrUsed > 256) >- ERREXIT(cinfo, JERR_BMP_BADCMAP); >- /* Allocate space to store the colormap */ >- source->colormap = (*cinfo->mem->alloc_sarray) >- ((j_common_ptr) cinfo, JPOOL_IMAGE, >- (JDIMENSION) biClrUsed, (JDIMENSION) 3); >- /* and read it from the file */ >- read_colormap(source, (int) biClrUsed, mapentrysize); >- /* account for size of colormap */ >- bPad -= biClrUsed * mapentrysize; >- } >- >- /* Skip any remaining pad bytes */ >- if (bPad < 0) /* incorrect bfOffBits value? */ >- ERREXIT(cinfo, JERR_BMP_BADHEADER); >- while (--bPad >= 0) { >- (void) read_byte(source); >- } >- >- /* Compute row width in file, including padding to 4-byte boundary */ >- if (source->bits_per_pixel == 24) >- row_width = (JDIMENSION) (biWidth * 3); >- else >- row_width = (JDIMENSION) biWidth; >- while ((row_width & 3) != 0) row_width++; >- source->row_width = row_width; >- >- /* Allocate space for inversion array, prepare for preload pass */ >- source->whole_image = (*cinfo->mem->request_virt_sarray) >- ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE, >- row_width, (JDIMENSION) biHeight, (JDIMENSION) 1); >- source->pub.get_pixel_rows = preload_image; >- if (cinfo->progress != NULL) { >- cd_progress_ptr progress = (cd_progress_ptr) cinfo->progress; >- progress->total_extra_passes++; /* count file input as separate pass */ >- } >- >- /* Allocate one-row buffer for returned data */ >- source->pub.buffer = (*cinfo->mem->alloc_sarray) >- ((j_common_ptr) cinfo, JPOOL_IMAGE, >- (JDIMENSION) (biWidth * 3), (JDIMENSION) 1); >- source->pub.buffer_height = 1; >- >- cinfo->in_color_space = JCS_RGB; >- cinfo->input_components = 3; >- cinfo->data_precision = 8; >- cinfo->image_width = (JDIMENSION) biWidth; >- cinfo->image_height = (JDIMENSION) biHeight; >-} >- >- >-/* >- * Finish up at the end of the file. >- */ >- >-METHODDEF(void) >-finish_input_bmp (j_compress_ptr cinfo, cjpeg_source_ptr sinfo) >-{ >- /* no work */ >-} >- >- >-/* >- * The module selection routine for BMP format input. >- */ >- >-GLOBAL(cjpeg_source_ptr) >-jinit_read_bmp (j_compress_ptr cinfo) >-{ >- bmp_source_ptr source; >- >- /* Create module interface object */ >- source = (bmp_source_ptr) >- (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, >- SIZEOF(bmp_source_struct)); >- source->cinfo = cinfo; /* make back link for subroutines */ >- /* Fill in method ptrs, except get_pixel_rows which start_input sets */ >- source->pub.start_input = start_input_bmp; >- source->pub.finish_input = finish_input_bmp; >- >- return (cjpeg_source_ptr) source; >-} >- >-#endif /* BMP_SUPPORTED */ >--- b/jpeg/rdcolmap.c >+++ /dev/null >@@ -1,253 +0,0 @@ >-/* >- * rdcolmap.c >- * >- * Copyright (C) 1994-1996, Thomas G. Lane. >- * This file is part of the Independent JPEG Group's software. >- * For conditions of distribution and use, see the accompanying README file. >- * >- * This file implements djpeg's "-map file" switch. It reads a source image >- * and constructs a colormap to be supplied to the JPEG decompressor. >- * >- * Currently, these file formats are supported for the map file: >- * GIF: the contents of the GIF's global colormap are used. >- * PPM (either text or raw flavor): the entire file is read and >- * each unique pixel value is entered in the map. >- * Note that reading a large PPM file will be horrendously slow. >- * Typically, a PPM-format map file should contain just one pixel >- * of each desired color. Such a file can be extracted from an >- * ordinary image PPM file with ppmtomap(1). >- * >- * Rescaling a PPM that has a maxval unequal to MAXJSAMPLE is not >- * currently implemented. >- */ >- >-#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */ >- >-#ifdef QUANT_2PASS_SUPPORTED /* otherwise can't quantize to supplied map */ >- >-/* Portions of this code are based on the PBMPLUS library, which is: >-** >-** Copyright (C) 1988 by Jef Poskanzer. >-** >-** Permission to use, copy, modify, and distribute this software and its >-** documentation for any purpose and without fee is hereby granted, provided >-** that the above copyright notice appear in all copies and that both that >-** copyright notice and this permission notice appear in supporting >-** documentation. This software is provided "as is" without express or >-** implied warranty. >-*/ >- >- >-/* >- * Add a (potentially) new color to the color map. >- */ >- >-LOCAL(void) >-add_map_entry (j_decompress_ptr cinfo, int R, int G, int B) >-{ >- JSAMPROW colormap0 = cinfo->colormap[0]; >- JSAMPROW colormap1 = cinfo->colormap[1]; >- JSAMPROW colormap2 = cinfo->colormap[2]; >- int ncolors = cinfo->actual_number_of_colors; >- int index; >- >- /* Check for duplicate color. */ >- for (index = 0; index < ncolors; index++) { >- if (GETJSAMPLE(colormap0[index]) == R && >- GETJSAMPLE(colormap1[index]) == G && >- GETJSAMPLE(colormap2[index]) == B) >- return; /* color is already in map */ >- } >- >- /* Check for map overflow. */ >- if (ncolors >= (MAXJSAMPLE+1)) >- ERREXIT1(cinfo, JERR_QUANT_MANY_COLORS, (MAXJSAMPLE+1)); >- >- /* OK, add color to map. */ >- colormap0[ncolors] = (JSAMPLE) R; >- colormap1[ncolors] = (JSAMPLE) G; >- colormap2[ncolors] = (JSAMPLE) B; >- cinfo->actual_number_of_colors++; >-} >- >- >-/* >- * Extract color map from a GIF file. >- */ >- >-LOCAL(void) >-read_gif_map (j_decompress_ptr cinfo, FILE * infile) >-{ >- int header[13]; >- int i, colormaplen; >- int R, G, B; >- >- /* Initial 'G' has already been read by read_color_map */ >- /* Read the rest of the GIF header and logical screen descriptor */ >- for (i = 1; i < 13; i++) { >- if ((header[i] = getc(infile)) == EOF) >- ERREXIT(cinfo, JERR_BAD_CMAP_FILE); >- } >- >- /* Verify GIF Header */ >- if (header[1] != 'I' || header[2] != 'F') >- ERREXIT(cinfo, JERR_BAD_CMAP_FILE); >- >- /* There must be a global color map. */ >- if ((header[10] & 0x80) == 0) >- ERREXIT(cinfo, JERR_BAD_CMAP_FILE); >- >- /* OK, fetch it. */ >- colormaplen = 2 << (header[10] & 0x07); >- >- for (i = 0; i < colormaplen; i++) { >- R = getc(infile); >- G = getc(infile); >- B = getc(infile); >- if (R == EOF || G == EOF || B == EOF) >- ERREXIT(cinfo, JERR_BAD_CMAP_FILE); >- add_map_entry(cinfo, >- R << (BITS_IN_JSAMPLE-8), >- G << (BITS_IN_JSAMPLE-8), >- B << (BITS_IN_JSAMPLE-8)); >- } >-} >- >- >-/* Support routines for reading PPM */ >- >- >-LOCAL(int) >-pbm_getc (FILE * infile) >-/* Read next char, skipping over any comments */ >-/* A comment/newline sequence is returned as a newline */ >-{ >- register int ch; >- >- ch = getc(infile); >- if (ch == '#') { >- do { >- ch = getc(infile); >- } while (ch != '\n' && ch != EOF); >- } >- return ch; >-} >- >- >-LOCAL(unsigned int) >-read_pbm_integer (j_decompress_ptr cinfo, FILE * infile) >-/* Read an unsigned decimal integer from the PPM file */ >-/* Swallows one trailing character after the integer */ >-/* Note that on a 16-bit-int machine, only values up to 64k can be read. */ >-/* This should not be a problem in practice. */ >-{ >- register int ch; >- register unsigned int val; >- >- /* Skip any leading whitespace */ >- do { >- ch = pbm_getc(infile); >- if (ch == EOF) >- ERREXIT(cinfo, JERR_BAD_CMAP_FILE); >- } while (ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r'); >- >- if (ch < '0' || ch > '9') >- ERREXIT(cinfo, JERR_BAD_CMAP_FILE); >- >- val = ch - '0'; >- while ((ch = pbm_getc(infile)) >= '0' && ch <= '9') { >- val *= 10; >- val += ch - '0'; >- } >- return val; >-} >- >- >-/* >- * Extract color map from a PPM file. >- */ >- >-LOCAL(void) >-read_ppm_map (j_decompress_ptr cinfo, FILE * infile) >-{ >- int c; >- unsigned int w, h, maxval, row, col; >- int R, G, B; >- >- /* Initial 'P' has already been read by read_color_map */ >- c = getc(infile); /* save format discriminator for a sec */ >- >- /* while we fetch the remaining header info */ >- w = read_pbm_integer(cinfo, infile); >- h = read_pbm_integer(cinfo, infile); >- maxval = read_pbm_integer(cinfo, infile); >- >- if (w <= 0 || h <= 0 || maxval <= 0) /* error check */ >- ERREXIT(cinfo, JERR_BAD_CMAP_FILE); >- >- /* For now, we don't support rescaling from an unusual maxval. */ >- if (maxval != (unsigned int) MAXJSAMPLE) >- ERREXIT(cinfo, JERR_BAD_CMAP_FILE); >- >- switch (c) { >- case '3': /* it's a text-format PPM file */ >- for (row = 0; row < h; row++) { >- for (col = 0; col < w; col++) { >- R = read_pbm_integer(cinfo, infile); >- G = read_pbm_integer(cinfo, infile); >- B = read_pbm_integer(cinfo, infile); >- add_map_entry(cinfo, R, G, B); >- } >- } >- break; >- >- case '6': /* it's a raw-format PPM file */ >- for (row = 0; row < h; row++) { >- for (col = 0; col < w; col++) { >- R = getc(infile); >- G = getc(infile); >- B = getc(infile); >- if (R == EOF || G == EOF || B == EOF) >- ERREXIT(cinfo, JERR_BAD_CMAP_FILE); >- add_map_entry(cinfo, R, G, B); >- } >- } >- break; >- >- default: >- ERREXIT(cinfo, JERR_BAD_CMAP_FILE); >- break; >- } >-} >- >- >-/* >- * Main entry point from djpeg.c. >- * Input: opened input file (from file name argument on command line). >- * Output: colormap and actual_number_of_colors fields are set in cinfo. >- */ >- >-GLOBAL(void) >-read_color_map (j_decompress_ptr cinfo, FILE * infile) >-{ >- /* Allocate space for a color map of maximum supported size. */ >- cinfo->colormap = (*cinfo->mem->alloc_sarray) >- ((j_common_ptr) cinfo, JPOOL_IMAGE, >- (JDIMENSION) (MAXJSAMPLE+1), (JDIMENSION) 3); >- cinfo->actual_number_of_colors = 0; /* initialize map to empty */ >- >- /* Read first byte to determine file format */ >- switch (getc(infile)) { >- case 'G': >- read_gif_map(cinfo, infile); >- break; >- case 'P': >- read_ppm_map(cinfo, infile); >- break; >- default: >- ERREXIT(cinfo, JERR_BAD_CMAP_FILE); >- break; >- } >-} >- >-#endif /* QUANT_2PASS_SUPPORTED */ >--- b/jpeg/rdgif.c >+++ /dev/null >@@ -1,38 +0,0 @@ >-/* >- * rdgif.c >- * >- * Copyright (C) 1991-1997, Thomas G. Lane. >- * This file is part of the Independent JPEG Group's software. >- * For conditions of distribution and use, see the accompanying README file. >- * >- * This file contains routines to read input images in GIF format. >- * >- ***************************************************************************** >- * NOTE: to avoid entanglements with Unisys' patent on LZW compression, * >- * the ability to read GIF files has been removed from the IJG distribution. * >- * Sorry about that. * >- ***************************************************************************** >- * >- * We are required to state that >- * "The Graphics Interchange Format(c) is the Copyright property of >- * CompuServe Incorporated. GIF(sm) is a Service Mark property of >- * CompuServe Incorporated." >- */ >- >-#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */ >- >-#ifdef GIF_SUPPORTED >- >-/* >- * The module selection routine for GIF format input. >- */ >- >-GLOBAL(cjpeg_source_ptr) >-jinit_read_gif (j_compress_ptr cinfo) >-{ >- fprintf(stderr, "GIF input is unsupported for legal reasons. Sorry.\n"); >- exit(EXIT_FAILURE); >- return NULL; /* keep compiler happy */ >-} >- >-#endif /* GIF_SUPPORTED */ >--- b/jpeg/rdjpgcom.1 >+++ /dev/null >@@ -1,54 +0,0 @@ >-.TH RDJPGCOM 1 "11 October 1997" >-.SH NAME >-rdjpgcom \- display text comments from a JPEG file >-.SH SYNOPSIS >-.B rdjpgcom >-[ >-.B \-verbose >-] >-[ >-.I filename >-] >-.LP >-.SH DESCRIPTION >-.LP >-.B rdjpgcom >-reads the named JPEG/JFIF file, or the standard input if no file is named, >-and prints any text comments found in the file on the standard output. >-.PP >-The JPEG standard allows "comment" (COM) blocks to occur within a JPEG file. >-Although the standard doesn't actually define what COM blocks are for, they >-are widely used to hold user-supplied text strings. This lets you add >-annotations, titles, index terms, etc to your JPEG files, and later retrieve >-them as text. COM blocks do not interfere with the image stored in the JPEG >-file. The maximum size of a COM block is 64K, but you can have as many of >-them as you like in one JPEG file. >-.SH OPTIONS >-.TP >-.B \-verbose >-Causes >-.B rdjpgcom >-to also display the JPEG image dimensions. >-.PP >-Switch names may be abbreviated, and are not case sensitive. >-.SH HINTS >-.B rdjpgcom >-does not depend on the IJG JPEG library. Its source code is intended as an >-illustration of the minimum amount of code required to parse a JPEG file >-header correctly. >-.PP >-In >-.B \-verbose >-mode, >-.B rdjpgcom >-will also attempt to print the contents of any "APP12" markers as text. >-Some digital cameras produce APP12 markers containing useful textual >-information. If you like, you can modify the source code to print >-other APPn marker types as well. >-.SH SEE ALSO >-.BR cjpeg (1), >-.BR djpeg (1), >-.BR jpegtran (1), >-.BR wrjpgcom (1) >-.SH AUTHOR >-Independent JPEG Group >--- b/jpeg/rdjpgcom.c >+++ /dev/null >@@ -1,496 +0,0 @@ >-/* >- * rdjpgcom.c >- * >- * Copyright (C) 1994-1997, Thomas G. Lane. >- * This file is part of the Independent JPEG Group's software. >- * For conditions of distribution and use, see the accompanying README file. >- * >- * This file contains a very simple stand-alone application that displays >- * the text in COM (comment) markers in a JFIF file. >- * This may be useful as an example of the minimum logic needed to parse >- * JPEG markers. >- */ >- >-#define JPEG_CJPEG_DJPEG /* to get the command-line config symbols */ >-#include "jinclude.h" /* get auto-config symbols, <stdio.h> */ >- >-#include <ctype.h> /* to declare isupper(), tolower() */ >-#ifdef USE_SETMODE >-#include <fcntl.h> /* to declare setmode()'s parameter macros */ >-/* If you have setmode() but not <io.h>, just delete this line: */ >-#include <io.h> /* to declare setmode() */ >-#endif >- >-#ifdef USE_CCOMMAND /* command-line reader for Macintosh */ >-#ifdef __MWERKS__ >-#include <SIOUX.h> /* Metrowerks needs this */ >-#include <console.h> /* ... and this */ >-#endif >-#ifdef THINK_C >-#include <console.h> /* Think declares it here */ >-#endif >-#endif >- >-#ifdef DONT_USE_B_MODE /* define mode parameters for fopen() */ >-#define READ_BINARY "r" >-#else >-#ifdef VMS /* VMS is very nonstandard */ >-#define READ_BINARY "rb", "ctx=stm" >-#else /* standard ANSI-compliant case */ >-#define READ_BINARY "rb" >-#endif >-#endif >- >-#ifndef EXIT_FAILURE /* define exit() codes if not provided */ >-#define EXIT_FAILURE 1 >-#endif >-#ifndef EXIT_SUCCESS >-#ifdef VMS >-#define EXIT_SUCCESS 1 /* VMS is very nonstandard */ >-#else >-#define EXIT_SUCCESS 0 >-#endif >-#endif >- >- >-/* >- * These macros are used to read the input file. >- * To reuse this code in another application, you might need to change these. >- */ >- >-static FILE * infile; /* input JPEG file */ >- >-/* Return next input byte, or EOF if no more */ >-#define NEXTBYTE() getc(infile) >- >- >-/* Error exit handler */ >-#define ERREXIT(msg) (fprintf(stderr, "%s\n", msg), exit(EXIT_FAILURE)) >- >- >-/* Read one byte, testing for EOF */ >-static int >-read_1_byte (void) >-{ >- int c; >- >- c = NEXTBYTE(); >- if (c == EOF) >- ERREXIT("Premature EOF in JPEG file"); >- return c; >-} >- >-/* Read 2 bytes, convert to unsigned int */ >-/* All 2-byte quantities in JPEG markers are MSB first */ >-static unsigned int >-read_2_bytes (void) >-{ >- int c1, c2; >- >- c1 = NEXTBYTE(); >- if (c1 == EOF) >- ERREXIT("Premature EOF in JPEG file"); >- c2 = NEXTBYTE(); >- if (c2 == EOF) >- ERREXIT("Premature EOF in JPEG file"); >- return (((unsigned int) c1) << 8) + ((unsigned int) c2); >-} >- >- >-/* >- * JPEG markers consist of one or more 0xFF bytes, followed by a marker >- * code byte (which is not an FF). Here are the marker codes of interest >- * in this program. (See jdmarker.c for a more complete list.) >- */ >- >-#define M_SOF0 0xC0 /* Start Of Frame N */ >-#define M_SOF1 0xC1 /* N indicates which compression process */ >-#define M_SOF2 0xC2 /* Only SOF0-SOF2 are now in common use */ >-#define M_SOF3 0xC3 >-#define M_SOF5 0xC5 /* NB: codes C4 and CC are NOT SOF markers */ >-#define M_SOF6 0xC6 >-#define M_SOF7 0xC7 >-#define M_SOF9 0xC9 >-#define M_SOF10 0xCA >-#define M_SOF11 0xCB >-#define M_SOF13 0xCD >-#define M_SOF14 0xCE >-#define M_SOF15 0xCF >-#define M_SOI 0xD8 /* Start Of Image (beginning of datastream) */ >-#define M_EOI 0xD9 /* End Of Image (end of datastream) */ >-#define M_SOS 0xDA /* Start Of Scan (begins compressed data) */ >-#define M_APP0 0xE0 /* Application-specific marker, type N */ >-#define M_APP12 0xEC /* (we don't bother to list all 16 APPn's) */ >-#define M_COM 0xFE /* COMment */ >- >- >-/* >- * Find the next JPEG marker and return its marker code. >- * We expect at least one FF byte, possibly more if the compressor used FFs >- * to pad the file. >- * There could also be non-FF garbage between markers. The treatment of such >- * garbage is unspecified; we choose to skip over it but emit a warning msg. >- * NB: this routine must not be used after seeing SOS marker, since it will >- * not deal correctly with FF/00 sequences in the compressed image data... >- */ >- >-static int >-next_marker (void) >-{ >- int c; >- int discarded_bytes = 0; >- >- /* Find 0xFF byte; count and skip any non-FFs. */ >- c = read_1_byte(); >- while (c != 0xFF) { >- discarded_bytes++; >- c = read_1_byte(); >- } >- /* Get marker code byte, swallowing any duplicate FF bytes. Extra FFs >- * are legal as pad bytes, so don't count them in discarded_bytes. >- */ >- do { >- c = read_1_byte(); >- } while (c == 0xFF); >- >- if (discarded_bytes != 0) { >- fprintf(stderr, "Warning: garbage data found in JPEG file\n"); >- } >- >- return c; >-} >- >- >-/* >- * Read the initial marker, which should be SOI. >- * For a JFIF file, the first two bytes of the file should be literally >- * 0xFF M_SOI. To be more general, we could use next_marker, but if the >- * input file weren't actually JPEG at all, next_marker might read the whole >- * file and then return a misleading error message... >- */ >- >-static int >-first_marker (void) >-{ >- int c1, c2; >- >- c1 = NEXTBYTE(); >- c2 = NEXTBYTE(); >- if (c1 != 0xFF || c2 != M_SOI) >- ERREXIT("Not a JPEG file"); >- return c2; >-} >- >- >-/* >- * Most types of marker are followed by a variable-length parameter segment. >- * This routine skips over the parameters for any marker we don't otherwise >- * want to process. >- * Note that we MUST skip the parameter segment explicitly in order not to >- * be fooled by 0xFF bytes that might appear within the parameter segment; >- * such bytes do NOT introduce new markers. >- */ >- >-static void >-skip_variable (void) >-/* Skip over an unknown or uninteresting variable-length marker */ >-{ >- unsigned int length; >- >- /* Get the marker parameter length count */ >- length = read_2_bytes(); >- /* Length includes itself, so must be at least 2 */ >- if (length < 2) >- ERREXIT("Erroneous JPEG marker length"); >- length -= 2; >- /* Skip over the remaining bytes */ >- while (length > 0) { >- (void) read_1_byte(); >- length--; >- } >-} >- >- >-/* >- * Process a COM marker. >- * We want to print out the marker contents as legible text; >- * we must guard against non-text junk and varying newline representations. >- */ >- >-static void >-process_COM (void) >-{ >- unsigned int length; >- int ch; >- int lastch = 0; >- >- /* Get the marker parameter length count */ >- length = read_2_bytes(); >- /* Length includes itself, so must be at least 2 */ >- if (length < 2) >- ERREXIT("Erroneous JPEG marker length"); >- length -= 2; >- >- while (length > 0) { >- ch = read_1_byte(); >- /* Emit the character in a readable form. >- * Nonprintables are converted to \nnn form, >- * while \ is converted to \\. >- * Newlines in CR, CR/LF, or LF form will be printed as one newline. >- */ >- if (ch == '\r') { >- printf("\n"); >- } else if (ch == '\n') { >- if (lastch != '\r') >- printf("\n"); >- } else if (ch == '\\') { >- printf("\\\\"); >- } else if (isprint(ch)) { >- putc(ch, stdout); >- } else { >- printf("\\%03o", ch); >- } >- lastch = ch; >- length--; >- } >- printf("\n"); >-} >- >- >-/* >- * Process a SOFn marker. >- * This code is only needed if you want to know the image dimensions... >- */ >- >-static void >-process_SOFn (int marker) >-{ >- unsigned int length; >- unsigned int image_height, image_width; >- int data_precision, num_components; >- const char * process; >- int ci; >- >- length = read_2_bytes(); /* usual parameter length count */ >- >- data_precision = read_1_byte(); >- image_height = read_2_bytes(); >- image_width = read_2_bytes(); >- num_components = read_1_byte(); >- >- switch (marker) { >- case M_SOF0: process = "Baseline"; break; >- case M_SOF1: process = "Extended sequential"; break; >- case M_SOF2: process = "Progressive"; break; >- case M_SOF3: process = "Lossless"; break; >- case M_SOF5: process = "Differential sequential"; break; >- case M_SOF6: process = "Differential progressive"; break; >- case M_SOF7: process = "Differential lossless"; break; >- case M_SOF9: process = "Extended sequential, arithmetic coding"; break; >- case M_SOF10: process = "Progressive, arithmetic coding"; break; >- case M_SOF11: process = "Lossless, arithmetic coding"; break; >- case M_SOF13: process = "Differential sequential, arithmetic coding"; break; >- case M_SOF14: process = "Differential progressive, arithmetic coding"; break; >- case M_SOF15: process = "Differential lossless, arithmetic coding"; break; >- default: process = "Unknown"; break; >- } >- >- printf("JPEG image is %uw * %uh, %d color components, %d bits per sample\n", >- image_width, image_height, num_components, data_precision); >- printf("JPEG process: %s\n", process); >- >- if (length != (unsigned int) (8 + num_components * 3)) >- ERREXIT("Bogus SOF marker length"); >- >- for (ci = 0; ci < num_components; ci++) { >- (void) read_1_byte(); /* Component ID code */ >- (void) read_1_byte(); /* H, V sampling factors */ >- (void) read_1_byte(); /* Quantization table number */ >- } >-} >- >- >-/* >- * Parse the marker stream until SOS or EOI is seen; >- * display any COM markers. >- * While the companion program wrjpgcom will always insert COM markers before >- * SOFn, other implementations might not, so we scan to SOS before stopping. >- * If we were only interested in the image dimensions, we would stop at SOFn. >- * (Conversely, if we only cared about COM markers, there would be no need >- * for special code to handle SOFn; we could treat it like other markers.) >- */ >- >-static int >-scan_JPEG_header (int verbose) >-{ >- int marker; >- >- /* Expect SOI at start of file */ >- if (first_marker() != M_SOI) >- ERREXIT("Expected SOI marker first"); >- >- /* Scan miscellaneous markers until we reach SOS. */ >- for (;;) { >- marker = next_marker(); >- switch (marker) { >- /* Note that marker codes 0xC4, 0xC8, 0xCC are not, and must not be, >- * treated as SOFn. C4 in particular is actually DHT. >- */ >- case M_SOF0: /* Baseline */ >- case M_SOF1: /* Extended sequential, Huffman */ >- case M_SOF2: /* Progressive, Huffman */ >- case M_SOF3: /* Lossless, Huffman */ >- case M_SOF5: /* Differential sequential, Huffman */ >- case M_SOF6: /* Differential progressive, Huffman */ >- case M_SOF7: /* Differential lossless, Huffman */ >- case M_SOF9: /* Extended sequential, arithmetic */ >- case M_SOF10: /* Progressive, arithmetic */ >- case M_SOF11: /* Lossless, arithmetic */ >- case M_SOF13: /* Differential sequential, arithmetic */ >- case M_SOF14: /* Differential progressive, arithmetic */ >- case M_SOF15: /* Differential lossless, arithmetic */ >- if (verbose) >- process_SOFn(marker); >- else >- skip_variable(); >- break; >- >- case M_SOS: /* stop before hitting compressed data */ >- return marker; >- >- case M_EOI: /* in case it's a tables-only JPEG stream */ >- return marker; >- >- case M_COM: >- process_COM(); >- break; >- >- case M_APP12: >- /* Some digital camera makers put useful textual information into >- * APP12 markers, so we print those out too when in -verbose mode. >- */ >- if (verbose) { >- printf("APP12 contains:\n"); >- process_COM(); >- } else >- skip_variable(); >- break; >- >- default: /* Anything else just gets skipped */ >- skip_variable(); /* we assume it has a parameter count... */ >- break; >- } >- } /* end loop */ >-} >- >- >-/* Command line parsing code */ >- >-static const char * progname; /* program name for error messages */ >- >- >-static void >-usage (void) >-/* complain about bad command line */ >-{ >- fprintf(stderr, "rdjpgcom displays any textual comments in a JPEG file.\n"); >- >- fprintf(stderr, "Usage: %s [switches] [inputfile]\n", progname); >- >- fprintf(stderr, "Switches (names may be abbreviated):\n"); >- fprintf(stderr, " -verbose Also display dimensions of JPEG image\n"); >- >- exit(EXIT_FAILURE); >-} >- >- >-static int >-keymatch (char * arg, const char * keyword, int minchars) >-/* Case-insensitive matching of (possibly abbreviated) keyword switches. */ >-/* keyword is the constant keyword (must be lower case already), */ >-/* minchars is length of minimum legal abbreviation. */ >-{ >- register int ca, ck; >- register int nmatched = 0; >- >- while ((ca = *arg++) != '\0') { >- if ((ck = *keyword++) == '\0') >- return 0; /* arg longer than keyword, no good */ >- if (isupper(ca)) /* force arg to lcase (assume ck is already) */ >- ca = tolower(ca); >- if (ca != ck) >- return 0; /* no good */ >- nmatched++; /* count matched characters */ >- } >- /* reached end of argument; fail if it's too short for unique abbrev */ >- if (nmatched < minchars) >- return 0; >- return 1; /* A-OK */ >-} >- >- >-/* >- * The main program. >- */ >- >-int >-main (int argc, char **argv) >-{ >- int argn; >- char * arg; >- int verbose = 0; >- >- /* On Mac, fetch a command line. */ >-#ifdef USE_CCOMMAND >- argc = ccommand(&argv); >-#endif >- >- progname = argv[0]; >- if (progname == NULL || progname[0] == 0) >- progname = "rdjpgcom"; /* in case C library doesn't provide it */ >- >- /* Parse switches, if any */ >- for (argn = 1; argn < argc; argn++) { >- arg = argv[argn]; >- if (arg[0] != '-') >- break; /* not switch, must be file name */ >- arg++; /* advance over '-' */ >- if (keymatch(arg, "verbose", 1)) { >- verbose++; >- } else >- usage(); >- } >- >- /* Open the input file. */ >- /* Unix style: expect zero or one file name */ >- if (argn < argc-1) { >- fprintf(stderr, "%s: only one input file\n", progname); >- usage(); >- } >- if (argn < argc) { >- if ((infile = fopen(argv[argn], READ_BINARY)) == NULL) { >- fprintf(stderr, "%s: can't open %s\n", progname, argv[argn]); >- exit(EXIT_FAILURE); >- } >- } else { >- /* default input file is stdin */ >-#ifdef USE_SETMODE /* need to hack file mode? */ >- setmode(fileno(stdin), O_BINARY); >-#endif >-#ifdef USE_FDOPEN /* need to re-open in binary mode? */ >- if ((infile = fdopen(fileno(stdin), READ_BINARY)) == NULL) { >- fprintf(stderr, "%s: can't open stdin\n", progname); >- exit(EXIT_FAILURE); >- } >-#else >- infile = stdin; >-#endif >- } >- >- /* Scan the JPEG headers. */ >- (void) scan_JPEG_header(verbose); >- >- /* All done. */ >- exit(EXIT_SUCCESS); >- return 0; /* suppress no-return-value warnings */ >-} >--- b/jpeg/rdppm.c >+++ /dev/null >@@ -1,458 +0,0 @@ >-/* >- * rdppm.c >- * >- * Copyright (C) 1991-1997, Thomas G. Lane. >- * This file is part of the Independent JPEG Group's software. >- * For conditions of distribution and use, see the accompanying README file. >- * >- * This file contains routines to read input images in PPM/PGM format. >- * The extended 2-byte-per-sample raw PPM/PGM formats are supported. >- * The PBMPLUS library is NOT required to compile this software >- * (but it is highly useful as a set of PPM image manipulation programs). >- * >- * These routines may need modification for non-Unix environments or >- * specialized applications. As they stand, they assume input from >- * an ordinary stdio stream. They further assume that reading begins >- * at the start of the file; start_input may need work if the >- * user interface has already read some data (e.g., to determine that >- * the file is indeed PPM format). >- */ >- >-#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */ >- >-#ifdef PPM_SUPPORTED >- >- >-/* Portions of this code are based on the PBMPLUS library, which is: >-** >-** Copyright (C) 1988 by Jef Poskanzer. >-** >-** Permission to use, copy, modify, and distribute this software and its >-** documentation for any purpose and without fee is hereby granted, provided >-** that the above copyright notice appear in all copies and that both that >-** copyright notice and this permission notice appear in supporting >-** documentation. This software is provided "as is" without express or >-** implied warranty. >-*/ >- >- >-/* Macros to deal with unsigned chars as efficiently as compiler allows */ >- >-#ifdef HAVE_UNSIGNED_CHAR >-typedef unsigned char U_CHAR; >-#define UCH(x) ((int) (x)) >-#else /* !HAVE_UNSIGNED_CHAR */ >-#ifdef CHAR_IS_UNSIGNED >-typedef char U_CHAR; >-#define UCH(x) ((int) (x)) >-#else >-typedef char U_CHAR; >-#define UCH(x) ((int) (x) & 0xFF) >-#endif >-#endif /* HAVE_UNSIGNED_CHAR */ >- >- >-#define ReadOK(file,buffer,len) (JFREAD(file,buffer,len) == ((size_t) (len))) >- >- >-/* >- * On most systems, reading individual bytes with getc() is drastically less >- * efficient than buffering a row at a time with fread(). On PCs, we must >- * allocate the buffer in near data space, because we are assuming small-data >- * memory model, wherein fread() can't reach far memory. If you need to >- * process very wide images on a PC, you might have to compile in large-memory >- * model, or else replace fread() with a getc() loop --- which will be much >- * slower. >- */ >- >- >-/* Private version of data source object */ >- >-typedef struct { >- struct cjpeg_source_struct pub; /* public fields */ >- >- U_CHAR *iobuffer; /* non-FAR pointer to I/O buffer */ >- JSAMPROW pixrow; /* FAR pointer to same */ >- size_t buffer_width; /* width of I/O buffer */ >- JSAMPLE *rescale; /* => maxval-remapping array, or NULL */ >-} ppm_source_struct; >- >-typedef ppm_source_struct * ppm_source_ptr; >- >- >-LOCAL(int) >-pbm_getc (FILE * infile) >-/* Read next char, skipping over any comments */ >-/* A comment/newline sequence is returned as a newline */ >-{ >- register int ch; >- >- ch = getc(infile); >- if (ch == '#') { >- do { >- ch = getc(infile); >- } while (ch != '\n' && ch != EOF); >- } >- return ch; >-} >- >- >-LOCAL(unsigned int) >-read_pbm_integer (j_compress_ptr cinfo, FILE * infile) >-/* Read an unsigned decimal integer from the PPM file */ >-/* Swallows one trailing character after the integer */ >-/* Note that on a 16-bit-int machine, only values up to 64k can be read. */ >-/* This should not be a problem in practice. */ >-{ >- register int ch; >- register unsigned int val; >- >- /* Skip any leading whitespace */ >- do { >- ch = pbm_getc(infile); >- if (ch == EOF) >- ERREXIT(cinfo, JERR_INPUT_EOF); >- } while (ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r'); >- >- if (ch < '0' || ch > '9') >- ERREXIT(cinfo, JERR_PPM_NONNUMERIC); >- >- val = ch - '0'; >- while ((ch = pbm_getc(infile)) >= '0' && ch <= '9') { >- val *= 10; >- val += ch - '0'; >- } >- return val; >-} >- >- >-/* >- * Read one row of pixels. >- * >- * We provide several different versions depending on input file format. >- * In all cases, input is scaled to the size of JSAMPLE. >- * >- * A really fast path is provided for reading byte/sample raw files with >- * maxval = MAXJSAMPLE, which is the normal case for 8-bit data. >- */ >- >- >-METHODDEF(JDIMENSION) >-get_text_gray_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo) >-/* This version is for reading text-format PGM files with any maxval */ >-{ >- ppm_source_ptr source = (ppm_source_ptr) sinfo; >- FILE * infile = source->pub.input_file; >- register JSAMPROW ptr; >- register JSAMPLE *rescale = source->rescale; >- JDIMENSION col; >- >- ptr = source->pub.buffer[0]; >- for (col = cinfo->image_width; col > 0; col--) { >- *ptr++ = rescale[read_pbm_integer(cinfo, infile)]; >- } >- return 1; >-} >- >- >-METHODDEF(JDIMENSION) >-get_text_rgb_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo) >-/* This version is for reading text-format PPM files with any maxval */ >-{ >- ppm_source_ptr source = (ppm_source_ptr) sinfo; >- FILE * infile = source->pub.input_file; >- register JSAMPROW ptr; >- register JSAMPLE *rescale = source->rescale; >- JDIMENSION col; >- >- ptr = source->pub.buffer[0]; >- for (col = cinfo->image_width; col > 0; col--) { >- *ptr++ = rescale[read_pbm_integer(cinfo, infile)]; >- *ptr++ = rescale[read_pbm_integer(cinfo, infile)]; >- *ptr++ = rescale[read_pbm_integer(cinfo, infile)]; >- } >- return 1; >-} >- >- >-METHODDEF(JDIMENSION) >-get_scaled_gray_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo) >-/* This version is for reading raw-byte-format PGM files with any maxval */ >-{ >- ppm_source_ptr source = (ppm_source_ptr) sinfo; >- register JSAMPROW ptr; >- register U_CHAR * bufferptr; >- register JSAMPLE *rescale = source->rescale; >- JDIMENSION col; >- >- if (! ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width)) >- ERREXIT(cinfo, JERR_INPUT_EOF); >- ptr = source->pub.buffer[0]; >- bufferptr = source->iobuffer; >- for (col = cinfo->image_width; col > 0; col--) { >- *ptr++ = rescale[UCH(*bufferptr++)]; >- } >- return 1; >-} >- >- >-METHODDEF(JDIMENSION) >-get_scaled_rgb_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo) >-/* This version is for reading raw-byte-format PPM files with any maxval */ >-{ >- ppm_source_ptr source = (ppm_source_ptr) sinfo; >- register JSAMPROW ptr; >- register U_CHAR * bufferptr; >- register JSAMPLE *rescale = source->rescale; >- JDIMENSION col; >- >- if (! ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width)) >- ERREXIT(cinfo, JERR_INPUT_EOF); >- ptr = source->pub.buffer[0]; >- bufferptr = source->iobuffer; >- for (col = cinfo->image_width; col > 0; col--) { >- *ptr++ = rescale[UCH(*bufferptr++)]; >- *ptr++ = rescale[UCH(*bufferptr++)]; >- *ptr++ = rescale[UCH(*bufferptr++)]; >- } >- return 1; >-} >- >- >-METHODDEF(JDIMENSION) >-get_raw_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo) >-/* This version is for reading raw-byte-format files with maxval = MAXJSAMPLE. >- * In this case we just read right into the JSAMPLE buffer! >- * Note that same code works for PPM and PGM files. >- */ >-{ >- ppm_source_ptr source = (ppm_source_ptr) sinfo; >- >- if (! ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width)) >- ERREXIT(cinfo, JERR_INPUT_EOF); >- return 1; >-} >- >- >-METHODDEF(JDIMENSION) >-get_word_gray_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo) >-/* This version is for reading raw-word-format PGM files with any maxval */ >-{ >- ppm_source_ptr source = (ppm_source_ptr) sinfo; >- register JSAMPROW ptr; >- register U_CHAR * bufferptr; >- register JSAMPLE *rescale = source->rescale; >- JDIMENSION col; >- >- if (! ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width)) >- ERREXIT(cinfo, JERR_INPUT_EOF); >- ptr = source->pub.buffer[0]; >- bufferptr = source->iobuffer; >- for (col = cinfo->image_width; col > 0; col--) { >- register int temp; >- temp = UCH(*bufferptr++); >- temp |= UCH(*bufferptr++) << 8; >- *ptr++ = rescale[temp]; >- } >- return 1; >-} >- >- >-METHODDEF(JDIMENSION) >-get_word_rgb_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo) >-/* This version is for reading raw-word-format PPM files with any maxval */ >-{ >- ppm_source_ptr source = (ppm_source_ptr) sinfo; >- register JSAMPROW ptr; >- register U_CHAR * bufferptr; >- register JSAMPLE *rescale = source->rescale; >- JDIMENSION col; >- >- if (! ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width)) >- ERREXIT(cinfo, JERR_INPUT_EOF); >- ptr = source->pub.buffer[0]; >- bufferptr = source->iobuffer; >- for (col = cinfo->image_width; col > 0; col--) { >- register int temp; >- temp = UCH(*bufferptr++); >- temp |= UCH(*bufferptr++) << 8; >- *ptr++ = rescale[temp]; >- temp = UCH(*bufferptr++); >- temp |= UCH(*bufferptr++) << 8; >- *ptr++ = rescale[temp]; >- temp = UCH(*bufferptr++); >- temp |= UCH(*bufferptr++) << 8; >- *ptr++ = rescale[temp]; >- } >- return 1; >-} >- >- >-/* >- * Read the file header; return image size and component count. >- */ >- >-METHODDEF(void) >-start_input_ppm (j_compress_ptr cinfo, cjpeg_source_ptr sinfo) >-{ >- ppm_source_ptr source = (ppm_source_ptr) sinfo; >- int c; >- unsigned int w, h, maxval; >- boolean need_iobuffer, use_raw_buffer, need_rescale; >- >- if (getc(source->pub.input_file) != 'P') >- ERREXIT(cinfo, JERR_PPM_NOT); >- >- c = getc(source->pub.input_file); /* subformat discriminator character */ >- >- /* detect unsupported variants (ie, PBM) before trying to read header */ >- switch (c) { >- case '2': /* it's a text-format PGM file */ >- case '3': /* it's a text-format PPM file */ >- case '5': /* it's a raw-format PGM file */ >- case '6': /* it's a raw-format PPM file */ >- break; >- default: >- ERREXIT(cinfo, JERR_PPM_NOT); >- break; >- } >- >- /* fetch the remaining header info */ >- w = read_pbm_integer(cinfo, source->pub.input_file); >- h = read_pbm_integer(cinfo, source->pub.input_file); >- maxval = read_pbm_integer(cinfo, source->pub.input_file); >- >- if (w <= 0 || h <= 0 || maxval <= 0) /* error check */ >- ERREXIT(cinfo, JERR_PPM_NOT); >- >- cinfo->data_precision = BITS_IN_JSAMPLE; /* we always rescale data to this */ >- cinfo->image_width = (JDIMENSION) w; >- cinfo->image_height = (JDIMENSION) h; >- >- /* initialize flags to most common settings */ >- need_iobuffer = TRUE; /* do we need an I/O buffer? */ >- use_raw_buffer = FALSE; /* do we map input buffer onto I/O buffer? */ >- need_rescale = TRUE; /* do we need a rescale array? */ >- >- switch (c) { >- case '2': /* it's a text-format PGM file */ >- cinfo->input_components = 1; >- cinfo->in_color_space = JCS_GRAYSCALE; >- TRACEMS2(cinfo, 1, JTRC_PGM_TEXT, w, h); >- source->pub.get_pixel_rows = get_text_gray_row; >- need_iobuffer = FALSE; >- break; >- >- case '3': /* it's a text-format PPM file */ >- cinfo->input_components = 3; >- cinfo->in_color_space = JCS_RGB; >- TRACEMS2(cinfo, 1, JTRC_PPM_TEXT, w, h); >- source->pub.get_pixel_rows = get_text_rgb_row; >- need_iobuffer = FALSE; >- break; >- >- case '5': /* it's a raw-format PGM file */ >- cinfo->input_components = 1; >- cinfo->in_color_space = JCS_GRAYSCALE; >- TRACEMS2(cinfo, 1, JTRC_PGM, w, h); >- if (maxval > 255) { >- source->pub.get_pixel_rows = get_word_gray_row; >- } else if (maxval == MAXJSAMPLE && SIZEOF(JSAMPLE) == SIZEOF(U_CHAR)) { >- source->pub.get_pixel_rows = get_raw_row; >- use_raw_buffer = TRUE; >- need_rescale = FALSE; >- } else { >- source->pub.get_pixel_rows = get_scaled_gray_row; >- } >- break; >- >- case '6': /* it's a raw-format PPM file */ >- cinfo->input_components = 3; >- cinfo->in_color_space = JCS_RGB; >- TRACEMS2(cinfo, 1, JTRC_PPM, w, h); >- if (maxval > 255) { >- source->pub.get_pixel_rows = get_word_rgb_row; >- } else if (maxval == MAXJSAMPLE && SIZEOF(JSAMPLE) == SIZEOF(U_CHAR)) { >- source->pub.get_pixel_rows = get_raw_row; >- use_raw_buffer = TRUE; >- need_rescale = FALSE; >- } else { >- source->pub.get_pixel_rows = get_scaled_rgb_row; >- } >- break; >- } >- >- /* Allocate space for I/O buffer: 1 or 3 bytes or words/pixel. */ >- if (need_iobuffer) { >- source->buffer_width = (size_t) w * cinfo->input_components * >- ((maxval<=255) ? SIZEOF(U_CHAR) : (2*SIZEOF(U_CHAR))); >- source->iobuffer = (U_CHAR *) >- (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, >- source->buffer_width); >- } >- >- /* Create compressor input buffer. */ >- if (use_raw_buffer) { >- /* For unscaled raw-input case, we can just map it onto the I/O buffer. */ >- /* Synthesize a JSAMPARRAY pointer structure */ >- /* Cast here implies near->far pointer conversion on PCs */ >- source->pixrow = (JSAMPROW) source->iobuffer; >- source->pub.buffer = & source->pixrow; >- source->pub.buffer_height = 1; >- } else { >- /* Need to translate anyway, so make a separate sample buffer. */ >- source->pub.buffer = (*cinfo->mem->alloc_sarray) >- ((j_common_ptr) cinfo, JPOOL_IMAGE, >- (JDIMENSION) w * cinfo->input_components, (JDIMENSION) 1); >- source->pub.buffer_height = 1; >- } >- >- /* Compute the rescaling array if required. */ >- if (need_rescale) { >- INT32 val, half_maxval; >- >- /* On 16-bit-int machines we have to be careful of maxval = 65535 */ >- source->rescale = (JSAMPLE *) >- (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, >- (size_t) (((long) maxval + 1L) * SIZEOF(JSAMPLE))); >- half_maxval = maxval / 2; >- for (val = 0; val <= (INT32) maxval; val++) { >- /* The multiplication here must be done in 32 bits to avoid overflow */ >- source->rescale[val] = (JSAMPLE) ((val*MAXJSAMPLE + half_maxval)/maxval); >- } >- } >-} >- >- >-/* >- * Finish up at the end of the file. >- */ >- >-METHODDEF(void) >-finish_input_ppm (j_compress_ptr cinfo, cjpeg_source_ptr sinfo) >-{ >- /* no work */ >-} >- >- >-/* >- * The module selection routine for PPM format input. >- */ >- >-GLOBAL(cjpeg_source_ptr) >-jinit_read_ppm (j_compress_ptr cinfo) >-{ >- ppm_source_ptr source; >- >- /* Create module interface object */ >- source = (ppm_source_ptr) >- (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, >- SIZEOF(ppm_source_struct)); >- /* Fill in method ptrs, except get_pixel_rows which start_input sets */ >- source->pub.start_input = start_input_ppm; >- source->pub.finish_input = finish_input_ppm; >- >- return (cjpeg_source_ptr) source; >-} >- >-#endif /* PPM_SUPPORTED */ >--- b/jpeg/rdrle.c >+++ /dev/null >@@ -1,387 +0,0 @@ >-/* >- * rdrle.c >- * >- * Copyright (C) 1991-1996, Thomas G. Lane. >- * This file is part of the Independent JPEG Group's software. >- * For conditions of distribution and use, see the accompanying README file. >- * >- * This file contains routines to read input images in Utah RLE format. >- * The Utah Raster Toolkit library is required (version 3.1 or later). >- * >- * These routines may need modification for non-Unix environments or >- * specialized applications. As they stand, they assume input from >- * an ordinary stdio stream. They further assume that reading begins >- * at the start of the file; start_input may need work if the >- * user interface has already read some data (e.g., to determine that >- * the file is indeed RLE format). >- * >- * Based on code contributed by Mike Lijewski, >- * with updates from Robert Hutchinson. >- */ >- >-#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */ >- >-#ifdef RLE_SUPPORTED >- >-/* rle.h is provided by the Utah Raster Toolkit. */ >- >-#include <rle.h> >- >-/* >- * We assume that JSAMPLE has the same representation as rle_pixel, >- * to wit, "unsigned char". Hence we can't cope with 12- or 16-bit samples. >- */ >- >-#if BITS_IN_JSAMPLE != 8 >- Sorry, this code only copes with 8-bit JSAMPLEs. /* deliberate syntax err */ >-#endif >- >-/* >- * We support the following types of RLE files: >- * >- * GRAYSCALE - 8 bits, no colormap >- * MAPPEDGRAY - 8 bits, 1 channel colomap >- * PSEUDOCOLOR - 8 bits, 3 channel colormap >- * TRUECOLOR - 24 bits, 3 channel colormap >- * DIRECTCOLOR - 24 bits, no colormap >- * >- * For now, we ignore any alpha channel in the image. >- */ >- >-typedef enum >- { GRAYSCALE, MAPPEDGRAY, PSEUDOCOLOR, TRUECOLOR, DIRECTCOLOR } rle_kind; >- >- >-/* >- * Since RLE stores scanlines bottom-to-top, we have to invert the image >- * to conform to JPEG's top-to-bottom order. To do this, we read the >- * incoming image into a virtual array on the first get_pixel_rows call, >- * then fetch the required row from the virtual array on subsequent calls. >- */ >- >-typedef struct _rle_source_struct * rle_source_ptr; >- >-typedef struct _rle_source_struct { >- struct cjpeg_source_struct pub; /* public fields */ >- >- rle_kind visual; /* actual type of input file */ >- jvirt_sarray_ptr image; /* virtual array to hold the image */ >- JDIMENSION row; /* current row # in the virtual array */ >- rle_hdr header; /* Input file information */ >- rle_pixel** rle_row; /* holds a row returned by rle_getrow() */ >- >-} rle_source_struct; >- >- >-/* >- * Read the file header; return image size and component count. >- */ >- >-METHODDEF(void) >-start_input_rle (j_compress_ptr cinfo, cjpeg_source_ptr sinfo) >-{ >- rle_source_ptr source = (rle_source_ptr) sinfo; >- JDIMENSION width, height; >-#ifdef PROGRESS_REPORT >- cd_progress_ptr progress = (cd_progress_ptr) cinfo->progress; >-#endif >- >- /* Use RLE library routine to get the header info */ >- source->header = *rle_hdr_init(NULL); >- source->header.rle_file = source->pub.input_file; >- switch (rle_get_setup(&(source->header))) { >- case RLE_SUCCESS: >- /* A-OK */ >- break; >- case RLE_NOT_RLE: >- ERREXIT(cinfo, JERR_RLE_NOT); >- break; >- case RLE_NO_SPACE: >- ERREXIT(cinfo, JERR_RLE_MEM); >- break; >- case RLE_EMPTY: >- ERREXIT(cinfo, JERR_RLE_EMPTY); >- break; >- case RLE_EOF: >- ERREXIT(cinfo, JERR_RLE_EOF); >- break; >- default: >- ERREXIT(cinfo, JERR_RLE_BADERROR); >- break; >- } >- >- /* Figure out what we have, set private vars and return values accordingly */ >- >- width = source->header.xmax - source->header.xmin + 1; >- height = source->header.ymax - source->header.ymin + 1; >- source->header.xmin = 0; /* realign horizontally */ >- source->header.xmax = width-1; >- >- cinfo->image_width = width; >- cinfo->image_height = height; >- cinfo->data_precision = 8; /* we can only handle 8 bit data */ >- >- if (source->header.ncolors == 1 && source->header.ncmap == 0) { >- source->visual = GRAYSCALE; >- TRACEMS2(cinfo, 1, JTRC_RLE_GRAY, width, height); >- } else if (source->header.ncolors == 1 && source->header.ncmap == 1) { >- source->visual = MAPPEDGRAY; >- TRACEMS3(cinfo, 1, JTRC_RLE_MAPGRAY, width, height, >- 1 << source->header.cmaplen); >- } else if (source->header.ncolors == 1 && source->header.ncmap == 3) { >- source->visual = PSEUDOCOLOR; >- TRACEMS3(cinfo, 1, JTRC_RLE_MAPPED, width, height, >- 1 << source->header.cmaplen); >- } else if (source->header.ncolors == 3 && source->header.ncmap == 3) { >- source->visual = TRUECOLOR; >- TRACEMS3(cinfo, 1, JTRC_RLE_FULLMAP, width, height, >- 1 << source->header.cmaplen); >- } else if (source->header.ncolors == 3 && source->header.ncmap == 0) { >- source->visual = DIRECTCOLOR; >- TRACEMS2(cinfo, 1, JTRC_RLE, width, height); >- } else >- ERREXIT(cinfo, JERR_RLE_UNSUPPORTED); >- >- if (source->visual == GRAYSCALE || source->visual == MAPPEDGRAY) { >- cinfo->in_color_space = JCS_GRAYSCALE; >- cinfo->input_components = 1; >- } else { >- cinfo->in_color_space = JCS_RGB; >- cinfo->input_components = 3; >- } >- >- /* >- * A place to hold each scanline while it's converted. >- * (GRAYSCALE scanlines don't need converting) >- */ >- if (source->visual != GRAYSCALE) { >- source->rle_row = (rle_pixel**) (*cinfo->mem->alloc_sarray) >- ((j_common_ptr) cinfo, JPOOL_IMAGE, >- (JDIMENSION) width, (JDIMENSION) cinfo->input_components); >- } >- >- /* request a virtual array to hold the image */ >- source->image = (*cinfo->mem->request_virt_sarray) >- ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE, >- (JDIMENSION) (width * source->header.ncolors), >- (JDIMENSION) height, (JDIMENSION) 1); >- >-#ifdef PROGRESS_REPORT >- if (progress != NULL) { >- /* count file input as separate pass */ >- progress->total_extra_passes++; >- } >-#endif >- >- source->pub.buffer_height = 1; >-} >- >- >-/* >- * Read one row of pixels. >- * Called only after load_image has read the image into the virtual array. >- * Used for GRAYSCALE, MAPPEDGRAY, TRUECOLOR, and DIRECTCOLOR images. >- */ >- >-METHODDEF(JDIMENSION) >-get_rle_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo) >-{ >- rle_source_ptr source = (rle_source_ptr) sinfo; >- >- source->row--; >- source->pub.buffer = (*cinfo->mem->access_virt_sarray) >- ((j_common_ptr) cinfo, source->image, source->row, (JDIMENSION) 1, FALSE); >- >- return 1; >-} >- >-/* >- * Read one row of pixels. >- * Called only after load_image has read the image into the virtual array. >- * Used for PSEUDOCOLOR images. >- */ >- >-METHODDEF(JDIMENSION) >-get_pseudocolor_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo) >-{ >- rle_source_ptr source = (rle_source_ptr) sinfo; >- JSAMPROW src_row, dest_row; >- JDIMENSION col; >- rle_map *colormap; >- int val; >- >- colormap = source->header.cmap; >- dest_row = source->pub.buffer[0]; >- source->row--; >- src_row = * (*cinfo->mem->access_virt_sarray) >- ((j_common_ptr) cinfo, source->image, source->row, (JDIMENSION) 1, FALSE); >- >- for (col = cinfo->image_width; col > 0; col--) { >- val = GETJSAMPLE(*src_row++); >- *dest_row++ = (JSAMPLE) (colormap[val ] >> 8); >- *dest_row++ = (JSAMPLE) (colormap[val + 256] >> 8); >- *dest_row++ = (JSAMPLE) (colormap[val + 512] >> 8); >- } >- >- return 1; >-} >- >- >-/* >- * Load the image into a virtual array. We have to do this because RLE >- * files start at the lower left while the JPEG standard has them starting >- * in the upper left. This is called the first time we want to get a row >- * of input. What we do is load the RLE data into the array and then call >- * the appropriate routine to read one row from the array. Before returning, >- * we set source->pub.get_pixel_rows so that subsequent calls go straight to >- * the appropriate row-reading routine. >- */ >- >-METHODDEF(JDIMENSION) >-load_image (j_compress_ptr cinfo, cjpeg_source_ptr sinfo) >-{ >- rle_source_ptr source = (rle_source_ptr) sinfo; >- JDIMENSION row, col; >- JSAMPROW scanline, red_ptr, green_ptr, blue_ptr; >- rle_pixel **rle_row; >- rle_map *colormap; >- char channel; >-#ifdef PROGRESS_REPORT >- cd_progress_ptr progress = (cd_progress_ptr) cinfo->progress; >-#endif >- >- colormap = source->header.cmap; >- rle_row = source->rle_row; >- >- /* Read the RLE data into our virtual array. >- * We assume here that (a) rle_pixel is represented the same as JSAMPLE, >- * and (b) we are not on a machine where FAR pointers differ from regular. >- */ >- RLE_CLR_BIT(source->header, RLE_ALPHA); /* don't read the alpha channel */ >- >-#ifdef PROGRESS_REPORT >- if (progress != NULL) { >- progress->pub.pass_limit = cinfo->image_height; >- progress->pub.pass_counter = 0; >- (*progress->pub.progress_monitor) ((j_common_ptr) cinfo); >- } >-#endif >- >- switch (source->visual) { >- >- case GRAYSCALE: >- case PSEUDOCOLOR: >- for (row = 0; row < cinfo->image_height; row++) { >- rle_row = (rle_pixel **) (*cinfo->mem->access_virt_sarray) >- ((j_common_ptr) cinfo, source->image, row, (JDIMENSION) 1, TRUE); >- rle_getrow(&source->header, rle_row); >-#ifdef PROGRESS_REPORT >- if (progress != NULL) { >- progress->pub.pass_counter++; >- (*progress->pub.progress_monitor) ((j_common_ptr) cinfo); >- } >-#endif >- } >- break; >- >- case MAPPEDGRAY: >- case TRUECOLOR: >- for (row = 0; row < cinfo->image_height; row++) { >- scanline = * (*cinfo->mem->access_virt_sarray) >- ((j_common_ptr) cinfo, source->image, row, (JDIMENSION) 1, TRUE); >- rle_row = source->rle_row; >- rle_getrow(&source->header, rle_row); >- >- for (col = 0; col < cinfo->image_width; col++) { >- for (channel = 0; channel < source->header.ncolors; channel++) { >- *scanline++ = (JSAMPLE) >- (colormap[GETJSAMPLE(rle_row[channel][col]) + 256 * channel] >> 8); >- } >- } >- >-#ifdef PROGRESS_REPORT >- if (progress != NULL) { >- progress->pub.pass_counter++; >- (*progress->pub.progress_monitor) ((j_common_ptr) cinfo); >- } >-#endif >- } >- break; >- >- case DIRECTCOLOR: >- for (row = 0; row < cinfo->image_height; row++) { >- scanline = * (*cinfo->mem->access_virt_sarray) >- ((j_common_ptr) cinfo, source->image, row, (JDIMENSION) 1, TRUE); >- rle_getrow(&source->header, rle_row); >- >- red_ptr = rle_row[0]; >- green_ptr = rle_row[1]; >- blue_ptr = rle_row[2]; >- >- for (col = cinfo->image_width; col > 0; col--) { >- *scanline++ = *red_ptr++; >- *scanline++ = *green_ptr++; >- *scanline++ = *blue_ptr++; >- } >- >-#ifdef PROGRESS_REPORT >- if (progress != NULL) { >- progress->pub.pass_counter++; >- (*progress->pub.progress_monitor) ((j_common_ptr) cinfo); >- } >-#endif >- } >- } >- >-#ifdef PROGRESS_REPORT >- if (progress != NULL) >- progress->completed_extra_passes++; >-#endif >- >- /* Set up to call proper row-extraction routine in future */ >- if (source->visual == PSEUDOCOLOR) { >- source->pub.buffer = source->rle_row; >- source->pub.get_pixel_rows = get_pseudocolor_row; >- } else { >- source->pub.get_pixel_rows = get_rle_row; >- } >- source->row = cinfo->image_height; >- >- /* And fetch the topmost (bottommost) row */ >- return (*source->pub.get_pixel_rows) (cinfo, sinfo); >-} >- >- >-/* >- * Finish up at the end of the file. >- */ >- >-METHODDEF(void) >-finish_input_rle (j_compress_ptr cinfo, cjpeg_source_ptr sinfo) >-{ >- /* no work */ >-} >- >- >-/* >- * The module selection routine for RLE format input. >- */ >- >-GLOBAL(cjpeg_source_ptr) >-jinit_read_rle (j_compress_ptr cinfo) >-{ >- rle_source_ptr source; >- >- /* Create module interface object */ >- source = (rle_source_ptr) >- (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, >- SIZEOF(rle_source_struct)); >- /* Fill in method ptrs */ >- source->pub.start_input = start_input_rle; >- source->pub.finish_input = finish_input_rle; >- source->pub.get_pixel_rows = load_image; >- >- return (cjpeg_source_ptr) source; >-} >- >-#endif /* RLE_SUPPORTED */ >--- b/jpeg/rdswitch.c >+++ /dev/null >@@ -1,332 +0,0 @@ >-/* >- * rdswitch.c >- * >- * Copyright (C) 1991-1996, Thomas G. Lane. >- * This file is part of the Independent JPEG Group's software. >- * For conditions of distribution and use, see the accompanying README file. >- * >- * This file contains routines to process some of cjpeg's more complicated >- * command-line switches. Switches processed here are: >- * -qtables file Read quantization tables from text file >- * -scans file Read scan script from text file >- * -qslots N[,N,...] Set component quantization table selectors >- * -sample HxV[,HxV,...] Set component sampling factors >- */ >- >-#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */ >-#include <ctype.h> /* to declare isdigit(), isspace() */ >- >- >-LOCAL(int) >-text_getc (FILE * file) >-/* Read next char, skipping over any comments (# to end of line) */ >-/* A comment/newline sequence is returned as a newline */ >-{ >- register int ch; >- >- ch = getc(file); >- if (ch == '#') { >- do { >- ch = getc(file); >- } while (ch != '\n' && ch != EOF); >- } >- return ch; >-} >- >- >-LOCAL(boolean) >-read_text_integer (FILE * file, long * result, int * termchar) >-/* Read an unsigned decimal integer from a file, store it in result */ >-/* Reads one trailing character after the integer; returns it in termchar */ >-{ >- register int ch; >- register long val; >- >- /* Skip any leading whitespace, detect EOF */ >- do { >- ch = text_getc(file); >- if (ch == EOF) { >- *termchar = ch; >- return FALSE; >- } >- } while (isspace(ch)); >- >- if (! isdigit(ch)) { >- *termchar = ch; >- return FALSE; >- } >- >- val = ch - '0'; >- while ((ch = text_getc(file)) != EOF) { >- if (! isdigit(ch)) >- break; >- val *= 10; >- val += ch - '0'; >- } >- *result = val; >- *termchar = ch; >- return TRUE; >-} >- >- >-GLOBAL(boolean) >-read_quant_tables (j_compress_ptr cinfo, char * filename, >- int scale_factor, boolean force_baseline) >-/* Read a set of quantization tables from the specified file. >- * The file is plain ASCII text: decimal numbers with whitespace between. >- * Comments preceded by '#' may be included in the file. >- * There may be one to NUM_QUANT_TBLS tables in the file, each of 64 values. >- * The tables are implicitly numbered 0,1,etc. >- * NOTE: does not affect the qslots mapping, which will default to selecting >- * table 0 for luminance (or primary) components, 1 for chrominance components. >- * You must use -qslots if you want a different component->table mapping. >- */ >-{ >- FILE * fp; >- int tblno, i, termchar; >- long val; >- unsigned int table[DCTSIZE2]; >- >- if ((fp = fopen(filename, "r")) == NULL) { >- fprintf(stderr, "Can't open table file %s\n", filename); >- return FALSE; >- } >- tblno = 0; >- >- while (read_text_integer(fp, &val, &termchar)) { /* read 1st element of table */ >- if (tblno >= NUM_QUANT_TBLS) { >- fprintf(stderr, "Too many tables in file %s\n", filename); >- fclose(fp); >- return FALSE; >- } >- table[0] = (unsigned int) val; >- for (i = 1; i < DCTSIZE2; i++) { >- if (! read_text_integer(fp, &val, &termchar)) { >- fprintf(stderr, "Invalid table data in file %s\n", filename); >- fclose(fp); >- return FALSE; >- } >- table[i] = (unsigned int) val; >- } >- jpeg_add_quant_table(cinfo, tblno, table, scale_factor, force_baseline); >- tblno++; >- } >- >- if (termchar != EOF) { >- fprintf(stderr, "Non-numeric data in file %s\n", filename); >- fclose(fp); >- return FALSE; >- } >- >- fclose(fp); >- return TRUE; >-} >- >- >-#ifdef C_MULTISCAN_FILES_SUPPORTED >- >-LOCAL(boolean) >-read_scan_integer (FILE * file, long * result, int * termchar) >-/* Variant of read_text_integer that always looks for a non-space termchar; >- * this simplifies parsing of punctuation in scan scripts. >- */ >-{ >- register int ch; >- >- if (! read_text_integer(file, result, termchar)) >- return FALSE; >- ch = *termchar; >- while (ch != EOF && isspace(ch)) >- ch = text_getc(file); >- if (isdigit(ch)) { /* oops, put it back */ >- if (ungetc(ch, file) == EOF) >- return FALSE; >- ch = ' '; >- } else { >- /* Any separators other than ';' and ':' are ignored; >- * this allows user to insert commas, etc, if desired. >- */ >- if (ch != EOF && ch != ';' && ch != ':') >- ch = ' '; >- } >- *termchar = ch; >- return TRUE; >-} >- >- >-GLOBAL(boolean) >-read_scan_script (j_compress_ptr cinfo, char * filename) >-/* Read a scan script from the specified text file. >- * Each entry in the file defines one scan to be emitted. >- * Entries are separated by semicolons ';'. >- * An entry contains one to four component indexes, >- * optionally followed by a colon ':' and four progressive-JPEG parameters. >- * The component indexes denote which component(s) are to be transmitted >- * in the current scan. The first component has index 0. >- * Sequential JPEG is used if the progressive-JPEG parameters are omitted. >- * The file is free format text: any whitespace may appear between numbers >- * and the ':' and ';' punctuation marks. Also, other punctuation (such >- * as commas or dashes) can be placed between numbers if desired. >- * Comments preceded by '#' may be included in the file. >- * Note: we do very little validity checking here; >- * jcmaster.c will validate the script parameters. >- */ >-{ >- FILE * fp; >- int scanno, ncomps, termchar; >- long val; >- jpeg_scan_info * scanptr; >-#define MAX_SCANS 100 /* quite arbitrary limit */ >- jpeg_scan_info scans[MAX_SCANS]; >- >- if ((fp = fopen(filename, "r")) == NULL) { >- fprintf(stderr, "Can't open scan definition file %s\n", filename); >- return FALSE; >- } >- scanptr = scans; >- scanno = 0; >- >- while (read_scan_integer(fp, &val, &termchar)) { >- if (scanno >= MAX_SCANS) { >- fprintf(stderr, "Too many scans defined in file %s\n", filename); >- fclose(fp); >- return FALSE; >- } >- scanptr->component_index[0] = (int) val; >- ncomps = 1; >- while (termchar == ' ') { >- if (ncomps >= MAX_COMPS_IN_SCAN) { >- fprintf(stderr, "Too many components in one scan in file %s\n", >- filename); >- fclose(fp); >- return FALSE; >- } >- if (! read_scan_integer(fp, &val, &termchar)) >- goto bogus; >- scanptr->component_index[ncomps] = (int) val; >- ncomps++; >- } >- scanptr->comps_in_scan = ncomps; >- if (termchar == ':') { >- if (! read_scan_integer(fp, &val, &termchar) || termchar != ' ') >- goto bogus; >- scanptr->Ss = (int) val; >- if (! read_scan_integer(fp, &val, &termchar) || termchar != ' ') >- goto bogus; >- scanptr->Se = (int) val; >- if (! read_scan_integer(fp, &val, &termchar) || termchar != ' ') >- goto bogus; >- scanptr->Ah = (int) val; >- if (! read_scan_integer(fp, &val, &termchar)) >- goto bogus; >- scanptr->Al = (int) val; >- } else { >- /* set non-progressive parameters */ >- scanptr->Ss = 0; >- scanptr->Se = DCTSIZE2-1; >- scanptr->Ah = 0; >- scanptr->Al = 0; >- } >- if (termchar != ';' && termchar != EOF) { >-bogus: >- fprintf(stderr, "Invalid scan entry format in file %s\n", filename); >- fclose(fp); >- return FALSE; >- } >- scanptr++, scanno++; >- } >- >- if (termchar != EOF) { >- fprintf(stderr, "Non-numeric data in file %s\n", filename); >- fclose(fp); >- return FALSE; >- } >- >- if (scanno > 0) { >- /* Stash completed scan list in cinfo structure. >- * NOTE: for cjpeg's use, JPOOL_IMAGE is the right lifetime for this data, >- * but if you want to compress multiple images you'd want JPOOL_PERMANENT. >- */ >- scanptr = (jpeg_scan_info *) >- (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, >- scanno * SIZEOF(jpeg_scan_info)); >- MEMCOPY(scanptr, scans, scanno * SIZEOF(jpeg_scan_info)); >- cinfo->scan_info = scanptr; >- cinfo->num_scans = scanno; >- } >- >- fclose(fp); >- return TRUE; >-} >- >-#endif /* C_MULTISCAN_FILES_SUPPORTED */ >- >- >-GLOBAL(boolean) >-set_quant_slots (j_compress_ptr cinfo, char *arg) >-/* Process a quantization-table-selectors parameter string, of the form >- * N[,N,...] >- * If there are more components than parameters, the last value is replicated. >- */ >-{ >- int val = 0; /* default table # */ >- int ci; >- char ch; >- >- for (ci = 0; ci < MAX_COMPONENTS; ci++) { >- if (*arg) { >- ch = ','; /* if not set by sscanf, will be ',' */ >- if (sscanf(arg, "%d%c", &val, &ch) < 1) >- return FALSE; >- if (ch != ',') /* syntax check */ >- return FALSE; >- if (val < 0 || val >= NUM_QUANT_TBLS) { >- fprintf(stderr, "JPEG quantization tables are numbered 0..%d\n", >- NUM_QUANT_TBLS-1); >- return FALSE; >- } >- cinfo->comp_info[ci].quant_tbl_no = val; >- while (*arg && *arg++ != ',') /* advance to next segment of arg string */ >- ; >- } else { >- /* reached end of parameter, set remaining components to last table */ >- cinfo->comp_info[ci].quant_tbl_no = val; >- } >- } >- return TRUE; >-} >- >- >-GLOBAL(boolean) >-set_sample_factors (j_compress_ptr cinfo, char *arg) >-/* Process a sample-factors parameter string, of the form >- * HxV[,HxV,...] >- * If there are more components than parameters, "1x1" is assumed for the rest. >- */ >-{ >- int ci, val1, val2; >- char ch1, ch2; >- >- for (ci = 0; ci < MAX_COMPONENTS; ci++) { >- if (*arg) { >- ch2 = ','; /* if not set by sscanf, will be ',' */ >- if (sscanf(arg, "%d%c%d%c", &val1, &ch1, &val2, &ch2) < 3) >- return FALSE; >- if ((ch1 != 'x' && ch1 != 'X') || ch2 != ',') /* syntax check */ >- return FALSE; >- if (val1 <= 0 || val1 > 4 || val2 <= 0 || val2 > 4) { >- fprintf(stderr, "JPEG sampling factors must be 1..4\n"); >- return FALSE; >- } >- cinfo->comp_info[ci].h_samp_factor = val1; >- cinfo->comp_info[ci].v_samp_factor = val2; >- while (*arg && *arg++ != ',') /* advance to next segment of arg string */ >- ; >- } else { >- /* reached end of parameter, set remaining components to 1x1 sampling */ >- cinfo->comp_info[ci].h_samp_factor = 1; >- cinfo->comp_info[ci].v_samp_factor = 1; >- } >- } >- return TRUE; >-} >--- b/jpeg/rdtarga.c >+++ /dev/null >@@ -1,500 +0,0 @@ >-/* >- * rdtarga.c >- * >- * Copyright (C) 1991-1996, Thomas G. Lane. >- * This file is part of the Independent JPEG Group's software. >- * For conditions of distribution and use, see the accompanying README file. >- * >- * This file contains routines to read input images in Targa format. >- * >- * These routines may need modification for non-Unix environments or >- * specialized applications. As they stand, they assume input from >- * an ordinary stdio stream. They further assume that reading begins >- * at the start of the file; start_input may need work if the >- * user interface has already read some data (e.g., to determine that >- * the file is indeed Targa format). >- * >- * Based on code contributed by Lee Daniel Crocker. >- */ >- >-#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */ >- >-#ifdef TARGA_SUPPORTED >- >- >-/* Macros to deal with unsigned chars as efficiently as compiler allows */ >- >-#ifdef HAVE_UNSIGNED_CHAR >-typedef unsigned char U_CHAR; >-#define UCH(x) ((int) (x)) >-#else /* !HAVE_UNSIGNED_CHAR */ >-#ifdef CHAR_IS_UNSIGNED >-typedef char U_CHAR; >-#define UCH(x) ((int) (x)) >-#else >-typedef char U_CHAR; >-#define UCH(x) ((int) (x) & 0xFF) >-#endif >-#endif /* HAVE_UNSIGNED_CHAR */ >- >- >-#define ReadOK(file,buffer,len) (JFREAD(file,buffer,len) == ((size_t) (len))) >- >- >-/* Private version of data source object */ >- >-typedef struct _tga_source_struct * tga_source_ptr; >- >-typedef struct _tga_source_struct { >- struct cjpeg_source_struct pub; /* public fields */ >- >- j_compress_ptr cinfo; /* back link saves passing separate parm */ >- >- JSAMPARRAY colormap; /* Targa colormap (converted to my format) */ >- >- jvirt_sarray_ptr whole_image; /* Needed if funny input row order */ >- JDIMENSION current_row; /* Current logical row number to read */ >- >- /* Pointer to routine to extract next Targa pixel from input file */ >- JMETHOD(void, read_pixel, (tga_source_ptr sinfo)); >- >- /* Result of read_pixel is delivered here: */ >- U_CHAR tga_pixel[4]; >- >- int pixel_size; /* Bytes per Targa pixel (1 to 4) */ >- >- /* State info for reading RLE-coded pixels; both counts must be init to 0 */ >- int block_count; /* # of pixels remaining in RLE block */ >- int dup_pixel_count; /* # of times to duplicate previous pixel */ >- >- /* This saves the correct pixel-row-expansion method for preload_image */ >- JMETHOD(JDIMENSION, get_pixel_rows, (j_compress_ptr cinfo, >- cjpeg_source_ptr sinfo)); >-} tga_source_struct; >- >- >-/* For expanding 5-bit pixel values to 8-bit with best rounding */ >- >-static const UINT8 c5to8bits[32] = { >- 0, 8, 16, 25, 33, 41, 49, 58, >- 66, 74, 82, 90, 99, 107, 115, 123, >- 132, 140, 148, 156, 165, 173, 181, 189, >- 197, 206, 214, 222, 230, 239, 247, 255 >-}; >- >- >- >-LOCAL(int) >-read_byte (tga_source_ptr sinfo) >-/* Read next byte from Targa file */ >-{ >- register FILE *infile = sinfo->pub.input_file; >- register int c; >- >- if ((c = getc(infile)) == EOF) >- ERREXIT(sinfo->cinfo, JERR_INPUT_EOF); >- return c; >-} >- >- >-LOCAL(void) >-read_colormap (tga_source_ptr sinfo, int cmaplen, int mapentrysize) >-/* Read the colormap from a Targa file */ >-{ >- int i; >- >- /* Presently only handles 24-bit BGR format */ >- if (mapentrysize != 24) >- ERREXIT(sinfo->cinfo, JERR_TGA_BADCMAP); >- >- for (i = 0; i < cmaplen; i++) { >- sinfo->colormap[2][i] = (JSAMPLE) read_byte(sinfo); >- sinfo->colormap[1][i] = (JSAMPLE) read_byte(sinfo); >- sinfo->colormap[0][i] = (JSAMPLE) read_byte(sinfo); >- } >-} >- >- >-/* >- * read_pixel methods: get a single pixel from Targa file into tga_pixel[] >- */ >- >-METHODDEF(void) >-read_non_rle_pixel (tga_source_ptr sinfo) >-/* Read one Targa pixel from the input file; no RLE expansion */ >-{ >- register FILE *infile = sinfo->pub.input_file; >- register int i; >- >- for (i = 0; i < sinfo->pixel_size; i++) { >- sinfo->tga_pixel[i] = (U_CHAR) getc(infile); >- } >-} >- >- >-METHODDEF(void) >-read_rle_pixel (tga_source_ptr sinfo) >-/* Read one Targa pixel from the input file, expanding RLE data as needed */ >-{ >- register FILE *infile = sinfo->pub.input_file; >- register int i; >- >- /* Duplicate previously read pixel? */ >- if (sinfo->dup_pixel_count > 0) { >- sinfo->dup_pixel_count--; >- return; >- } >- >- /* Time to read RLE block header? */ >- if (--sinfo->block_count < 0) { /* decrement pixels remaining in block */ >- i = read_byte(sinfo); >- if (i & 0x80) { /* Start of duplicate-pixel block? */ >- sinfo->dup_pixel_count = i & 0x7F; /* number of dups after this one */ >- sinfo->block_count = 0; /* then read new block header */ >- } else { >- sinfo->block_count = i & 0x7F; /* number of pixels after this one */ >- } >- } >- >- /* Read next pixel */ >- for (i = 0; i < sinfo->pixel_size; i++) { >- sinfo->tga_pixel[i] = (U_CHAR) getc(infile); >- } >-} >- >- >-/* >- * Read one row of pixels. >- * >- * We provide several different versions depending on input file format. >- */ >- >- >-METHODDEF(JDIMENSION) >-get_8bit_gray_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo) >-/* This version is for reading 8-bit grayscale pixels */ >-{ >- tga_source_ptr source = (tga_source_ptr) sinfo; >- register JSAMPROW ptr; >- register JDIMENSION col; >- >- ptr = source->pub.buffer[0]; >- for (col = cinfo->image_width; col > 0; col--) { >- (*source->read_pixel) (source); /* Load next pixel into tga_pixel */ >- *ptr++ = (JSAMPLE) UCH(source->tga_pixel[0]); >- } >- return 1; >-} >- >-METHODDEF(JDIMENSION) >-get_8bit_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo) >-/* This version is for reading 8-bit colormap indexes */ >-{ >- tga_source_ptr source = (tga_source_ptr) sinfo; >- register int t; >- register JSAMPROW ptr; >- register JDIMENSION col; >- register JSAMPARRAY colormap = source->colormap; >- >- ptr = source->pub.buffer[0]; >- for (col = cinfo->image_width; col > 0; col--) { >- (*source->read_pixel) (source); /* Load next pixel into tga_pixel */ >- t = UCH(source->tga_pixel[0]); >- *ptr++ = colormap[0][t]; >- *ptr++ = colormap[1][t]; >- *ptr++ = colormap[2][t]; >- } >- return 1; >-} >- >-METHODDEF(JDIMENSION) >-get_16bit_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo) >-/* This version is for reading 16-bit pixels */ >-{ >- tga_source_ptr source = (tga_source_ptr) sinfo; >- register int t; >- register JSAMPROW ptr; >- register JDIMENSION col; >- >- ptr = source->pub.buffer[0]; >- for (col = cinfo->image_width; col > 0; col--) { >- (*source->read_pixel) (source); /* Load next pixel into tga_pixel */ >- t = UCH(source->tga_pixel[0]); >- t += UCH(source->tga_pixel[1]) << 8; >- /* We expand 5 bit data to 8 bit sample width. >- * The format of the 16-bit (LSB first) input word is >- * xRRRRRGGGGGBBBBB >- */ >- ptr[2] = (JSAMPLE) c5to8bits[t & 0x1F]; >- t >>= 5; >- ptr[1] = (JSAMPLE) c5to8bits[t & 0x1F]; >- t >>= 5; >- ptr[0] = (JSAMPLE) c5to8bits[t & 0x1F]; >- ptr += 3; >- } >- return 1; >-} >- >-METHODDEF(JDIMENSION) >-get_24bit_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo) >-/* This version is for reading 24-bit pixels */ >-{ >- tga_source_ptr source = (tga_source_ptr) sinfo; >- register JSAMPROW ptr; >- register JDIMENSION col; >- >- ptr = source->pub.buffer[0]; >- for (col = cinfo->image_width; col > 0; col--) { >- (*source->read_pixel) (source); /* Load next pixel into tga_pixel */ >- *ptr++ = (JSAMPLE) UCH(source->tga_pixel[2]); /* change BGR to RGB order */ >- *ptr++ = (JSAMPLE) UCH(source->tga_pixel[1]); >- *ptr++ = (JSAMPLE) UCH(source->tga_pixel[0]); >- } >- return 1; >-} >- >-/* >- * Targa also defines a 32-bit pixel format with order B,G,R,A. >- * We presently ignore the attribute byte, so the code for reading >- * these pixels is identical to the 24-bit routine above. >- * This works because the actual pixel length is only known to read_pixel. >- */ >- >-#define get_32bit_row get_24bit_row >- >- >-/* >- * This method is for re-reading the input data in standard top-down >- * row order. The entire image has already been read into whole_image >- * with proper conversion of pixel format, but it's in a funny row order. >- */ >- >-METHODDEF(JDIMENSION) >-get_memory_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo) >-{ >- tga_source_ptr source = (tga_source_ptr) sinfo; >- JDIMENSION source_row; >- >- /* Compute row of source that maps to current_row of normal order */ >- /* For now, assume image is bottom-up and not interlaced. */ >- /* NEEDS WORK to support interlaced images! */ >- source_row = cinfo->image_height - source->current_row - 1; >- >- /* Fetch that row from virtual array */ >- source->pub.buffer = (*cinfo->mem->access_virt_sarray) >- ((j_common_ptr) cinfo, source->whole_image, >- source_row, (JDIMENSION) 1, FALSE); >- >- source->current_row++; >- return 1; >-} >- >- >-/* >- * This method loads the image into whole_image during the first call on >- * get_pixel_rows. The get_pixel_rows pointer is then adjusted to call >- * get_memory_row on subsequent calls. >- */ >- >-METHODDEF(JDIMENSION) >-preload_image (j_compress_ptr cinfo, cjpeg_source_ptr sinfo) >-{ >- tga_source_ptr source = (tga_source_ptr) sinfo; >- JDIMENSION row; >- cd_progress_ptr progress = (cd_progress_ptr) cinfo->progress; >- >- /* Read the data into a virtual array in input-file row order. */ >- for (row = 0; row < cinfo->image_height; row++) { >- if (progress != NULL) { >- progress->pub.pass_counter = (long) row; >- progress->pub.pass_limit = (long) cinfo->image_height; >- (*progress->pub.progress_monitor) ((j_common_ptr) cinfo); >- } >- source->pub.buffer = (*cinfo->mem->access_virt_sarray) >- ((j_common_ptr) cinfo, source->whole_image, row, (JDIMENSION) 1, TRUE); >- (*source->get_pixel_rows) (cinfo, sinfo); >- } >- if (progress != NULL) >- progress->completed_extra_passes++; >- >- /* Set up to read from the virtual array in unscrambled order */ >- source->pub.get_pixel_rows = get_memory_row; >- source->current_row = 0; >- /* And read the first row */ >- return get_memory_row(cinfo, sinfo); >-} >- >- >-/* >- * Read the file header; return image size and component count. >- */ >- >-METHODDEF(void) >-start_input_tga (j_compress_ptr cinfo, cjpeg_source_ptr sinfo) >-{ >- tga_source_ptr source = (tga_source_ptr) sinfo; >- U_CHAR targaheader[18]; >- int idlen, cmaptype, subtype, flags, interlace_type, components; >- unsigned int width, height, maplen; >- boolean is_bottom_up; >- >-#define GET_2B(offset) ((unsigned int) UCH(targaheader[offset]) + \ >- (((unsigned int) UCH(targaheader[offset+1])) << 8)) >- >- if (! ReadOK(source->pub.input_file, targaheader, 18)) >- ERREXIT(cinfo, JERR_INPUT_EOF); >- >- /* Pretend "15-bit" pixels are 16-bit --- we ignore attribute bit anyway */ >- if (targaheader[16] == 15) >- targaheader[16] = 16; >- >- idlen = UCH(targaheader[0]); >- cmaptype = UCH(targaheader[1]); >- subtype = UCH(targaheader[2]); >- maplen = GET_2B(5); >- width = GET_2B(12); >- height = GET_2B(14); >- source->pixel_size = UCH(targaheader[16]) >> 3; >- flags = UCH(targaheader[17]); /* Image Descriptor byte */ >- >- is_bottom_up = ((flags & 0x20) == 0); /* bit 5 set => top-down */ >- interlace_type = flags >> 6; /* bits 6/7 are interlace code */ >- >- if (cmaptype > 1 || /* cmaptype must be 0 or 1 */ >- source->pixel_size < 1 || source->pixel_size > 4 || >- (UCH(targaheader[16]) & 7) != 0 || /* bits/pixel must be multiple of 8 */ >- interlace_type != 0) /* currently don't allow interlaced image */ >- ERREXIT(cinfo, JERR_TGA_BADPARMS); >- >- if (subtype > 8) { >- /* It's an RLE-coded file */ >- source->read_pixel = read_rle_pixel; >- source->block_count = source->dup_pixel_count = 0; >- subtype -= 8; >- } else { >- /* Non-RLE file */ >- source->read_pixel = read_non_rle_pixel; >- } >- >- /* Now should have subtype 1, 2, or 3 */ >- components = 3; /* until proven different */ >- cinfo->in_color_space = JCS_RGB; >- >- switch (subtype) { >- case 1: /* Colormapped image */ >- if (source->pixel_size == 1 && cmaptype == 1) >- source->get_pixel_rows = get_8bit_row; >- else >- ERREXIT(cinfo, JERR_TGA_BADPARMS); >- TRACEMS2(cinfo, 1, JTRC_TGA_MAPPED, width, height); >- break; >- case 2: /* RGB image */ >- switch (source->pixel_size) { >- case 2: >- source->get_pixel_rows = get_16bit_row; >- break; >- case 3: >- source->get_pixel_rows = get_24bit_row; >- break; >- case 4: >- source->get_pixel_rows = get_32bit_row; >- break; >- default: >- ERREXIT(cinfo, JERR_TGA_BADPARMS); >- break; >- } >- TRACEMS2(cinfo, 1, JTRC_TGA, width, height); >- break; >- case 3: /* Grayscale image */ >- components = 1; >- cinfo->in_color_space = JCS_GRAYSCALE; >- if (source->pixel_size == 1) >- source->get_pixel_rows = get_8bit_gray_row; >- else >- ERREXIT(cinfo, JERR_TGA_BADPARMS); >- TRACEMS2(cinfo, 1, JTRC_TGA_GRAY, width, height); >- break; >- default: >- ERREXIT(cinfo, JERR_TGA_BADPARMS); >- break; >- } >- >- if (is_bottom_up) { >- /* Create a virtual array to buffer the upside-down image. */ >- source->whole_image = (*cinfo->mem->request_virt_sarray) >- ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE, >- (JDIMENSION) width * components, (JDIMENSION) height, (JDIMENSION) 1); >- if (cinfo->progress != NULL) { >- cd_progress_ptr progress = (cd_progress_ptr) cinfo->progress; >- progress->total_extra_passes++; /* count file input as separate pass */ >- } >- /* source->pub.buffer will point to the virtual array. */ >- source->pub.buffer_height = 1; /* in case anyone looks at it */ >- source->pub.get_pixel_rows = preload_image; >- } else { >- /* Don't need a virtual array, but do need a one-row input buffer. */ >- source->whole_image = NULL; >- source->pub.buffer = (*cinfo->mem->alloc_sarray) >- ((j_common_ptr) cinfo, JPOOL_IMAGE, >- (JDIMENSION) width * components, (JDIMENSION) 1); >- source->pub.buffer_height = 1; >- source->pub.get_pixel_rows = source->get_pixel_rows; >- } >- >- while (idlen--) /* Throw away ID field */ >- (void) read_byte(source); >- >- if (maplen > 0) { >- if (maplen > 256 || GET_2B(3) != 0) >- ERREXIT(cinfo, JERR_TGA_BADCMAP); >- /* Allocate space to store the colormap */ >- source->colormap = (*cinfo->mem->alloc_sarray) >- ((j_common_ptr) cinfo, JPOOL_IMAGE, (JDIMENSION) maplen, (JDIMENSION) 3); >- /* and read it from the file */ >- read_colormap(source, (int) maplen, UCH(targaheader[7])); >- } else { >- if (cmaptype) /* but you promised a cmap! */ >- ERREXIT(cinfo, JERR_TGA_BADPARMS); >- source->colormap = NULL; >- } >- >- cinfo->input_components = components; >- cinfo->data_precision = 8; >- cinfo->image_width = width; >- cinfo->image_height = height; >-} >- >- >-/* >- * Finish up at the end of the file. >- */ >- >-METHODDEF(void) >-finish_input_tga (j_compress_ptr cinfo, cjpeg_source_ptr sinfo) >-{ >- /* no work */ >-} >- >- >-/* >- * The module selection routine for Targa format input. >- */ >- >-GLOBAL(cjpeg_source_ptr) >-jinit_read_targa (j_compress_ptr cinfo) >-{ >- tga_source_ptr source; >- >- /* Create module interface object */ >- source = (tga_source_ptr) >- (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, >- SIZEOF(tga_source_struct)); >- source->cinfo = cinfo; /* make back link for subroutines */ >- /* Fill in method ptrs, except get_pixel_rows which start_input sets */ >- source->pub.start_input = start_input_tga; >- source->pub.finish_input = finish_input_tga; >- >- return (cjpeg_source_ptr) source; >-} >- >-#endif /* TARGA_SUPPORTED */ >--- b/jpeg/simd/Makefile.am >+++ /dev/null >@@ -1,58 +0,0 @@ >-noinst_LTLIBRARIES = libsimd.la >- >-BUILT_SOURCES = jsimdcfg.inc >- >-EXTRA_DIST = nasm_lt.sh jcclrmmx.asm jcclrss2.asm jdclrmmx.asm jdclrss2.asm \ >- jdmrgmmx.asm jdmrgss2.asm jcclrss2-64.asm jdclrss2-64.asm \ >- jdmrgss2-64.asm >- >-if SIMD_X86_64 >- >-libsimd_la_SOURCES = jsimd_x86_64.c \ >- jsimd.h jsimdcfg.inc.h \ >- jsimdext.inc jcolsamp.inc jdct.inc \ >- jfsseflt-64.asm \ >- jccolss2-64.asm jdcolss2-64.asm \ >- jcsamss2-64.asm jdsamss2-64.asm jdmerss2-64.asm \ >- jcqnts2i-64.asm jfss2fst-64.asm jfss2int-64.asm \ >- jiss2red-64.asm jiss2int-64.asm jiss2fst-64.asm \ >- jcqnts2f-64.asm jiss2flt-64.asm >- >-jccolss2-64.lo: jcclrss2-64.asm >-jdcolss2-64.lo: jdclrss2-64.asm >-jdmerss2-64.lo: jdmrgss2-64.asm >-endif >- >-if SIMD_I386 >- >-libsimd_la_SOURCES = jsimd_i386.c \ >- jsimd.h jsimdcfg.inc.h \ >- jsimdext.inc jcolsamp.inc jdct.inc \ >- jsimdcpu.asm \ >- jccolmmx.asm jdcolmmx.asm \ >- jcsammmx.asm jdsammmx.asm jdmermmx.asm \ >- jcqntmmx.asm jfmmxfst.asm jfmmxint.asm \ >- jimmxred.asm jimmxint.asm jimmxfst.asm \ >- jcqnt3dn.asm jf3dnflt.asm ji3dnflt.asm \ >- jcqntsse.asm jfsseflt.asm jisseflt.asm \ >- jccolss2.asm jdcolss2.asm \ >- jcsamss2.asm jdsamss2.asm jdmerss2.asm \ >- jcqnts2i.asm jfss2fst.asm jfss2int.asm \ >- jiss2red.asm jiss2int.asm jiss2fst.asm \ >- jcqnts2f.asm jiss2flt.asm >- >-jccolmmx.lo: jcclrmmx.asm >-jccolss2.lo: jcclrss2.asm >-jdcolmmx.lo: jdclrmmx.asm >-jdcolss2.lo: jdclrss2.asm >-jdmermmx.lo: jdmrgmmx.asm >-jdmerss2.lo: jdmrgss2.asm >-endif >- >-AM_CPPFLAGS = -I$(top_srcdir) >- >-.asm.lo: >- $(LIBTOOL) --mode=compile --tag NASM $(srcdir)/nasm_lt.sh $(NASM) $(NAFLAGS) -I$(srcdir) $< -o $@ >- >-jsimdcfg.inc: $(srcdir)/jsimdcfg.inc.h ../jpeglib.h ../jconfig.h ../jmorecfg.h >- $(CPP) -I$(top_builddir) -I$(top_builddir)/simd $(srcdir)/jsimdcfg.inc.h | $(EGREP) "^[\;%]|^\ %" | sed 's%_cpp_protection_%%' | sed 's@% define@%define@g' > $@ >diff -U8 b/jpeg/simd/jsimd.h b/jpeg/simd/jsimd.h >--- b/jpeg/simd/jsimd.h >+++ b/jpeg/simd/jsimd.h >@@ -1,15 +1,16 @@ > /* > * simd/jsimd.h > * > * Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB > * > * 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 > * > */ > > /* Bitmask for supported acceleration methods */ > > #define JSIMD_NONE 0x00 > #define JSIMD_MMX 0x01 > #define JSIMD_3DNOW 0x02 >diff -U8 b/jpeg/simd/jsimd_i386.c b/jpeg/simd/jsimd_i386.c >--- b/jpeg/simd/jsimd_i386.c >+++ b/jpeg/simd/jsimd_i386.c >@@ -1,16 +1,17 @@ > /* > * jsimd_i386.c > * > * Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB > * Copyright 2009 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 a > * 32-bit x86 architecture. > */ > > #define JPEG_INTERNALS > #include "../jinclude.h" >diff -U8 b/jpeg/simd/jsimd_x86_64.c b/jpeg/simd/jsimd_x86_64.c >--- b/jpeg/simd/jsimd_x86_64.c >+++ b/jpeg/simd/jsimd_x86_64.c >@@ -1,29 +1,30 @@ > /* > * jsimd_x86_64.c > * > * Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB > * Copyright 2009 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 a > * x86_64 architecture. > */ > > #define JPEG_INTERNALS > #include "../jinclude.h" > #include "../jpeglib.h" > #include "../jsimd.h" > #include "../jdct.h" > #include "../jsimddct.h" >-#include "simd/jsimd.h" >+#include "jsimd.h" > > /* > * In the PIC cases, we have no guarantee that constants will keep > * their alignment. This macro allows us to verify it at runtime. > */ > #define IS_ALIGNED(ptr, order) (((size_t)ptr & ((1 << order) - 1)) == 0) > > #define IS_ALIGNED_SSE(ptr) (IS_ALIGNED(ptr, 4)) /* 16 byte alignment */ >--- b/jpeg/simd/nasm_lt.sh >+++ /dev/null >@@ -1,57 +0,0 @@ >-#! /bin/sh >-command="" >-infile="" >-o_opt=no >-pic=no >-while [ $# -gt 0 ]; do >- case "$1" in >- -DPIC|-fPIC|-fpic|-Kpic|-KPIC) >- if [ "$pic" != "yes" ] ; then >- command="$command -DPIC" >- pic=yes >- fi >- ;; >- -f|-fbin|-faout|-faoutb|-fcoff|-felf|-felf64|-fas86| \ >- -fobj|-fwin32|-fwin64|-frdf|-fieee|-fmacho|-fmacho64) >- # it's a file format specifier for nasm. >- command="$command $1" >- ;; >- -f*) >- # maybe a code-generation flag for gcc. >- ;; >- -[Ii]*) >- incdir=`echo "$1" | sed 's/^-[Ii]//'` >- if [ "x$incdir" = x -a "x$2" != x ] ; then >- case "$2" in >- -*) ;; >- *) incdir="$2"; shift;; >- esac >- fi >- if [ "x$incdir" != x ] ; then >- # In the case of NASM, the trailing slash is necessary. >- incdir=`echo "$incdir" | sed 's%/*$%/%'` >- command="$command -I$incdir" >- fi >- ;; >- -o*) >- o_opt=yes >- command="$command $1" >- ;; >- *.asm) >- infile=$1 >- command="$command $1" >- ;; >- *) >- command="$command $1" >- ;; >- esac >- shift >-done >-if [ "$o_opt" != yes ] ; then >- # By default, NASM creates an output file >- # in the same directory as the input file. >- outfile="-o `echo $infile | sed -e 's%^.*/%%' -e 's%\.[^.]*$%%'`.o" >- command="$command $outfile" >-fi >-echo $command >-exec $command >--- b/jpeg/transupp.c >+++ /dev/null >@@ -1,928 +0,0 @@ >-/* >- * transupp.c >- * >- * Copyright (C) 1997, Thomas G. Lane. >- * This file is part of the Independent JPEG Group's software. >- * For conditions of distribution and use, see the accompanying README file. >- * >- * This file contains image transformation routines and other utility code >- * used by the jpegtran sample application. These are NOT part of the core >- * JPEG library. But we keep these routines separate from jpegtran.c to >- * ease the task of maintaining jpegtran-like programs that have other user >- * interfaces. >- */ >- >-/* Although this file really shouldn't have access to the library internals, >- * it's helpful to let it call jround_up() and jcopy_block_row(). >- */ >-#define JPEG_INTERNALS >- >-#include "jinclude.h" >-#include "jpeglib.h" >-#include "transupp.h" /* My own external interface */ >- >- >-#if TRANSFORMS_SUPPORTED >- >-/* >- * Lossless image transformation routines. These routines work on DCT >- * coefficient arrays and thus do not require any lossy decompression >- * or recompression of the image. >- * Thanks to Guido Vollbeding for the initial design and code of this feature. >- * >- * Horizontal flipping is done in-place, using a single top-to-bottom >- * pass through the virtual source array. It will thus be much the >- * fastest option for images larger than main memory. >- * >- * The other routines require a set of destination virtual arrays, so they >- * need twice as much memory as jpegtran normally does. The destination >- * arrays are always written in normal scan order (top to bottom) because >- * the virtual array manager expects this. The source arrays will be scanned >- * in the corresponding order, which means multiple passes through the source >- * arrays for most of the transforms. That could result in much thrashing >- * if the image is larger than main memory. >- * >- * Some notes about the operating environment of the individual transform >- * routines: >- * 1. Both the source and destination virtual arrays are allocated from the >- * source JPEG object, and therefore should be manipulated by calling the >- * source's memory manager. >- * 2. The destination's component count should be used. It may be smaller >- * than the source's when forcing to grayscale. >- * 3. Likewise the destination's sampling factors should be used. When >- * forcing to grayscale the destination's sampling factors will be all 1, >- * and we may as well take that as the effective iMCU size. >- * 4. When "trim" is in effect, the destination's dimensions will be the >- * trimmed values but the source's will be untrimmed. >- * 5. All the routines assume that the source and destination buffers are >- * padded out to a full iMCU boundary. This is true, although for the >- * source buffer it is an undocumented property of jdcoefct.c. >- * Notes 2,3,4 boil down to this: generally we should use the destination's >- * dimensions and ignore the source's. >- */ >- >- >-LOCAL(void) >-do_flip_h (j_decompress_ptr srcinfo, j_compress_ptr dstinfo, >- jvirt_barray_ptr *src_coef_arrays) >-/* Horizontal flip; done in-place, so no separate dest array is required */ >-{ >- JDIMENSION MCU_cols, comp_width, blk_x, blk_y; >- int ci, k, offset_y; >- JBLOCKARRAY buffer; >- JCOEFPTR ptr1, ptr2; >- JCOEF temp1, temp2; >- jpeg_component_info *compptr; >- >- /* Horizontal mirroring of DCT blocks is accomplished by swapping >- * pairs of blocks in-place. Within a DCT block, we perform horizontal >- * mirroring by changing the signs of odd-numbered columns. >- * Partial iMCUs at the right edge are left untouched. >- */ >- MCU_cols = dstinfo->image_width / (dstinfo->max_h_samp_factor * DCTSIZE); >- >- for (ci = 0; ci < dstinfo->num_components; ci++) { >- compptr = dstinfo->comp_info + ci; >- comp_width = MCU_cols * compptr->h_samp_factor; >- for (blk_y = 0; blk_y < compptr->height_in_blocks; >- blk_y += compptr->v_samp_factor) { >- buffer = (*srcinfo->mem->access_virt_barray) >- ((j_common_ptr) srcinfo, src_coef_arrays[ci], blk_y, >- (JDIMENSION) compptr->v_samp_factor, TRUE); >- for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) { >- for (blk_x = 0; blk_x * 2 < comp_width; blk_x++) { >- ptr1 = buffer[offset_y][blk_x]; >- ptr2 = buffer[offset_y][comp_width - blk_x - 1]; >- /* this unrolled loop doesn't need to know which row it's on... */ >- for (k = 0; k < DCTSIZE2; k += 2) { >- temp1 = *ptr1; /* swap even column */ >- temp2 = *ptr2; >- *ptr1++ = temp2; >- *ptr2++ = temp1; >- temp1 = *ptr1; /* swap odd column with sign change */ >- temp2 = *ptr2; >- *ptr1++ = -temp2; >- *ptr2++ = -temp1; >- } >- } >- } >- } >- } >-} >- >- >-LOCAL(void) >-do_flip_v (j_decompress_ptr srcinfo, j_compress_ptr dstinfo, >- jvirt_barray_ptr *src_coef_arrays, >- jvirt_barray_ptr *dst_coef_arrays) >-/* Vertical flip */ >-{ >- JDIMENSION MCU_rows, comp_height, dst_blk_x, dst_blk_y; >- int ci, i, j, offset_y; >- JBLOCKARRAY src_buffer, dst_buffer; >- JBLOCKROW src_row_ptr, dst_row_ptr; >- JCOEFPTR src_ptr, dst_ptr; >- jpeg_component_info *compptr; >- >- /* We output into a separate array because we can't touch different >- * rows of the source virtual array simultaneously. Otherwise, this >- * is a pretty straightforward analog of horizontal flip. >- * Within a DCT block, vertical mirroring is done by changing the signs >- * of odd-numbered rows. >- * Partial iMCUs at the bottom edge are copied verbatim. >- */ >- MCU_rows = dstinfo->image_height / (dstinfo->max_v_samp_factor * DCTSIZE); >- >- for (ci = 0; ci < dstinfo->num_components; ci++) { >- compptr = dstinfo->comp_info + ci; >- comp_height = MCU_rows * compptr->v_samp_factor; >- for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks; >- dst_blk_y += compptr->v_samp_factor) { >- dst_buffer = (*srcinfo->mem->access_virt_barray) >- ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y, >- (JDIMENSION) compptr->v_samp_factor, TRUE); >- if (dst_blk_y < comp_height) { >- /* Row is within the mirrorable area. */ >- src_buffer = (*srcinfo->mem->access_virt_barray) >- ((j_common_ptr) srcinfo, src_coef_arrays[ci], >- comp_height - dst_blk_y - (JDIMENSION) compptr->v_samp_factor, >- (JDIMENSION) compptr->v_samp_factor, FALSE); >- } else { >- /* Bottom-edge blocks will be copied verbatim. */ >- src_buffer = (*srcinfo->mem->access_virt_barray) >- ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_y, >- (JDIMENSION) compptr->v_samp_factor, FALSE); >- } >- for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) { >- if (dst_blk_y < comp_height) { >- /* Row is within the mirrorable area. */ >- dst_row_ptr = dst_buffer[offset_y]; >- src_row_ptr = src_buffer[compptr->v_samp_factor - offset_y - 1]; >- for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks; >- dst_blk_x++) { >- dst_ptr = dst_row_ptr[dst_blk_x]; >- src_ptr = src_row_ptr[dst_blk_x]; >- for (i = 0; i < DCTSIZE; i += 2) { >- /* copy even row */ >- for (j = 0; j < DCTSIZE; j++) >- *dst_ptr++ = *src_ptr++; >- /* copy odd row with sign change */ >- for (j = 0; j < DCTSIZE; j++) >- *dst_ptr++ = - *src_ptr++; >- } >- } >- } else { >- /* Just copy row verbatim. */ >- jcopy_block_row(src_buffer[offset_y], dst_buffer[offset_y], >- compptr->width_in_blocks); >- } >- } >- } >- } >-} >- >- >-LOCAL(void) >-do_transpose (j_decompress_ptr srcinfo, j_compress_ptr dstinfo, >- jvirt_barray_ptr *src_coef_arrays, >- jvirt_barray_ptr *dst_coef_arrays) >-/* Transpose source into destination */ >-{ >- JDIMENSION dst_blk_x, dst_blk_y; >- int ci, i, j, offset_x, offset_y; >- JBLOCKARRAY src_buffer, dst_buffer; >- JCOEFPTR src_ptr, dst_ptr; >- jpeg_component_info *compptr; >- >- /* Transposing pixels within a block just requires transposing the >- * DCT coefficients. >- * Partial iMCUs at the edges require no special treatment; we simply >- * process all the available DCT blocks for every component. >- */ >- for (ci = 0; ci < dstinfo->num_components; ci++) { >- compptr = dstinfo->comp_info + ci; >- for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks; >- dst_blk_y += compptr->v_samp_factor) { >- dst_buffer = (*srcinfo->mem->access_virt_barray) >- ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y, >- (JDIMENSION) compptr->v_samp_factor, TRUE); >- for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) { >- for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks; >- dst_blk_x += compptr->h_samp_factor) { >- src_buffer = (*srcinfo->mem->access_virt_barray) >- ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_x, >- (JDIMENSION) compptr->h_samp_factor, FALSE); >- for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) { >- src_ptr = src_buffer[offset_x][dst_blk_y + offset_y]; >- dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x]; >- for (i = 0; i < DCTSIZE; i++) >- for (j = 0; j < DCTSIZE; j++) >- dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j]; >- } >- } >- } >- } >- } >-} >- >- >-LOCAL(void) >-do_rot_90 (j_decompress_ptr srcinfo, j_compress_ptr dstinfo, >- jvirt_barray_ptr *src_coef_arrays, >- jvirt_barray_ptr *dst_coef_arrays) >-/* 90 degree rotation is equivalent to >- * 1. Transposing the image; >- * 2. Horizontal mirroring. >- * These two steps are merged into a single processing routine. >- */ >-{ >- JDIMENSION MCU_cols, comp_width, dst_blk_x, dst_blk_y; >- int ci, i, j, offset_x, offset_y; >- JBLOCKARRAY src_buffer, dst_buffer; >- JCOEFPTR src_ptr, dst_ptr; >- jpeg_component_info *compptr; >- >- /* Because of the horizontal mirror step, we can't process partial iMCUs >- * at the (output) right edge properly. They just get transposed and >- * not mirrored. >- */ >- MCU_cols = dstinfo->image_width / (dstinfo->max_h_samp_factor * DCTSIZE); >- >- for (ci = 0; ci < dstinfo->num_components; ci++) { >- compptr = dstinfo->comp_info + ci; >- comp_width = MCU_cols * compptr->h_samp_factor; >- for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks; >- dst_blk_y += compptr->v_samp_factor) { >- dst_buffer = (*srcinfo->mem->access_virt_barray) >- ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y, >- (JDIMENSION) compptr->v_samp_factor, TRUE); >- for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) { >- for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks; >- dst_blk_x += compptr->h_samp_factor) { >- src_buffer = (*srcinfo->mem->access_virt_barray) >- ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_x, >- (JDIMENSION) compptr->h_samp_factor, FALSE); >- for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) { >- src_ptr = src_buffer[offset_x][dst_blk_y + offset_y]; >- if (dst_blk_x < comp_width) { >- /* Block is within the mirrorable area. */ >- dst_ptr = dst_buffer[offset_y] >- [comp_width - dst_blk_x - offset_x - 1]; >- for (i = 0; i < DCTSIZE; i++) { >- for (j = 0; j < DCTSIZE; j++) >- dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j]; >- i++; >- for (j = 0; j < DCTSIZE; j++) >- dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j]; >- } >- } else { >- /* Edge blocks are transposed but not mirrored. */ >- dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x]; >- for (i = 0; i < DCTSIZE; i++) >- for (j = 0; j < DCTSIZE; j++) >- dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j]; >- } >- } >- } >- } >- } >- } >-} >- >- >-LOCAL(void) >-do_rot_270 (j_decompress_ptr srcinfo, j_compress_ptr dstinfo, >- jvirt_barray_ptr *src_coef_arrays, >- jvirt_barray_ptr *dst_coef_arrays) >-/* 270 degree rotation is equivalent to >- * 1. Horizontal mirroring; >- * 2. Transposing the image. >- * These two steps are merged into a single processing routine. >- */ >-{ >- JDIMENSION MCU_rows, comp_height, dst_blk_x, dst_blk_y; >- int ci, i, j, offset_x, offset_y; >- JBLOCKARRAY src_buffer, dst_buffer; >- JCOEFPTR src_ptr, dst_ptr; >- jpeg_component_info *compptr; >- >- /* Because of the horizontal mirror step, we can't process partial iMCUs >- * at the (output) bottom edge properly. They just get transposed and >- * not mirrored. >- */ >- MCU_rows = dstinfo->image_height / (dstinfo->max_v_samp_factor * DCTSIZE); >- >- for (ci = 0; ci < dstinfo->num_components; ci++) { >- compptr = dstinfo->comp_info + ci; >- comp_height = MCU_rows * compptr->v_samp_factor; >- for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks; >- dst_blk_y += compptr->v_samp_factor) { >- dst_buffer = (*srcinfo->mem->access_virt_barray) >- ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y, >- (JDIMENSION) compptr->v_samp_factor, TRUE); >- for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) { >- for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks; >- dst_blk_x += compptr->h_samp_factor) { >- src_buffer = (*srcinfo->mem->access_virt_barray) >- ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_x, >- (JDIMENSION) compptr->h_samp_factor, FALSE); >- for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) { >- dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x]; >- if (dst_blk_y < comp_height) { >- /* Block is within the mirrorable area. */ >- src_ptr = src_buffer[offset_x] >- [comp_height - dst_blk_y - offset_y - 1]; >- for (i = 0; i < DCTSIZE; i++) { >- for (j = 0; j < DCTSIZE; j++) { >- dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j]; >- j++; >- dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j]; >- } >- } >- } else { >- /* Edge blocks are transposed but not mirrored. */ >- src_ptr = src_buffer[offset_x][dst_blk_y + offset_y]; >- for (i = 0; i < DCTSIZE; i++) >- for (j = 0; j < DCTSIZE; j++) >- dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j]; >- } >- } >- } >- } >- } >- } >-} >- >- >-LOCAL(void) >-do_rot_180 (j_decompress_ptr srcinfo, j_compress_ptr dstinfo, >- jvirt_barray_ptr *src_coef_arrays, >- jvirt_barray_ptr *dst_coef_arrays) >-/* 180 degree rotation is equivalent to >- * 1. Vertical mirroring; >- * 2. Horizontal mirroring. >- * These two steps are merged into a single processing routine. >- */ >-{ >- JDIMENSION MCU_cols, MCU_rows, comp_width, comp_height, dst_blk_x, dst_blk_y; >- int ci, i, j, offset_y; >- JBLOCKARRAY src_buffer, dst_buffer; >- JBLOCKROW src_row_ptr, dst_row_ptr; >- JCOEFPTR src_ptr, dst_ptr; >- jpeg_component_info *compptr; >- >- MCU_cols = dstinfo->image_width / (dstinfo->max_h_samp_factor * DCTSIZE); >- MCU_rows = dstinfo->image_height / (dstinfo->max_v_samp_factor * DCTSIZE); >- >- for (ci = 0; ci < dstinfo->num_components; ci++) { >- compptr = dstinfo->comp_info + ci; >- comp_width = MCU_cols * compptr->h_samp_factor; >- comp_height = MCU_rows * compptr->v_samp_factor; >- for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks; >- dst_blk_y += compptr->v_samp_factor) { >- dst_buffer = (*srcinfo->mem->access_virt_barray) >- ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y, >- (JDIMENSION) compptr->v_samp_factor, TRUE); >- if (dst_blk_y < comp_height) { >- /* Row is within the vertically mirrorable area. */ >- src_buffer = (*srcinfo->mem->access_virt_barray) >- ((j_common_ptr) srcinfo, src_coef_arrays[ci], >- comp_height - dst_blk_y - (JDIMENSION) compptr->v_samp_factor, >- (JDIMENSION) compptr->v_samp_factor, FALSE); >- } else { >- /* Bottom-edge rows are only mirrored horizontally. */ >- src_buffer = (*srcinfo->mem->access_virt_barray) >- ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_y, >- (JDIMENSION) compptr->v_samp_factor, FALSE); >- } >- for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) { >- if (dst_blk_y < comp_height) { >- /* Row is within the mirrorable area. */ >- dst_row_ptr = dst_buffer[offset_y]; >- src_row_ptr = src_buffer[compptr->v_samp_factor - offset_y - 1]; >- /* Process the blocks that can be mirrored both ways. */ >- for (dst_blk_x = 0; dst_blk_x < comp_width; dst_blk_x++) { >- dst_ptr = dst_row_ptr[dst_blk_x]; >- src_ptr = src_row_ptr[comp_width - dst_blk_x - 1]; >- for (i = 0; i < DCTSIZE; i += 2) { >- /* For even row, negate every odd column. */ >- for (j = 0; j < DCTSIZE; j += 2) { >- *dst_ptr++ = *src_ptr++; >- *dst_ptr++ = - *src_ptr++; >- } >- /* For odd row, negate every even column. */ >- for (j = 0; j < DCTSIZE; j += 2) { >- *dst_ptr++ = - *src_ptr++; >- *dst_ptr++ = *src_ptr++; >- } >- } >- } >- /* Any remaining right-edge blocks are only mirrored vertically. */ >- for (; dst_blk_x < compptr->width_in_blocks; dst_blk_x++) { >- dst_ptr = dst_row_ptr[dst_blk_x]; >- src_ptr = src_row_ptr[dst_blk_x]; >- for (i = 0; i < DCTSIZE; i += 2) { >- for (j = 0; j < DCTSIZE; j++) >- *dst_ptr++ = *src_ptr++; >- for (j = 0; j < DCTSIZE; j++) >- *dst_ptr++ = - *src_ptr++; >- } >- } >- } else { >- /* Remaining rows are just mirrored horizontally. */ >- dst_row_ptr = dst_buffer[offset_y]; >- src_row_ptr = src_buffer[offset_y]; >- /* Process the blocks that can be mirrored. */ >- for (dst_blk_x = 0; dst_blk_x < comp_width; dst_blk_x++) { >- dst_ptr = dst_row_ptr[dst_blk_x]; >- src_ptr = src_row_ptr[comp_width - dst_blk_x - 1]; >- for (i = 0; i < DCTSIZE2; i += 2) { >- *dst_ptr++ = *src_ptr++; >- *dst_ptr++ = - *src_ptr++; >- } >- } >- /* Any remaining right-edge blocks are only copied. */ >- for (; dst_blk_x < compptr->width_in_blocks; dst_blk_x++) { >- dst_ptr = dst_row_ptr[dst_blk_x]; >- src_ptr = src_row_ptr[dst_blk_x]; >- for (i = 0; i < DCTSIZE2; i++) >- *dst_ptr++ = *src_ptr++; >- } >- } >- } >- } >- } >-} >- >- >-LOCAL(void) >-do_transverse (j_decompress_ptr srcinfo, j_compress_ptr dstinfo, >- jvirt_barray_ptr *src_coef_arrays, >- jvirt_barray_ptr *dst_coef_arrays) >-/* Transverse transpose is equivalent to >- * 1. 180 degree rotation; >- * 2. Transposition; >- * or >- * 1. Horizontal mirroring; >- * 2. Transposition; >- * 3. Horizontal mirroring. >- * These steps are merged into a single processing routine. >- */ >-{ >- JDIMENSION MCU_cols, MCU_rows, comp_width, comp_height, dst_blk_x, dst_blk_y; >- int ci, i, j, offset_x, offset_y; >- JBLOCKARRAY src_buffer, dst_buffer; >- JCOEFPTR src_ptr, dst_ptr; >- jpeg_component_info *compptr; >- >- MCU_cols = dstinfo->image_width / (dstinfo->max_h_samp_factor * DCTSIZE); >- MCU_rows = dstinfo->image_height / (dstinfo->max_v_samp_factor * DCTSIZE); >- >- for (ci = 0; ci < dstinfo->num_components; ci++) { >- compptr = dstinfo->comp_info + ci; >- comp_width = MCU_cols * compptr->h_samp_factor; >- comp_height = MCU_rows * compptr->v_samp_factor; >- for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks; >- dst_blk_y += compptr->v_samp_factor) { >- dst_buffer = (*srcinfo->mem->access_virt_barray) >- ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y, >- (JDIMENSION) compptr->v_samp_factor, TRUE); >- for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) { >- for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks; >- dst_blk_x += compptr->h_samp_factor) { >- src_buffer = (*srcinfo->mem->access_virt_barray) >- ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_x, >- (JDIMENSION) compptr->h_samp_factor, FALSE); >- for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) { >- if (dst_blk_y < comp_height) { >- src_ptr = src_buffer[offset_x] >- [comp_height - dst_blk_y - offset_y - 1]; >- if (dst_blk_x < comp_width) { >- /* Block is within the mirrorable area. */ >- dst_ptr = dst_buffer[offset_y] >- [comp_width - dst_blk_x - offset_x - 1]; >- for (i = 0; i < DCTSIZE; i++) { >- for (j = 0; j < DCTSIZE; j++) { >- dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j]; >- j++; >- dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j]; >- } >- i++; >- for (j = 0; j < DCTSIZE; j++) { >- dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j]; >- j++; >- dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j]; >- } >- } >- } else { >- /* Right-edge blocks are mirrored in y only */ >- dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x]; >- for (i = 0; i < DCTSIZE; i++) { >- for (j = 0; j < DCTSIZE; j++) { >- dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j]; >- j++; >- dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j]; >- } >- } >- } >- } else { >- src_ptr = src_buffer[offset_x][dst_blk_y + offset_y]; >- if (dst_blk_x < comp_width) { >- /* Bottom-edge blocks are mirrored in x only */ >- dst_ptr = dst_buffer[offset_y] >- [comp_width - dst_blk_x - offset_x - 1]; >- for (i = 0; i < DCTSIZE; i++) { >- for (j = 0; j < DCTSIZE; j++) >- dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j]; >- i++; >- for (j = 0; j < DCTSIZE; j++) >- dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j]; >- } >- } else { >- /* At lower right corner, just transpose, no mirroring */ >- dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x]; >- for (i = 0; i < DCTSIZE; i++) >- for (j = 0; j < DCTSIZE; j++) >- dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j]; >- } >- } >- } >- } >- } >- } >- } >-} >- >- >-/* Request any required workspace. >- * >- * We allocate the workspace virtual arrays from the source decompression >- * object, so that all the arrays (both the original data and the workspace) >- * will be taken into account while making memory management decisions. >- * Hence, this routine must be called after jpeg_read_header (which reads >- * the image dimensions) and before jpeg_read_coefficients (which realizes >- * the source's virtual arrays). >- */ >- >-GLOBAL(void) >-jtransform_request_workspace (j_decompress_ptr srcinfo, >- jpeg_transform_info *info) >-{ >- jvirt_barray_ptr *coef_arrays = NULL; >- jpeg_component_info *compptr; >- int ci; >- >- if (info->force_grayscale && >- srcinfo->jpeg_color_space == JCS_YCbCr && >- srcinfo->num_components == 3) { >- /* We'll only process the first component */ >- info->num_components = 1; >- } else { >- /* Process all the components */ >- info->num_components = srcinfo->num_components; >- } >- >- switch (info->transform) { >- case JXFORM_NONE: >- case JXFORM_FLIP_H: >- /* Don't need a workspace array */ >- break; >- case JXFORM_FLIP_V: >- case JXFORM_ROT_180: >- /* Need workspace arrays having same dimensions as source image. >- * Note that we allocate arrays padded out to the next iMCU boundary, >- * so that transform routines need not worry about missing edge blocks. >- */ >- coef_arrays = (jvirt_barray_ptr *) >- (*srcinfo->mem->alloc_small) ((j_common_ptr) srcinfo, JPOOL_IMAGE, >- SIZEOF(jvirt_barray_ptr) * info->num_components); >- for (ci = 0; ci < info->num_components; ci++) { >- compptr = srcinfo->comp_info + ci; >- coef_arrays[ci] = (*srcinfo->mem->request_virt_barray) >- ((j_common_ptr) srcinfo, JPOOL_IMAGE, FALSE, >- (JDIMENSION) jround_up((long) compptr->width_in_blocks, >- (long) compptr->h_samp_factor), >- (JDIMENSION) jround_up((long) compptr->height_in_blocks, >- (long) compptr->v_samp_factor), >- (JDIMENSION) compptr->v_samp_factor); >- } >- break; >- case JXFORM_TRANSPOSE: >- case JXFORM_TRANSVERSE: >- case JXFORM_ROT_90: >- case JXFORM_ROT_270: >- /* Need workspace arrays having transposed dimensions. >- * Note that we allocate arrays padded out to the next iMCU boundary, >- * so that transform routines need not worry about missing edge blocks. >- */ >- coef_arrays = (jvirt_barray_ptr *) >- (*srcinfo->mem->alloc_small) ((j_common_ptr) srcinfo, JPOOL_IMAGE, >- SIZEOF(jvirt_barray_ptr) * info->num_components); >- for (ci = 0; ci < info->num_components; ci++) { >- compptr = srcinfo->comp_info + ci; >- coef_arrays[ci] = (*srcinfo->mem->request_virt_barray) >- ((j_common_ptr) srcinfo, JPOOL_IMAGE, FALSE, >- (JDIMENSION) jround_up((long) compptr->height_in_blocks, >- (long) compptr->v_samp_factor), >- (JDIMENSION) jround_up((long) compptr->width_in_blocks, >- (long) compptr->h_samp_factor), >- (JDIMENSION) compptr->h_samp_factor); >- } >- break; >- } >- info->workspace_coef_arrays = coef_arrays; >-} >- >- >-/* Transpose destination image parameters */ >- >-LOCAL(void) >-transpose_critical_parameters (j_compress_ptr dstinfo) >-{ >- int tblno, i, j, ci, itemp; >- jpeg_component_info *compptr; >- JQUANT_TBL *qtblptr; >- JDIMENSION dtemp; >- UINT16 qtemp; >- >- /* Transpose basic image dimensions */ >- dtemp = dstinfo->image_width; >- dstinfo->image_width = dstinfo->image_height; >- dstinfo->image_height = dtemp; >- >- /* Transpose sampling factors */ >- for (ci = 0; ci < dstinfo->num_components; ci++) { >- compptr = dstinfo->comp_info + ci; >- itemp = compptr->h_samp_factor; >- compptr->h_samp_factor = compptr->v_samp_factor; >- compptr->v_samp_factor = itemp; >- } >- >- /* Transpose quantization tables */ >- for (tblno = 0; tblno < NUM_QUANT_TBLS; tblno++) { >- qtblptr = dstinfo->quant_tbl_ptrs[tblno]; >- if (qtblptr != NULL) { >- for (i = 0; i < DCTSIZE; i++) { >- for (j = 0; j < i; j++) { >- qtemp = qtblptr->quantval[i*DCTSIZE+j]; >- qtblptr->quantval[i*DCTSIZE+j] = qtblptr->quantval[j*DCTSIZE+i]; >- qtblptr->quantval[j*DCTSIZE+i] = qtemp; >- } >- } >- } >- } >-} >- >- >-/* Trim off any partial iMCUs on the indicated destination edge */ >- >-LOCAL(void) >-trim_right_edge (j_compress_ptr dstinfo) >-{ >- int ci, max_h_samp_factor; >- JDIMENSION MCU_cols; >- >- /* We have to compute max_h_samp_factor ourselves, >- * because it hasn't been set yet in the destination >- * (and we don't want to use the source's value). >- */ >- max_h_samp_factor = 1; >- for (ci = 0; ci < dstinfo->num_components; ci++) { >- int h_samp_factor = dstinfo->comp_info[ci].h_samp_factor; >- max_h_samp_factor = MAX(max_h_samp_factor, h_samp_factor); >- } >- MCU_cols = dstinfo->image_width / (max_h_samp_factor * DCTSIZE); >- if (MCU_cols > 0) /* can't trim to 0 pixels */ >- dstinfo->image_width = MCU_cols * (max_h_samp_factor * DCTSIZE); >-} >- >-LOCAL(void) >-trim_bottom_edge (j_compress_ptr dstinfo) >-{ >- int ci, max_v_samp_factor; >- JDIMENSION MCU_rows; >- >- /* We have to compute max_v_samp_factor ourselves, >- * because it hasn't been set yet in the destination >- * (and we don't want to use the source's value). >- */ >- max_v_samp_factor = 1; >- for (ci = 0; ci < dstinfo->num_components; ci++) { >- int v_samp_factor = dstinfo->comp_info[ci].v_samp_factor; >- max_v_samp_factor = MAX(max_v_samp_factor, v_samp_factor); >- } >- MCU_rows = dstinfo->image_height / (max_v_samp_factor * DCTSIZE); >- if (MCU_rows > 0) /* can't trim to 0 pixels */ >- dstinfo->image_height = MCU_rows * (max_v_samp_factor * DCTSIZE); >-} >- >- >-/* Adjust output image parameters as needed. >- * >- * This must be called after jpeg_copy_critical_parameters() >- * and before jpeg_write_coefficients(). >- * >- * The return value is the set of virtual coefficient arrays to be written >- * (either the ones allocated by jtransform_request_workspace, or the >- * original source data arrays). The caller will need to pass this value >- * to jpeg_write_coefficients(). >- */ >- >-GLOBAL(jvirt_barray_ptr *) >-jtransform_adjust_parameters (j_decompress_ptr srcinfo, >- j_compress_ptr dstinfo, >- jvirt_barray_ptr *src_coef_arrays, >- jpeg_transform_info *info) >-{ >- /* If force-to-grayscale is requested, adjust destination parameters */ >- if (info->force_grayscale) { >- /* We use jpeg_set_colorspace to make sure subsidiary settings get fixed >- * properly. Among other things, the target h_samp_factor & v_samp_factor >- * will get set to 1, which typically won't match the source. >- * In fact we do this even if the source is already grayscale; that >- * provides an easy way of coercing a grayscale JPEG with funny sampling >- * factors to the customary 1,1. (Some decoders fail on other factors.) >- */ >- if ((dstinfo->jpeg_color_space == JCS_YCbCr && >- dstinfo->num_components == 3) || >- (dstinfo->jpeg_color_space == JCS_GRAYSCALE && >- dstinfo->num_components == 1)) { >- /* We have to preserve the source's quantization table number. */ >- int sv_quant_tbl_no = dstinfo->comp_info[0].quant_tbl_no; >- jpeg_set_colorspace(dstinfo, JCS_GRAYSCALE); >- dstinfo->comp_info[0].quant_tbl_no = sv_quant_tbl_no; >- } else { >- /* Sorry, can't do it */ >- ERREXIT(dstinfo, JERR_CONVERSION_NOTIMPL); >- } >- } >- >- /* Correct the destination's image dimensions etc if necessary */ >- switch (info->transform) { >- case JXFORM_NONE: >- /* Nothing to do */ >- break; >- case JXFORM_FLIP_H: >- if (info->trim) >- trim_right_edge(dstinfo); >- break; >- case JXFORM_FLIP_V: >- if (info->trim) >- trim_bottom_edge(dstinfo); >- break; >- case JXFORM_TRANSPOSE: >- transpose_critical_parameters(dstinfo); >- /* transpose does NOT have to trim anything */ >- break; >- case JXFORM_TRANSVERSE: >- transpose_critical_parameters(dstinfo); >- if (info->trim) { >- trim_right_edge(dstinfo); >- trim_bottom_edge(dstinfo); >- } >- break; >- case JXFORM_ROT_90: >- transpose_critical_parameters(dstinfo); >- if (info->trim) >- trim_right_edge(dstinfo); >- break; >- case JXFORM_ROT_180: >- if (info->trim) { >- trim_right_edge(dstinfo); >- trim_bottom_edge(dstinfo); >- } >- break; >- case JXFORM_ROT_270: >- transpose_critical_parameters(dstinfo); >- if (info->trim) >- trim_bottom_edge(dstinfo); >- break; >- } >- >- /* Return the appropriate output data set */ >- if (info->workspace_coef_arrays != NULL) >- return info->workspace_coef_arrays; >- return src_coef_arrays; >-} >- >- >-/* Execute the actual transformation, if any. >- * >- * This must be called *after* jpeg_write_coefficients, because it depends >- * on jpeg_write_coefficients to have computed subsidiary values such as >- * the per-component width and height fields in the destination object. >- * >- * Note that some transformations will modify the source data arrays! >- */ >- >-GLOBAL(void) >-jtransform_execute_transformation (j_decompress_ptr srcinfo, >- j_compress_ptr dstinfo, >- jvirt_barray_ptr *src_coef_arrays, >- jpeg_transform_info *info) >-{ >- jvirt_barray_ptr *dst_coef_arrays = info->workspace_coef_arrays; >- >- switch (info->transform) { >- case JXFORM_NONE: >- break; >- case JXFORM_FLIP_H: >- do_flip_h(srcinfo, dstinfo, src_coef_arrays); >- break; >- case JXFORM_FLIP_V: >- do_flip_v(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays); >- break; >- case JXFORM_TRANSPOSE: >- do_transpose(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays); >- break; >- case JXFORM_TRANSVERSE: >- do_transverse(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays); >- break; >- case JXFORM_ROT_90: >- do_rot_90(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays); >- break; >- case JXFORM_ROT_180: >- do_rot_180(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays); >- break; >- case JXFORM_ROT_270: >- do_rot_270(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays); >- break; >- } >-} >- >-#endif /* TRANSFORMS_SUPPORTED */ >- >- >-/* Setup decompression object to save desired markers in memory. >- * This must be called before jpeg_read_header() to have the desired effect. >- */ >- >-GLOBAL(void) >-jcopy_markers_setup (j_decompress_ptr srcinfo, JCOPY_OPTION option) >-{ >-#ifdef SAVE_MARKERS_SUPPORTED >- int m; >- >- /* Save comments except under NONE option */ >- if (option != JCOPYOPT_NONE) { >- jpeg_save_markers(srcinfo, JPEG_COM, 0xFFFF); >- } >- /* Save all types of APPn markers iff ALL option */ >- if (option == JCOPYOPT_ALL) { >- for (m = 0; m < 16; m++) >- jpeg_save_markers(srcinfo, JPEG_APP0 + m, 0xFFFF); >- } >-#endif /* SAVE_MARKERS_SUPPORTED */ >-} >- >-/* Copy markers saved in the given source object to the destination object. >- * This should be called just after jpeg_start_compress() or >- * jpeg_write_coefficients(). >- * Note that those routines will have written the SOI, and also the >- * JFIF APP0 or Adobe APP14 markers if selected. >- */ >- >-GLOBAL(void) >-jcopy_markers_execute (j_decompress_ptr srcinfo, j_compress_ptr dstinfo, >- JCOPY_OPTION option) >-{ >- jpeg_saved_marker_ptr marker; >- >- /* In the current implementation, we don't actually need to examine the >- * option flag here; we just copy everything that got saved. >- * But to avoid confusion, we do not output JFIF and Adobe APP14 markers >- * if the encoder library already wrote one. >- */ >- for (marker = srcinfo->marker_list; marker != NULL; marker = marker->next) { >- if (dstinfo->write_JFIF_header && >- marker->marker == JPEG_APP0 && >- marker->data_length >= 5 && >- GETJOCTET(marker->data[0]) == 0x4A && >- GETJOCTET(marker->data[1]) == 0x46 && >- GETJOCTET(marker->data[2]) == 0x49 && >- GETJOCTET(marker->data[3]) == 0x46 && >- GETJOCTET(marker->data[4]) == 0) >- continue; /* reject duplicate JFIF */ >- if (dstinfo->write_Adobe_marker && >- marker->marker == JPEG_APP0+14 && >- marker->data_length >= 5 && >- GETJOCTET(marker->data[0]) == 0x41 && >- GETJOCTET(marker->data[1]) == 0x64 && >- GETJOCTET(marker->data[2]) == 0x6F && >- GETJOCTET(marker->data[3]) == 0x62 && >- GETJOCTET(marker->data[4]) == 0x65) >- continue; /* reject duplicate Adobe */ >-#ifdef NEED_FAR_POINTERS >- /* We could use jpeg_write_marker if the data weren't FAR... */ >- { >- unsigned int i; >- jpeg_write_m_header(dstinfo, marker->marker, marker->data_length); >- for (i = 0; i < marker->data_length; i++) >- jpeg_write_m_byte(dstinfo, marker->data[i]); >- } >-#else >- jpeg_write_marker(dstinfo, marker->marker, >- marker->data, marker->data_length); >-#endif >- } >-} >diff -U8 b/jpeg/transupp.h b/jpeg/transupp.h >--- b/jpeg/transupp.h >+++ b/jpeg/transupp.h >@@ -1,12 +1,12 @@ > /* > * transupp.h > * >- * Copyright (C) 1997, Thomas G. Lane. >+ * Copyright (C) 1997-2009, Thomas G. Lane, Guido Vollbeding. > * This file is part of the Independent JPEG Group's software. > * For conditions of distribution and use, see the accompanying README file. > * > * This file contains declarations for image transformation routines and > * other utility code used by the jpegtran sample application. These are > * NOT part of the core JPEG library. But we keep these routines separate > * from jpegtran.c to ease the task of maintaining jpegtran-like programs > * that have other user interfaces. >@@ -17,42 +17,16 @@ > * jpegtran.c for an example of correct usage. > */ > > /* If you happen not to want the image transform support, disable it here */ > #ifndef TRANSFORMS_SUPPORTED > #define TRANSFORMS_SUPPORTED 1 /* 0 disables transform code */ > #endif > >-/* Short forms of external names for systems with brain-damaged linkers. */ >- >-#ifdef NEED_SHORT_EXTERNAL_NAMES >-#define jtransform_request_workspace jTrRequest >-#define jtransform_adjust_parameters jTrAdjust >-#define jtransform_execute_transformation jTrExec >-#define jcopy_markers_setup jCMrkSetup >-#define jcopy_markers_execute jCMrkExec >-#endif /* NEED_SHORT_EXTERNAL_NAMES */ >- >- >-/* >- * Codes for supported types of image transformations. >- */ >- >-typedef enum { >- JXFORM_NONE, /* no transformation */ >- JXFORM_FLIP_H, /* horizontal flip */ >- JXFORM_FLIP_V, /* vertical flip */ >- JXFORM_TRANSPOSE, /* transpose across UL-to-LR axis */ >- JXFORM_TRANSVERSE, /* transpose across UR-to-LL axis */ >- JXFORM_ROT_90, /* 90-degree clockwise rotation */ >- JXFORM_ROT_180, /* 180-degree rotation */ >- JXFORM_ROT_270 /* 270-degree clockwise (or 90 ccw) */ >-} JXFORM_CODE; >- > /* > * Although rotating and flipping data expressed as DCT coefficients is not > * hard, there is an asymmetry in the JPEG format specification for images > * whose dimensions aren't multiples of the iMCU size. The right and bottom > * image edges are padded out to the next iMCU boundary with junk data; but > * no padding is possible at the top and left edges. If we were to flip > * the whole image including the pad data, then pad garbage would become > * visible at the top and/or left, and real pixels would disappear into the >@@ -70,51 +44,152 @@ > * > * The "trim" option causes untransformable partial iMCUs to be dropped; > * this is not strictly lossless, but it usually gives the best-looking > * result for odd-size images. Note that when this option is active, > * the expected mathematical equivalences between the transforms may not hold. > * (For example, -rot 270 -trim trims only the bottom edge, but -rot 90 -trim > * followed by -rot 180 -trim trims both edges.) > * >+ * We also offer a lossless-crop option, which discards data outside a given >+ * image region but losslessly preserves what is inside. Like the rotate and >+ * flip transforms, lossless crop is restricted by the JPEG format: the upper >+ * left corner of the selected region must fall on an iMCU boundary. If this >+ * does not hold for the given crop parameters, we silently move the upper left >+ * corner up and/or left to make it so, simultaneously increasing the region >+ * dimensions to keep the lower right crop corner unchanged. (Thus, the >+ * output image covers at least the requested region, but may cover more.) >+ * >+ * We also provide a lossless-resize option, which is kind of a lossless-crop >+ * operation in the DCT coefficient block domain - it discards higher-order >+ * coefficients and losslessly preserves lower-order coefficients of a >+ * sub-block. >+ * >+ * Rotate/flip transform, resize, and crop can be requested together in a >+ * single invocation. The crop is applied last --- that is, the crop region >+ * is specified in terms of the destination image after transform/resize. >+ * > * We also offer a "force to grayscale" option, which simply discards the > * chrominance channels of a YCbCr image. This is lossless in the sense that > * the luminance channel is preserved exactly. It's not the same kind of > * thing as the rotate/flip transformations, but it's convenient to handle it > * as part of this package, mainly because the transformation routines have to > * be aware of the option to know how many components to work on. > */ > >+ >+/* Short forms of external names for systems with brain-damaged linkers. */ >+ >+#ifdef NEED_SHORT_EXTERNAL_NAMES >+#define jtransform_parse_crop_spec jTrParCrop >+#define jtransform_request_workspace jTrRequest >+#define jtransform_adjust_parameters jTrAdjust >+#define jtransform_execute_transform jTrExec >+#define jtransform_perfect_transform jTrPerfect >+#define jcopy_markers_setup jCMrkSetup >+#define jcopy_markers_execute jCMrkExec >+#endif /* NEED_SHORT_EXTERNAL_NAMES */ >+ >+ >+/* >+ * Codes for supported types of image transformations. >+ */ >+ >+typedef enum { >+ JXFORM_NONE, /* no transformation */ >+ JXFORM_FLIP_H, /* horizontal flip */ >+ JXFORM_FLIP_V, /* vertical flip */ >+ JXFORM_TRANSPOSE, /* transpose across UL-to-LR axis */ >+ JXFORM_TRANSVERSE, /* transpose across UR-to-LL axis */ >+ JXFORM_ROT_90, /* 90-degree clockwise rotation */ >+ JXFORM_ROT_180, /* 180-degree rotation */ >+ JXFORM_ROT_270 /* 270-degree clockwise (or 90 ccw) */ >+} JXFORM_CODE; >+ >+/* >+ * Codes for crop parameters, which can individually be unspecified, >+ * positive, or negative. (Negative width or height makes no sense, though.) >+ */ >+ >+typedef enum { >+ JCROP_UNSET, >+ JCROP_POS, >+ JCROP_NEG >+} JCROP_CODE; >+ >+/* >+ * Transform parameters struct. >+ * NB: application must not change any elements of this struct after >+ * calling jtransform_request_workspace. >+ */ >+ > typedef struct { > /* Options: set by caller */ > JXFORM_CODE transform; /* image transform operator */ >+ boolean perfect; /* if TRUE, fail if partial MCUs are requested */ > boolean trim; /* if TRUE, trim partial MCUs as needed */ > boolean force_grayscale; /* if TRUE, convert color image to grayscale */ >+ boolean crop; /* if TRUE, crop source image */ >+ >+ /* Crop parameters: application need not set these unless crop is TRUE. >+ * These can be filled in by jtransform_parse_crop_spec(). >+ */ >+ JDIMENSION crop_width; /* Width of selected region */ >+ JCROP_CODE crop_width_set; >+ JDIMENSION crop_height; /* Height of selected region */ >+ JCROP_CODE crop_height_set; >+ JDIMENSION crop_xoffset; /* X offset of selected region */ >+ JCROP_CODE crop_xoffset_set; /* (negative measures from right edge) */ >+ JDIMENSION crop_yoffset; /* Y offset of selected region */ >+ JCROP_CODE crop_yoffset_set; /* (negative measures from bottom edge) */ > > /* Internal workspace: caller should not touch these */ > int num_components; /* # of components in workspace */ > jvirt_barray_ptr * workspace_coef_arrays; /* workspace for transformations */ >+ JDIMENSION output_width; /* cropped destination dimensions */ >+ JDIMENSION output_height; >+ JDIMENSION x_crop_offset; /* destination crop offsets measured in iMCUs */ >+ JDIMENSION y_crop_offset; >+ int iMCU_sample_width; /* destination iMCU size */ >+ int iMCU_sample_height; > } jpeg_transform_info; > > > #if TRANSFORMS_SUPPORTED > >+/* Parse a crop specification (written in X11 geometry style) */ >+EXTERN(boolean) jtransform_parse_crop_spec >+ JPP((jpeg_transform_info *info, const char *spec)); > /* Request any required workspace */ >-EXTERN(void) jtransform_request_workspace >+EXTERN(boolean) jtransform_request_workspace > JPP((j_decompress_ptr srcinfo, jpeg_transform_info *info)); > /* Adjust output image parameters */ > EXTERN(jvirt_barray_ptr *) jtransform_adjust_parameters > JPP((j_decompress_ptr srcinfo, j_compress_ptr dstinfo, > jvirt_barray_ptr *src_coef_arrays, > jpeg_transform_info *info)); > /* Execute the actual transformation, if any */ >-EXTERN(void) jtransform_execute_transformation >+EXTERN(void) jtransform_execute_transform > JPP((j_decompress_ptr srcinfo, j_compress_ptr dstinfo, > jvirt_barray_ptr *src_coef_arrays, > jpeg_transform_info *info)); >+/* Determine whether lossless transformation is perfectly >+ * possible for a specified image and transformation. >+ */ >+EXTERN(boolean) jtransform_perfect_transform >+ JPP((JDIMENSION image_width, JDIMENSION image_height, >+ int MCU_width, int MCU_height, >+ JXFORM_CODE transform)); >+ >+/* jtransform_execute_transform used to be called >+ * jtransform_execute_transformation, but some compilers complain about >+ * routine names that long. This macro is here to avoid breaking any >+ * old source code that uses the original name... >+ */ >+#define jtransform_execute_transformation jtransform_execute_transform > > #endif /* TRANSFORMS_SUPPORTED */ > > > /* > * Support for copying optional markers from source to destination file. > */ > >--- b/jpeg/turbojpeg-mapfile >+++ /dev/null >@@ -1,13 +0,0 @@ >-{ >- global: >- tjInitCompress; >- tjCompress; >- TJBUFSIZE; >- tjInitDecompress; >- tjDecompressHeader; >- tjDecompress; >- tjDestroy; >- tjGetErrorStr; >- local: >- *; >-}; >--- b/jpeg/wrbmp.c >+++ /dev/null >@@ -1,442 +0,0 @@ >-/* >- * wrbmp.c >- * >- * Copyright (C) 1994-1996, Thomas G. Lane. >- * This file is part of the Independent JPEG Group's software. >- * For conditions of distribution and use, see the accompanying README file. >- * >- * This file contains routines to write output images in Microsoft "BMP" >- * format (MS Windows 3.x and OS/2 1.x flavors). >- * Either 8-bit colormapped or 24-bit full-color format can be written. >- * No compression is supported. >- * >- * These routines may need modification for non-Unix environments or >- * specialized applications. As they stand, they assume output to >- * an ordinary stdio stream. >- * >- * This code contributed by James Arthur Boucher. >- */ >- >-#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */ >- >-#ifdef BMP_SUPPORTED >- >- >-/* >- * To support 12-bit JPEG data, we'd have to scale output down to 8 bits. >- * This is not yet implemented. >- */ >- >-#if BITS_IN_JSAMPLE != 8 >- Sorry, this code only copes with 8-bit JSAMPLEs. /* deliberate syntax err */ >-#endif >- >-/* >- * Since BMP stores scanlines bottom-to-top, we have to invert the image >- * from JPEG's top-to-bottom order. To do this, we save the outgoing data >- * in a virtual array during put_pixel_row calls, then actually emit the >- * BMP file during finish_output. The virtual array contains one JSAMPLE per >- * pixel if the output is grayscale or colormapped, three if it is full color. >- */ >- >-/* Private version of data destination object */ >- >-typedef struct { >- struct djpeg_dest_struct pub; /* public fields */ >- >- boolean is_os2; /* saves the OS2 format request flag */ >- >- jvirt_sarray_ptr whole_image; /* needed to reverse row order */ >- JDIMENSION data_width; /* JSAMPLEs per row */ >- JDIMENSION row_width; /* physical width of one row in the BMP file */ >- int pad_bytes; /* number of padding bytes needed per row */ >- JDIMENSION cur_output_row; /* next row# to write to virtual array */ >-} bmp_dest_struct; >- >-typedef bmp_dest_struct * bmp_dest_ptr; >- >- >-/* Forward declarations */ >-LOCAL(void) write_colormap >- JPP((j_decompress_ptr cinfo, bmp_dest_ptr dest, >- int map_colors, int map_entry_size)); >- >- >-/* >- * Write some pixel data. >- * In this module rows_supplied will always be 1. >- */ >- >-METHODDEF(void) >-put_pixel_rows (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo, >- JDIMENSION rows_supplied) >-/* This version is for writing 24-bit pixels */ >-{ >- bmp_dest_ptr dest = (bmp_dest_ptr) dinfo; >- JSAMPARRAY image_ptr; >- register JSAMPROW inptr, outptr; >- register JDIMENSION col; >- int pad; >- >- /* Access next row in virtual array */ >- image_ptr = (*cinfo->mem->access_virt_sarray) >- ((j_common_ptr) cinfo, dest->whole_image, >- dest->cur_output_row, (JDIMENSION) 1, TRUE); >- dest->cur_output_row++; >- >- /* Transfer data. Note destination values must be in BGR order >- * (even though Microsoft's own documents say the opposite). >- */ >- inptr = dest->pub.buffer[0]; >- outptr = image_ptr[0]; >- for (col = cinfo->output_width; col > 0; col--) { >- outptr[2] = *inptr++; /* can omit GETJSAMPLE() safely */ >- outptr[1] = *inptr++; >- outptr[0] = *inptr++; >- outptr += 3; >- } >- >- /* Zero out the pad bytes. */ >- pad = dest->pad_bytes; >- while (--pad >= 0) >- *outptr++ = 0; >-} >- >-METHODDEF(void) >-put_gray_rows (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo, >- JDIMENSION rows_supplied) >-/* This version is for grayscale OR quantized color output */ >-{ >- bmp_dest_ptr dest = (bmp_dest_ptr) dinfo; >- JSAMPARRAY image_ptr; >- register JSAMPROW inptr, outptr; >- register JDIMENSION col; >- int pad; >- >- /* Access next row in virtual array */ >- image_ptr = (*cinfo->mem->access_virt_sarray) >- ((j_common_ptr) cinfo, dest->whole_image, >- dest->cur_output_row, (JDIMENSION) 1, TRUE); >- dest->cur_output_row++; >- >- /* Transfer data. */ >- inptr = dest->pub.buffer[0]; >- outptr = image_ptr[0]; >- for (col = cinfo->output_width; col > 0; col--) { >- *outptr++ = *inptr++; /* can omit GETJSAMPLE() safely */ >- } >- >- /* Zero out the pad bytes. */ >- pad = dest->pad_bytes; >- while (--pad >= 0) >- *outptr++ = 0; >-} >- >- >-/* >- * Startup: normally writes the file header. >- * In this module we may as well postpone everything until finish_output. >- */ >- >-METHODDEF(void) >-start_output_bmp (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo) >-{ >- /* no work here */ >-} >- >- >-/* >- * Finish up at the end of the file. >- * >- * Here is where we really output the BMP file. >- * >- * First, routines to write the Windows and OS/2 variants of the file header. >- */ >- >-LOCAL(void) >-write_bmp_header (j_decompress_ptr cinfo, bmp_dest_ptr dest) >-/* Write a Windows-style BMP file header, including colormap if needed */ >-{ >- char bmpfileheader[14]; >- char bmpinfoheader[40]; >-#define PUT_2B(array,offset,value) \ >- (array[offset] = (char) ((value) & 0xFF), \ >- array[offset+1] = (char) (((value) >> 8) & 0xFF)) >-#define PUT_4B(array,offset,value) \ >- (array[offset] = (char) ((value) & 0xFF), \ >- array[offset+1] = (char) (((value) >> 8) & 0xFF), \ >- array[offset+2] = (char) (((value) >> 16) & 0xFF), \ >- array[offset+3] = (char) (((value) >> 24) & 0xFF)) >- INT32 headersize, bfSize; >- int bits_per_pixel, cmap_entries; >- >- /* Compute colormap size and total file size */ >- if (cinfo->out_color_space == JCS_RGB) { >- if (cinfo->quantize_colors) { >- /* Colormapped RGB */ >- bits_per_pixel = 8; >- cmap_entries = 256; >- } else { >- /* Unquantized, full color RGB */ >- bits_per_pixel = 24; >- cmap_entries = 0; >- } >- } else { >- /* Grayscale output. We need to fake a 256-entry colormap. */ >- bits_per_pixel = 8; >- cmap_entries = 256; >- } >- /* File size */ >- headersize = 14 + 40 + cmap_entries * 4; /* Header and colormap */ >- bfSize = headersize + (INT32) dest->row_width * (INT32) cinfo->output_height; >- >- /* Set unused fields of header to 0 */ >- MEMZERO(bmpfileheader, SIZEOF(bmpfileheader)); >- MEMZERO(bmpinfoheader, SIZEOF(bmpinfoheader)); >- >- /* Fill the file header */ >- bmpfileheader[0] = 0x42; /* first 2 bytes are ASCII 'B', 'M' */ >- bmpfileheader[1] = 0x4D; >- PUT_4B(bmpfileheader, 2, bfSize); /* bfSize */ >- /* we leave bfReserved1 & bfReserved2 = 0 */ >- PUT_4B(bmpfileheader, 10, headersize); /* bfOffBits */ >- >- /* Fill the info header (Microsoft calls this a BITMAPINFOHEADER) */ >- PUT_2B(bmpinfoheader, 0, 40); /* biSize */ >- PUT_4B(bmpinfoheader, 4, cinfo->output_width); /* biWidth */ >- PUT_4B(bmpinfoheader, 8, cinfo->output_height); /* biHeight */ >- PUT_2B(bmpinfoheader, 12, 1); /* biPlanes - must be 1 */ >- PUT_2B(bmpinfoheader, 14, bits_per_pixel); /* biBitCount */ >- /* we leave biCompression = 0, for none */ >- /* we leave biSizeImage = 0; this is correct for uncompressed data */ >- if (cinfo->density_unit == 2) { /* if have density in dots/cm, then */ >- PUT_4B(bmpinfoheader, 24, (INT32) (cinfo->X_density*100)); /* XPels/M */ >- PUT_4B(bmpinfoheader, 28, (INT32) (cinfo->Y_density*100)); /* XPels/M */ >- } >- PUT_2B(bmpinfoheader, 32, cmap_entries); /* biClrUsed */ >- /* we leave biClrImportant = 0 */ >- >- if (JFWRITE(dest->pub.output_file, bmpfileheader, 14) != (size_t) 14) >- ERREXIT(cinfo, JERR_FILE_WRITE); >- if (JFWRITE(dest->pub.output_file, bmpinfoheader, 40) != (size_t) 40) >- ERREXIT(cinfo, JERR_FILE_WRITE); >- >- if (cmap_entries > 0) >- write_colormap(cinfo, dest, cmap_entries, 4); >-} >- >- >-LOCAL(void) >-write_os2_header (j_decompress_ptr cinfo, bmp_dest_ptr dest) >-/* Write an OS2-style BMP file header, including colormap if needed */ >-{ >- char bmpfileheader[14]; >- char bmpcoreheader[12]; >- INT32 headersize, bfSize; >- int bits_per_pixel, cmap_entries; >- >- /* Compute colormap size and total file size */ >- if (cinfo->out_color_space == JCS_RGB) { >- if (cinfo->quantize_colors) { >- /* Colormapped RGB */ >- bits_per_pixel = 8; >- cmap_entries = 256; >- } else { >- /* Unquantized, full color RGB */ >- bits_per_pixel = 24; >- cmap_entries = 0; >- } >- } else { >- /* Grayscale output. We need to fake a 256-entry colormap. */ >- bits_per_pixel = 8; >- cmap_entries = 256; >- } >- /* File size */ >- headersize = 14 + 12 + cmap_entries * 3; /* Header and colormap */ >- bfSize = headersize + (INT32) dest->row_width * (INT32) cinfo->output_height; >- >- /* Set unused fields of header to 0 */ >- MEMZERO(bmpfileheader, SIZEOF(bmpfileheader)); >- MEMZERO(bmpcoreheader, SIZEOF(bmpcoreheader)); >- >- /* Fill the file header */ >- bmpfileheader[0] = 0x42; /* first 2 bytes are ASCII 'B', 'M' */ >- bmpfileheader[1] = 0x4D; >- PUT_4B(bmpfileheader, 2, bfSize); /* bfSize */ >- /* we leave bfReserved1 & bfReserved2 = 0 */ >- PUT_4B(bmpfileheader, 10, headersize); /* bfOffBits */ >- >- /* Fill the info header (Microsoft calls this a BITMAPCOREHEADER) */ >- PUT_2B(bmpcoreheader, 0, 12); /* bcSize */ >- PUT_2B(bmpcoreheader, 4, cinfo->output_width); /* bcWidth */ >- PUT_2B(bmpcoreheader, 6, cinfo->output_height); /* bcHeight */ >- PUT_2B(bmpcoreheader, 8, 1); /* bcPlanes - must be 1 */ >- PUT_2B(bmpcoreheader, 10, bits_per_pixel); /* bcBitCount */ >- >- if (JFWRITE(dest->pub.output_file, bmpfileheader, 14) != (size_t) 14) >- ERREXIT(cinfo, JERR_FILE_WRITE); >- if (JFWRITE(dest->pub.output_file, bmpcoreheader, 12) != (size_t) 12) >- ERREXIT(cinfo, JERR_FILE_WRITE); >- >- if (cmap_entries > 0) >- write_colormap(cinfo, dest, cmap_entries, 3); >-} >- >- >-/* >- * Write the colormap. >- * Windows uses BGR0 map entries; OS/2 uses BGR entries. >- */ >- >-LOCAL(void) >-write_colormap (j_decompress_ptr cinfo, bmp_dest_ptr dest, >- int map_colors, int map_entry_size) >-{ >- JSAMPARRAY colormap = cinfo->colormap; >- int num_colors = cinfo->actual_number_of_colors; >- FILE * outfile = dest->pub.output_file; >- int i; >- >- if (colormap != NULL) { >- if (cinfo->out_color_components == 3) { >- /* Normal case with RGB colormap */ >- for (i = 0; i < num_colors; i++) { >- putc(GETJSAMPLE(colormap[2][i]), outfile); >- putc(GETJSAMPLE(colormap[1][i]), outfile); >- putc(GETJSAMPLE(colormap[0][i]), outfile); >- if (map_entry_size == 4) >- putc(0, outfile); >- } >- } else { >- /* Grayscale colormap (only happens with grayscale quantization) */ >- for (i = 0; i < num_colors; i++) { >- putc(GETJSAMPLE(colormap[0][i]), outfile); >- putc(GETJSAMPLE(colormap[0][i]), outfile); >- putc(GETJSAMPLE(colormap[0][i]), outfile); >- if (map_entry_size == 4) >- putc(0, outfile); >- } >- } >- } else { >- /* If no colormap, must be grayscale data. Generate a linear "map". */ >- for (i = 0; i < 256; i++) { >- putc(i, outfile); >- putc(i, outfile); >- putc(i, outfile); >- if (map_entry_size == 4) >- putc(0, outfile); >- } >- } >- /* Pad colormap with zeros to ensure specified number of colormap entries */ >- if (i > map_colors) >- ERREXIT1(cinfo, JERR_TOO_MANY_COLORS, i); >- for (; i < map_colors; i++) { >- putc(0, outfile); >- putc(0, outfile); >- putc(0, outfile); >- if (map_entry_size == 4) >- putc(0, outfile); >- } >-} >- >- >-METHODDEF(void) >-finish_output_bmp (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo) >-{ >- bmp_dest_ptr dest = (bmp_dest_ptr) dinfo; >- register FILE * outfile = dest->pub.output_file; >- JSAMPARRAY image_ptr; >- register JSAMPROW data_ptr; >- JDIMENSION row; >- register JDIMENSION col; >- cd_progress_ptr progress = (cd_progress_ptr) cinfo->progress; >- >- /* Write the header and colormap */ >- if (dest->is_os2) >- write_os2_header(cinfo, dest); >- else >- write_bmp_header(cinfo, dest); >- >- /* Write the file body from our virtual array */ >- for (row = cinfo->output_height; row > 0; row--) { >- if (progress != NULL) { >- progress->pub.pass_counter = (long) (cinfo->output_height - row); >- progress->pub.pass_limit = (long) cinfo->output_height; >- (*progress->pub.progress_monitor) ((j_common_ptr) cinfo); >- } >- image_ptr = (*cinfo->mem->access_virt_sarray) >- ((j_common_ptr) cinfo, dest->whole_image, row-1, (JDIMENSION) 1, FALSE); >- data_ptr = image_ptr[0]; >- for (col = dest->row_width; col > 0; col--) { >- putc(GETJSAMPLE(*data_ptr), outfile); >- data_ptr++; >- } >- } >- if (progress != NULL) >- progress->completed_extra_passes++; >- >- /* Make sure we wrote the output file OK */ >- fflush(outfile); >- if (ferror(outfile)) >- ERREXIT(cinfo, JERR_FILE_WRITE); >-} >- >- >-/* >- * The module selection routine for BMP format output. >- */ >- >-GLOBAL(djpeg_dest_ptr) >-jinit_write_bmp (j_decompress_ptr cinfo, boolean is_os2) >-{ >- bmp_dest_ptr dest; >- JDIMENSION row_width; >- >- /* Create module interface object, fill in method pointers */ >- dest = (bmp_dest_ptr) >- (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, >- SIZEOF(bmp_dest_struct)); >- dest->pub.start_output = start_output_bmp; >- dest->pub.finish_output = finish_output_bmp; >- dest->is_os2 = is_os2; >- >- if (cinfo->out_color_space == JCS_GRAYSCALE) { >- dest->pub.put_pixel_rows = put_gray_rows; >- } else if (cinfo->out_color_space == JCS_RGB) { >- if (cinfo->quantize_colors) >- dest->pub.put_pixel_rows = put_gray_rows; >- else >- dest->pub.put_pixel_rows = put_pixel_rows; >- } else { >- ERREXIT(cinfo, JERR_BMP_COLORSPACE); >- } >- >- /* Calculate output image dimensions so we can allocate space */ >- jpeg_calc_output_dimensions(cinfo); >- >- /* Determine width of rows in the BMP file (padded to 4-byte boundary). */ >- row_width = cinfo->output_width * cinfo->output_components; >- dest->data_width = row_width; >- while ((row_width & 3) != 0) row_width++; >- dest->row_width = row_width; >- dest->pad_bytes = (int) (row_width - dest->data_width); >- >- /* Allocate space for inversion array, prepare for write pass */ >- dest->whole_image = (*cinfo->mem->request_virt_sarray) >- ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE, >- row_width, cinfo->output_height, (JDIMENSION) 1); >- dest->cur_output_row = 0; >- if (cinfo->progress != NULL) { >- cd_progress_ptr progress = (cd_progress_ptr) cinfo->progress; >- progress->total_extra_passes++; /* count file input as separate pass */ >- } >- >- /* Create decompressor output buffer. */ >- dest->pub.buffer = (*cinfo->mem->alloc_sarray) >- ((j_common_ptr) cinfo, JPOOL_IMAGE, row_width, (JDIMENSION) 1); >- dest->pub.buffer_height = 1; >- >- return (djpeg_dest_ptr) dest; >-} >- >-#endif /* BMP_SUPPORTED */ >--- b/jpeg/wrgif.c >+++ /dev/null >@@ -1,399 +0,0 @@ >-/* >- * wrgif.c >- * >- * Copyright (C) 1991-1997, Thomas G. Lane. >- * This file is part of the Independent JPEG Group's software. >- * For conditions of distribution and use, see the accompanying README file. >- * >- * This file contains routines to write output images in GIF format. >- * >- ************************************************************************** >- * NOTE: to avoid entanglements with Unisys' patent on LZW compression, * >- * this code has been modified to output "uncompressed GIF" files. * >- * There is no trace of the LZW algorithm in this file. * >- ************************************************************************** >- * >- * These routines may need modification for non-Unix environments or >- * specialized applications. As they stand, they assume output to >- * an ordinary stdio stream. >- */ >- >-/* >- * This code is loosely based on ppmtogif from the PBMPLUS distribution >- * of Feb. 1991. That file contains the following copyright notice: >- * Based on GIFENCODE by David Rowley <mgardi@watdscu.waterloo.edu>. >- * Lempel-Ziv compression based on "compress" by Spencer W. Thomas et al. >- * Copyright (C) 1989 by Jef Poskanzer. >- * Permission to use, copy, modify, and distribute this software and its >- * documentation for any purpose and without fee is hereby granted, provided >- * that the above copyright notice appear in all copies and that both that >- * copyright notice and this permission notice appear in supporting >- * documentation. This software is provided "as is" without express or >- * implied warranty. >- * >- * We are also required to state that >- * "The Graphics Interchange Format(c) is the Copyright property of >- * CompuServe Incorporated. GIF(sm) is a Service Mark property of >- * CompuServe Incorporated." >- */ >- >-#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */ >- >-#ifdef GIF_SUPPORTED >- >- >-/* Private version of data destination object */ >- >-typedef struct { >- struct djpeg_dest_struct pub; /* public fields */ >- >- j_decompress_ptr cinfo; /* back link saves passing separate parm */ >- >- /* State for packing variable-width codes into a bitstream */ >- int n_bits; /* current number of bits/code */ >- int maxcode; /* maximum code, given n_bits */ >- INT32 cur_accum; /* holds bits not yet output */ >- int cur_bits; /* # of bits in cur_accum */ >- >- /* State for GIF code assignment */ >- int ClearCode; /* clear code (doesn't change) */ >- int EOFCode; /* EOF code (ditto) */ >- int code_counter; /* counts output symbols */ >- >- /* GIF data packet construction buffer */ >- int bytesinpkt; /* # of bytes in current packet */ >- char packetbuf[256]; /* workspace for accumulating packet */ >- >-} gif_dest_struct; >- >-typedef gif_dest_struct * gif_dest_ptr; >- >-/* Largest value that will fit in N bits */ >-#define MAXCODE(n_bits) ((1 << (n_bits)) - 1) >- >- >-/* >- * Routines to package finished data bytes into GIF data blocks. >- * A data block consists of a count byte (1..255) and that many data bytes. >- */ >- >-LOCAL(void) >-flush_packet (gif_dest_ptr dinfo) >-/* flush any accumulated data */ >-{ >- if (dinfo->bytesinpkt > 0) { /* never write zero-length packet */ >- dinfo->packetbuf[0] = (char) dinfo->bytesinpkt++; >- if (JFWRITE(dinfo->pub.output_file, dinfo->packetbuf, dinfo->bytesinpkt) >- != (size_t) dinfo->bytesinpkt) >- ERREXIT(dinfo->cinfo, JERR_FILE_WRITE); >- dinfo->bytesinpkt = 0; >- } >-} >- >- >-/* Add a character to current packet; flush to disk if necessary */ >-#define CHAR_OUT(dinfo,c) \ >- { (dinfo)->packetbuf[++(dinfo)->bytesinpkt] = (char) (c); \ >- if ((dinfo)->bytesinpkt >= 255) \ >- flush_packet(dinfo); \ >- } >- >- >-/* Routine to convert variable-width codes into a byte stream */ >- >-LOCAL(void) >-output (gif_dest_ptr dinfo, int code) >-/* Emit a code of n_bits bits */ >-/* Uses cur_accum and cur_bits to reblock into 8-bit bytes */ >-{ >- dinfo->cur_accum |= ((INT32) code) << dinfo->cur_bits; >- dinfo->cur_bits += dinfo->n_bits; >- >- while (dinfo->cur_bits >= 8) { >- CHAR_OUT(dinfo, dinfo->cur_accum & 0xFF); >- dinfo->cur_accum >>= 8; >- dinfo->cur_bits -= 8; >- } >-} >- >- >-/* The pseudo-compression algorithm. >- * >- * In this module we simply output each pixel value as a separate symbol; >- * thus, no compression occurs. In fact, there is expansion of one bit per >- * pixel, because we use a symbol width one bit wider than the pixel width. >- * >- * GIF ordinarily uses variable-width symbols, and the decoder will expect >- * to ratchet up the symbol width after a fixed number of symbols. >- * To simplify the logic and keep the expansion penalty down, we emit a >- * GIF Clear code to reset the decoder just before the width would ratchet up. >- * Thus, all the symbols in the output file will have the same bit width. >- * Note that emitting the Clear codes at the right times is a mere matter of >- * counting output symbols and is in no way dependent on the LZW patent. >- * >- * With a small basic pixel width (low color count), Clear codes will be >- * needed very frequently, causing the file to expand even more. So this >- * simplistic approach wouldn't work too well on bilevel images, for example. >- * But for output of JPEG conversions the pixel width will usually be 8 bits >- * (129 to 256 colors), so the overhead added by Clear symbols is only about >- * one symbol in every 256. >- */ >- >-LOCAL(void) >-compress_init (gif_dest_ptr dinfo, int i_bits) >-/* Initialize pseudo-compressor */ >-{ >- /* init all the state variables */ >- dinfo->n_bits = i_bits; >- dinfo->maxcode = MAXCODE(dinfo->n_bits); >- dinfo->ClearCode = (1 << (i_bits - 1)); >- dinfo->EOFCode = dinfo->ClearCode + 1; >- dinfo->code_counter = dinfo->ClearCode + 2; >- /* init output buffering vars */ >- dinfo->bytesinpkt = 0; >- dinfo->cur_accum = 0; >- dinfo->cur_bits = 0; >- /* GIF specifies an initial Clear code */ >- output(dinfo, dinfo->ClearCode); >-} >- >- >-LOCAL(void) >-compress_pixel (gif_dest_ptr dinfo, int c) >-/* Accept and "compress" one pixel value. >- * The given value must be less than n_bits wide. >- */ >-{ >- /* Output the given pixel value as a symbol. */ >- output(dinfo, c); >- /* Issue Clear codes often enough to keep the reader from ratcheting up >- * its symbol size. >- */ >- if (dinfo->code_counter < dinfo->maxcode) { >- dinfo->code_counter++; >- } else { >- output(dinfo, dinfo->ClearCode); >- dinfo->code_counter = dinfo->ClearCode + 2; /* reset the counter */ >- } >-} >- >- >-LOCAL(void) >-compress_term (gif_dest_ptr dinfo) >-/* Clean up at end */ >-{ >- /* Send an EOF code */ >- output(dinfo, dinfo->EOFCode); >- /* Flush the bit-packing buffer */ >- if (dinfo->cur_bits > 0) { >- CHAR_OUT(dinfo, dinfo->cur_accum & 0xFF); >- } >- /* Flush the packet buffer */ >- flush_packet(dinfo); >-} >- >- >-/* GIF header construction */ >- >- >-LOCAL(void) >-put_word (gif_dest_ptr dinfo, unsigned int w) >-/* Emit a 16-bit word, LSB first */ >-{ >- putc(w & 0xFF, dinfo->pub.output_file); >- putc((w >> 8) & 0xFF, dinfo->pub.output_file); >-} >- >- >-LOCAL(void) >-put_3bytes (gif_dest_ptr dinfo, int val) >-/* Emit 3 copies of same byte value --- handy subr for colormap construction */ >-{ >- putc(val, dinfo->pub.output_file); >- putc(val, dinfo->pub.output_file); >- putc(val, dinfo->pub.output_file); >-} >- >- >-LOCAL(void) >-emit_header (gif_dest_ptr dinfo, int num_colors, JSAMPARRAY colormap) >-/* Output the GIF file header, including color map */ >-/* If colormap==NULL, synthesize a gray-scale colormap */ >-{ >- int BitsPerPixel, ColorMapSize, InitCodeSize, FlagByte; >- int cshift = dinfo->cinfo->data_precision - 8; >- int i; >- >- if (num_colors > 256) >- ERREXIT1(dinfo->cinfo, JERR_TOO_MANY_COLORS, num_colors); >- /* Compute bits/pixel and related values */ >- BitsPerPixel = 1; >- while (num_colors > (1 << BitsPerPixel)) >- BitsPerPixel++; >- ColorMapSize = 1 << BitsPerPixel; >- if (BitsPerPixel <= 1) >- InitCodeSize = 2; >- else >- InitCodeSize = BitsPerPixel; >- /* >- * Write the GIF header. >- * Note that we generate a plain GIF87 header for maximum compatibility. >- */ >- putc('G', dinfo->pub.output_file); >- putc('I', dinfo->pub.output_file); >- putc('F', dinfo->pub.output_file); >- putc('8', dinfo->pub.output_file); >- putc('7', dinfo->pub.output_file); >- putc('a', dinfo->pub.output_file); >- /* Write the Logical Screen Descriptor */ >- put_word(dinfo, (unsigned int) dinfo->cinfo->output_width); >- put_word(dinfo, (unsigned int) dinfo->cinfo->output_height); >- FlagByte = 0x80; /* Yes, there is a global color table */ >- FlagByte |= (BitsPerPixel-1) << 4; /* color resolution */ >- FlagByte |= (BitsPerPixel-1); /* size of global color table */ >- putc(FlagByte, dinfo->pub.output_file); >- putc(0, dinfo->pub.output_file); /* Background color index */ >- putc(0, dinfo->pub.output_file); /* Reserved (aspect ratio in GIF89) */ >- /* Write the Global Color Map */ >- /* If the color map is more than 8 bits precision, */ >- /* we reduce it to 8 bits by shifting */ >- for (i=0; i < ColorMapSize; i++) { >- if (i < num_colors) { >- if (colormap != NULL) { >- if (dinfo->cinfo->out_color_space == JCS_RGB) { >- /* Normal case: RGB color map */ >- putc(GETJSAMPLE(colormap[0][i]) >> cshift, dinfo->pub.output_file); >- putc(GETJSAMPLE(colormap[1][i]) >> cshift, dinfo->pub.output_file); >- putc(GETJSAMPLE(colormap[2][i]) >> cshift, dinfo->pub.output_file); >- } else { >- /* Grayscale "color map": possible if quantizing grayscale image */ >- put_3bytes(dinfo, GETJSAMPLE(colormap[0][i]) >> cshift); >- } >- } else { >- /* Create a gray-scale map of num_colors values, range 0..255 */ >- put_3bytes(dinfo, (i * 255 + (num_colors-1)/2) / (num_colors-1)); >- } >- } else { >- /* fill out the map to a power of 2 */ >- put_3bytes(dinfo, 0); >- } >- } >- /* Write image separator and Image Descriptor */ >- putc(',', dinfo->pub.output_file); /* separator */ >- put_word(dinfo, 0); /* left/top offset */ >- put_word(dinfo, 0); >- put_word(dinfo, (unsigned int) dinfo->cinfo->output_width); /* image size */ >- put_word(dinfo, (unsigned int) dinfo->cinfo->output_height); >- /* flag byte: not interlaced, no local color map */ >- putc(0x00, dinfo->pub.output_file); >- /* Write Initial Code Size byte */ >- putc(InitCodeSize, dinfo->pub.output_file); >- >- /* Initialize for "compression" of image data */ >- compress_init(dinfo, InitCodeSize+1); >-} >- >- >-/* >- * Startup: write the file header. >- */ >- >-METHODDEF(void) >-start_output_gif (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo) >-{ >- gif_dest_ptr dest = (gif_dest_ptr) dinfo; >- >- if (cinfo->quantize_colors) >- emit_header(dest, cinfo->actual_number_of_colors, cinfo->colormap); >- else >- emit_header(dest, 256, (JSAMPARRAY) NULL); >-} >- >- >-/* >- * Write some pixel data. >- * In this module rows_supplied will always be 1. >- */ >- >-METHODDEF(void) >-put_pixel_rows (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo, >- JDIMENSION rows_supplied) >-{ >- gif_dest_ptr dest = (gif_dest_ptr) dinfo; >- register JSAMPROW ptr; >- register JDIMENSION col; >- >- ptr = dest->pub.buffer[0]; >- for (col = cinfo->output_width; col > 0; col--) { >- compress_pixel(dest, GETJSAMPLE(*ptr++)); >- } >-} >- >- >-/* >- * Finish up at the end of the file. >- */ >- >-METHODDEF(void) >-finish_output_gif (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo) >-{ >- gif_dest_ptr dest = (gif_dest_ptr) dinfo; >- >- /* Flush "compression" mechanism */ >- compress_term(dest); >- /* Write a zero-length data block to end the series */ >- putc(0, dest->pub.output_file); >- /* Write the GIF terminator mark */ >- putc(';', dest->pub.output_file); >- /* Make sure we wrote the output file OK */ >- fflush(dest->pub.output_file); >- if (ferror(dest->pub.output_file)) >- ERREXIT(cinfo, JERR_FILE_WRITE); >-} >- >- >-/* >- * The module selection routine for GIF format output. >- */ >- >-GLOBAL(djpeg_dest_ptr) >-jinit_write_gif (j_decompress_ptr cinfo) >-{ >- gif_dest_ptr dest; >- >- /* Create module interface object, fill in method pointers */ >- dest = (gif_dest_ptr) >- (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, >- SIZEOF(gif_dest_struct)); >- dest->cinfo = cinfo; /* make back link for subroutines */ >- dest->pub.start_output = start_output_gif; >- dest->pub.put_pixel_rows = put_pixel_rows; >- dest->pub.finish_output = finish_output_gif; >- >- if (cinfo->out_color_space != JCS_GRAYSCALE && >- cinfo->out_color_space != JCS_RGB) >- ERREXIT(cinfo, JERR_GIF_COLORSPACE); >- >- /* Force quantization if color or if > 8 bits input */ >- if (cinfo->out_color_space != JCS_GRAYSCALE || cinfo->data_precision > 8) { >- /* Force quantization to at most 256 colors */ >- cinfo->quantize_colors = TRUE; >- if (cinfo->desired_number_of_colors > 256) >- cinfo->desired_number_of_colors = 256; >- } >- >- /* Calculate output image dimensions so we can allocate space */ >- jpeg_calc_output_dimensions(cinfo); >- >- if (cinfo->output_components != 1) /* safety check: just one component? */ >- ERREXIT(cinfo, JERR_GIF_BUG); >- >- /* Create decompressor output buffer. */ >- dest->pub.buffer = (*cinfo->mem->alloc_sarray) >- ((j_common_ptr) cinfo, JPOOL_IMAGE, cinfo->output_width, (JDIMENSION) 1); >- dest->pub.buffer_height = 1; >- >- return (djpeg_dest_ptr) dest; >-} >- >-#endif /* GIF_SUPPORTED */ >--- b/jpeg/wrjpgcom.1 >+++ /dev/null >@@ -1,103 +0,0 @@ >-.TH WRJPGCOM 1 "15 June 1995" >-.SH NAME >-wrjpgcom \- insert text comments into a JPEG file >-.SH SYNOPSIS >-.B wrjpgcom >-[ >-.B \-replace >-] >-[ >-.BI \-comment " text" >-] >-[ >-.BI \-cfile " name" >-] >-[ >-.I filename >-] >-.LP >-.SH DESCRIPTION >-.LP >-.B wrjpgcom >-reads the named JPEG/JFIF file, or the standard input if no file is named, >-and generates a new JPEG/JFIF file on standard output. A comment block is >-added to the file. >-.PP >-The JPEG standard allows "comment" (COM) blocks to occur within a JPEG file. >-Although the standard doesn't actually define what COM blocks are for, they >-are widely used to hold user-supplied text strings. This lets you add >-annotations, titles, index terms, etc to your JPEG files, and later retrieve >-them as text. COM blocks do not interfere with the image stored in the JPEG >-file. The maximum size of a COM block is 64K, but you can have as many of >-them as you like in one JPEG file. >-.PP >-.B wrjpgcom >-adds a COM block, containing text you provide, to a JPEG file. >-Ordinarily, the COM block is added after any existing COM blocks; but you >-can delete the old COM blocks if you wish. >-.SH OPTIONS >-Switch names may be abbreviated, and are not case sensitive. >-.TP >-.B \-replace >-Delete any existing COM blocks from the file. >-.TP >-.BI \-comment " text" >-Supply text for new COM block on command line. >-.TP >-.BI \-cfile " name" >-Read text for new COM block from named file. >-.PP >-If you have only one line of comment text to add, you can provide it on the >-command line with >-.BR \-comment . >-The comment text must be surrounded with quotes so that it is treated as a >-single argument. Longer comments can be read from a text file. >-.PP >-If you give neither >-.B \-comment >-nor >-.BR \-cfile , >-then >-.B wrjpgcom >-will read the comment text from standard input. (In this case an input image >-file name MUST be supplied, so that the source JPEG file comes from somewhere >-else.) You can enter multiple lines, up to 64KB worth. Type an end-of-file >-indicator (usually control-D) to terminate the comment text entry. >-.PP >-.B wrjpgcom >-will not add a COM block if the provided comment string is empty. Therefore >-\fB\-replace \-comment ""\fR can be used to delete all COM blocks from a file. >-.SH EXAMPLES >-.LP >-Add a short comment to in.jpg, producing out.jpg: >-.IP >-.B wrjpgcom \-c >-\fI"View of my back yard" in.jpg >-.B > >-.I out.jpg >-.PP >-Attach a long comment previously stored in comment.txt: >-.IP >-.B wrjpgcom >-.I in.jpg >-.B < >-.I comment.txt >-.B > >-.I out.jpg >-.PP >-or equivalently >-.IP >-.B wrjpgcom >-.B -cfile >-.I comment.txt >-.B < >-.I in.jpg >-.B > >-.I out.jpg >-.SH SEE ALSO >-.BR cjpeg (1), >-.BR djpeg (1), >-.BR jpegtran (1), >-.BR rdjpgcom (1) >-.SH AUTHOR >-Independent JPEG Group >--- b/jpeg/wrjpgcom.c >+++ /dev/null >@@ -1,583 +0,0 @@ >-/* >- * wrjpgcom.c >- * >- * Copyright (C) 1994-1997, Thomas G. Lane. >- * This file is part of the Independent JPEG Group's software. >- * For conditions of distribution and use, see the accompanying README file. >- * >- * This file contains a very simple stand-alone application that inserts >- * user-supplied text as a COM (comment) marker in a JFIF file. >- * This may be useful as an example of the minimum logic needed to parse >- * JPEG markers. >- */ >- >-#define JPEG_CJPEG_DJPEG /* to get the command-line config symbols */ >-#include "jinclude.h" /* get auto-config symbols, <stdio.h> */ >- >-#ifndef HAVE_STDLIB_H /* <stdlib.h> should declare malloc() */ >-extern void * malloc (); >-#endif >-#include <ctype.h> /* to declare isupper(), tolower() */ >-#ifdef USE_SETMODE >-#include <fcntl.h> /* to declare setmode()'s parameter macros */ >-/* If you have setmode() but not <io.h>, just delete this line: */ >-#include <io.h> /* to declare setmode() */ >-#endif >- >-#ifdef USE_CCOMMAND /* command-line reader for Macintosh */ >-#ifdef __MWERKS__ >-#include <SIOUX.h> /* Metrowerks needs this */ >-#include <console.h> /* ... and this */ >-#endif >-#ifdef THINK_C >-#include <console.h> /* Think declares it here */ >-#endif >-#endif >- >-#ifdef DONT_USE_B_MODE /* define mode parameters for fopen() */ >-#define READ_BINARY "r" >-#define WRITE_BINARY "w" >-#else >-#ifdef VMS /* VMS is very nonstandard */ >-#define READ_BINARY "rb", "ctx=stm" >-#define WRITE_BINARY "wb", "ctx=stm" >-#else /* standard ANSI-compliant case */ >-#define READ_BINARY "rb" >-#define WRITE_BINARY "wb" >-#endif >-#endif >- >-#ifndef EXIT_FAILURE /* define exit() codes if not provided */ >-#define EXIT_FAILURE 1 >-#endif >-#ifndef EXIT_SUCCESS >-#ifdef VMS >-#define EXIT_SUCCESS 1 /* VMS is very nonstandard */ >-#else >-#define EXIT_SUCCESS 0 >-#endif >-#endif >- >-/* Reduce this value if your malloc() can't allocate blocks up to 64K. >- * On DOS, compiling in large model is usually a better solution. >- */ >- >-#ifndef MAX_COM_LENGTH >-#define MAX_COM_LENGTH 65000L /* must be <= 65533 in any case */ >-#endif >- >- >-/* >- * These macros are used to read the input file and write the output file. >- * To reuse this code in another application, you might need to change these. >- */ >- >-static FILE * infile; /* input JPEG file */ >- >-/* Return next input byte, or EOF if no more */ >-#define NEXTBYTE() getc(infile) >- >-static FILE * outfile; /* output JPEG file */ >- >-/* Emit an output byte */ >-#define PUTBYTE(x) putc((x), outfile) >- >- >-/* Error exit handler */ >-#define ERREXIT(msg) (fprintf(stderr, "%s\n", msg), exit(EXIT_FAILURE)) >- >- >-/* Read one byte, testing for EOF */ >-static int >-read_1_byte (void) >-{ >- int c; >- >- c = NEXTBYTE(); >- if (c == EOF) >- ERREXIT("Premature EOF in JPEG file"); >- return c; >-} >- >-/* Read 2 bytes, convert to unsigned int */ >-/* All 2-byte quantities in JPEG markers are MSB first */ >-static unsigned int >-read_2_bytes (void) >-{ >- int c1, c2; >- >- c1 = NEXTBYTE(); >- if (c1 == EOF) >- ERREXIT("Premature EOF in JPEG file"); >- c2 = NEXTBYTE(); >- if (c2 == EOF) >- ERREXIT("Premature EOF in JPEG file"); >- return (((unsigned int) c1) << 8) + ((unsigned int) c2); >-} >- >- >-/* Routines to write data to output file */ >- >-static void >-write_1_byte (int c) >-{ >- PUTBYTE(c); >-} >- >-static void >-write_2_bytes (unsigned int val) >-{ >- PUTBYTE((val >> 8) & 0xFF); >- PUTBYTE(val & 0xFF); >-} >- >-static void >-write_marker (int marker) >-{ >- PUTBYTE(0xFF); >- PUTBYTE(marker); >-} >- >-static void >-copy_rest_of_file (void) >-{ >- int c; >- >- while ((c = NEXTBYTE()) != EOF) >- PUTBYTE(c); >-} >- >- >-/* >- * JPEG markers consist of one or more 0xFF bytes, followed by a marker >- * code byte (which is not an FF). Here are the marker codes of interest >- * in this program. (See jdmarker.c for a more complete list.) >- */ >- >-#define M_SOF0 0xC0 /* Start Of Frame N */ >-#define M_SOF1 0xC1 /* N indicates which compression process */ >-#define M_SOF2 0xC2 /* Only SOF0-SOF2 are now in common use */ >-#define M_SOF3 0xC3 >-#define M_SOF5 0xC5 /* NB: codes C4 and CC are NOT SOF markers */ >-#define M_SOF6 0xC6 >-#define M_SOF7 0xC7 >-#define M_SOF9 0xC9 >-#define M_SOF10 0xCA >-#define M_SOF11 0xCB >-#define M_SOF13 0xCD >-#define M_SOF14 0xCE >-#define M_SOF15 0xCF >-#define M_SOI 0xD8 /* Start Of Image (beginning of datastream) */ >-#define M_EOI 0xD9 /* End Of Image (end of datastream) */ >-#define M_SOS 0xDA /* Start Of Scan (begins compressed data) */ >-#define M_COM 0xFE /* COMment */ >- >- >-/* >- * Find the next JPEG marker and return its marker code. >- * We expect at least one FF byte, possibly more if the compressor used FFs >- * to pad the file. (Padding FFs will NOT be replicated in the output file.) >- * There could also be non-FF garbage between markers. The treatment of such >- * garbage is unspecified; we choose to skip over it but emit a warning msg. >- * NB: this routine must not be used after seeing SOS marker, since it will >- * not deal correctly with FF/00 sequences in the compressed image data... >- */ >- >-static int >-next_marker (void) >-{ >- int c; >- int discarded_bytes = 0; >- >- /* Find 0xFF byte; count and skip any non-FFs. */ >- c = read_1_byte(); >- while (c != 0xFF) { >- discarded_bytes++; >- c = read_1_byte(); >- } >- /* Get marker code byte, swallowing any duplicate FF bytes. Extra FFs >- * are legal as pad bytes, so don't count them in discarded_bytes. >- */ >- do { >- c = read_1_byte(); >- } while (c == 0xFF); >- >- if (discarded_bytes != 0) { >- fprintf(stderr, "Warning: garbage data found in JPEG file\n"); >- } >- >- return c; >-} >- >- >-/* >- * Read the initial marker, which should be SOI. >- * For a JFIF file, the first two bytes of the file should be literally >- * 0xFF M_SOI. To be more general, we could use next_marker, but if the >- * input file weren't actually JPEG at all, next_marker might read the whole >- * file and then return a misleading error message... >- */ >- >-static int >-first_marker (void) >-{ >- int c1, c2; >- >- c1 = NEXTBYTE(); >- c2 = NEXTBYTE(); >- if (c1 != 0xFF || c2 != M_SOI) >- ERREXIT("Not a JPEG file"); >- return c2; >-} >- >- >-/* >- * Most types of marker are followed by a variable-length parameter segment. >- * This routine skips over the parameters for any marker we don't otherwise >- * want to process. >- * Note that we MUST skip the parameter segment explicitly in order not to >- * be fooled by 0xFF bytes that might appear within the parameter segment; >- * such bytes do NOT introduce new markers. >- */ >- >-static void >-copy_variable (void) >-/* Copy an unknown or uninteresting variable-length marker */ >-{ >- unsigned int length; >- >- /* Get the marker parameter length count */ >- length = read_2_bytes(); >- write_2_bytes(length); >- /* Length includes itself, so must be at least 2 */ >- if (length < 2) >- ERREXIT("Erroneous JPEG marker length"); >- length -= 2; >- /* Skip over the remaining bytes */ >- while (length > 0) { >- write_1_byte(read_1_byte()); >- length--; >- } >-} >- >-static void >-skip_variable (void) >-/* Skip over an unknown or uninteresting variable-length marker */ >-{ >- unsigned int length; >- >- /* Get the marker parameter length count */ >- length = read_2_bytes(); >- /* Length includes itself, so must be at least 2 */ >- if (length < 2) >- ERREXIT("Erroneous JPEG marker length"); >- length -= 2; >- /* Skip over the remaining bytes */ >- while (length > 0) { >- (void) read_1_byte(); >- length--; >- } >-} >- >- >-/* >- * Parse the marker stream until SOFn or EOI is seen; >- * copy data to output, but discard COM markers unless keep_COM is true. >- */ >- >-static int >-scan_JPEG_header (int keep_COM) >-{ >- int marker; >- >- /* Expect SOI at start of file */ >- if (first_marker() != M_SOI) >- ERREXIT("Expected SOI marker first"); >- write_marker(M_SOI); >- >- /* Scan miscellaneous markers until we reach SOFn. */ >- for (;;) { >- marker = next_marker(); >- switch (marker) { >- /* Note that marker codes 0xC4, 0xC8, 0xCC are not, and must not be, >- * treated as SOFn. C4 in particular is actually DHT. >- */ >- case M_SOF0: /* Baseline */ >- case M_SOF1: /* Extended sequential, Huffman */ >- case M_SOF2: /* Progressive, Huffman */ >- case M_SOF3: /* Lossless, Huffman */ >- case M_SOF5: /* Differential sequential, Huffman */ >- case M_SOF6: /* Differential progressive, Huffman */ >- case M_SOF7: /* Differential lossless, Huffman */ >- case M_SOF9: /* Extended sequential, arithmetic */ >- case M_SOF10: /* Progressive, arithmetic */ >- case M_SOF11: /* Lossless, arithmetic */ >- case M_SOF13: /* Differential sequential, arithmetic */ >- case M_SOF14: /* Differential progressive, arithmetic */ >- case M_SOF15: /* Differential lossless, arithmetic */ >- return marker; >- >- case M_SOS: /* should not see compressed data before SOF */ >- ERREXIT("SOS without prior SOFn"); >- break; >- >- case M_EOI: /* in case it's a tables-only JPEG stream */ >- return marker; >- >- case M_COM: /* Existing COM: conditionally discard */ >- if (keep_COM) { >- write_marker(marker); >- copy_variable(); >- } else { >- skip_variable(); >- } >- break; >- >- default: /* Anything else just gets copied */ >- write_marker(marker); >- copy_variable(); /* we assume it has a parameter count... */ >- break; >- } >- } /* end loop */ >-} >- >- >-/* Command line parsing code */ >- >-static const char * progname; /* program name for error messages */ >- >- >-static void >-usage (void) >-/* complain about bad command line */ >-{ >- fprintf(stderr, "wrjpgcom inserts a textual comment in a JPEG file.\n"); >- fprintf(stderr, "You can add to or replace any existing comment(s).\n"); >- >- fprintf(stderr, "Usage: %s [switches] ", progname); >-#ifdef TWO_FILE_COMMANDLINE >- fprintf(stderr, "inputfile outputfile\n"); >-#else >- fprintf(stderr, "[inputfile]\n"); >-#endif >- >- fprintf(stderr, "Switches (names may be abbreviated):\n"); >- fprintf(stderr, " -replace Delete any existing comments\n"); >- fprintf(stderr, " -comment \"text\" Insert comment with given text\n"); >- fprintf(stderr, " -cfile name Read comment from named file\n"); >- fprintf(stderr, "Notice that you must put quotes around the comment text\n"); >- fprintf(stderr, "when you use -comment.\n"); >- fprintf(stderr, "If you do not give either -comment or -cfile on the command line,\n"); >- fprintf(stderr, "then the comment text is read from standard input.\n"); >- fprintf(stderr, "It can be multiple lines, up to %u characters total.\n", >- (unsigned int) MAX_COM_LENGTH); >-#ifndef TWO_FILE_COMMANDLINE >- fprintf(stderr, "You must specify an input JPEG file name when supplying\n"); >- fprintf(stderr, "comment text from standard input.\n"); >-#endif >- >- exit(EXIT_FAILURE); >-} >- >- >-static int >-keymatch (char * arg, const char * keyword, int minchars) >-/* Case-insensitive matching of (possibly abbreviated) keyword switches. */ >-/* keyword is the constant keyword (must be lower case already), */ >-/* minchars is length of minimum legal abbreviation. */ >-{ >- register int ca, ck; >- register int nmatched = 0; >- >- while ((ca = *arg++) != '\0') { >- if ((ck = *keyword++) == '\0') >- return 0; /* arg longer than keyword, no good */ >- if (isupper(ca)) /* force arg to lcase (assume ck is already) */ >- ca = tolower(ca); >- if (ca != ck) >- return 0; /* no good */ >- nmatched++; /* count matched characters */ >- } >- /* reached end of argument; fail if it's too short for unique abbrev */ >- if (nmatched < minchars) >- return 0; >- return 1; /* A-OK */ >-} >- >- >-/* >- * The main program. >- */ >- >-int >-main (int argc, char **argv) >-{ >- int argn; >- char * arg; >- int keep_COM = 1; >- char * comment_arg = NULL; >- FILE * comment_file = NULL; >- unsigned int comment_length = 0; >- int marker; >- >- /* On Mac, fetch a command line. */ >-#ifdef USE_CCOMMAND >- argc = ccommand(&argv); >-#endif >- >- progname = argv[0]; >- if (progname == NULL || progname[0] == 0) >- progname = "wrjpgcom"; /* in case C library doesn't provide it */ >- >- /* Parse switches, if any */ >- for (argn = 1; argn < argc; argn++) { >- arg = argv[argn]; >- if (arg[0] != '-') >- break; /* not switch, must be file name */ >- arg++; /* advance over '-' */ >- if (keymatch(arg, "replace", 1)) { >- keep_COM = 0; >- } else if (keymatch(arg, "cfile", 2)) { >- if (++argn >= argc) usage(); >- if ((comment_file = fopen(argv[argn], "r")) == NULL) { >- fprintf(stderr, "%s: can't open %s\n", progname, argv[argn]); >- exit(EXIT_FAILURE); >- } >- } else if (keymatch(arg, "comment", 1)) { >- if (++argn >= argc) usage(); >- comment_arg = argv[argn]; >- /* If the comment text starts with '"', then we are probably running >- * under MS-DOG and must parse out the quoted string ourselves. Sigh. >- */ >- if (comment_arg[0] == '"') { >- comment_arg = (char *) malloc((size_t) MAX_COM_LENGTH); >- if (comment_arg == NULL) >- ERREXIT("Insufficient memory"); >- strcpy(comment_arg, argv[argn]+1); >- for (;;) { >- comment_length = (unsigned int) strlen(comment_arg); >- if (comment_length > 0 && comment_arg[comment_length-1] == '"') { >- comment_arg[comment_length-1] = '\0'; /* zap terminating quote */ >- break; >- } >- if (++argn >= argc) >- ERREXIT("Missing ending quote mark"); >- strcat(comment_arg, " "); >- strcat(comment_arg, argv[argn]); >- } >- } >- comment_length = (unsigned int) strlen(comment_arg); >- } else >- usage(); >- } >- >- /* Cannot use both -comment and -cfile. */ >- if (comment_arg != NULL && comment_file != NULL) >- usage(); >- /* If there is neither -comment nor -cfile, we will read the comment text >- * from stdin; in this case there MUST be an input JPEG file name. >- */ >- if (comment_arg == NULL && comment_file == NULL && argn >= argc) >- usage(); >- >- /* Open the input file. */ >- if (argn < argc) { >- if ((infile = fopen(argv[argn], READ_BINARY)) == NULL) { >- fprintf(stderr, "%s: can't open %s\n", progname, argv[argn]); >- exit(EXIT_FAILURE); >- } >- } else { >- /* default input file is stdin */ >-#ifdef USE_SETMODE /* need to hack file mode? */ >- setmode(fileno(stdin), O_BINARY); >-#endif >-#ifdef USE_FDOPEN /* need to re-open in binary mode? */ >- if ((infile = fdopen(fileno(stdin), READ_BINARY)) == NULL) { >- fprintf(stderr, "%s: can't open stdin\n", progname); >- exit(EXIT_FAILURE); >- } >-#else >- infile = stdin; >-#endif >- } >- >- /* Open the output file. */ >-#ifdef TWO_FILE_COMMANDLINE >- /* Must have explicit output file name */ >- if (argn != argc-2) { >- fprintf(stderr, "%s: must name one input and one output file\n", >- progname); >- usage(); >- } >- if ((outfile = fopen(argv[argn+1], WRITE_BINARY)) == NULL) { >- fprintf(stderr, "%s: can't open %s\n", progname, argv[argn+1]); >- exit(EXIT_FAILURE); >- } >-#else >- /* Unix style: expect zero or one file name */ >- if (argn < argc-1) { >- fprintf(stderr, "%s: only one input file\n", progname); >- usage(); >- } >- /* default output file is stdout */ >-#ifdef USE_SETMODE /* need to hack file mode? */ >- setmode(fileno(stdout), O_BINARY); >-#endif >-#ifdef USE_FDOPEN /* need to re-open in binary mode? */ >- if ((outfile = fdopen(fileno(stdout), WRITE_BINARY)) == NULL) { >- fprintf(stderr, "%s: can't open stdout\n", progname); >- exit(EXIT_FAILURE); >- } >-#else >- outfile = stdout; >-#endif >-#endif /* TWO_FILE_COMMANDLINE */ >- >- /* Collect comment text from comment_file or stdin, if necessary */ >- if (comment_arg == NULL) { >- FILE * src_file; >- int c; >- >- comment_arg = (char *) malloc((size_t) MAX_COM_LENGTH); >- if (comment_arg == NULL) >- ERREXIT("Insufficient memory"); >- comment_length = 0; >- src_file = (comment_file != NULL ? comment_file : stdin); >- while ((c = getc(src_file)) != EOF) { >- if (comment_length >= (unsigned int) MAX_COM_LENGTH) { >- fprintf(stderr, "Comment text may not exceed %u bytes\n", >- (unsigned int) MAX_COM_LENGTH); >- exit(EXIT_FAILURE); >- } >- comment_arg[comment_length++] = (char) c; >- } >- if (comment_file != NULL) >- fclose(comment_file); >- } >- >- /* Copy JPEG headers until SOFn marker; >- * we will insert the new comment marker just before SOFn. >- * This (a) causes the new comment to appear after, rather than before, >- * existing comments; and (b) ensures that comments come after any JFIF >- * or JFXX markers, as required by the JFIF specification. >- */ >- marker = scan_JPEG_header(keep_COM); >- /* Insert the new COM marker, but only if nonempty text has been supplied */ >- if (comment_length > 0) { >- write_marker(M_COM); >- write_2_bytes(comment_length + 2); >- while (comment_length > 0) { >- write_1_byte(*comment_arg++); >- comment_length--; >- } >- } >- /* Duplicate the remainder of the source file. >- * Note that any COM markers occuring after SOF will not be touched. >- */ >- write_marker(marker); >- copy_rest_of_file(); >- >- /* All done. */ >- exit(EXIT_SUCCESS); >- return 0; /* suppress no-return-value warnings */ >-} >--- b/jpeg/wrppm.c >+++ /dev/null >@@ -1,268 +0,0 @@ >-/* >- * wrppm.c >- * >- * Copyright (C) 1991-1996, Thomas G. Lane. >- * This file is part of the Independent JPEG Group's software. >- * For conditions of distribution and use, see the accompanying README file. >- * >- * This file contains routines to write output images in PPM/PGM format. >- * The extended 2-byte-per-sample raw PPM/PGM formats are supported. >- * The PBMPLUS library is NOT required to compile this software >- * (but it is highly useful as a set of PPM image manipulation programs). >- * >- * These routines may need modification for non-Unix environments or >- * specialized applications. As they stand, they assume output to >- * an ordinary stdio stream. >- */ >- >-#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */ >- >-#ifdef PPM_SUPPORTED >- >- >-/* >- * For 12-bit JPEG data, we either downscale the values to 8 bits >- * (to write standard byte-per-sample PPM/PGM files), or output >- * nonstandard word-per-sample PPM/PGM files. Downscaling is done >- * if PPM_NORAWWORD is defined (this can be done in the Makefile >- * or in jconfig.h). >- * (When the core library supports data precision reduction, a cleaner >- * implementation will be to ask for that instead.) >- */ >- >-#if BITS_IN_JSAMPLE == 8 >-#define PUTPPMSAMPLE(ptr,v) *ptr++ = (char) (v) >-#define BYTESPERSAMPLE 1 >-#define PPM_MAXVAL 255 >-#else >-#ifdef PPM_NORAWWORD >-#define PUTPPMSAMPLE(ptr,v) *ptr++ = (char) ((v) >> (BITS_IN_JSAMPLE-8)) >-#define BYTESPERSAMPLE 1 >-#define PPM_MAXVAL 255 >-#else >-/* The word-per-sample format always puts the LSB first. */ >-#define PUTPPMSAMPLE(ptr,v) \ >- { register int val_ = v; \ >- *ptr++ = (char) (val_ & 0xFF); \ >- *ptr++ = (char) ((val_ >> 8) & 0xFF); \ >- } >-#define BYTESPERSAMPLE 2 >-#define PPM_MAXVAL ((1<<BITS_IN_JSAMPLE)-1) >-#endif >-#endif >- >- >-/* >- * When JSAMPLE is the same size as char, we can just fwrite() the >- * decompressed data to the PPM or PGM file. On PCs, in order to make this >- * work the output buffer must be allocated in near data space, because we are >- * assuming small-data memory model wherein fwrite() can't reach far memory. >- * If you need to process very wide images on a PC, you might have to compile >- * in large-memory model, or else replace fwrite() with a putc() loop --- >- * which will be much slower. >- */ >- >- >-/* Private version of data destination object */ >- >-typedef struct { >- struct djpeg_dest_struct pub; /* public fields */ >- >- /* Usually these two pointers point to the same place: */ >- char *iobuffer; /* fwrite's I/O buffer */ >- JSAMPROW pixrow; /* decompressor output buffer */ >- size_t buffer_width; /* width of I/O buffer */ >- JDIMENSION samples_per_row; /* JSAMPLEs per output row */ >-} ppm_dest_struct; >- >-typedef ppm_dest_struct * ppm_dest_ptr; >- >- >-/* >- * Write some pixel data. >- * In this module rows_supplied will always be 1. >- * >- * put_pixel_rows handles the "normal" 8-bit case where the decompressor >- * output buffer is physically the same as the fwrite buffer. >- */ >- >-METHODDEF(void) >-put_pixel_rows (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo, >- JDIMENSION rows_supplied) >-{ >- ppm_dest_ptr dest = (ppm_dest_ptr) dinfo; >- >- (void) JFWRITE(dest->pub.output_file, dest->iobuffer, dest->buffer_width); >-} >- >- >-/* >- * This code is used when we have to copy the data and apply a pixel >- * format translation. Typically this only happens in 12-bit mode. >- */ >- >-METHODDEF(void) >-copy_pixel_rows (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo, >- JDIMENSION rows_supplied) >-{ >- ppm_dest_ptr dest = (ppm_dest_ptr) dinfo; >- register char * bufferptr; >- register JSAMPROW ptr; >- register JDIMENSION col; >- >- ptr = dest->pub.buffer[0]; >- bufferptr = dest->iobuffer; >- for (col = dest->samples_per_row; col > 0; col--) { >- PUTPPMSAMPLE(bufferptr, GETJSAMPLE(*ptr++)); >- } >- (void) JFWRITE(dest->pub.output_file, dest->iobuffer, dest->buffer_width); >-} >- >- >-/* >- * Write some pixel data when color quantization is in effect. >- * We have to demap the color index values to straight data. >- */ >- >-METHODDEF(void) >-put_demapped_rgb (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo, >- JDIMENSION rows_supplied) >-{ >- ppm_dest_ptr dest = (ppm_dest_ptr) dinfo; >- register char * bufferptr; >- register int pixval; >- register JSAMPROW ptr; >- register JSAMPROW color_map0 = cinfo->colormap[0]; >- register JSAMPROW color_map1 = cinfo->colormap[1]; >- register JSAMPROW color_map2 = cinfo->colormap[2]; >- register JDIMENSION col; >- >- ptr = dest->pub.buffer[0]; >- bufferptr = dest->iobuffer; >- for (col = cinfo->output_width; col > 0; col--) { >- pixval = GETJSAMPLE(*ptr++); >- PUTPPMSAMPLE(bufferptr, GETJSAMPLE(color_map0[pixval])); >- PUTPPMSAMPLE(bufferptr, GETJSAMPLE(color_map1[pixval])); >- PUTPPMSAMPLE(bufferptr, GETJSAMPLE(color_map2[pixval])); >- } >- (void) JFWRITE(dest->pub.output_file, dest->iobuffer, dest->buffer_width); >-} >- >- >-METHODDEF(void) >-put_demapped_gray (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo, >- JDIMENSION rows_supplied) >-{ >- ppm_dest_ptr dest = (ppm_dest_ptr) dinfo; >- register char * bufferptr; >- register JSAMPROW ptr; >- register JSAMPROW color_map = cinfo->colormap[0]; >- register JDIMENSION col; >- >- ptr = dest->pub.buffer[0]; >- bufferptr = dest->iobuffer; >- for (col = cinfo->output_width; col > 0; col--) { >- PUTPPMSAMPLE(bufferptr, GETJSAMPLE(color_map[GETJSAMPLE(*ptr++)])); >- } >- (void) JFWRITE(dest->pub.output_file, dest->iobuffer, dest->buffer_width); >-} >- >- >-/* >- * Startup: write the file header. >- */ >- >-METHODDEF(void) >-start_output_ppm (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo) >-{ >- ppm_dest_ptr dest = (ppm_dest_ptr) dinfo; >- >- /* Emit file header */ >- switch (cinfo->out_color_space) { >- case JCS_GRAYSCALE: >- /* emit header for raw PGM format */ >- fprintf(dest->pub.output_file, "P5\n%ld %ld\n%d\n", >- (long) cinfo->output_width, (long) cinfo->output_height, >- PPM_MAXVAL); >- break; >- case JCS_RGB: >- /* emit header for raw PPM format */ >- fprintf(dest->pub.output_file, "P6\n%ld %ld\n%d\n", >- (long) cinfo->output_width, (long) cinfo->output_height, >- PPM_MAXVAL); >- break; >- default: >- ERREXIT(cinfo, JERR_PPM_COLORSPACE); >- } >-} >- >- >-/* >- * Finish up at the end of the file. >- */ >- >-METHODDEF(void) >-finish_output_ppm (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo) >-{ >- /* Make sure we wrote the output file OK */ >- fflush(dinfo->output_file); >- if (ferror(dinfo->output_file)) >- ERREXIT(cinfo, JERR_FILE_WRITE); >-} >- >- >-/* >- * The module selection routine for PPM format output. >- */ >- >-GLOBAL(djpeg_dest_ptr) >-jinit_write_ppm (j_decompress_ptr cinfo) >-{ >- ppm_dest_ptr dest; >- >- /* Create module interface object, fill in method pointers */ >- dest = (ppm_dest_ptr) >- (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, >- SIZEOF(ppm_dest_struct)); >- dest->pub.start_output = start_output_ppm; >- dest->pub.finish_output = finish_output_ppm; >- >- /* Calculate output image dimensions so we can allocate space */ >- jpeg_calc_output_dimensions(cinfo); >- >- /* Create physical I/O buffer. Note we make this near on a PC. */ >- dest->samples_per_row = cinfo->output_width * cinfo->out_color_components; >- dest->buffer_width = dest->samples_per_row * (BYTESPERSAMPLE * SIZEOF(char)); >- dest->iobuffer = (char *) (*cinfo->mem->alloc_small) >- ((j_common_ptr) cinfo, JPOOL_IMAGE, dest->buffer_width); >- >- if (cinfo->quantize_colors || BITS_IN_JSAMPLE != 8 || >- SIZEOF(JSAMPLE) != SIZEOF(char)) { >- /* When quantizing, we need an output buffer for colormap indexes >- * that's separate from the physical I/O buffer. We also need a >- * separate buffer if pixel format translation must take place. >- */ >- dest->pub.buffer = (*cinfo->mem->alloc_sarray) >- ((j_common_ptr) cinfo, JPOOL_IMAGE, >- cinfo->output_width * cinfo->output_components, (JDIMENSION) 1); >- dest->pub.buffer_height = 1; >- if (! cinfo->quantize_colors) >- dest->pub.put_pixel_rows = copy_pixel_rows; >- else if (cinfo->out_color_space == JCS_GRAYSCALE) >- dest->pub.put_pixel_rows = put_demapped_gray; >- else >- dest->pub.put_pixel_rows = put_demapped_rgb; >- } else { >- /* We will fwrite() directly from decompressor output buffer. */ >- /* Synthesize a JSAMPARRAY pointer structure */ >- /* Cast here implies near->far pointer conversion on PCs */ >- dest->pixrow = (JSAMPROW) dest->iobuffer; >- dest->pub.buffer = & dest->pixrow; >- dest->pub.buffer_height = 1; >- dest->pub.put_pixel_rows = put_pixel_rows; >- } >- >- return (djpeg_dest_ptr) dest; >-} >- >-#endif /* PPM_SUPPORTED */ >--- b/jpeg/wrrle.c >+++ /dev/null >@@ -1,305 +0,0 @@ >-/* >- * wrrle.c >- * >- * Copyright (C) 1991-1996, Thomas G. Lane. >- * This file is part of the Independent JPEG Group's software. >- * For conditions of distribution and use, see the accompanying README file. >- * >- * This file contains routines to write output images in RLE format. >- * The Utah Raster Toolkit library is required (version 3.1 or later). >- * >- * These routines may need modification for non-Unix environments or >- * specialized applications. As they stand, they assume output to >- * an ordinary stdio stream. >- * >- * Based on code contributed by Mike Lijewski, >- * with updates from Robert Hutchinson. >- */ >- >-#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */ >- >-#ifdef RLE_SUPPORTED >- >-/* rle.h is provided by the Utah Raster Toolkit. */ >- >-#include <rle.h> >- >-/* >- * We assume that JSAMPLE has the same representation as rle_pixel, >- * to wit, "unsigned char". Hence we can't cope with 12- or 16-bit samples. >- */ >- >-#if BITS_IN_JSAMPLE != 8 >- Sorry, this code only copes with 8-bit JSAMPLEs. /* deliberate syntax err */ >-#endif >- >- >-/* >- * Since RLE stores scanlines bottom-to-top, we have to invert the image >- * from JPEG's top-to-bottom order. To do this, we save the outgoing data >- * in a virtual array during put_pixel_row calls, then actually emit the >- * RLE file during finish_output. >- */ >- >- >-/* >- * For now, if we emit an RLE color map then it is always 256 entries long, >- * though not all of the entries need be used. >- */ >- >-#define CMAPBITS 8 >-#define CMAPLENGTH (1<<(CMAPBITS)) >- >-typedef struct { >- struct djpeg_dest_struct pub; /* public fields */ >- >- jvirt_sarray_ptr image; /* virtual array to store the output image */ >- rle_map *colormap; /* RLE-style color map, or NULL if none */ >- rle_pixel **rle_row; /* To pass rows to rle_putrow() */ >- >-} rle_dest_struct; >- >-typedef rle_dest_struct * rle_dest_ptr; >- >-/* Forward declarations */ >-METHODDEF(void) rle_put_pixel_rows >- JPP((j_decompress_ptr cinfo, djpeg_dest_ptr dinfo, >- JDIMENSION rows_supplied)); >- >- >-/* >- * Write the file header. >- * >- * In this module it's easier to wait till finish_output to write anything. >- */ >- >-METHODDEF(void) >-start_output_rle (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo) >-{ >- rle_dest_ptr dest = (rle_dest_ptr) dinfo; >- size_t cmapsize; >- int i, ci; >-#ifdef PROGRESS_REPORT >- cd_progress_ptr progress = (cd_progress_ptr) cinfo->progress; >-#endif >- >- /* >- * Make sure the image can be stored in RLE format. >- * >- * - RLE stores image dimensions as *signed* 16 bit integers. JPEG >- * uses unsigned, so we have to check the width. >- * >- * - Colorspace is expected to be grayscale or RGB. >- * >- * - The number of channels (components) is expected to be 1 (grayscale/ >- * pseudocolor) or 3 (truecolor/directcolor). >- * (could be 2 or 4 if using an alpha channel, but we aren't) >- */ >- >- if (cinfo->output_width > 32767 || cinfo->output_height > 32767) >- ERREXIT2(cinfo, JERR_RLE_DIMENSIONS, cinfo->output_width, >- cinfo->output_height); >- >- if (cinfo->out_color_space != JCS_GRAYSCALE && >- cinfo->out_color_space != JCS_RGB) >- ERREXIT(cinfo, JERR_RLE_COLORSPACE); >- >- if (cinfo->output_components != 1 && cinfo->output_components != 3) >- ERREXIT1(cinfo, JERR_RLE_TOOMANYCHANNELS, cinfo->num_components); >- >- /* Convert colormap, if any, to RLE format. */ >- >- dest->colormap = NULL; >- >- if (cinfo->quantize_colors) { >- /* Allocate storage for RLE-style cmap, zero any extra entries */ >- cmapsize = cinfo->out_color_components * CMAPLENGTH * SIZEOF(rle_map); >- dest->colormap = (rle_map *) (*cinfo->mem->alloc_small) >- ((j_common_ptr) cinfo, JPOOL_IMAGE, cmapsize); >- MEMZERO(dest->colormap, cmapsize); >- >- /* Save away data in RLE format --- note 8-bit left shift! */ >- /* Shifting would need adjustment for JSAMPLEs wider than 8 bits. */ >- for (ci = 0; ci < cinfo->out_color_components; ci++) { >- for (i = 0; i < cinfo->actual_number_of_colors; i++) { >- dest->colormap[ci * CMAPLENGTH + i] = >- GETJSAMPLE(cinfo->colormap[ci][i]) << 8; >- } >- } >- } >- >- /* Set the output buffer to the first row */ >- dest->pub.buffer = (*cinfo->mem->access_virt_sarray) >- ((j_common_ptr) cinfo, dest->image, (JDIMENSION) 0, (JDIMENSION) 1, TRUE); >- dest->pub.buffer_height = 1; >- >- dest->pub.put_pixel_rows = rle_put_pixel_rows; >- >-#ifdef PROGRESS_REPORT >- if (progress != NULL) { >- progress->total_extra_passes++; /* count file writing as separate pass */ >- } >-#endif >-} >- >- >-/* >- * Write some pixel data. >- * >- * This routine just saves the data away in a virtual array. >- */ >- >-METHODDEF(void) >-rle_put_pixel_rows (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo, >- JDIMENSION rows_supplied) >-{ >- rle_dest_ptr dest = (rle_dest_ptr) dinfo; >- >- if (cinfo->output_scanline < cinfo->output_height) { >- dest->pub.buffer = (*cinfo->mem->access_virt_sarray) >- ((j_common_ptr) cinfo, dest->image, >- cinfo->output_scanline, (JDIMENSION) 1, TRUE); >- } >-} >- >-/* >- * Finish up at the end of the file. >- * >- * Here is where we really output the RLE file. >- */ >- >-METHODDEF(void) >-finish_output_rle (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo) >-{ >- rle_dest_ptr dest = (rle_dest_ptr) dinfo; >- rle_hdr header; /* Output file information */ >- rle_pixel **rle_row, *red, *green, *blue; >- JSAMPROW output_row; >- char cmapcomment[80]; >- int row, col; >- int ci; >-#ifdef PROGRESS_REPORT >- cd_progress_ptr progress = (cd_progress_ptr) cinfo->progress; >-#endif >- >- /* Initialize the header info */ >- header = *rle_hdr_init(NULL); >- header.rle_file = dest->pub.output_file; >- header.xmin = 0; >- header.xmax = cinfo->output_width - 1; >- header.ymin = 0; >- header.ymax = cinfo->output_height - 1; >- header.alpha = 0; >- header.ncolors = cinfo->output_components; >- for (ci = 0; ci < cinfo->output_components; ci++) { >- RLE_SET_BIT(header, ci); >- } >- if (cinfo->quantize_colors) { >- header.ncmap = cinfo->out_color_components; >- header.cmaplen = CMAPBITS; >- header.cmap = dest->colormap; >- /* Add a comment to the output image with the true colormap length. */ >- sprintf(cmapcomment, "color_map_length=%d", cinfo->actual_number_of_colors); >- rle_putcom(cmapcomment, &header); >- } >- >- /* Emit the RLE header and color map (if any) */ >- rle_put_setup(&header); >- >- /* Now output the RLE data from our virtual array. >- * We assume here that (a) rle_pixel is represented the same as JSAMPLE, >- * and (b) we are not on a machine where FAR pointers differ from regular. >- */ >- >-#ifdef PROGRESS_REPORT >- if (progress != NULL) { >- progress->pub.pass_limit = cinfo->output_height; >- progress->pub.pass_counter = 0; >- (*progress->pub.progress_monitor) ((j_common_ptr) cinfo); >- } >-#endif >- >- if (cinfo->output_components == 1) { >- for (row = cinfo->output_height-1; row >= 0; row--) { >- rle_row = (rle_pixel **) (*cinfo->mem->access_virt_sarray) >- ((j_common_ptr) cinfo, dest->image, >- (JDIMENSION) row, (JDIMENSION) 1, FALSE); >- rle_putrow(rle_row, (int) cinfo->output_width, &header); >-#ifdef PROGRESS_REPORT >- if (progress != NULL) { >- progress->pub.pass_counter++; >- (*progress->pub.progress_monitor) ((j_common_ptr) cinfo); >- } >-#endif >- } >- } else { >- for (row = cinfo->output_height-1; row >= 0; row--) { >- rle_row = (rle_pixel **) dest->rle_row; >- output_row = * (*cinfo->mem->access_virt_sarray) >- ((j_common_ptr) cinfo, dest->image, >- (JDIMENSION) row, (JDIMENSION) 1, FALSE); >- red = rle_row[0]; >- green = rle_row[1]; >- blue = rle_row[2]; >- for (col = cinfo->output_width; col > 0; col--) { >- *red++ = GETJSAMPLE(*output_row++); >- *green++ = GETJSAMPLE(*output_row++); >- *blue++ = GETJSAMPLE(*output_row++); >- } >- rle_putrow(rle_row, (int) cinfo->output_width, &header); >-#ifdef PROGRESS_REPORT >- if (progress != NULL) { >- progress->pub.pass_counter++; >- (*progress->pub.progress_monitor) ((j_common_ptr) cinfo); >- } >-#endif >- } >- } >- >-#ifdef PROGRESS_REPORT >- if (progress != NULL) >- progress->completed_extra_passes++; >-#endif >- >- /* Emit file trailer */ >- rle_puteof(&header); >- fflush(dest->pub.output_file); >- if (ferror(dest->pub.output_file)) >- ERREXIT(cinfo, JERR_FILE_WRITE); >-} >- >- >-/* >- * The module selection routine for RLE format output. >- */ >- >-GLOBAL(djpeg_dest_ptr) >-jinit_write_rle (j_decompress_ptr cinfo) >-{ >- rle_dest_ptr dest; >- >- /* Create module interface object, fill in method pointers */ >- dest = (rle_dest_ptr) >- (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, >- SIZEOF(rle_dest_struct)); >- dest->pub.start_output = start_output_rle; >- dest->pub.finish_output = finish_output_rle; >- >- /* Calculate output image dimensions so we can allocate space */ >- jpeg_calc_output_dimensions(cinfo); >- >- /* Allocate a work array for output to the RLE library. */ >- dest->rle_row = (*cinfo->mem->alloc_sarray) >- ((j_common_ptr) cinfo, JPOOL_IMAGE, >- cinfo->output_width, (JDIMENSION) cinfo->output_components); >- >- /* Allocate a virtual array to hold the image. */ >- dest->image = (*cinfo->mem->request_virt_sarray) >- ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE, >- (JDIMENSION) (cinfo->output_width * cinfo->output_components), >- cinfo->output_height, (JDIMENSION) 1); >- >- return (djpeg_dest_ptr) dest; >-} >- >-#endif /* RLE_SUPPORTED */ >--- b/jpeg/wrtarga.c >+++ /dev/null >@@ -1,253 +0,0 @@ >-/* >- * wrtarga.c >- * >- * Copyright (C) 1991-1996, Thomas G. Lane. >- * This file is part of the Independent JPEG Group's software. >- * For conditions of distribution and use, see the accompanying README file. >- * >- * This file contains routines to write output images in Targa format. >- * >- * These routines may need modification for non-Unix environments or >- * specialized applications. As they stand, they assume output to >- * an ordinary stdio stream. >- * >- * Based on code contributed by Lee Daniel Crocker. >- */ >- >-#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */ >- >-#ifdef TARGA_SUPPORTED >- >- >-/* >- * To support 12-bit JPEG data, we'd have to scale output down to 8 bits. >- * This is not yet implemented. >- */ >- >-#if BITS_IN_JSAMPLE != 8 >- Sorry, this code only copes with 8-bit JSAMPLEs. /* deliberate syntax err */ >-#endif >- >-/* >- * The output buffer needs to be writable by fwrite(). On PCs, we must >- * allocate the buffer in near data space, because we are assuming small-data >- * memory model, wherein fwrite() can't reach far memory. If you need to >- * process very wide images on a PC, you might have to compile in large-memory >- * model, or else replace fwrite() with a putc() loop --- which will be much >- * slower. >- */ >- >- >-/* Private version of data destination object */ >- >-typedef struct { >- struct djpeg_dest_struct pub; /* public fields */ >- >- char *iobuffer; /* physical I/O buffer */ >- JDIMENSION buffer_width; /* width of one row */ >-} tga_dest_struct; >- >-typedef tga_dest_struct * tga_dest_ptr; >- >- >-LOCAL(void) >-write_header (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo, int num_colors) >-/* Create and write a Targa header */ >-{ >- char targaheader[18]; >- >- /* Set unused fields of header to 0 */ >- MEMZERO(targaheader, SIZEOF(targaheader)); >- >- if (num_colors > 0) { >- targaheader[1] = 1; /* color map type 1 */ >- targaheader[5] = (char) (num_colors & 0xFF); >- targaheader[6] = (char) (num_colors >> 8); >- targaheader[7] = 24; /* 24 bits per cmap entry */ >- } >- >- targaheader[12] = (char) (cinfo->output_width & 0xFF); >- targaheader[13] = (char) (cinfo->output_width >> 8); >- targaheader[14] = (char) (cinfo->output_height & 0xFF); >- targaheader[15] = (char) (cinfo->output_height >> 8); >- targaheader[17] = 0x20; /* Top-down, non-interlaced */ >- >- if (cinfo->out_color_space == JCS_GRAYSCALE) { >- targaheader[2] = 3; /* image type = uncompressed gray-scale */ >- targaheader[16] = 8; /* bits per pixel */ >- } else { /* must be RGB */ >- if (num_colors > 0) { >- targaheader[2] = 1; /* image type = colormapped RGB */ >- targaheader[16] = 8; >- } else { >- targaheader[2] = 2; /* image type = uncompressed RGB */ >- targaheader[16] = 24; >- } >- } >- >- if (JFWRITE(dinfo->output_file, targaheader, 18) != (size_t) 18) >- ERREXIT(cinfo, JERR_FILE_WRITE); >-} >- >- >-/* >- * Write some pixel data. >- * In this module rows_supplied will always be 1. >- */ >- >-METHODDEF(void) >-put_pixel_rows (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo, >- JDIMENSION rows_supplied) >-/* used for unquantized full-color output */ >-{ >- tga_dest_ptr dest = (tga_dest_ptr) dinfo; >- register JSAMPROW inptr; >- register char * outptr; >- register JDIMENSION col; >- >- inptr = dest->pub.buffer[0]; >- outptr = dest->iobuffer; >- for (col = cinfo->output_width; col > 0; col--) { >- outptr[0] = (char) GETJSAMPLE(inptr[2]); /* RGB to BGR order */ >- outptr[1] = (char) GETJSAMPLE(inptr[1]); >- outptr[2] = (char) GETJSAMPLE(inptr[0]); >- inptr += 3, outptr += 3; >- } >- (void) JFWRITE(dest->pub.output_file, dest->iobuffer, dest->buffer_width); >-} >- >-METHODDEF(void) >-put_gray_rows (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo, >- JDIMENSION rows_supplied) >-/* used for grayscale OR quantized color output */ >-{ >- tga_dest_ptr dest = (tga_dest_ptr) dinfo; >- register JSAMPROW inptr; >- register char * outptr; >- register JDIMENSION col; >- >- inptr = dest->pub.buffer[0]; >- outptr = dest->iobuffer; >- for (col = cinfo->output_width; col > 0; col--) { >- *outptr++ = (char) GETJSAMPLE(*inptr++); >- } >- (void) JFWRITE(dest->pub.output_file, dest->iobuffer, dest->buffer_width); >-} >- >- >-/* >- * Write some demapped pixel data when color quantization is in effect. >- * For Targa, this is only applied to grayscale data. >- */ >- >-METHODDEF(void) >-put_demapped_gray (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo, >- JDIMENSION rows_supplied) >-{ >- tga_dest_ptr dest = (tga_dest_ptr) dinfo; >- register JSAMPROW inptr; >- register char * outptr; >- register JSAMPROW color_map0 = cinfo->colormap[0]; >- register JDIMENSION col; >- >- inptr = dest->pub.buffer[0]; >- outptr = dest->iobuffer; >- for (col = cinfo->output_width; col > 0; col--) { >- *outptr++ = (char) GETJSAMPLE(color_map0[GETJSAMPLE(*inptr++)]); >- } >- (void) JFWRITE(dest->pub.output_file, dest->iobuffer, dest->buffer_width); >-} >- >- >-/* >- * Startup: write the file header. >- */ >- >-METHODDEF(void) >-start_output_tga (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo) >-{ >- tga_dest_ptr dest = (tga_dest_ptr) dinfo; >- int num_colors, i; >- FILE *outfile; >- >- if (cinfo->out_color_space == JCS_GRAYSCALE) { >- /* Targa doesn't have a mapped grayscale format, so we will */ >- /* demap quantized gray output. Never emit a colormap. */ >- write_header(cinfo, dinfo, 0); >- if (cinfo->quantize_colors) >- dest->pub.put_pixel_rows = put_demapped_gray; >- else >- dest->pub.put_pixel_rows = put_gray_rows; >- } else if (cinfo->out_color_space == JCS_RGB) { >- if (cinfo->quantize_colors) { >- /* We only support 8-bit colormap indexes, so only 256 colors */ >- num_colors = cinfo->actual_number_of_colors; >- if (num_colors > 256) >- ERREXIT1(cinfo, JERR_TOO_MANY_COLORS, num_colors); >- write_header(cinfo, dinfo, num_colors); >- /* Write the colormap. Note Targa uses BGR byte order */ >- outfile = dest->pub.output_file; >- for (i = 0; i < num_colors; i++) { >- putc(GETJSAMPLE(cinfo->colormap[2][i]), outfile); >- putc(GETJSAMPLE(cinfo->colormap[1][i]), outfile); >- putc(GETJSAMPLE(cinfo->colormap[0][i]), outfile); >- } >- dest->pub.put_pixel_rows = put_gray_rows; >- } else { >- write_header(cinfo, dinfo, 0); >- dest->pub.put_pixel_rows = put_pixel_rows; >- } >- } else { >- ERREXIT(cinfo, JERR_TGA_COLORSPACE); >- } >-} >- >- >-/* >- * Finish up at the end of the file. >- */ >- >-METHODDEF(void) >-finish_output_tga (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo) >-{ >- /* Make sure we wrote the output file OK */ >- fflush(dinfo->output_file); >- if (ferror(dinfo->output_file)) >- ERREXIT(cinfo, JERR_FILE_WRITE); >-} >- >- >-/* >- * The module selection routine for Targa format output. >- */ >- >-GLOBAL(djpeg_dest_ptr) >-jinit_write_targa (j_decompress_ptr cinfo) >-{ >- tga_dest_ptr dest; >- >- /* Create module interface object, fill in method pointers */ >- dest = (tga_dest_ptr) >- (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, >- SIZEOF(tga_dest_struct)); >- dest->pub.start_output = start_output_tga; >- dest->pub.finish_output = finish_output_tga; >- >- /* Calculate output image dimensions so we can allocate space */ >- jpeg_calc_output_dimensions(cinfo); >- >- /* Create I/O buffer. Note we make this near on a PC. */ >- dest->buffer_width = cinfo->output_width * cinfo->output_components; >- dest->iobuffer = (char *) >- (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, >- (size_t) (dest->buffer_width * SIZEOF(char))); >- >- /* Create decompressor output buffer. */ >- dest->pub.buffer = (*cinfo->mem->alloc_sarray) >- ((j_common_ptr) cinfo, JPOOL_IMAGE, dest->buffer_width, (JDIMENSION) 1); >- dest->pub.buffer_height = 1; >- >- return (djpeg_dest_ptr) dest; >-} >- >-#endif /* TARGA_SUPPORTED */ >only in patch2: >--- a/jpeg/cderror.h >+++ b/jpeg/cderror.h >@@ -4,2 +4,3 @@ > * Copyright (C) 1994-1997, Thomas G. Lane. >+ * Modified 2009 by Guido Vollbeding. > * This file is part of the Independent JPEG Group's software. >@@ -47,2 +48,3 @@ > JMESSAGE(JERR_BMP_COMPRESSED, "Sorry, compressed BMPs not yet supported") >+JMESSAGE(JERR_BMP_EMPTY, "Empty BMP image") > JMESSAGE(JERR_BMP_NOT, "Not a BMP file - does not start with BM") >only in patch2: >--- a/jpeg/cdjpeg.c >+++ /dev/null >@@ -1,181 +0,0 @@ >-/* >- * cdjpeg.c >- * >- * Copyright (C) 1991-1997, Thomas G. Lane. >- * This file is part of the Independent JPEG Group's software. >- * For conditions of distribution and use, see the accompanying README file. >- * >- * This file contains common support routines used by the IJG application >- * programs (cjpeg, djpeg, jpegtran). >- */ >- >-#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */ >-#include <ctype.h> /* to declare isupper(), tolower() */ >-#ifdef NEED_SIGNAL_CATCHER >-#include <signal.h> /* to declare signal() */ >-#endif >-#ifdef USE_SETMODE >-#include <fcntl.h> /* to declare setmode()'s parameter macros */ >-/* If you have setmode() but not <io.h>, just delete this line: */ >-#include <io.h> /* to declare setmode() */ >-#endif >- >- >-/* >- * Signal catcher to ensure that temporary files are removed before aborting. >- * NB: for Amiga Manx C this is actually a global routine named _abort(); >- * we put "#define signal_catcher _abort" in jconfig.h. Talk about bogus... >- */ >- >-#ifdef NEED_SIGNAL_CATCHER >- >-static j_common_ptr sig_cinfo; >- >-void /* must be global for Manx C */ >-signal_catcher (int signum) >-{ >- if (sig_cinfo != NULL) { >- if (sig_cinfo->err != NULL) /* turn off trace output */ >- sig_cinfo->err->trace_level = 0; >- jpeg_destroy(sig_cinfo); /* clean up memory allocation & temp files */ >- } >- exit(EXIT_FAILURE); >-} >- >- >-GLOBAL(void) >-enable_signal_catcher (j_common_ptr cinfo) >-{ >- sig_cinfo = cinfo; >-#ifdef SIGINT /* not all systems have SIGINT */ >- signal(SIGINT, signal_catcher); >-#endif >-#ifdef SIGTERM /* not all systems have SIGTERM */ >- signal(SIGTERM, signal_catcher); >-#endif >-} >- >-#endif >- >- >-/* >- * Optional progress monitor: display a percent-done figure on stderr. >- */ >- >-#ifdef PROGRESS_REPORT >- >-METHODDEF(void) >-progress_monitor (j_common_ptr cinfo) >-{ >- cd_progress_ptr prog = (cd_progress_ptr) cinfo->progress; >- int total_passes = prog->pub.total_passes + prog->total_extra_passes; >- int percent_done = (int) (prog->pub.pass_counter*100L/prog->pub.pass_limit); >- >- if (percent_done != prog->percent_done) { >- prog->percent_done = percent_done; >- if (total_passes > 1) { >- fprintf(stderr, "\rPass %d/%d: %3d%% ", >- prog->pub.completed_passes + prog->completed_extra_passes + 1, >- total_passes, percent_done); >- } else { >- fprintf(stderr, "\r %3d%% ", percent_done); >- } >- fflush(stderr); >- } >-} >- >- >-GLOBAL(void) >-start_progress_monitor (j_common_ptr cinfo, cd_progress_ptr progress) >-{ >- /* Enable progress display, unless trace output is on */ >- if (cinfo->err->trace_level == 0) { >- progress->pub.progress_monitor = progress_monitor; >- progress->completed_extra_passes = 0; >- progress->total_extra_passes = 0; >- progress->percent_done = -1; >- cinfo->progress = &progress->pub; >- } >-} >- >- >-GLOBAL(void) >-end_progress_monitor (j_common_ptr cinfo) >-{ >- /* Clear away progress display */ >- if (cinfo->err->trace_level == 0) { >- fprintf(stderr, "\r \r"); >- fflush(stderr); >- } >-} >- >-#endif >- >- >-/* >- * Case-insensitive matching of possibly-abbreviated keyword switches. >- * keyword is the constant keyword (must be lower case already), >- * minchars is length of minimum legal abbreviation. >- */ >- >-GLOBAL(boolean) >-keymatch (char * arg, const char * keyword, int minchars) >-{ >- register int ca, ck; >- register int nmatched = 0; >- >- while ((ca = *arg++) != '\0') { >- if ((ck = *keyword++) == '\0') >- return FALSE; /* arg longer than keyword, no good */ >- if (isupper(ca)) /* force arg to lcase (assume ck is already) */ >- ca = tolower(ca); >- if (ca != ck) >- return FALSE; /* no good */ >- nmatched++; /* count matched characters */ >- } >- /* reached end of argument; fail if it's too short for unique abbrev */ >- if (nmatched < minchars) >- return FALSE; >- return TRUE; /* A-OK */ >-} >- >- >-/* >- * Routines to establish binary I/O mode for stdin and stdout. >- * Non-Unix systems often require some hacking to get out of text mode. >- */ >- >-GLOBAL(FILE *) >-read_stdin (void) >-{ >- FILE * input_file = stdin; >- >-#ifdef USE_SETMODE /* need to hack file mode? */ >- setmode(fileno(stdin), O_BINARY); >-#endif >-#ifdef USE_FDOPEN /* need to re-open in binary mode? */ >- if ((input_file = fdopen(fileno(stdin), READ_BINARY)) == NULL) { >- fprintf(stderr, "Cannot reopen stdin\n"); >- exit(EXIT_FAILURE); >- } >-#endif >- return input_file; >-} >- >- >-GLOBAL(FILE *) >-write_stdout (void) >-{ >- FILE * output_file = stdout; >- >-#ifdef USE_SETMODE /* need to hack file mode? */ >- setmode(fileno(stdout), O_BINARY); >-#endif >-#ifdef USE_FDOPEN /* need to re-open in binary mode? */ >- if ((output_file = fdopen(fileno(stdout), WRITE_BINARY)) == NULL) { >- fprintf(stderr, "Cannot reopen stdout\n"); >- exit(EXIT_FAILURE); >- } >-#endif >- return output_file; >-} >only in patch2: >--- a/jpeg/cdjpeg.h >+++ b/jpeg/cdjpeg.h >@@ -106,2 +106,3 @@ > #define read_scan_script RdScnScript >+#define set_quality_ratings SetQRates > #define set_quant_slots SetQSlots >@@ -133,4 +134,6 @@ > EXTERN(boolean) read_quant_tables JPP((j_compress_ptr cinfo, char * filename, >- int scale_factor, boolean force_baseline)); >+ boolean force_baseline)); > EXTERN(boolean) read_scan_script JPP((j_compress_ptr cinfo, char * filename)); >+EXTERN(boolean) set_quality_ratings JPP((j_compress_ptr cinfo, char *arg, >+ boolean force_baseline)); > EXTERN(boolean) set_quant_slots JPP((j_compress_ptr cinfo, char *arg)); >only in patch2: >--- a/jpeg/change.log >+++ /dev/null >@@ -1,217 +0,0 @@ >-CHANGE LOG for Independent JPEG Group's JPEG software >- >- >-Version 6b 27-Mar-1998 >------------------------ >- >-jpegtran has new features for lossless image transformations (rotation >-and flipping) as well as "lossless" reduction to grayscale. >- >-jpegtran now copies comments by default; it has a -copy switch to enable >-copying all APPn blocks as well, or to suppress comments. (Formerly it >-always suppressed comments and APPn blocks.) jpegtran now also preserves >-JFIF version and resolution information. >- >-New decompressor library feature: COM and APPn markers found in the input >-file can be saved in memory for later use by the application. (Before, >-you had to code this up yourself with a custom marker processor.) >- >-There is an unused field "void * client_data" now in compress and decompress >-parameter structs; this may be useful in some applications. >- >-JFIF version number information is now saved by the decoder and accepted by >-the encoder. jpegtran uses this to copy the source file's version number, >-to ensure "jpegtran -copy all" won't create bogus files that contain JFXX >-extensions but claim to be version 1.01. Applications that generate their >-own JFXX extension markers also (finally) have a supported way to cause the >-encoder to emit JFIF version number 1.02. >- >-djpeg's trace mode reports JFIF 1.02 thumbnail images as such, rather >-than as unknown APP0 markers. >- >-In -verbose mode, djpeg and rdjpgcom will try to print the contents of >-APP12 markers as text. Some digital cameras store useful text information >-in APP12 markers. >- >-Handling of truncated data streams is more robust: blocks beyond the one in >-which the error occurs will be output as uniform gray, or left unchanged >-if decoding a progressive JPEG. The appearance no longer depends on the >-Huffman tables being used. >- >-Huffman tables are checked for validity much more carefully than before. >- >-To avoid the Unisys LZW patent, djpeg's GIF output capability has been >-changed to produce "uncompressed GIFs", and cjpeg's GIF input capability >-has been removed altogether. We're not happy about it either, but there >-seems to be no good alternative. >- >-The configure script now supports building libjpeg as a shared library >-on many flavors of Unix (all the ones that GNU libtool knows how to >-build shared libraries for). Use "./configure --enable-shared" to >-try this out. >- >-New jconfig file and makefiles for Microsoft Visual C++ and Developer Studio. >-Also, a jconfig file and a build script for Metrowerks CodeWarrior >-on Apple Macintosh. makefile.dj has been updated for DJGPP v2, and there >-are miscellaneous other minor improvements in the makefiles. >- >-jmemmac.c now knows how to create temporary files following Mac System 7 >-conventions. >- >-djpeg's -map switch is now able to read raw-format PPM files reliably. >- >-cjpeg -progressive -restart no longer generates any unnecessary DRI markers. >- >-Multiple calls to jpeg_simple_progression for a single JPEG object >-no longer leak memory. >- >- >-Version 6a 7-Feb-96 >--------------------- >- >-Library initialization sequence modified to detect version mismatches >-and struct field packing mismatches between library and calling application. >-This change requires applications to be recompiled, but does not require >-any application source code change. >- >-All routine declarations changed to the style "GLOBAL(type) name ...", >-that is, GLOBAL, LOCAL, METHODDEF, EXTERN are now macros taking the >-routine's return type as an argument. This makes it possible to add >-Microsoft-style linkage keywords to all the routines by changing just >-these macros. Note that any application code that was using these macros >-will have to be changed. >- >-DCT coefficient quantization tables are now stored in normal array order >-rather than zigzag order. Application code that calls jpeg_add_quant_table, >-or otherwise manipulates quantization tables directly, will need to be >-changed. If you need to make such code work with either older or newer >-versions of the library, a test like "#if JPEG_LIB_VERSION >= 61" is >-recommended. >- >-djpeg's trace capability now dumps DQT tables in natural order, not zigzag >-order. This allows the trace output to be made into a "-qtables" file >-more easily. >- >-New system-dependent memory manager module for use on Apple Macintosh. >- >-Fix bug in cjpeg's -smooth option: last one or two scanlines would be >-duplicates of the prior line unless the image height mod 16 was 1 or 2. >- >-Repair minor problems in VMS, BCC, MC6 makefiles. >- >-New configure script based on latest GNU Autoconf. >- >-Correct the list of include files needed by MetroWerks C for ccommand(). >- >-Numerous small documentation updates. >- >- >-Version 6 2-Aug-95 >-------------------- >- >-Progressive JPEG support: library can read and write full progressive JPEG >-files. A "buffered image" mode supports incremental decoding for on-the-fly >-display of progressive images. Simply recompiling an existing IJG-v5-based >-decoder with v6 should allow it to read progressive files, though of course >-without any special progressive display. >- >-New "jpegtran" application performs lossless transcoding between different >-JPEG formats; primarily, it can be used to convert baseline to progressive >-JPEG and vice versa. In support of jpegtran, the library now allows lossless >-reading and writing of JPEG files as DCT coefficient arrays. This ability >-may be of use in other applications. >- >-Notes for programmers: >-* We changed jpeg_start_decompress() to be able to suspend; this makes all >-decoding modes available to suspending-input applications. However, >-existing applications that use suspending input will need to be changed >-to check the return value from jpeg_start_decompress(). You don't need to >-do anything if you don't use a suspending data source. >-* We changed the interface to the virtual array routines: access_virt_array >-routines now take a count of the number of rows to access this time. The >-last parameter to request_virt_array routines is now interpreted as the >-maximum number of rows that may be accessed at once, but not necessarily >-the height of every access. >- >- >-Version 5b 15-Mar-95 >---------------------- >- >-Correct bugs with grayscale images having v_samp_factor > 1. >- >-jpeg_write_raw_data() now supports output suspension. >- >-Correct bugs in "configure" script for case of compiling in >-a directory other than the one containing the source files. >- >-Repair bug in jquant1.c: sometimes didn't use as many colors as it could. >- >-Borland C makefile and jconfig file work under either MS-DOS or OS/2. >- >-Miscellaneous improvements to documentation. >- >- >-Version 5a 7-Dec-94 >--------------------- >- >-Changed color conversion roundoff behavior so that grayscale values are >-represented exactly. (This causes test image files to change.) >- >-Make ordered dither use 16x16 instead of 4x4 pattern for a small quality >-improvement. >- >-New configure script based on latest GNU Autoconf. >-Fix configure script to handle CFLAGS correctly. >-Rename *.auto files to *.cfg, so that configure script still works if >-file names have been truncated for DOS. >- >-Fix bug in rdbmp.c: didn't allow for extra data between header and image. >- >-Modify rdppm.c/wrppm.c to handle 2-byte raw PPM/PGM formats for 12-bit data. >- >-Fix several bugs in rdrle.c. >- >-NEED_SHORT_EXTERNAL_NAMES option was broken. >- >-Revise jerror.h/jerror.c for more flexibility in message table. >- >-Repair oversight in jmemname.c NO_MKTEMP case: file could be there >-but unreadable. >- >- >-Version 5 24-Sep-94 >--------------------- >- >-Version 5 represents a nearly complete redesign and rewrite of the IJG >-software. Major user-visible changes include: >- * Automatic configuration simplifies installation for most Unix systems. >- * A range of speed vs. image quality tradeoffs are supported. >- This includes resizing of an image during decompression: scaling down >- by a factor of 1/2, 1/4, or 1/8 is handled very efficiently. >- * New programs rdjpgcom and wrjpgcom allow insertion and extraction >- of text comments in a JPEG file. >- >-The application programmer's interface to the library has changed completely. >-Notable improvements include: >- * We have eliminated the use of callback routines for handling the >- uncompressed image data. The application now sees the library as a >- set of routines that it calls to read or write image data on a >- scanline-by-scanline basis. >- * The application image data is represented in a conventional interleaved- >- pixel format, rather than as a separate array for each color channel. >- This can save a copying step in many programs. >- * The handling of compressed data has been cleaned up: the application can >- supply routines to source or sink the compressed data. It is possible to >- suspend processing on source/sink buffer overrun, although this is not >- supported in all operating modes. >- * All static state has been eliminated from the library, so that multiple >- instances of compression or decompression can be active concurrently. >- * JPEG abbreviated datastream formats are supported, ie, quantization and >- Huffman tables can be stored separately from the image data. >- * And not only that, but the documentation of the library has improved >- considerably! >- >- >-The last widely used release before the version 5 rewrite was version 4A of >-18-Feb-93. Change logs before that point have been discarded, since they >-are not of much interest after the rewrite. >only in patch2: >--- a/jpeg/cjpeg.c >+++ /dev/null >@@ -1,606 +0,0 @@ >-/* >- * cjpeg.c >- * >- * Copyright (C) 1991-1998, Thomas G. Lane. >- * This file is part of the Independent JPEG Group's software. >- * For conditions of distribution and use, see the accompanying README file. >- * >- * This file contains a command-line user interface for the JPEG compressor. >- * It should work on any system with Unix- or MS-DOS-style command lines. >- * >- * Two different command line styles are permitted, depending on the >- * compile-time switch TWO_FILE_COMMANDLINE: >- * cjpeg [options] inputfile outputfile >- * cjpeg [options] [inputfile] >- * In the second style, output is always to standard output, which you'd >- * normally redirect to a file or pipe to some other program. Input is >- * either from a named file or from standard input (typically redirected). >- * The second style is convenient on Unix but is unhelpful on systems that >- * don't support pipes. Also, you MUST use the first style if your system >- * doesn't do binary I/O to stdin/stdout. >- * To simplify script writing, the "-outfile" switch is provided. The syntax >- * cjpeg [options] -outfile outputfile inputfile >- * works regardless of which command line style is used. >- */ >- >-#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */ >-#include "jversion.h" /* for version message */ >- >-#ifdef USE_CCOMMAND /* command-line reader for Macintosh */ >-#ifdef __MWERKS__ >-#include <SIOUX.h> /* Metrowerks needs this */ >-#include <console.h> /* ... and this */ >-#endif >-#ifdef THINK_C >-#include <console.h> /* Think declares it here */ >-#endif >-#endif >- >- >-/* Create the add-on message string table. */ >- >-#define JMESSAGE(code,string) string , >- >-static const char * const cdjpeg_message_table[] = { >-#include "cderror.h" >- NULL >-}; >- >- >-/* >- * This routine determines what format the input file is, >- * and selects the appropriate input-reading module. >- * >- * To determine which family of input formats the file belongs to, >- * we may look only at the first byte of the file, since C does not >- * guarantee that more than one character can be pushed back with ungetc. >- * Looking at additional bytes would require one of these approaches: >- * 1) assume we can fseek() the input file (fails for piped input); >- * 2) assume we can push back more than one character (works in >- * some C implementations, but unportable); >- * 3) provide our own buffering (breaks input readers that want to use >- * stdio directly, such as the RLE library); >- * or 4) don't put back the data, and modify the input_init methods to assume >- * they start reading after the start of file (also breaks RLE library). >- * #1 is attractive for MS-DOS but is untenable on Unix. >- * >- * The most portable solution for file types that can't be identified by their >- * first byte is to make the user tell us what they are. This is also the >- * only approach for "raw" file types that contain only arbitrary values. >- * We presently apply this method for Targa files. Most of the time Targa >- * files start with 0x00, so we recognize that case. Potentially, however, >- * a Targa file could start with any byte value (byte 0 is the length of the >- * seldom-used ID field), so we provide a switch to force Targa input mode. >- */ >- >-static boolean is_targa; /* records user -targa switch */ >- >- >-LOCAL(cjpeg_source_ptr) >-select_file_type (j_compress_ptr cinfo, FILE * infile) >-{ >- int c; >- >- if (is_targa) { >-#ifdef TARGA_SUPPORTED >- return jinit_read_targa(cinfo); >-#else >- ERREXIT(cinfo, JERR_TGA_NOTCOMP); >-#endif >- } >- >- if ((c = getc(infile)) == EOF) >- ERREXIT(cinfo, JERR_INPUT_EMPTY); >- if (ungetc(c, infile) == EOF) >- ERREXIT(cinfo, JERR_UNGETC_FAILED); >- >- switch (c) { >-#ifdef BMP_SUPPORTED >- case 'B': >- return jinit_read_bmp(cinfo); >-#endif >-#ifdef GIF_SUPPORTED >- case 'G': >- return jinit_read_gif(cinfo); >-#endif >-#ifdef PPM_SUPPORTED >- case 'P': >- return jinit_read_ppm(cinfo); >-#endif >-#ifdef RLE_SUPPORTED >- case 'R': >- return jinit_read_rle(cinfo); >-#endif >-#ifdef TARGA_SUPPORTED >- case 0x00: >- return jinit_read_targa(cinfo); >-#endif >- default: >- ERREXIT(cinfo, JERR_UNKNOWN_FORMAT); >- break; >- } >- >- return NULL; /* suppress compiler warnings */ >-} >- >- >-/* >- * Argument-parsing code. >- * The switch parser is designed to be useful with DOS-style command line >- * syntax, ie, intermixed switches and file names, where only the switches >- * to the left of a given file name affect processing of that file. >- * The main program in this file doesn't actually use this capability... >- */ >- >- >-static const char * progname; /* program name for error messages */ >-static char * outfilename; /* for -outfile switch */ >- >- >-LOCAL(void) >-usage (void) >-/* complain about bad command line */ >-{ >- fprintf(stderr, "usage: %s [switches] ", progname); >-#ifdef TWO_FILE_COMMANDLINE >- fprintf(stderr, "inputfile outputfile\n"); >-#else >- fprintf(stderr, "[inputfile]\n"); >-#endif >- >- fprintf(stderr, "Switches (names may be abbreviated):\n"); >- fprintf(stderr, " -quality N Compression quality (0..100; 5-95 is useful range)\n"); >- fprintf(stderr, " -grayscale Create monochrome JPEG file\n"); >-#ifdef ENTROPY_OPT_SUPPORTED >- fprintf(stderr, " -optimize Optimize Huffman table (smaller file, but slow compression)\n"); >-#endif >-#ifdef C_PROGRESSIVE_SUPPORTED >- fprintf(stderr, " -progressive Create progressive JPEG file\n"); >-#endif >-#ifdef TARGA_SUPPORTED >- fprintf(stderr, " -targa Input file is Targa format (usually not needed)\n"); >-#endif >- fprintf(stderr, "Switches for advanced users:\n"); >-#ifdef DCT_ISLOW_SUPPORTED >- fprintf(stderr, " -dct int Use integer DCT method%s\n", >- (JDCT_DEFAULT == JDCT_ISLOW ? " (default)" : "")); >-#endif >-#ifdef DCT_IFAST_SUPPORTED >- fprintf(stderr, " -dct fast Use fast integer DCT (less accurate)%s\n", >- (JDCT_DEFAULT == JDCT_IFAST ? " (default)" : "")); >-#endif >-#ifdef DCT_FLOAT_SUPPORTED >- fprintf(stderr, " -dct float Use floating-point DCT method%s\n", >- (JDCT_DEFAULT == JDCT_FLOAT ? " (default)" : "")); >-#endif >- fprintf(stderr, " -restart N Set restart interval in rows, or in blocks with B\n"); >-#ifdef INPUT_SMOOTHING_SUPPORTED >- fprintf(stderr, " -smooth N Smooth dithered input (N=1..100 is strength)\n"); >-#endif >- fprintf(stderr, " -maxmemory N Maximum memory to use (in kbytes)\n"); >- fprintf(stderr, " -outfile name Specify name for output file\n"); >- fprintf(stderr, " -verbose or -debug Emit debug output\n"); >- fprintf(stderr, "Switches for wizards:\n"); >-#ifdef C_ARITH_CODING_SUPPORTED >- fprintf(stderr, " -arithmetic Use arithmetic coding\n"); >-#endif >- fprintf(stderr, " -baseline Force baseline quantization tables\n"); >- fprintf(stderr, " -qtables file Use quantization tables given in file\n"); >- fprintf(stderr, " -qslots N[,...] Set component quantization tables\n"); >- fprintf(stderr, " -sample HxV[,...] Set component sampling factors\n"); >-#ifdef C_MULTISCAN_FILES_SUPPORTED >- fprintf(stderr, " -scans file Create multi-scan JPEG per script file\n"); >-#endif >- exit(EXIT_FAILURE); >-} >- >- >-LOCAL(int) >-parse_switches (j_compress_ptr cinfo, int argc, char **argv, >- int last_file_arg_seen, boolean for_real) >-/* Parse optional switches. >- * Returns argv[] index of first file-name argument (== argc if none). >- * Any file names with indexes <= last_file_arg_seen are ignored; >- * they have presumably been processed in a previous iteration. >- * (Pass 0 for last_file_arg_seen on the first or only iteration.) >- * for_real is FALSE on the first (dummy) pass; we may skip any expensive >- * processing. >- */ >-{ >- int argn; >- char * arg; >- int quality; /* -quality parameter */ >- int q_scale_factor; /* scaling percentage for -qtables */ >- boolean force_baseline; >- boolean simple_progressive; >- char * qtablefile = NULL; /* saves -qtables filename if any */ >- char * qslotsarg = NULL; /* saves -qslots parm if any */ >- char * samplearg = NULL; /* saves -sample parm if any */ >- char * scansarg = NULL; /* saves -scans parm if any */ >- >- /* Set up default JPEG parameters. */ >- /* Note that default -quality level need not, and does not, >- * match the default scaling for an explicit -qtables argument. >- */ >- quality = 75; /* default -quality value */ >- q_scale_factor = 100; /* default to no scaling for -qtables */ >- force_baseline = FALSE; /* by default, allow 16-bit quantizers */ >- simple_progressive = FALSE; >- is_targa = FALSE; >- outfilename = NULL; >- cinfo->err->trace_level = 0; >- >- /* Scan command line options, adjust parameters */ >- >- for (argn = 1; argn < argc; argn++) { >- arg = argv[argn]; >- if (*arg != '-') { >- /* Not a switch, must be a file name argument */ >- if (argn <= last_file_arg_seen) { >- outfilename = NULL; /* -outfile applies to just one input file */ >- continue; /* ignore this name if previously processed */ >- } >- break; /* else done parsing switches */ >- } >- arg++; /* advance past switch marker character */ >- >- if (keymatch(arg, "arithmetic", 1)) { >- /* Use arithmetic coding. */ >-#ifdef C_ARITH_CODING_SUPPORTED >- cinfo->arith_code = TRUE; >-#else >- fprintf(stderr, "%s: sorry, arithmetic coding not supported\n", >- progname); >- exit(EXIT_FAILURE); >-#endif >- >- } else if (keymatch(arg, "baseline", 1)) { >- /* Force baseline-compatible output (8-bit quantizer values). */ >- force_baseline = TRUE; >- >- } else if (keymatch(arg, "dct", 2)) { >- /* Select DCT algorithm. */ >- if (++argn >= argc) /* advance to next argument */ >- usage(); >- if (keymatch(argv[argn], "int", 1)) { >- cinfo->dct_method = JDCT_ISLOW; >- } else if (keymatch(argv[argn], "fast", 2)) { >- cinfo->dct_method = JDCT_IFAST; >- } else if (keymatch(argv[argn], "float", 2)) { >- cinfo->dct_method = JDCT_FLOAT; >- } else >- usage(); >- >- } else if (keymatch(arg, "debug", 1) || keymatch(arg, "verbose", 1)) { >- /* Enable debug printouts. */ >- /* On first -d, print version identification */ >- static boolean printed_version = FALSE; >- >- if (! printed_version) { >- fprintf(stderr, "Independent JPEG Group's CJPEG, version %s\n%s\n", >- JVERSION, JCOPYRIGHT); >- printed_version = TRUE; >- } >- cinfo->err->trace_level++; >- >- } else if (keymatch(arg, "grayscale", 2) || keymatch(arg, "greyscale",2)) { >- /* Force a monochrome JPEG file to be generated. */ >- jpeg_set_colorspace(cinfo, JCS_GRAYSCALE); >- >- } else if (keymatch(arg, "maxmemory", 3)) { >- /* Maximum memory in Kb (or Mb with 'm'). */ >- long lval; >- char ch = 'x'; >- >- if (++argn >= argc) /* advance to next argument */ >- usage(); >- if (sscanf(argv[argn], "%ld%c", &lval, &ch) < 1) >- usage(); >- if (ch == 'm' || ch == 'M') >- lval *= 1000L; >- cinfo->mem->max_memory_to_use = lval * 1000L; >- >- } else if (keymatch(arg, "optimize", 1) || keymatch(arg, "optimise", 1)) { >- /* Enable entropy parm optimization. */ >-#ifdef ENTROPY_OPT_SUPPORTED >- cinfo->optimize_coding = TRUE; >-#else >- fprintf(stderr, "%s: sorry, entropy optimization was not compiled\n", >- progname); >- exit(EXIT_FAILURE); >-#endif >- >- } else if (keymatch(arg, "outfile", 4)) { >- /* Set output file name. */ >- if (++argn >= argc) /* advance to next argument */ >- usage(); >- outfilename = argv[argn]; /* save it away for later use */ >- >- } else if (keymatch(arg, "progressive", 1)) { >- /* Select simple progressive mode. */ >-#ifdef C_PROGRESSIVE_SUPPORTED >- simple_progressive = TRUE; >- /* We must postpone execution until num_components is known. */ >-#else >- fprintf(stderr, "%s: sorry, progressive output was not compiled\n", >- progname); >- exit(EXIT_FAILURE); >-#endif >- >- } else if (keymatch(arg, "quality", 1)) { >- /* Quality factor (quantization table scaling factor). */ >- if (++argn >= argc) /* advance to next argument */ >- usage(); >- if (sscanf(argv[argn], "%d", &quality) != 1) >- usage(); >- /* Change scale factor in case -qtables is present. */ >- q_scale_factor = jpeg_quality_scaling(quality); >- >- } else if (keymatch(arg, "qslots", 2)) { >- /* Quantization table slot numbers. */ >- if (++argn >= argc) /* advance to next argument */ >- usage(); >- qslotsarg = argv[argn]; >- /* Must delay setting qslots until after we have processed any >- * colorspace-determining switches, since jpeg_set_colorspace sets >- * default quant table numbers. >- */ >- >- } else if (keymatch(arg, "qtables", 2)) { >- /* Quantization tables fetched from file. */ >- if (++argn >= argc) /* advance to next argument */ >- usage(); >- qtablefile = argv[argn]; >- /* We postpone actually reading the file in case -quality comes later. */ >- >- } else if (keymatch(arg, "restart", 1)) { >- /* Restart interval in MCU rows (or in MCUs with 'b'). */ >- long lval; >- char ch = 'x'; >- >- if (++argn >= argc) /* advance to next argument */ >- usage(); >- if (sscanf(argv[argn], "%ld%c", &lval, &ch) < 1) >- usage(); >- if (lval < 0 || lval > 65535L) >- usage(); >- if (ch == 'b' || ch == 'B') { >- cinfo->restart_interval = (unsigned int) lval; >- cinfo->restart_in_rows = 0; /* else prior '-restart n' overrides me */ >- } else { >- cinfo->restart_in_rows = (int) lval; >- /* restart_interval will be computed during startup */ >- } >- >- } else if (keymatch(arg, "sample", 2)) { >- /* Set sampling factors. */ >- if (++argn >= argc) /* advance to next argument */ >- usage(); >- samplearg = argv[argn]; >- /* Must delay setting sample factors until after we have processed any >- * colorspace-determining switches, since jpeg_set_colorspace sets >- * default sampling factors. >- */ >- >- } else if (keymatch(arg, "scans", 2)) { >- /* Set scan script. */ >-#ifdef C_MULTISCAN_FILES_SUPPORTED >- if (++argn >= argc) /* advance to next argument */ >- usage(); >- scansarg = argv[argn]; >- /* We must postpone reading the file in case -progressive appears. */ >-#else >- fprintf(stderr, "%s: sorry, multi-scan output was not compiled\n", >- progname); >- exit(EXIT_FAILURE); >-#endif >- >- } else if (keymatch(arg, "smooth", 2)) { >- /* Set input smoothing factor. */ >- int val; >- >- if (++argn >= argc) /* advance to next argument */ >- usage(); >- if (sscanf(argv[argn], "%d", &val) != 1) >- usage(); >- if (val < 0 || val > 100) >- usage(); >- cinfo->smoothing_factor = val; >- >- } else if (keymatch(arg, "targa", 1)) { >- /* Input file is Targa format. */ >- is_targa = TRUE; >- >- } else { >- usage(); /* bogus switch */ >- } >- } >- >- /* Post-switch-scanning cleanup */ >- >- if (for_real) { >- >- /* Set quantization tables for selected quality. */ >- /* Some or all may be overridden if -qtables is present. */ >- jpeg_set_quality(cinfo, quality, force_baseline); >- >- if (qtablefile != NULL) /* process -qtables if it was present */ >- if (! read_quant_tables(cinfo, qtablefile, >- q_scale_factor, force_baseline)) >- usage(); >- >- if (qslotsarg != NULL) /* process -qslots if it was present */ >- if (! set_quant_slots(cinfo, qslotsarg)) >- usage(); >- >- if (samplearg != NULL) /* process -sample if it was present */ >- if (! set_sample_factors(cinfo, samplearg)) >- usage(); >- >-#ifdef C_PROGRESSIVE_SUPPORTED >- if (simple_progressive) /* process -progressive; -scans can override */ >- jpeg_simple_progression(cinfo); >-#endif >- >-#ifdef C_MULTISCAN_FILES_SUPPORTED >- if (scansarg != NULL) /* process -scans if it was present */ >- if (! read_scan_script(cinfo, scansarg)) >- usage(); >-#endif >- } >- >- return argn; /* return index of next arg (file name) */ >-} >- >- >-/* >- * The main program. >- */ >- >-int >-main (int argc, char **argv) >-{ >- struct jpeg_compress_struct cinfo; >- struct jpeg_error_mgr jerr; >-#ifdef PROGRESS_REPORT >- struct cdjpeg_progress_mgr progress; >-#endif >- int file_index; >- cjpeg_source_ptr src_mgr; >- FILE * input_file; >- FILE * output_file; >- JDIMENSION num_scanlines; >- >- /* On Mac, fetch a command line. */ >-#ifdef USE_CCOMMAND >- argc = ccommand(&argv); >-#endif >- >- progname = argv[0]; >- if (progname == NULL || progname[0] == 0) >- progname = "cjpeg"; /* in case C library doesn't provide it */ >- >- /* Initialize the JPEG compression object with default error handling. */ >- cinfo.err = jpeg_std_error(&jerr); >- jpeg_create_compress(&cinfo); >- /* Add some application-specific error messages (from cderror.h) */ >- jerr.addon_message_table = cdjpeg_message_table; >- jerr.first_addon_message = JMSG_FIRSTADDONCODE; >- jerr.last_addon_message = JMSG_LASTADDONCODE; >- >- /* Now safe to enable signal catcher. */ >-#ifdef NEED_SIGNAL_CATCHER >- enable_signal_catcher((j_common_ptr) &cinfo); >-#endif >- >- /* Initialize JPEG parameters. >- * Much of this may be overridden later. >- * In particular, we don't yet know the input file's color space, >- * but we need to provide some value for jpeg_set_defaults() to work. >- */ >- >- cinfo.in_color_space = JCS_RGB; /* arbitrary guess */ >- jpeg_set_defaults(&cinfo); >- >- /* Scan command line to find file names. >- * It is convenient to use just one switch-parsing routine, but the switch >- * values read here are ignored; we will rescan the switches after opening >- * the input file. >- */ >- >- file_index = parse_switches(&cinfo, argc, argv, 0, FALSE); >- >-#ifdef TWO_FILE_COMMANDLINE >- /* Must have either -outfile switch or explicit output file name */ >- if (outfilename == NULL) { >- if (file_index != argc-2) { >- fprintf(stderr, "%s: must name one input and one output file\n", >- progname); >- usage(); >- } >- outfilename = argv[file_index+1]; >- } else { >- if (file_index != argc-1) { >- fprintf(stderr, "%s: must name one input and one output file\n", >- progname); >- usage(); >- } >- } >-#else >- /* Unix style: expect zero or one file name */ >- if (file_index < argc-1) { >- fprintf(stderr, "%s: only one input file\n", progname); >- usage(); >- } >-#endif /* TWO_FILE_COMMANDLINE */ >- >- /* Open the input file. */ >- if (file_index < argc) { >- if ((input_file = fopen(argv[file_index], READ_BINARY)) == NULL) { >- fprintf(stderr, "%s: can't open %s\n", progname, argv[file_index]); >- exit(EXIT_FAILURE); >- } >- } else { >- /* default input file is stdin */ >- input_file = read_stdin(); >- } >- >- /* Open the output file. */ >- if (outfilename != NULL) { >- if ((output_file = fopen(outfilename, WRITE_BINARY)) == NULL) { >- fprintf(stderr, "%s: can't open %s\n", progname, outfilename); >- exit(EXIT_FAILURE); >- } >- } else { >- /* default output file is stdout */ >- output_file = write_stdout(); >- } >- >-#ifdef PROGRESS_REPORT >- start_progress_monitor((j_common_ptr) &cinfo, &progress); >-#endif >- >- /* Figure out the input file format, and set up to read it. */ >- src_mgr = select_file_type(&cinfo, input_file); >- src_mgr->input_file = input_file; >- >- /* Read the input file header to obtain file size & colorspace. */ >- (*src_mgr->start_input) (&cinfo, src_mgr); >- >- /* Now that we know input colorspace, fix colorspace-dependent defaults */ >- jpeg_default_colorspace(&cinfo); >- >- /* Adjust default compression parameters by re-parsing the options */ >- file_index = parse_switches(&cinfo, argc, argv, 0, TRUE); >- >- /* Specify data destination for compression */ >- jpeg_stdio_dest(&cinfo, output_file); >- >- /* Start compressor */ >- jpeg_start_compress(&cinfo, TRUE); >- >- /* Process data */ >- while (cinfo.next_scanline < cinfo.image_height) { >- num_scanlines = (*src_mgr->get_pixel_rows) (&cinfo, src_mgr); >- (void) jpeg_write_scanlines(&cinfo, src_mgr->buffer, num_scanlines); >- } >- >- /* Finish compression and release memory */ >- (*src_mgr->finish_input) (&cinfo, src_mgr); >- jpeg_finish_compress(&cinfo); >- jpeg_destroy_compress(&cinfo); >- >- /* Close files, if we opened them */ >- if (input_file != stdin) >- fclose(input_file); >- if (output_file != stdout) >- fclose(output_file); >- >-#ifdef PROGRESS_REPORT >- end_progress_monitor((j_common_ptr) &cinfo); >-#endif >- >- /* All done. */ >- exit(jerr.num_warnings ? EXIT_WARNING : EXIT_SUCCESS); >- return 0; /* suppress no-return-value warnings */ >-} >only in patch2: >--- a/jpeg/coderules.doc >+++ /dev/null >@@ -1,118 +0,0 @@ >-IJG JPEG LIBRARY: CODING RULES >- >-Copyright (C) 1991-1996, Thomas G. Lane. >-This file is part of the Independent JPEG Group's software. >-For conditions of distribution and use, see the accompanying README file. >- >- >-Since numerous people will be contributing code and bug fixes, it's important >-to establish a common coding style. The goal of using similar coding styles >-is much more important than the details of just what that style is. >- >-In general we follow the recommendations of "Recommended C Style and Coding >-Standards" revision 6.1 (Cannon et al. as modified by Spencer, Keppel and >-Brader). This document is available in the IJG FTP archive (see >-jpeg/doc/cstyle.ms.tbl.Z, or cstyle.txt.Z for those without nroff/tbl). >- >-Block comments should be laid out thusly: >- >-/* >- * Block comments in this style. >- */ >- >-We indent statements in K&R style, e.g., >- if (test) { >- then-part; >- } else { >- else-part; >- } >-with two spaces per indentation level. (This indentation convention is >-handled automatically by GNU Emacs and many other text editors.) >- >-Multi-word names should be written in lower case with underscores, e.g., >-multi_word_name (not multiWordName). Preprocessor symbols and enum constants >-are similar but upper case (MULTI_WORD_NAME). Names should be unique within >-the first fifteen characters. (On some older systems, global names must be >-unique within six characters. We accommodate this without cluttering the >-source code by using macros to substitute shorter names.) >- >-We use function prototypes everywhere; we rely on automatic source code >-transformation to feed prototype-less C compilers. Transformation is done >-by the simple and portable tool 'ansi2knr.c' (courtesy of Ghostscript). >-ansi2knr is not very bright, so it imposes a format requirement on function >-declarations: the function name MUST BEGIN IN COLUMN 1. Thus all functions >-should be written in the following style: >- >-LOCAL(int *) >-function_name (int a, char *b) >-{ >- code... >-} >- >-Note that each function definition must begin with GLOBAL(type), LOCAL(type), >-or METHODDEF(type). These macros expand to "static type" or just "type" as >-appropriate. They provide a readable indication of the routine's usage and >-can readily be changed for special needs. (For instance, special linkage >-keywords can be inserted for use in Windows DLLs.) >- >-ansi2knr does not transform method declarations (function pointers in >-structs). We handle these with a macro JMETHOD, defined as >- #ifdef HAVE_PROTOTYPES >- #define JMETHOD(type,methodname,arglist) type (*methodname) arglist >- #else >- #define JMETHOD(type,methodname,arglist) type (*methodname) () >- #endif >-which is used like this: >- struct function_pointers { >- JMETHOD(void, init_entropy_encoder, (int somearg, jparms *jp)); >- JMETHOD(void, term_entropy_encoder, (void)); >- }; >-Note the set of parentheses surrounding the parameter list. >- >-A similar solution is used for forward and external function declarations >-(see the EXTERN and JPP macros). >- >-If the code is to work on non-ANSI compilers, we cannot rely on a prototype >-declaration to coerce actual parameters into the right types. Therefore, use >-explicit casts on actual parameters whenever the actual parameter type is not >-identical to the formal parameter. Beware of implicit conversions to "int". >- >-It seems there are some non-ANSI compilers in which the sizeof() operator >-is defined to return int, yet size_t is defined as long. Needless to say, >-this is brain-damaged. Always use the SIZEOF() macro in place of sizeof(), >-so that the result is guaranteed to be of type size_t. >- >- >-The JPEG library is intended to be used within larger programs. Furthermore, >-we want it to be reentrant so that it can be used by applications that process >-multiple images concurrently. The following rules support these requirements: >- >-1. Avoid direct use of file I/O, "malloc", error report printouts, etc; >-pass these through the common routines provided. >- >-2. Minimize global namespace pollution. Functions should be declared static >-wherever possible. (Note that our method-based calling conventions help this >-a lot: in many modules only the initialization function will ever need to be >-called directly, so only that function need be externally visible.) All >-global function names should begin with "jpeg_", and should have an >-abbreviated name (unique in the first six characters) substituted by macro >-when NEED_SHORT_EXTERNAL_NAMES is set. >- >-3. Don't use global variables; anything that must be used in another module >-should be in the common data structures. >- >-4. Don't use static variables except for read-only constant tables. Variables >-that should be private to a module can be placed into private structures (see >-the system architecture document, structure.doc). >- >-5. Source file names should begin with "j" for files that are part of the >-library proper; source files that are not part of the library, such as cjpeg.c >-and djpeg.c, do not begin with "j". Keep source file names to eight >-characters (plus ".c" or ".h", etc) to make life easy for MS-DOSers. Keep >-compression and decompression code in separate source files --- some >-applications may want only one half of the library. >- >-Note: these rules (particularly #4) are not followed religiously in the >-modules that are used in cjpeg/djpeg but are not part of the JPEG library >-proper. Those modules are not really intended to be used in other >-applications. >only in patch2: >--- a/jpeg/djpeg.c >+++ /dev/null >@@ -1,616 +0,0 @@ >-/* >- * djpeg.c >- * >- * Copyright (C) 1991-1997, Thomas G. Lane. >- * This file is part of the Independent JPEG Group's software. >- * For conditions of distribution and use, see the accompanying README file. >- * >- * This file contains a command-line user interface for the JPEG decompressor. >- * It should work on any system with Unix- or MS-DOS-style command lines. >- * >- * Two different command line styles are permitted, depending on the >- * compile-time switch TWO_FILE_COMMANDLINE: >- * djpeg [options] inputfile outputfile >- * djpeg [options] [inputfile] >- * In the second style, output is always to standard output, which you'd >- * normally redirect to a file or pipe to some other program. Input is >- * either from a named file or from standard input (typically redirected). >- * The second style is convenient on Unix but is unhelpful on systems that >- * don't support pipes. Also, you MUST use the first style if your system >- * doesn't do binary I/O to stdin/stdout. >- * To simplify script writing, the "-outfile" switch is provided. The syntax >- * djpeg [options] -outfile outputfile inputfile >- * works regardless of which command line style is used. >- */ >- >-#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */ >-#include "jversion.h" /* for version message */ >- >-#include <ctype.h> /* to declare isprint() */ >- >-#ifdef USE_CCOMMAND /* command-line reader for Macintosh */ >-#ifdef __MWERKS__ >-#include <SIOUX.h> /* Metrowerks needs this */ >-#include <console.h> /* ... and this */ >-#endif >-#ifdef THINK_C >-#include <console.h> /* Think declares it here */ >-#endif >-#endif >- >- >-/* Create the add-on message string table. */ >- >-#define JMESSAGE(code,string) string , >- >-static const char * const cdjpeg_message_table[] = { >-#include "cderror.h" >- NULL >-}; >- >- >-/* >- * This list defines the known output image formats >- * (not all of which need be supported by a given version). >- * You can change the default output format by defining DEFAULT_FMT; >- * indeed, you had better do so if you undefine PPM_SUPPORTED. >- */ >- >-typedef enum { >- FMT_BMP, /* BMP format (Windows flavor) */ >- FMT_GIF, /* GIF format */ >- FMT_OS2, /* BMP format (OS/2 flavor) */ >- FMT_PPM, /* PPM/PGM (PBMPLUS formats) */ >- FMT_RLE, /* RLE format */ >- FMT_TARGA, /* Targa format */ >- FMT_TIFF /* TIFF format */ >-} IMAGE_FORMATS; >- >-#ifndef DEFAULT_FMT /* so can override from CFLAGS in Makefile */ >-#define DEFAULT_FMT FMT_PPM >-#endif >- >-static IMAGE_FORMATS requested_fmt; >- >- >-/* >- * Argument-parsing code. >- * The switch parser is designed to be useful with DOS-style command line >- * syntax, ie, intermixed switches and file names, where only the switches >- * to the left of a given file name affect processing of that file. >- * The main program in this file doesn't actually use this capability... >- */ >- >- >-static const char * progname; /* program name for error messages */ >-static char * outfilename; /* for -outfile switch */ >- >- >-LOCAL(void) >-usage (void) >-/* complain about bad command line */ >-{ >- fprintf(stderr, "usage: %s [switches] ", progname); >-#ifdef TWO_FILE_COMMANDLINE >- fprintf(stderr, "inputfile outputfile\n"); >-#else >- fprintf(stderr, "[inputfile]\n"); >-#endif >- >- fprintf(stderr, "Switches (names may be abbreviated):\n"); >- fprintf(stderr, " -colors N Reduce image to no more than N colors\n"); >- fprintf(stderr, " -fast Fast, low-quality processing\n"); >- fprintf(stderr, " -grayscale Force grayscale output\n"); >-#ifdef IDCT_SCALING_SUPPORTED >- fprintf(stderr, " -scale M/N Scale output image by fraction M/N, eg, 1/8\n"); >-#endif >-#ifdef BMP_SUPPORTED >- fprintf(stderr, " -bmp Select BMP output format (Windows style)%s\n", >- (DEFAULT_FMT == FMT_BMP ? " (default)" : "")); >-#endif >-#ifdef GIF_SUPPORTED >- fprintf(stderr, " -gif Select GIF output format%s\n", >- (DEFAULT_FMT == FMT_GIF ? " (default)" : "")); >-#endif >-#ifdef BMP_SUPPORTED >- fprintf(stderr, " -os2 Select BMP output format (OS/2 style)%s\n", >- (DEFAULT_FMT == FMT_OS2 ? " (default)" : "")); >-#endif >-#ifdef PPM_SUPPORTED >- fprintf(stderr, " -pnm Select PBMPLUS (PPM/PGM) output format%s\n", >- (DEFAULT_FMT == FMT_PPM ? " (default)" : "")); >-#endif >-#ifdef RLE_SUPPORTED >- fprintf(stderr, " -rle Select Utah RLE output format%s\n", >- (DEFAULT_FMT == FMT_RLE ? " (default)" : "")); >-#endif >-#ifdef TARGA_SUPPORTED >- fprintf(stderr, " -targa Select Targa output format%s\n", >- (DEFAULT_FMT == FMT_TARGA ? " (default)" : "")); >-#endif >- fprintf(stderr, "Switches for advanced users:\n"); >-#ifdef DCT_ISLOW_SUPPORTED >- fprintf(stderr, " -dct int Use integer DCT method%s\n", >- (JDCT_DEFAULT == JDCT_ISLOW ? " (default)" : "")); >-#endif >-#ifdef DCT_IFAST_SUPPORTED >- fprintf(stderr, " -dct fast Use fast integer DCT (less accurate)%s\n", >- (JDCT_DEFAULT == JDCT_IFAST ? " (default)" : "")); >-#endif >-#ifdef DCT_FLOAT_SUPPORTED >- fprintf(stderr, " -dct float Use floating-point DCT method%s\n", >- (JDCT_DEFAULT == JDCT_FLOAT ? " (default)" : "")); >-#endif >- fprintf(stderr, " -dither fs Use F-S dithering (default)\n"); >- fprintf(stderr, " -dither none Don't use dithering in quantization\n"); >- fprintf(stderr, " -dither ordered Use ordered dither (medium speed, quality)\n"); >-#ifdef QUANT_2PASS_SUPPORTED >- fprintf(stderr, " -map FILE Map to colors used in named image file\n"); >-#endif >- fprintf(stderr, " -nosmooth Don't use high-quality upsampling\n"); >-#ifdef QUANT_1PASS_SUPPORTED >- fprintf(stderr, " -onepass Use 1-pass quantization (fast, low quality)\n"); >-#endif >- fprintf(stderr, " -maxmemory N Maximum memory to use (in kbytes)\n"); >- fprintf(stderr, " -outfile name Specify name for output file\n"); >- fprintf(stderr, " -verbose or -debug Emit debug output\n"); >- exit(EXIT_FAILURE); >-} >- >- >-LOCAL(int) >-parse_switches (j_decompress_ptr cinfo, int argc, char **argv, >- int last_file_arg_seen, boolean for_real) >-/* Parse optional switches. >- * Returns argv[] index of first file-name argument (== argc if none). >- * Any file names with indexes <= last_file_arg_seen are ignored; >- * they have presumably been processed in a previous iteration. >- * (Pass 0 for last_file_arg_seen on the first or only iteration.) >- * for_real is FALSE on the first (dummy) pass; we may skip any expensive >- * processing. >- */ >-{ >- int argn; >- char * arg; >- >- /* Set up default JPEG parameters. */ >- requested_fmt = DEFAULT_FMT; /* set default output file format */ >- outfilename = NULL; >- cinfo->err->trace_level = 0; >- >- /* Scan command line options, adjust parameters */ >- >- for (argn = 1; argn < argc; argn++) { >- arg = argv[argn]; >- if (*arg != '-') { >- /* Not a switch, must be a file name argument */ >- if (argn <= last_file_arg_seen) { >- outfilename = NULL; /* -outfile applies to just one input file */ >- continue; /* ignore this name if previously processed */ >- } >- break; /* else done parsing switches */ >- } >- arg++; /* advance past switch marker character */ >- >- if (keymatch(arg, "bmp", 1)) { >- /* BMP output format. */ >- requested_fmt = FMT_BMP; >- >- } else if (keymatch(arg, "colors", 1) || keymatch(arg, "colours", 1) || >- keymatch(arg, "quantize", 1) || keymatch(arg, "quantise", 1)) { >- /* Do color quantization. */ >- int val; >- >- if (++argn >= argc) /* advance to next argument */ >- usage(); >- if (sscanf(argv[argn], "%d", &val) != 1) >- usage(); >- cinfo->desired_number_of_colors = val; >- cinfo->quantize_colors = TRUE; >- >- } else if (keymatch(arg, "dct", 2)) { >- /* Select IDCT algorithm. */ >- if (++argn >= argc) /* advance to next argument */ >- usage(); >- if (keymatch(argv[argn], "int", 1)) { >- cinfo->dct_method = JDCT_ISLOW; >- } else if (keymatch(argv[argn], "fast", 2)) { >- cinfo->dct_method = JDCT_IFAST; >- } else if (keymatch(argv[argn], "float", 2)) { >- cinfo->dct_method = JDCT_FLOAT; >- } else >- usage(); >- >- } else if (keymatch(arg, "dither", 2)) { >- /* Select dithering algorithm. */ >- if (++argn >= argc) /* advance to next argument */ >- usage(); >- if (keymatch(argv[argn], "fs", 2)) { >- cinfo->dither_mode = JDITHER_FS; >- } else if (keymatch(argv[argn], "none", 2)) { >- cinfo->dither_mode = JDITHER_NONE; >- } else if (keymatch(argv[argn], "ordered", 2)) { >- cinfo->dither_mode = JDITHER_ORDERED; >- } else >- usage(); >- >- } else if (keymatch(arg, "debug", 1) || keymatch(arg, "verbose", 1)) { >- /* Enable debug printouts. */ >- /* On first -d, print version identification */ >- static boolean printed_version = FALSE; >- >- if (! printed_version) { >- fprintf(stderr, "Independent JPEG Group's DJPEG, version %s\n%s\n", >- JVERSION, JCOPYRIGHT); >- printed_version = TRUE; >- } >- cinfo->err->trace_level++; >- >- } else if (keymatch(arg, "fast", 1)) { >- /* Select recommended processing options for quick-and-dirty output. */ >- cinfo->two_pass_quantize = FALSE; >- cinfo->dither_mode = JDITHER_ORDERED; >- if (! cinfo->quantize_colors) /* don't override an earlier -colors */ >- cinfo->desired_number_of_colors = 216; >- cinfo->dct_method = JDCT_FASTEST; >- cinfo->do_fancy_upsampling = FALSE; >- >- } else if (keymatch(arg, "gif", 1)) { >- /* GIF output format. */ >- requested_fmt = FMT_GIF; >- >- } else if (keymatch(arg, "grayscale", 2) || keymatch(arg, "greyscale",2)) { >- /* Force monochrome output. */ >- cinfo->out_color_space = JCS_GRAYSCALE; >- >- } else if (keymatch(arg, "map", 3)) { >- /* Quantize to a color map taken from an input file. */ >- if (++argn >= argc) /* advance to next argument */ >- usage(); >- if (for_real) { /* too expensive to do twice! */ >-#ifdef QUANT_2PASS_SUPPORTED /* otherwise can't quantize to supplied map */ >- FILE * mapfile; >- >- if ((mapfile = fopen(argv[argn], READ_BINARY)) == NULL) { >- fprintf(stderr, "%s: can't open %s\n", progname, argv[argn]); >- exit(EXIT_FAILURE); >- } >- read_color_map(cinfo, mapfile); >- fclose(mapfile); >- cinfo->quantize_colors = TRUE; >-#else >- ERREXIT(cinfo, JERR_NOT_COMPILED); >-#endif >- } >- >- } else if (keymatch(arg, "maxmemory", 3)) { >- /* Maximum memory in Kb (or Mb with 'm'). */ >- long lval; >- char ch = 'x'; >- >- if (++argn >= argc) /* advance to next argument */ >- usage(); >- if (sscanf(argv[argn], "%ld%c", &lval, &ch) < 1) >- usage(); >- if (ch == 'm' || ch == 'M') >- lval *= 1000L; >- cinfo->mem->max_memory_to_use = lval * 1000L; >- >- } else if (keymatch(arg, "nosmooth", 3)) { >- /* Suppress fancy upsampling */ >- cinfo->do_fancy_upsampling = FALSE; >- >- } else if (keymatch(arg, "onepass", 3)) { >- /* Use fast one-pass quantization. */ >- cinfo->two_pass_quantize = FALSE; >- >- } else if (keymatch(arg, "os2", 3)) { >- /* BMP output format (OS/2 flavor). */ >- requested_fmt = FMT_OS2; >- >- } else if (keymatch(arg, "outfile", 4)) { >- /* Set output file name. */ >- if (++argn >= argc) /* advance to next argument */ >- usage(); >- outfilename = argv[argn]; /* save it away for later use */ >- >- } else if (keymatch(arg, "pnm", 1) || keymatch(arg, "ppm", 1)) { >- /* PPM/PGM output format. */ >- requested_fmt = FMT_PPM; >- >- } else if (keymatch(arg, "rle", 1)) { >- /* RLE output format. */ >- requested_fmt = FMT_RLE; >- >- } else if (keymatch(arg, "scale", 1)) { >- /* Scale the output image by a fraction M/N. */ >- if (++argn >= argc) /* advance to next argument */ >- usage(); >- if (sscanf(argv[argn], "%d/%d", >- &cinfo->scale_num, &cinfo->scale_denom) != 2) >- usage(); >- >- } else if (keymatch(arg, "targa", 1)) { >- /* Targa output format. */ >- requested_fmt = FMT_TARGA; >- >- } else { >- usage(); /* bogus switch */ >- } >- } >- >- return argn; /* return index of next arg (file name) */ >-} >- >- >-/* >- * Marker processor for COM and interesting APPn markers. >- * This replaces the library's built-in processor, which just skips the marker. >- * We want to print out the marker as text, to the extent possible. >- * Note this code relies on a non-suspending data source. >- */ >- >-LOCAL(unsigned int) >-jpeg_getc (j_decompress_ptr cinfo) >-/* Read next byte */ >-{ >- struct jpeg_source_mgr * datasrc = cinfo->src; >- >- if (datasrc->bytes_in_buffer == 0) { >- if (! (*datasrc->fill_input_buffer) (cinfo)) >- ERREXIT(cinfo, JERR_CANT_SUSPEND); >- } >- datasrc->bytes_in_buffer--; >- return GETJOCTET(*datasrc->next_input_byte++); >-} >- >- >-METHODDEF(boolean) >-print_text_marker (j_decompress_ptr cinfo) >-{ >- boolean traceit = (cinfo->err->trace_level >= 1); >- INT32 length; >- unsigned int ch; >- unsigned int lastch = 0; >- >- length = jpeg_getc(cinfo) << 8; >- length += jpeg_getc(cinfo); >- length -= 2; /* discount the length word itself */ >- >- if (traceit) { >- if (cinfo->unread_marker == JPEG_COM) >- fprintf(stderr, "Comment, length %ld:\n", (long) length); >- else /* assume it is an APPn otherwise */ >- fprintf(stderr, "APP%d, length %ld:\n", >- cinfo->unread_marker - JPEG_APP0, (long) length); >- } >- >- while (--length >= 0) { >- ch = jpeg_getc(cinfo); >- if (traceit) { >- /* Emit the character in a readable form. >- * Nonprintables are converted to \nnn form, >- * while \ is converted to \\. >- * Newlines in CR, CR/LF, or LF form will be printed as one newline. >- */ >- if (ch == '\r') { >- fprintf(stderr, "\n"); >- } else if (ch == '\n') { >- if (lastch != '\r') >- fprintf(stderr, "\n"); >- } else if (ch == '\\') { >- fprintf(stderr, "\\\\"); >- } else if (isprint(ch)) { >- putc(ch, stderr); >- } else { >- fprintf(stderr, "\\%03o", ch); >- } >- lastch = ch; >- } >- } >- >- if (traceit) >- fprintf(stderr, "\n"); >- >- return TRUE; >-} >- >- >-/* >- * The main program. >- */ >- >-int >-main (int argc, char **argv) >-{ >- struct jpeg_decompress_struct cinfo; >- struct jpeg_error_mgr jerr; >-#ifdef PROGRESS_REPORT >- struct cdjpeg_progress_mgr progress; >-#endif >- int file_index; >- djpeg_dest_ptr dest_mgr = NULL; >- FILE * input_file; >- FILE * output_file; >- JDIMENSION num_scanlines; >- >- /* On Mac, fetch a command line. */ >-#ifdef USE_CCOMMAND >- argc = ccommand(&argv); >-#endif >- >- progname = argv[0]; >- if (progname == NULL || progname[0] == 0) >- progname = "djpeg"; /* in case C library doesn't provide it */ >- >- /* Initialize the JPEG decompression object with default error handling. */ >- cinfo.err = jpeg_std_error(&jerr); >- jpeg_create_decompress(&cinfo); >- /* Add some application-specific error messages (from cderror.h) */ >- jerr.addon_message_table = cdjpeg_message_table; >- jerr.first_addon_message = JMSG_FIRSTADDONCODE; >- jerr.last_addon_message = JMSG_LASTADDONCODE; >- >- /* Insert custom marker processor for COM and APP12. >- * APP12 is used by some digital camera makers for textual info, >- * so we provide the ability to display it as text. >- * If you like, additional APPn marker types can be selected for display, >- * but don't try to override APP0 or APP14 this way (see libjpeg.doc). >- */ >- jpeg_set_marker_processor(&cinfo, JPEG_COM, print_text_marker); >- jpeg_set_marker_processor(&cinfo, JPEG_APP0+12, print_text_marker); >- >- /* Now safe to enable signal catcher. */ >-#ifdef NEED_SIGNAL_CATCHER >- enable_signal_catcher((j_common_ptr) &cinfo); >-#endif >- >- /* Scan command line to find file names. */ >- /* It is convenient to use just one switch-parsing routine, but the switch >- * values read here are ignored; we will rescan the switches after opening >- * the input file. >- * (Exception: tracing level set here controls verbosity for COM markers >- * found during jpeg_read_header...) >- */ >- >- file_index = parse_switches(&cinfo, argc, argv, 0, FALSE); >- >-#ifdef TWO_FILE_COMMANDLINE >- /* Must have either -outfile switch or explicit output file name */ >- if (outfilename == NULL) { >- if (file_index != argc-2) { >- fprintf(stderr, "%s: must name one input and one output file\n", >- progname); >- usage(); >- } >- outfilename = argv[file_index+1]; >- } else { >- if (file_index != argc-1) { >- fprintf(stderr, "%s: must name one input and one output file\n", >- progname); >- usage(); >- } >- } >-#else >- /* Unix style: expect zero or one file name */ >- if (file_index < argc-1) { >- fprintf(stderr, "%s: only one input file\n", progname); >- usage(); >- } >-#endif /* TWO_FILE_COMMANDLINE */ >- >- /* Open the input file. */ >- if (file_index < argc) { >- if ((input_file = fopen(argv[file_index], READ_BINARY)) == NULL) { >- fprintf(stderr, "%s: can't open %s\n", progname, argv[file_index]); >- exit(EXIT_FAILURE); >- } >- } else { >- /* default input file is stdin */ >- input_file = read_stdin(); >- } >- >- /* Open the output file. */ >- if (outfilename != NULL) { >- if ((output_file = fopen(outfilename, WRITE_BINARY)) == NULL) { >- fprintf(stderr, "%s: can't open %s\n", progname, outfilename); >- exit(EXIT_FAILURE); >- } >- } else { >- /* default output file is stdout */ >- output_file = write_stdout(); >- } >- >-#ifdef PROGRESS_REPORT >- start_progress_monitor((j_common_ptr) &cinfo, &progress); >-#endif >- >- /* Specify data source for decompression */ >- jpeg_stdio_src(&cinfo, input_file); >- >- /* Read file header, set default decompression parameters */ >- (void) jpeg_read_header(&cinfo, TRUE); >- >- /* Adjust default decompression parameters by re-parsing the options */ >- file_index = parse_switches(&cinfo, argc, argv, 0, TRUE); >- >- /* Initialize the output module now to let it override any crucial >- * option settings (for instance, GIF wants to force color quantization). >- */ >- switch (requested_fmt) { >-#ifdef BMP_SUPPORTED >- case FMT_BMP: >- dest_mgr = jinit_write_bmp(&cinfo, FALSE); >- break; >- case FMT_OS2: >- dest_mgr = jinit_write_bmp(&cinfo, TRUE); >- break; >-#endif >-#ifdef GIF_SUPPORTED >- case FMT_GIF: >- dest_mgr = jinit_write_gif(&cinfo); >- break; >-#endif >-#ifdef PPM_SUPPORTED >- case FMT_PPM: >- dest_mgr = jinit_write_ppm(&cinfo); >- break; >-#endif >-#ifdef RLE_SUPPORTED >- case FMT_RLE: >- dest_mgr = jinit_write_rle(&cinfo); >- break; >-#endif >-#ifdef TARGA_SUPPORTED >- case FMT_TARGA: >- dest_mgr = jinit_write_targa(&cinfo); >- break; >-#endif >- default: >- ERREXIT(&cinfo, JERR_UNSUPPORTED_FORMAT); >- break; >- } >- dest_mgr->output_file = output_file; >- >- /* Start decompressor */ >- (void) jpeg_start_decompress(&cinfo); >- >- /* Write output file header */ >- (*dest_mgr->start_output) (&cinfo, dest_mgr); >- >- /* Process data */ >- while (cinfo.output_scanline < cinfo.output_height) { >- num_scanlines = jpeg_read_scanlines(&cinfo, dest_mgr->buffer, >- dest_mgr->buffer_height); >- (*dest_mgr->put_pixel_rows) (&cinfo, dest_mgr, num_scanlines); >- } >- >-#ifdef PROGRESS_REPORT >- /* Hack: count final pass as done in case finish_output does an extra pass. >- * The library won't have updated completed_passes. >- */ >- progress.pub.completed_passes = progress.pub.total_passes; >-#endif >- >- /* Finish decompression and release memory. >- * I must do it in this order because output module has allocated memory >- * of lifespan JPOOL_IMAGE; it needs to finish before releasing memory. >- */ >- (*dest_mgr->finish_output) (&cinfo, dest_mgr); >- (void) jpeg_finish_decompress(&cinfo); >- jpeg_destroy_decompress(&cinfo); >- >- /* Close files, if we opened them */ >- if (input_file != stdin) >- fclose(input_file); >- if (output_file != stdout) >- fclose(output_file); >- >-#ifdef PROGRESS_REPORT >- end_progress_monitor((j_common_ptr) &cinfo); >-#endif >- >- /* All done. */ >- exit(jerr.num_warnings ? EXIT_WARNING : EXIT_SUCCESS); >- return 0; /* suppress no-return-value warnings */ >-} >only in patch2: >--- a/jpeg/example.c >+++ /dev/null >@@ -1,433 +0,0 @@ >-/* >- * example.c >- * >- * This file illustrates how to use the IJG code as a subroutine library >- * to read or write JPEG image files. You should look at this code in >- * conjunction with the documentation file libjpeg.doc. >- * >- * This code will not do anything useful as-is, but it may be helpful as a >- * skeleton for constructing routines that call the JPEG library. >- * >- * We present these routines in the same coding style used in the JPEG code >- * (ANSI function definitions, etc); but you are of course free to code your >- * routines in a different style if you prefer. >- */ >- >-#include <stdio.h> >- >-/* >- * Include file for users of JPEG library. >- * You will need to have included system headers that define at least >- * the typedefs FILE and size_t before you can include jpeglib.h. >- * (stdio.h is sufficient on ANSI-conforming systems.) >- * You may also wish to include "jerror.h". >- */ >- >-#include "jpeglib.h" >- >-/* >- * <setjmp.h> is used for the optional error recovery mechanism shown in >- * the second part of the example. >- */ >- >-#include <setjmp.h> >- >- >- >-/******************** JPEG COMPRESSION SAMPLE INTERFACE *******************/ >- >-/* This half of the example shows how to feed data into the JPEG compressor. >- * We present a minimal version that does not worry about refinements such >- * as error recovery (the JPEG code will just exit() if it gets an error). >- */ >- >- >-/* >- * IMAGE DATA FORMATS: >- * >- * The standard input image format is a rectangular array of pixels, with >- * each pixel having the same number of "component" values (color channels). >- * Each pixel row is an array of JSAMPLEs (which typically are unsigned chars). >- * If you are working with color data, then the color values for each pixel >- * must be adjacent in the row; for example, R,G,B,R,G,B,R,G,B,... for 24-bit >- * RGB color. >- * >- * For this example, we'll assume that this data structure matches the way >- * our application has stored the image in memory, so we can just pass a >- * pointer to our image buffer. In particular, let's say that the image is >- * RGB color and is described by: >- */ >- >-extern JSAMPLE * image_buffer; /* Points to large array of R,G,B-order data */ >-extern int image_height; /* Number of rows in image */ >-extern int image_width; /* Number of columns in image */ >- >- >-/* >- * Sample routine for JPEG compression. We assume that the target file name >- * and a compression quality factor are passed in. >- */ >- >-GLOBAL(void) >-write_JPEG_file (char * filename, int quality) >-{ >- /* This struct contains the JPEG compression parameters and pointers to >- * working space (which is allocated as needed by the JPEG library). >- * It is possible to have several such structures, representing multiple >- * compression/decompression processes, in existence at once. We refer >- * to any one struct (and its associated working data) as a "JPEG object". >- */ >- struct jpeg_compress_struct cinfo; >- /* This struct represents a JPEG error handler. It is declared separately >- * because applications often want to supply a specialized error handler >- * (see the second half of this file for an example). But here we just >- * take the easy way out and use the standard error handler, which will >- * print a message on stderr and call exit() if compression fails. >- * Note that this struct must live as long as the main JPEG parameter >- * struct, to avoid dangling-pointer problems. >- */ >- struct jpeg_error_mgr jerr; >- /* More stuff */ >- FILE * outfile; /* target file */ >- JSAMPROW row_pointer[1]; /* pointer to JSAMPLE row[s] */ >- int row_stride; /* physical row width in image buffer */ >- >- /* Step 1: allocate and initialize JPEG compression object */ >- >- /* We have to set up the error handler first, in case the initialization >- * step fails. (Unlikely, but it could happen if you are out of memory.) >- * This routine fills in the contents of struct jerr, and returns jerr's >- * address which we place into the link field in cinfo. >- */ >- cinfo.err = jpeg_std_error(&jerr); >- /* Now we can initialize the JPEG compression object. */ >- jpeg_create_compress(&cinfo); >- >- /* Step 2: specify data destination (eg, a file) */ >- /* Note: steps 2 and 3 can be done in either order. */ >- >- /* Here we use the library-supplied code to send compressed data to a >- * stdio stream. You can also write your own code to do something else. >- * VERY IMPORTANT: use "b" option to fopen() if you are on a machine that >- * requires it in order to write binary files. >- */ >- if ((outfile = fopen(filename, "wb")) == NULL) { >- fprintf(stderr, "can't open %s\n", filename); >- exit(1); >- } >- jpeg_stdio_dest(&cinfo, outfile); >- >- /* Step 3: set parameters for compression */ >- >- /* First we supply a description of the input image. >- * Four fields of the cinfo struct must be filled in: >- */ >- cinfo.image_width = image_width; /* image width and height, in pixels */ >- cinfo.image_height = image_height; >- cinfo.input_components = 3; /* # of color components per pixel */ >- cinfo.in_color_space = JCS_RGB; /* colorspace of input image */ >- /* Now use the library's routine to set default compression parameters. >- * (You must set at least cinfo.in_color_space before calling this, >- * since the defaults depend on the source color space.) >- */ >- jpeg_set_defaults(&cinfo); >- /* Now you can set any non-default parameters you wish to. >- * Here we just illustrate the use of quality (quantization table) scaling: >- */ >- jpeg_set_quality(&cinfo, quality, TRUE /* limit to baseline-JPEG values */); >- >- /* Step 4: Start compressor */ >- >- /* TRUE ensures that we will write a complete interchange-JPEG file. >- * Pass TRUE unless you are very sure of what you're doing. >- */ >- jpeg_start_compress(&cinfo, TRUE); >- >- /* Step 5: while (scan lines remain to be written) */ >- /* jpeg_write_scanlines(...); */ >- >- /* Here we use the library's state variable cinfo.next_scanline as the >- * loop counter, so that we don't have to keep track ourselves. >- * To keep things simple, we pass one scanline per call; you can pass >- * more if you wish, though. >- */ >- row_stride = image_width * 3; /* JSAMPLEs per row in image_buffer */ >- >- while (cinfo.next_scanline < cinfo.image_height) { >- /* jpeg_write_scanlines expects an array of pointers to scanlines. >- * Here the array is only one element long, but you could pass >- * more than one scanline at a time if that's more convenient. >- */ >- row_pointer[0] = & image_buffer[cinfo.next_scanline * row_stride]; >- (void) jpeg_write_scanlines(&cinfo, row_pointer, 1); >- } >- >- /* Step 6: Finish compression */ >- >- jpeg_finish_compress(&cinfo); >- /* After finish_compress, we can close the output file. */ >- fclose(outfile); >- >- /* Step 7: release JPEG compression object */ >- >- /* This is an important step since it will release a good deal of memory. */ >- jpeg_destroy_compress(&cinfo); >- >- /* And we're done! */ >-} >- >- >-/* >- * SOME FINE POINTS: >- * >- * In the above loop, we ignored the return value of jpeg_write_scanlines, >- * which is the number of scanlines actually written. We could get away >- * with this because we were only relying on the value of cinfo.next_scanline, >- * which will be incremented correctly. If you maintain additional loop >- * variables then you should be careful to increment them properly. >- * Actually, for output to a stdio stream you needn't worry, because >- * then jpeg_write_scanlines will write all the lines passed (or else exit >- * with a fatal error). Partial writes can only occur if you use a data >- * destination module that can demand suspension of the compressor. >- * (If you don't know what that's for, you don't need it.) >- * >- * If the compressor requires full-image buffers (for entropy-coding >- * optimization or a multi-scan JPEG file), it will create temporary >- * files for anything that doesn't fit within the maximum-memory setting. >- * (Note that temp files are NOT needed if you use the default parameters.) >- * On some systems you may need to set up a signal handler to ensure that >- * temporary files are deleted if the program is interrupted. See libjpeg.doc. >- * >- * Scanlines MUST be supplied in top-to-bottom order if you want your JPEG >- * files to be compatible with everyone else's. If you cannot readily read >- * your data in that order, you'll need an intermediate array to hold the >- * image. See rdtarga.c or rdbmp.c for examples of handling bottom-to-top >- * source data using the JPEG code's internal virtual-array mechanisms. >- */ >- >- >- >-/******************** JPEG DECOMPRESSION SAMPLE INTERFACE *******************/ >- >-/* This half of the example shows how to read data from the JPEG decompressor. >- * It's a bit more refined than the above, in that we show: >- * (a) how to modify the JPEG library's standard error-reporting behavior; >- * (b) how to allocate workspace using the library's memory manager. >- * >- * Just to make this example a little different from the first one, we'll >- * assume that we do not intend to put the whole image into an in-memory >- * buffer, but to send it line-by-line someplace else. We need a one- >- * scanline-high JSAMPLE array as a work buffer, and we will let the JPEG >- * memory manager allocate it for us. This approach is actually quite useful >- * because we don't need to remember to deallocate the buffer separately: it >- * will go away automatically when the JPEG object is cleaned up. >- */ >- >- >-/* >- * ERROR HANDLING: >- * >- * The JPEG library's standard error handler (jerror.c) is divided into >- * several "methods" which you can override individually. This lets you >- * adjust the behavior without duplicating a lot of code, which you might >- * have to update with each future release. >- * >- * Our example here shows how to override the "error_exit" method so that >- * control is returned to the library's caller when a fatal error occurs, >- * rather than calling exit() as the standard error_exit method does. >- * >- * We use C's setjmp/longjmp facility to return control. This means that the >- * routine which calls the JPEG library must first execute a setjmp() call to >- * establish the return point. We want the replacement error_exit to do a >- * longjmp(). But we need to make the setjmp buffer accessible to the >- * error_exit routine. To do this, we make a private extension of the >- * standard JPEG error handler object. (If we were using C++, we'd say we >- * were making a subclass of the regular error handler.) >- * >- * Here's the extended error handler struct: >- */ >- >-struct my_error_mgr { >- struct jpeg_error_mgr pub; /* "public" fields */ >- >- jmp_buf setjmp_buffer; /* for return to caller */ >-}; >- >-typedef struct my_error_mgr * my_error_ptr; >- >-/* >- * Here's the routine that will replace the standard error_exit method: >- */ >- >-METHODDEF(void) >-my_error_exit (j_common_ptr cinfo) >-{ >- /* cinfo->err really points to a my_error_mgr struct, so coerce pointer */ >- my_error_ptr myerr = (my_error_ptr) cinfo->err; >- >- /* Always display the message. */ >- /* We could postpone this until after returning, if we chose. */ >- (*cinfo->err->output_message) (cinfo); >- >- /* Return control to the setjmp point */ >- longjmp(myerr->setjmp_buffer, 1); >-} >- >- >-/* >- * Sample routine for JPEG decompression. We assume that the source file name >- * is passed in. We want to return 1 on success, 0 on error. >- */ >- >- >-GLOBAL(int) >-read_JPEG_file (char * filename) >-{ >- /* This struct contains the JPEG decompression parameters and pointers to >- * working space (which is allocated as needed by the JPEG library). >- */ >- struct jpeg_decompress_struct cinfo; >- /* We use our private extension JPEG error handler. >- * Note that this struct must live as long as the main JPEG parameter >- * struct, to avoid dangling-pointer problems. >- */ >- struct my_error_mgr jerr; >- /* More stuff */ >- FILE * infile; /* source file */ >- JSAMPARRAY buffer; /* Output row buffer */ >- int row_stride; /* physical row width in output buffer */ >- >- /* In this example we want to open the input file before doing anything else, >- * so that the setjmp() error recovery below can assume the file is open. >- * VERY IMPORTANT: use "b" option to fopen() if you are on a machine that >- * requires it in order to read binary files. >- */ >- >- if ((infile = fopen(filename, "rb")) == NULL) { >- fprintf(stderr, "can't open %s\n", filename); >- return 0; >- } >- >- /* Step 1: allocate and initialize JPEG decompression object */ >- >- /* We set up the normal JPEG error routines, then override error_exit. */ >- cinfo.err = jpeg_std_error(&jerr.pub); >- jerr.pub.error_exit = my_error_exit; >- /* Establish the setjmp return context for my_error_exit to use. */ >- if (setjmp(jerr.setjmp_buffer)) { >- /* If we get here, the JPEG code has signaled an error. >- * We need to clean up the JPEG object, close the input file, and return. >- */ >- jpeg_destroy_decompress(&cinfo); >- fclose(infile); >- return 0; >- } >- /* Now we can initialize the JPEG decompression object. */ >- jpeg_create_decompress(&cinfo); >- >- /* Step 2: specify data source (eg, a file) */ >- >- jpeg_stdio_src(&cinfo, infile); >- >- /* Step 3: read file parameters with jpeg_read_header() */ >- >- (void) jpeg_read_header(&cinfo, TRUE); >- /* We can ignore the return value from jpeg_read_header since >- * (a) suspension is not possible with the stdio data source, and >- * (b) we passed TRUE to reject a tables-only JPEG file as an error. >- * See libjpeg.doc for more info. >- */ >- >- /* Step 4: set parameters for decompression */ >- >- /* In this example, we don't need to change any of the defaults set by >- * jpeg_read_header(), so we do nothing here. >- */ >- >- /* Step 5: Start decompressor */ >- >- (void) jpeg_start_decompress(&cinfo); >- /* We can ignore the return value since suspension is not possible >- * with the stdio data source. >- */ >- >- /* We may need to do some setup of our own at this point before reading >- * the data. After jpeg_start_decompress() we have the correct scaled >- * output image dimensions available, as well as the output colormap >- * if we asked for color quantization. >- * In this example, we need to make an output work buffer of the right size. >- */ >- /* JSAMPLEs per row in output buffer */ >- row_stride = cinfo.output_width * cinfo.output_components; >- /* Make a one-row-high sample array that will go away when done with image */ >- buffer = (*cinfo.mem->alloc_sarray) >- ((j_common_ptr) &cinfo, JPOOL_IMAGE, row_stride, 1); >- >- /* Step 6: while (scan lines remain to be read) */ >- /* jpeg_read_scanlines(...); */ >- >- /* Here we use the library's state variable cinfo.output_scanline as the >- * loop counter, so that we don't have to keep track ourselves. >- */ >- while (cinfo.output_scanline < cinfo.output_height) { >- /* jpeg_read_scanlines expects an array of pointers to scanlines. >- * Here the array is only one element long, but you could ask for >- * more than one scanline at a time if that's more convenient. >- */ >- (void) jpeg_read_scanlines(&cinfo, buffer, 1); >- /* Assume put_scanline_someplace wants a pointer and sample count. */ >- put_scanline_someplace(buffer[0], row_stride); >- } >- >- /* Step 7: Finish decompression */ >- >- (void) jpeg_finish_decompress(&cinfo); >- /* We can ignore the return value since suspension is not possible >- * with the stdio data source. >- */ >- >- /* Step 8: Release JPEG decompression object */ >- >- /* This is an important step since it will release a good deal of memory. */ >- jpeg_destroy_decompress(&cinfo); >- >- /* After finish_decompress, we can close the input file. >- * Here we postpone it until after no more JPEG errors are possible, >- * so as to simplify the setjmp error logic above. (Actually, I don't >- * think that jpeg_destroy can do an error exit, but why assume anything...) >- */ >- fclose(infile); >- >- /* At this point you may want to check to see whether any corrupt-data >- * warnings occurred (test whether jerr.pub.num_warnings is nonzero). >- */ >- >- /* And we're done! */ >- return 1; >-} >- >- >-/* >- * SOME FINE POINTS: >- * >- * In the above code, we ignored the return value of jpeg_read_scanlines, >- * which is the number of scanlines actually read. We could get away with >- * this because we asked for only one line at a time and we weren't using >- * a suspending data source. See libjpeg.doc for more info. >- * >- * We cheated a bit by calling alloc_sarray() after jpeg_start_decompress(); >- * we should have done it beforehand to ensure that the space would be >- * counted against the JPEG max_memory setting. In some systems the above >- * code would risk an out-of-memory error. However, in general we don't >- * know the output image dimensions before jpeg_start_decompress(), unless we >- * call jpeg_calc_output_dimensions(). See libjpeg.doc for more about this. >- * >- * Scanlines are returned in the same order as they appear in the JPEG file, >- * which is standardly top-to-bottom. If you must emit data bottom-to-top, >- * you can use one of the virtual arrays provided by the JPEG memory manager >- * to invert the data. See wrbmp.c for an example. >- * >- * As with compression, some operating modes may require temporary files. >- * On some systems you may need to set up a signal handler to ensure that >- * temporary files are deleted if the program is interrupted. See libjpeg.doc. >- */ >only in patch2: >--- a/jpeg/filelist.doc >+++ /dev/null >@@ -1,210 +0,0 @@ >-IJG JPEG LIBRARY: FILE LIST >- >-Copyright (C) 1994-1998, Thomas G. Lane. >-This file is part of the Independent JPEG Group's software. >-For conditions of distribution and use, see the accompanying README file. >- >- >-Here is a road map to the files in the IJG JPEG distribution. The >-distribution includes the JPEG library proper, plus two application >-programs ("cjpeg" and "djpeg") which use the library to convert JPEG >-files to and from some other popular image formats. A third application >-"jpegtran" uses the library to do lossless conversion between different >-variants of JPEG. There are also two stand-alone applications, >-"rdjpgcom" and "wrjpgcom". >- >- >-THE JPEG LIBRARY >-================ >- >-Include files: >- >-jpeglib.h JPEG library's exported data and function declarations. >-jconfig.h Configuration declarations. Note: this file is not present >- in the distribution; it is generated during installation. >-jmorecfg.h Additional configuration declarations; need not be changed >- for a standard installation. >-jerror.h Declares JPEG library's error and trace message codes. >-jinclude.h Central include file used by all IJG .c files to reference >- system include files. >-jpegint.h JPEG library's internal data structures. >-jchuff.h Private declarations for Huffman encoder modules. >-jdhuff.h Private declarations for Huffman decoder modules. >-jdct.h Private declarations for forward & reverse DCT subsystems. >-jmemsys.h Private declarations for memory management subsystem. >-jversion.h Version information. >- >-Applications using the library should include jpeglib.h (which in turn >-includes jconfig.h and jmorecfg.h). Optionally, jerror.h may be included >-if the application needs to reference individual JPEG error codes. The >-other include files are intended for internal use and would not normally >-be included by an application program. (cjpeg/djpeg/etc do use jinclude.h, >-since its function is to improve portability of the whole IJG distribution. >-Most other applications will directly include the system include files they >-want, and hence won't need jinclude.h.) >- >- >-C source code files: >- >-These files contain most of the functions intended to be called directly by >-an application program: >- >-jcapimin.c Application program interface: core routines for compression. >-jcapistd.c Application program interface: standard compression. >-jdapimin.c Application program interface: core routines for decompression. >-jdapistd.c Application program interface: standard decompression. >-jcomapi.c Application program interface routines common to compression >- and decompression. >-jcparam.c Compression parameter setting helper routines. >-jctrans.c API and library routines for transcoding compression. >-jdtrans.c API and library routines for transcoding decompression. >- >-Compression side of the library: >- >-jcinit.c Initialization: determines which other modules to use. >-jcmaster.c Master control: setup and inter-pass sequencing logic. >-jcmainct.c Main buffer controller (preprocessor => JPEG compressor). >-jcprepct.c Preprocessor buffer controller. >-jccoefct.c Buffer controller for DCT coefficient buffer. >-jccolor.c Color space conversion. >-jcsample.c Downsampling. >-jcdctmgr.c DCT manager (DCT implementation selection & control). >-jfdctint.c Forward DCT using slow-but-accurate integer method. >-jfdctfst.c Forward DCT using faster, less accurate integer method. >-jfdctflt.c Forward DCT using floating-point arithmetic. >-jchuff.c Huffman entropy coding for sequential JPEG. >-jcphuff.c Huffman entropy coding for progressive JPEG. >-jcmarker.c JPEG marker writing. >-jdatadst.c Data destination manager for stdio output. >- >-Decompression side of the library: >- >-jdmaster.c Master control: determines which other modules to use. >-jdinput.c Input controller: controls input processing modules. >-jdmainct.c Main buffer controller (JPEG decompressor => postprocessor). >-jdcoefct.c Buffer controller for DCT coefficient buffer. >-jdpostct.c Postprocessor buffer controller. >-jdmarker.c JPEG marker reading. >-jdhuff.c Huffman entropy decoding for sequential JPEG. >-jdphuff.c Huffman entropy decoding for progressive JPEG. >-jddctmgr.c IDCT manager (IDCT implementation selection & control). >-jidctint.c Inverse DCT using slow-but-accurate integer method. >-jidctfst.c Inverse DCT using faster, less accurate integer method. >-jidctflt.c Inverse DCT using floating-point arithmetic. >-jidctred.c Inverse DCTs with reduced-size outputs. >-jdsample.c Upsampling. >-jdcolor.c Color space conversion. >-jdmerge.c Merged upsampling/color conversion (faster, lower quality). >-jquant1.c One-pass color quantization using a fixed-spacing colormap. >-jquant2.c Two-pass color quantization using a custom-generated colormap. >- Also handles one-pass quantization to an externally given map. >-jdatasrc.c Data source manager for stdio input. >- >-Support files for both compression and decompression: >- >-jerror.c Standard error handling routines (application replaceable). >-jmemmgr.c System-independent (more or less) memory management code. >-jutils.c Miscellaneous utility routines. >- >-jmemmgr.c relies on a system-dependent memory management module. The IJG >-distribution includes the following implementations of the system-dependent >-module: >- >-jmemnobs.c "No backing store": assumes adequate virtual memory exists. >-jmemansi.c Makes temporary files with ANSI-standard routine tmpfile(). >-jmemname.c Makes temporary files with program-generated file names. >-jmemdos.c Custom implementation for MS-DOS (16-bit environment only): >- can use extended and expanded memory as well as temp files. >-jmemmac.c Custom implementation for Apple Macintosh. >- >-Exactly one of the system-dependent modules should be configured into an >-installed JPEG library (see install.doc for hints about which one to use). >-On unusual systems you may find it worthwhile to make a special >-system-dependent memory manager. >- >- >-Non-C source code files: >- >-jmemdosa.asm 80x86 assembly code support for jmemdos.c; used only in >- MS-DOS-specific configurations of the JPEG library. >- >- >-CJPEG/DJPEG/JPEGTRAN >-==================== >- >-Include files: >- >-cdjpeg.h Declarations shared by cjpeg/djpeg/jpegtran modules. >-cderror.h Additional error and trace message codes for cjpeg et al. >-transupp.h Declarations for jpegtran support routines in transupp.c. >- >-C source code files: >- >-cjpeg.c Main program for cjpeg. >-djpeg.c Main program for djpeg. >-jpegtran.c Main program for jpegtran. >-cdjpeg.c Utility routines used by all three programs. >-rdcolmap.c Code to read a colormap file for djpeg's "-map" switch. >-rdswitch.c Code to process some of cjpeg's more complex switches. >- Also used by jpegtran. >-transupp.c Support code for jpegtran: lossless image manipulations. >- >-Image file reader modules for cjpeg: >- >-rdbmp.c BMP file input. >-rdgif.c GIF file input (now just a stub). >-rdppm.c PPM/PGM file input. >-rdrle.c Utah RLE file input. >-rdtarga.c Targa file input. >- >-Image file writer modules for djpeg: >- >-wrbmp.c BMP file output. >-wrgif.c GIF file output (a mere shadow of its former self). >-wrppm.c PPM/PGM file output. >-wrrle.c Utah RLE file output. >-wrtarga.c Targa file output. >- >- >-RDJPGCOM/WRJPGCOM >-================= >- >-C source code files: >- >-rdjpgcom.c Stand-alone rdjpgcom application. >-wrjpgcom.c Stand-alone wrjpgcom application. >- >-These programs do not depend on the IJG library. They do use >-jconfig.h and jinclude.h, only to improve portability. >- >- >-ADDITIONAL FILES >-================ >- >-Documentation (see README for a guide to the documentation files): >- >-README Master documentation file. >-*.doc Other documentation files. >-*.1 Documentation in Unix man page format. >-change.log Version-to-version change highlights. >-example.c Sample code for calling JPEG library. >- >-Configuration/installation files and programs (see install.doc for more info): >- >-configure Unix shell script to perform automatic configuration. >-ltconfig Support scripts for configure (from GNU libtool). >-ltmain.sh >-config.guess >-config.sub >-install-sh Install shell script for those Unix systems lacking one. >-ckconfig.c Program to generate jconfig.h on non-Unix systems. >-jconfig.doc Template for making jconfig.h by hand. >-makefile.* Sample makefiles for particular systems. >-jconfig.* Sample jconfig.h for particular systems. >-ansi2knr.c De-ANSIfier for pre-ANSI C compilers (courtesy of >- L. Peter Deutsch and Aladdin Enterprises). >- >-Test files (see install.doc for test procedure): >- >-test*.* Source and comparison files for confidence test. >- These are binary image files, NOT text files. >only in patch2: >--- a/jpeg/install.doc >+++ /dev/null >@@ -1,1063 +0,0 @@ >-INSTALLATION INSTRUCTIONS for the Independent JPEG Group's JPEG software >- >-Copyright (C) 1991-1998, Thomas G. Lane. >-This file is part of the Independent JPEG Group's software. >-For conditions of distribution and use, see the accompanying README file. >- >- >-This file explains how to configure and install the IJG software. We have >-tried to make this software extremely portable and flexible, so that it can be >-adapted to almost any environment. The downside of this decision is that the >-installation process is complicated. We have provided shortcuts to simplify >-the task on common systems. But in any case, you will need at least a little >-familiarity with C programming and program build procedures for your system. >- >-If you are only using this software as part of a larger program, the larger >-program's installation procedure may take care of configuring the IJG code. >-For example, Ghostscript's installation script will configure the IJG code. >-You don't need to read this file if you just want to compile Ghostscript. >- >-If you are on a Unix machine, you may not need to read this file at all. >-Try doing >- ./configure >- make >- make test >-If that doesn't complain, do >- make install >-(better do "make -n install" first to see if the makefile will put the files >-where you want them). Read further if you run into snags or want to customize >-the code for your system. >- >- >-TABLE OF CONTENTS >------------------ >- >-Before you start >-Configuring the software: >- using the automatic "configure" script >- using one of the supplied jconfig and makefile files >- by hand >-Building the software >-Testing the software >-Installing the software >-Optional stuff >-Optimization >-Hints for specific systems >- >- >-BEFORE YOU START >-================ >- >-Before installing the software you must unpack the distributed source code. >-Since you are reading this file, you have probably already succeeded in this >-task. However, there is a potential for error if you needed to convert the >-files to the local standard text file format (for example, if you are on >-MS-DOS you may have converted LF end-of-line to CR/LF). You must apply >-such conversion to all the files EXCEPT those whose names begin with "test". >-The test files contain binary data; if you change them in any way then the >-self-test will give bad results. >- >-Please check the last section of this file to see if there are hints for the >-specific machine or compiler you are using. >- >- >-CONFIGURING THE SOFTWARE >-======================== >- >-To configure the IJG code for your system, you need to create two files: >- * jconfig.h: contains values for system-dependent #define symbols. >- * Makefile: controls the compilation process. >-(On a non-Unix machine, you may create "project files" or some other >-substitute for a Makefile. jconfig.h is needed in any environment.) >- >-We provide three different ways to generate these files: >- * On a Unix system, you can just run the "configure" script. >- * We provide sample jconfig files and makefiles for popular machines; >- if your machine matches one of the samples, just copy the right sample >- files to jconfig.h and Makefile. >- * If all else fails, read the instructions below and make your own files. >- >- >-Configuring the software using the automatic "configure" script >---------------------------------------------------------------- >- >-If you are on a Unix machine, you can just type >- ./configure >-and let the configure script construct appropriate configuration files. >-If you're using "csh" on an old version of System V, you might need to type >- sh configure >-instead to prevent csh from trying to execute configure itself. >-Expect configure to run for a few minutes, particularly on slower machines; >-it works by compiling a series of test programs. >- >-Configure was created with GNU Autoconf and it follows the usual conventions >-for GNU configure scripts. It makes a few assumptions that you may want to >-override. You can do this by providing optional switches to configure: >- >-* If you want to build libjpeg as a shared library, say >- ./configure --enable-shared >-To get both shared and static libraries, say >- ./configure --enable-shared --enable-static >-Note that these switches invoke GNU libtool to take care of system-dependent >-shared library building methods. If things don't work this way, please try >-running configure without either switch; that should build a static library >-without using libtool. If that works, your problem is probably with libtool >-not with the IJG code. libtool is fairly new and doesn't support all flavors >-of Unix yet. (You might be able to find a newer version of libtool than the >-one included with libjpeg; see ftp.gnu.org. Report libtool problems to >-bug-libtool@gnu.org.) >- >-* Configure will use gcc (GNU C compiler) if it's available, otherwise cc. >-To force a particular compiler to be selected, use the CC option, for example >- ./configure CC='cc' >-The same method can be used to include any unusual compiler switches. >-For example, on HP-UX you probably want to say >- ./configure CC='cc -Aa' >-to get HP's compiler to run in ANSI mode. >- >-* The default CFLAGS setting is "-O" for non-gcc compilers, "-O2" for gcc. >-You can override this by saying, for example, >- ./configure CFLAGS='-g' >-if you want to compile with debugging support. >- >-* Configure will set up the makefile so that "make install" will install files >-into /usr/local/bin, /usr/local/man, etc. You can specify an installation >-prefix other than "/usr/local" by giving configure the option "--prefix=PATH". >- >-* If you don't have a lot of swap space, you may need to enable the IJG >-software's internal virtual memory mechanism. To do this, give the option >-"--enable-maxmem=N" where N is the default maxmemory limit in megabytes. >-This is discussed in more detail under "Selecting a memory manager", below. >-You probably don't need to worry about this on reasonably-sized Unix machines, >-unless you plan to process very large images. >- >-Configure has some other features that are useful if you are cross-compiling >-or working in a network of multiple machine types; but if you need those >-features, you probably already know how to use them. >- >- >-Configuring the software using one of the supplied jconfig and makefile files >------------------------------------------------------------------------------ >- >-If you have one of these systems, you can just use the provided configuration >-files: >- >-Makefile jconfig file System and/or compiler >- >-makefile.manx jconfig.manx Amiga, Manx Aztec C >-makefile.sas jconfig.sas Amiga, SAS C >-makeproj.mac jconfig.mac Apple Macintosh, Metrowerks CodeWarrior >-mak*jpeg.st jconfig.st Atari ST/STE/TT, Pure C or Turbo C >-makefile.bcc jconfig.bcc MS-DOS or OS/2, Borland C >-makefile.dj jconfig.dj MS-DOS, DJGPP (Delorie's port of GNU C) >-makefile.mc6 jconfig.mc6 MS-DOS, Microsoft C (16-bit only) >-makefile.wat jconfig.wat MS-DOS, OS/2, or Windows NT, Watcom C >-makefile.vc jconfig.vc Windows NT/95, MS Visual C++ >-make*.ds jconfig.vc Windows NT/95, MS Developer Studio >-makefile.mms jconfig.vms Digital VMS, with MMS software >-makefile.vms jconfig.vms Digital VMS, without MMS software >- >-Copy the proper jconfig file to jconfig.h and the makefile to Makefile (or >-whatever your system uses as the standard makefile name). For more info see >-the appropriate system-specific hints section near the end of this file. >- >- >-Configuring the software by hand >--------------------------------- >- >-First, generate a jconfig.h file. If you are moderately familiar with C, >-the comments in jconfig.doc should be enough information to do this; just >-copy jconfig.doc to jconfig.h and edit it appropriately. Otherwise, you may >-prefer to use the ckconfig.c program. You will need to compile and execute >-ckconfig.c by hand --- we hope you know at least enough to do that. >-ckconfig.c may not compile the first try (in fact, the whole idea is for it >-to fail if anything is going to). If you get compile errors, fix them by >-editing ckconfig.c according to the directions given in ckconfig.c. Once >-you get it to run, it will write a suitable jconfig.h file, and will also >-print out some advice about which makefile to use. >- >-You may also want to look at the canned jconfig files, if there is one for a >-system similar to yours. >- >-Second, select a makefile and copy it to Makefile (or whatever your system >-uses as the standard makefile name). The most generic makefiles we provide >-are >- makefile.ansi: if your C compiler supports function prototypes >- makefile.unix: if not. >-(You have function prototypes if ckconfig.c put "#define HAVE_PROTOTYPES" >-in jconfig.h.) You may want to start from one of the other makefiles if >-there is one for a system similar to yours. >- >-Look over the selected Makefile and adjust options as needed. In particular >-you may want to change the CC and CFLAGS definitions. For instance, if you >-are using GCC, set CC=gcc. If you had to use any compiler switches to get >-ckconfig.c to work, make sure the same switches are in CFLAGS. >- >-If you are on a system that doesn't use makefiles, you'll need to set up >-project files (or whatever you do use) to compile all the source files and >-link them into executable files cjpeg, djpeg, jpegtran, rdjpgcom, and wrjpgcom. >-See the file lists in any of the makefiles to find out which files go into >-each program. Note that the provided makefiles all make a "library" file >-libjpeg first, but you don't have to do that if you don't want to; the file >-lists identify which source files are actually needed for compression, >-decompression, or both. As a last resort, you can make a batch script that >-just compiles everything and links it all together; makefile.vms is an example >-of this (it's for VMS systems that have no make-like utility). >- >-Here are comments about some specific configuration decisions you'll >-need to make: >- >-Command line style >------------------- >- >-These programs can use a Unix-like command line style which supports >-redirection and piping, like this: >- cjpeg inputfile >outputfile >- cjpeg <inputfile >outputfile >- source program | cjpeg >outputfile >-The simpler "two file" command line style is just >- cjpeg inputfile outputfile >-You may prefer the two-file style, particularly if you don't have pipes. >- >-You MUST use two-file style on any system that doesn't cope well with binary >-data fed through stdin/stdout; this is true for some MS-DOS compilers, for >-example. If you're not on a Unix system, it's safest to assume you need >-two-file style. (But if your compiler provides either the Posix-standard >-fdopen() library routine or a Microsoft-compatible setmode() routine, you >-can safely use the Unix command line style, by defining USE_FDOPEN or >-USE_SETMODE respectively.) >- >-To use the two-file style, make jconfig.h say "#define TWO_FILE_COMMANDLINE". >- >-Selecting a memory manager >--------------------------- >- >-The IJG code is capable of working on images that are too big to fit in main >-memory; data is swapped out to temporary files as necessary. However, the >-code to do this is rather system-dependent. We provide five different >-memory managers: >- >-* jmemansi.c This version uses the ANSI-standard library routine tmpfile(), >- which not all non-ANSI systems have. On some systems >- tmpfile() may put the temporary file in a non-optimal >- location; if you don't like what it does, use jmemname.c. >- >-* jmemname.c This version creates named temporary files. For anything >- except a Unix machine, you'll need to configure the >- select_file_name() routine appropriately; see the comments >- near the head of jmemname.c. If you use this version, define >- NEED_SIGNAL_CATCHER in jconfig.h to make sure the temp files >- are removed if the program is aborted. >- >-* jmemnobs.c (That stands for No Backing Store :-).) This will compile on >- almost any system, but it assumes you have enough main memory >- or virtual memory to hold the biggest images you work with. >- >-* jmemdos.c This should be used with most 16-bit MS-DOS compilers. >- See the system-specific notes about MS-DOS for more info. >- IMPORTANT: if you use this, define USE_MSDOS_MEMMGR in >- jconfig.h, and include the assembly file jmemdosa.asm in the >- programs. The supplied makefiles and jconfig files for >- 16-bit MS-DOS compilers already do both. >- >-* jmemmac.c Custom version for Apple Macintosh; see the system-specific >- notes for Macintosh for more info. >- >-To use a particular memory manager, change the SYSDEPMEM variable in your >-makefile to equal the corresponding object file name (for example, jmemansi.o >-or jmemansi.obj for jmemansi.c). >- >-If you have plenty of (real or virtual) main memory, just use jmemnobs.c. >-"Plenty" means about ten bytes for every pixel in the largest images >-you plan to process, so a lot of systems don't meet this criterion. >-If yours doesn't, try jmemansi.c first. If that doesn't compile, you'll have >-to use jmemname.c; be sure to adjust select_file_name() for local conditions. >-You may also need to change unlink() to remove() in close_backing_store(). >- >-Except with jmemnobs.c or jmemmac.c, you need to adjust the DEFAULT_MAX_MEM >-setting to a reasonable value for your system (either by adding a #define for >-DEFAULT_MAX_MEM to jconfig.h, or by adding a -D switch to the Makefile). >-This value limits the amount of data space the program will attempt to >-allocate. Code and static data space isn't counted, so the actual memory >-needs for cjpeg or djpeg are typically 100 to 150Kb more than the max-memory >-setting. Larger max-memory settings reduce the amount of I/O needed to >-process a large image, but too large a value can result in "insufficient >-memory" failures. On most Unix machines (and other systems with virtual >-memory), just set DEFAULT_MAX_MEM to several million and forget it. At the >-other end of the spectrum, for MS-DOS machines you probably can't go much >-above 300K to 400K. (On MS-DOS the value refers to conventional memory only. >-Extended/expanded memory is handled separately by jmemdos.c.) >- >- >-BUILDING THE SOFTWARE >-===================== >- >-Now you should be able to compile the software. Just say "make" (or >-whatever's necessary to start the compilation). Have a cup of coffee. >- >-Here are some things that could go wrong: >- >-If your compiler complains about undefined structures, you should be able to >-shut it up by putting "#define INCOMPLETE_TYPES_BROKEN" in jconfig.h. >- >-If you have trouble with missing system include files or inclusion of the >-wrong ones, read jinclude.h. This shouldn't happen if you used configure >-or ckconfig.c to set up jconfig.h. >- >-There are a fair number of routines that do not use all of their parameters; >-some compilers will issue warnings about this, which you can ignore. There >-are also a few configuration checks that may give "unreachable code" warnings. >-Any other warning deserves investigation. >- >-If you don't have a getenv() library routine, define NO_GETENV. >- >-Also see the system-specific hints, below. >- >- >-TESTING THE SOFTWARE >-==================== >- >-As a quick test of functionality we've included a small sample image in >-several forms: >- testorig.jpg Starting point for the djpeg tests. >- testimg.ppm The output of djpeg testorig.jpg >- testimg.bmp The output of djpeg -bmp -colors 256 testorig.jpg >- testimg.jpg The output of cjpeg testimg.ppm >- testprog.jpg Progressive-mode equivalent of testorig.jpg. >- testimgp.jpg The output of cjpeg -progressive -optimize testimg.ppm >-(The first- and second-generation .jpg files aren't identical since JPEG is >-lossy.) If you can generate duplicates of the testimg* files then you >-probably have working programs. >- >-With most of the makefiles, "make test" will perform the necessary >-comparisons. >- >-If you're using a makefile that doesn't provide the test option, run djpeg >-and cjpeg by hand and compare the output files to testimg* with whatever >-binary file comparison tool you have. The files should be bit-for-bit >-identical. >- >-If the programs complain "MAX_ALLOC_CHUNK is wrong, please fix", then you >-need to reduce MAX_ALLOC_CHUNK to a value that fits in type size_t. >-Try adding "#define MAX_ALLOC_CHUNK 65520L" to jconfig.h. A less likely >-configuration error is "ALIGN_TYPE is wrong, please fix": defining ALIGN_TYPE >-as long should take care of that one. >- >-If the cjpeg test run fails with "Missing Huffman code table entry", it's a >-good bet that you needed to define RIGHT_SHIFT_IS_UNSIGNED. Go back to the >-configuration step and run ckconfig.c. (This is a good plan for any other >-test failure, too.) >- >-If you are using Unix (one-file) command line style on a non-Unix system, >-it's a good idea to check that binary I/O through stdin/stdout actually >-works. You should get the same results from "djpeg <testorig.jpg >out.ppm" >-as from "djpeg -outfile out.ppm testorig.jpg". Note that the makefiles all >-use the latter style and therefore do not exercise stdin/stdout! If this >-check fails, try recompiling with USE_SETMODE or USE_FDOPEN defined. >-If it still doesn't work, better use two-file style. >- >-If you chose a memory manager other than jmemnobs.c, you should test that >-temporary-file usage works. Try "djpeg -bmp -colors 256 -max 0 testorig.jpg" >-and make sure its output matches testimg.bmp. If you have any really large >-images handy, try compressing them with -optimize and/or decompressing with >--colors 256 to make sure your DEFAULT_MAX_MEM setting is not too large. >- >-NOTE: this is far from an exhaustive test of the JPEG software; some modules, >-such as 1-pass color quantization, are not exercised at all. It's just a >-quick test to give you some confidence that you haven't missed something >-major. >- >- >-INSTALLING THE SOFTWARE >-======================= >- >-Once you're done with the above steps, you can install the software by >-copying the executable files (cjpeg, djpeg, jpegtran, rdjpgcom, and wrjpgcom) >-to wherever you normally install programs. On Unix systems, you'll also want >-to put the man pages (cjpeg.1, djpeg.1, jpegtran.1, rdjpgcom.1, wrjpgcom.1) >-in the man-page directory. The pre-fab makefiles don't support this step >-since there's such a wide variety of installation procedures on different >-systems. >- >-If you generated a Makefile with the "configure" script, you can just say >- make install >-to install the programs and their man pages into the standard places. >-(You'll probably need to be root to do this.) We recommend first saying >- make -n install >-to see where configure thought the files should go. You may need to edit >-the Makefile, particularly if your system's conventions for man page >-filenames don't match what configure expects. >- >-If you want to install the IJG library itself, for use in compiling other >-programs besides ours, then you need to put the four include files >- jpeglib.h jerror.h jconfig.h jmorecfg.h >-into your include-file directory, and put the library file libjpeg.a >-(extension may vary depending on system) wherever library files go. >-If you generated a Makefile with "configure", it will do what it thinks >-is the right thing if you say >- make install-lib >- >- >-OPTIONAL STUFF >-============== >- >-Progress monitor: >- >-If you like, you can #define PROGRESS_REPORT (in jconfig.h) to enable display >-of percent-done progress reports. The routine provided in cdjpeg.c merely >-prints percentages to stderr, but you can customize it to do something >-fancier. >- >-Utah RLE file format support: >- >-We distribute the software with support for RLE image files (Utah Raster >-Toolkit format) disabled, because the RLE support won't compile without the >-Utah library. If you have URT version 3.1 or later, you can enable RLE >-support as follows: >- 1. #define RLE_SUPPORTED in jconfig.h. >- 2. Add a -I option to CFLAGS in the Makefile for the directory >- containing the URT .h files (typically the "include" >- subdirectory of the URT distribution). >- 3. Add -L... -lrle to LDLIBS in the Makefile, where ... specifies >- the directory containing the URT "librle.a" file (typically the >- "lib" subdirectory of the URT distribution). >- >-Support for 12-bit-deep pixel data: >- >-The JPEG standard allows either 8-bit or 12-bit data precision. (For color, >-this means 8 or 12 bits per channel, of course.) If you need to work with >-deeper than 8-bit data, you can compile the IJG code for 12-bit operation. >-To do so: >- 1. In jmorecfg.h, define BITS_IN_JSAMPLE as 12 rather than 8. >- 2. In jconfig.h, undefine BMP_SUPPORTED, RLE_SUPPORTED, and TARGA_SUPPORTED, >- because the code for those formats doesn't handle 12-bit data and won't >- even compile. (The PPM code does work, as explained below. The GIF >- code works too; it scales 8-bit GIF data to and from 12-bit depth >- automatically.) >- 3. Compile. Don't expect "make test" to pass, since the supplied test >- files are for 8-bit data. >- >-Currently, 12-bit support does not work on 16-bit-int machines. >- >-Note that a 12-bit version will not read 8-bit JPEG files, nor vice versa; >-so you'll want to keep around a regular 8-bit compilation as well. >-(Run-time selection of data depth, to allow a single copy that does both, >-is possible but would probably slow things down considerably; it's very low >-on our to-do list.) >- >-The PPM reader (rdppm.c) can read 12-bit data from either text-format or >-binary-format PPM and PGM files. Binary-format PPM/PGM files which have a >-maxval greater than 255 are assumed to use 2 bytes per sample, LSB first >-(little-endian order). As of early 1995, 2-byte binary format is not >-officially supported by the PBMPLUS library, but it is expected that a >-future release of PBMPLUS will support it. Note that the PPM reader will >-read files of any maxval regardless of the BITS_IN_JSAMPLE setting; incoming >-data is automatically rescaled to either maxval=255 or maxval=4095 as >-appropriate for the cjpeg bit depth. >- >-The PPM writer (wrppm.c) will normally write 2-byte binary PPM or PGM >-format, maxval 4095, when compiled with BITS_IN_JSAMPLE=12. Since this >-format is not yet widely supported, you can disable it by compiling wrppm.c >-with PPM_NORAWWORD defined; then the data is scaled down to 8 bits to make a >-standard 1-byte/sample PPM or PGM file. (Yes, this means still another copy >-of djpeg to keep around. But hopefully you won't need it for very long. >-Poskanzer's supposed to get that new PBMPLUS release out Real Soon Now.) >- >-Of course, if you are working with 12-bit data, you probably have it stored >-in some other, nonstandard format. In that case you'll probably want to >-write your own I/O modules to read and write your format. >- >-Note that a 12-bit version of cjpeg always runs in "-optimize" mode, in >-order to generate valid Huffman tables. This is necessary because our >-default Huffman tables only cover 8-bit data. >- >-Removing code: >- >-If you need to make a smaller version of the JPEG software, some optional >-functions can be removed at compile time. See the xxx_SUPPORTED #defines in >-jconfig.h and jmorecfg.h. If at all possible, we recommend that you leave in >-decoder support for all valid JPEG files, to ensure that you can read anyone's >-output. Taking out support for image file formats that you don't use is the >-most painless way to make the programs smaller. Another possibility is to >-remove some of the DCT methods: in particular, the "IFAST" method may not be >-enough faster than the others to be worth keeping on your machine. (If you >-do remove ISLOW or IFAST, be sure to redefine JDCT_DEFAULT or JDCT_FASTEST >-to a supported method, by adding a #define in jconfig.h.) >- >- >-OPTIMIZATION >-============ >- >-Unless you own a Cray, you'll probably be interested in making the JPEG >-software go as fast as possible. This section covers some machine-dependent >-optimizations you may want to try. We suggest that before trying any of >-this, you first get the basic installation to pass the self-test step. >-Repeat the self-test after any optimization to make sure that you haven't >-broken anything. >- >-The integer DCT routines perform a lot of multiplications. These >-multiplications must yield 32-bit results, but none of their input values >-are more than 16 bits wide. On many machines, notably the 680x0 and 80x86 >-CPUs, a 16x16=>32 bit multiply instruction is faster than a full 32x32=>32 >-bit multiply. Unfortunately there is no portable way to specify such a >-multiplication in C, but some compilers can generate one when you use the >-right combination of casts. See the MULTIPLYxxx macro definitions in >-jdct.h. If your compiler makes "int" be 32 bits and "short" be 16 bits, >-defining SHORTxSHORT_32 is fairly likely to work. When experimenting with >-alternate definitions, be sure to test not only whether the code still works >-(use the self-test), but also whether it is actually faster --- on some >-compilers, alternate definitions may compute the right answer, yet be slower >-than the default. Timing cjpeg on a large PGM (grayscale) input file is the >-best way to check this, as the DCT will be the largest fraction of the runtime >-in that mode. (Note: some of the distributed compiler-specific jconfig files >-already contain #define switches to select appropriate MULTIPLYxxx >-definitions.) >- >-If your machine has sufficiently fast floating point hardware, you may find >-that the float DCT method is faster than the integer DCT methods, even >-after tweaking the integer multiply macros. In that case you may want to >-make the float DCT be the default method. (The only objection to this is >-that float DCT results may vary slightly across machines.) To do that, add >-"#define JDCT_DEFAULT JDCT_FLOAT" to jconfig.h. Even if you don't change >-the default, you should redefine JDCT_FASTEST, which is the method selected >-by djpeg's -fast switch. Don't forget to update the documentation files >-(usage.doc and/or cjpeg.1, djpeg.1) to agree with what you've done. >- >-If access to "short" arrays is slow on your machine, it may be a win to >-define type JCOEF as int rather than short. This will cost a good deal of >-memory though, particularly in some multi-pass modes, so don't do it unless >-you have memory to burn and short is REALLY slow. >- >-If your compiler can compile function calls in-line, make sure the INLINE >-macro in jmorecfg.h is defined as the keyword that marks a function >-inline-able. Some compilers have a switch that tells the compiler to inline >-any function it thinks is profitable (e.g., -finline-functions for gcc). >-Enabling such a switch is likely to make the compiled code bigger but faster. >- >-In general, it's worth trying the maximum optimization level of your compiler, >-and experimenting with any optional optimizations such as loop unrolling. >-(Unfortunately, far too many compilers have optimizer bugs ... be prepared to >-back off if the code fails self-test.) If you do any experimentation along >-these lines, please report the optimal settings to jpeg-info@uunet.uu.net so >-we can mention them in future releases. Be sure to specify your machine and >-compiler version. >- >- >-HINTS FOR SPECIFIC SYSTEMS >-========================== >- >-We welcome reports on changes needed for systems not mentioned here. Submit >-'em to jpeg-info@uunet.uu.net. Also, if configure or ckconfig.c is wrong >-about how to configure the JPEG software for your system, please let us know. >- >- >-Acorn RISC OS: >- >-(Thanks to Simon Middleton for these hints on compiling with Desktop C.) >-After renaming the files according to Acorn conventions, take a copy of >-makefile.ansi, change all occurrences of 'libjpeg.a' to 'libjpeg.o' and >-change these definitions as indicated: >- >-CFLAGS= -throwback -IC: -Wn >-LDLIBS=C:o.Stubs >-SYSDEPMEM=jmemansi.o >-LN=Link >-AR=LibFile -c -o >- >-Also add a new line '.c.o:; $(cc) $< $(cflags) -c -o $@'. Remove the >-lines '$(RM) libjpeg.o' and '$(AR2) libjpeg.o' and the 'jconfig.h' >-dependency section. >- >-Copy jconfig.doc to jconfig.h. Edit jconfig.h to define TWO_FILE_COMMANDLINE >-and CHAR_IS_UNSIGNED. >- >-Run the makefile using !AMU not !Make. If you want to use the 'clean' and >-'test' makefile entries then you will have to fiddle with the syntax a bit >-and rename the test files. >- >- >-Amiga: >- >-SAS C 6.50 reportedly is too buggy to compile the IJG code properly. >-A patch to update to 6.51 is available from SAS or AmiNet FTP sites. >- >-The supplied config files are set up to use jmemname.c as the memory >-manager, with temporary files being created on the device named by >-"JPEGTMP:". >- >- >-Atari ST/STE/TT: >- >-Copy the project files makcjpeg.st, makdjpeg.st, maktjpeg.st, and makljpeg.st >-to cjpeg.prj, djpeg.prj, jpegtran.prj, and libjpeg.prj respectively. The >-project files should work as-is with Pure C. For Turbo C, change library >-filenames "pc..." to "tc..." in each project file. Note that libjpeg.prj >-selects jmemansi.c as the recommended memory manager. You'll probably want to >-adjust the DEFAULT_MAX_MEM setting --- you want it to be a couple hundred K >-less than your normal free memory. Put "#define DEFAULT_MAX_MEM nnnn" into >-jconfig.h to do this. >- >-To use the 68881/68882 coprocessor for the floating point DCT, add the >-compiler option "-8" to the project files and replace pcfltlib.lib with >-pc881lib.lib in cjpeg.prj and djpeg.prj. Or if you don't have a >-coprocessor, you may prefer to remove the float DCT code by undefining >-DCT_FLOAT_SUPPORTED in jmorecfg.h (since without a coprocessor, the float >-code will be too slow to be useful). In that case, you can delete >-pcfltlib.lib from the project files. >- >-Note that you must make libjpeg.lib before making cjpeg.ttp, djpeg.ttp, >-or jpegtran.ttp. You'll have to perform the self-test by hand. >- >-We haven't bothered to include project files for rdjpgcom and wrjpgcom. >-Those source files should just be compiled by themselves; they don't >-depend on the JPEG library. >- >-There is a bug in some older versions of the Turbo C library which causes the >-space used by temporary files created with "tmpfile()" not to be freed after >-an abnormal program exit. If you check your disk afterwards, you will find >-cluster chains that are allocated but not used by a file. This should not >-happen in cjpeg/djpeg/jpegtran, since we enable a signal catcher to explicitly >-close temp files before exiting. But if you use the JPEG library with your >-own code, be sure to supply a signal catcher, or else use a different >-system-dependent memory manager. >- >- >-Cray: >- >-Should you be so fortunate as to be running JPEG on a Cray YMP, there is a >-compiler bug in old versions of Cray's Standard C (prior to 3.1). If you >-still have an old compiler, you'll need to insert a line reading >-"#pragma novector" just before the loop >- for (i = 1; i <= (int) htbl->bits[l]; i++) >- huffsize[p++] = (char) l; >-in fix_huff_tbl (in V5beta1, line 204 of jchuff.c and line 176 of jdhuff.c). >-[This bug may or may not still occur with the current IJG code, but it's >-probably a dead issue anyway...] >- >- >-HP-UX: >- >-If you have HP-UX 7.05 or later with the "software development" C compiler, >-you should run the compiler in ANSI mode. If using the configure script, >-say >- ./configure CC='cc -Aa' >-(or -Ae if you prefer). If configuring by hand, use makefile.ansi and add >-"-Aa" to the CFLAGS line in the makefile. >- >-If you have a pre-7.05 system, or if you are using the non-ANSI C compiler >-delivered with a minimum HP-UX system, then you must use makefile.unix >-(and do NOT add -Aa); or just run configure without the CC option. >- >-On HP 9000 series 800 machines, the HP C compiler is buggy in revisions prior >-to A.08.07. If you get complaints about "not a typedef name", you'll have to >-use makefile.unix, or run configure without the CC option. >- >- >-Macintosh, generic comments: >- >-The supplied user-interface files (cjpeg.c, djpeg.c, etc) are set up to >-provide a Unix-style command line interface. You can use this interface on >-the Mac by means of the ccommand() library routine provided by Metrowerks >-CodeWarrior or Think C. This is only appropriate for testing the library, >-however; to make a user-friendly equivalent of cjpeg/djpeg you'd really want >-to develop a Mac-style user interface. There isn't a complete example >-available at the moment, but there are some helpful starting points: >-1. Sam Bushell's free "To JPEG" applet provides drag-and-drop conversion to >-JPEG under System 7 and later. This only illustrates how to use the >-compression half of the library, but it does a very nice job of that part. >-The CodeWarrior source code is available from http://www.pobox.com/~jsam. >-2. Jim Brunner prepared a Mac-style user interface for both compression and >-decompression. Unfortunately, it hasn't been updated since IJG v4, and >-the library's API has changed considerably since then. Still it may be of >-some help, particularly as a guide to compiling the IJG code under Think C. >-Jim's code is available from the Info-Mac archives, at sumex-aim.stanford.edu >-or mirrors thereof; see file /info-mac/dev/src/jpeg-convert-c.hqx. >- >-jmemmac.c is the recommended memory manager back end for Macintosh. It uses >-NewPtr/DisposePtr instead of malloc/free, and has a Mac-specific >-implementation of jpeg_mem_available(). It also creates temporary files that >-follow Mac conventions. (That part of the code relies on System-7-or-later OS >-functions. See the comments in jmemmac.c if you need to run it on System 6.) >-NOTE that USE_MAC_MEMMGR must be defined in jconfig.h to use jmemmac.c. >- >-You can also use jmemnobs.c, if you don't care about handling images larger >-than available memory. If you use any memory manager back end other than >-jmemmac.c, we recommend replacing "malloc" and "free" by "NewPtr" and >-"DisposePtr", because Mac C libraries often have peculiar implementations of >-malloc/free. (For instance, free() may not return the freed space to the >-Mac Memory Manager. This is undesirable for the IJG code because jmemmgr.c >-already clumps space requests.) >- >- >-Macintosh, Metrowerks CodeWarrior: >- >-The Unix-command-line-style interface can be used by defining USE_CCOMMAND. >-You'll also need to define TWO_FILE_COMMANDLINE to avoid stdin/stdout. >-This means that when using the cjpeg/djpeg programs, you'll have to type the >-input and output file names in the "Arguments" text-edit box, rather than >-using the file radio buttons. (Perhaps USE_FDOPEN or USE_SETMODE would >-eliminate the problem, but I haven't heard from anyone who's tried it.) >- >-On 680x0 Macs, Metrowerks defines type "double" as a 10-byte IEEE extended >-float. jmemmgr.c won't like this: it wants sizeof(ALIGN_TYPE) to be a power >-of 2. Add "#define ALIGN_TYPE long" to jconfig.h to eliminate the complaint. >- >-The supplied configuration file jconfig.mac can be used for your jconfig.h; >-it includes all the recommended symbol definitions. If you have AppleScript >-installed, you can run the supplied script makeproj.mac to create CodeWarrior >-project files for the library and the testbed applications, then build the >-library and applications. (Thanks to Dan Sears and Don Agro for this nifty >-hack, which saves us from trying to maintain CodeWarrior project files as part >-of the IJG distribution...) >- >- >-Macintosh, Think C: >- >-The documentation in Jim Brunner's "JPEG Convert" source code (see above) >-includes detailed build instructions for Think C; it's probably somewhat >-out of date for the current release, but may be helpful. >- >-If you want to build the minimal command line version, proceed as follows. >-You'll have to prepare project files for the programs; we don't include any >-in the distribution since they are not text files. Use the file lists in >-any of the supplied makefiles as a guide. Also add the ANSI and Unix C >-libraries in a separate segment. You may need to divide the JPEG files into >-more than one segment; we recommend dividing compression and decompression >-modules. Define USE_CCOMMAND in jconfig.h so that the ccommand() routine is >-called. You must also define TWO_FILE_COMMANDLINE because stdin/stdout >-don't handle binary data correctly. >- >-On 680x0 Macs, Think C defines type "double" as a 12-byte IEEE extended float. >-jmemmgr.c won't like this: it wants sizeof(ALIGN_TYPE) to be a power of 2. >-Add "#define ALIGN_TYPE long" to jconfig.h to eliminate the complaint. >- >-jconfig.mac should work as a jconfig.h configuration file for Think C, >-but the makeproj.mac AppleScript script is specific to CodeWarrior. Sorry. >- >- >-MIPS R3000: >- >-MIPS's cc version 1.31 has a rather nasty optimization bug. Don't use -O >-if you have that compiler version. (Use "cc -V" to check the version.) >-Note that the R3000 chip is found in workstations from DEC and others. >- >- >-MS-DOS, generic comments for 16-bit compilers: >- >-The IJG code is designed to work well in 80x86 "small" or "medium" memory >-models (i.e., data pointers are 16 bits unless explicitly declared "far"; >-code pointers can be either size). You may be able to use small model to >-compile cjpeg or djpeg by itself, but you will probably have to use medium >-model for any larger application. This won't make much difference in >-performance. You *will* take a noticeable performance hit if you use a >-large-data memory model, and you should avoid "huge" model if at all >-possible. Be sure that NEED_FAR_POINTERS is defined in jconfig.h if you use >-a small-data memory model; be sure it is NOT defined if you use a large-data >-model. (The supplied makefiles and jconfig files for Borland and Microsoft C >-compile in medium model and define NEED_FAR_POINTERS.) >- >-The DOS-specific memory manager, jmemdos.c, should be used if possible. >-It needs some assembly-code routines which are in jmemdosa.asm; make sure >-your makefile assembles that file and includes it in the library. If you >-don't have a suitable assembler, you can get pre-assembled object files for >-jmemdosa by FTP from ftp.uu.net:/graphics/jpeg/jdosaobj.zip. (DOS-oriented >-distributions of the IJG source code often include these object files.) >- >-When using jmemdos.c, jconfig.h must define USE_MSDOS_MEMMGR and must set >-MAX_ALLOC_CHUNK to less than 64K (65520L is a typical value). If your >-C library's far-heap malloc() can't allocate blocks that large, reduce >-MAX_ALLOC_CHUNK to whatever it can handle. >- >-If you can't use jmemdos.c for some reason --- for example, because you >-don't have an assembler to assemble jmemdosa.asm --- you'll have to fall >-back to jmemansi.c or jmemname.c. You'll probably still need to set >-MAX_ALLOC_CHUNK in jconfig.h, because most DOS C libraries won't malloc() >-more than 64K at a time. IMPORTANT: if you use jmemansi.c or jmemname.c, >-you will have to compile in a large-data memory model in order to get the >-right stdio library. Too bad. >- >-wrjpgcom needs to be compiled in large model, because it malloc()s a 64KB >-work area to hold the comment text. If your C library's malloc can't >-handle that, reduce MAX_COM_LENGTH as necessary in wrjpgcom.c. >- >-Most MS-DOS compilers treat stdin/stdout as text files, so you must use >-two-file command line style. But if your compiler has either fdopen() or >-setmode(), you can use one-file style if you like. To do this, define >-USE_SETMODE or USE_FDOPEN so that stdin/stdout will be set to binary mode. >-(USE_SETMODE seems to work with more DOS compilers than USE_FDOPEN.) You >-should test that I/O through stdin/stdout produces the same results as I/O >-to explicitly named files... the "make test" procedures in the supplied >-makefiles do NOT use stdin/stdout. >- >- >-MS-DOS, generic comments for 32-bit compilers: >- >-None of the above comments about memory models apply if you are using a >-32-bit flat-memory-space environment, such as DJGPP or Watcom C. (And you >-should use one if you have it, as performance will be much better than >-8086-compatible code!) For flat-memory-space compilers, do NOT define >-NEED_FAR_POINTERS, and do NOT use jmemdos.c. Use jmemnobs.c if the >-environment supplies adequate virtual memory, otherwise use jmemansi.c or >-jmemname.c. >- >-You'll still need to be careful about binary I/O through stdin/stdout. >-See the last paragraph of the previous section. >- >- >-MS-DOS, Borland C: >- >-Be sure to convert all the source files to DOS text format (CR/LF newlines). >-Although Borland C will often work OK with unmodified Unix (LF newlines) >-source files, sometimes it will give bogus compile errors. >-"Illegal character '#'" is the most common such error. (This is true with >-Borland C 3.1, but perhaps is fixed in newer releases.) >- >-If you want one-file command line style, just undefine TWO_FILE_COMMANDLINE. >-jconfig.bcc already includes #define USE_SETMODE to make this work. >-(fdopen does not work correctly.) >- >- >-MS-DOS, Microsoft C: >- >-makefile.mc6 works with Microsoft C, DOS Visual C++, etc. It should only >-be used if you want to build a 16-bit (small or medium memory model) program. >- >-If you want one-file command line style, just undefine TWO_FILE_COMMANDLINE. >-jconfig.mc6 already includes #define USE_SETMODE to make this work. >-(fdopen does not work correctly.) >- >-Note that this makefile assumes that the working copy of itself is called >-"makefile". If you want to call it something else, say "makefile.mak", >-be sure to adjust the dependency line that reads "$(RFILE) : makefile". >-Otherwise the make will fail because it doesn't know how to create "makefile". >-Worse, some releases of Microsoft's make utilities give an incorrect error >-message in this situation. >- >-Old versions of MS C fail with an "out of macro expansion space" error >-because they can't cope with the macro TRACEMS8 (defined in jerror.h). >-If this happens to you, the easiest solution is to change TRACEMS8 to >-expand to nothing. You'll lose the ability to dump out JPEG coefficient >-tables with djpeg -debug -debug, but at least you can compile. >- >-Original MS C 6.0 is very buggy; it compiles incorrect code unless you turn >-off optimization entirely (remove -O from CFLAGS). 6.00A is better, but it >-still generates bad code if you enable loop optimizations (-Ol or -Ox). >- >-MS C 8.0 crashes when compiling jquant1.c with optimization switch /Oo ... >-which is on by default. To work around this bug, compile that one file >-with /Oo-. >- >- >-Microsoft Windows (all versions), generic comments: >- >-Some Windows system include files define typedef boolean as "unsigned char". >-The IJG code also defines typedef boolean, but we make it "int" by default. >-This doesn't affect the IJG programs because we don't import those Windows >-include files. But if you use the JPEG library in your own program, and some >-of your program's files import one definition of boolean while some import the >-other, you can get all sorts of mysterious problems. A good preventive step >-is to make the IJG library use "unsigned char" for boolean. To do that, >-add something like this to your jconfig.h file: >- /* Define "boolean" as unsigned char, not int, per Windows custom */ >- #ifndef __RPCNDR_H__ /* don't conflict if rpcndr.h already read */ >- typedef unsigned char boolean; >- #endif >- #define HAVE_BOOLEAN /* prevent jmorecfg.h from redefining it */ >-(This is already in jconfig.vc, by the way.) >- >-windef.h contains the declarations >- #define far >- #define FAR far >-Since jmorecfg.h tries to define FAR as empty, you may get a compiler >-warning if you include both jpeglib.h and windef.h (which windows.h >-includes). To suppress the warning, you can put "#ifndef FAR"/"#endif" >-around the line "#define FAR" in jmorecfg.h. >- >-When using the library in a Windows application, you will almost certainly >-want to modify or replace the error handler module jerror.c, since our >-default error handler does a couple of inappropriate things: >- 1. it tries to write error and warning messages on stderr; >- 2. in event of a fatal error, it exits by calling exit(). >- >-A simple stopgap solution for problem 1 is to replace the line >- fprintf(stderr, "%s\n", buffer); >-(in output_message in jerror.c) with >- MessageBox(GetActiveWindow(),buffer,"JPEG Error",MB_OK|MB_ICONERROR); >-It's highly recommended that you at least do that much, since otherwise >-error messages will disappear into nowhere. (Beginning with IJG v6b, this >-code is already present in jerror.c; just define USE_WINDOWS_MESSAGEBOX in >-jconfig.h to enable it.) >- >-The proper solution for problem 2 is to return control to your calling >-application after a library error. This can be done with the setjmp/longjmp >-technique discussed in libjpeg.doc and illustrated in example.c. (NOTE: >-some older Windows C compilers provide versions of setjmp/longjmp that >-don't actually work under Windows. You may need to use the Windows system >-functions Catch and Throw instead.) >- >-The recommended memory manager under Windows is jmemnobs.c; in other words, >-let Windows do any virtual memory management needed. You should NOT use >-jmemdos.c nor jmemdosa.asm under Windows. >- >-For Windows 3.1, we recommend compiling in medium or large memory model; >-for newer Windows versions, use a 32-bit flat memory model. (See the MS-DOS >-sections above for more info about memory models.) In the 16-bit memory >-models only, you'll need to put >- #define MAX_ALLOC_CHUNK 65520L /* Maximum request to malloc() */ >-into jconfig.h to limit allocation chunks to 64Kb. (Without that, you'd >-have to use huge memory model, which slows things down unnecessarily.) >-jmemnobs.c works without modification in large or flat memory models, but to >-use medium model, you need to modify its jpeg_get_large and jpeg_free_large >-routines to allocate far memory. In any case, you might like to replace >-its calls to malloc and free with direct calls on Windows memory allocation >-functions. >- >-You may also want to modify jdatasrc.c and jdatadst.c to use Windows file >-operations rather than fread/fwrite. This is only necessary if your C >-compiler doesn't provide a competent implementation of C stdio functions. >- >-You might want to tweak the RGB_xxx macros in jmorecfg.h so that the library >-will accept or deliver color pixels in BGR sample order, not RGB; BGR order >-is usually more convenient under Windows. Note that this change will break >-the sample applications cjpeg/djpeg, but the library itself works fine. >- >- >-Many people want to convert the IJG library into a DLL. This is reasonably >-straightforward, but watch out for the following: >- >- 1. Don't try to compile as a DLL in small or medium memory model; use >-large model, or even better, 32-bit flat model. Many places in the IJG code >-assume the address of a local variable is an ordinary (not FAR) pointer; >-that isn't true in a medium-model DLL. >- >- 2. Microsoft C cannot pass file pointers between applications and DLLs. >-(See Microsoft Knowledge Base, PSS ID Number Q50336.) So jdatasrc.c and >-jdatadst.c don't work if you open a file in your application and then pass >-the pointer to the DLL. One workaround is to make jdatasrc.c/jdatadst.c >-part of your main application rather than part of the DLL. >- >- 3. You'll probably need to modify the macros GLOBAL() and EXTERN() to >-attach suitable linkage keywords to the exported routine names. Similarly, >-you'll want to modify METHODDEF() and JMETHOD() to ensure function pointers >-are declared in a way that lets application routines be called back through >-the function pointers. These macros are in jmorecfg.h. Typical definitions >-for a 16-bit DLL are: >- #define GLOBAL(type) type _far _pascal _loadds _export >- #define EXTERN(type) extern type _far _pascal _loadds >- #define METHODDEF(type) static type _far _pascal >- #define JMETHOD(type,methodname,arglist) \ >- type (_far _pascal *methodname) arglist >-For a 32-bit DLL you may want something like >- #define GLOBAL(type) __declspec(dllexport) type >- #define EXTERN(type) extern __declspec(dllexport) type >-Although not all the GLOBAL routines are actually intended to be called by >-the application, the performance cost of making them all DLL entry points is >-negligible. >- >-The unmodified IJG library presents a very C-specific application interface, >-so the resulting DLL is only usable from C or C++ applications. There has >-been some talk of writing wrapper code that would present a simpler interface >-usable from other languages, such as Visual Basic. This is on our to-do list >-but hasn't been very high priority --- any volunteers out there? >- >- >-Microsoft Windows, Borland C: >- >-The provided jconfig.bcc should work OK in a 32-bit Windows environment, >-but you'll need to tweak it in a 16-bit environment (you'd need to define >-NEED_FAR_POINTERS and MAX_ALLOC_CHUNK). Beware that makefile.bcc will need >-alteration if you want to use it for Windows --- in particular, you should >-use jmemnobs.c not jmemdos.c under Windows. >- >-Borland C++ 4.5 fails with an internal compiler error when trying to compile >-jdmerge.c in 32-bit mode. If enough people complain, perhaps Borland will fix >-it. In the meantime, the simplest known workaround is to add a redundant >-definition of the variable range_limit in h2v1_merged_upsample(), at the head >-of the block that handles odd image width (about line 268 in v6 jdmerge.c): >- /* If image width is odd, do the last output column separately */ >- if (cinfo->output_width & 1) { >- register JSAMPLE * range_limit = cinfo->sample_range_limit; /* ADD THIS */ >- cb = GETJSAMPLE(*inptr1); >-Pretty bizarre, especially since the very similar routine h2v2_merged_upsample >-doesn't trigger the bug. >-Recent reports suggest that this bug does not occur with "bcc32a" (the >-Pentium-optimized version of the compiler). >- >-Another report from a user of Borland C 4.5 was that incorrect code (leading >-to a color shift in processed images) was produced if any of the following >-optimization switch combinations were used: >- -Ot -Og >- -Ot -Op >- -Ot -Om >-So try backing off on optimization if you see such a problem. (Are there >-several different releases all numbered "4.5"??) >- >- >-Microsoft Windows, Microsoft Visual C++: >- >-jconfig.vc should work OK with any Microsoft compiler for a 32-bit memory >-model. makefile.vc is intended for command-line use. (If you are using >-the Developer Studio environment, you may prefer the DevStudio project >-files; see below.) >- >-Some users feel that it's easier to call the library from C++ code if you >-force VC++ to treat the library as C++ code, which you can do by renaming >-all the *.c files to *.cpp (and adjusting the makefile to match). This >-avoids the need to put extern "C" { ... } around #include "jpeglib.h" in >-your C++ application. >- >- >-Microsoft Windows, Microsoft Developer Studio: >- >-We include makefiles that should work as project files in DevStudio 4.2 or >-later. There is a library makefile that builds the IJG library as a static >-Win32 library, and an application makefile that builds the sample applications >-as Win32 console applications. (Even if you only want the library, we >-recommend building the applications so that you can run the self-test.) >- >-To use: >-1. Copy jconfig.vc to jconfig.h, makelib.ds to jpeg.mak, and >- makeapps.ds to apps.mak. (Note that the renaming is critical!) >-2. Click on the .mak files to construct project workspaces. >- (If you are using DevStudio more recent than 4.2, you'll probably >- get a message saying that the makefiles are being updated.) >-3. Build the library project, then the applications project. >-4. Move the application .exe files from `app`\Release to an >- appropriate location on your path. >-5. To perform the self-test, execute the command line >- NMAKE /f makefile.vc test >- >- >-OS/2, Borland C++: >- >-Watch out for optimization bugs in older Borland compilers; you may need >-to back off the optimization switch settings. See the comments in >-makefile.bcc. >- >- >-SGI: >- >-On some SGI systems, you may need to set "AR2= ar -ts" in the Makefile. >-If you are using configure, you can do this by saying >- ./configure RANLIB='ar -ts' >-This change is not needed on all SGIs. Use it only if the make fails at the >-stage of linking the completed programs. >- >-On the MIPS R4000 architecture (Indy, etc.), the compiler option "-mips2" >-reportedly speeds up the float DCT method substantially, enough to make it >-faster than the default int method (but still slower than the fast int >-method). If you use -mips2, you may want to alter the default DCT method to >-be float. To do this, put "#define JDCT_DEFAULT JDCT_FLOAT" in jconfig.h. >- >- >-VMS: >- >-On an Alpha/VMS system with MMS, be sure to use the "/Marco=Alpha=1" >-qualifier with MMS when building the JPEG package. >- >-VAX/VMS v5.5-1 may have problems with the test step of the build procedure >-reporting differences when it compares the original and test images. If the >-error points to the last block of the files, it is most likely bogus and may >-be safely ignored. It seems to be because the files are Stream_LF and >-Backup/Compare has difficulty with the (presumably) null padded files. >-This problem was not observed on VAX/VMS v6.1 or AXP/VMS v6.1. >only in patch2: >--- /dev/null >+++ b/jpeg/jaricom.c >@@ -0,0 +1,152 @@ >+/* >+ * jaricom.c >+ * >+ * Developed 1997-2009 by Guido Vollbeding. >+ * This file is part of the Independent JPEG Group's software. >+ * For conditions of distribution and use, see the accompanying README file. >+ * >+ * This file contains probability estimation tables for common use in >+ * arithmetic entropy encoding and decoding routines. >+ * >+ * This data represents Table D.2 in the JPEG spec (ISO/IEC IS 10918-1 >+ * and CCITT Recommendation ITU-T T.81) and Table 24 in the JBIG spec >+ * (ISO/IEC IS 11544 and CCITT Recommendation ITU-T T.82). >+ */ >+ >+#define JPEG_INTERNALS >+#include "jinclude.h" >+#include "jpeglib.h" >+ >+/* The following #define specifies the packing of the four components >+ * into the compact INT32 representation. >+ * Note that this formula must match the actual arithmetic encoder >+ * and decoder implementation. The implementation has to be changed >+ * if this formula is changed. >+ * The current organization is leaned on Markus Kuhn's JBIG >+ * implementation (jbig_tab.c). >+ */ >+ >+#define V(i,a,b,c,d) (((INT32)a << 16) | ((INT32)c << 8) | ((INT32)d << 7) | b) >+ >+const INT32 jpeg_aritab[113+1] = { >+/* >+ * Index, Qe_Value, Next_Index_LPS, Next_Index_MPS, Switch_MPS >+ */ >+ V( 0, 0x5a1d, 1, 1, 1 ), >+ V( 1, 0x2586, 14, 2, 0 ), >+ V( 2, 0x1114, 16, 3, 0 ), >+ V( 3, 0x080b, 18, 4, 0 ), >+ V( 4, 0x03d8, 20, 5, 0 ), >+ V( 5, 0x01da, 23, 6, 0 ), >+ V( 6, 0x00e5, 25, 7, 0 ), >+ V( 7, 0x006f, 28, 8, 0 ), >+ V( 8, 0x0036, 30, 9, 0 ), >+ V( 9, 0x001a, 33, 10, 0 ), >+ V( 10, 0x000d, 35, 11, 0 ), >+ V( 11, 0x0006, 9, 12, 0 ), >+ V( 12, 0x0003, 10, 13, 0 ), >+ V( 13, 0x0001, 12, 13, 0 ), >+ V( 14, 0x5a7f, 15, 15, 1 ), >+ V( 15, 0x3f25, 36, 16, 0 ), >+ V( 16, 0x2cf2, 38, 17, 0 ), >+ V( 17, 0x207c, 39, 18, 0 ), >+ V( 18, 0x17b9, 40, 19, 0 ), >+ V( 19, 0x1182, 42, 20, 0 ), >+ V( 20, 0x0cef, 43, 21, 0 ), >+ V( 21, 0x09a1, 45, 22, 0 ), >+ V( 22, 0x072f, 46, 23, 0 ), >+ V( 23, 0x055c, 48, 24, 0 ), >+ V( 24, 0x0406, 49, 25, 0 ), >+ V( 25, 0x0303, 51, 26, 0 ), >+ V( 26, 0x0240, 52, 27, 0 ), >+ V( 27, 0x01b1, 54, 28, 0 ), >+ V( 28, 0x0144, 56, 29, 0 ), >+ V( 29, 0x00f5, 57, 30, 0 ), >+ V( 30, 0x00b7, 59, 31, 0 ), >+ V( 31, 0x008a, 60, 32, 0 ), >+ V( 32, 0x0068, 62, 33, 0 ), >+ V( 33, 0x004e, 63, 34, 0 ), >+ V( 34, 0x003b, 32, 35, 0 ), >+ V( 35, 0x002c, 33, 9, 0 ), >+ V( 36, 0x5ae1, 37, 37, 1 ), >+ V( 37, 0x484c, 64, 38, 0 ), >+ V( 38, 0x3a0d, 65, 39, 0 ), >+ V( 39, 0x2ef1, 67, 40, 0 ), >+ V( 40, 0x261f, 68, 41, 0 ), >+ V( 41, 0x1f33, 69, 42, 0 ), >+ V( 42, 0x19a8, 70, 43, 0 ), >+ V( 43, 0x1518, 72, 44, 0 ), >+ V( 44, 0x1177, 73, 45, 0 ), >+ V( 45, 0x0e74, 74, 46, 0 ), >+ V( 46, 0x0bfb, 75, 47, 0 ), >+ V( 47, 0x09f8, 77, 48, 0 ), >+ V( 48, 0x0861, 78, 49, 0 ), >+ V( 49, 0x0706, 79, 50, 0 ), >+ V( 50, 0x05cd, 48, 51, 0 ), >+ V( 51, 0x04de, 50, 52, 0 ), >+ V( 52, 0x040f, 50, 53, 0 ), >+ V( 53, 0x0363, 51, 54, 0 ), >+ V( 54, 0x02d4, 52, 55, 0 ), >+ V( 55, 0x025c, 53, 56, 0 ), >+ V( 56, 0x01f8, 54, 57, 0 ), >+ V( 57, 0x01a4, 55, 58, 0 ), >+ V( 58, 0x0160, 56, 59, 0 ), >+ V( 59, 0x0125, 57, 60, 0 ), >+ V( 60, 0x00f6, 58, 61, 0 ), >+ V( 61, 0x00cb, 59, 62, 0 ), >+ V( 62, 0x00ab, 61, 63, 0 ), >+ V( 63, 0x008f, 61, 32, 0 ), >+ V( 64, 0x5b12, 65, 65, 1 ), >+ V( 65, 0x4d04, 80, 66, 0 ), >+ V( 66, 0x412c, 81, 67, 0 ), >+ V( 67, 0x37d8, 82, 68, 0 ), >+ V( 68, 0x2fe8, 83, 69, 0 ), >+ V( 69, 0x293c, 84, 70, 0 ), >+ V( 70, 0x2379, 86, 71, 0 ), >+ V( 71, 0x1edf, 87, 72, 0 ), >+ V( 72, 0x1aa9, 87, 73, 0 ), >+ V( 73, 0x174e, 72, 74, 0 ), >+ V( 74, 0x1424, 72, 75, 0 ), >+ V( 75, 0x119c, 74, 76, 0 ), >+ V( 76, 0x0f6b, 74, 77, 0 ), >+ V( 77, 0x0d51, 75, 78, 0 ), >+ V( 78, 0x0bb6, 77, 79, 0 ), >+ V( 79, 0x0a40, 77, 48, 0 ), >+ V( 80, 0x5832, 80, 81, 1 ), >+ V( 81, 0x4d1c, 88, 82, 0 ), >+ V( 82, 0x438e, 89, 83, 0 ), >+ V( 83, 0x3bdd, 90, 84, 0 ), >+ V( 84, 0x34ee, 91, 85, 0 ), >+ V( 85, 0x2eae, 92, 86, 0 ), >+ V( 86, 0x299a, 93, 87, 0 ), >+ V( 87, 0x2516, 86, 71, 0 ), >+ V( 88, 0x5570, 88, 89, 1 ), >+ V( 89, 0x4ca9, 95, 90, 0 ), >+ V( 90, 0x44d9, 96, 91, 0 ), >+ V( 91, 0x3e22, 97, 92, 0 ), >+ V( 92, 0x3824, 99, 93, 0 ), >+ V( 93, 0x32b4, 99, 94, 0 ), >+ V( 94, 0x2e17, 93, 86, 0 ), >+ V( 95, 0x56a8, 95, 96, 1 ), >+ V( 96, 0x4f46, 101, 97, 0 ), >+ V( 97, 0x47e5, 102, 98, 0 ), >+ V( 98, 0x41cf, 103, 99, 0 ), >+ V( 99, 0x3c3d, 104, 100, 0 ), >+ V( 100, 0x375e, 99, 93, 0 ), >+ V( 101, 0x5231, 105, 102, 0 ), >+ V( 102, 0x4c0f, 106, 103, 0 ), >+ V( 103, 0x4639, 107, 104, 0 ), >+ V( 104, 0x415e, 103, 99, 0 ), >+ V( 105, 0x5627, 105, 106, 1 ), >+ V( 106, 0x50e7, 108, 107, 0 ), >+ V( 107, 0x4b85, 109, 103, 0 ), >+ V( 108, 0x5597, 110, 109, 0 ), >+ V( 109, 0x504f, 111, 107, 0 ), >+ V( 110, 0x5a10, 110, 111, 1 ), >+ V( 111, 0x5522, 112, 109, 0 ), >+ V( 112, 0x59eb, 112, 111, 1 ), >+/* >+ * This last entry is used for fixed probability estimate of 0.5 >+ * as recommended in Section 10.3 Table 5 of ITU-T Rec. T.851. >+ */ >+ V( 113, 0x5a1d, 113, 113, 0 ) >only in patch2: >--- a/jpeg/jcapimin.c >+++ b/jpeg/jcapimin.c >@@ -4,2 +4,3 @@ > * Copyright (C) 1994-1998, Thomas G. Lane. >+ * Modified 2003-2010 by Guido Vollbeding. > * This file is part of the Independent JPEG Group's software. >@@ -65,4 +66,8 @@ > >- for (i = 0; i < NUM_QUANT_TBLS; i++) >+ for (i = 0; i < NUM_QUANT_TBLS; i++) { > cinfo->quant_tbl_ptrs[i] = NULL; >+#if JPEG_LIB_VERSION >= 70 >+ cinfo->q_scale_factor[i] = 100; >+#endif >+ } > >@@ -73,2 +78,9 @@ > >+#if JPEG_LIB_VERSION >= 80 >+ /* Must do it here for emit_dqt in case jpeg_write_tables is used */ >+ cinfo->block_size = DCTSIZE; >+ cinfo->natural_order = jpeg_natural_order; >+ cinfo->lim_Se = DCTSIZE2-1; >+#endif >+ > cinfo->script_space = NULL; >only in patch2: >--- /dev/null >+++ b/jpeg/jcarith.c >@@ -0,0 +1,925 @@ >+/* >+ * jcarith.c >+ * >+ * Developed 1997-2009 by Guido Vollbeding. >+ * This file is part of the Independent JPEG Group's software. >+ * For conditions of distribution and use, see the accompanying README file. >+ * >+ * This file contains portable arithmetic entropy encoding routines for JPEG >+ * (implementing the ISO/IEC IS 10918-1 and CCITT Recommendation ITU-T T.81). >+ * >+ * Both sequential and progressive modes are supported in this single module. >+ * >+ * Suspension is not currently supported in this module. >+ */ >+ >+#define JPEG_INTERNALS >+#include "jinclude.h" >+#include "jpeglib.h" >+ >+ >+/* Expanded entropy encoder object for arithmetic encoding. */ >+ >+typedef struct { >+ struct jpeg_entropy_encoder pub; /* public fields */ >+ >+ INT32 c; /* C register, base of coding interval, layout as in sec. D.1.3 */ >+ INT32 a; /* A register, normalized size of coding interval */ >+ INT32 sc; /* counter for stacked 0xFF values which might overflow */ >+ INT32 zc; /* counter for pending 0x00 output values which might * >+ * be discarded at the end ("Pacman" termination) */ >+ int ct; /* bit shift counter, determines when next byte will be written */ >+ int buffer; /* buffer for most recent output byte != 0xFF */ >+ >+ int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */ >+ int dc_context[MAX_COMPS_IN_SCAN]; /* context index for DC conditioning */ >+ >+ unsigned int restarts_to_go; /* MCUs left in this restart interval */ >+ int next_restart_num; /* next restart number to write (0-7) */ >+ >+ /* Pointers to statistics areas (these workspaces have image lifespan) */ >+ unsigned char * dc_stats[NUM_ARITH_TBLS]; >+ unsigned char * ac_stats[NUM_ARITH_TBLS]; >+ >+ /* Statistics bin for coding with fixed probability 0.5 */ >+ unsigned char fixed_bin[4]; >+} arith_entropy_encoder; >+ >+typedef arith_entropy_encoder * arith_entropy_ptr; >+ >+/* The following two definitions specify the allocation chunk size >+ * for the statistics area. >+ * According to sections F.1.4.4.1.3 and F.1.4.4.2, we need at least >+ * 49 statistics bins for DC, and 245 statistics bins for AC coding. >+ * >+ * We use a compact representation with 1 byte per statistics bin, >+ * thus the numbers directly represent byte sizes. >+ * This 1 byte per statistics bin contains the meaning of the MPS >+ * (more probable symbol) in the highest bit (mask 0x80), and the >+ * index into the probability estimation state machine table >+ * in the lower bits (mask 0x7F). >+ */ >+ >+#define DC_STAT_BINS 64 >+#define AC_STAT_BINS 256 >+ >+/* NOTE: Uncomment the following #define if you want to use the >+ * given formula for calculating the AC conditioning parameter Kx >+ * for spectral selection progressive coding in section G.1.3.2 >+ * of the spec (Kx = Kmin + SRL (8 + Se - Kmin) 4). >+ * Although the spec and P&M authors claim that this "has proven >+ * to give good results for 8 bit precision samples", I'm not >+ * convinced yet that this is really beneficial. >+ * Early tests gave only very marginal compression enhancements >+ * (a few - around 5 or so - bytes even for very large files), >+ * which would turn out rather negative if we'd suppress the >+ * DAC (Define Arithmetic Conditioning) marker segments for >+ * the default parameters in the future. >+ * Note that currently the marker writing module emits 12-byte >+ * DAC segments for a full-component scan in a color image. >+ * This is not worth worrying about IMHO. However, since the >+ * spec defines the default values to be used if the tables >+ * are omitted (unlike Huffman tables, which are required >+ * anyway), one might optimize this behaviour in the future, >+ * and then it would be disadvantageous to use custom tables if >+ * they don't provide sufficient gain to exceed the DAC size. >+ * >+ * On the other hand, I'd consider it as a reasonable result >+ * that the conditioning has no significant influence on the >+ * compression performance. This means that the basic >+ * statistical model is already rather stable. >+ * >+ * Thus, at the moment, we use the default conditioning values >+ * anyway, and do not use the custom formula. >+ * >+#define CALCULATE_SPECTRAL_CONDITIONING >+ */ >+ >+/* IRIGHT_SHIFT is like RIGHT_SHIFT, but works on int rather than INT32. >+ * We assume that int right shift is unsigned if INT32 right shift is, >+ * which should be safe. >+ */ >+ >+#ifdef RIGHT_SHIFT_IS_UNSIGNED >+#define ISHIFT_TEMPS int ishift_temp; >+#define IRIGHT_SHIFT(x,shft) \ >+ ((ishift_temp = (x)) < 0 ? \ >+ (ishift_temp >> (shft)) | ((~0) << (16-(shft))) : \ >+ (ishift_temp >> (shft))) >+#else >+#define ISHIFT_TEMPS >+#define IRIGHT_SHIFT(x,shft) ((x) >> (shft)) >+#endif >+ >+ >+LOCAL(void) >+emit_byte (int val, j_compress_ptr cinfo) >+/* Write next output byte; we do not support suspension in this module. */ >+{ >+ struct jpeg_destination_mgr * dest = cinfo->dest; >+ >+ *dest->next_output_byte++ = (JOCTET) val; >+ if (--dest->free_in_buffer == 0) >+ if (! (*dest->empty_output_buffer) (cinfo)) >+ ERREXIT(cinfo, JERR_CANT_SUSPEND); >+} >+ >+ >+/* >+ * Finish up at the end of an arithmetic-compressed scan. >+ */ >+ >+METHODDEF(void) >+finish_pass (j_compress_ptr cinfo) >+{ >+ arith_entropy_ptr e = (arith_entropy_ptr) cinfo->entropy; >+ INT32 temp; >+ >+ /* Section D.1.8: Termination of encoding */ >+ >+ /* Find the e->c in the coding interval with the largest >+ * number of trailing zero bits */ >+ if ((temp = (e->a - 1 + e->c) & 0xFFFF0000L) < e->c) >+ e->c = temp + 0x8000L; >+ else >+ e->c = temp; >+ /* Send remaining bytes to output */ >+ e->c <<= e->ct; >+ if (e->c & 0xF8000000L) { >+ /* One final overflow has to be handled */ >+ if (e->buffer >= 0) { >+ if (e->zc) >+ do emit_byte(0x00, cinfo); >+ while (--e->zc); >+ emit_byte(e->buffer + 1, cinfo); >+ if (e->buffer + 1 == 0xFF) >+ emit_byte(0x00, cinfo); >+ } >+ e->zc += e->sc; /* carry-over converts stacked 0xFF bytes to 0x00 */ >+ e->sc = 0; >+ } else { >+ if (e->buffer == 0) >+ ++e->zc; >+ else if (e->buffer >= 0) { >+ if (e->zc) >+ do emit_byte(0x00, cinfo); >+ while (--e->zc); >+ emit_byte(e->buffer, cinfo); >+ } >+ if (e->sc) { >+ if (e->zc) >+ do emit_byte(0x00, cinfo); >+ while (--e->zc); >+ do { >+ emit_byte(0xFF, cinfo); >+ emit_byte(0x00, cinfo); >+ } while (--e->sc); >+ } >+ } >+ /* Output final bytes only if they are not 0x00 */ >+ if (e->c & 0x7FFF800L) { >+ if (e->zc) /* output final pending zero bytes */ >+ do emit_byte(0x00, cinfo); >+ while (--e->zc); >+ emit_byte((e->c >> 19) & 0xFF, cinfo); >+ if (((e->c >> 19) & 0xFF) == 0xFF) >+ emit_byte(0x00, cinfo); >+ if (e->c & 0x7F800L) { >+ emit_byte((e->c >> 11) & 0xFF, cinfo); >+ if (((e->c >> 11) & 0xFF) == 0xFF) >+ emit_byte(0x00, cinfo); >+ } >+ } >+} >+ >+ >+/* >+ * The core arithmetic encoding routine (common in JPEG and JBIG). >+ * This needs to go as fast as possible. >+ * Machine-dependent optimization facilities >+ * are not utilized in this portable implementation. >+ * However, this code should be fairly efficient and >+ * may be a good base for further optimizations anyway. >+ * >+ * Parameter 'val' to be encoded may be 0 or 1 (binary decision). >+ * >+ * Note: I've added full "Pacman" termination support to the >+ * byte output routines, which is equivalent to the optional >+ * Discard_final_zeros procedure (Figure D.15) in the spec. >+ * Thus, we always produce the shortest possible output >+ * stream compliant to the spec (no trailing zero bytes, >+ * except for FF stuffing). >+ * >+ * I've also introduced a new scheme for accessing >+ * the probability estimation state machine table, >+ * derived from Markus Kuhn's JBIG implementation. >+ */ >+ >+LOCAL(void) >+arith_encode (j_compress_ptr cinfo, unsigned char *st, int val) >+{ >+ register arith_entropy_ptr e = (arith_entropy_ptr) cinfo->entropy; >+ register unsigned char nl, nm; >+ register INT32 qe, temp; >+ register int sv; >+ >+ /* Fetch values from our compact representation of Table D.2: >+ * Qe values and probability estimation state machine >+ */ >+ sv = *st; >+ qe = jpeg_aritab[sv & 0x7F]; /* => Qe_Value */ >+ nl = qe & 0xFF; qe >>= 8; /* Next_Index_LPS + Switch_MPS */ >+ nm = qe & 0xFF; qe >>= 8; /* Next_Index_MPS */ >+ >+ /* Encode & estimation procedures per sections D.1.4 & D.1.5 */ >+ e->a -= qe; >+ if (val != (sv >> 7)) { >+ /* Encode the less probable symbol */ >+ if (e->a >= qe) { >+ /* If the interval size (qe) for the less probable symbol (LPS) >+ * is larger than the interval size for the MPS, then exchange >+ * the two symbols for coding efficiency, otherwise code the LPS >+ * as usual: */ >+ e->c += e->a; >+ e->a = qe; >+ } >+ *st = (sv & 0x80) ^ nl; /* Estimate_after_LPS */ >+ } else { >+ /* Encode the more probable symbol */ >+ if (e->a >= 0x8000L) >+ return; /* A >= 0x8000 -> ready, no renormalization required */ >+ if (e->a < qe) { >+ /* If the interval size (qe) for the less probable symbol (LPS) >+ * is larger than the interval size for the MPS, then exchange >+ * the two symbols for coding efficiency: */ >+ e->c += e->a; >+ e->a = qe; >+ } >+ *st = (sv & 0x80) ^ nm; /* Estimate_after_MPS */ >+ } >+ >+ /* Renormalization & data output per section D.1.6 */ >+ do { >+ e->a <<= 1; >+ e->c <<= 1; >+ if (--e->ct == 0) { >+ /* Another byte is ready for output */ >+ temp = e->c >> 19; >+ if (temp > 0xFF) { >+ /* Handle overflow over all stacked 0xFF bytes */ >+ if (e->buffer >= 0) { >+ if (e->zc) >+ do emit_byte(0x00, cinfo); >+ while (--e->zc); >+ emit_byte(e->buffer + 1, cinfo); >+ if (e->buffer + 1 == 0xFF) >+ emit_byte(0x00, cinfo); >+ } >+ e->zc += e->sc; /* carry-over converts stacked 0xFF bytes to 0x00 */ >+ e->sc = 0; >+ /* Note: The 3 spacer bits in the C register guarantee >+ * that the new buffer byte can't be 0xFF here >+ * (see page 160 in the P&M JPEG book). */ >+ e->buffer = temp & 0xFF; /* new output byte, might overflow later */ >+ } else if (temp == 0xFF) { >+ ++e->sc; /* stack 0xFF byte (which might overflow later) */ >+ } else { >+ /* Output all stacked 0xFF bytes, they will not overflow any more */ >+ if (e->buffer == 0) >+ ++e->zc; >+ else if (e->buffer >= 0) { >+ if (e->zc) >+ do emit_byte(0x00, cinfo); >+ while (--e->zc); >+ emit_byte(e->buffer, cinfo); >+ } >+ if (e->sc) { >+ if (e->zc) >+ do emit_byte(0x00, cinfo); >+ while (--e->zc); >+ do { >+ emit_byte(0xFF, cinfo); >+ emit_byte(0x00, cinfo); >+ } while (--e->sc); >+ } >+ e->buffer = temp & 0xFF; /* new output byte (can still overflow) */ >+ } >+ e->c &= 0x7FFFFL; >+ e->ct += 8; >+ } >+ } while (e->a < 0x8000L); >+} >+ >+ >+/* >+ * Emit a restart marker & resynchronize predictions. >+ */ >+ >+LOCAL(void) >+emit_restart (j_compress_ptr cinfo, int restart_num) >+{ >+ arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy; >+ int ci; >+ jpeg_component_info * compptr; >+ >+ finish_pass(cinfo); >+ >+ emit_byte(0xFF, cinfo); >+ emit_byte(JPEG_RST0 + restart_num, cinfo); >+ >+ /* Re-initialize statistics areas */ >+ for (ci = 0; ci < cinfo->comps_in_scan; ci++) { >+ compptr = cinfo->cur_comp_info[ci]; >+ /* DC needs no table for refinement scan */ >+ if (cinfo->progressive_mode == 0 || (cinfo->Ss == 0 && cinfo->Ah == 0)) { >+ MEMZERO(entropy->dc_stats[compptr->dc_tbl_no], DC_STAT_BINS); >+ /* Reset DC predictions to 0 */ >+ entropy->last_dc_val[ci] = 0; >+ entropy->dc_context[ci] = 0; >+ } >+ /* AC needs no table when not present */ >+ if (cinfo->progressive_mode == 0 || cinfo->Se) { >+ MEMZERO(entropy->ac_stats[compptr->ac_tbl_no], AC_STAT_BINS); >+ } >+ } >+ >+ /* Reset arithmetic encoding variables */ >+ entropy->c = 0; >+ entropy->a = 0x10000L; >+ entropy->sc = 0; >+ entropy->zc = 0; >+ entropy->ct = 11; >+ entropy->buffer = -1; /* empty */ >+} >+ >+ >+/* >+ * MCU encoding for DC initial scan (either spectral selection, >+ * or first pass of successive approximation). >+ */ >+ >+METHODDEF(boolean) >+encode_mcu_DC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data) >+{ >+ arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy; >+ JBLOCKROW block; >+ unsigned char *st; >+ int blkn, ci, tbl; >+ int v, v2, m; >+ ISHIFT_TEMPS >+ >+ /* Emit restart marker if needed */ >+ if (cinfo->restart_interval) { >+ if (entropy->restarts_to_go == 0) { >+ emit_restart(cinfo, entropy->next_restart_num); >+ entropy->restarts_to_go = cinfo->restart_interval; >+ entropy->next_restart_num++; >+ entropy->next_restart_num &= 7; >+ } >+ entropy->restarts_to_go--; >+ } >+ >+ /* Encode the MCU data blocks */ >+ for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) { >+ block = MCU_data[blkn]; >+ ci = cinfo->MCU_membership[blkn]; >+ tbl = cinfo->cur_comp_info[ci]->dc_tbl_no; >+ >+ /* Compute the DC value after the required point transform by Al. >+ * This is simply an arithmetic right shift. >+ */ >+ m = IRIGHT_SHIFT((int) ((*block)[0]), cinfo->Al); >+ >+ /* Sections F.1.4.1 & F.1.4.4.1: Encoding of DC coefficients */ >+ >+ /* Table F.4: Point to statistics bin S0 for DC coefficient coding */ >+ st = entropy->dc_stats[tbl] + entropy->dc_context[ci]; >+ >+ /* Figure F.4: Encode_DC_DIFF */ >+ if ((v = m - entropy->last_dc_val[ci]) == 0) { >+ arith_encode(cinfo, st, 0); >+ entropy->dc_context[ci] = 0; /* zero diff category */ >+ } else { >+ entropy->last_dc_val[ci] = m; >+ arith_encode(cinfo, st, 1); >+ /* Figure F.6: Encoding nonzero value v */ >+ /* Figure F.7: Encoding the sign of v */ >+ if (v > 0) { >+ arith_encode(cinfo, st + 1, 0); /* Table F.4: SS = S0 + 1 */ >+ st += 2; /* Table F.4: SP = S0 + 2 */ >+ entropy->dc_context[ci] = 4; /* small positive diff category */ >+ } else { >+ v = -v; >+ arith_encode(cinfo, st + 1, 1); /* Table F.4: SS = S0 + 1 */ >+ st += 3; /* Table F.4: SN = S0 + 3 */ >+ entropy->dc_context[ci] = 8; /* small negative diff category */ >+ } >+ /* Figure F.8: Encoding the magnitude category of v */ >+ m = 0; >+ if (v -= 1) { >+ arith_encode(cinfo, st, 1); >+ m = 1; >+ v2 = v; >+ st = entropy->dc_stats[tbl] + 20; /* Table F.4: X1 = 20 */ >+ while (v2 >>= 1) { >+ arith_encode(cinfo, st, 1); >+ m <<= 1; >+ st += 1; >+ } >+ } >+ arith_encode(cinfo, st, 0); >+ /* Section F.1.4.4.1.2: Establish dc_context conditioning category */ >+ if (m < (int) ((1L << cinfo->arith_dc_L[tbl]) >> 1)) >+ entropy->dc_context[ci] = 0; /* zero diff category */ >+ else if (m > (int) ((1L << cinfo->arith_dc_U[tbl]) >> 1)) >+ entropy->dc_context[ci] += 8; /* large diff category */ >+ /* Figure F.9: Encoding the magnitude bit pattern of v */ >+ st += 14; >+ while (m >>= 1) >+ arith_encode(cinfo, st, (m & v) ? 1 : 0); >+ } >+ } >+ >+ return TRUE; >+} >+ >+ >+/* >+ * MCU encoding for AC initial scan (either spectral selection, >+ * or first pass of successive approximation). >+ */ >+ >+METHODDEF(boolean) >+encode_mcu_AC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data) >+{ >+ arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy; >+ JBLOCKROW block; >+ unsigned char *st; >+ int tbl, k, ke; >+ int v, v2, m; >+ >+ /* Emit restart marker if needed */ >+ if (cinfo->restart_interval) { >+ if (entropy->restarts_to_go == 0) { >+ emit_restart(cinfo, entropy->next_restart_num); >+ entropy->restarts_to_go = cinfo->restart_interval; >+ entropy->next_restart_num++; >+ entropy->next_restart_num &= 7; >+ } >+ entropy->restarts_to_go--; >+ } >+ >+ /* Encode the MCU data block */ >+ block = MCU_data[0]; >+ tbl = cinfo->cur_comp_info[0]->ac_tbl_no; >+ >+ /* Sections F.1.4.2 & F.1.4.4.2: Encoding of AC coefficients */ >+ >+ /* Establish EOB (end-of-block) index */ >+ for (ke = cinfo->Se; ke > 0; ke--) >+ /* We must apply the point transform by Al. For AC coefficients this >+ * is an integer division with rounding towards 0. To do this portably >+ * in C, we shift after obtaining the absolute value. >+ */ >+ if ((v = (*block)[jpeg_natural_order[ke]]) >= 0) { >+ if (v >>= cinfo->Al) break; >+ } else { >+ v = -v; >+ if (v >>= cinfo->Al) break; >+ } >+ >+ /* Figure F.5: Encode_AC_Coefficients */ >+ for (k = cinfo->Ss; k <= ke; k++) { >+ st = entropy->ac_stats[tbl] + 3 * (k - 1); >+ arith_encode(cinfo, st, 0); /* EOB decision */ >+ for (;;) { >+ if ((v = (*block)[jpeg_natural_order[k]]) >= 0) { >+ if (v >>= cinfo->Al) { >+ arith_encode(cinfo, st + 1, 1); >+ arith_encode(cinfo, entropy->fixed_bin, 0); >+ break; >+ } >+ } else { >+ v = -v; >+ if (v >>= cinfo->Al) { >+ arith_encode(cinfo, st + 1, 1); >+ arith_encode(cinfo, entropy->fixed_bin, 1); >+ break; >+ } >+ } >+ arith_encode(cinfo, st + 1, 0); st += 3; k++; >+ } >+ st += 2; >+ /* Figure F.8: Encoding the magnitude category of v */ >+ m = 0; >+ if (v -= 1) { >+ arith_encode(cinfo, st, 1); >+ m = 1; >+ v2 = v; >+ if (v2 >>= 1) { >+ arith_encode(cinfo, st, 1); >+ m <<= 1; >+ st = entropy->ac_stats[tbl] + >+ (k <= cinfo->arith_ac_K[tbl] ? 189 : 217); >+ while (v2 >>= 1) { >+ arith_encode(cinfo, st, 1); >+ m <<= 1; >+ st += 1; >+ } >+ } >+ } >+ arith_encode(cinfo, st, 0); >+ /* Figure F.9: Encoding the magnitude bit pattern of v */ >+ st += 14; >+ while (m >>= 1) >+ arith_encode(cinfo, st, (m & v) ? 1 : 0); >+ } >+ /* Encode EOB decision only if k <= cinfo->Se */ >+ if (k <= cinfo->Se) { >+ st = entropy->ac_stats[tbl] + 3 * (k - 1); >+ arith_encode(cinfo, st, 1); >+ } >+ >+ return TRUE; >+} >+ >+ >+/* >+ * MCU encoding for DC successive approximation refinement scan. >+ */ >+ >+METHODDEF(boolean) >+encode_mcu_DC_refine (j_compress_ptr cinfo, JBLOCKROW *MCU_data) >+{ >+ arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy; >+ unsigned char *st; >+ int Al, blkn; >+ >+ /* Emit restart marker if needed */ >+ if (cinfo->restart_interval) { >+ if (entropy->restarts_to_go == 0) { >+ emit_restart(cinfo, entropy->next_restart_num); >+ entropy->restarts_to_go = cinfo->restart_interval; >+ entropy->next_restart_num++; >+ entropy->next_restart_num &= 7; >+ } >+ entropy->restarts_to_go--; >+ } >+ >+ st = entropy->fixed_bin; /* use fixed probability estimation */ >+ Al = cinfo->Al; >+ >+ /* Encode the MCU data blocks */ >+ for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) { >+ /* We simply emit the Al'th bit of the DC coefficient value. */ >+ arith_encode(cinfo, st, (MCU_data[blkn][0][0] >> Al) & 1); >+ } >+ >+ return TRUE; >+} >+ >+ >+/* >+ * MCU encoding for AC successive approximation refinement scan. >+ */ >+ >+METHODDEF(boolean) >+encode_mcu_AC_refine (j_compress_ptr cinfo, JBLOCKROW *MCU_data) >+{ >+ arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy; >+ JBLOCKROW block; >+ unsigned char *st; >+ int tbl, k, ke, kex; >+ int v; >+ >+ /* Emit restart marker if needed */ >+ if (cinfo->restart_interval) { >+ if (entropy->restarts_to_go == 0) { >+ emit_restart(cinfo, entropy->next_restart_num); >+ entropy->restarts_to_go = cinfo->restart_interval; >+ entropy->next_restart_num++; >+ entropy->next_restart_num &= 7; >+ } >+ entropy->restarts_to_go--; >+ } >+ >+ /* Encode the MCU data block */ >+ block = MCU_data[0]; >+ tbl = cinfo->cur_comp_info[0]->ac_tbl_no; >+ >+ /* Section G.1.3.3: Encoding of AC coefficients */ >+ >+ /* Establish EOB (end-of-block) index */ >+ for (ke = cinfo->Se; ke > 0; ke--) >+ /* We must apply the point transform by Al. For AC coefficients this >+ * is an integer division with rounding towards 0. To do this portably >+ * in C, we shift after obtaining the absolute value. >+ */ >+ if ((v = (*block)[jpeg_natural_order[ke]]) >= 0) { >+ if (v >>= cinfo->Al) break; >+ } else { >+ v = -v; >+ if (v >>= cinfo->Al) break; >+ } >+ >+ /* Establish EOBx (previous stage end-of-block) index */ >+ for (kex = ke; kex > 0; kex--) >+ if ((v = (*block)[jpeg_natural_order[kex]]) >= 0) { >+ if (v >>= cinfo->Ah) break; >+ } else { >+ v = -v; >+ if (v >>= cinfo->Ah) break; >+ } >+ >+ /* Figure G.10: Encode_AC_Coefficients_SA */ >+ for (k = cinfo->Ss; k <= ke; k++) { >+ st = entropy->ac_stats[tbl] + 3 * (k - 1); >+ if (k > kex) >+ arith_encode(cinfo, st, 0); /* EOB decision */ >+ for (;;) { >+ if ((v = (*block)[jpeg_natural_order[k]]) >= 0) { >+ if (v >>= cinfo->Al) { >+ if (v >> 1) /* previously nonzero coef */ >+ arith_encode(cinfo, st + 2, (v & 1)); >+ else { /* newly nonzero coef */ >+ arith_encode(cinfo, st + 1, 1); >+ arith_encode(cinfo, entropy->fixed_bin, 0); >+ } >+ break; >+ } >+ } else { >+ v = -v; >+ if (v >>= cinfo->Al) { >+ if (v >> 1) /* previously nonzero coef */ >+ arith_encode(cinfo, st + 2, (v & 1)); >+ else { /* newly nonzero coef */ >+ arith_encode(cinfo, st + 1, 1); >+ arith_encode(cinfo, entropy->fixed_bin, 1); >+ } >+ break; >+ } >+ } >+ arith_encode(cinfo, st + 1, 0); st += 3; k++; >+ } >+ } >+ /* Encode EOB decision only if k <= cinfo->Se */ >+ if (k <= cinfo->Se) { >+ st = entropy->ac_stats[tbl] + 3 * (k - 1); >+ arith_encode(cinfo, st, 1); >+ } >+ >+ return TRUE; >+} >+ >+ >+/* >+ * Encode and output one MCU's worth of arithmetic-compressed coefficients. >+ */ >+ >+METHODDEF(boolean) >+encode_mcu (j_compress_ptr cinfo, JBLOCKROW *MCU_data) >+{ >+ arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy; >+ jpeg_component_info * compptr; >+ JBLOCKROW block; >+ unsigned char *st; >+ int blkn, ci, tbl, k, ke; >+ int v, v2, m; >+ >+ /* Emit restart marker if needed */ >+ if (cinfo->restart_interval) { >+ if (entropy->restarts_to_go == 0) { >+ emit_restart(cinfo, entropy->next_restart_num); >+ entropy->restarts_to_go = cinfo->restart_interval; >+ entropy->next_restart_num++; >+ entropy->next_restart_num &= 7; >+ } >+ entropy->restarts_to_go--; >+ } >+ >+ /* Encode the MCU data blocks */ >+ for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) { >+ block = MCU_data[blkn]; >+ ci = cinfo->MCU_membership[blkn]; >+ compptr = cinfo->cur_comp_info[ci]; >+ >+ /* Sections F.1.4.1 & F.1.4.4.1: Encoding of DC coefficients */ >+ >+ tbl = compptr->dc_tbl_no; >+ >+ /* Table F.4: Point to statistics bin S0 for DC coefficient coding */ >+ st = entropy->dc_stats[tbl] + entropy->dc_context[ci]; >+ >+ /* Figure F.4: Encode_DC_DIFF */ >+ if ((v = (*block)[0] - entropy->last_dc_val[ci]) == 0) { >+ arith_encode(cinfo, st, 0); >+ entropy->dc_context[ci] = 0; /* zero diff category */ >+ } else { >+ entropy->last_dc_val[ci] = (*block)[0]; >+ arith_encode(cinfo, st, 1); >+ /* Figure F.6: Encoding nonzero value v */ >+ /* Figure F.7: Encoding the sign of v */ >+ if (v > 0) { >+ arith_encode(cinfo, st + 1, 0); /* Table F.4: SS = S0 + 1 */ >+ st += 2; /* Table F.4: SP = S0 + 2 */ >+ entropy->dc_context[ci] = 4; /* small positive diff category */ >+ } else { >+ v = -v; >+ arith_encode(cinfo, st + 1, 1); /* Table F.4: SS = S0 + 1 */ >+ st += 3; /* Table F.4: SN = S0 + 3 */ >+ entropy->dc_context[ci] = 8; /* small negative diff category */ >+ } >+ /* Figure F.8: Encoding the magnitude category of v */ >+ m = 0; >+ if (v -= 1) { >+ arith_encode(cinfo, st, 1); >+ m = 1; >+ v2 = v; >+ st = entropy->dc_stats[tbl] + 20; /* Table F.4: X1 = 20 */ >+ while (v2 >>= 1) { >+ arith_encode(cinfo, st, 1); >+ m <<= 1; >+ st += 1; >+ } >+ } >+ arith_encode(cinfo, st, 0); >+ /* Section F.1.4.4.1.2: Establish dc_context conditioning category */ >+ if (m < (int) ((1L << cinfo->arith_dc_L[tbl]) >> 1)) >+ entropy->dc_context[ci] = 0; /* zero diff category */ >+ else if (m > (int) ((1L << cinfo->arith_dc_U[tbl]) >> 1)) >+ entropy->dc_context[ci] += 8; /* large diff category */ >+ /* Figure F.9: Encoding the magnitude bit pattern of v */ >+ st += 14; >+ while (m >>= 1) >+ arith_encode(cinfo, st, (m & v) ? 1 : 0); >+ } >+ >+ /* Sections F.1.4.2 & F.1.4.4.2: Encoding of AC coefficients */ >+ >+ tbl = compptr->ac_tbl_no; >+ >+ /* Establish EOB (end-of-block) index */ >+ for (ke = DCTSIZE2 - 1; ke > 0; ke--) >+ if ((*block)[jpeg_natural_order[ke]]) break; >+ >+ /* Figure F.5: Encode_AC_Coefficients */ >+ for (k = 1; k <= ke; k++) { >+ st = entropy->ac_stats[tbl] + 3 * (k - 1); >+ arith_encode(cinfo, st, 0); /* EOB decision */ >+ while ((v = (*block)[jpeg_natural_order[k]]) == 0) { >+ arith_encode(cinfo, st + 1, 0); st += 3; k++; >+ } >+ arith_encode(cinfo, st + 1, 1); >+ /* Figure F.6: Encoding nonzero value v */ >+ /* Figure F.7: Encoding the sign of v */ >+ if (v > 0) { >+ arith_encode(cinfo, entropy->fixed_bin, 0); >+ } else { >+ v = -v; >+ arith_encode(cinfo, entropy->fixed_bin, 1); >+ } >+ st += 2; >+ /* Figure F.8: Encoding the magnitude category of v */ >+ m = 0; >+ if (v -= 1) { >+ arith_encode(cinfo, st, 1); >+ m = 1; >+ v2 = v; >+ if (v2 >>= 1) { >+ arith_encode(cinfo, st, 1); >+ m <<= 1; >+ st = entropy->ac_stats[tbl] + >+ (k <= cinfo->arith_ac_K[tbl] ? 189 : 217); >+ while (v2 >>= 1) { >+ arith_encode(cinfo, st, 1); >+ m <<= 1; >+ st += 1; >+ } >+ } >+ } >+ arith_encode(cinfo, st, 0); >+ /* Figure F.9: Encoding the magnitude bit pattern of v */ >+ st += 14; >+ while (m >>= 1) >+ arith_encode(cinfo, st, (m & v) ? 1 : 0); >+ } >+ /* Encode EOB decision only if k <= DCTSIZE2 - 1 */ >+ if (k <= DCTSIZE2 - 1) { >+ st = entropy->ac_stats[tbl] + 3 * (k - 1); >+ arith_encode(cinfo, st, 1); >+ } >+ } >+ >+ return TRUE; >+} >+ >+ >+/* >+ * Initialize for an arithmetic-compressed scan. >+ */ >+ >+METHODDEF(void) >+start_pass (j_compress_ptr cinfo, boolean gather_statistics) >+{ >+ arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy; >+ int ci, tbl; >+ jpeg_component_info * compptr; >+ >+ if (gather_statistics) >+ /* Make sure to avoid that in the master control logic! >+ * We are fully adaptive here and need no extra >+ * statistics gathering pass! >+ */ >+ ERREXIT(cinfo, JERR_NOT_COMPILED); >+ >+ /* We assume jcmaster.c already validated the progressive scan parameters. */ >+ >+ /* Select execution routines */ >+ if (cinfo->progressive_mode) { >+ if (cinfo->Ah == 0) { >+ if (cinfo->Ss == 0) >+ entropy->pub.encode_mcu = encode_mcu_DC_first; >+ else >+ entropy->pub.encode_mcu = encode_mcu_AC_first; >+ } else { >+ if (cinfo->Ss == 0) >+ entropy->pub.encode_mcu = encode_mcu_DC_refine; >+ else >+ entropy->pub.encode_mcu = encode_mcu_AC_refine; >+ } >+ } else >+ entropy->pub.encode_mcu = encode_mcu; >+ >+ /* Allocate & initialize requested statistics areas */ >+ for (ci = 0; ci < cinfo->comps_in_scan; ci++) { >+ compptr = cinfo->cur_comp_info[ci]; >+ /* DC needs no table for refinement scan */ >+ if (cinfo->progressive_mode == 0 || (cinfo->Ss == 0 && cinfo->Ah == 0)) { >+ tbl = compptr->dc_tbl_no; >+ if (tbl < 0 || tbl >= NUM_ARITH_TBLS) >+ ERREXIT1(cinfo, JERR_NO_ARITH_TABLE, tbl); >+ if (entropy->dc_stats[tbl] == NULL) >+ entropy->dc_stats[tbl] = (unsigned char *) (*cinfo->mem->alloc_small) >+ ((j_common_ptr) cinfo, JPOOL_IMAGE, DC_STAT_BINS); >+ MEMZERO(entropy->dc_stats[tbl], DC_STAT_BINS); >+ /* Initialize DC predictions to 0 */ >+ entropy->last_dc_val[ci] = 0; >+ entropy->dc_context[ci] = 0; >+ } >+ /* AC needs no table when not present */ >+ if (cinfo->progressive_mode == 0 || cinfo->Se) { >+ tbl = compptr->ac_tbl_no; >+ if (tbl < 0 || tbl >= NUM_ARITH_TBLS) >+ ERREXIT1(cinfo, JERR_NO_ARITH_TABLE, tbl); >+ if (entropy->ac_stats[tbl] == NULL) >+ entropy->ac_stats[tbl] = (unsigned char *) (*cinfo->mem->alloc_small) >+ ((j_common_ptr) cinfo, JPOOL_IMAGE, AC_STAT_BINS); >+ MEMZERO(entropy->ac_stats[tbl], AC_STAT_BINS); >+#ifdef CALCULATE_SPECTRAL_CONDITIONING >+ if (cinfo->progressive_mode) >+ /* Section G.1.3.2: Set appropriate arithmetic conditioning value Kx */ >+ cinfo->arith_ac_K[tbl] = cinfo->Ss + ((8 + cinfo->Se - cinfo->Ss) >> 4); >+#endif >+ } >+ } >+ >+ /* Initialize arithmetic encoding variables */ >+ entropy->c = 0; >+ entropy->a = 0x10000L; >+ entropy->sc = 0; >+ entropy->zc = 0; >+ entropy->ct = 11; >+ entropy->buffer = -1; /* empty */ >+ >+ /* Initialize restart stuff */ >+ entropy->restarts_to_go = cinfo->restart_interval; >+ entropy->next_restart_num = 0; >+} >+ >+ >+/* >+ * Module initialization routine for arithmetic entropy encoding. >+ */ >+ >+GLOBAL(void) >+jinit_arith_encoder (j_compress_ptr cinfo) >+{ >+ arith_entropy_ptr entropy; >+ int i; >+ >+ entropy = (arith_entropy_ptr) >+ (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, >+ SIZEOF(arith_entropy_encoder)); >+ cinfo->entropy = (struct jpeg_entropy_encoder *) entropy; >+ entropy->pub.start_pass = start_pass; >+ entropy->pub.finish_pass = finish_pass; >+ >+ /* Mark tables unallocated */ >+ for (i = 0; i < NUM_ARITH_TBLS; i++) { >+ entropy->dc_stats[i] = NULL; >+ entropy->ac_stats[i] = NULL; >+ } >+ >+ /* Initialize index for fixed probability estimation */ >+ entropy->fixed_bin[0] = 113; >+} >only in patch2: >--- a/jpeg/jcinit.c >+++ b/jpeg/jcinit.c >@@ -44,3 +44,7 @@ > if (cinfo->arith_code) { >+#ifdef C_ARITH_CODING_SUPPORTED >+ jinit_arith_encoder(cinfo); >+#else > ERREXIT(cinfo, JERR_ARITH_NOTIMPL); >+#endif > } else { >only in patch2: >--- a/jpeg/jcmaster.c >+++ b/jpeg/jcmaster.c >@@ -4,2 +4,4 @@ > * Copyright (C) 1991-1997, Thomas G. Lane. >+ * Modified 2003-2010 by Guido Vollbeding. >+ * Copyright (C) 2010, D. R. Commander. > * This file is part of the Independent JPEG Group's software. >@@ -16,2 +18,3 @@ > #include "jpeglib.h" >+#include "jpegcomp.h" > >@@ -44,4 +47,24 @@ > >+#if JPEG_LIB_VERSION >= 70 >+/* >+ * Compute JPEG image dimensions and related values. >+ * NOTE: this is exported for possible use by application. >+ * Hence it mustn't do anything that can't be done twice. >+ */ >+ >+GLOBAL(void) >+jpeg_calc_jpeg_dimensions (j_compress_ptr cinfo) >+/* Do computations that are needed before master selection phase */ >+{ >+ /* Hardwire it to "no scaling" */ >+ cinfo->jpeg_width = cinfo->image_width; >+ cinfo->jpeg_height = cinfo->image_height; >+ cinfo->min_DCT_h_scaled_size = DCTSIZE; >+ cinfo->min_DCT_v_scaled_size = DCTSIZE; >+} >+#endif >+ >+ > LOCAL(void) >-initial_setup (j_compress_ptr cinfo) >+initial_setup (j_compress_ptr cinfo, boolean transcode_only) > /* Do computations that are needed before master selection phase */ >@@ -53,4 +76,9 @@ > >+#if JPEG_LIB_VERSION >= 70 >+ if (!transcode_only) >+ jpeg_calc_jpeg_dimensions(cinfo); >+#endif >+ > /* Sanity check on image dimensions */ >- if (cinfo->image_height <= 0 || cinfo->image_width <= 0 >+ if (cinfo->_jpeg_height <= 0 || cinfo->_jpeg_width <= 0 > || cinfo->num_components <= 0 || cinfo->input_components <= 0) >@@ -59,4 +87,4 @@ > /* Make sure image isn't bigger than I can handle */ >- if ((long) cinfo->image_height > (long) JPEG_MAX_DIMENSION || >- (long) cinfo->image_width > (long) JPEG_MAX_DIMENSION) >+ if ((long) cinfo->_jpeg_height > (long) JPEG_MAX_DIMENSION || >+ (long) cinfo->_jpeg_width > (long) JPEG_MAX_DIMENSION) > ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) JPEG_MAX_DIMENSION); >@@ -98,9 +126,13 @@ > /* For compression, we never do DCT scaling. */ >+#if JPEG_LIB_VERSION >= 70 >+ compptr->DCT_h_scaled_size = compptr->DCT_v_scaled_size = DCTSIZE; >+#else > compptr->DCT_scaled_size = DCTSIZE; >+#endif > /* Size in DCT blocks */ > compptr->width_in_blocks = (JDIMENSION) >- jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor, >+ jdiv_round_up((long) cinfo->_jpeg_width * (long) compptr->h_samp_factor, > (long) (cinfo->max_h_samp_factor * DCTSIZE)); > compptr->height_in_blocks = (JDIMENSION) >- jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor, >+ jdiv_round_up((long) cinfo->_jpeg_height * (long) compptr->v_samp_factor, > (long) (cinfo->max_v_samp_factor * DCTSIZE)); >@@ -108,6 +140,6 @@ > compptr->downsampled_width = (JDIMENSION) >- jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor, >+ jdiv_round_up((long) cinfo->_jpeg_width * (long) compptr->h_samp_factor, > (long) cinfo->max_h_samp_factor); > compptr->downsampled_height = (JDIMENSION) >- jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor, >+ jdiv_round_up((long) cinfo->_jpeg_height * (long) compptr->v_samp_factor, > (long) cinfo->max_v_samp_factor); >@@ -121,3 +153,3 @@ > cinfo->total_iMCU_rows = (JDIMENSION) >- jdiv_round_up((long) cinfo->image_height, >+ jdiv_round_up((long) cinfo->_jpeg_height, > (long) (cinfo->max_v_samp_factor*DCTSIZE)); >@@ -349,6 +381,6 @@ > cinfo->MCUs_per_row = (JDIMENSION) >- jdiv_round_up((long) cinfo->image_width, >+ jdiv_round_up((long) cinfo->_jpeg_width, > (long) (cinfo->max_h_samp_factor*DCTSIZE)); > cinfo->MCU_rows_in_scan = (JDIMENSION) >- jdiv_round_up((long) cinfo->image_height, >+ jdiv_round_up((long) cinfo->_jpeg_height, > (long) (cinfo->max_v_samp_factor*DCTSIZE)); >@@ -556,3 +588,3 @@ > /* Validate parameters, determine derived values */ >- initial_setup(cinfo); >+ initial_setup(cinfo, transcode_only); > >only in patch2: >--- a/jpeg/jconfig.doc >+++ /dev/null >@@ -1,155 +0,0 @@ >-/* >- * jconfig.doc >- * >- * Copyright (C) 1991-1994, Thomas G. Lane. >- * This file is part of the Independent JPEG Group's software. >- * For conditions of distribution and use, see the accompanying README file. >- * >- * This file documents the configuration options that are required to >- * customize the JPEG software for a particular system. >- * >- * The actual configuration options for a particular installation are stored >- * in jconfig.h. On many machines, jconfig.h can be generated automatically >- * or copied from one of the "canned" jconfig files that we supply. But if >- * you need to generate a jconfig.h file by hand, this file tells you how. >- * >- * DO NOT EDIT THIS FILE --- IT WON'T ACCOMPLISH ANYTHING. >- * EDIT A COPY NAMED JCONFIG.H. >- */ >- >- >-/* >- * These symbols indicate the properties of your machine or compiler. >- * #define the symbol if yes, #undef it if no. >- */ >- >-/* Does your compiler support function prototypes? >- * (If not, you also need to use ansi2knr, see install.doc) >- */ >-#define HAVE_PROTOTYPES >- >-/* Does your compiler support the declaration "unsigned char" ? >- * How about "unsigned short" ? >- */ >-#define HAVE_UNSIGNED_CHAR >-#define HAVE_UNSIGNED_SHORT >- >-/* Define "void" as "char" if your compiler doesn't know about type void. >- * NOTE: be sure to define void such that "void *" represents the most general >- * pointer type, e.g., that returned by malloc(). >- */ >-/* #define void char */ >- >-/* Define "const" as empty if your compiler doesn't know the "const" keyword. >- */ >-/* #define const */ >- >-/* Define this if an ordinary "char" type is unsigned. >- * If you're not sure, leaving it undefined will work at some cost in speed. >- * If you defined HAVE_UNSIGNED_CHAR then the speed difference is minimal. >- */ >-#undef CHAR_IS_UNSIGNED >- >-/* Define this if your system has an ANSI-conforming <stddef.h> file. >- */ >-#define HAVE_STDDEF_H >- >-/* Define this if your system has an ANSI-conforming <stdlib.h> file. >- */ >-#define HAVE_STDLIB_H >- >-/* Define this if your system does not have an ANSI/SysV <string.h>, >- * but does have a BSD-style <strings.h>. >- */ >-#undef NEED_BSD_STRINGS >- >-/* Define this if your system does not provide typedef size_t in any of the >- * ANSI-standard places (stddef.h, stdlib.h, or stdio.h), but places it in >- * <sys/types.h> instead. >- */ >-#undef NEED_SYS_TYPES_H >- >-/* For 80x86 machines, you need to define NEED_FAR_POINTERS, >- * unless you are using a large-data memory model or 80386 flat-memory mode. >- * On less brain-damaged CPUs this symbol must not be defined. >- * (Defining this symbol causes large data structures to be referenced through >- * "far" pointers and to be allocated with a special version of malloc.) >- */ >-#undef NEED_FAR_POINTERS >- >-/* Define this if your linker needs global names to be unique in less >- * than the first 15 characters. >- */ >-#undef NEED_SHORT_EXTERNAL_NAMES >- >-/* Although a real ANSI C compiler can deal perfectly well with pointers to >- * unspecified structures (see "incomplete types" in the spec), a few pre-ANSI >- * and pseudo-ANSI compilers get confused. To keep one of these bozos happy, >- * define INCOMPLETE_TYPES_BROKEN. This is not recommended unless you >- * actually get "missing structure definition" warnings or errors while >- * compiling the JPEG code. >- */ >-#undef INCOMPLETE_TYPES_BROKEN >- >- >-/* >- * The following options affect code selection within the JPEG library, >- * but they don't need to be visible to applications using the library. >- * To minimize application namespace pollution, the symbols won't be >- * defined unless JPEG_INTERNALS has been defined. >- */ >- >-#ifdef JPEG_INTERNALS >- >-/* Define this if your compiler implements ">>" on signed values as a logical >- * (unsigned) shift; leave it undefined if ">>" is a signed (arithmetic) shift, >- * which is the normal and rational definition. >- */ >-#undef RIGHT_SHIFT_IS_UNSIGNED >- >- >-#endif /* JPEG_INTERNALS */ >- >- >-/* >- * The remaining options do not affect the JPEG library proper, >- * but only the sample applications cjpeg/djpeg (see cjpeg.c, djpeg.c). >- * Other applications can ignore these. >- */ >- >-#ifdef JPEG_CJPEG_DJPEG >- >-/* These defines indicate which image (non-JPEG) file formats are allowed. */ >- >-#define BMP_SUPPORTED /* BMP image file format */ >-#define GIF_SUPPORTED /* GIF image file format */ >-#define PPM_SUPPORTED /* PBMPLUS PPM/PGM image file format */ >-#undef RLE_SUPPORTED /* Utah RLE image file format */ >-#define TARGA_SUPPORTED /* Targa image file format */ >- >-/* Define this if you want to name both input and output files on the command >- * line, rather than using stdout and optionally stdin. You MUST do this if >- * your system can't cope with binary I/O to stdin/stdout. See comments at >- * head of cjpeg.c or djpeg.c. >- */ >-#undef TWO_FILE_COMMANDLINE >- >-/* Define this if your system needs explicit cleanup of temporary files. >- * This is crucial under MS-DOS, where the temporary "files" may be areas >- * of extended memory; on most other systems it's not as important. >- */ >-#undef NEED_SIGNAL_CATCHER >- >-/* By default, we open image files with fopen(...,"rb") or fopen(...,"wb"). >- * This is necessary on systems that distinguish text files from binary files, >- * and is harmless on most systems that don't. If you have one of the rare >- * systems that complains about the "b" spec, define this symbol. >- */ >-#undef DONT_USE_B_MODE >- >-/* Define this if you want percent-done progress reports from cjpeg/djpeg. >- */ >-#undef PROGRESS_REPORT >- >- >-#endif /* JPEG_CJPEG_DJPEG */ >only in patch2: >--- a/jpeg/jdapistd.c >+++ b/jpeg/jdapistd.c >@@ -4,2 +4,3 @@ > * Copyright (C) 1994-1996, Thomas G. Lane. >+ * Copyright (C) 2010, D. R. Commander. > * This file is part of the Independent JPEG Group's software. >@@ -19,2 +20,3 @@ > #include "jpeglib.h" >+#include "jpegcomp.h" > >@@ -204,3 +206,3 @@ > /* Verify that at least one iMCU row can be returned. */ >- lines_per_iMCU_row = cinfo->max_v_samp_factor * cinfo->min_DCT_scaled_size; >+ lines_per_iMCU_row = cinfo->max_v_samp_factor * cinfo->_min_DCT_scaled_size; > if (max_lines < lines_per_iMCU_row) >only in patch2: >--- /dev/null >+++ b/jpeg/jdarith.c >@@ -0,0 +1,761 @@ >+/* >+ * jdarith.c >+ * >+ * Developed 1997-2009 by Guido Vollbeding. >+ * This file is part of the Independent JPEG Group's software. >+ * For conditions of distribution and use, see the accompanying README file. >+ * >+ * This file contains portable arithmetic entropy decoding routines for JPEG >+ * (implementing the ISO/IEC IS 10918-1 and CCITT Recommendation ITU-T T.81). >+ * >+ * Both sequential and progressive modes are supported in this single module. >+ * >+ * Suspension is not currently supported in this module. >+ */ >+ >+#define JPEG_INTERNALS >+#include "jinclude.h" >+#include "jpeglib.h" >+ >+ >+/* Expanded entropy decoder object for arithmetic decoding. */ >+ >+typedef struct { >+ struct jpeg_entropy_decoder pub; /* public fields */ >+ >+ INT32 c; /* C register, base of coding interval + input bit buffer */ >+ INT32 a; /* A register, normalized size of coding interval */ >+ int ct; /* bit shift counter, # of bits left in bit buffer part of C */ >+ /* init: ct = -16 */ >+ /* run: ct = 0..7 */ >+ /* error: ct = -1 */ >+ int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */ >+ int dc_context[MAX_COMPS_IN_SCAN]; /* context index for DC conditioning */ >+ >+ unsigned int restarts_to_go; /* MCUs left in this restart interval */ >+ >+ /* Pointers to statistics areas (these workspaces have image lifespan) */ >+ unsigned char * dc_stats[NUM_ARITH_TBLS]; >+ unsigned char * ac_stats[NUM_ARITH_TBLS]; >+ >+ /* Statistics bin for coding with fixed probability 0.5 */ >+ unsigned char fixed_bin[4]; >+} arith_entropy_decoder; >+ >+typedef arith_entropy_decoder * arith_entropy_ptr; >+ >+/* The following two definitions specify the allocation chunk size >+ * for the statistics area. >+ * According to sections F.1.4.4.1.3 and F.1.4.4.2, we need at least >+ * 49 statistics bins for DC, and 245 statistics bins for AC coding. >+ * >+ * We use a compact representation with 1 byte per statistics bin, >+ * thus the numbers directly represent byte sizes. >+ * This 1 byte per statistics bin contains the meaning of the MPS >+ * (more probable symbol) in the highest bit (mask 0x80), and the >+ * index into the probability estimation state machine table >+ * in the lower bits (mask 0x7F). >+ */ >+ >+#define DC_STAT_BINS 64 >+#define AC_STAT_BINS 256 >+ >+ >+LOCAL(int) >+get_byte (j_decompress_ptr cinfo) >+/* Read next input byte; we do not support suspension in this module. */ >+{ >+ struct jpeg_source_mgr * src = cinfo->src; >+ >+ if (src->bytes_in_buffer == 0) >+ if (! (*src->fill_input_buffer) (cinfo)) >+ ERREXIT(cinfo, JERR_CANT_SUSPEND); >+ src->bytes_in_buffer--; >+ return GETJOCTET(*src->next_input_byte++); >+} >+ >+ >+/* >+ * The core arithmetic decoding routine (common in JPEG and JBIG). >+ * This needs to go as fast as possible. >+ * Machine-dependent optimization facilities >+ * are not utilized in this portable implementation. >+ * However, this code should be fairly efficient and >+ * may be a good base for further optimizations anyway. >+ * >+ * Return value is 0 or 1 (binary decision). >+ * >+ * Note: I've changed the handling of the code base & bit >+ * buffer register C compared to other implementations >+ * based on the standards layout & procedures. >+ * While it also contains both the actual base of the >+ * coding interval (16 bits) and the next-bits buffer, >+ * the cut-point between these two parts is floating >+ * (instead of fixed) with the bit shift counter CT. >+ * Thus, we also need only one (variable instead of >+ * fixed size) shift for the LPS/MPS decision, and >+ * we can get away with any renormalization update >+ * of C (except for new data insertion, of course). >+ * >+ * I've also introduced a new scheme for accessing >+ * the probability estimation state machine table, >+ * derived from Markus Kuhn's JBIG implementation. >+ */ >+ >+LOCAL(int) >+arith_decode (j_decompress_ptr cinfo, unsigned char *st) >+{ >+ register arith_entropy_ptr e = (arith_entropy_ptr) cinfo->entropy; >+ register unsigned char nl, nm; >+ register INT32 qe, temp; >+ register int sv, data; >+ >+ /* Renormalization & data input per section D.2.6 */ >+ while (e->a < 0x8000L) { >+ if (--e->ct < 0) { >+ /* Need to fetch next data byte */ >+ if (cinfo->unread_marker) >+ data = 0; /* stuff zero data */ >+ else { >+ data = get_byte(cinfo); /* read next input byte */ >+ if (data == 0xFF) { /* zero stuff or marker code */ >+ do data = get_byte(cinfo); >+ while (data == 0xFF); /* swallow extra 0xFF bytes */ >+ if (data == 0) >+ data = 0xFF; /* discard stuffed zero byte */ >+ else { >+ /* Note: Different from the Huffman decoder, hitting >+ * a marker while processing the compressed data >+ * segment is legal in arithmetic coding. >+ * The convention is to supply zero data >+ * then until decoding is complete. >+ */ >+ cinfo->unread_marker = data; >+ data = 0; >+ } >+ } >+ } >+ e->c = (e->c << 8) | data; /* insert data into C register */ >+ if ((e->ct += 8) < 0) /* update bit shift counter */ >+ /* Need more initial bytes */ >+ if (++e->ct == 0) >+ /* Got 2 initial bytes -> re-init A and exit loop */ >+ e->a = 0x8000L; /* => e->a = 0x10000L after loop exit */ >+ } >+ e->a <<= 1; >+ } >+ >+ /* Fetch values from our compact representation of Table D.2: >+ * Qe values and probability estimation state machine >+ */ >+ sv = *st; >+ qe = jpeg_aritab[sv & 0x7F]; /* => Qe_Value */ >+ nl = qe & 0xFF; qe >>= 8; /* Next_Index_LPS + Switch_MPS */ >+ nm = qe & 0xFF; qe >>= 8; /* Next_Index_MPS */ >+ >+ /* Decode & estimation procedures per sections D.2.4 & D.2.5 */ >+ temp = e->a - qe; >+ e->a = temp; >+ temp <<= e->ct; >+ if (e->c >= temp) { >+ e->c -= temp; >+ /* Conditional LPS (less probable symbol) exchange */ >+ if (e->a < qe) { >+ e->a = qe; >+ *st = (sv & 0x80) ^ nm; /* Estimate_after_MPS */ >+ } else { >+ e->a = qe; >+ *st = (sv & 0x80) ^ nl; /* Estimate_after_LPS */ >+ sv ^= 0x80; /* Exchange LPS/MPS */ >+ } >+ } else if (e->a < 0x8000L) { >+ /* Conditional MPS (more probable symbol) exchange */ >+ if (e->a < qe) { >+ *st = (sv & 0x80) ^ nl; /* Estimate_after_LPS */ >+ sv ^= 0x80; /* Exchange LPS/MPS */ >+ } else { >+ *st = (sv & 0x80) ^ nm; /* Estimate_after_MPS */ >+ } >+ } >+ >+ return sv >> 7; >+} >+ >+ >+/* >+ * Check for a restart marker & resynchronize decoder. >+ */ >+ >+LOCAL(void) >+process_restart (j_decompress_ptr cinfo) >+{ >+ arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy; >+ int ci; >+ jpeg_component_info * compptr; >+ >+ /* Advance past the RSTn marker */ >+ if (! (*cinfo->marker->read_restart_marker) (cinfo)) >+ ERREXIT(cinfo, JERR_CANT_SUSPEND); >+ >+ /* Re-initialize statistics areas */ >+ for (ci = 0; ci < cinfo->comps_in_scan; ci++) { >+ compptr = cinfo->cur_comp_info[ci]; >+ if (! cinfo->progressive_mode || (cinfo->Ss == 0 && cinfo->Ah == 0)) { >+ MEMZERO(entropy->dc_stats[compptr->dc_tbl_no], DC_STAT_BINS); >+ /* Reset DC predictions to 0 */ >+ entropy->last_dc_val[ci] = 0; >+ entropy->dc_context[ci] = 0; >+ } >+ if (! cinfo->progressive_mode || cinfo->Ss) { >+ MEMZERO(entropy->ac_stats[compptr->ac_tbl_no], AC_STAT_BINS); >+ } >+ } >+ >+ /* Reset arithmetic decoding variables */ >+ entropy->c = 0; >+ entropy->a = 0; >+ entropy->ct = -16; /* force reading 2 initial bytes to fill C */ >+ >+ /* Reset restart counter */ >+ entropy->restarts_to_go = cinfo->restart_interval; >+} >+ >+ >+/* >+ * Arithmetic MCU decoding. >+ * Each of these routines decodes and returns one MCU's worth of >+ * arithmetic-compressed coefficients. >+ * The coefficients are reordered from zigzag order into natural array order, >+ * but are not dequantized. >+ * >+ * The i'th block of the MCU is stored into the block pointed to by >+ * MCU_data[i]. WE ASSUME THIS AREA IS INITIALLY ZEROED BY THE CALLER. >+ */ >+ >+/* >+ * MCU decoding for DC initial scan (either spectral selection, >+ * or first pass of successive approximation). >+ */ >+ >+METHODDEF(boolean) >+decode_mcu_DC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data) >+{ >+ arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy; >+ JBLOCKROW block; >+ unsigned char *st; >+ int blkn, ci, tbl, sign; >+ int v, m; >+ >+ /* Process restart marker if needed */ >+ if (cinfo->restart_interval) { >+ if (entropy->restarts_to_go == 0) >+ process_restart(cinfo); >+ entropy->restarts_to_go--; >+ } >+ >+ if (entropy->ct == -1) return TRUE; /* if error do nothing */ >+ >+ /* Outer loop handles each block in the MCU */ >+ >+ for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) { >+ block = MCU_data[blkn]; >+ ci = cinfo->MCU_membership[blkn]; >+ tbl = cinfo->cur_comp_info[ci]->dc_tbl_no; >+ >+ /* Sections F.2.4.1 & F.1.4.4.1: Decoding of DC coefficients */ >+ >+ /* Table F.4: Point to statistics bin S0 for DC coefficient coding */ >+ st = entropy->dc_stats[tbl] + entropy->dc_context[ci]; >+ >+ /* Figure F.19: Decode_DC_DIFF */ >+ if (arith_decode(cinfo, st) == 0) >+ entropy->dc_context[ci] = 0; >+ else { >+ /* Figure F.21: Decoding nonzero value v */ >+ /* Figure F.22: Decoding the sign of v */ >+ sign = arith_decode(cinfo, st + 1); >+ st += 2; st += sign; >+ /* Figure F.23: Decoding the magnitude category of v */ >+ if ((m = arith_decode(cinfo, st)) != 0) { >+ st = entropy->dc_stats[tbl] + 20; /* Table F.4: X1 = 20 */ >+ while (arith_decode(cinfo, st)) { >+ if ((m <<= 1) == 0x8000) { >+ WARNMS(cinfo, JWRN_ARITH_BAD_CODE); >+ entropy->ct = -1; /* magnitude overflow */ >+ return TRUE; >+ } >+ st += 1; >+ } >+ } >+ /* Section F.1.4.4.1.2: Establish dc_context conditioning category */ >+ if (m < (int) ((1L << cinfo->arith_dc_L[tbl]) >> 1)) >+ entropy->dc_context[ci] = 0; /* zero diff category */ >+ else if (m > (int) ((1L << cinfo->arith_dc_U[tbl]) >> 1)) >+ entropy->dc_context[ci] = 12 + (sign * 4); /* large diff category */ >+ else >+ entropy->dc_context[ci] = 4 + (sign * 4); /* small diff category */ >+ v = m; >+ /* Figure F.24: Decoding the magnitude bit pattern of v */ >+ st += 14; >+ while (m >>= 1) >+ if (arith_decode(cinfo, st)) v |= m; >+ v += 1; if (sign) v = -v; >+ entropy->last_dc_val[ci] += v; >+ } >+ >+ /* Scale and output the DC coefficient (assumes jpeg_natural_order[0]=0) */ >+ (*block)[0] = (JCOEF) (entropy->last_dc_val[ci] << cinfo->Al); >+ } >+ >+ return TRUE; >+} >+ >+ >+/* >+ * MCU decoding for AC initial scan (either spectral selection, >+ * or first pass of successive approximation). >+ */ >+ >+METHODDEF(boolean) >+decode_mcu_AC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data) >+{ >+ arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy; >+ JBLOCKROW block; >+ unsigned char *st; >+ int tbl, sign, k; >+ int v, m; >+ >+ /* Process restart marker if needed */ >+ if (cinfo->restart_interval) { >+ if (entropy->restarts_to_go == 0) >+ process_restart(cinfo); >+ entropy->restarts_to_go--; >+ } >+ >+ if (entropy->ct == -1) return TRUE; /* if error do nothing */ >+ >+ /* There is always only one block per MCU */ >+ block = MCU_data[0]; >+ tbl = cinfo->cur_comp_info[0]->ac_tbl_no; >+ >+ /* Sections F.2.4.2 & F.1.4.4.2: Decoding of AC coefficients */ >+ >+ /* Figure F.20: Decode_AC_coefficients */ >+ for (k = cinfo->Ss; k <= cinfo->Se; k++) { >+ st = entropy->ac_stats[tbl] + 3 * (k - 1); >+ if (arith_decode(cinfo, st)) break; /* EOB flag */ >+ while (arith_decode(cinfo, st + 1) == 0) { >+ st += 3; k++; >+ if (k > cinfo->Se) { >+ WARNMS(cinfo, JWRN_ARITH_BAD_CODE); >+ entropy->ct = -1; /* spectral overflow */ >+ return TRUE; >+ } >+ } >+ /* Figure F.21: Decoding nonzero value v */ >+ /* Figure F.22: Decoding the sign of v */ >+ sign = arith_decode(cinfo, entropy->fixed_bin); >+ st += 2; >+ /* Figure F.23: Decoding the magnitude category of v */ >+ if ((m = arith_decode(cinfo, st)) != 0) { >+ if (arith_decode(cinfo, st)) { >+ m <<= 1; >+ st = entropy->ac_stats[tbl] + >+ (k <= cinfo->arith_ac_K[tbl] ? 189 : 217); >+ while (arith_decode(cinfo, st)) { >+ if ((m <<= 1) == 0x8000) { >+ WARNMS(cinfo, JWRN_ARITH_BAD_CODE); >+ entropy->ct = -1; /* magnitude overflow */ >+ return TRUE; >+ } >+ st += 1; >+ } >+ } >+ } >+ v = m; >+ /* Figure F.24: Decoding the magnitude bit pattern of v */ >+ st += 14; >+ while (m >>= 1) >+ if (arith_decode(cinfo, st)) v |= m; >+ v += 1; if (sign) v = -v; >+ /* Scale and output coefficient in natural (dezigzagged) order */ >+ (*block)[jpeg_natural_order[k]] = (JCOEF) (v << cinfo->Al); >+ } >+ >+ return TRUE; >+} >+ >+ >+/* >+ * MCU decoding for DC successive approximation refinement scan. >+ */ >+ >+METHODDEF(boolean) >+decode_mcu_DC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data) >+{ >+ arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy; >+ unsigned char *st; >+ int p1, blkn; >+ >+ /* Process restart marker if needed */ >+ if (cinfo->restart_interval) { >+ if (entropy->restarts_to_go == 0) >+ process_restart(cinfo); >+ entropy->restarts_to_go--; >+ } >+ >+ st = entropy->fixed_bin; /* use fixed probability estimation */ >+ p1 = 1 << cinfo->Al; /* 1 in the bit position being coded */ >+ >+ /* Outer loop handles each block in the MCU */ >+ >+ for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) { >+ /* Encoded data is simply the next bit of the two's-complement DC value */ >+ if (arith_decode(cinfo, st)) >+ MCU_data[blkn][0][0] |= p1; >+ } >+ >+ return TRUE; >+} >+ >+ >+/* >+ * MCU decoding for AC successive approximation refinement scan. >+ */ >+ >+METHODDEF(boolean) >+decode_mcu_AC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data) >+{ >+ arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy; >+ JBLOCKROW block; >+ JCOEFPTR thiscoef; >+ unsigned char *st; >+ int tbl, k, kex; >+ int p1, m1; >+ >+ /* Process restart marker if needed */ >+ if (cinfo->restart_interval) { >+ if (entropy->restarts_to_go == 0) >+ process_restart(cinfo); >+ entropy->restarts_to_go--; >+ } >+ >+ if (entropy->ct == -1) return TRUE; /* if error do nothing */ >+ >+ /* There is always only one block per MCU */ >+ block = MCU_data[0]; >+ tbl = cinfo->cur_comp_info[0]->ac_tbl_no; >+ >+ p1 = 1 << cinfo->Al; /* 1 in the bit position being coded */ >+ m1 = (-1) << cinfo->Al; /* -1 in the bit position being coded */ >+ >+ /* Establish EOBx (previous stage end-of-block) index */ >+ for (kex = cinfo->Se; kex > 0; kex--) >+ if ((*block)[jpeg_natural_order[kex]]) break; >+ >+ for (k = cinfo->Ss; k <= cinfo->Se; k++) { >+ st = entropy->ac_stats[tbl] + 3 * (k - 1); >+ if (k > kex) >+ if (arith_decode(cinfo, st)) break; /* EOB flag */ >+ for (;;) { >+ thiscoef = *block + jpeg_natural_order[k]; >+ if (*thiscoef) { /* previously nonzero coef */ >+ if (arith_decode(cinfo, st + 2)) { >+ if (*thiscoef < 0) >+ *thiscoef += m1; >+ else >+ *thiscoef += p1; >+ } >+ break; >+ } >+ if (arith_decode(cinfo, st + 1)) { /* newly nonzero coef */ >+ if (arith_decode(cinfo, entropy->fixed_bin)) >+ *thiscoef = m1; >+ else >+ *thiscoef = p1; >+ break; >+ } >+ st += 3; k++; >+ if (k > cinfo->Se) { >+ WARNMS(cinfo, JWRN_ARITH_BAD_CODE); >+ entropy->ct = -1; /* spectral overflow */ >+ return TRUE; >+ } >+ } >+ } >+ >+ return TRUE; >+} >+ >+ >+/* >+ * Decode one MCU's worth of arithmetic-compressed coefficients. >+ */ >+ >+METHODDEF(boolean) >+decode_mcu (j_decompress_ptr cinfo, JBLOCKROW *MCU_data) >+{ >+ arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy; >+ jpeg_component_info * compptr; >+ JBLOCKROW block; >+ unsigned char *st; >+ int blkn, ci, tbl, sign, k; >+ int v, m; >+ >+ /* Process restart marker if needed */ >+ if (cinfo->restart_interval) { >+ if (entropy->restarts_to_go == 0) >+ process_restart(cinfo); >+ entropy->restarts_to_go--; >+ } >+ >+ if (entropy->ct == -1) return TRUE; /* if error do nothing */ >+ >+ /* Outer loop handles each block in the MCU */ >+ >+ for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) { >+ block = MCU_data[blkn]; >+ ci = cinfo->MCU_membership[blkn]; >+ compptr = cinfo->cur_comp_info[ci]; >+ >+ /* Sections F.2.4.1 & F.1.4.4.1: Decoding of DC coefficients */ >+ >+ tbl = compptr->dc_tbl_no; >+ >+ /* Table F.4: Point to statistics bin S0 for DC coefficient coding */ >+ st = entropy->dc_stats[tbl] + entropy->dc_context[ci]; >+ >+ /* Figure F.19: Decode_DC_DIFF */ >+ if (arith_decode(cinfo, st) == 0) >+ entropy->dc_context[ci] = 0; >+ else { >+ /* Figure F.21: Decoding nonzero value v */ >+ /* Figure F.22: Decoding the sign of v */ >+ sign = arith_decode(cinfo, st + 1); >+ st += 2; st += sign; >+ /* Figure F.23: Decoding the magnitude category of v */ >+ if ((m = arith_decode(cinfo, st)) != 0) { >+ st = entropy->dc_stats[tbl] + 20; /* Table F.4: X1 = 20 */ >+ while (arith_decode(cinfo, st)) { >+ if ((m <<= 1) == 0x8000) { >+ WARNMS(cinfo, JWRN_ARITH_BAD_CODE); >+ entropy->ct = -1; /* magnitude overflow */ >+ return TRUE; >+ } >+ st += 1; >+ } >+ } >+ /* Section F.1.4.4.1.2: Establish dc_context conditioning category */ >+ if (m < (int) ((1L << cinfo->arith_dc_L[tbl]) >> 1)) >+ entropy->dc_context[ci] = 0; /* zero diff category */ >+ else if (m > (int) ((1L << cinfo->arith_dc_U[tbl]) >> 1)) >+ entropy->dc_context[ci] = 12 + (sign * 4); /* large diff category */ >+ else >+ entropy->dc_context[ci] = 4 + (sign * 4); /* small diff category */ >+ v = m; >+ /* Figure F.24: Decoding the magnitude bit pattern of v */ >+ st += 14; >+ while (m >>= 1) >+ if (arith_decode(cinfo, st)) v |= m; >+ v += 1; if (sign) v = -v; >+ entropy->last_dc_val[ci] += v; >+ } >+ >+ (*block)[0] = (JCOEF) entropy->last_dc_val[ci]; >+ >+ /* Sections F.2.4.2 & F.1.4.4.2: Decoding of AC coefficients */ >+ >+ tbl = compptr->ac_tbl_no; >+ >+ /* Figure F.20: Decode_AC_coefficients */ >+ for (k = 1; k <= DCTSIZE2 - 1; k++) { >+ st = entropy->ac_stats[tbl] + 3 * (k - 1); >+ if (arith_decode(cinfo, st)) break; /* EOB flag */ >+ while (arith_decode(cinfo, st + 1) == 0) { >+ st += 3; k++; >+ if (k > DCTSIZE2 - 1) { >+ WARNMS(cinfo, JWRN_ARITH_BAD_CODE); >+ entropy->ct = -1; /* spectral overflow */ >+ return TRUE; >+ } >+ } >+ /* Figure F.21: Decoding nonzero value v */ >+ /* Figure F.22: Decoding the sign of v */ >+ sign = arith_decode(cinfo, entropy->fixed_bin); >+ st += 2; >+ /* Figure F.23: Decoding the magnitude category of v */ >+ if ((m = arith_decode(cinfo, st)) != 0) { >+ if (arith_decode(cinfo, st)) { >+ m <<= 1; >+ st = entropy->ac_stats[tbl] + >+ (k <= cinfo->arith_ac_K[tbl] ? 189 : 217); >+ while (arith_decode(cinfo, st)) { >+ if ((m <<= 1) == 0x8000) { >+ WARNMS(cinfo, JWRN_ARITH_BAD_CODE); >+ entropy->ct = -1; /* magnitude overflow */ >+ return TRUE; >+ } >+ st += 1; >+ } >+ } >+ } >+ v = m; >+ /* Figure F.24: Decoding the magnitude bit pattern of v */ >+ st += 14; >+ while (m >>= 1) >+ if (arith_decode(cinfo, st)) v |= m; >+ v += 1; if (sign) v = -v; >+ (*block)[jpeg_natural_order[k]] = (JCOEF) v; >+ } >+ } >+ >+ return TRUE; >+} >+ >+ >+/* >+ * Initialize for an arithmetic-compressed scan. >+ */ >+ >+METHODDEF(void) >+start_pass (j_decompress_ptr cinfo) >+{ >+ arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy; >+ int ci, tbl; >+ jpeg_component_info * compptr; >+ >+ if (cinfo->progressive_mode) { >+ /* Validate progressive scan parameters */ >+ if (cinfo->Ss == 0) { >+ if (cinfo->Se != 0) >+ goto bad; >+ } else { >+ /* need not check Ss/Se < 0 since they came from unsigned bytes */ >+ if (cinfo->Se < cinfo->Ss || cinfo->Se > DCTSIZE2 - 1) >+ goto bad; >+ /* AC scans may have only one component */ >+ if (cinfo->comps_in_scan != 1) >+ goto bad; >+ } >+ if (cinfo->Ah != 0) { >+ /* Successive approximation refinement scan: must have Al = Ah-1. */ >+ if (cinfo->Ah-1 != cinfo->Al) >+ goto bad; >+ } >+ if (cinfo->Al > 13) { /* need not check for < 0 */ >+ bad: >+ ERREXIT4(cinfo, JERR_BAD_PROGRESSION, >+ cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al); >+ } >+ /* Update progression status, and verify that scan order is legal. >+ * Note that inter-scan inconsistencies are treated as warnings >+ * not fatal errors ... not clear if this is right way to behave. >+ */ >+ for (ci = 0; ci < cinfo->comps_in_scan; ci++) { >+ int coefi, cindex = cinfo->cur_comp_info[ci]->component_index; >+ int *coef_bit_ptr = & cinfo->coef_bits[cindex][0]; >+ if (cinfo->Ss && coef_bit_ptr[0] < 0) /* AC without prior DC scan */ >+ WARNMS2(cinfo, JWRN_BOGUS_PROGRESSION, cindex, 0); >+ for (coefi = cinfo->Ss; coefi <= cinfo->Se; coefi++) { >+ int expected = (coef_bit_ptr[coefi] < 0) ? 0 : coef_bit_ptr[coefi]; >+ if (cinfo->Ah != expected) >+ WARNMS2(cinfo, JWRN_BOGUS_PROGRESSION, cindex, coefi); >+ coef_bit_ptr[coefi] = cinfo->Al; >+ } >+ } >+ /* Select MCU decoding routine */ >+ if (cinfo->Ah == 0) { >+ if (cinfo->Ss == 0) >+ entropy->pub.decode_mcu = decode_mcu_DC_first; >+ else >+ entropy->pub.decode_mcu = decode_mcu_AC_first; >+ } else { >+ if (cinfo->Ss == 0) >+ entropy->pub.decode_mcu = decode_mcu_DC_refine; >+ else >+ entropy->pub.decode_mcu = decode_mcu_AC_refine; >+ } >+ } else { >+ /* Check that the scan parameters Ss, Se, Ah/Al are OK for sequential JPEG. >+ * This ought to be an error condition, but we make it a warning. >+ */ >+ if (cinfo->Ss != 0 || cinfo->Ah != 0 || cinfo->Al != 0 || >+ (cinfo->Se < DCTSIZE2 && cinfo->Se != DCTSIZE2 - 1)) >+ WARNMS(cinfo, JWRN_NOT_SEQUENTIAL); >+ /* Select MCU decoding routine */ >+ entropy->pub.decode_mcu = decode_mcu; >+ } >+ >+ /* Allocate & initialize requested statistics areas */ >+ for (ci = 0; ci < cinfo->comps_in_scan; ci++) { >+ compptr = cinfo->cur_comp_info[ci]; >+ if (! cinfo->progressive_mode || (cinfo->Ss == 0 && cinfo->Ah == 0)) { >+ tbl = compptr->dc_tbl_no; >+ if (tbl < 0 || tbl >= NUM_ARITH_TBLS) >+ ERREXIT1(cinfo, JERR_NO_ARITH_TABLE, tbl); >+ if (entropy->dc_stats[tbl] == NULL) >+ entropy->dc_stats[tbl] = (unsigned char *) (*cinfo->mem->alloc_small) >+ ((j_common_ptr) cinfo, JPOOL_IMAGE, DC_STAT_BINS); >+ MEMZERO(entropy->dc_stats[tbl], DC_STAT_BINS); >+ /* Initialize DC predictions to 0 */ >+ entropy->last_dc_val[ci] = 0; >+ entropy->dc_context[ci] = 0; >+ } >+ if (! cinfo->progressive_mode || cinfo->Ss) { >+ tbl = compptr->ac_tbl_no; >+ if (tbl < 0 || tbl >= NUM_ARITH_TBLS) >+ ERREXIT1(cinfo, JERR_NO_ARITH_TABLE, tbl); >+ if (entropy->ac_stats[tbl] == NULL) >+ entropy->ac_stats[tbl] = (unsigned char *) (*cinfo->mem->alloc_small) >+ ((j_common_ptr) cinfo, JPOOL_IMAGE, AC_STAT_BINS); >+ MEMZERO(entropy->ac_stats[tbl], AC_STAT_BINS); >+ } >+ } >+ >+ /* Initialize arithmetic decoding variables */ >+ entropy->c = 0; >+ entropy->a = 0; >+ entropy->ct = -16; /* force reading 2 initial bytes to fill C */ >+ >+ /* Initialize restart counter */ >+ entropy->restarts_to_go = cinfo->restart_interval; >+} >+ >+ >+/* >+ * Module initialization routine for arithmetic entropy decoding. >+ */ >+ >+GLOBAL(void) >+jinit_arith_decoder (j_decompress_ptr cinfo) >+{ >+ arith_entropy_ptr entropy; >+ int i; >+ >+ entropy = (arith_entropy_ptr) >+ (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, >+ SIZEOF(arith_entropy_decoder)); >+ cinfo->entropy = (struct jpeg_entropy_decoder *) entropy; >+ entropy->pub.start_pass = start_pass; >+ >+ /* Mark tables unallocated */ >+ for (i = 0; i < NUM_ARITH_TBLS; i++) { >+ entropy->dc_stats[i] = NULL; >+ entropy->ac_stats[i] = NULL; >+ } >+ >+ /* Initialize index for fixed probability estimation */ >+ entropy->fixed_bin[0] = 113; >+ >+ if (cinfo->progressive_mode) { >+ /* Create progression status table */ >+ int *coef_bit_ptr, ci; >+ cinfo->coef_bits = (int (*)[DCTSIZE2]) >+ (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, >+ cinfo->num_components*DCTSIZE2*SIZEOF(int)); >+ coef_bit_ptr = & cinfo->coef_bits[0][0]; >+ for (ci = 0; ci < cinfo->num_components; ci++) >+ for (i = 0; i < DCTSIZE2; i++) >+ *coef_bit_ptr++ = -1; >+ } >+} >only in patch2: >--- a/jpeg/jdatasrc.c >+++ b/jpeg/jdatasrc.c >@@ -4,2 +4,3 @@ > * Copyright (C) 1994-1996, Thomas G. Lane. >+ * Modified 2009-2010 by Guido Vollbeding. > * This file is part of the Independent JPEG Group's software. >@@ -8,5 +9,5 @@ > * This file contains decompression data source routines for the case of >- * reading JPEG data from a file (or any stdio stream). While these routines >- * are sufficient for most applications, some will want to use a different >- * source manager. >+ * reading JPEG data from memory or from a file (or any stdio stream). >+ * While these routines are sufficient for most applications, >+ * some will want to use a different source manager. > * IMPORTANT: we assume that fread() will correctly transcribe an array of >@@ -54,2 +55,10 @@ > >+#if JPEG_LIB_VERSION >= 80 >+METHODDEF(void) >+init_mem_source (j_decompress_ptr cinfo) >+{ >+ /* no work necessary here */ >+} >+#endif >+ > >@@ -113,2 +122,24 @@ > >+#if JPEG_LIB_VERSION >= 80 >+METHODDEF(boolean) >+fill_mem_input_buffer (j_decompress_ptr cinfo) >+{ >+ static JOCTET mybuffer[4]; >+ >+ /* The whole JPEG data is expected to reside in the supplied memory >+ * buffer, so any request for more data beyond the given buffer size >+ * is treated as an error. >+ */ >+ WARNMS(cinfo, JWRN_JPEG_EOF); >+ /* Insert a fake EOI marker */ >+ mybuffer[0] = (JOCTET) 0xFF; >+ mybuffer[1] = (JOCTET) JPEG_EOI; >+ >+ cinfo->src->next_input_byte = mybuffer; >+ cinfo->src->bytes_in_buffer = 2; >+ >+ return TRUE; >+} >+#endif >+ > >@@ -129,3 +160,3 @@ > { >- my_src_ptr src = (my_src_ptr) cinfo->src; >+ struct jpeg_source_mgr * src = cinfo->src; > >@@ -136,5 +167,5 @@ > if (num_bytes > 0) { >- while (num_bytes > (long) src->pub.bytes_in_buffer) { >- num_bytes -= (long) src->pub.bytes_in_buffer; >- (void) fill_input_buffer(cinfo); >+ while (num_bytes > (long) src->bytes_in_buffer) { >+ num_bytes -= (long) src->bytes_in_buffer; >+ (void) (*src->fill_input_buffer) (cinfo); > /* note we assume that fill_input_buffer will never return FALSE, >@@ -143,4 +174,4 @@ > } >- src->pub.next_input_byte += (size_t) num_bytes; >- src->pub.bytes_in_buffer -= (size_t) num_bytes; >+ src->next_input_byte += (size_t) num_bytes; >+ src->bytes_in_buffer -= (size_t) num_bytes; > } >@@ -212 +243,38 @@ > } >+ >+ >+#if JPEG_LIB_VERSION >= 80 >+/* >+ * Prepare for input from a supplied memory buffer. >+ * The buffer must contain the whole JPEG data. >+ */ >+ >+GLOBAL(void) >+jpeg_mem_src (j_decompress_ptr cinfo, >+ unsigned char * inbuffer, unsigned long insize) >+{ >+ struct jpeg_source_mgr * src; >+ >+ if (inbuffer == NULL || insize == 0) /* Treat empty input as fatal error */ >+ ERREXIT(cinfo, JERR_INPUT_EMPTY); >+ >+ /* The source object is made permanent so that a series of JPEG images >+ * can be read from the same buffer by calling jpeg_mem_src only before >+ * the first one. >+ */ >+ if (cinfo->src == NULL) { /* first time for this JPEG object? */ >+ cinfo->src = (struct jpeg_source_mgr *) >+ (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT, >+ SIZEOF(struct jpeg_source_mgr)); >+ } >+ >+ src = cinfo->src; >+ src->init_source = init_mem_source; >+ src->fill_input_buffer = fill_mem_input_buffer; >+ src->skip_input_data = skip_input_data; >+ src->resync_to_restart = jpeg_resync_to_restart; /* use default method */ >+ src->term_source = term_source; >+ src->bytes_in_buffer = (size_t) insize; >+ src->next_input_byte = (JOCTET *) inbuffer; >+} >+#endif >only in patch2: >--- a/jpeg/jdinput.c >+++ b/jpeg/jdinput.c >@@ -4,2 +4,4 @@ > * Copyright (C) 1991-1997, Thomas G. Lane. >+ * Modified 2002-2009 by Guido Vollbeding. >+ * Copyright (C) 2010, D. R. Commander. > * This file is part of the Independent JPEG Group's software. >@@ -16,2 +18,3 @@ > #include "jpeglib.h" >+#include "jpegcomp.h" > >@@ -37,2 +40,75 @@ > >+ >+#if JPEG_LIB_VERSION >= 80 >+/* >+ * Compute output image dimensions and related values. >+ * NOTE: this is exported for possible use by application. >+ * Hence it mustn't do anything that can't be done twice. >+ */ >+ >+GLOBAL(void) >+jpeg_core_output_dimensions (j_decompress_ptr cinfo) >+/* Do computations that are needed before master selection phase. >+ * This function is used for transcoding and full decompression. >+ */ >+{ >+#ifdef IDCT_SCALING_SUPPORTED >+ int ci; >+ jpeg_component_info *compptr; >+ >+ /* Compute actual output image dimensions and DCT scaling choices. */ >+ if (cinfo->scale_num * cinfo->block_size <= cinfo->scale_denom) { >+ /* Provide 1/block_size scaling */ >+ cinfo->output_width = (JDIMENSION) >+ jdiv_round_up((long) cinfo->image_width, (long) cinfo->block_size); >+ cinfo->output_height = (JDIMENSION) >+ jdiv_round_up((long) cinfo->image_height, (long) cinfo->block_size); >+ cinfo->min_DCT_h_scaled_size = 1; >+ cinfo->min_DCT_v_scaled_size = 1; >+ } else if (cinfo->scale_num * cinfo->block_size <= cinfo->scale_denom * 2) { >+ /* Provide 2/block_size scaling */ >+ cinfo->output_width = (JDIMENSION) >+ jdiv_round_up((long) cinfo->image_width * 2L, (long) cinfo->block_size); >+ cinfo->output_height = (JDIMENSION) >+ jdiv_round_up((long) cinfo->image_height * 2L, (long) cinfo->block_size); >+ cinfo->min_DCT_h_scaled_size = 2; >+ cinfo->min_DCT_v_scaled_size = 2; >+ } else if (cinfo->scale_num * cinfo->block_size <= cinfo->scale_denom * 4) { >+ /* Provide 4/block_size scaling */ >+ cinfo->output_width = (JDIMENSION) >+ jdiv_round_up((long) cinfo->image_width * 4L, (long) cinfo->block_size); >+ cinfo->output_height = (JDIMENSION) >+ jdiv_round_up((long) cinfo->image_height * 4L, (long) cinfo->block_size); >+ cinfo->min_DCT_h_scaled_size = 4; >+ cinfo->min_DCT_v_scaled_size = 4; >+ } else if (cinfo->scale_num * cinfo->block_size <= cinfo->scale_denom * 8) { >+ /* Provide 8/block_size scaling */ >+ cinfo->output_width = (JDIMENSION) >+ jdiv_round_up((long) cinfo->image_width * 8L, (long) cinfo->block_size); >+ cinfo->output_height = (JDIMENSION) >+ jdiv_round_up((long) cinfo->image_height * 8L, (long) cinfo->block_size); >+ cinfo->min_DCT_h_scaled_size = 8; >+ cinfo->min_DCT_v_scaled_size = 8; >+ } >+ /* Recompute dimensions of components */ >+ for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; >+ ci++, compptr++) { >+ compptr->DCT_h_scaled_size = cinfo->min_DCT_h_scaled_size; >+ compptr->DCT_v_scaled_size = cinfo->min_DCT_v_scaled_size; >+ } >+ >+#else /* !IDCT_SCALING_SUPPORTED */ >+ >+ /* Hardwire it to "no scaling" */ >+ cinfo->output_width = cinfo->image_width; >+ cinfo->output_height = cinfo->image_height; >+ /* jdinput.c has already initialized DCT_scaled_size, >+ * and has computed unscaled downsampled_width and downsampled_height. >+ */ >+ >+#endif /* IDCT_SCALING_SUPPORTED */ >+} >+#endif >+ >+ > LOCAL(void) >@@ -72,2 +148,8 @@ > >+#if JPEG_LIB_VERSION >=80 >+ cinfo->block_size = DCTSIZE; >+ cinfo->natural_order = jpeg_natural_order; >+ cinfo->lim_Se = DCTSIZE2-1; >+#endif >+ > /* We initialize DCT_scaled_size and min_DCT_scaled_size to DCTSIZE. >@@ -76,3 +158,7 @@ > */ >+#if JPEG_LIB_VERSION >= 70 >+ cinfo->min_DCT_h_scaled_size = cinfo->min_DCT_v_scaled_size = DCTSIZE; >+#else > cinfo->min_DCT_scaled_size = DCTSIZE; >+#endif > >@@ -81,3 +167,7 @@ > ci++, compptr++) { >+#if JPEG_LIB_VERSION >= 70 >+ compptr->DCT_h_scaled_size = compptr->DCT_v_scaled_size = DCTSIZE; >+#else > compptr->DCT_scaled_size = DCTSIZE; >+#endif > /* Size in DCT blocks */ >@@ -140,3 +230,3 @@ > compptr->MCU_blocks = 1; >- compptr->MCU_sample_width = compptr->DCT_scaled_size; >+ compptr->MCU_sample_width = compptr->_DCT_scaled_size; > compptr->last_col_width = 1; >@@ -176,3 +266,3 @@ > compptr->MCU_blocks = compptr->MCU_width * compptr->MCU_height; >- compptr->MCU_sample_width = compptr->MCU_width * compptr->DCT_scaled_size; >+ compptr->MCU_sample_width = compptr->MCU_width * compptr->_DCT_scaled_size; > /* Figure number of non-dummy blocks in last MCU column & row */ >only in patch2: >--- a/jpeg/jdmainct.c >+++ b/jpeg/jdmainct.c >@@ -4,2 +4,3 @@ > * Copyright (C) 1994-1996, Thomas G. Lane. >+ * Copyright (C) 2010, D. R. Commander. > * This file is part of the Independent JPEG Group's software. >@@ -18,2 +19,3 @@ > #include "jpeglib.h" >+#include "jpegcomp.h" > >@@ -163,3 +165,3 @@ > int ci, rgroup; >- int M = cinfo->min_DCT_scaled_size; >+ int M = cinfo->_min_DCT_scaled_size; > jpeg_component_info *compptr; >@@ -177,4 +179,4 @@ > ci++, compptr++) { >- rgroup = (compptr->v_samp_factor * compptr->DCT_scaled_size) / >- cinfo->min_DCT_scaled_size; /* height of a row group of component */ >+ rgroup = (compptr->v_samp_factor * compptr->_DCT_scaled_size) / >+ cinfo->_min_DCT_scaled_size; /* height of a row group of component */ > /* Get space for pointer lists --- M+4 row groups in each list. >@@ -204,3 +206,3 @@ > int ci, i, rgroup; >- int M = cinfo->min_DCT_scaled_size; >+ int M = cinfo->_min_DCT_scaled_size; > jpeg_component_info *compptr; >@@ -210,4 +212,4 @@ > ci++, compptr++) { >- rgroup = (compptr->v_samp_factor * compptr->DCT_scaled_size) / >- cinfo->min_DCT_scaled_size; /* height of a row group of component */ >+ rgroup = (compptr->v_samp_factor * compptr->_DCT_scaled_size) / >+ cinfo->_min_DCT_scaled_size; /* height of a row group of component */ > xbuf0 = main->xbuffer[0][ci]; >@@ -244,3 +246,3 @@ > int ci, i, rgroup; >- int M = cinfo->min_DCT_scaled_size; >+ int M = cinfo->_min_DCT_scaled_size; > jpeg_component_info *compptr; >@@ -250,4 +252,4 @@ > ci++, compptr++) { >- rgroup = (compptr->v_samp_factor * compptr->DCT_scaled_size) / >- cinfo->min_DCT_scaled_size; /* height of a row group of component */ >+ rgroup = (compptr->v_samp_factor * compptr->_DCT_scaled_size) / >+ cinfo->_min_DCT_scaled_size; /* height of a row group of component */ > xbuf0 = main->xbuffer[0][ci]; >@@ -279,4 +281,4 @@ > /* Count sample rows in one iMCU row and in one row group */ >- iMCUheight = compptr->v_samp_factor * compptr->DCT_scaled_size; >- rgroup = iMCUheight / cinfo->min_DCT_scaled_size; >+ iMCUheight = compptr->v_samp_factor * compptr->_DCT_scaled_size; >+ rgroup = iMCUheight / cinfo->_min_DCT_scaled_size; > /* Count nondummy sample rows remaining for this component */ >@@ -359,3 +361,3 @@ > /* There are always min_DCT_scaled_size row groups in an iMCU row. */ >- rowgroups_avail = (JDIMENSION) cinfo->min_DCT_scaled_size; >+ rowgroups_avail = (JDIMENSION) cinfo->_min_DCT_scaled_size; > /* Note: at the bottom of the image, we may pass extra garbage row groups >@@ -419,3 +421,3 @@ > main->rowgroup_ctr = 0; >- main->rowgroups_avail = (JDIMENSION) (cinfo->min_DCT_scaled_size - 1); >+ main->rowgroups_avail = (JDIMENSION) (cinfo->_min_DCT_scaled_size - 1); > /* Check for bottom of image: if so, tweak pointers to "duplicate" >@@ -442,4 +444,4 @@ > /* which is saved at index M+1 of the other xbuffer */ >- main->rowgroup_ctr = (JDIMENSION) (cinfo->min_DCT_scaled_size + 1); >- main->rowgroups_avail = (JDIMENSION) (cinfo->min_DCT_scaled_size + 2); >+ main->rowgroup_ctr = (JDIMENSION) (cinfo->_min_DCT_scaled_size + 1); >+ main->rowgroups_avail = (JDIMENSION) (cinfo->_min_DCT_scaled_size + 2); > main->context_state = CTX_POSTPONED_ROW; >@@ -494,8 +496,8 @@ > if (cinfo->upsample->need_context_rows) { >- if (cinfo->min_DCT_scaled_size < 2) /* unsupported, see comments above */ >+ if (cinfo->_min_DCT_scaled_size < 2) /* unsupported, see comments above */ > ERREXIT(cinfo, JERR_NOTIMPL); > alloc_funny_pointers(cinfo); /* Alloc space for xbuffer[] lists */ >- ngroups = cinfo->min_DCT_scaled_size + 2; >+ ngroups = cinfo->_min_DCT_scaled_size + 2; > } else { >- ngroups = cinfo->min_DCT_scaled_size; >+ ngroups = cinfo->_min_DCT_scaled_size; > } >@@ -504,7 +506,7 @@ > ci++, compptr++) { >- rgroup = (compptr->v_samp_factor * compptr->DCT_scaled_size) / >- cinfo->min_DCT_scaled_size; /* height of a row group of component */ >+ rgroup = (compptr->v_samp_factor * compptr->_DCT_scaled_size) / >+ cinfo->_min_DCT_scaled_size; /* height of a row group of component */ > main->buffer[ci] = (*cinfo->mem->alloc_sarray) > ((j_common_ptr) cinfo, JPOOL_IMAGE, >- compptr->width_in_blocks * compptr->DCT_scaled_size, >+ compptr->width_in_blocks * compptr->_DCT_scaled_size, > (JDIMENSION) (rgroup * ngroups)); >only in patch2: >--- a/jpeg/jerror.h >+++ b/jpeg/jerror.h >@@ -4,2 +4,3 @@ > * Copyright (C) 1994-1997, Thomas G. Lane. >+ * Modified 1997-2009 by Guido Vollbeding. > * This file is part of the Independent JPEG Group's software. >@@ -42,3 +43,3 @@ > JMESSAGE(JERR_ARITH_NOTIMPL, >- "Sorry, there are legal restrictions on arithmetic coding") >+ "Sorry, arithmetic coding is not implemented") > JMESSAGE(JERR_BAD_ALIGN_TYPE, "ALIGN_TYPE is wrong, please fix") >@@ -47,2 +48,3 @@ > JMESSAGE(JERR_BAD_COMPONENT_ID, "Invalid component ID %d in SOS") >+JMESSAGE(JERR_BAD_CROP_SPEC, "Invalid crop request") > JMESSAGE(JERR_BAD_DCT_COEF, "DCT coefficient out of range") >@@ -95,2 +97,3 @@ > JMESSAGE(JERR_NOT_COMPILED, "Requested feature was omitted at compile time") >+JMESSAGE(JERR_NO_ARITH_TABLE, "Arithmetic table 0x%02x was not defined") > JMESSAGE(JERR_NO_BACKING_STORE, "Backing store not supported") >@@ -172,2 +175,3 @@ > JMESSAGE(JWRN_ADOBE_XFORM, "Unknown Adobe color transform code %d") >+JMESSAGE(JWRN_ARITH_BAD_CODE, "Corrupt JPEG data: bad arithmetic code") > JMESSAGE(JWRN_BOGUS_PROGRESSION, >only in patch2: >--- /dev/null >+++ b/jpeg/jpegcomp.h >@@ -0,0 +1,26 @@ >+/* >+ * jpegcomp.h >+ * >+ * Copyright (C) 2010, D. R. Commander >+ * For conditions of distribution and use, see the accompanying README file. >+ * >+ * JPEG compatibility macros >+ * These declarations are considered internal to the JPEG library; most >+ * applications using the library shouldn't need to include this file. >+ */ >+ >+#if JPEG_LIB_VERSION >= 70 >+#define _DCT_scaled_size DCT_h_scaled_size >+#define _min_DCT_scaled_size min_DCT_h_scaled_size >+#define _min_DCT_h_scaled_size min_DCT_h_scaled_size >+#define _min_DCT_v_scaled_size min_DCT_v_scaled_size >+#define _jpeg_width jpeg_width >+#define _jpeg_height jpeg_height >+#else >+#define _DCT_scaled_size DCT_scaled_size >+#define _min_DCT_scaled_size min_DCT_scaled_size >+#define _min_DCT_h_scaled_size min_DCT_scaled_size >+#define _min_DCT_v_scaled_size min_DCT_scaled_size >+#define _jpeg_width image_width >+#define _jpeg_height image_height >+#endif >only in patch2: >--- a/jpeg/jversion.h >+++ b/jpeg/jversion.h >@@ -3,3 +3,4 @@ > * >- * Copyright (C) 1991-1998, Thomas G. Lane. >+ * Copyright (C) 1991-2010, Thomas G. Lane, Guido Vollbeding. >+ * Copyright (C) 2010, D. R. Commander. > * This file is part of the Independent JPEG Group's software. >@@ -11,2 +12,16 @@ > >+#if JPEG_LIB_VERSION >= 80 >+ >+#define JVERSION "8b 16-May-2010" >+ >+#define JCOPYRIGHT "Copyright (C) 2010, Thomas G. Lane, Guido Vollbeding" >+ >+#elif JPEG_LIB_VERSION >= 70 >+ >+#define JVERSION "7 27-Jun-2009" >+ >+#define JCOPYRIGHT "Copyright (C) 2009, Thomas G. Lane, Guido Vollbeding" >+ >+#else >+ > #define JVERSION "6b 27-Mar-1998" >@@ -14 +29,9 @@ > #define JCOPYRIGHT "Copyright (C) 1998, Thomas G. Lane" >+ >+#endif >+ >+#define LJTCOPYRIGHT "Copyright (C) 1999-2006 MIYASAKA Masaru\n" \ >+ "Copyright (C) 2004 Landmark Graphics Corporation\n" \ >+ "Copyright (C) 2005-2007 Sun Microsystems, Inc.\n" \ >+ "Copyright (C) 2009 Pierre Ossman for Cendio AB\n" \ >+ "Copyright (C) 2009-2011 D. R. Commander" >only in patch2: >--- a/jpeg/libjpeg.doc >+++ /dev/null >@@ -1,3006 +0,0 @@ >-USING THE IJG JPEG LIBRARY >- >-Copyright (C) 1994-1998, Thomas G. Lane. >-This file is part of the Independent JPEG Group's software. >-For conditions of distribution and use, see the accompanying README file. >- >- >-This file describes how to use the IJG JPEG library within an application >-program. Read it if you want to write a program that uses the library. >- >-The file example.c provides heavily commented skeleton code for calling the >-JPEG library. Also see jpeglib.h (the include file to be used by application >-programs) for full details about data structures and function parameter lists. >-The library source code, of course, is the ultimate reference. >- >-Note that there have been *major* changes from the application interface >-presented by IJG version 4 and earlier versions. The old design had several >-inherent limitations, and it had accumulated a lot of cruft as we added >-features while trying to minimize application-interface changes. We have >-sacrificed backward compatibility in the version 5 rewrite, but we think the >-improvements justify this. >- >- >-TABLE OF CONTENTS >------------------ >- >-Overview: >- Functions provided by the library >- Outline of typical usage >-Basic library usage: >- Data formats >- Compression details >- Decompression details >- Mechanics of usage: include files, linking, etc >-Advanced features: >- Compression parameter selection >- Decompression parameter selection >- Special color spaces >- Error handling >- Compressed data handling (source and destination managers) >- I/O suspension >- Progressive JPEG support >- Buffered-image mode >- Abbreviated datastreams and multiple images >- Special markers >- Raw (downsampled) image data >- Really raw data: DCT coefficients >- Progress monitoring >- Memory management >- Memory usage >- Library compile-time options >- Portability considerations >- Notes for MS-DOS implementors >- >-You should read at least the overview and basic usage sections before trying >-to program with the library. The sections on advanced features can be read >-if and when you need them. >- >- >-OVERVIEW >-======== >- >-Functions provided by the library >---------------------------------- >- >-The IJG JPEG library provides C code to read and write JPEG-compressed image >-files. The surrounding application program receives or supplies image data a >-scanline at a time, using a straightforward uncompressed image format. All >-details of color conversion and other preprocessing/postprocessing can be >-handled by the library. >- >-The library includes a substantial amount of code that is not covered by the >-JPEG standard but is necessary for typical applications of JPEG. These >-functions preprocess the image before JPEG compression or postprocess it after >-decompression. They include colorspace conversion, downsampling/upsampling, >-and color quantization. The application indirectly selects use of this code >-by specifying the format in which it wishes to supply or receive image data. >-For example, if colormapped output is requested, then the decompression >-library automatically invokes color quantization. >- >-A wide range of quality vs. speed tradeoffs are possible in JPEG processing, >-and even more so in decompression postprocessing. The decompression library >-provides multiple implementations that cover most of the useful tradeoffs, >-ranging from very-high-quality down to fast-preview operation. On the >-compression side we have generally not provided low-quality choices, since >-compression is normally less time-critical. It should be understood that the >-low-quality modes may not meet the JPEG standard's accuracy requirements; >-nonetheless, they are useful for viewers. >- >-A word about functions *not* provided by the library. We handle a subset of >-the ISO JPEG standard; most baseline, extended-sequential, and progressive >-JPEG processes are supported. (Our subset includes all features now in common >-use.) Unsupported ISO options include: >- * Hierarchical storage >- * Lossless JPEG >- * Arithmetic entropy coding (unsupported for legal reasons) >- * DNL marker >- * Nonintegral subsampling ratios >-We support both 8- and 12-bit data precision, but this is a compile-time >-choice rather than a run-time choice; hence it is difficult to use both >-precisions in a single application. >- >-By itself, the library handles only interchange JPEG datastreams --- in >-particular the widely used JFIF file format. The library can be used by >-surrounding code to process interchange or abbreviated JPEG datastreams that >-are embedded in more complex file formats. (For example, this library is >-used by the free LIBTIFF library to support JPEG compression in TIFF.) >- >- >-Outline of typical usage >------------------------- >- >-The rough outline of a JPEG compression operation is: >- >- Allocate and initialize a JPEG compression object >- Specify the destination for the compressed data (eg, a file) >- Set parameters for compression, including image size & colorspace >- jpeg_start_compress(...); >- while (scan lines remain to be written) >- jpeg_write_scanlines(...); >- jpeg_finish_compress(...); >- Release the JPEG compression object >- >-A JPEG compression object holds parameters and working state for the JPEG >-library. We make creation/destruction of the object separate from starting >-or finishing compression of an image; the same object can be re-used for a >-series of image compression operations. This makes it easy to re-use the >-same parameter settings for a sequence of images. Re-use of a JPEG object >-also has important implications for processing abbreviated JPEG datastreams, >-as discussed later. >- >-The image data to be compressed is supplied to jpeg_write_scanlines() from >-in-memory buffers. If the application is doing file-to-file compression, >-reading image data from the source file is the application's responsibility. >-The library emits compressed data by calling a "data destination manager", >-which typically will write the data into a file; but the application can >-provide its own destination manager to do something else. >- >-Similarly, the rough outline of a JPEG decompression operation is: >- >- Allocate and initialize a JPEG decompression object >- Specify the source of the compressed data (eg, a file) >- Call jpeg_read_header() to obtain image info >- Set parameters for decompression >- jpeg_start_decompress(...); >- while (scan lines remain to be read) >- jpeg_read_scanlines(...); >- jpeg_finish_decompress(...); >- Release the JPEG decompression object >- >-This is comparable to the compression outline except that reading the >-datastream header is a separate step. This is helpful because information >-about the image's size, colorspace, etc is available when the application >-selects decompression parameters. For example, the application can choose an >-output scaling ratio that will fit the image into the available screen size. >- >-The decompression library obtains compressed data by calling a data source >-manager, which typically will read the data from a file; but other behaviors >-can be obtained with a custom source manager. Decompressed data is delivered >-into in-memory buffers passed to jpeg_read_scanlines(). >- >-It is possible to abort an incomplete compression or decompression operation >-by calling jpeg_abort(); or, if you do not need to retain the JPEG object, >-simply release it by calling jpeg_destroy(). >- >-JPEG compression and decompression objects are two separate struct types. >-However, they share some common fields, and certain routines such as >-jpeg_destroy() can work on either type of object. >- >-The JPEG library has no static variables: all state is in the compression >-or decompression object. Therefore it is possible to process multiple >-compression and decompression operations concurrently, using multiple JPEG >-objects. >- >-Both compression and decompression can be done in an incremental memory-to- >-memory fashion, if suitable source/destination managers are used. See the >-section on "I/O suspension" for more details. >- >- >-BASIC LIBRARY USAGE >-=================== >- >-Data formats >------------- >- >-Before diving into procedural details, it is helpful to understand the >-image data format that the JPEG library expects or returns. >- >-The standard input image format is a rectangular array of pixels, with each >-pixel having the same number of "component" or "sample" values (color >-channels). You must specify how many components there are and the colorspace >-interpretation of the components. Most applications will use RGB data >-(three components per pixel) or grayscale data (one component per pixel). >-PLEASE NOTE THAT RGB DATA IS THREE SAMPLES PER PIXEL, GRAYSCALE ONLY ONE. >-A remarkable number of people manage to miss this, only to find that their >-programs don't work with grayscale JPEG files. >- >-There is no provision for colormapped input. JPEG files are always full-color >-or full grayscale (or sometimes another colorspace such as CMYK). You can >-feed in a colormapped image by expanding it to full-color format. However >-JPEG often doesn't work very well with source data that has been colormapped, >-because of dithering noise. This is discussed in more detail in the JPEG FAQ >-and the other references mentioned in the README file. >- >-Pixels are stored by scanlines, with each scanline running from left to >-right. The component values for each pixel are adjacent in the row; for >-example, R,G,B,R,G,B,R,G,B,... for 24-bit RGB color. Each scanline is an >-array of data type JSAMPLE --- which is typically "unsigned char", unless >-you've changed jmorecfg.h. (You can also change the RGB pixel layout, say >-to B,G,R order, by modifying jmorecfg.h. But see the restrictions listed in >-that file before doing so.) >- >-A 2-D array of pixels is formed by making a list of pointers to the starts of >-scanlines; so the scanlines need not be physically adjacent in memory. Even >-if you process just one scanline at a time, you must make a one-element >-pointer array to conform to this structure. Pointers to JSAMPLE rows are of >-type JSAMPROW, and the pointer to the pointer array is of type JSAMPARRAY. >- >-The library accepts or supplies one or more complete scanlines per call. >-It is not possible to process part of a row at a time. Scanlines are always >-processed top-to-bottom. You can process an entire image in one call if you >-have it all in memory, but usually it's simplest to process one scanline at >-a time. >- >-For best results, source data values should have the precision specified by >-BITS_IN_JSAMPLE (normally 8 bits). For instance, if you choose to compress >-data that's only 6 bits/channel, you should left-justify each value in a >-byte before passing it to the compressor. If you need to compress data >-that has more than 8 bits/channel, compile with BITS_IN_JSAMPLE = 12. >-(See "Library compile-time options", later.) >- >- >-The data format returned by the decompressor is the same in all details, >-except that colormapped output is supported. (Again, a JPEG file is never >-colormapped. But you can ask the decompressor to perform on-the-fly color >-quantization to deliver colormapped output.) If you request colormapped >-output then the returned data array contains a single JSAMPLE per pixel; >-its value is an index into a color map. The color map is represented as >-a 2-D JSAMPARRAY in which each row holds the values of one color component, >-that is, colormap[i][j] is the value of the i'th color component for pixel >-value (map index) j. Note that since the colormap indexes are stored in >-JSAMPLEs, the maximum number of colors is limited by the size of JSAMPLE >-(ie, at most 256 colors for an 8-bit JPEG library). >- >- >-Compression details >-------------------- >- >-Here we revisit the JPEG compression outline given in the overview. >- >-1. Allocate and initialize a JPEG compression object. >- >-A JPEG compression object is a "struct jpeg_compress_struct". (It also has >-a bunch of subsidiary structures which are allocated via malloc(), but the >-application doesn't control those directly.) This struct can be just a local >-variable in the calling routine, if a single routine is going to execute the >-whole JPEG compression sequence. Otherwise it can be static or allocated >-from malloc(). >- >-You will also need a structure representing a JPEG error handler. The part >-of this that the library cares about is a "struct jpeg_error_mgr". If you >-are providing your own error handler, you'll typically want to embed the >-jpeg_error_mgr struct in a larger structure; this is discussed later under >-"Error handling". For now we'll assume you are just using the default error >-handler. The default error handler will print JPEG error/warning messages >-on stderr, and it will call exit() if a fatal error occurs. >- >-You must initialize the error handler structure, store a pointer to it into >-the JPEG object's "err" field, and then call jpeg_create_compress() to >-initialize the rest of the JPEG object. >- >-Typical code for this step, if you are using the default error handler, is >- >- struct jpeg_compress_struct cinfo; >- struct jpeg_error_mgr jerr; >- ... >- cinfo.err = jpeg_std_error(&jerr); >- jpeg_create_compress(&cinfo); >- >-jpeg_create_compress allocates a small amount of memory, so it could fail >-if you are out of memory. In that case it will exit via the error handler; >-that's why the error handler must be initialized first. >- >- >-2. Specify the destination for the compressed data (eg, a file). >- >-As previously mentioned, the JPEG library delivers compressed data to a >-"data destination" module. The library includes one data destination >-module which knows how to write to a stdio stream. You can use your own >-destination module if you want to do something else, as discussed later. >- >-If you use the standard destination module, you must open the target stdio >-stream beforehand. Typical code for this step looks like: >- >- FILE * outfile; >- ... >- if ((outfile = fopen(filename, "wb")) == NULL) { >- fprintf(stderr, "can't open %s\n", filename); >- exit(1); >- } >- jpeg_stdio_dest(&cinfo, outfile); >- >-where the last line invokes the standard destination module. >- >-WARNING: it is critical that the binary compressed data be delivered to the >-output file unchanged. On non-Unix systems the stdio library may perform >-newline translation or otherwise corrupt binary data. To suppress this >-behavior, you may need to use a "b" option to fopen (as shown above), or use >-setmode() or another routine to put the stdio stream in binary mode. See >-cjpeg.c and djpeg.c for code that has been found to work on many systems. >- >-You can select the data destination after setting other parameters (step 3), >-if that's more convenient. You may not change the destination between >-calling jpeg_start_compress() and jpeg_finish_compress(). >- >- >-3. Set parameters for compression, including image size & colorspace. >- >-You must supply information about the source image by setting the following >-fields in the JPEG object (cinfo structure): >- >- image_width Width of image, in pixels >- image_height Height of image, in pixels >- input_components Number of color channels (samples per pixel) >- in_color_space Color space of source image >- >-The image dimensions are, hopefully, obvious. JPEG supports image dimensions >-of 1 to 64K pixels in either direction. The input color space is typically >-RGB or grayscale, and input_components is 3 or 1 accordingly. (See "Special >-color spaces", later, for more info.) The in_color_space field must be >-assigned one of the J_COLOR_SPACE enum constants, typically JCS_RGB or >-JCS_GRAYSCALE. >- >-JPEG has a large number of compression parameters that determine how the >-image is encoded. Most applications don't need or want to know about all >-these parameters. You can set all the parameters to reasonable defaults by >-calling jpeg_set_defaults(); then, if there are particular values you want >-to change, you can do so after that. The "Compression parameter selection" >-section tells about all the parameters. >- >-You must set in_color_space correctly before calling jpeg_set_defaults(), >-because the defaults depend on the source image colorspace. However the >-other three source image parameters need not be valid until you call >-jpeg_start_compress(). There's no harm in calling jpeg_set_defaults() more >-than once, if that happens to be convenient. >- >-Typical code for a 24-bit RGB source image is >- >- cinfo.image_width = Width; /* image width and height, in pixels */ >- cinfo.image_height = Height; >- cinfo.input_components = 3; /* # of color components per pixel */ >- cinfo.in_color_space = JCS_RGB; /* colorspace of input image */ >- >- jpeg_set_defaults(&cinfo); >- /* Make optional parameter settings here */ >- >- >-4. jpeg_start_compress(...); >- >-After you have established the data destination and set all the necessary >-source image info and other parameters, call jpeg_start_compress() to begin >-a compression cycle. This will initialize internal state, allocate working >-storage, and emit the first few bytes of the JPEG datastream header. >- >-Typical code: >- >- jpeg_start_compress(&cinfo, TRUE); >- >-The "TRUE" parameter ensures that a complete JPEG interchange datastream >-will be written. This is appropriate in most cases. If you think you might >-want to use an abbreviated datastream, read the section on abbreviated >-datastreams, below. >- >-Once you have called jpeg_start_compress(), you may not alter any JPEG >-parameters or other fields of the JPEG object until you have completed >-the compression cycle. >- >- >-5. while (scan lines remain to be written) >- jpeg_write_scanlines(...); >- >-Now write all the required image data by calling jpeg_write_scanlines() >-one or more times. You can pass one or more scanlines in each call, up >-to the total image height. In most applications it is convenient to pass >-just one or a few scanlines at a time. The expected format for the passed >-data is discussed under "Data formats", above. >- >-Image data should be written in top-to-bottom scanline order. The JPEG spec >-contains some weasel wording about how top and bottom are application-defined >-terms (a curious interpretation of the English language...) but if you want >-your files to be compatible with everyone else's, you WILL use top-to-bottom >-order. If the source data must be read in bottom-to-top order, you can use >-the JPEG library's virtual array mechanism to invert the data efficiently. >-Examples of this can be found in the sample application cjpeg. >- >-The library maintains a count of the number of scanlines written so far >-in the next_scanline field of the JPEG object. Usually you can just use >-this variable as the loop counter, so that the loop test looks like >-"while (cinfo.next_scanline < cinfo.image_height)". >- >-Code for this step depends heavily on the way that you store the source data. >-example.c shows the following code for the case of a full-size 2-D source >-array containing 3-byte RGB pixels: >- >- JSAMPROW row_pointer[1]; /* pointer to a single row */ >- int row_stride; /* physical row width in buffer */ >- >- row_stride = image_width * 3; /* JSAMPLEs per row in image_buffer */ >- >- while (cinfo.next_scanline < cinfo.image_height) { >- row_pointer[0] = & image_buffer[cinfo.next_scanline * row_stride]; >- jpeg_write_scanlines(&cinfo, row_pointer, 1); >- } >- >-jpeg_write_scanlines() returns the number of scanlines actually written. >-This will normally be equal to the number passed in, so you can usually >-ignore the return value. It is different in just two cases: >- * If you try to write more scanlines than the declared image height, >- the additional scanlines are ignored. >- * If you use a suspending data destination manager, output buffer overrun >- will cause the compressor to return before accepting all the passed lines. >- This feature is discussed under "I/O suspension", below. The normal >- stdio destination manager will NOT cause this to happen. >-In any case, the return value is the same as the change in the value of >-next_scanline. >- >- >-6. jpeg_finish_compress(...); >- >-After all the image data has been written, call jpeg_finish_compress() to >-complete the compression cycle. This step is ESSENTIAL to ensure that the >-last bufferload of data is written to the data destination. >-jpeg_finish_compress() also releases working memory associated with the JPEG >-object. >- >-Typical code: >- >- jpeg_finish_compress(&cinfo); >- >-If using the stdio destination manager, don't forget to close the output >-stdio stream (if necessary) afterwards. >- >-If you have requested a multi-pass operating mode, such as Huffman code >-optimization, jpeg_finish_compress() will perform the additional passes using >-data buffered by the first pass. In this case jpeg_finish_compress() may take >-quite a while to complete. With the default compression parameters, this will >-not happen. >- >-It is an error to call jpeg_finish_compress() before writing the necessary >-total number of scanlines. If you wish to abort compression, call >-jpeg_abort() as discussed below. >- >-After completing a compression cycle, you may dispose of the JPEG object >-as discussed next, or you may use it to compress another image. In that case >-return to step 2, 3, or 4 as appropriate. If you do not change the >-destination manager, the new datastream will be written to the same target. >-If you do not change any JPEG parameters, the new datastream will be written >-with the same parameters as before. Note that you can change the input image >-dimensions freely between cycles, but if you change the input colorspace, you >-should call jpeg_set_defaults() to adjust for the new colorspace; and then >-you'll need to repeat all of step 3. >- >- >-7. Release the JPEG compression object. >- >-When you are done with a JPEG compression object, destroy it by calling >-jpeg_destroy_compress(). This will free all subsidiary memory (regardless of >-the previous state of the object). Or you can call jpeg_destroy(), which >-works for either compression or decompression objects --- this may be more >-convenient if you are sharing code between compression and decompression >-cases. (Actually, these routines are equivalent except for the declared type >-of the passed pointer. To avoid gripes from ANSI C compilers, jpeg_destroy() >-should be passed a j_common_ptr.) >- >-If you allocated the jpeg_compress_struct structure from malloc(), freeing >-it is your responsibility --- jpeg_destroy() won't. Ditto for the error >-handler structure. >- >-Typical code: >- >- jpeg_destroy_compress(&cinfo); >- >- >-8. Aborting. >- >-If you decide to abort a compression cycle before finishing, you can clean up >-in either of two ways: >- >-* If you don't need the JPEG object any more, just call >- jpeg_destroy_compress() or jpeg_destroy() to release memory. This is >- legitimate at any point after calling jpeg_create_compress() --- in fact, >- it's safe even if jpeg_create_compress() fails. >- >-* If you want to re-use the JPEG object, call jpeg_abort_compress(), or call >- jpeg_abort() which works on both compression and decompression objects. >- This will return the object to an idle state, releasing any working memory. >- jpeg_abort() is allowed at any time after successful object creation. >- >-Note that cleaning up the data destination, if required, is your >-responsibility; neither of these routines will call term_destination(). >-(See "Compressed data handling", below, for more about that.) >- >-jpeg_destroy() and jpeg_abort() are the only safe calls to make on a JPEG >-object that has reported an error by calling error_exit (see "Error handling" >-for more info). The internal state of such an object is likely to be out of >-whack. Either of these two routines will return the object to a known state. >- >- >-Decompression details >---------------------- >- >-Here we revisit the JPEG decompression outline given in the overview. >- >-1. Allocate and initialize a JPEG decompression object. >- >-This is just like initialization for compression, as discussed above, >-except that the object is a "struct jpeg_decompress_struct" and you >-call jpeg_create_decompress(). Error handling is exactly the same. >- >-Typical code: >- >- struct jpeg_decompress_struct cinfo; >- struct jpeg_error_mgr jerr; >- ... >- cinfo.err = jpeg_std_error(&jerr); >- jpeg_create_decompress(&cinfo); >- >-(Both here and in the IJG code, we usually use variable name "cinfo" for >-both compression and decompression objects.) >- >- >-2. Specify the source of the compressed data (eg, a file). >- >-As previously mentioned, the JPEG library reads compressed data from a "data >-source" module. The library includes one data source module which knows how >-to read from a stdio stream. You can use your own source module if you want >-to do something else, as discussed later. >- >-If you use the standard source module, you must open the source stdio stream >-beforehand. Typical code for this step looks like: >- >- FILE * infile; >- ... >- if ((infile = fopen(filename, "rb")) == NULL) { >- fprintf(stderr, "can't open %s\n", filename); >- exit(1); >- } >- jpeg_stdio_src(&cinfo, infile); >- >-where the last line invokes the standard source module. >- >-WARNING: it is critical that the binary compressed data be read unchanged. >-On non-Unix systems the stdio library may perform newline translation or >-otherwise corrupt binary data. To suppress this behavior, you may need to use >-a "b" option to fopen (as shown above), or use setmode() or another routine to >-put the stdio stream in binary mode. See cjpeg.c and djpeg.c for code that >-has been found to work on many systems. >- >-You may not change the data source between calling jpeg_read_header() and >-jpeg_finish_decompress(). If you wish to read a series of JPEG images from >-a single source file, you should repeat the jpeg_read_header() to >-jpeg_finish_decompress() sequence without reinitializing either the JPEG >-object or the data source module; this prevents buffered input data from >-being discarded. >- >- >-3. Call jpeg_read_header() to obtain image info. >- >-Typical code for this step is just >- >- jpeg_read_header(&cinfo, TRUE); >- >-This will read the source datastream header markers, up to the beginning >-of the compressed data proper. On return, the image dimensions and other >-info have been stored in the JPEG object. The application may wish to >-consult this information before selecting decompression parameters. >- >-More complex code is necessary if >- * A suspending data source is used --- in that case jpeg_read_header() >- may return before it has read all the header data. See "I/O suspension", >- below. The normal stdio source manager will NOT cause this to happen. >- * Abbreviated JPEG files are to be processed --- see the section on >- abbreviated datastreams. Standard applications that deal only in >- interchange JPEG files need not be concerned with this case either. >- >-It is permissible to stop at this point if you just wanted to find out the >-image dimensions and other header info for a JPEG file. In that case, >-call jpeg_destroy() when you are done with the JPEG object, or call >-jpeg_abort() to return it to an idle state before selecting a new data >-source and reading another header. >- >- >-4. Set parameters for decompression. >- >-jpeg_read_header() sets appropriate default decompression parameters based on >-the properties of the image (in particular, its colorspace). However, you >-may well want to alter these defaults before beginning the decompression. >-For example, the default is to produce full color output from a color file. >-If you want colormapped output you must ask for it. Other options allow the >-returned image to be scaled and allow various speed/quality tradeoffs to be >-selected. "Decompression parameter selection", below, gives details. >- >-If the defaults are appropriate, nothing need be done at this step. >- >-Note that all default values are set by each call to jpeg_read_header(). >-If you reuse a decompression object, you cannot expect your parameter >-settings to be preserved across cycles, as you can for compression. >-You must set desired parameter values each time. >- >- >-5. jpeg_start_decompress(...); >- >-Once the parameter values are satisfactory, call jpeg_start_decompress() to >-begin decompression. This will initialize internal state, allocate working >-memory, and prepare for returning data. >- >-Typical code is just >- >- jpeg_start_decompress(&cinfo); >- >-If you have requested a multi-pass operating mode, such as 2-pass color >-quantization, jpeg_start_decompress() will do everything needed before data >-output can begin. In this case jpeg_start_decompress() may take quite a while >-to complete. With a single-scan (non progressive) JPEG file and default >-decompression parameters, this will not happen; jpeg_start_decompress() will >-return quickly. >- >-After this call, the final output image dimensions, including any requested >-scaling, are available in the JPEG object; so is the selected colormap, if >-colormapped output has been requested. Useful fields include >- >- output_width image width and height, as scaled >- output_height >- out_color_components # of color components in out_color_space >- output_components # of color components returned per pixel >- colormap the selected colormap, if any >- actual_number_of_colors number of entries in colormap >- >-output_components is 1 (a colormap index) when quantizing colors; otherwise it >-equals out_color_components. It is the number of JSAMPLE values that will be >-emitted per pixel in the output arrays. >- >-Typically you will need to allocate data buffers to hold the incoming image. >-You will need output_width * output_components JSAMPLEs per scanline in your >-output buffer, and a total of output_height scanlines will be returned. >- >-Note: if you are using the JPEG library's internal memory manager to allocate >-data buffers (as djpeg does), then the manager's protocol requires that you >-request large buffers *before* calling jpeg_start_decompress(). This is a >-little tricky since the output_XXX fields are not normally valid then. You >-can make them valid by calling jpeg_calc_output_dimensions() after setting the >-relevant parameters (scaling, output color space, and quantization flag). >- >- >-6. while (scan lines remain to be read) >- jpeg_read_scanlines(...); >- >-Now you can read the decompressed image data by calling jpeg_read_scanlines() >-one or more times. At each call, you pass in the maximum number of scanlines >-to be read (ie, the height of your working buffer); jpeg_read_scanlines() >-will return up to that many lines. The return value is the number of lines >-actually read. The format of the returned data is discussed under "Data >-formats", above. Don't forget that grayscale and color JPEGs will return >-different data formats! >- >-Image data is returned in top-to-bottom scanline order. If you must write >-out the image in bottom-to-top order, you can use the JPEG library's virtual >-array mechanism to invert the data efficiently. Examples of this can be >-found in the sample application djpeg. >- >-The library maintains a count of the number of scanlines returned so far >-in the output_scanline field of the JPEG object. Usually you can just use >-this variable as the loop counter, so that the loop test looks like >-"while (cinfo.output_scanline < cinfo.output_height)". (Note that the test >-should NOT be against image_height, unless you never use scaling. The >-image_height field is the height of the original unscaled image.) >-The return value always equals the change in the value of output_scanline. >- >-If you don't use a suspending data source, it is safe to assume that >-jpeg_read_scanlines() reads at least one scanline per call, until the >-bottom of the image has been reached. >- >-If you use a buffer larger than one scanline, it is NOT safe to assume that >-jpeg_read_scanlines() fills it. (The current implementation returns only a >-few scanlines per call, no matter how large a buffer you pass.) So you must >-always provide a loop that calls jpeg_read_scanlines() repeatedly until the >-whole image has been read. >- >- >-7. jpeg_finish_decompress(...); >- >-After all the image data has been read, call jpeg_finish_decompress() to >-complete the decompression cycle. This causes working memory associated >-with the JPEG object to be released. >- >-Typical code: >- >- jpeg_finish_decompress(&cinfo); >- >-If using the stdio source manager, don't forget to close the source stdio >-stream if necessary. >- >-It is an error to call jpeg_finish_decompress() before reading the correct >-total number of scanlines. If you wish to abort decompression, call >-jpeg_abort() as discussed below. >- >-After completing a decompression cycle, you may dispose of the JPEG object as >-discussed next, or you may use it to decompress another image. In that case >-return to step 2 or 3 as appropriate. If you do not change the source >-manager, the next image will be read from the same source. >- >- >-8. Release the JPEG decompression object. >- >-When you are done with a JPEG decompression object, destroy it by calling >-jpeg_destroy_decompress() or jpeg_destroy(). The previous discussion of >-destroying compression objects applies here too. >- >-Typical code: >- >- jpeg_destroy_decompress(&cinfo); >- >- >-9. Aborting. >- >-You can abort a decompression cycle by calling jpeg_destroy_decompress() or >-jpeg_destroy() if you don't need the JPEG object any more, or >-jpeg_abort_decompress() or jpeg_abort() if you want to reuse the object. >-The previous discussion of aborting compression cycles applies here too. >- >- >-Mechanics of usage: include files, linking, etc >------------------------------------------------ >- >-Applications using the JPEG library should include the header file jpeglib.h >-to obtain declarations of data types and routines. Before including >-jpeglib.h, include system headers that define at least the typedefs FILE and >-size_t. On ANSI-conforming systems, including <stdio.h> is sufficient; on >-older Unix systems, you may need <sys/types.h> to define size_t. >- >-If the application needs to refer to individual JPEG library error codes, also >-include jerror.h to define those symbols. >- >-jpeglib.h indirectly includes the files jconfig.h and jmorecfg.h. If you are >-installing the JPEG header files in a system directory, you will want to >-install all four files: jpeglib.h, jerror.h, jconfig.h, jmorecfg.h. >- >-The most convenient way to include the JPEG code into your executable program >-is to prepare a library file ("libjpeg.a", or a corresponding name on non-Unix >-machines) and reference it at your link step. If you use only half of the >-library (only compression or only decompression), only that much code will be >-included from the library, unless your linker is hopelessly brain-damaged. >-The supplied makefiles build libjpeg.a automatically (see install.doc). >- >-While you can build the JPEG library as a shared library if the whim strikes >-you, we don't really recommend it. The trouble with shared libraries is that >-at some point you'll probably try to substitute a new version of the library >-without recompiling the calling applications. That generally doesn't work >-because the parameter struct declarations usually change with each new >-version. In other words, the library's API is *not* guaranteed binary >-compatible across versions; we only try to ensure source-code compatibility. >-(In hindsight, it might have been smarter to hide the parameter structs from >-applications and introduce a ton of access functions instead. Too late now, >-however.) >- >-On some systems your application may need to set up a signal handler to ensure >-that temporary files are deleted if the program is interrupted. This is most >-critical if you are on MS-DOS and use the jmemdos.c memory manager back end; >-it will try to grab extended memory for temp files, and that space will NOT be >-freed automatically. See cjpeg.c or djpeg.c for an example signal handler. >- >-It may be worth pointing out that the core JPEG library does not actually >-require the stdio library: only the default source/destination managers and >-error handler need it. You can use the library in a stdio-less environment >-if you replace those modules and use jmemnobs.c (or another memory manager of >-your own devising). More info about the minimum system library requirements >-may be found in jinclude.h. >- >- >-ADVANCED FEATURES >-================= >- >-Compression parameter selection >-------------------------------- >- >-This section describes all the optional parameters you can set for JPEG >-compression, as well as the "helper" routines provided to assist in this >-task. Proper setting of some parameters requires detailed understanding >-of the JPEG standard; if you don't know what a parameter is for, it's best >-not to mess with it! See REFERENCES in the README file for pointers to >-more info about JPEG. >- >-It's a good idea to call jpeg_set_defaults() first, even if you plan to set >-all the parameters; that way your code is more likely to work with future JPEG >-libraries that have additional parameters. For the same reason, we recommend >-you use a helper routine where one is provided, in preference to twiddling >-cinfo fields directly. >- >-The helper routines are: >- >-jpeg_set_defaults (j_compress_ptr cinfo) >- This routine sets all JPEG parameters to reasonable defaults, using >- only the input image's color space (field in_color_space, which must >- already be set in cinfo). Many applications will only need to use >- this routine and perhaps jpeg_set_quality(). >- >-jpeg_set_colorspace (j_compress_ptr cinfo, J_COLOR_SPACE colorspace) >- Sets the JPEG file's colorspace (field jpeg_color_space) as specified, >- and sets other color-space-dependent parameters appropriately. See >- "Special color spaces", below, before using this. A large number of >- parameters, including all per-component parameters, are set by this >- routine; if you want to twiddle individual parameters you should call >- jpeg_set_colorspace() before rather than after. >- >-jpeg_default_colorspace (j_compress_ptr cinfo) >- Selects an appropriate JPEG colorspace based on cinfo->in_color_space, >- and calls jpeg_set_colorspace(). This is actually a subroutine of >- jpeg_set_defaults(). It's broken out in case you want to change >- just the colorspace-dependent JPEG parameters. >- >-jpeg_set_quality (j_compress_ptr cinfo, int quality, boolean force_baseline) >- Constructs JPEG quantization tables appropriate for the indicated >- quality setting. The quality value is expressed on the 0..100 scale >- recommended by IJG (cjpeg's "-quality" switch uses this routine). >- Note that the exact mapping from quality values to tables may change >- in future IJG releases as more is learned about DCT quantization. >- If the force_baseline parameter is TRUE, then the quantization table >- entries are constrained to the range 1..255 for full JPEG baseline >- compatibility. In the current implementation, this only makes a >- difference for quality settings below 25, and it effectively prevents >- very small/low quality files from being generated. The IJG decoder >- is capable of reading the non-baseline files generated at low quality >- settings when force_baseline is FALSE, but other decoders may not be. >- >-jpeg_set_linear_quality (j_compress_ptr cinfo, int scale_factor, >- boolean force_baseline) >- Same as jpeg_set_quality() except that the generated tables are the >- sample tables given in the JPEC spec section K.1, multiplied by the >- specified scale factor (which is expressed as a percentage; thus >- scale_factor = 100 reproduces the spec's tables). Note that larger >- scale factors give lower quality. This entry point is useful for >- conforming to the Adobe PostScript DCT conventions, but we do not >- recommend linear scaling as a user-visible quality scale otherwise. >- force_baseline again constrains the computed table entries to 1..255. >- >-int jpeg_quality_scaling (int quality) >- Converts a value on the IJG-recommended quality scale to a linear >- scaling percentage. Note that this routine may change or go away >- in future releases --- IJG may choose to adopt a scaling method that >- can't be expressed as a simple scalar multiplier, in which case the >- premise of this routine collapses. Caveat user. >- >-jpeg_add_quant_table (j_compress_ptr cinfo, int which_tbl, >- const unsigned int *basic_table, >- int scale_factor, boolean force_baseline) >- Allows an arbitrary quantization table to be created. which_tbl >- indicates which table slot to fill. basic_table points to an array >- of 64 unsigned ints given in normal array order. These values are >- multiplied by scale_factor/100 and then clamped to the range 1..65535 >- (or to 1..255 if force_baseline is TRUE). >- CAUTION: prior to library version 6a, jpeg_add_quant_table expected >- the basic table to be given in JPEG zigzag order. If you need to >- write code that works with either older or newer versions of this >- routine, you must check the library version number. Something like >- "#if JPEG_LIB_VERSION >= 61" is the right test. >- >-jpeg_simple_progression (j_compress_ptr cinfo) >- Generates a default scan script for writing a progressive-JPEG file. >- This is the recommended method of creating a progressive file, >- unless you want to make a custom scan sequence. You must ensure that >- the JPEG color space is set correctly before calling this routine. >- >- >-Compression parameters (cinfo fields) include: >- >-J_DCT_METHOD dct_method >- Selects the algorithm used for the DCT step. Choices are: >- JDCT_ISLOW: slow but accurate integer algorithm >- JDCT_IFAST: faster, less accurate integer method >- JDCT_FLOAT: floating-point method >- JDCT_DEFAULT: default method (normally JDCT_ISLOW) >- JDCT_FASTEST: fastest method (normally JDCT_IFAST) >- The FLOAT method is very slightly more accurate than the ISLOW method, >- but may give different results on different machines due to varying >- roundoff behavior. The integer methods should give the same results >- on all machines. On machines with sufficiently fast FP hardware, the >- floating-point method may also be the fastest. The IFAST method is >- considerably less accurate than the other two; its use is not >- recommended if high quality is a concern. JDCT_DEFAULT and >- JDCT_FASTEST are macros configurable by each installation. >- >-J_COLOR_SPACE jpeg_color_space >-int num_components >- The JPEG color space and corresponding number of components; see >- "Special color spaces", below, for more info. We recommend using >- jpeg_set_color_space() if you want to change these. >- >-boolean optimize_coding >- TRUE causes the compressor to compute optimal Huffman coding tables >- for the image. This requires an extra pass over the data and >- therefore costs a good deal of space and time. The default is >- FALSE, which tells the compressor to use the supplied or default >- Huffman tables. In most cases optimal tables save only a few percent >- of file size compared to the default tables. Note that when this is >- TRUE, you need not supply Huffman tables at all, and any you do >- supply will be overwritten. >- >-unsigned int restart_interval >-int restart_in_rows >- To emit restart markers in the JPEG file, set one of these nonzero. >- Set restart_interval to specify the exact interval in MCU blocks. >- Set restart_in_rows to specify the interval in MCU rows. (If >- restart_in_rows is not 0, then restart_interval is set after the >- image width in MCUs is computed.) Defaults are zero (no restarts). >- One restart marker per MCU row is often a good choice. >- NOTE: the overhead of restart markers is higher in grayscale JPEG >- files than in color files, and MUCH higher in progressive JPEGs. >- If you use restarts, you may want to use larger intervals in those >- cases. >- >-const jpeg_scan_info * scan_info >-int num_scans >- By default, scan_info is NULL; this causes the compressor to write a >- single-scan sequential JPEG file. If not NULL, scan_info points to >- an array of scan definition records of length num_scans. The >- compressor will then write a JPEG file having one scan for each scan >- definition record. This is used to generate noninterleaved or >- progressive JPEG files. The library checks that the scan array >- defines a valid JPEG scan sequence. (jpeg_simple_progression creates >- a suitable scan definition array for progressive JPEG.) This is >- discussed further under "Progressive JPEG support". >- >-int smoothing_factor >- If non-zero, the input image is smoothed; the value should be 1 for >- minimal smoothing to 100 for maximum smoothing. Consult jcsample.c >- for details of the smoothing algorithm. The default is zero. >- >-boolean write_JFIF_header >- If TRUE, a JFIF APP0 marker is emitted. jpeg_set_defaults() and >- jpeg_set_colorspace() set this TRUE if a JFIF-legal JPEG color space >- (ie, YCbCr or grayscale) is selected, otherwise FALSE. >- >-UINT8 JFIF_major_version >-UINT8 JFIF_minor_version >- The version number to be written into the JFIF marker. >- jpeg_set_defaults() initializes the version to 1.01 (major=minor=1). >- You should set it to 1.02 (major=1, minor=2) if you plan to write >- any JFIF 1.02 extension markers. >- >-UINT8 density_unit >-UINT16 X_density >-UINT16 Y_density >- The resolution information to be written into the JFIF marker; >- not used otherwise. density_unit may be 0 for unknown, >- 1 for dots/inch, or 2 for dots/cm. The default values are 0,1,1 >- indicating square pixels of unknown size. >- >-boolean write_Adobe_marker >- If TRUE, an Adobe APP14 marker is emitted. jpeg_set_defaults() and >- jpeg_set_colorspace() set this TRUE if JPEG color space RGB, CMYK, >- or YCCK is selected, otherwise FALSE. It is generally a bad idea >- to set both write_JFIF_header and write_Adobe_marker. In fact, >- you probably shouldn't change the default settings at all --- the >- default behavior ensures that the JPEG file's color space can be >- recognized by the decoder. >- >-JQUANT_TBL * quant_tbl_ptrs[NUM_QUANT_TBLS] >- Pointers to coefficient quantization tables, one per table slot, >- or NULL if no table is defined for a slot. Usually these should >- be set via one of the above helper routines; jpeg_add_quant_table() >- is general enough to define any quantization table. The other >- routines will set up table slot 0 for luminance quality and table >- slot 1 for chrominance. >- >-JHUFF_TBL * dc_huff_tbl_ptrs[NUM_HUFF_TBLS] >-JHUFF_TBL * ac_huff_tbl_ptrs[NUM_HUFF_TBLS] >- Pointers to Huffman coding tables, one per table slot, or NULL if >- no table is defined for a slot. Slots 0 and 1 are filled with the >- JPEG sample tables by jpeg_set_defaults(). If you need to allocate >- more table structures, jpeg_alloc_huff_table() may be used. >- Note that optimal Huffman tables can be computed for an image >- by setting optimize_coding, as discussed above; there's seldom >- any need to mess with providing your own Huffman tables. >- >-There are some additional cinfo fields which are not documented here >-because you currently can't change them; for example, you can't set >-arith_code TRUE because arithmetic coding is unsupported. >- >- >-Per-component parameters are stored in the struct cinfo.comp_info[i] for >-component number i. Note that components here refer to components of the >-JPEG color space, *not* the source image color space. A suitably large >-comp_info[] array is allocated by jpeg_set_defaults(); if you choose not >-to use that routine, it's up to you to allocate the array. >- >-int component_id >- The one-byte identifier code to be recorded in the JPEG file for >- this component. For the standard color spaces, we recommend you >- leave the default values alone. >- >-int h_samp_factor >-int v_samp_factor >- Horizontal and vertical sampling factors for the component; must >- be 1..4 according to the JPEG standard. Note that larger sampling >- factors indicate a higher-resolution component; many people find >- this behavior quite unintuitive. The default values are 2,2 for >- luminance components and 1,1 for chrominance components, except >- for grayscale where 1,1 is used. >- >-int quant_tbl_no >- Quantization table number for component. The default value is >- 0 for luminance components and 1 for chrominance components. >- >-int dc_tbl_no >-int ac_tbl_no >- DC and AC entropy coding table numbers. The default values are >- 0 for luminance components and 1 for chrominance components. >- >-int component_index >- Must equal the component's index in comp_info[]. (Beginning in >- release v6, the compressor library will fill this in automatically; >- you don't have to.) >- >- >-Decompression parameter selection >---------------------------------- >- >-Decompression parameter selection is somewhat simpler than compression >-parameter selection, since all of the JPEG internal parameters are >-recorded in the source file and need not be supplied by the application. >-(Unless you are working with abbreviated files, in which case see >-"Abbreviated datastreams", below.) Decompression parameters control >-the postprocessing done on the image to deliver it in a format suitable >-for the application's use. Many of the parameters control speed/quality >-tradeoffs, in which faster decompression may be obtained at the price of >-a poorer-quality image. The defaults select the highest quality (slowest) >-processing. >- >-The following fields in the JPEG object are set by jpeg_read_header() and >-may be useful to the application in choosing decompression parameters: >- >-JDIMENSION image_width Width and height of image >-JDIMENSION image_height >-int num_components Number of color components >-J_COLOR_SPACE jpeg_color_space Colorspace of image >-boolean saw_JFIF_marker TRUE if a JFIF APP0 marker was seen >- UINT8 JFIF_major_version Version information from JFIF marker >- UINT8 JFIF_minor_version >- UINT8 density_unit Resolution data from JFIF marker >- UINT16 X_density >- UINT16 Y_density >-boolean saw_Adobe_marker TRUE if an Adobe APP14 marker was seen >- UINT8 Adobe_transform Color transform code from Adobe marker >- >-The JPEG color space, unfortunately, is something of a guess since the JPEG >-standard proper does not provide a way to record it. In practice most files >-adhere to the JFIF or Adobe conventions, and the decoder will recognize these >-correctly. See "Special color spaces", below, for more info. >- >- >-The decompression parameters that determine the basic properties of the >-returned image are: >- >-J_COLOR_SPACE out_color_space >- Output color space. jpeg_read_header() sets an appropriate default >- based on jpeg_color_space; typically it will be RGB or grayscale. >- The application can change this field to request output in a different >- colorspace. For example, set it to JCS_GRAYSCALE to get grayscale >- output from a color file. (This is useful for previewing: grayscale >- output is faster than full color since the color components need not >- be processed.) Note that not all possible color space transforms are >- currently implemented; you may need to extend jdcolor.c if you want an >- unusual conversion. >- >-unsigned int scale_num, scale_denom >- Scale the image by the fraction scale_num/scale_denom. Default is >- 1/1, or no scaling. Currently, the only supported scaling ratios >- are 1/1, 1/2, 1/4, and 1/8. (The library design allows for arbitrary >- scaling ratios but this is not likely to be implemented any time soon.) >- Smaller scaling ratios permit significantly faster decoding since >- fewer pixels need be processed and a simpler IDCT method can be used. >- >-boolean quantize_colors >- If set TRUE, colormapped output will be delivered. Default is FALSE, >- meaning that full-color output will be delivered. >- >-The next three parameters are relevant only if quantize_colors is TRUE. >- >-int desired_number_of_colors >- Maximum number of colors to use in generating a library-supplied color >- map (the actual number of colors is returned in a different field). >- Default 256. Ignored when the application supplies its own color map. >- >-boolean two_pass_quantize >- If TRUE, an extra pass over the image is made to select a custom color >- map for the image. This usually looks a lot better than the one-size- >- fits-all colormap that is used otherwise. Default is TRUE. Ignored >- when the application supplies its own color map. >- >-J_DITHER_MODE dither_mode >- Selects color dithering method. Supported values are: >- JDITHER_NONE no dithering: fast, very low quality >- JDITHER_ORDERED ordered dither: moderate speed and quality >- JDITHER_FS Floyd-Steinberg dither: slow, high quality >- Default is JDITHER_FS. (At present, ordered dither is implemented >- only in the single-pass, standard-colormap case. If you ask for >- ordered dither when two_pass_quantize is TRUE or when you supply >- an external color map, you'll get F-S dithering.) >- >-When quantize_colors is TRUE, the target color map is described by the next >-two fields. colormap is set to NULL by jpeg_read_header(). The application >-can supply a color map by setting colormap non-NULL and setting >-actual_number_of_colors to the map size. Otherwise, jpeg_start_decompress() >-selects a suitable color map and sets these two fields itself. >-[Implementation restriction: at present, an externally supplied colormap is >-only accepted for 3-component output color spaces.] >- >-JSAMPARRAY colormap >- The color map, represented as a 2-D pixel array of out_color_components >- rows and actual_number_of_colors columns. Ignored if not quantizing. >- CAUTION: if the JPEG library creates its own colormap, the storage >- pointed to by this field is released by jpeg_finish_decompress(). >- Copy the colormap somewhere else first, if you want to save it. >- >-int actual_number_of_colors >- The number of colors in the color map. >- >-Additional decompression parameters that the application may set include: >- >-J_DCT_METHOD dct_method >- Selects the algorithm used for the DCT step. Choices are the same >- as described above for compression. >- >-boolean do_fancy_upsampling >- If TRUE, do careful upsampling of chroma components. If FALSE, >- a faster but sloppier method is used. Default is TRUE. The visual >- impact of the sloppier method is often very small. >- >-boolean do_block_smoothing >- If TRUE, interblock smoothing is applied in early stages of decoding >- progressive JPEG files; if FALSE, not. Default is TRUE. Early >- progression stages look "fuzzy" with smoothing, "blocky" without. >- In any case, block smoothing ceases to be applied after the first few >- AC coefficients are known to full accuracy, so it is relevant only >- when using buffered-image mode for progressive images. >- >-boolean enable_1pass_quant >-boolean enable_external_quant >-boolean enable_2pass_quant >- These are significant only in buffered-image mode, which is >- described in its own section below. >- >- >-The output image dimensions are given by the following fields. These are >-computed from the source image dimensions and the decompression parameters >-by jpeg_start_decompress(). You can also call jpeg_calc_output_dimensions() >-to obtain the values that will result from the current parameter settings. >-This can be useful if you are trying to pick a scaling ratio that will get >-close to a desired target size. It's also important if you are using the >-JPEG library's memory manager to allocate output buffer space, because you >-are supposed to request such buffers *before* jpeg_start_decompress(). >- >-JDIMENSION output_width Actual dimensions of output image. >-JDIMENSION output_height >-int out_color_components Number of color components in out_color_space. >-int output_components Number of color components returned. >-int rec_outbuf_height Recommended height of scanline buffer. >- >-When quantizing colors, output_components is 1, indicating a single color map >-index per pixel. Otherwise it equals out_color_components. The output arrays >-are required to be output_width * output_components JSAMPLEs wide. >- >-rec_outbuf_height is the recommended minimum height (in scanlines) of the >-buffer passed to jpeg_read_scanlines(). If the buffer is smaller, the >-library will still work, but time will be wasted due to unnecessary data >-copying. In high-quality modes, rec_outbuf_height is always 1, but some >-faster, lower-quality modes set it to larger values (typically 2 to 4). >-If you are going to ask for a high-speed processing mode, you may as well >-go to the trouble of honoring rec_outbuf_height so as to avoid data copying. >-(An output buffer larger than rec_outbuf_height lines is OK, but won't >-provide any material speed improvement over that height.) >- >- >-Special color spaces >--------------------- >- >-The JPEG standard itself is "color blind" and doesn't specify any particular >-color space. It is customary to convert color data to a luminance/chrominance >-color space before compressing, since this permits greater compression. The >-existing de-facto JPEG file format standards specify YCbCr or grayscale data >-(JFIF), or grayscale, RGB, YCbCr, CMYK, or YCCK (Adobe). For special >-applications such as multispectral images, other color spaces can be used, >-but it must be understood that such files will be unportable. >- >-The JPEG library can handle the most common colorspace conversions (namely >-RGB <=> YCbCr and CMYK <=> YCCK). It can also deal with data of an unknown >-color space, passing it through without conversion. If you deal extensively >-with an unusual color space, you can easily extend the library to understand >-additional color spaces and perform appropriate conversions. >- >-For compression, the source data's color space is specified by field >-in_color_space. This is transformed to the JPEG file's color space given >-by jpeg_color_space. jpeg_set_defaults() chooses a reasonable JPEG color >-space depending on in_color_space, but you can override this by calling >-jpeg_set_colorspace(). Of course you must select a supported transformation. >-jccolor.c currently supports the following transformations: >- RGB => YCbCr >- RGB => GRAYSCALE >- YCbCr => GRAYSCALE >- CMYK => YCCK >-plus the null transforms: GRAYSCALE => GRAYSCALE, RGB => RGB, >-YCbCr => YCbCr, CMYK => CMYK, YCCK => YCCK, and UNKNOWN => UNKNOWN. >- >-The de-facto file format standards (JFIF and Adobe) specify APPn markers that >-indicate the color space of the JPEG file. It is important to ensure that >-these are written correctly, or omitted if the JPEG file's color space is not >-one of the ones supported by the de-facto standards. jpeg_set_colorspace() >-will set the compression parameters to include or omit the APPn markers >-properly, so long as it is told the truth about the JPEG color space. >-For example, if you are writing some random 3-component color space without >-conversion, don't try to fake out the library by setting in_color_space and >-jpeg_color_space to JCS_YCbCr; use JCS_UNKNOWN. You may want to write an >-APPn marker of your own devising to identify the colorspace --- see "Special >-markers", below. >- >-When told that the color space is UNKNOWN, the library will default to using >-luminance-quality compression parameters for all color components. You may >-well want to change these parameters. See the source code for >-jpeg_set_colorspace(), in jcparam.c, for details. >- >-For decompression, the JPEG file's color space is given in jpeg_color_space, >-and this is transformed to the output color space out_color_space. >-jpeg_read_header's setting of jpeg_color_space can be relied on if the file >-conforms to JFIF or Adobe conventions, but otherwise it is no better than a >-guess. If you know the JPEG file's color space for certain, you can override >-jpeg_read_header's guess by setting jpeg_color_space. jpeg_read_header also >-selects a default output color space based on (its guess of) jpeg_color_space; >-set out_color_space to override this. Again, you must select a supported >-transformation. jdcolor.c currently supports >- YCbCr => GRAYSCALE >- YCbCr => RGB >- GRAYSCALE => RGB >- YCCK => CMYK >-as well as the null transforms. (Since GRAYSCALE=>RGB is provided, an >-application can force grayscale JPEGs to look like color JPEGs if it only >-wants to handle one case.) >- >-The two-pass color quantizer, jquant2.c, is specialized to handle RGB data >-(it weights distances appropriately for RGB colors). You'll need to modify >-the code if you want to use it for non-RGB output color spaces. Note that >-jquant2.c is used to map to an application-supplied colormap as well as for >-the normal two-pass colormap selection process. >- >-CAUTION: it appears that Adobe Photoshop writes inverted data in CMYK JPEG >-files: 0 represents 100% ink coverage, rather than 0% ink as you'd expect. >-This is arguably a bug in Photoshop, but if you need to work with Photoshop >-CMYK files, you will have to deal with it in your application. We cannot >-"fix" this in the library by inverting the data during the CMYK<=>YCCK >-transform, because that would break other applications, notably Ghostscript. >-Photoshop versions prior to 3.0 write EPS files containing JPEG-encoded CMYK >-data in the same inverted-YCCK representation used in bare JPEG files, but >-the surrounding PostScript code performs an inversion using the PS image >-operator. I am told that Photoshop 3.0 will write uninverted YCCK in >-EPS/JPEG files, and will omit the PS-level inversion. (But the data >-polarity used in bare JPEG files will not change in 3.0.) In either case, >-the JPEG library must not invert the data itself, or else Ghostscript would >-read these EPS files incorrectly. >- >- >-Error handling >--------------- >- >-When the default error handler is used, any error detected inside the JPEG >-routines will cause a message to be printed on stderr, followed by exit(). >-You can supply your own error handling routines to override this behavior >-and to control the treatment of nonfatal warnings and trace/debug messages. >-The file example.c illustrates the most common case, which is to have the >-application regain control after an error rather than exiting. >- >-The JPEG library never writes any message directly; it always goes through >-the error handling routines. Three classes of messages are recognized: >- * Fatal errors: the library cannot continue. >- * Warnings: the library can continue, but the data is corrupt, and a >- damaged output image is likely to result. >- * Trace/informational messages. These come with a trace level indicating >- the importance of the message; you can control the verbosity of the >- program by adjusting the maximum trace level that will be displayed. >- >-You may, if you wish, simply replace the entire JPEG error handling module >-(jerror.c) with your own code. However, you can avoid code duplication by >-only replacing some of the routines depending on the behavior you need. >-This is accomplished by calling jpeg_std_error() as usual, but then overriding >-some of the method pointers in the jpeg_error_mgr struct, as illustrated by >-example.c. >- >-All of the error handling routines will receive a pointer to the JPEG object >-(a j_common_ptr which points to either a jpeg_compress_struct or a >-jpeg_decompress_struct; if you need to tell which, test the is_decompressor >-field). This struct includes a pointer to the error manager struct in its >-"err" field. Frequently, custom error handler routines will need to access >-additional data which is not known to the JPEG library or the standard error >-handler. The most convenient way to do this is to embed either the JPEG >-object or the jpeg_error_mgr struct in a larger structure that contains >-additional fields; then casting the passed pointer provides access to the >-additional fields. Again, see example.c for one way to do it. (Beginning >-with IJG version 6b, there is also a void pointer "client_data" in each >-JPEG object, which the application can also use to find related data. >-The library does not touch client_data at all.) >- >-The individual methods that you might wish to override are: >- >-error_exit (j_common_ptr cinfo) >- Receives control for a fatal error. Information sufficient to >- generate the error message has been stored in cinfo->err; call >- output_message to display it. Control must NOT return to the caller; >- generally this routine will exit() or longjmp() somewhere. >- Typically you would override this routine to get rid of the exit() >- default behavior. Note that if you continue processing, you should >- clean up the JPEG object with jpeg_abort() or jpeg_destroy(). >- >-output_message (j_common_ptr cinfo) >- Actual output of any JPEG message. Override this to send messages >- somewhere other than stderr. Note that this method does not know >- how to generate a message, only where to send it. >- >-format_message (j_common_ptr cinfo, char * buffer) >- Constructs a readable error message string based on the error info >- stored in cinfo->err. This method is called by output_message. Few >- applications should need to override this method. One possible >- reason for doing so is to implement dynamic switching of error message >- language. >- >-emit_message (j_common_ptr cinfo, int msg_level) >- Decide whether or not to emit a warning or trace message; if so, >- calls output_message. The main reason for overriding this method >- would be to abort on warnings. msg_level is -1 for warnings, >- 0 and up for trace messages. >- >-Only error_exit() and emit_message() are called from the rest of the JPEG >-library; the other two are internal to the error handler. >- >-The actual message texts are stored in an array of strings which is pointed to >-by the field err->jpeg_message_table. The messages are numbered from 0 to >-err->last_jpeg_message, and it is these code numbers that are used in the >-JPEG library code. You could replace the message texts (for instance, with >-messages in French or German) by changing the message table pointer. See >-jerror.h for the default texts. CAUTION: this table will almost certainly >-change or grow from one library version to the next. >- >-It may be useful for an application to add its own message texts that are >-handled by the same mechanism. The error handler supports a second "add-on" >-message table for this purpose. To define an addon table, set the pointer >-err->addon_message_table and the message numbers err->first_addon_message and >-err->last_addon_message. If you number the addon messages beginning at 1000 >-or so, you won't have to worry about conflicts with the library's built-in >-messages. See the sample applications cjpeg/djpeg for an example of using >-addon messages (the addon messages are defined in cderror.h). >- >-Actual invocation of the error handler is done via macros defined in jerror.h: >- ERREXITn(...) for fatal errors >- WARNMSn(...) for corrupt-data warnings >- TRACEMSn(...) for trace and informational messages. >-These macros store the message code and any additional parameters into the >-error handler struct, then invoke the error_exit() or emit_message() method. >-The variants of each macro are for varying numbers of additional parameters. >-The additional parameters are inserted into the generated message using >-standard printf() format codes. >- >-See jerror.h and jerror.c for further details. >- >- >-Compressed data handling (source and destination managers) >----------------------------------------------------------- >- >-The JPEG compression library sends its compressed data to a "destination >-manager" module. The default destination manager just writes the data to a >-stdio stream, but you can provide your own manager to do something else. >-Similarly, the decompression library calls a "source manager" to obtain the >-compressed data; you can provide your own source manager if you want the data >-to come from somewhere other than a stdio stream. >- >-In both cases, compressed data is processed a bufferload at a time: the >-destination or source manager provides a work buffer, and the library invokes >-the manager only when the buffer is filled or emptied. (You could define a >-one-character buffer to force the manager to be invoked for each byte, but >-that would be rather inefficient.) The buffer's size and location are >-controlled by the manager, not by the library. For example, if you desired to >-decompress a JPEG datastream that was all in memory, you could just make the >-buffer pointer and length point to the original data in memory. Then the >-buffer-reload procedure would be invoked only if the decompressor ran off the >-end of the datastream, which would indicate an erroneous datastream. >- >-The work buffer is defined as an array of datatype JOCTET, which is generally >-"char" or "unsigned char". On a machine where char is not exactly 8 bits >-wide, you must define JOCTET as a wider data type and then modify the data >-source and destination modules to transcribe the work arrays into 8-bit units >-on external storage. >- >-A data destination manager struct contains a pointer and count defining the >-next byte to write in the work buffer and the remaining free space: >- >- JOCTET * next_output_byte; /* => next byte to write in buffer */ >- size_t free_in_buffer; /* # of byte spaces remaining in buffer */ >- >-The library increments the pointer and decrements the count until the buffer >-is filled. The manager's empty_output_buffer method must reset the pointer >-and count. The manager is expected to remember the buffer's starting address >-and total size in private fields not visible to the library. >- >-A data destination manager provides three methods: >- >-init_destination (j_compress_ptr cinfo) >- Initialize destination. This is called by jpeg_start_compress() >- before any data is actually written. It must initialize >- next_output_byte and free_in_buffer. free_in_buffer must be >- initialized to a positive value. >- >-empty_output_buffer (j_compress_ptr cinfo) >- This is called whenever the buffer has filled (free_in_buffer >- reaches zero). In typical applications, it should write out the >- *entire* buffer (use the saved start address and buffer length; >- ignore the current state of next_output_byte and free_in_buffer). >- Then reset the pointer & count to the start of the buffer, and >- return TRUE indicating that the buffer has been dumped. >- free_in_buffer must be set to a positive value when TRUE is >- returned. A FALSE return should only be used when I/O suspension is >- desired (this operating mode is discussed in the next section). >- >-term_destination (j_compress_ptr cinfo) >- Terminate destination --- called by jpeg_finish_compress() after all >- data has been written. In most applications, this must flush any >- data remaining in the buffer. Use either next_output_byte or >- free_in_buffer to determine how much data is in the buffer. >- >-term_destination() is NOT called by jpeg_abort() or jpeg_destroy(). If you >-want the destination manager to be cleaned up during an abort, you must do it >-yourself. >- >-You will also need code to create a jpeg_destination_mgr struct, fill in its >-method pointers, and insert a pointer to the struct into the "dest" field of >-the JPEG compression object. This can be done in-line in your setup code if >-you like, but it's probably cleaner to provide a separate routine similar to >-the jpeg_stdio_dest() routine of the supplied destination manager. >- >-Decompression source managers follow a parallel design, but with some >-additional frammishes. The source manager struct contains a pointer and count >-defining the next byte to read from the work buffer and the number of bytes >-remaining: >- >- const JOCTET * next_input_byte; /* => next byte to read from buffer */ >- size_t bytes_in_buffer; /* # of bytes remaining in buffer */ >- >-The library increments the pointer and decrements the count until the buffer >-is emptied. The manager's fill_input_buffer method must reset the pointer and >-count. In most applications, the manager must remember the buffer's starting >-address and total size in private fields not visible to the library. >- >-A data source manager provides five methods: >- >-init_source (j_decompress_ptr cinfo) >- Initialize source. This is called by jpeg_read_header() before any >- data is actually read. Unlike init_destination(), it may leave >- bytes_in_buffer set to 0 (in which case a fill_input_buffer() call >- will occur immediately). >- >-fill_input_buffer (j_decompress_ptr cinfo) >- This is called whenever bytes_in_buffer has reached zero and more >- data is wanted. In typical applications, it should read fresh data >- into the buffer (ignoring the current state of next_input_byte and >- bytes_in_buffer), reset the pointer & count to the start of the >- buffer, and return TRUE indicating that the buffer has been reloaded. >- It is not necessary to fill the buffer entirely, only to obtain at >- least one more byte. bytes_in_buffer MUST be set to a positive value >- if TRUE is returned. A FALSE return should only be used when I/O >- suspension is desired (this mode is discussed in the next section). >- >-skip_input_data (j_decompress_ptr cinfo, long num_bytes) >- Skip num_bytes worth of data. The buffer pointer and count should >- be advanced over num_bytes input bytes, refilling the buffer as >- needed. This is used to skip over a potentially large amount of >- uninteresting data (such as an APPn marker). In some applications >- it may be possible to optimize away the reading of the skipped data, >- but it's not clear that being smart is worth much trouble; large >- skips are uncommon. bytes_in_buffer may be zero on return. >- A zero or negative skip count should be treated as a no-op. >- >-resync_to_restart (j_decompress_ptr cinfo, int desired) >- This routine is called only when the decompressor has failed to find >- a restart (RSTn) marker where one is expected. Its mission is to >- find a suitable point for resuming decompression. For most >- applications, we recommend that you just use the default resync >- procedure, jpeg_resync_to_restart(). However, if you are able to back >- up in the input data stream, or if you have a-priori knowledge about >- the likely location of restart markers, you may be able to do better. >- Read the read_restart_marker() and jpeg_resync_to_restart() routines >- in jdmarker.c if you think you'd like to implement your own resync >- procedure. >- >-term_source (j_decompress_ptr cinfo) >- Terminate source --- called by jpeg_finish_decompress() after all >- data has been read. Often a no-op. >- >-For both fill_input_buffer() and skip_input_data(), there is no such thing >-as an EOF return. If the end of the file has been reached, the routine has >-a choice of exiting via ERREXIT() or inserting fake data into the buffer. >-In most cases, generating a warning message and inserting a fake EOI marker >-is the best course of action --- this will allow the decompressor to output >-however much of the image is there. In pathological cases, the decompressor >-may swallow the EOI and again demand data ... just keep feeding it fake EOIs. >-jdatasrc.c illustrates the recommended error recovery behavior. >- >-term_source() is NOT called by jpeg_abort() or jpeg_destroy(). If you want >-the source manager to be cleaned up during an abort, you must do it yourself. >- >-You will also need code to create a jpeg_source_mgr struct, fill in its method >-pointers, and insert a pointer to the struct into the "src" field of the JPEG >-decompression object. This can be done in-line in your setup code if you >-like, but it's probably cleaner to provide a separate routine similar to the >-jpeg_stdio_src() routine of the supplied source manager. >- >-For more information, consult the stdio source and destination managers >-in jdatasrc.c and jdatadst.c. >- >- >-I/O suspension >--------------- >- >-Some applications need to use the JPEG library as an incremental memory-to- >-memory filter: when the compressed data buffer is filled or emptied, they want >-control to return to the outer loop, rather than expecting that the buffer can >-be emptied or reloaded within the data source/destination manager subroutine. >-The library supports this need by providing an "I/O suspension" mode, which we >-describe in this section. >- >-The I/O suspension mode is not a panacea: nothing is guaranteed about the >-maximum amount of time spent in any one call to the library, so it will not >-eliminate response-time problems in single-threaded applications. If you >-need guaranteed response time, we suggest you "bite the bullet" and implement >-a real multi-tasking capability. >- >-To use I/O suspension, cooperation is needed between the calling application >-and the data source or destination manager; you will always need a custom >-source/destination manager. (Please read the previous section if you haven't >-already.) The basic idea is that the empty_output_buffer() or >-fill_input_buffer() routine is a no-op, merely returning FALSE to indicate >-that it has done nothing. Upon seeing this, the JPEG library suspends >-operation and returns to its caller. The surrounding application is >-responsible for emptying or refilling the work buffer before calling the >-JPEG library again. >- >-Compression suspension: >- >-For compression suspension, use an empty_output_buffer() routine that returns >-FALSE; typically it will not do anything else. This will cause the >-compressor to return to the caller of jpeg_write_scanlines(), with the return >-value indicating that not all the supplied scanlines have been accepted. >-The application must make more room in the output buffer, adjust the output >-buffer pointer/count appropriately, and then call jpeg_write_scanlines() >-again, pointing to the first unconsumed scanline. >- >-When forced to suspend, the compressor will backtrack to a convenient stopping >-point (usually the start of the current MCU); it will regenerate some output >-data when restarted. Therefore, although empty_output_buffer() is only >-called when the buffer is filled, you should NOT write out the entire buffer >-after a suspension. Write only the data up to the current position of >-next_output_byte/free_in_buffer. The data beyond that point will be >-regenerated after resumption. >- >-Because of the backtracking behavior, a good-size output buffer is essential >-for efficiency; you don't want the compressor to suspend often. (In fact, an >-overly small buffer could lead to infinite looping, if a single MCU required >-more data than would fit in the buffer.) We recommend a buffer of at least >-several Kbytes. You may want to insert explicit code to ensure that you don't >-call jpeg_write_scanlines() unless there is a reasonable amount of space in >-the output buffer; in other words, flush the buffer before trying to compress >-more data. >- >-The compressor does not allow suspension while it is trying to write JPEG >-markers at the beginning and end of the file. This means that: >- * At the beginning of a compression operation, there must be enough free >- space in the output buffer to hold the header markers (typically 600 or >- so bytes). The recommended buffer size is bigger than this anyway, so >- this is not a problem as long as you start with an empty buffer. However, >- this restriction might catch you if you insert large special markers, such >- as a JFIF thumbnail image, without flushing the buffer afterwards. >- * When you call jpeg_finish_compress(), there must be enough space in the >- output buffer to emit any buffered data and the final EOI marker. In the >- current implementation, half a dozen bytes should suffice for this, but >- for safety's sake we recommend ensuring that at least 100 bytes are free >- before calling jpeg_finish_compress(). >- >-A more significant restriction is that jpeg_finish_compress() cannot suspend. >-This means you cannot use suspension with multi-pass operating modes, namely >-Huffman code optimization and multiple-scan output. Those modes write the >-whole file during jpeg_finish_compress(), which will certainly result in >-buffer overrun. (Note that this restriction applies only to compression, >-not decompression. The decompressor supports input suspension in all of its >-operating modes.) >- >-Decompression suspension: >- >-For decompression suspension, use a fill_input_buffer() routine that simply >-returns FALSE (except perhaps during error recovery, as discussed below). >-This will cause the decompressor to return to its caller with an indication >-that suspension has occurred. This can happen at four places: >- * jpeg_read_header(): will return JPEG_SUSPENDED. >- * jpeg_start_decompress(): will return FALSE, rather than its usual TRUE. >- * jpeg_read_scanlines(): will return the number of scanlines already >- completed (possibly 0). >- * jpeg_finish_decompress(): will return FALSE, rather than its usual TRUE. >-The surrounding application must recognize these cases, load more data into >-the input buffer, and repeat the call. In the case of jpeg_read_scanlines(), >-increment the passed pointers past any scanlines successfully read. >- >-Just as with compression, the decompressor will typically backtrack to a >-convenient restart point before suspending. When fill_input_buffer() is >-called, next_input_byte/bytes_in_buffer point to the current restart point, >-which is where the decompressor will backtrack to if FALSE is returned. >-The data beyond that position must NOT be discarded if you suspend; it needs >-to be re-read upon resumption. In most implementations, you'll need to shift >-this data down to the start of your work buffer and then load more data after >-it. Again, this behavior means that a several-Kbyte work buffer is essential >-for decent performance; furthermore, you should load a reasonable amount of >-new data before resuming decompression. (If you loaded, say, only one new >-byte each time around, you could waste a LOT of cycles.) >- >-The skip_input_data() source manager routine requires special care in a >-suspension scenario. This routine is NOT granted the ability to suspend the >-decompressor; it can decrement bytes_in_buffer to zero, but no more. If the >-requested skip distance exceeds the amount of data currently in the input >-buffer, then skip_input_data() must set bytes_in_buffer to zero and record the >-additional skip distance somewhere else. The decompressor will immediately >-call fill_input_buffer(), which should return FALSE, which will cause a >-suspension return. The surrounding application must then arrange to discard >-the recorded number of bytes before it resumes loading the input buffer. >-(Yes, this design is rather baroque, but it avoids complexity in the far more >-common case where a non-suspending source manager is used.) >- >-If the input data has been exhausted, we recommend that you emit a warning >-and insert dummy EOI markers just as a non-suspending data source manager >-would do. This can be handled either in the surrounding application logic or >-within fill_input_buffer(); the latter is probably more efficient. If >-fill_input_buffer() knows that no more data is available, it can set the >-pointer/count to point to a dummy EOI marker and then return TRUE just as >-though it had read more data in a non-suspending situation. >- >-The decompressor does not attempt to suspend within standard JPEG markers; >-instead it will backtrack to the start of the marker and reprocess the whole >-marker next time. Hence the input buffer must be large enough to hold the >-longest standard marker in the file. Standard JPEG markers should normally >-not exceed a few hundred bytes each (DHT tables are typically the longest). >-We recommend at least a 2K buffer for performance reasons, which is much >-larger than any correct marker is likely to be. For robustness against >-damaged marker length counts, you may wish to insert a test in your >-application for the case that the input buffer is completely full and yet >-the decoder has suspended without consuming any data --- otherwise, if this >-situation did occur, it would lead to an endless loop. (The library can't >-provide this test since it has no idea whether "the buffer is full", or >-even whether there is a fixed-size input buffer.) >- >-The input buffer would need to be 64K to allow for arbitrary COM or APPn >-markers, but these are handled specially: they are either saved into allocated >-memory, or skipped over by calling skip_input_data(). In the former case, >-suspension is handled correctly, and in the latter case, the problem of >-buffer overrun is placed on skip_input_data's shoulders, as explained above. >-Note that if you provide your own marker handling routine for large markers, >-you should consider how to deal with buffer overflow. >- >-Multiple-buffer management: >- >-In some applications it is desirable to store the compressed data in a linked >-list of buffer areas, so as to avoid data copying. This can be handled by >-having empty_output_buffer() or fill_input_buffer() set the pointer and count >-to reference the next available buffer; FALSE is returned only if no more >-buffers are available. Although seemingly straightforward, there is a >-pitfall in this approach: the backtrack that occurs when FALSE is returned >-could back up into an earlier buffer. For example, when fill_input_buffer() >-is called, the current pointer & count indicate the backtrack restart point. >-Since fill_input_buffer() will set the pointer and count to refer to a new >-buffer, the restart position must be saved somewhere else. Suppose a second >-call to fill_input_buffer() occurs in the same library call, and no >-additional input data is available, so fill_input_buffer must return FALSE. >-If the JPEG library has not moved the pointer/count forward in the current >-buffer, then *the correct restart point is the saved position in the prior >-buffer*. Prior buffers may be discarded only after the library establishes >-a restart point within a later buffer. Similar remarks apply for output into >-a chain of buffers. >- >-The library will never attempt to backtrack over a skip_input_data() call, >-so any skipped data can be permanently discarded. You still have to deal >-with the case of skipping not-yet-received data, however. >- >-It's much simpler to use only a single buffer; when fill_input_buffer() is >-called, move any unconsumed data (beyond the current pointer/count) down to >-the beginning of this buffer and then load new data into the remaining buffer >-space. This approach requires a little more data copying but is far easier >-to get right. >- >- >-Progressive JPEG support >------------------------- >- >-Progressive JPEG rearranges the stored data into a series of scans of >-increasing quality. In situations where a JPEG file is transmitted across a >-slow communications link, a decoder can generate a low-quality image very >-quickly from the first scan, then gradually improve the displayed quality as >-more scans are received. The final image after all scans are complete is >-identical to that of a regular (sequential) JPEG file of the same quality >-setting. Progressive JPEG files are often slightly smaller than equivalent >-sequential JPEG files, but the possibility of incremental display is the main >-reason for using progressive JPEG. >- >-The IJG encoder library generates progressive JPEG files when given a >-suitable "scan script" defining how to divide the data into scans. >-Creation of progressive JPEG files is otherwise transparent to the encoder. >-Progressive JPEG files can also be read transparently by the decoder library. >-If the decoding application simply uses the library as defined above, it >-will receive a final decoded image without any indication that the file was >-progressive. Of course, this approach does not allow incremental display. >-To perform incremental display, an application needs to use the decoder >-library's "buffered-image" mode, in which it receives a decoded image >-multiple times. >- >-Each displayed scan requires about as much work to decode as a full JPEG >-image of the same size, so the decoder must be fairly fast in relation to the >-data transmission rate in order to make incremental display useful. However, >-it is possible to skip displaying the image and simply add the incoming bits >-to the decoder's coefficient buffer. This is fast because only Huffman >-decoding need be done, not IDCT, upsampling, colorspace conversion, etc. >-The IJG decoder library allows the application to switch dynamically between >-displaying the image and simply absorbing the incoming bits. A properly >-coded application can automatically adapt the number of display passes to >-suit the time available as the image is received. Also, a final >-higher-quality display cycle can be performed from the buffered data after >-the end of the file is reached. >- >-Progressive compression: >- >-To create a progressive JPEG file (or a multiple-scan sequential JPEG file), >-set the scan_info cinfo field to point to an array of scan descriptors, and >-perform compression as usual. Instead of constructing your own scan list, >-you can call the jpeg_simple_progression() helper routine to create a >-recommended progression sequence; this method should be used by all >-applications that don't want to get involved in the nitty-gritty of >-progressive scan sequence design. (If you want to provide user control of >-scan sequences, you may wish to borrow the scan script reading code found >-in rdswitch.c, so that you can read scan script files just like cjpeg's.) >-When scan_info is not NULL, the compression library will store DCT'd data >-into a buffer array as jpeg_write_scanlines() is called, and will emit all >-the requested scans during jpeg_finish_compress(). This implies that >-multiple-scan output cannot be created with a suspending data destination >-manager, since jpeg_finish_compress() does not support suspension. We >-should also note that the compressor currently forces Huffman optimization >-mode when creating a progressive JPEG file, because the default Huffman >-tables are unsuitable for progressive files. >- >-Progressive decompression: >- >-When buffered-image mode is not used, the decoder library will read all of >-a multi-scan file during jpeg_start_decompress(), so that it can provide a >-final decoded image. (Here "multi-scan" means either progressive or >-multi-scan sequential.) This makes multi-scan files transparent to the >-decoding application. However, existing applications that used suspending >-input with version 5 of the IJG library will need to be modified to check >-for a suspension return from jpeg_start_decompress(). >- >-To perform incremental display, an application must use the library's >-buffered-image mode. This is described in the next section. >- >- >-Buffered-image mode >-------------------- >- >-In buffered-image mode, the library stores the partially decoded image in a >-coefficient buffer, from which it can be read out as many times as desired. >-This mode is typically used for incremental display of progressive JPEG files, >-but it can be used with any JPEG file. Each scan of a progressive JPEG file >-adds more data (more detail) to the buffered image. The application can >-display in lockstep with the source file (one display pass per input scan), >-or it can allow input processing to outrun display processing. By making >-input and display processing run independently, it is possible for the >-application to adapt progressive display to a wide range of data transmission >-rates. >- >-The basic control flow for buffered-image decoding is >- >- jpeg_create_decompress() >- set data source >- jpeg_read_header() >- set overall decompression parameters >- cinfo.buffered_image = TRUE; /* select buffered-image mode */ >- jpeg_start_decompress() >- for (each output pass) { >- adjust output decompression parameters if required >- jpeg_start_output() /* start a new output pass */ >- for (all scanlines in image) { >- jpeg_read_scanlines() >- display scanlines >- } >- jpeg_finish_output() /* terminate output pass */ >- } >- jpeg_finish_decompress() >- jpeg_destroy_decompress() >- >-This differs from ordinary unbuffered decoding in that there is an additional >-level of looping. The application can choose how many output passes to make >-and how to display each pass. >- >-The simplest approach to displaying progressive images is to do one display >-pass for each scan appearing in the input file. In this case the outer loop >-condition is typically >- while (! jpeg_input_complete(&cinfo)) >-and the start-output call should read >- jpeg_start_output(&cinfo, cinfo.input_scan_number); >-The second parameter to jpeg_start_output() indicates which scan of the input >-file is to be displayed; the scans are numbered starting at 1 for this >-purpose. (You can use a loop counter starting at 1 if you like, but using >-the library's input scan counter is easier.) The library automatically reads >-data as necessary to complete each requested scan, and jpeg_finish_output() >-advances to the next scan or end-of-image marker (hence input_scan_number >-will be incremented by the time control arrives back at jpeg_start_output()). >-With this technique, data is read from the input file only as needed, and >-input and output processing run in lockstep. >- >-After reading the final scan and reaching the end of the input file, the >-buffered image remains available; it can be read additional times by >-repeating the jpeg_start_output()/jpeg_read_scanlines()/jpeg_finish_output() >-sequence. For example, a useful technique is to use fast one-pass color >-quantization for display passes made while the image is arriving, followed by >-a final display pass using two-pass quantization for highest quality. This >-is done by changing the library parameters before the final output pass. >-Changing parameters between passes is discussed in detail below. >- >-In general the last scan of a progressive file cannot be recognized as such >-until after it is read, so a post-input display pass is the best approach if >-you want special processing in the final pass. >- >-When done with the image, be sure to call jpeg_finish_decompress() to release >-the buffered image (or just use jpeg_destroy_decompress()). >- >-If input data arrives faster than it can be displayed, the application can >-cause the library to decode input data in advance of what's needed to produce >-output. This is done by calling the routine jpeg_consume_input(). >-The return value is one of the following: >- JPEG_REACHED_SOS: reached an SOS marker (the start of a new scan) >- JPEG_REACHED_EOI: reached the EOI marker (end of image) >- JPEG_ROW_COMPLETED: completed reading one MCU row of compressed data >- JPEG_SCAN_COMPLETED: completed reading last MCU row of current scan >- JPEG_SUSPENDED: suspended before completing any of the above >-(JPEG_SUSPENDED can occur only if a suspending data source is used.) This >-routine can be called at any time after initializing the JPEG object. It >-reads some additional data and returns when one of the indicated significant >-events occurs. (If called after the EOI marker is reached, it will >-immediately return JPEG_REACHED_EOI without attempting to read more data.) >- >-The library's output processing will automatically call jpeg_consume_input() >-whenever the output processing overtakes the input; thus, simple lockstep >-display requires no direct calls to jpeg_consume_input(). But by adding >-calls to jpeg_consume_input(), you can absorb data in advance of what is >-being displayed. This has two benefits: >- * You can limit buildup of unprocessed data in your input buffer. >- * You can eliminate extra display passes by paying attention to the >- state of the library's input processing. >- >-The first of these benefits only requires interspersing calls to >-jpeg_consume_input() with your display operations and any other processing >-you may be doing. To avoid wasting cycles due to backtracking, it's best to >-call jpeg_consume_input() only after a hundred or so new bytes have arrived. >-This is discussed further under "I/O suspension", above. (Note: the JPEG >-library currently is not thread-safe. You must not call jpeg_consume_input() >-from one thread of control if a different library routine is working on the >-same JPEG object in another thread.) >- >-When input arrives fast enough that more than one new scan is available >-before you start a new output pass, you may as well skip the output pass >-corresponding to the completed scan. This occurs for free if you pass >-cinfo.input_scan_number as the target scan number to jpeg_start_output(). >-The input_scan_number field is simply the index of the scan currently being >-consumed by the input processor. You can ensure that this is up-to-date by >-emptying the input buffer just before calling jpeg_start_output(): call >-jpeg_consume_input() repeatedly until it returns JPEG_SUSPENDED or >-JPEG_REACHED_EOI. >- >-The target scan number passed to jpeg_start_output() is saved in the >-cinfo.output_scan_number field. The library's output processing calls >-jpeg_consume_input() whenever the current input scan number and row within >-that scan is less than or equal to the current output scan number and row. >-Thus, input processing can "get ahead" of the output processing but is not >-allowed to "fall behind". You can achieve several different effects by >-manipulating this interlock rule. For example, if you pass a target scan >-number greater than the current input scan number, the output processor will >-wait until that scan starts to arrive before producing any output. (To avoid >-an infinite loop, the target scan number is automatically reset to the last >-scan number when the end of image is reached. Thus, if you specify a large >-target scan number, the library will just absorb the entire input file and >-then perform an output pass. This is effectively the same as what >-jpeg_start_decompress() does when you don't select buffered-image mode.) >-When you pass a target scan number equal to the current input scan number, >-the image is displayed no faster than the current input scan arrives. The >-final possibility is to pass a target scan number less than the current input >-scan number; this disables the input/output interlock and causes the output >-processor to simply display whatever it finds in the image buffer, without >-waiting for input. (However, the library will not accept a target scan >-number less than one, so you can't avoid waiting for the first scan.) >- >-When data is arriving faster than the output display processing can advance >-through the image, jpeg_consume_input() will store data into the buffered >-image beyond the point at which the output processing is reading data out >-again. If the input arrives fast enough, it may "wrap around" the buffer to >-the point where the input is more than one whole scan ahead of the output. >-If the output processing simply proceeds through its display pass without >-paying attention to the input, the effect seen on-screen is that the lower >-part of the image is one or more scans better in quality than the upper part. >-Then, when the next output scan is started, you have a choice of what target >-scan number to use. The recommended choice is to use the current input scan >-number at that time, which implies that you've skipped the output scans >-corresponding to the input scans that were completed while you processed the >-previous output scan. In this way, the decoder automatically adapts its >-speed to the arriving data, by skipping output scans as necessary to keep up >-with the arriving data. >- >-When using this strategy, you'll want to be sure that you perform a final >-output pass after receiving all the data; otherwise your last display may not >-be full quality across the whole screen. So the right outer loop logic is >-something like this: >- do { >- absorb any waiting input by calling jpeg_consume_input() >- final_pass = jpeg_input_complete(&cinfo); >- adjust output decompression parameters if required >- jpeg_start_output(&cinfo, cinfo.input_scan_number); >- ... >- jpeg_finish_output() >- } while (! final_pass); >-rather than quitting as soon as jpeg_input_complete() returns TRUE. This >-arrangement makes it simple to use higher-quality decoding parameters >-for the final pass. But if you don't want to use special parameters for >-the final pass, the right loop logic is like this: >- for (;;) { >- absorb any waiting input by calling jpeg_consume_input() >- jpeg_start_output(&cinfo, cinfo.input_scan_number); >- ... >- jpeg_finish_output() >- if (jpeg_input_complete(&cinfo) && >- cinfo.input_scan_number == cinfo.output_scan_number) >- break; >- } >-In this case you don't need to know in advance whether an output pass is to >-be the last one, so it's not necessary to have reached EOF before starting >-the final output pass; rather, what you want to test is whether the output >-pass was performed in sync with the final input scan. This form of the loop >-will avoid an extra output pass whenever the decoder is able (or nearly able) >-to keep up with the incoming data. >- >-When the data transmission speed is high, you might begin a display pass, >-then find that much or all of the file has arrived before you can complete >-the pass. (You can detect this by noting the JPEG_REACHED_EOI return code >-from jpeg_consume_input(), or equivalently by testing jpeg_input_complete().) >-In this situation you may wish to abort the current display pass and start a >-new one using the newly arrived information. To do so, just call >-jpeg_finish_output() and then start a new pass with jpeg_start_output(). >- >-A variant strategy is to abort and restart display if more than one complete >-scan arrives during an output pass; this can be detected by noting >-JPEG_REACHED_SOS returns and/or examining cinfo.input_scan_number. This >-idea should be employed with caution, however, since the display process >-might never get to the bottom of the image before being aborted, resulting >-in the lower part of the screen being several passes worse than the upper. >-In most cases it's probably best to abort an output pass only if the whole >-file has arrived and you want to begin the final output pass immediately. >- >-When receiving data across a communication link, we recommend always using >-the current input scan number for the output target scan number; if a >-higher-quality final pass is to be done, it should be started (aborting any >-incomplete output pass) as soon as the end of file is received. However, >-many other strategies are possible. For example, the application can examine >-the parameters of the current input scan and decide whether to display it or >-not. If the scan contains only chroma data, one might choose not to use it >-as the target scan, expecting that the scan will be small and will arrive >-quickly. To skip to the next scan, call jpeg_consume_input() until it >-returns JPEG_REACHED_SOS or JPEG_REACHED_EOI. Or just use the next higher >-number as the target scan for jpeg_start_output(); but that method doesn't >-let you inspect the next scan's parameters before deciding to display it. >- >- >-In buffered-image mode, jpeg_start_decompress() never performs input and >-thus never suspends. An application that uses input suspension with >-buffered-image mode must be prepared for suspension returns from these >-routines: >-* jpeg_start_output() performs input only if you request 2-pass quantization >- and the target scan isn't fully read yet. (This is discussed below.) >-* jpeg_read_scanlines(), as always, returns the number of scanlines that it >- was able to produce before suspending. >-* jpeg_finish_output() will read any markers following the target scan, >- up to the end of the file or the SOS marker that begins another scan. >- (But it reads no input if jpeg_consume_input() has already reached the >- end of the file or a SOS marker beyond the target output scan.) >-* jpeg_finish_decompress() will read until the end of file, and thus can >- suspend if the end hasn't already been reached (as can be tested by >- calling jpeg_input_complete()). >-jpeg_start_output(), jpeg_finish_output(), and jpeg_finish_decompress() >-all return TRUE if they completed their tasks, FALSE if they had to suspend. >-In the event of a FALSE return, the application must load more input data >-and repeat the call. Applications that use non-suspending data sources need >-not check the return values of these three routines. >- >- >-It is possible to change decoding parameters between output passes in the >-buffered-image mode. The decoder library currently supports only very >-limited changes of parameters. ONLY THE FOLLOWING parameter changes are >-allowed after jpeg_start_decompress() is called: >-* dct_method can be changed before each call to jpeg_start_output(). >- For example, one could use a fast DCT method for early scans, changing >- to a higher quality method for the final scan. >-* dither_mode can be changed before each call to jpeg_start_output(); >- of course this has no impact if not using color quantization. Typically >- one would use ordered dither for initial passes, then switch to >- Floyd-Steinberg dither for the final pass. Caution: changing dither mode >- can cause more memory to be allocated by the library. Although the amount >- of memory involved is not large (a scanline or so), it may cause the >- initial max_memory_to_use specification to be exceeded, which in the worst >- case would result in an out-of-memory failure. >-* do_block_smoothing can be changed before each call to jpeg_start_output(). >- This setting is relevant only when decoding a progressive JPEG image. >- During the first DC-only scan, block smoothing provides a very "fuzzy" look >- instead of the very "blocky" look seen without it; which is better seems a >- matter of personal taste. But block smoothing is nearly always a win >- during later stages, especially when decoding a successive-approximation >- image: smoothing helps to hide the slight blockiness that otherwise shows >- up on smooth gradients until the lowest coefficient bits are sent. >-* Color quantization mode can be changed under the rules described below. >- You *cannot* change between full-color and quantized output (because that >- would alter the required I/O buffer sizes), but you can change which >- quantization method is used. >- >-When generating color-quantized output, changing quantization method is a >-very useful way of switching between high-speed and high-quality display. >-The library allows you to change among its three quantization methods: >-1. Single-pass quantization to a fixed color cube. >- Selected by cinfo.two_pass_quantize = FALSE and cinfo.colormap = NULL. >-2. Single-pass quantization to an application-supplied colormap. >- Selected by setting cinfo.colormap to point to the colormap (the value of >- two_pass_quantize is ignored); also set cinfo.actual_number_of_colors. >-3. Two-pass quantization to a colormap chosen specifically for the image. >- Selected by cinfo.two_pass_quantize = TRUE and cinfo.colormap = NULL. >- (This is the default setting selected by jpeg_read_header, but it is >- probably NOT what you want for the first pass of progressive display!) >-These methods offer successively better quality and lesser speed. However, >-only the first method is available for quantizing in non-RGB color spaces. >- >-IMPORTANT: because the different quantizer methods have very different >-working-storage requirements, the library requires you to indicate which >-one(s) you intend to use before you call jpeg_start_decompress(). (If we did >-not require this, the max_memory_to_use setting would be a complete fiction.) >-You do this by setting one or more of these three cinfo fields to TRUE: >- enable_1pass_quant Fixed color cube colormap >- enable_external_quant Externally-supplied colormap >- enable_2pass_quant Two-pass custom colormap >-All three are initialized FALSE by jpeg_read_header(). But >-jpeg_start_decompress() automatically sets TRUE the one selected by the >-current two_pass_quantize and colormap settings, so you only need to set the >-enable flags for any other quantization methods you plan to change to later. >- >-After setting the enable flags correctly at jpeg_start_decompress() time, you >-can change to any enabled quantization method by setting two_pass_quantize >-and colormap properly just before calling jpeg_start_output(). The following >-special rules apply: >-1. You must explicitly set cinfo.colormap to NULL when switching to 1-pass >- or 2-pass mode from a different mode, or when you want the 2-pass >- quantizer to be re-run to generate a new colormap. >-2. To switch to an external colormap, or to change to a different external >- colormap than was used on the prior pass, you must call >- jpeg_new_colormap() after setting cinfo.colormap. >-NOTE: if you want to use the same colormap as was used in the prior pass, >-you should not do either of these things. This will save some nontrivial >-switchover costs. >-(These requirements exist because cinfo.colormap will always be non-NULL >-after completing a prior output pass, since both the 1-pass and 2-pass >-quantizers set it to point to their output colormaps. Thus you have to >-do one of these two things to notify the library that something has changed. >-Yup, it's a bit klugy, but it's necessary to do it this way for backwards >-compatibility.) >- >-Note that in buffered-image mode, the library generates any requested colormap >-during jpeg_start_output(), not during jpeg_start_decompress(). >- >-When using two-pass quantization, jpeg_start_output() makes a pass over the >-buffered image to determine the optimum color map; it therefore may take a >-significant amount of time, whereas ordinarily it does little work. The >-progress monitor hook is called during this pass, if defined. It is also >-important to realize that if the specified target scan number is greater than >-or equal to the current input scan number, jpeg_start_output() will attempt >-to consume input as it makes this pass. If you use a suspending data source, >-you need to check for a FALSE return from jpeg_start_output() under these >-conditions. The combination of 2-pass quantization and a not-yet-fully-read >-target scan is the only case in which jpeg_start_output() will consume input. >- >- >-Application authors who support buffered-image mode may be tempted to use it >-for all JPEG images, even single-scan ones. This will work, but it is >-inefficient: there is no need to create an image-sized coefficient buffer for >-single-scan images. Requesting buffered-image mode for such an image wastes >-memory. Worse, it can cost time on large images, since the buffered data has >-to be swapped out or written to a temporary file. If you are concerned about >-maximum performance on baseline JPEG files, you should use buffered-image >-mode only when the incoming file actually has multiple scans. This can be >-tested by calling jpeg_has_multiple_scans(), which will return a correct >-result at any time after jpeg_read_header() completes. >- >-It is also worth noting that when you use jpeg_consume_input() to let input >-processing get ahead of output processing, the resulting pattern of access to >-the coefficient buffer is quite nonsequential. It's best to use the memory >-manager jmemnobs.c if you can (ie, if you have enough real or virtual main >-memory). If not, at least make sure that max_memory_to_use is set as high as >-possible. If the JPEG memory manager has to use a temporary file, you will >-probably see a lot of disk traffic and poor performance. (This could be >-improved with additional work on the memory manager, but we haven't gotten >-around to it yet.) >- >-In some applications it may be convenient to use jpeg_consume_input() for all >-input processing, including reading the initial markers; that is, you may >-wish to call jpeg_consume_input() instead of jpeg_read_header() during >-startup. This works, but note that you must check for JPEG_REACHED_SOS and >-JPEG_REACHED_EOI return codes as the equivalent of jpeg_read_header's codes. >-Once the first SOS marker has been reached, you must call >-jpeg_start_decompress() before jpeg_consume_input() will consume more input; >-it'll just keep returning JPEG_REACHED_SOS until you do. If you read a >-tables-only file this way, jpeg_consume_input() will return JPEG_REACHED_EOI >-without ever returning JPEG_REACHED_SOS; be sure to check for this case. >-If this happens, the decompressor will not read any more input until you call >-jpeg_abort() to reset it. It is OK to call jpeg_consume_input() even when not >-using buffered-image mode, but in that case it's basically a no-op after the >-initial markers have been read: it will just return JPEG_SUSPENDED. >- >- >-Abbreviated datastreams and multiple images >-------------------------------------------- >- >-A JPEG compression or decompression object can be reused to process multiple >-images. This saves a small amount of time per image by eliminating the >-"create" and "destroy" operations, but that isn't the real purpose of the >-feature. Rather, reuse of an object provides support for abbreviated JPEG >-datastreams. Object reuse can also simplify processing a series of images in >-a single input or output file. This section explains these features. >- >-A JPEG file normally contains several hundred bytes worth of quantization >-and Huffman tables. In a situation where many images will be stored or >-transmitted with identical tables, this may represent an annoying overhead. >-The JPEG standard therefore permits tables to be omitted. The standard >-defines three classes of JPEG datastreams: >- * "Interchange" datastreams contain an image and all tables needed to decode >- the image. These are the usual kind of JPEG file. >- * "Abbreviated image" datastreams contain an image, but are missing some or >- all of the tables needed to decode that image. >- * "Abbreviated table specification" (henceforth "tables-only") datastreams >- contain only table specifications. >-To decode an abbreviated image, it is necessary to load the missing table(s) >-into the decoder beforehand. This can be accomplished by reading a separate >-tables-only file. A variant scheme uses a series of images in which the first >-image is an interchange (complete) datastream, while subsequent ones are >-abbreviated and rely on the tables loaded by the first image. It is assumed >-that once the decoder has read a table, it will remember that table until a >-new definition for the same table number is encountered. >- >-It is the application designer's responsibility to figure out how to associate >-the correct tables with an abbreviated image. While abbreviated datastreams >-can be useful in a closed environment, their use is strongly discouraged in >-any situation where data exchange with other applications might be needed. >-Caveat designer. >- >-The JPEG library provides support for reading and writing any combination of >-tables-only datastreams and abbreviated images. In both compression and >-decompression objects, a quantization or Huffman table will be retained for >-the lifetime of the object, unless it is overwritten by a new table definition. >- >- >-To create abbreviated image datastreams, it is only necessary to tell the >-compressor not to emit some or all of the tables it is using. Each >-quantization and Huffman table struct contains a boolean field "sent_table", >-which normally is initialized to FALSE. For each table used by the image, the >-header-writing process emits the table and sets sent_table = TRUE unless it is >-already TRUE. (In normal usage, this prevents outputting the same table >-definition multiple times, as would otherwise occur because the chroma >-components typically share tables.) Thus, setting this field to TRUE before >-calling jpeg_start_compress() will prevent the table from being written at >-all. >- >-If you want to create a "pure" abbreviated image file containing no tables, >-just call "jpeg_suppress_tables(&cinfo, TRUE)" after constructing all the >-tables. If you want to emit some but not all tables, you'll need to set the >-individual sent_table fields directly. >- >-To create an abbreviated image, you must also call jpeg_start_compress() >-with a second parameter of FALSE, not TRUE. Otherwise jpeg_start_compress() >-will force all the sent_table fields to FALSE. (This is a safety feature to >-prevent abbreviated images from being created accidentally.) >- >-To create a tables-only file, perform the same parameter setup that you >-normally would, but instead of calling jpeg_start_compress() and so on, call >-jpeg_write_tables(&cinfo). This will write an abbreviated datastream >-containing only SOI, DQT and/or DHT markers, and EOI. All the quantization >-and Huffman tables that are currently defined in the compression object will >-be emitted unless their sent_tables flag is already TRUE, and then all the >-sent_tables flags will be set TRUE. >- >-A sure-fire way to create matching tables-only and abbreviated image files >-is to proceed as follows: >- >- create JPEG compression object >- set JPEG parameters >- set destination to tables-only file >- jpeg_write_tables(&cinfo); >- set destination to image file >- jpeg_start_compress(&cinfo, FALSE); >- write data... >- jpeg_finish_compress(&cinfo); >- >-Since the JPEG parameters are not altered between writing the table file and >-the abbreviated image file, the same tables are sure to be used. Of course, >-you can repeat the jpeg_start_compress() ... jpeg_finish_compress() sequence >-many times to produce many abbreviated image files matching the table file. >- >-You cannot suppress output of the computed Huffman tables when Huffman >-optimization is selected. (If you could, there'd be no way to decode the >-image...) Generally, you don't want to set optimize_coding = TRUE when >-you are trying to produce abbreviated files. >- >-In some cases you might want to compress an image using tables which are >-not stored in the application, but are defined in an interchange or >-tables-only file readable by the application. This can be done by setting up >-a JPEG decompression object to read the specification file, then copying the >-tables into your compression object. See jpeg_copy_critical_parameters() >-for an example of copying quantization tables. >- >- >-To read abbreviated image files, you simply need to load the proper tables >-into the decompression object before trying to read the abbreviated image. >-If the proper tables are stored in the application program, you can just >-allocate the table structs and fill in their contents directly. For example, >-to load a fixed quantization table into table slot "n": >- >- if (cinfo.quant_tbl_ptrs[n] == NULL) >- cinfo.quant_tbl_ptrs[n] = jpeg_alloc_quant_table((j_common_ptr) &cinfo); >- quant_ptr = cinfo.quant_tbl_ptrs[n]; /* quant_ptr is JQUANT_TBL* */ >- for (i = 0; i < 64; i++) { >- /* Qtable[] is desired quantization table, in natural array order */ >- quant_ptr->quantval[i] = Qtable[i]; >- } >- >-Code to load a fixed Huffman table is typically (for AC table "n"): >- >- if (cinfo.ac_huff_tbl_ptrs[n] == NULL) >- cinfo.ac_huff_tbl_ptrs[n] = jpeg_alloc_huff_table((j_common_ptr) &cinfo); >- huff_ptr = cinfo.ac_huff_tbl_ptrs[n]; /* huff_ptr is JHUFF_TBL* */ >- for (i = 1; i <= 16; i++) { >- /* counts[i] is number of Huffman codes of length i bits, i=1..16 */ >- huff_ptr->bits[i] = counts[i]; >- } >- for (i = 0; i < 256; i++) { >- /* symbols[] is the list of Huffman symbols, in code-length order */ >- huff_ptr->huffval[i] = symbols[i]; >- } >- >-(Note that trying to set cinfo.quant_tbl_ptrs[n] to point directly at a >-constant JQUANT_TBL object is not safe. If the incoming file happened to >-contain a quantization table definition, your master table would get >-overwritten! Instead allocate a working table copy and copy the master table >-into it, as illustrated above. Ditto for Huffman tables, of course.) >- >-You might want to read the tables from a tables-only file, rather than >-hard-wiring them into your application. The jpeg_read_header() call is >-sufficient to read a tables-only file. You must pass a second parameter of >-FALSE to indicate that you do not require an image to be present. Thus, the >-typical scenario is >- >- create JPEG decompression object >- set source to tables-only file >- jpeg_read_header(&cinfo, FALSE); >- set source to abbreviated image file >- jpeg_read_header(&cinfo, TRUE); >- set decompression parameters >- jpeg_start_decompress(&cinfo); >- read data... >- jpeg_finish_decompress(&cinfo); >- >-In some cases, you may want to read a file without knowing whether it contains >-an image or just tables. In that case, pass FALSE and check the return value >-from jpeg_read_header(): it will be JPEG_HEADER_OK if an image was found, >-JPEG_HEADER_TABLES_ONLY if only tables were found. (A third return value, >-JPEG_SUSPENDED, is possible when using a suspending data source manager.) >-Note that jpeg_read_header() will not complain if you read an abbreviated >-image for which you haven't loaded the missing tables; the missing-table check >-occurs later, in jpeg_start_decompress(). >- >- >-It is possible to read a series of images from a single source file by >-repeating the jpeg_read_header() ... jpeg_finish_decompress() sequence, >-without releasing/recreating the JPEG object or the data source module. >-(If you did reinitialize, any partial bufferload left in the data source >-buffer at the end of one image would be discarded, causing you to lose the >-start of the next image.) When you use this method, stored tables are >-automatically carried forward, so some of the images can be abbreviated images >-that depend on tables from earlier images. >- >-If you intend to write a series of images into a single destination file, >-you might want to make a specialized data destination module that doesn't >-flush the output buffer at term_destination() time. This would speed things >-up by some trifling amount. Of course, you'd need to remember to flush the >-buffer after the last image. You can make the later images be abbreviated >-ones by passing FALSE to jpeg_start_compress(). >- >- >-Special markers >---------------- >- >-Some applications may need to insert or extract special data in the JPEG >-datastream. The JPEG standard provides marker types "COM" (comment) and >-"APP0" through "APP15" (application) to hold application-specific data. >-Unfortunately, the use of these markers is not specified by the standard. >-COM markers are fairly widely used to hold user-supplied text. The JFIF file >-format spec uses APP0 markers with specified initial strings to hold certain >-data. Adobe applications use APP14 markers beginning with the string "Adobe" >-for miscellaneous data. Other APPn markers are rarely seen, but might >-contain almost anything. >- >-If you wish to store user-supplied text, we recommend you use COM markers >-and place readable 7-bit ASCII text in them. Newline conventions are not >-standardized --- expect to find LF (Unix style), CR/LF (DOS style), or CR >-(Mac style). A robust COM reader should be able to cope with random binary >-garbage, including nulls, since some applications generate COM markers >-containing non-ASCII junk. (But yours should not be one of them.) >- >-For program-supplied data, use an APPn marker, and be sure to begin it with an >-identifying string so that you can tell whether the marker is actually yours. >-It's probably best to avoid using APP0 or APP14 for any private markers. >-(NOTE: the upcoming SPIFF standard will use APP8 markers; we recommend you >-not use APP8 markers for any private purposes, either.) >- >-Keep in mind that at most 65533 bytes can be put into one marker, but you >-can have as many markers as you like. >- >-By default, the IJG compression library will write a JFIF APP0 marker if the >-selected JPEG colorspace is grayscale or YCbCr, or an Adobe APP14 marker if >-the selected colorspace is RGB, CMYK, or YCCK. You can disable this, but >-we don't recommend it. The decompression library will recognize JFIF and >-Adobe markers and will set the JPEG colorspace properly when one is found. >- >- >-You can write special markers immediately following the datastream header by >-calling jpeg_write_marker() after jpeg_start_compress() and before the first >-call to jpeg_write_scanlines(). When you do this, the markers appear after >-the SOI and the JFIF APP0 and Adobe APP14 markers (if written), but before >-all else. Specify the marker type parameter as "JPEG_COM" for COM or >-"JPEG_APP0 + n" for APPn. (Actually, jpeg_write_marker will let you write >-any marker type, but we don't recommend writing any other kinds of marker.) >-For example, to write a user comment string pointed to by comment_text: >- jpeg_write_marker(cinfo, JPEG_COM, comment_text, strlen(comment_text)); >- >-If it's not convenient to store all the marker data in memory at once, >-you can instead call jpeg_write_m_header() followed by multiple calls to >-jpeg_write_m_byte(). If you do it this way, it's your responsibility to >-call jpeg_write_m_byte() exactly the number of times given in the length >-parameter to jpeg_write_m_header(). (This method lets you empty the >-output buffer partway through a marker, which might be important when >-using a suspending data destination module. In any case, if you are using >-a suspending destination, you should flush its buffer after inserting >-any special markers. See "I/O suspension".) >- >-Or, if you prefer to synthesize the marker byte sequence yourself, >-you can just cram it straight into the data destination module. >- >-If you are writing JFIF 1.02 extension markers (thumbnail images), don't >-forget to set cinfo.JFIF_minor_version = 2 so that the encoder will write the >-correct JFIF version number in the JFIF header marker. The library's default >-is to write version 1.01, but that's wrong if you insert any 1.02 extension >-markers. (We could probably get away with just defaulting to 1.02, but there >-used to be broken decoders that would complain about unknown minor version >-numbers. To reduce compatibility risks it's safest not to write 1.02 unless >-you are actually using 1.02 extensions.) >- >- >-When reading, two methods of handling special markers are available: >-1. You can ask the library to save the contents of COM and/or APPn markers >-into memory, and then examine them at your leisure afterwards. >-2. You can supply your own routine to process COM and/or APPn markers >-on-the-fly as they are read. >-The first method is simpler to use, especially if you are using a suspending >-data source; writing a marker processor that copes with input suspension is >-not easy (consider what happens if the marker is longer than your available >-input buffer). However, the second method conserves memory since the marker >-data need not be kept around after it's been processed. >- >-For either method, you'd normally set up marker handling after creating a >-decompression object and before calling jpeg_read_header(), because the >-markers of interest will typically be near the head of the file and so will >-be scanned by jpeg_read_header. Once you've established a marker handling >-method, it will be used for the life of that decompression object >-(potentially many datastreams), unless you change it. Marker handling is >-determined separately for COM markers and for each APPn marker code. >- >- >-To save the contents of special markers in memory, call >- jpeg_save_markers(cinfo, marker_code, length_limit) >-where marker_code is the marker type to save, JPEG_COM or JPEG_APP0+n. >-(To arrange to save all the special marker types, you need to call this >-routine 17 times, for COM and APP0-APP15.) If the incoming marker is longer >-than length_limit data bytes, only length_limit bytes will be saved; this >-parameter allows you to avoid chewing up memory when you only need to see the >-first few bytes of a potentially large marker. If you want to save all the >-data, set length_limit to 0xFFFF; that is enough since marker lengths are only >-16 bits. As a special case, setting length_limit to 0 prevents that marker >-type from being saved at all. (That is the default behavior, in fact.) >- >-After jpeg_read_header() completes, you can examine the special markers by >-following the cinfo->marker_list pointer chain. All the special markers in >-the file appear in this list, in order of their occurrence in the file (but >-omitting any markers of types you didn't ask for). Both the original data >-length and the saved data length are recorded for each list entry; the latter >-will not exceed length_limit for the particular marker type. Note that these >-lengths exclude the marker length word, whereas the stored representation >-within the JPEG file includes it. (Hence the maximum data length is really >-only 65533.) >- >-It is possible that additional special markers appear in the file beyond the >-SOS marker at which jpeg_read_header stops; if so, the marker list will be >-extended during reading of the rest of the file. This is not expected to be >-common, however. If you are short on memory you may want to reset the length >-limit to zero for all marker types after finishing jpeg_read_header, to >-ensure that the max_memory_to_use setting cannot be exceeded due to addition >-of later markers. >- >-The marker list remains stored until you call jpeg_finish_decompress or >-jpeg_abort, at which point the memory is freed and the list is set to empty. >-(jpeg_destroy also releases the storage, of course.) >- >-Note that the library is internally interested in APP0 and APP14 markers; >-if you try to set a small nonzero length limit on these types, the library >-will silently force the length up to the minimum it wants. (But you can set >-a zero length limit to prevent them from being saved at all.) Also, in a >-16-bit environment, the maximum length limit may be constrained to less than >-65533 by malloc() limitations. It is therefore best not to assume that the >-effective length limit is exactly what you set it to be. >- >- >-If you want to supply your own marker-reading routine, you do it by calling >-jpeg_set_marker_processor(). A marker processor routine must have the >-signature >- boolean jpeg_marker_parser_method (j_decompress_ptr cinfo) >-Although the marker code is not explicitly passed, the routine can find it >-in cinfo->unread_marker. At the time of call, the marker proper has been >-read from the data source module. The processor routine is responsible for >-reading the marker length word and the remaining parameter bytes, if any. >-Return TRUE to indicate success. (FALSE should be returned only if you are >-using a suspending data source and it tells you to suspend. See the standard >-marker processors in jdmarker.c for appropriate coding methods if you need to >-use a suspending data source.) >- >-If you override the default APP0 or APP14 processors, it is up to you to >-recognize JFIF and Adobe markers if you want colorspace recognition to occur >-properly. We recommend copying and extending the default processors if you >-want to do that. (A better idea is to save these marker types for later >-examination by calling jpeg_save_markers(); that method doesn't interfere >-with the library's own processing of these markers.) >- >-jpeg_set_marker_processor() and jpeg_save_markers() are mutually exclusive >---- if you call one it overrides any previous call to the other, for the >-particular marker type specified. >- >-A simple example of an external COM processor can be found in djpeg.c. >-Also, see jpegtran.c for an example of using jpeg_save_markers. >- >- >-Raw (downsampled) image data >----------------------------- >- >-Some applications need to supply already-downsampled image data to the JPEG >-compressor, or to receive raw downsampled data from the decompressor. The >-library supports this requirement by allowing the application to write or >-read raw data, bypassing the normal preprocessing or postprocessing steps. >-The interface is different from the standard one and is somewhat harder to >-use. If your interest is merely in bypassing color conversion, we recommend >-that you use the standard interface and simply set jpeg_color_space = >-in_color_space (or jpeg_color_space = out_color_space for decompression). >-The mechanism described in this section is necessary only to supply or >-receive downsampled image data, in which not all components have the same >-dimensions. >- >- >-To compress raw data, you must supply the data in the colorspace to be used >-in the JPEG file (please read the earlier section on Special color spaces) >-and downsampled to the sampling factors specified in the JPEG parameters. >-You must supply the data in the format used internally by the JPEG library, >-namely a JSAMPIMAGE array. This is an array of pointers to two-dimensional >-arrays, each of type JSAMPARRAY. Each 2-D array holds the values for one >-color component. This structure is necessary since the components are of >-different sizes. If the image dimensions are not a multiple of the MCU size, >-you must also pad the data correctly (usually, this is done by replicating >-the last column and/or row). The data must be padded to a multiple of a DCT >-block in each component: that is, each downsampled row must contain a >-multiple of 8 valid samples, and there must be a multiple of 8 sample rows >-for each component. (For applications such as conversion of digital TV >-images, the standard image size is usually a multiple of the DCT block size, >-so that no padding need actually be done.) >- >-The procedure for compression of raw data is basically the same as normal >-compression, except that you call jpeg_write_raw_data() in place of >-jpeg_write_scanlines(). Before calling jpeg_start_compress(), you must do >-the following: >- * Set cinfo->raw_data_in to TRUE. (It is set FALSE by jpeg_set_defaults().) >- This notifies the library that you will be supplying raw data. >- * Ensure jpeg_color_space is correct --- an explicit jpeg_set_colorspace() >- call is a good idea. Note that since color conversion is bypassed, >- in_color_space is ignored, except that jpeg_set_defaults() uses it to >- choose the default jpeg_color_space setting. >- * Ensure the sampling factors, cinfo->comp_info[i].h_samp_factor and >- cinfo->comp_info[i].v_samp_factor, are correct. Since these indicate the >- dimensions of the data you are supplying, it's wise to set them >- explicitly, rather than assuming the library's defaults are what you want. >- >-To pass raw data to the library, call jpeg_write_raw_data() in place of >-jpeg_write_scanlines(). The two routines work similarly except that >-jpeg_write_raw_data takes a JSAMPIMAGE data array rather than JSAMPARRAY. >-The scanlines count passed to and returned from jpeg_write_raw_data is >-measured in terms of the component with the largest v_samp_factor. >- >-jpeg_write_raw_data() processes one MCU row per call, which is to say >-v_samp_factor*DCTSIZE sample rows of each component. The passed num_lines >-value must be at least max_v_samp_factor*DCTSIZE, and the return value will >-be exactly that amount (or possibly some multiple of that amount, in future >-library versions). This is true even on the last call at the bottom of the >-image; don't forget to pad your data as necessary. >- >-The required dimensions of the supplied data can be computed for each >-component as >- cinfo->comp_info[i].width_in_blocks*DCTSIZE samples per row >- cinfo->comp_info[i].height_in_blocks*DCTSIZE rows in image >-after jpeg_start_compress() has initialized those fields. If the valid data >-is smaller than this, it must be padded appropriately. For some sampling >-factors and image sizes, additional dummy DCT blocks are inserted to make >-the image a multiple of the MCU dimensions. The library creates such dummy >-blocks itself; it does not read them from your supplied data. Therefore you >-need never pad by more than DCTSIZE samples. An example may help here. >-Assume 2h2v downsampling of YCbCr data, that is >- cinfo->comp_info[0].h_samp_factor = 2 for Y >- cinfo->comp_info[0].v_samp_factor = 2 >- cinfo->comp_info[1].h_samp_factor = 1 for Cb >- cinfo->comp_info[1].v_samp_factor = 1 >- cinfo->comp_info[2].h_samp_factor = 1 for Cr >- cinfo->comp_info[2].v_samp_factor = 1 >-and suppose that the nominal image dimensions (cinfo->image_width and >-cinfo->image_height) are 101x101 pixels. Then jpeg_start_compress() will >-compute downsampled_width = 101 and width_in_blocks = 13 for Y, >-downsampled_width = 51 and width_in_blocks = 7 for Cb and Cr (and the same >-for the height fields). You must pad the Y data to at least 13*8 = 104 >-columns and rows, the Cb/Cr data to at least 7*8 = 56 columns and rows. The >-MCU height is max_v_samp_factor = 2 DCT rows so you must pass at least 16 >-scanlines on each call to jpeg_write_raw_data(), which is to say 16 actual >-sample rows of Y and 8 each of Cb and Cr. A total of 7 MCU rows are needed, >-so you must pass a total of 7*16 = 112 "scanlines". The last DCT block row >-of Y data is dummy, so it doesn't matter what you pass for it in the data >-arrays, but the scanlines count must total up to 112 so that all of the Cb >-and Cr data gets passed. >- >-Output suspension is supported with raw-data compression: if the data >-destination module suspends, jpeg_write_raw_data() will return 0. >-In this case the same data rows must be passed again on the next call. >- >- >-Decompression with raw data output implies bypassing all postprocessing: >-you cannot ask for rescaling or color quantization, for instance. More >-seriously, you must deal with the color space and sampling factors present in >-the incoming file. If your application only handles, say, 2h1v YCbCr data, >-you must check for and fail on other color spaces or other sampling factors. >-The library will not convert to a different color space for you. >- >-To obtain raw data output, set cinfo->raw_data_out = TRUE before >-jpeg_start_decompress() (it is set FALSE by jpeg_read_header()). Be sure to >-verify that the color space and sampling factors are ones you can handle. >-Then call jpeg_read_raw_data() in place of jpeg_read_scanlines(). The >-decompression process is otherwise the same as usual. >- >-jpeg_read_raw_data() returns one MCU row per call, and thus you must pass a >-buffer of at least max_v_samp_factor*DCTSIZE scanlines (scanline counting is >-the same as for raw-data compression). The buffer you pass must be large >-enough to hold the actual data plus padding to DCT-block boundaries. As with >-compression, any entirely dummy DCT blocks are not processed so you need not >-allocate space for them, but the total scanline count includes them. The >-above example of computing buffer dimensions for raw-data compression is >-equally valid for decompression. >- >-Input suspension is supported with raw-data decompression: if the data source >-module suspends, jpeg_read_raw_data() will return 0. You can also use >-buffered-image mode to read raw data in multiple passes. >- >- >-Really raw data: DCT coefficients >---------------------------------- >- >-It is possible to read or write the contents of a JPEG file as raw DCT >-coefficients. This facility is mainly intended for use in lossless >-transcoding between different JPEG file formats. Other possible applications >-include lossless cropping of a JPEG image, lossless reassembly of a >-multi-strip or multi-tile TIFF/JPEG file into a single JPEG datastream, etc. >- >-To read the contents of a JPEG file as DCT coefficients, open the file and do >-jpeg_read_header() as usual. But instead of calling jpeg_start_decompress() >-and jpeg_read_scanlines(), call jpeg_read_coefficients(). This will read the >-entire image into a set of virtual coefficient-block arrays, one array per >-component. The return value is a pointer to an array of virtual-array >-descriptors. Each virtual array can be accessed directly using the JPEG >-memory manager's access_virt_barray method (see Memory management, below, >-and also read structure.doc's discussion of virtual array handling). Or, >-for simple transcoding to a different JPEG file format, the array list can >-just be handed directly to jpeg_write_coefficients(). >- >-Each block in the block arrays contains quantized coefficient values in >-normal array order (not JPEG zigzag order). The block arrays contain only >-DCT blocks containing real data; any entirely-dummy blocks added to fill out >-interleaved MCUs at the right or bottom edges of the image are discarded >-during reading and are not stored in the block arrays. (The size of each >-block array can be determined from the width_in_blocks and height_in_blocks >-fields of the component's comp_info entry.) This is also the data format >-expected by jpeg_write_coefficients(). >- >-When you are done using the virtual arrays, call jpeg_finish_decompress() >-to release the array storage and return the decompression object to an idle >-state; or just call jpeg_destroy() if you don't need to reuse the object. >- >-If you use a suspending data source, jpeg_read_coefficients() will return >-NULL if it is forced to suspend; a non-NULL return value indicates successful >-completion. You need not test for a NULL return value when using a >-non-suspending data source. >- >-It is also possible to call jpeg_read_coefficients() to obtain access to the >-decoder's coefficient arrays during a normal decode cycle in buffered-image >-mode. This frammish might be useful for progressively displaying an incoming >-image and then re-encoding it without loss. To do this, decode in buffered- >-image mode as discussed previously, then call jpeg_read_coefficients() after >-the last jpeg_finish_output() call. The arrays will be available for your use >-until you call jpeg_finish_decompress(). >- >- >-To write the contents of a JPEG file as DCT coefficients, you must provide >-the DCT coefficients stored in virtual block arrays. You can either pass >-block arrays read from an input JPEG file by jpeg_read_coefficients(), or >-allocate virtual arrays from the JPEG compression object and fill them >-yourself. In either case, jpeg_write_coefficients() is substituted for >-jpeg_start_compress() and jpeg_write_scanlines(). Thus the sequence is >- * Create compression object >- * Set all compression parameters as necessary >- * Request virtual arrays if needed >- * jpeg_write_coefficients() >- * jpeg_finish_compress() >- * Destroy or re-use compression object >-jpeg_write_coefficients() is passed a pointer to an array of virtual block >-array descriptors; the number of arrays is equal to cinfo.num_components. >- >-The virtual arrays need only have been requested, not realized, before >-jpeg_write_coefficients() is called. A side-effect of >-jpeg_write_coefficients() is to realize any virtual arrays that have been >-requested from the compression object's memory manager. Thus, when obtaining >-the virtual arrays from the compression object, you should fill the arrays >-after calling jpeg_write_coefficients(). The data is actually written out >-when you call jpeg_finish_compress(); jpeg_write_coefficients() only writes >-the file header. >- >-When writing raw DCT coefficients, it is crucial that the JPEG quantization >-tables and sampling factors match the way the data was encoded, or the >-resulting file will be invalid. For transcoding from an existing JPEG file, >-we recommend using jpeg_copy_critical_parameters(). This routine initializes >-all the compression parameters to default values (like jpeg_set_defaults()), >-then copies the critical information from a source decompression object. >-The decompression object should have just been used to read the entire >-JPEG input file --- that is, it should be awaiting jpeg_finish_decompress(). >- >-jpeg_write_coefficients() marks all tables stored in the compression object >-as needing to be written to the output file (thus, it acts like >-jpeg_start_compress(cinfo, TRUE)). This is for safety's sake, to avoid >-emitting abbreviated JPEG files by accident. If you really want to emit an >-abbreviated JPEG file, call jpeg_suppress_tables(), or set the tables' >-individual sent_table flags, between calling jpeg_write_coefficients() and >-jpeg_finish_compress(). >- >- >-Progress monitoring >-------------------- >- >-Some applications may need to regain control from the JPEG library every so >-often. The typical use of this feature is to produce a percent-done bar or >-other progress display. (For a simple example, see cjpeg.c or djpeg.c.) >-Although you do get control back frequently during the data-transferring pass >-(the jpeg_read_scanlines or jpeg_write_scanlines loop), any additional passes >-will occur inside jpeg_finish_compress or jpeg_start_decompress; those >-routines may take a long time to execute, and you don't get control back >-until they are done. >- >-You can define a progress-monitor routine which will be called periodically >-by the library. No guarantees are made about how often this call will occur, >-so we don't recommend you use it for mouse tracking or anything like that. >-At present, a call will occur once per MCU row, scanline, or sample row >-group, whichever unit is convenient for the current processing mode; so the >-wider the image, the longer the time between calls. During the data >-transferring pass, only one call occurs per call of jpeg_read_scanlines or >-jpeg_write_scanlines, so don't pass a large number of scanlines at once if >-you want fine resolution in the progress count. (If you really need to use >-the callback mechanism for time-critical tasks like mouse tracking, you could >-insert additional calls inside some of the library's inner loops.) >- >-To establish a progress-monitor callback, create a struct jpeg_progress_mgr, >-fill in its progress_monitor field with a pointer to your callback routine, >-and set cinfo->progress to point to the struct. The callback will be called >-whenever cinfo->progress is non-NULL. (This pointer is set to NULL by >-jpeg_create_compress or jpeg_create_decompress; the library will not change >-it thereafter. So if you allocate dynamic storage for the progress struct, >-make sure it will live as long as the JPEG object does. Allocating from the >-JPEG memory manager with lifetime JPOOL_PERMANENT will work nicely.) You >-can use the same callback routine for both compression and decompression. >- >-The jpeg_progress_mgr struct contains four fields which are set by the library: >- long pass_counter; /* work units completed in this pass */ >- long pass_limit; /* total number of work units in this pass */ >- int completed_passes; /* passes completed so far */ >- int total_passes; /* total number of passes expected */ >-During any one pass, pass_counter increases from 0 up to (not including) >-pass_limit; the step size is usually but not necessarily 1. The pass_limit >-value may change from one pass to another. The expected total number of >-passes is in total_passes, and the number of passes already completed is in >-completed_passes. Thus the fraction of work completed may be estimated as >- completed_passes + (pass_counter/pass_limit) >- -------------------------------------------- >- total_passes >-ignoring the fact that the passes may not be equal amounts of work. >- >-When decompressing, pass_limit can even change within a pass, because it >-depends on the number of scans in the JPEG file, which isn't always known in >-advance. The computed fraction-of-work-done may jump suddenly (if the library >-discovers it has overestimated the number of scans) or even decrease (in the >-opposite case). It is not wise to put great faith in the work estimate. >- >-When using the decompressor's buffered-image mode, the progress monitor work >-estimate is likely to be completely unhelpful, because the library has no way >-to know how many output passes will be demanded of it. Currently, the library >-sets total_passes based on the assumption that there will be one more output >-pass if the input file end hasn't yet been read (jpeg_input_complete() isn't >-TRUE), but no more output passes if the file end has been reached when the >-output pass is started. This means that total_passes will rise as additional >-output passes are requested. If you have a way of determining the input file >-size, estimating progress based on the fraction of the file that's been read >-will probably be more useful than using the library's value. >- >- >-Memory management >------------------ >- >-This section covers some key facts about the JPEG library's built-in memory >-manager. For more info, please read structure.doc's section about the memory >-manager, and consult the source code if necessary. >- >-All memory and temporary file allocation within the library is done via the >-memory manager. If necessary, you can replace the "back end" of the memory >-manager to control allocation yourself (for example, if you don't want the >-library to use malloc() and free() for some reason). >- >-Some data is allocated "permanently" and will not be freed until the JPEG >-object is destroyed. Most data is allocated "per image" and is freed by >-jpeg_finish_compress, jpeg_finish_decompress, or jpeg_abort. You can call the >-memory manager yourself to allocate structures that will automatically be >-freed at these times. Typical code for this is >- ptr = (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, size); >-Use JPOOL_PERMANENT to get storage that lasts as long as the JPEG object. >-Use alloc_large instead of alloc_small for anything bigger than a few Kbytes. >-There are also alloc_sarray and alloc_barray routines that automatically >-build 2-D sample or block arrays. >- >-The library's minimum space requirements to process an image depend on the >-image's width, but not on its height, because the library ordinarily works >-with "strip" buffers that are as wide as the image but just a few rows high. >-Some operating modes (eg, two-pass color quantization) require full-image >-buffers. Such buffers are treated as "virtual arrays": only the current strip >-need be in memory, and the rest can be swapped out to a temporary file. >- >-If you use the simplest memory manager back end (jmemnobs.c), then no >-temporary files are used; virtual arrays are simply malloc()'d. Images bigger >-than memory can be processed only if your system supports virtual memory. >-The other memory manager back ends support temporary files of various flavors >-and thus work in machines without virtual memory. They may also be useful on >-Unix machines if you need to process images that exceed available swap space. >- >-When using temporary files, the library will make the in-memory buffers for >-its virtual arrays just big enough to stay within a "maximum memory" setting. >-Your application can set this limit by setting cinfo->mem->max_memory_to_use >-after creating the JPEG object. (Of course, there is still a minimum size for >-the buffers, so the max-memory setting is effective only if it is bigger than >-the minimum space needed.) If you allocate any large structures yourself, you >-must allocate them before jpeg_start_compress() or jpeg_start_decompress() in >-order to have them counted against the max memory limit. Also keep in mind >-that space allocated with alloc_small() is ignored, on the assumption that >-it's too small to be worth worrying about; so a reasonable safety margin >-should be left when setting max_memory_to_use. >- >-If you use the jmemname.c or jmemdos.c memory manager back end, it is >-important to clean up the JPEG object properly to ensure that the temporary >-files get deleted. (This is especially crucial with jmemdos.c, where the >-"temporary files" may be extended-memory segments; if they are not freed, >-DOS will require a reboot to recover the memory.) Thus, with these memory >-managers, it's a good idea to provide a signal handler that will trap any >-early exit from your program. The handler should call either jpeg_abort() >-or jpeg_destroy() for any active JPEG objects. A handler is not needed with >-jmemnobs.c, and shouldn't be necessary with jmemansi.c or jmemmac.c either, >-since the C library is supposed to take care of deleting files made with >-tmpfile(). >- >- >-Memory usage >------------- >- >-Working memory requirements while performing compression or decompression >-depend on image dimensions, image characteristics (such as colorspace and >-JPEG process), and operating mode (application-selected options). >- >-As of v6b, the decompressor requires: >- 1. About 24K in more-or-less-fixed-size data. This varies a bit depending >- on operating mode and image characteristics (particularly color vs. >- grayscale), but it doesn't depend on image dimensions. >- 2. Strip buffers (of size proportional to the image width) for IDCT and >- upsampling results. The worst case for commonly used sampling factors >- is about 34 bytes * width in pixels for a color image. A grayscale image >- only needs about 8 bytes per pixel column. >- 3. A full-image DCT coefficient buffer is needed to decode a multi-scan JPEG >- file (including progressive JPEGs), or whenever you select buffered-image >- mode. This takes 2 bytes/coefficient. At typical 2x2 sampling, that's >- 3 bytes per pixel for a color image. Worst case (1x1 sampling) requires >- 6 bytes/pixel. For grayscale, figure 2 bytes/pixel. >- 4. To perform 2-pass color quantization, the decompressor also needs a >- 128K color lookup table and a full-image pixel buffer (3 bytes/pixel). >-This does not count any memory allocated by the application, such as a >-buffer to hold the final output image. >- >-The above figures are valid for 8-bit JPEG data precision and a machine with >-32-bit ints. For 12-bit JPEG data, double the size of the strip buffers and >-quantization pixel buffer. The "fixed-size" data will be somewhat smaller >-with 16-bit ints, larger with 64-bit ints. Also, CMYK or other unusual >-color spaces will require different amounts of space. >- >-The full-image coefficient and pixel buffers, if needed at all, do not >-have to be fully RAM resident; you can have the library use temporary >-files instead when the total memory usage would exceed a limit you set. >-(But if your OS supports virtual memory, it's probably better to just use >-jmemnobs and let the OS do the swapping.) >- >-The compressor's memory requirements are similar, except that it has no need >-for color quantization. Also, it needs a full-image DCT coefficient buffer >-if Huffman-table optimization is asked for, even if progressive mode is not >-requested. >- >-If you need more detailed information about memory usage in a particular >-situation, you can enable the MEM_STATS code in jmemmgr.c. >- >- >-Library compile-time options >----------------------------- >- >-A number of compile-time options are available by modifying jmorecfg.h. >- >-The JPEG standard provides for both the baseline 8-bit DCT process and >-a 12-bit DCT process. The IJG code supports 12-bit lossy JPEG if you define >-BITS_IN_JSAMPLE as 12 rather than 8. Note that this causes JSAMPLE to be >-larger than a char, so it affects the surrounding application's image data. >-The sample applications cjpeg and djpeg can support 12-bit mode only for PPM >-and GIF file formats; you must disable the other file formats to compile a >-12-bit cjpeg or djpeg. (install.doc has more information about that.) >-At present, a 12-bit library can handle *only* 12-bit images, not both >-precisions. (If you need to include both 8- and 12-bit libraries in a single >-application, you could probably do it by defining NEED_SHORT_EXTERNAL_NAMES >-for just one of the copies. You'd have to access the 8-bit and 12-bit copies >-from separate application source files. This is untested ... if you try it, >-we'd like to hear whether it works!) >- >-Note that a 12-bit library always compresses in Huffman optimization mode, >-in order to generate valid Huffman tables. This is necessary because our >-default Huffman tables only cover 8-bit data. If you need to output 12-bit >-files in one pass, you'll have to supply suitable default Huffman tables. >-You may also want to supply your own DCT quantization tables; the existing >-quality-scaling code has been developed for 8-bit use, and probably doesn't >-generate especially good tables for 12-bit. >- >-The maximum number of components (color channels) in the image is determined >-by MAX_COMPONENTS. The JPEG standard allows up to 255 components, but we >-expect that few applications will need more than four or so. >- >-On machines with unusual data type sizes, you may be able to improve >-performance or reduce memory space by tweaking the various typedefs in >-jmorecfg.h. In particular, on some RISC CPUs, access to arrays of "short"s >-is quite slow; consider trading memory for speed by making JCOEF, INT16, and >-UINT16 be "int" or "unsigned int". UINT8 is also a candidate to become int. >-You probably don't want to make JSAMPLE be int unless you have lots of memory >-to burn. >- >-You can reduce the size of the library by compiling out various optional >-functions. To do this, undefine xxx_SUPPORTED symbols as necessary. >- >-You can also save a few K by not having text error messages in the library; >-the standard error message table occupies about 5Kb. This is particularly >-reasonable for embedded applications where there's no good way to display >-a message anyway. To do this, remove the creation of the message table >-(jpeg_std_message_table[]) from jerror.c, and alter format_message to do >-something reasonable without it. You could output the numeric value of the >-message code number, for example. If you do this, you can also save a couple >-more K by modifying the TRACEMSn() macros in jerror.h to expand to nothing; >-you don't need trace capability anyway, right? >- >- >-Portability considerations >--------------------------- >- >-The JPEG library has been written to be extremely portable; the sample >-applications cjpeg and djpeg are slightly less so. This section summarizes >-the design goals in this area. (If you encounter any bugs that cause the >-library to be less portable than is claimed here, we'd appreciate hearing >-about them.) >- >-The code works fine on ANSI C, C++, and pre-ANSI C compilers, using any of >-the popular system include file setups, and some not-so-popular ones too. >-See install.doc for configuration procedures. >- >-The code is not dependent on the exact sizes of the C data types. As >-distributed, we make the assumptions that >- char is at least 8 bits wide >- short is at least 16 bits wide >- int is at least 16 bits wide >- long is at least 32 bits wide >-(These are the minimum requirements of the ANSI C standard.) Wider types will >-work fine, although memory may be used inefficiently if char is much larger >-than 8 bits or short is much bigger than 16 bits. The code should work >-equally well with 16- or 32-bit ints. >- >-In a system where these assumptions are not met, you may be able to make the >-code work by modifying the typedefs in jmorecfg.h. However, you will probably >-have difficulty if int is less than 16 bits wide, since references to plain >-int abound in the code. >- >-char can be either signed or unsigned, although the code runs faster if an >-unsigned char type is available. If char is wider than 8 bits, you will need >-to redefine JOCTET and/or provide custom data source/destination managers so >-that JOCTET represents exactly 8 bits of data on external storage. >- >-The JPEG library proper does not assume ASCII representation of characters. >-But some of the image file I/O modules in cjpeg/djpeg do have ASCII >-dependencies in file-header manipulation; so does cjpeg's select_file_type() >-routine. >- >-The JPEG library does not rely heavily on the C library. In particular, C >-stdio is used only by the data source/destination modules and the error >-handler, all of which are application-replaceable. (cjpeg/djpeg are more >-heavily dependent on stdio.) malloc and free are called only from the memory >-manager "back end" module, so you can use a different memory allocator by >-replacing that one file. >- >-The code generally assumes that C names must be unique in the first 15 >-characters. However, global function names can be made unique in the >-first 6 characters by defining NEED_SHORT_EXTERNAL_NAMES. >- >-More info about porting the code may be gleaned by reading jconfig.doc, >-jmorecfg.h, and jinclude.h. >- >- >-Notes for MS-DOS implementors >------------------------------ >- >-The IJG code is designed to work efficiently in 80x86 "small" or "medium" >-memory models (i.e., data pointers are 16 bits unless explicitly declared >-"far"; code pointers can be either size). You may be able to use small >-model to compile cjpeg or djpeg by itself, but you will probably have to use >-medium model for any larger application. This won't make much difference in >-performance. You *will* take a noticeable performance hit if you use a >-large-data memory model (perhaps 10%-25%), and you should avoid "huge" model >-if at all possible. >- >-The JPEG library typically needs 2Kb-3Kb of stack space. It will also >-malloc about 20K-30K of near heap space while executing (and lots of far >-heap, but that doesn't count in this calculation). This figure will vary >-depending on selected operating mode, and to a lesser extent on image size. >-There is also about 5Kb-6Kb of constant data which will be allocated in the >-near data segment (about 4Kb of this is the error message table). >-Thus you have perhaps 20K available for other modules' static data and near >-heap space before you need to go to a larger memory model. The C library's >-static data will account for several K of this, but that still leaves a good >-deal for your needs. (If you are tight on space, you could reduce the sizes >-of the I/O buffers allocated by jdatasrc.c and jdatadst.c, say from 4K to >-1K. Another possibility is to move the error message table to far memory; >-this should be doable with only localized hacking on jerror.c.) >- >-About 2K of the near heap space is "permanent" memory that will not be >-released until you destroy the JPEG object. This is only an issue if you >-save a JPEG object between compression or decompression operations. >- >-Far data space may also be a tight resource when you are dealing with large >-images. The most memory-intensive case is decompression with two-pass color >-quantization, or single-pass quantization to an externally supplied color >-map. This requires a 128Kb color lookup table plus strip buffers amounting >-to about 40 bytes per column for typical sampling ratios (eg, about 25600 >-bytes for a 640-pixel-wide image). You may not be able to process wide >-images if you have large data structures of your own. >- >-Of course, all of these concerns vanish if you use a 32-bit flat-memory-model >-compiler, such as DJGPP or Watcom C. We highly recommend flat model if you >-can use it; the JPEG library is significantly faster in flat model. >only in patch2: >--- a/jpeg/structure.doc >+++ /dev/null >@@ -1,948 +0,0 @@ >-IJG JPEG LIBRARY: SYSTEM ARCHITECTURE >- >-Copyright (C) 1991-1995, Thomas G. Lane. >-This file is part of the Independent JPEG Group's software. >-For conditions of distribution and use, see the accompanying README file. >- >- >-This file provides an overview of the architecture of the IJG JPEG software; >-that is, the functions of the various modules in the system and the interfaces >-between modules. For more precise details about any data structure or calling >-convention, see the include files and comments in the source code. >- >-We assume that the reader is already somewhat familiar with the JPEG standard. >-The README file includes references for learning about JPEG. The file >-libjpeg.doc describes the library from the viewpoint of an application >-programmer using the library; it's best to read that file before this one. >-Also, the file coderules.doc describes the coding style conventions we use. >- >-In this document, JPEG-specific terminology follows the JPEG standard: >- A "component" means a color channel, e.g., Red or Luminance. >- A "sample" is a single component value (i.e., one number in the image data). >- A "coefficient" is a frequency coefficient (a DCT transform output number). >- A "block" is an 8x8 group of samples or coefficients. >- An "MCU" (minimum coded unit) is an interleaved set of blocks of size >- determined by the sampling factors, or a single block in a >- noninterleaved scan. >-We do not use the terms "pixel" and "sample" interchangeably. When we say >-pixel, we mean an element of the full-size image, while a sample is an element >-of the downsampled image. Thus the number of samples may vary across >-components while the number of pixels does not. (This terminology is not used >-rigorously throughout the code, but it is used in places where confusion would >-otherwise result.) >- >- >-*** System features *** >- >-The IJG distribution contains two parts: >- * A subroutine library for JPEG compression and decompression. >- * cjpeg/djpeg, two sample applications that use the library to transform >- JFIF JPEG files to and from several other image formats. >-cjpeg/djpeg are of no great intellectual complexity: they merely add a simple >-command-line user interface and I/O routines for several uncompressed image >-formats. This document concentrates on the library itself. >- >-We desire the library to be capable of supporting all JPEG baseline, extended >-sequential, and progressive DCT processes. Hierarchical processes are not >-supported. >- >-The library does not support the lossless (spatial) JPEG process. Lossless >-JPEG shares little or no code with lossy JPEG, and would normally be used >-without the extensive pre- and post-processing provided by this library. >-We feel that lossless JPEG is better handled by a separate library. >- >-Within these limits, any set of compression parameters allowed by the JPEG >-spec should be readable for decompression. (We can be more restrictive about >-what formats we can generate.) Although the system design allows for all >-parameter values, some uncommon settings are not yet implemented and may >-never be; nonintegral sampling ratios are the prime example. Furthermore, >-we treat 8-bit vs. 12-bit data precision as a compile-time switch, not a >-run-time option, because most machines can store 8-bit pixels much more >-compactly than 12-bit. >- >-For legal reasons, JPEG arithmetic coding is not currently supported, but >-extending the library to include it would be straightforward. >- >-By itself, the library handles only interchange JPEG datastreams --- in >-particular the widely used JFIF file format. The library can be used by >-surrounding code to process interchange or abbreviated JPEG datastreams that >-are embedded in more complex file formats. (For example, libtiff uses this >-library to implement JPEG compression within the TIFF file format.) >- >-The library includes a substantial amount of code that is not covered by the >-JPEG standard but is necessary for typical applications of JPEG. These >-functions preprocess the image before JPEG compression or postprocess it after >-decompression. They include colorspace conversion, downsampling/upsampling, >-and color quantization. This code can be omitted if not needed. >- >-A wide range of quality vs. speed tradeoffs are possible in JPEG processing, >-and even more so in decompression postprocessing. The decompression library >-provides multiple implementations that cover most of the useful tradeoffs, >-ranging from very-high-quality down to fast-preview operation. On the >-compression side we have generally not provided low-quality choices, since >-compression is normally less time-critical. It should be understood that the >-low-quality modes may not meet the JPEG standard's accuracy requirements; >-nonetheless, they are useful for viewers. >- >- >-*** Portability issues *** >- >-Portability is an essential requirement for the library. The key portability >-issues that show up at the level of system architecture are: >- >-1. Memory usage. We want the code to be able to run on PC-class machines >-with limited memory. Images should therefore be processed sequentially (in >-strips), to avoid holding the whole image in memory at once. Where a >-full-image buffer is necessary, we should be able to use either virtual memory >-or temporary files. >- >-2. Near/far pointer distinction. To run efficiently on 80x86 machines, the >-code should distinguish "small" objects (kept in near data space) from >-"large" ones (kept in far data space). This is an annoying restriction, but >-fortunately it does not impact code quality for less brain-damaged machines, >-and the source code clutter turns out to be minimal with sufficient use of >-pointer typedefs. >- >-3. Data precision. We assume that "char" is at least 8 bits, "short" and >-"int" at least 16, "long" at least 32. The code will work fine with larger >-data sizes, although memory may be used inefficiently in some cases. However, >-the JPEG compressed datastream must ultimately appear on external storage as a >-sequence of 8-bit bytes if it is to conform to the standard. This may pose a >-problem on machines where char is wider than 8 bits. The library represents >-compressed data as an array of values of typedef JOCTET. If no data type >-exactly 8 bits wide is available, custom data source and data destination >-modules must be written to unpack and pack the chosen JOCTET datatype into >-8-bit external representation. >- >- >-*** System overview *** >- >-The compressor and decompressor are each divided into two main sections: >-the JPEG compressor or decompressor proper, and the preprocessing or >-postprocessing functions. The interface between these two sections is the >-image data that the official JPEG spec regards as its input or output: this >-data is in the colorspace to be used for compression, and it is downsampled >-to the sampling factors to be used. The preprocessing and postprocessing >-steps are responsible for converting a normal image representation to or from >-this form. (Those few applications that want to deal with YCbCr downsampled >-data can skip the preprocessing or postprocessing step.) >- >-Looking more closely, the compressor library contains the following main >-elements: >- >- Preprocessing: >- * Color space conversion (e.g., RGB to YCbCr). >- * Edge expansion and downsampling. Optionally, this step can do simple >- smoothing --- this is often helpful for low-quality source data. >- JPEG proper: >- * MCU assembly, DCT, quantization. >- * Entropy coding (sequential or progressive, Huffman or arithmetic). >- >-In addition to these modules we need overall control, marker generation, >-and support code (memory management & error handling). There is also a >-module responsible for physically writing the output data --- typically >-this is just an interface to fwrite(), but some applications may need to >-do something else with the data. >- >-The decompressor library contains the following main elements: >- >- JPEG proper: >- * Entropy decoding (sequential or progressive, Huffman or arithmetic). >- * Dequantization, inverse DCT, MCU disassembly. >- Postprocessing: >- * Upsampling. Optionally, this step may be able to do more general >- rescaling of the image. >- * Color space conversion (e.g., YCbCr to RGB). This step may also >- provide gamma adjustment [ currently it does not ]. >- * Optional color quantization (e.g., reduction to 256 colors). >- * Optional color precision reduction (e.g., 24-bit to 15-bit color). >- [This feature is not currently implemented.] >- >-We also need overall control, marker parsing, and a data source module. >-The support code (memory management & error handling) can be shared with >-the compression half of the library. >- >-There may be several implementations of each of these elements, particularly >-in the decompressor, where a wide range of speed/quality tradeoffs is very >-useful. It must be understood that some of the best speedups involve >-merging adjacent steps in the pipeline. For example, upsampling, color space >-conversion, and color quantization might all be done at once when using a >-low-quality ordered-dither technique. The system architecture is designed to >-allow such merging where appropriate. >- >- >-Note: it is convenient to regard edge expansion (padding to block boundaries) >-as a preprocessing/postprocessing function, even though the JPEG spec includes >-it in compression/decompression. We do this because downsampling/upsampling >-can be simplified a little if they work on padded data: it's not necessary to >-have special cases at the right and bottom edges. Therefore the interface >-buffer is always an integral number of blocks wide and high, and we expect >-compression preprocessing to pad the source data properly. Padding will occur >-only to the next block (8-sample) boundary. In an interleaved-scan situation, >-additional dummy blocks may be used to fill out MCUs, but the MCU assembly and >-disassembly logic will create or discard these blocks internally. (This is >-advantageous for speed reasons, since we avoid DCTing the dummy blocks. >-It also permits a small reduction in file size, because the compressor can >-choose dummy block contents so as to minimize their size in compressed form. >-Finally, it makes the interface buffer specification independent of whether >-the file is actually interleaved or not.) Applications that wish to deal >-directly with the downsampled data must provide similar buffering and padding >-for odd-sized images. >- >- >-*** Poor man's object-oriented programming *** >- >-It should be clear by now that we have a lot of quasi-independent processing >-steps, many of which have several possible behaviors. To avoid cluttering the >-code with lots of switch statements, we use a simple form of object-style >-programming to separate out the different possibilities. >- >-For example, two different color quantization algorithms could be implemented >-as two separate modules that present the same external interface; at runtime, >-the calling code will access the proper module indirectly through an "object". >- >-We can get the limited features we need while staying within portable C. >-The basic tool is a function pointer. An "object" is just a struct >-containing one or more function pointer fields, each of which corresponds to >-a method name in real object-oriented languages. During initialization we >-fill in the function pointers with references to whichever module we have >-determined we need to use in this run. Then invocation of the module is done >-by indirecting through a function pointer; on most machines this is no more >-expensive than a switch statement, which would be the only other way of >-making the required run-time choice. The really significant benefit, of >-course, is keeping the source code clean and well structured. >- >-We can also arrange to have private storage that varies between different >-implementations of the same kind of object. We do this by making all the >-module-specific object structs be separately allocated entities, which will >-be accessed via pointers in the master compression or decompression struct. >-The "public" fields or methods for a given kind of object are specified by >-a commonly known struct. But a module's initialization code can allocate >-a larger struct that contains the common struct as its first member, plus >-additional private fields. With appropriate pointer casting, the module's >-internal functions can access these private fields. (For a simple example, >-see jdatadst.c, which implements the external interface specified by struct >-jpeg_destination_mgr, but adds extra fields.) >- >-(Of course this would all be a lot easier if we were using C++, but we are >-not yet prepared to assume that everyone has a C++ compiler.) >- >-An important benefit of this scheme is that it is easy to provide multiple >-versions of any method, each tuned to a particular case. While a lot of >-precalculation might be done to select an optimal implementation of a method, >-the cost per invocation is constant. For example, the upsampling step might >-have a "generic" method, plus one or more "hardwired" methods for the most >-popular sampling factors; the hardwired methods would be faster because they'd >-use straight-line code instead of for-loops. The cost to determine which >-method to use is paid only once, at startup, and the selection criteria are >-hidden from the callers of the method. >- >-This plan differs a little bit from usual object-oriented structures, in that >-only one instance of each object class will exist during execution. The >-reason for having the class structure is that on different runs we may create >-different instances (choose to execute different modules). You can think of >-the term "method" as denoting the common interface presented by a particular >-set of interchangeable functions, and "object" as denoting a group of related >-methods, or the total shared interface behavior of a group of modules. >- >- >-*** Overall control structure *** >- >-We previously mentioned the need for overall control logic in the compression >-and decompression libraries. In IJG implementations prior to v5, overall >-control was mostly provided by "pipeline control" modules, which proved to be >-large, unwieldy, and hard to understand. To improve the situation, the >-control logic has been subdivided into multiple modules. The control modules >-consist of: >- >-1. Master control for module selection and initialization. This has two >-responsibilities: >- >- 1A. Startup initialization at the beginning of image processing. >- The individual processing modules to be used in this run are selected >- and given initialization calls. >- >- 1B. Per-pass control. This determines how many passes will be performed >- and calls each active processing module to configure itself >- appropriately at the beginning of each pass. End-of-pass processing, >- where necessary, is also invoked from the master control module. >- >- Method selection is partially distributed, in that a particular processing >- module may contain several possible implementations of a particular method, >- which it will select among when given its initialization call. The master >- control code need only be concerned with decisions that affect more than >- one module. >- >-2. Data buffering control. A separate control module exists for each >- inter-processing-step data buffer. This module is responsible for >- invoking the processing steps that write or read that data buffer. >- >-Each buffer controller sees the world as follows: >- >-input data => processing step A => buffer => processing step B => output data >- | | | >- ------------------ controller ------------------ >- >-The controller knows the dataflow requirements of steps A and B: how much data >-they want to accept in one chunk and how much they output in one chunk. Its >-function is to manage its buffer and call A and B at the proper times. >- >-A data buffer control module may itself be viewed as a processing step by a >-higher-level control module; thus the control modules form a binary tree with >-elementary processing steps at the leaves of the tree. >- >-The control modules are objects. A considerable amount of flexibility can >-be had by replacing implementations of a control module. For example: >-* Merging of adjacent steps in the pipeline is done by replacing a control >- module and its pair of processing-step modules with a single processing- >- step module. (Hence the possible merges are determined by the tree of >- control modules.) >-* In some processing modes, a given interstep buffer need only be a "strip" >- buffer large enough to accommodate the desired data chunk sizes. In other >- modes, a full-image buffer is needed and several passes are required. >- The control module determines which kind of buffer is used and manipulates >- virtual array buffers as needed. One or both processing steps may be >- unaware of the multi-pass behavior. >- >-In theory, we might be able to make all of the data buffer controllers >-interchangeable and provide just one set of implementations for all. In >-practice, each one contains considerable special-case processing for its >-particular job. The buffer controller concept should be regarded as an >-overall system structuring principle, not as a complete description of the >-task performed by any one controller. >- >- >-*** Compression object structure *** >- >-Here is a sketch of the logical structure of the JPEG compression library: >- >- |-- Colorspace conversion >- |-- Preprocessing controller --| >- | |-- Downsampling >-Main controller --| >- | |-- Forward DCT, quantize >- |-- Coefficient controller --| >- |-- Entropy encoding >- >-This sketch also describes the flow of control (subroutine calls) during >-typical image data processing. Each of the components shown in the diagram is >-an "object" which may have several different implementations available. One >-or more source code files contain the actual implementation(s) of each object. >- >-The objects shown above are: >- >-* Main controller: buffer controller for the subsampled-data buffer, which >- holds the preprocessed input data. This controller invokes preprocessing to >- fill the subsampled-data buffer, and JPEG compression to empty it. There is >- usually no need for a full-image buffer here; a strip buffer is adequate. >- >-* Preprocessing controller: buffer controller for the downsampling input data >- buffer, which lies between colorspace conversion and downsampling. Note >- that a unified conversion/downsampling module would probably replace this >- controller entirely. >- >-* Colorspace conversion: converts application image data into the desired >- JPEG color space; also changes the data from pixel-interleaved layout to >- separate component planes. Processes one pixel row at a time. >- >-* Downsampling: performs reduction of chroma components as required. >- Optionally may perform pixel-level smoothing as well. Processes a "row >- group" at a time, where a row group is defined as Vmax pixel rows of each >- component before downsampling, and Vk sample rows afterwards (remember Vk >- differs across components). Some downsampling or smoothing algorithms may >- require context rows above and below the current row group; the >- preprocessing controller is responsible for supplying these rows via proper >- buffering. The downsampler is responsible for edge expansion at the right >- edge (i.e., extending each sample row to a multiple of 8 samples); but the >- preprocessing controller is responsible for vertical edge expansion (i.e., >- duplicating the bottom sample row as needed to make a multiple of 8 rows). >- >-* Coefficient controller: buffer controller for the DCT-coefficient data. >- This controller handles MCU assembly, including insertion of dummy DCT >- blocks when needed at the right or bottom edge. When performing >- Huffman-code optimization or emitting a multiscan JPEG file, this >- controller is responsible for buffering the full image. The equivalent of >- one fully interleaved MCU row of subsampled data is processed per call, >- even when the JPEG file is noninterleaved. >- >-* Forward DCT and quantization: Perform DCT, quantize, and emit coefficients. >- Works on one or more DCT blocks at a time. (Note: the coefficients are now >- emitted in normal array order, which the entropy encoder is expected to >- convert to zigzag order as necessary. Prior versions of the IJG code did >- the conversion to zigzag order within the quantization step.) >- >-* Entropy encoding: Perform Huffman or arithmetic entropy coding and emit the >- coded data to the data destination module. Works on one MCU per call. >- For progressive JPEG, the same DCT blocks are fed to the entropy coder >- during each pass, and the coder must emit the appropriate subset of >- coefficients. >- >-In addition to the above objects, the compression library includes these >-objects: >- >-* Master control: determines the number of passes required, controls overall >- and per-pass initialization of the other modules. >- >-* Marker writing: generates JPEG markers (except for RSTn, which is emitted >- by the entropy encoder when needed). >- >-* Data destination manager: writes the output JPEG datastream to its final >- destination (e.g., a file). The destination manager supplied with the >- library knows how to write to a stdio stream; for other behaviors, the >- surrounding application may provide its own destination manager. >- >-* Memory manager: allocates and releases memory, controls virtual arrays >- (with backing store management, where required). >- >-* Error handler: performs formatting and output of error and trace messages; >- determines handling of nonfatal errors. The surrounding application may >- override some or all of this object's methods to change error handling. >- >-* Progress monitor: supports output of "percent-done" progress reports. >- This object represents an optional callback to the surrounding application: >- if wanted, it must be supplied by the application. >- >-The error handler, destination manager, and progress monitor objects are >-defined as separate objects in order to simplify application-specific >-customization of the JPEG library. A surrounding application may override >-individual methods or supply its own all-new implementation of one of these >-objects. The object interfaces for these objects are therefore treated as >-part of the application interface of the library, whereas the other objects >-are internal to the library. >- >-The error handler and memory manager are shared by JPEG compression and >-decompression; the progress monitor, if used, may be shared as well. >- >- >-*** Decompression object structure *** >- >-Here is a sketch of the logical structure of the JPEG decompression library: >- >- |-- Entropy decoding >- |-- Coefficient controller --| >- | |-- Dequantize, Inverse DCT >-Main controller --| >- | |-- Upsampling >- |-- Postprocessing controller --| |-- Colorspace conversion >- |-- Color quantization >- |-- Color precision reduction >- >-As before, this diagram also represents typical control flow. The objects >-shown are: >- >-* Main controller: buffer controller for the subsampled-data buffer, which >- holds the output of JPEG decompression proper. This controller's primary >- task is to feed the postprocessing procedure. Some upsampling algorithms >- may require context rows above and below the current row group; when this >- is true, the main controller is responsible for managing its buffer so as >- to make context rows available. In the current design, the main buffer is >- always a strip buffer; a full-image buffer is never required. >- >-* Coefficient controller: buffer controller for the DCT-coefficient data. >- This controller handles MCU disassembly, including deletion of any dummy >- DCT blocks at the right or bottom edge. When reading a multiscan JPEG >- file, this controller is responsible for buffering the full image. >- (Buffering DCT coefficients, rather than samples, is necessary to support >- progressive JPEG.) The equivalent of one fully interleaved MCU row of >- subsampled data is processed per call, even when the source JPEG file is >- noninterleaved. >- >-* Entropy decoding: Read coded data from the data source module and perform >- Huffman or arithmetic entropy decoding. Works on one MCU per call. >- For progressive JPEG decoding, the coefficient controller supplies the prior >- coefficients of each MCU (initially all zeroes), which the entropy decoder >- modifies in each scan. >- >-* Dequantization and inverse DCT: like it says. Note that the coefficients >- buffered by the coefficient controller have NOT been dequantized; we >- merge dequantization and inverse DCT into a single step for speed reasons. >- When scaled-down output is asked for, simplified DCT algorithms may be used >- that emit only 1x1, 2x2, or 4x4 samples per DCT block, not the full 8x8. >- Works on one DCT block at a time. >- >-* Postprocessing controller: buffer controller for the color quantization >- input buffer, when quantization is in use. (Without quantization, this >- controller just calls the upsampler.) For two-pass quantization, this >- controller is responsible for buffering the full-image data. >- >-* Upsampling: restores chroma components to full size. (May support more >- general output rescaling, too. Note that if undersized DCT outputs have >- been emitted by the DCT module, this module must adjust so that properly >- sized outputs are created.) Works on one row group at a time. This module >- also calls the color conversion module, so its top level is effectively a >- buffer controller for the upsampling->color conversion buffer. However, in >- all but the highest-quality operating modes, upsampling and color >- conversion are likely to be merged into a single step. >- >-* Colorspace conversion: convert from JPEG color space to output color space, >- and change data layout from separate component planes to pixel-interleaved. >- Works on one pixel row at a time. >- >-* Color quantization: reduce the data to colormapped form, using either an >- externally specified colormap or an internally generated one. This module >- is not used for full-color output. Works on one pixel row at a time; may >- require two passes to generate a color map. Note that the output will >- always be a single component representing colormap indexes. In the current >- design, the output values are JSAMPLEs, so an 8-bit compilation cannot >- quantize to more than 256 colors. This is unlikely to be a problem in >- practice. >- >-* Color reduction: this module handles color precision reduction, e.g., >- generating 15-bit color (5 bits/primary) from JPEG's 24-bit output. >- Not quite clear yet how this should be handled... should we merge it with >- colorspace conversion??? >- >-Note that some high-speed operating modes might condense the entire >-postprocessing sequence to a single module (upsample, color convert, and >-quantize in one step). >- >-In addition to the above objects, the decompression library includes these >-objects: >- >-* Master control: determines the number of passes required, controls overall >- and per-pass initialization of the other modules. This is subdivided into >- input and output control: jdinput.c controls only input-side processing, >- while jdmaster.c handles overall initialization and output-side control. >- >-* Marker reading: decodes JPEG markers (except for RSTn). >- >-* Data source manager: supplies the input JPEG datastream. The source >- manager supplied with the library knows how to read from a stdio stream; >- for other behaviors, the surrounding application may provide its own source >- manager. >- >-* Memory manager: same as for compression library. >- >-* Error handler: same as for compression library. >- >-* Progress monitor: same as for compression library. >- >-As with compression, the data source manager, error handler, and progress >-monitor are candidates for replacement by a surrounding application. >- >- >-*** Decompression input and output separation *** >- >-To support efficient incremental display of progressive JPEG files, the >-decompressor is divided into two sections that can run independently: >- >-1. Data input includes marker parsing, entropy decoding, and input into the >- coefficient controller's DCT coefficient buffer. Note that this >- processing is relatively cheap and fast. >- >-2. Data output reads from the DCT coefficient buffer and performs the IDCT >- and all postprocessing steps. >- >-For a progressive JPEG file, the data input processing is allowed to get >-arbitrarily far ahead of the data output processing. (This occurs only >-if the application calls jpeg_consume_input(); otherwise input and output >-run in lockstep, since the input section is called only when the output >-section needs more data.) In this way the application can avoid making >-extra display passes when data is arriving faster than the display pass >-can run. Furthermore, it is possible to abort an output pass without >-losing anything, since the coefficient buffer is read-only as far as the >-output section is concerned. See libjpeg.doc for more detail. >- >-A full-image coefficient array is only created if the JPEG file has multiple >-scans (or if the application specifies buffered-image mode anyway). When >-reading a single-scan file, the coefficient controller normally creates only >-a one-MCU buffer, so input and output processing must run in lockstep in this >-case. jpeg_consume_input() is effectively a no-op in this situation. >- >-The main impact of dividing the decompressor in this fashion is that we must >-be very careful with shared variables in the cinfo data structure. Each >-variable that can change during the course of decompression must be >-classified as belonging to data input or data output, and each section must >-look only at its own variables. For example, the data output section may not >-depend on any of the variables that describe the current scan in the JPEG >-file, because these may change as the data input section advances into a new >-scan. >- >-The progress monitor is (somewhat arbitrarily) defined to treat input of the >-file as one pass when buffered-image mode is not used, and to ignore data >-input work completely when buffered-image mode is used. Note that the >-library has no reliable way to predict the number of passes when dealing >-with a progressive JPEG file, nor can it predict the number of output passes >-in buffered-image mode. So the work estimate is inherently bogus anyway. >- >-No comparable division is currently made in the compression library, because >-there isn't any real need for it. >- >- >-*** Data formats *** >- >-Arrays of pixel sample values use the following data structure: >- >- typedef something JSAMPLE; a pixel component value, 0..MAXJSAMPLE >- typedef JSAMPLE *JSAMPROW; ptr to a row of samples >- typedef JSAMPROW *JSAMPARRAY; ptr to a list of rows >- typedef JSAMPARRAY *JSAMPIMAGE; ptr to a list of color-component arrays >- >-The basic element type JSAMPLE will typically be one of unsigned char, >-(signed) char, or short. Short will be used if samples wider than 8 bits are >-to be supported (this is a compile-time option). Otherwise, unsigned char is >-used if possible. If the compiler only supports signed chars, then it is >-necessary to mask off the value when reading. Thus, all reads of JSAMPLE >-values must be coded as "GETJSAMPLE(value)", where the macro will be defined >-as "((value) & 0xFF)" on signed-char machines and "((int) (value))" elsewhere. >- >-With these conventions, JSAMPLE values can be assumed to be >= 0. This helps >-simplify correct rounding during downsampling, etc. The JPEG standard's >-specification that sample values run from -128..127 is accommodated by >-subtracting 128 just as the sample value is copied into the source array for >-the DCT step (this will be an array of signed ints). Similarly, during >-decompression the output of the IDCT step will be immediately shifted back to >-0..255. (NB: different values are required when 12-bit samples are in use. >-The code is written in terms of MAXJSAMPLE and CENTERJSAMPLE, which will be >-defined as 255 and 128 respectively in an 8-bit implementation, and as 4095 >-and 2048 in a 12-bit implementation.) >- >-We use a pointer per row, rather than a two-dimensional JSAMPLE array. This >-choice costs only a small amount of memory and has several benefits: >-* Code using the data structure doesn't need to know the allocated width of >- the rows. This simplifies edge expansion/compression, since we can work >- in an array that's wider than the logical picture width. >-* Indexing doesn't require multiplication; this is a performance win on many >- machines. >-* Arrays with more than 64K total elements can be supported even on machines >- where malloc() cannot allocate chunks larger than 64K. >-* The rows forming a component array may be allocated at different times >- without extra copying. This trick allows some speedups in smoothing steps >- that need access to the previous and next rows. >- >-Note that each color component is stored in a separate array; we don't use the >-traditional layout in which the components of a pixel are stored together. >-This simplifies coding of modules that work on each component independently, >-because they don't need to know how many components there are. Furthermore, >-we can read or write each component to a temporary file independently, which >-is helpful when dealing with noninterleaved JPEG files. >- >-In general, a specific sample value is accessed by code such as >- GETJSAMPLE(image[colorcomponent][row][col]) >-where col is measured from the image left edge, but row is measured from the >-first sample row currently in memory. Either of the first two indexings can >-be precomputed by copying the relevant pointer. >- >- >-Since most image-processing applications prefer to work on images in which >-the components of a pixel are stored together, the data passed to or from the >-surrounding application uses the traditional convention: a single pixel is >-represented by N consecutive JSAMPLE values, and an image row is an array of >-(# of color components)*(image width) JSAMPLEs. One or more rows of data can >-be represented by a pointer of type JSAMPARRAY in this scheme. This scheme is >-converted to component-wise storage inside the JPEG library. (Applications >-that want to skip JPEG preprocessing or postprocessing will have to contend >-with component-wise storage.) >- >- >-Arrays of DCT-coefficient values use the following data structure: >- >- typedef short JCOEF; a 16-bit signed integer >- typedef JCOEF JBLOCK[DCTSIZE2]; an 8x8 block of coefficients >- typedef JBLOCK *JBLOCKROW; ptr to one horizontal row of 8x8 blocks >- typedef JBLOCKROW *JBLOCKARRAY; ptr to a list of such rows >- typedef JBLOCKARRAY *JBLOCKIMAGE; ptr to a list of color component arrays >- >-The underlying type is at least a 16-bit signed integer; while "short" is big >-enough on all machines of interest, on some machines it is preferable to use >-"int" for speed reasons, despite the storage cost. Coefficients are grouped >-into 8x8 blocks (but we always use #defines DCTSIZE and DCTSIZE2 rather than >-"8" and "64"). >- >-The contents of a coefficient block may be in either "natural" or zigzagged >-order, and may be true values or divided by the quantization coefficients, >-depending on where the block is in the processing pipeline. In the current >-library, coefficient blocks are kept in natural order everywhere; the entropy >-codecs zigzag or dezigzag the data as it is written or read. The blocks >-contain quantized coefficients everywhere outside the DCT/IDCT subsystems. >-(This latter decision may need to be revisited to support variable >-quantization a la JPEG Part 3.) >- >-Notice that the allocation unit is now a row of 8x8 blocks, corresponding to >-eight rows of samples. Otherwise the structure is much the same as for >-samples, and for the same reasons. >- >-On machines where malloc() can't handle a request bigger than 64Kb, this data >-structure limits us to rows of less than 512 JBLOCKs, or a picture width of >-4000+ pixels. This seems an acceptable restriction. >- >- >-On 80x86 machines, the bottom-level pointer types (JSAMPROW and JBLOCKROW) >-must be declared as "far" pointers, but the upper levels can be "near" >-(implying that the pointer lists are allocated in the DS segment). >-We use a #define symbol FAR, which expands to the "far" keyword when >-compiling on 80x86 machines and to nothing elsewhere. >- >- >-*** Suspendable processing *** >- >-In some applications it is desirable to use the JPEG library as an >-incremental, memory-to-memory filter. In this situation the data source or >-destination may be a limited-size buffer, and we can't rely on being able to >-empty or refill the buffer at arbitrary times. Instead the application would >-like to have control return from the library at buffer overflow/underrun, and >-then resume compression or decompression at a later time. >- >-This scenario is supported for simple cases. (For anything more complex, we >-recommend that the application "bite the bullet" and develop real multitasking >-capability.) The libjpeg.doc file goes into more detail about the usage and >-limitations of this capability; here we address the implications for library >-structure. >- >-The essence of the problem is that the entropy codec (coder or decoder) must >-be prepared to stop at arbitrary times. In turn, the controllers that call >-the entropy codec must be able to stop before having produced or consumed all >-the data that they normally would handle in one call. That part is reasonably >-straightforward: we make the controller call interfaces include "progress >-counters" which indicate the number of data chunks successfully processed, and >-we require callers to test the counter rather than just assume all of the data >-was processed. >- >-Rather than trying to restart at an arbitrary point, the current Huffman >-codecs are designed to restart at the beginning of the current MCU after a >-suspension due to buffer overflow/underrun. At the start of each call, the >-codec's internal state is loaded from permanent storage (in the JPEG object >-structures) into local variables. On successful completion of the MCU, the >-permanent state is updated. (This copying is not very expensive, and may even >-lead to *improved* performance if the local variables can be registerized.) >-If a suspension occurs, the codec simply returns without updating the state, >-thus effectively reverting to the start of the MCU. Note that this implies >-leaving some data unprocessed in the source/destination buffer (ie, the >-compressed partial MCU). The data source/destination module interfaces are >-specified so as to make this possible. This also implies that the data buffer >-must be large enough to hold a worst-case compressed MCU; a couple thousand >-bytes should be enough. >- >-In a successive-approximation AC refinement scan, the progressive Huffman >-decoder has to be able to undo assignments of newly nonzero coefficients if it >-suspends before the MCU is complete, since decoding requires distinguishing >-previously-zero and previously-nonzero coefficients. This is a bit tedious >-but probably won't have much effect on performance. Other variants of Huffman >-decoding need not worry about this, since they will just store the same values >-again if forced to repeat the MCU. >- >-This approach would probably not work for an arithmetic codec, since its >-modifiable state is quite large and couldn't be copied cheaply. Instead it >-would have to suspend and resume exactly at the point of the buffer end. >- >-The JPEG marker reader is designed to cope with suspension at an arbitrary >-point. It does so by backing up to the start of the marker parameter segment, >-so the data buffer must be big enough to hold the largest marker of interest. >-Again, a couple KB should be adequate. (A special "skip" convention is used >-to bypass COM and APPn markers, so these can be larger than the buffer size >-without causing problems; otherwise a 64K buffer would be needed in the worst >-case.) >- >-The JPEG marker writer currently does *not* cope with suspension. I feel that >-this is not necessary; it is much easier simply to require the application to >-ensure there is enough buffer space before starting. (An empty 2K buffer is >-more than sufficient for the header markers; and ensuring there are a dozen or >-two bytes available before calling jpeg_finish_compress() will suffice for the >-trailer.) This would not work for writing multi-scan JPEG files, but >-we simply do not intend to support that capability with suspension. >- >- >-*** Memory manager services *** >- >-The JPEG library's memory manager controls allocation and deallocation of >-memory, and it manages large "virtual" data arrays on machines where the >-operating system does not provide virtual memory. Note that the same >-memory manager serves both compression and decompression operations. >- >-In all cases, allocated objects are tied to a particular compression or >-decompression master record, and they will be released when that master >-record is destroyed. >- >-The memory manager does not provide explicit deallocation of objects. >-Instead, objects are created in "pools" of free storage, and a whole pool >-can be freed at once. This approach helps prevent storage-leak bugs, and >-it speeds up operations whenever malloc/free are slow (as they often are). >-The pools can be regarded as lifetime identifiers for objects. Two >-pools/lifetimes are defined: >- * JPOOL_PERMANENT lasts until master record is destroyed >- * JPOOL_IMAGE lasts until done with image (JPEG datastream) >-Permanent lifetime is used for parameters and tables that should be carried >-across from one datastream to another; this includes all application-visible >-parameters. Image lifetime is used for everything else. (A third lifetime, >-JPOOL_PASS = one processing pass, was originally planned. However it was >-dropped as not being worthwhile. The actual usage patterns are such that the >-peak memory usage would be about the same anyway; and having per-pass storage >-substantially complicates the virtual memory allocation rules --- see below.) >- >-The memory manager deals with three kinds of object: >-1. "Small" objects. Typically these require no more than 10K-20K total. >-2. "Large" objects. These may require tens to hundreds of K depending on >- image size. Semantically they behave the same as small objects, but we >- distinguish them for two reasons: >- * On MS-DOS machines, large objects are referenced by FAR pointers, >- small objects by NEAR pointers. >- * Pool allocation heuristics may differ for large and small objects. >- Note that individual "large" objects cannot exceed the size allowed by >- type size_t, which may be 64K or less on some machines. >-3. "Virtual" objects. These are large 2-D arrays of JSAMPLEs or JBLOCKs >- (typically large enough for the entire image being processed). The >- memory manager provides stripwise access to these arrays. On machines >- without virtual memory, the rest of the array may be swapped out to a >- temporary file. >- >-(Note: JSAMPARRAY and JBLOCKARRAY data structures are a combination of large >-objects for the data proper and small objects for the row pointers. For >-convenience and speed, the memory manager provides single routines to create >-these structures. Similarly, virtual arrays include a small control block >-and a JSAMPARRAY or JBLOCKARRAY working buffer, all created with one call.) >- >-In the present implementation, virtual arrays are only permitted to have image >-lifespan. (Permanent lifespan would not be reasonable, and pass lifespan is >-not very useful since a virtual array's raison d'etre is to store data for >-multiple passes through the image.) We also expect that only "small" objects >-will be given permanent lifespan, though this restriction is not required by >-the memory manager. >- >-In a non-virtual-memory machine, some performance benefit can be gained by >-making the in-memory buffers for virtual arrays be as large as possible. >-(For small images, the buffers might fit entirely in memory, so blind >-swapping would be very wasteful.) The memory manager will adjust the height >-of the buffers to fit within a prespecified maximum memory usage. In order >-to do this in a reasonably optimal fashion, the manager needs to allocate all >-of the virtual arrays at once. Therefore, there isn't a one-step allocation >-routine for virtual arrays; instead, there is a "request" routine that simply >-allocates the control block, and a "realize" routine (called just once) that >-determines space allocation and creates all of the actual buffers. The >-realize routine must allow for space occupied by non-virtual large objects. >-(We don't bother to factor in the space needed for small objects, on the >-grounds that it isn't worth the trouble.) >- >-To support all this, we establish the following protocol for doing business >-with the memory manager: >- 1. Modules must request virtual arrays (which may have only image lifespan) >- during the initial setup phase, i.e., in their jinit_xxx routines. >- 2. All "large" objects (including JSAMPARRAYs and JBLOCKARRAYs) must also be >- allocated during initial setup. >- 3. realize_virt_arrays will be called at the completion of initial setup. >- The above conventions ensure that sufficient information is available >- for it to choose a good size for virtual array buffers. >-Small objects of any lifespan may be allocated at any time. We expect that >-the total space used for small objects will be small enough to be negligible >-in the realize_virt_arrays computation. >- >-In a virtual-memory machine, we simply pretend that the available space is >-infinite, thus causing realize_virt_arrays to decide that it can allocate all >-the virtual arrays as full-size in-memory buffers. The overhead of the >-virtual-array access protocol is very small when no swapping occurs. >- >-A virtual array can be specified to be "pre-zeroed"; when this flag is set, >-never-yet-written sections of the array are set to zero before being made >-available to the caller. If this flag is not set, never-written sections >-of the array contain garbage. (This feature exists primarily because the >-equivalent logic would otherwise be needed in jdcoefct.c for progressive >-JPEG mode; we may as well make it available for possible other uses.) >- >-The first write pass on a virtual array is required to occur in top-to-bottom >-order; read passes, as well as any write passes after the first one, may >-access the array in any order. This restriction exists partly to simplify >-the virtual array control logic, and partly because some file systems may not >-support seeking beyond the current end-of-file in a temporary file. The main >-implication of this restriction is that rearrangement of rows (such as >-converting top-to-bottom data order to bottom-to-top) must be handled while >-reading data out of the virtual array, not while putting it in. >- >- >-*** Memory manager internal structure *** >- >-To isolate system dependencies as much as possible, we have broken the >-memory manager into two parts. There is a reasonably system-independent >-"front end" (jmemmgr.c) and a "back end" that contains only the code >-likely to change across systems. All of the memory management methods >-outlined above are implemented by the front end. The back end provides >-the following routines for use by the front end (none of these routines >-are known to the rest of the JPEG code): >- >-jpeg_mem_init, jpeg_mem_term system-dependent initialization/shutdown >- >-jpeg_get_small, jpeg_free_small interface to malloc and free library routines >- (or their equivalents) >- >-jpeg_get_large, jpeg_free_large interface to FAR malloc/free in MSDOS machines; >- else usually the same as >- jpeg_get_small/jpeg_free_small >- >-jpeg_mem_available estimate available memory >- >-jpeg_open_backing_store create a backing-store object >- >-read_backing_store, manipulate a backing-store object >-write_backing_store, >-close_backing_store >- >-On some systems there will be more than one type of backing-store object >-(specifically, in MS-DOS a backing store file might be an area of extended >-memory as well as a disk file). jpeg_open_backing_store is responsible for >-choosing how to implement a given object. The read/write/close routines >-are method pointers in the structure that describes a given object; this >-lets them be different for different object types. >- >-It may be necessary to ensure that backing store objects are explicitly >-released upon abnormal program termination. For example, MS-DOS won't free >-extended memory by itself. To support this, we will expect the main program >-or surrounding application to arrange to call self_destruct (typically via >-jpeg_destroy) upon abnormal termination. This may require a SIGINT signal >-handler or equivalent. We don't want to have the back end module install its >-own signal handler, because that would pre-empt the surrounding application's >-ability to control signal handling. >- >-The IJG distribution includes several memory manager back end implementations. >-Usually the same back end should be suitable for all applications on a given >-system, but it is possible for an application to supply its own back end at >-need. >- >- >-*** Implications of DNL marker *** >- >-Some JPEG files may use a DNL marker to postpone definition of the image >-height (this would be useful for a fax-like scanner's output, for instance). >-In these files the SOF marker claims the image height is 0, and you only >-find out the true image height at the end of the first scan. >- >-We could read these files as follows: >-1. Upon seeing zero image height, replace it by 65535 (the maximum allowed). >-2. When the DNL is found, update the image height in the global image >- descriptor. >-This implies that control modules must avoid making copies of the image >-height, and must re-test for termination after each MCU row. This would >-be easy enough to do. >- >-In cases where image-size data structures are allocated, this approach will >-result in very inefficient use of virtual memory or much-larger-than-necessary >-temporary files. This seems acceptable for something that probably won't be a >-mainstream usage. People might have to forgo use of memory-hogging options >-(such as two-pass color quantization or noninterleaved JPEG files) if they >-want efficient conversion of such files. (One could improve efficiency by >-demanding a user-supplied upper bound for the height, less than 65536; in most >-cases it could be much less.) >- >-The standard also permits the SOF marker to overestimate the image height, >-with a DNL to give the true, smaller height at the end of the first scan. >-This would solve the space problems if the overestimate wasn't too great. >-However, it implies that you don't even know whether DNL will be used. >- >-This leads to a couple of very serious objections: >-1. Testing for a DNL marker must occur in the inner loop of the decompressor's >- Huffman decoder; this implies a speed penalty whether the feature is used >- or not. >-2. There is no way to hide the last-minute change in image height from an >- application using the decoder. Thus *every* application using the IJG >- library would suffer a complexity penalty whether it cared about DNL or >- not. >-We currently do not support DNL because of these problems. >- >-A different approach is to insist that DNL-using files be preprocessed by a >-separate program that reads ahead to the DNL, then goes back and fixes the SOF >-marker. This is a much simpler solution and is probably far more efficient. >-Even if one wants piped input, buffering the first scan of the JPEG file needs >-a lot smaller temp file than is implied by the maximum-height method. For >-this approach we'd simply treat DNL as a no-op in the decompressor (at most, >-check that it matches the SOF image height). >- >-We will not worry about making the compressor capable of outputting DNL. >-Something similar to the first scheme above could be applied if anyone ever >-wants to make that work. >only in patch2: >--- a/jpeg/usage.doc >+++ /dev/null >@@ -1,562 +0,0 @@ >-USAGE instructions for the Independent JPEG Group's JPEG software >-================================================================= >- >-This file describes usage of the JPEG conversion programs cjpeg and djpeg, >-as well as the utility programs jpegtran, rdjpgcom and wrjpgcom. (See >-the other documentation files if you wish to use the JPEG library within >-your own programs.) >- >-If you are on a Unix machine you may prefer to read the Unix-style manual >-pages in files cjpeg.1, djpeg.1, jpegtran.1, rdjpgcom.1, wrjpgcom.1. >- >- >-INTRODUCTION >- >-These programs implement JPEG image compression and decompression. JPEG >-(pronounced "jay-peg") is a standardized compression method for full-color >-and gray-scale images. JPEG is designed to handle "real-world" scenes, >-for example scanned photographs. Cartoons, line drawings, and other >-non-realistic images are not JPEG's strong suit; on that sort of material >-you may get poor image quality and/or little compression. >- >-JPEG is lossy, meaning that the output image is not necessarily identical to >-the input image. Hence you should not use JPEG if you have to have identical >-output bits. However, on typical real-world images, very good compression >-levels can be obtained with no visible change, and amazingly high compression >-is possible if you can tolerate a low-quality image. You can trade off image >-quality against file size by adjusting the compressor's "quality" setting. >- >- >-GENERAL USAGE >- >-We provide two programs, cjpeg to compress an image file into JPEG format, >-and djpeg to decompress a JPEG file back into a conventional image format. >- >-On Unix-like systems, you say: >- cjpeg [switches] [imagefile] >jpegfile >-or >- djpeg [switches] [jpegfile] >imagefile >-The programs read the specified input file, or standard input if none is >-named. They always write to standard output (with trace/error messages to >-standard error). These conventions are handy for piping images between >-programs. >- >-On most non-Unix systems, you say: >- cjpeg [switches] imagefile jpegfile >-or >- djpeg [switches] jpegfile imagefile >-i.e., both the input and output files are named on the command line. This >-style is a little more foolproof, and it loses no functionality if you don't >-have pipes. (You can get this style on Unix too, if you prefer, by defining >-TWO_FILE_COMMANDLINE when you compile the programs; see install.doc.) >- >-You can also say: >- cjpeg [switches] -outfile jpegfile imagefile >-or >- djpeg [switches] -outfile imagefile jpegfile >-This syntax works on all systems, so it is useful for scripts. >- >-The currently supported image file formats are: PPM (PBMPLUS color format), >-PGM (PBMPLUS gray-scale format), BMP, Targa, and RLE (Utah Raster Toolkit >-format). (RLE is supported only if the URT library is available.) >-cjpeg recognizes the input image format automatically, with the exception >-of some Targa-format files. You have to tell djpeg which format to generate. >- >-JPEG files are in the defacto standard JFIF file format. There are other, >-less widely used JPEG-based file formats, but we don't support them. >- >-All switch names may be abbreviated; for example, -grayscale may be written >--gray or -gr. Most of the "basic" switches can be abbreviated to as little as >-one letter. Upper and lower case are equivalent (-BMP is the same as -bmp). >-British spellings are also accepted (e.g., -greyscale), though for brevity >-these are not mentioned below. >- >- >-CJPEG DETAILS >- >-The basic command line switches for cjpeg are: >- >- -quality N Scale quantization tables to adjust image quality. >- Quality is 0 (worst) to 100 (best); default is 75. >- (See below for more info.) >- >- -grayscale Create monochrome JPEG file from color input. >- Be sure to use this switch when compressing a grayscale >- BMP file, because cjpeg isn't bright enough to notice >- whether a BMP file uses only shades of gray. By >- saying -grayscale, you'll get a smaller JPEG file that >- takes less time to process. >- >- -optimize Perform optimization of entropy encoding parameters. >- Without this, default encoding parameters are used. >- -optimize usually makes the JPEG file a little smaller, >- but cjpeg runs somewhat slower and needs much more >- memory. Image quality and speed of decompression are >- unaffected by -optimize. >- >- -progressive Create progressive JPEG file (see below). >- >- -targa Input file is Targa format. Targa files that contain >- an "identification" field will not be automatically >- recognized by cjpeg; for such files you must specify >- -targa to make cjpeg treat the input as Targa format. >- For most Targa files, you won't need this switch. >- >-The -quality switch lets you trade off compressed file size against quality of >-the reconstructed image: the higher the quality setting, the larger the JPEG >-file, and the closer the output image will be to the original input. Normally >-you want to use the lowest quality setting (smallest file) that decompresses >-into something visually indistinguishable from the original image. For this >-purpose the quality setting should be between 50 and 95; the default of 75 is >-often about right. If you see defects at -quality 75, then go up 5 or 10 >-counts at a time until you are happy with the output image. (The optimal >-setting will vary from one image to another.) >- >--quality 100 will generate a quantization table of all 1's, minimizing loss >-in the quantization step (but there is still information loss in subsampling, >-as well as roundoff error). This setting is mainly of interest for >-experimental purposes. Quality values above about 95 are NOT recommended for >-normal use; the compressed file size goes up dramatically for hardly any gain >-in output image quality. >- >-In the other direction, quality values below 50 will produce very small files >-of low image quality. Settings around 5 to 10 might be useful in preparing an >-index of a large image library, for example. Try -quality 2 (or so) for some >-amusing Cubist effects. (Note: quality values below about 25 generate 2-byte >-quantization tables, which are considered optional in the JPEG standard. >-cjpeg emits a warning message when you give such a quality value, because some >-other JPEG programs may be unable to decode the resulting file. Use -baseline >-if you need to ensure compatibility at low quality values.) >- >-The -progressive switch creates a "progressive JPEG" file. In this type of >-JPEG file, the data is stored in multiple scans of increasing quality. If the >-file is being transmitted over a slow communications link, the decoder can use >-the first scan to display a low-quality image very quickly, and can then >-improve the display with each subsequent scan. The final image is exactly >-equivalent to a standard JPEG file of the same quality setting, and the total >-file size is about the same --- often a little smaller. CAUTION: progressive >-JPEG is not yet widely implemented, so many decoders will be unable to view a >-progressive JPEG file at all. >- >-Switches for advanced users: >- >- -dct int Use integer DCT method (default). >- -dct fast Use fast integer DCT (less accurate). >- -dct float Use floating-point DCT method. >- The float method is very slightly more accurate than >- the int method, but is much slower unless your machine >- has very fast floating-point hardware. Also note that >- results of the floating-point method may vary slightly >- across machines, while the integer methods should give >- the same results everywhere. The fast integer method >- is much less accurate than the other two. >- >- -restart N Emit a JPEG restart marker every N MCU rows, or every >- N MCU blocks if "B" is attached to the number. >- -restart 0 (the default) means no restart markers. >- >- -smooth N Smooth the input image to eliminate dithering noise. >- N, ranging from 1 to 100, indicates the strength of >- smoothing. 0 (the default) means no smoothing. >- >- -maxmemory N Set limit for amount of memory to use in processing >- large images. Value is in thousands of bytes, or >- millions of bytes if "M" is attached to the number. >- For example, -max 4m selects 4000000 bytes. If more >- space is needed, temporary files will be used. >- >- -verbose Enable debug printout. More -v's give more printout. >- or -debug Also, version information is printed at startup. >- >-The -restart option inserts extra markers that allow a JPEG decoder to >-resynchronize after a transmission error. Without restart markers, any damage >-to a compressed file will usually ruin the image from the point of the error >-to the end of the image; with restart markers, the damage is usually confined >-to the portion of the image up to the next restart marker. Of course, the >-restart markers occupy extra space. We recommend -restart 1 for images that >-will be transmitted across unreliable networks such as Usenet. >- >-The -smooth option filters the input to eliminate fine-scale noise. This is >-often useful when converting dithered images to JPEG: a moderate smoothing >-factor of 10 to 50 gets rid of dithering patterns in the input file, resulting >-in a smaller JPEG file and a better-looking image. Too large a smoothing >-factor will visibly blur the image, however. >- >-Switches for wizards: >- >- -baseline Force baseline-compatible quantization tables to be >- generated. This clamps quantization values to 8 bits >- even at low quality settings. (This switch is poorly >- named, since it does not ensure that the output is >- actually baseline JPEG. For example, you can use >- -baseline and -progressive together.) >- >- -qtables file Use the quantization tables given in the specified >- text file. >- >- -qslots N[,...] Select which quantization table to use for each color >- component. >- >- -sample HxV[,...] Set JPEG sampling factors for each color component. >- >- -scans file Use the scan script given in the specified text file. >- >-The "wizard" switches are intended for experimentation with JPEG. If you >-don't know what you are doing, DON'T USE THEM. These switches are documented >-further in the file wizard.doc. >- >- >-DJPEG DETAILS >- >-The basic command line switches for djpeg are: >- >- -colors N Reduce image to at most N colors. This reduces the >- or -quantize N number of colors used in the output image, so that it >- can be displayed on a colormapped display or stored in >- a colormapped file format. For example, if you have >- an 8-bit display, you'd need to reduce to 256 or fewer >- colors. (-colors is the recommended name, -quantize >- is provided only for backwards compatibility.) >- >- -fast Select recommended processing options for fast, low >- quality output. (The default options are chosen for >- highest quality output.) Currently, this is equivalent >- to "-dct fast -nosmooth -onepass -dither ordered". >- >- -grayscale Force gray-scale output even if JPEG file is color. >- Useful for viewing on monochrome displays; also, >- djpeg runs noticeably faster in this mode. >- >- -scale M/N Scale the output image by a factor M/N. Currently >- the scale factor must be 1/1, 1/2, 1/4, or 1/8. >- Scaling is handy if the image is larger than your >- screen; also, djpeg runs much faster when scaling >- down the output. >- >- -bmp Select BMP output format (Windows flavor). 8-bit >- colormapped format is emitted if -colors or -grayscale >- is specified, or if the JPEG file is gray-scale; >- otherwise, 24-bit full-color format is emitted. >- >- -gif Select GIF output format. Since GIF does not support >- more than 256 colors, -colors 256 is assumed (unless >- you specify a smaller number of colors). If you >- specify -fast, the default number of colors is 216. >- >- -os2 Select BMP output format (OS/2 1.x flavor). 8-bit >- colormapped format is emitted if -colors or -grayscale >- is specified, or if the JPEG file is gray-scale; >- otherwise, 24-bit full-color format is emitted. >- >- -pnm Select PBMPLUS (PPM/PGM) output format (this is the >- default format). PGM is emitted if the JPEG file is >- gray-scale or if -grayscale is specified; otherwise >- PPM is emitted. >- >- -rle Select RLE output format. (Requires URT library.) >- >- -targa Select Targa output format. Gray-scale format is >- emitted if the JPEG file is gray-scale or if >- -grayscale is specified; otherwise, colormapped format >- is emitted if -colors is specified; otherwise, 24-bit >- full-color format is emitted. >- >-Switches for advanced users: >- >- -dct int Use integer DCT method (default). >- -dct fast Use fast integer DCT (less accurate). >- -dct float Use floating-point DCT method. >- The float method is very slightly more accurate than >- the int method, but is much slower unless your machine >- has very fast floating-point hardware. Also note that >- results of the floating-point method may vary slightly >- across machines, while the integer methods should give >- the same results everywhere. The fast integer method >- is much less accurate than the other two. >- >- -dither fs Use Floyd-Steinberg dithering in color quantization. >- -dither ordered Use ordered dithering in color quantization. >- -dither none Do not use dithering in color quantization. >- By default, Floyd-Steinberg dithering is applied when >- quantizing colors; this is slow but usually produces >- the best results. Ordered dither is a compromise >- between speed and quality; no dithering is fast but >- usually looks awful. Note that these switches have >- no effect unless color quantization is being done. >- Ordered dither is only available in -onepass mode. >- >- -map FILE Quantize to the colors used in the specified image >- file. This is useful for producing multiple files >- with identical color maps, or for forcing a predefined >- set of colors to be used. The FILE must be a GIF >- or PPM file. This option overrides -colors and >- -onepass. >- >- -nosmooth Use a faster, lower-quality upsampling routine. >- >- -onepass Use one-pass instead of two-pass color quantization. >- The one-pass method is faster and needs less memory, >- but it produces a lower-quality image. -onepass is >- ignored unless you also say -colors N. Also, >- the one-pass method is always used for gray-scale >- output (the two-pass method is no improvement then). >- >- -maxmemory N Set limit for amount of memory to use in processing >- large images. Value is in thousands of bytes, or >- millions of bytes if "M" is attached to the number. >- For example, -max 4m selects 4000000 bytes. If more >- space is needed, temporary files will be used. >- >- -verbose Enable debug printout. More -v's give more printout. >- or -debug Also, version information is printed at startup. >- >- >-HINTS FOR CJPEG >- >-Color GIF files are not the ideal input for JPEG; JPEG is really intended for >-compressing full-color (24-bit) images. In particular, don't try to convert >-cartoons, line drawings, and other images that have only a few distinct >-colors. GIF works great on these, JPEG does not. If you want to convert a >-GIF to JPEG, you should experiment with cjpeg's -quality and -smooth options >-to get a satisfactory conversion. -smooth 10 or so is often helpful. >- >-Avoid running an image through a series of JPEG compression/decompression >-cycles. Image quality loss will accumulate; after ten or so cycles the image >-may be noticeably worse than it was after one cycle. It's best to use a >-lossless format while manipulating an image, then convert to JPEG format when >-you are ready to file the image away. >- >-The -optimize option to cjpeg is worth using when you are making a "final" >-version for posting or archiving. It's also a win when you are using low >-quality settings to make very small JPEG files; the percentage improvement >-is often a lot more than it is on larger files. (At present, -optimize >-mode is always selected when generating progressive JPEG files.) >- >-GIF input files are no longer supported, to avoid the Unisys LZW patent. >-Use a Unisys-licensed program if you need to read a GIF file. (Conversion >-of GIF files to JPEG is usually a bad idea anyway.) >- >- >-HINTS FOR DJPEG >- >-To get a quick preview of an image, use the -grayscale and/or -scale switches. >-"-grayscale -scale 1/8" is the fastest case. >- >-Several options are available that trade off image quality to gain speed. >-"-fast" turns on the recommended settings. >- >-"-dct fast" and/or "-nosmooth" gain speed at a small sacrifice in quality. >-When producing a color-quantized image, "-onepass -dither ordered" is fast but >-much lower quality than the default behavior. "-dither none" may give >-acceptable results in two-pass mode, but is seldom tolerable in one-pass mode. >- >-If you are fortunate enough to have very fast floating point hardware, >-"-dct float" may be even faster than "-dct fast". But on most machines >-"-dct float" is slower than "-dct int"; in this case it is not worth using, >-because its theoretical accuracy advantage is too small to be significant >-in practice. >- >-Two-pass color quantization requires a good deal of memory; on MS-DOS machines >-it may run out of memory even with -maxmemory 0. In that case you can still >-decompress, with some loss of image quality, by specifying -onepass for >-one-pass quantization. >- >-To avoid the Unisys LZW patent, djpeg produces uncompressed GIF files. These >-are larger than they should be, but are readable by standard GIF decoders. >- >- >-HINTS FOR BOTH PROGRAMS >- >-If more space is needed than will fit in the available main memory (as >-determined by -maxmemory), temporary files will be used. (MS-DOS versions >-will try to get extended or expanded memory first.) The temporary files are >-often rather large: in typical cases they occupy three bytes per pixel, for >-example 3*800*600 = 1.44Mb for an 800x600 image. If you don't have enough >-free disk space, leave out -progressive and -optimize (for cjpeg) or specify >--onepass (for djpeg). >- >-On MS-DOS, the temporary files are created in the directory named by the TMP >-or TEMP environment variable, or in the current directory if neither of those >-exist. Amiga implementations put the temp files in the directory named by >-JPEGTMP:, so be sure to assign JPEGTMP: to a disk partition with adequate free >-space. >- >-The default memory usage limit (-maxmemory) is set when the software is >-compiled. If you get an "insufficient memory" error, try specifying a smaller >--maxmemory value, even -maxmemory 0 to use the absolute minimum space. You >-may want to recompile with a smaller default value if this happens often. >- >-On machines that have "environment" variables, you can define the environment >-variable JPEGMEM to set the default memory limit. The value is specified as >-described for the -maxmemory switch. JPEGMEM overrides the default value >-specified when the program was compiled, and itself is overridden by an >-explicit -maxmemory switch. >- >-On MS-DOS machines, -maxmemory is the amount of main (conventional) memory to >-use. (Extended or expanded memory is also used if available.) Most >-DOS-specific versions of this software do their own memory space estimation >-and do not need you to specify -maxmemory. >- >- >-JPEGTRAN >- >-jpegtran performs various useful transformations of JPEG files. >-It can translate the coded representation from one variant of JPEG to another, >-for example from baseline JPEG to progressive JPEG or vice versa. It can also >-perform some rearrangements of the image data, for example turning an image >-from landscape to portrait format by rotation. >- >-jpegtran works by rearranging the compressed data (DCT coefficients), without >-ever fully decoding the image. Therefore, its transformations are lossless: >-there is no image degradation at all, which would not be true if you used >-djpeg followed by cjpeg to accomplish the same conversion. But by the same >-token, jpegtran cannot perform lossy operations such as changing the image >-quality. >- >-jpegtran uses a command line syntax similar to cjpeg or djpeg. >-On Unix-like systems, you say: >- jpegtran [switches] [inputfile] >outputfile >-On most non-Unix systems, you say: >- jpegtran [switches] inputfile outputfile >-where both the input and output files are JPEG files. >- >-To specify the coded JPEG representation used in the output file, >-jpegtran accepts a subset of the switches recognized by cjpeg: >- -optimize Perform optimization of entropy encoding parameters. >- -progressive Create progressive JPEG file. >- -restart N Emit a JPEG restart marker every N MCU rows, or every >- N MCU blocks if "B" is attached to the number. >- -scans file Use the scan script given in the specified text file. >-See the previous discussion of cjpeg for more details about these switches. >-If you specify none of these switches, you get a plain baseline-JPEG output >-file. The quality setting and so forth are determined by the input file. >- >-The image can be losslessly transformed by giving one of these switches: >- -flip horizontal Mirror image horizontally (left-right). >- -flip vertical Mirror image vertically (top-bottom). >- -rotate 90 Rotate image 90 degrees clockwise. >- -rotate 180 Rotate image 180 degrees. >- -rotate 270 Rotate image 270 degrees clockwise (or 90 ccw). >- -transpose Transpose image (across UL-to-LR axis). >- -transverse Transverse transpose (across UR-to-LL axis). >- >-The transpose transformation has no restrictions regarding image dimensions. >-The other transformations operate rather oddly if the image dimensions are not >-a multiple of the iMCU size (usually 8 or 16 pixels), because they can only >-transform complete blocks of DCT coefficient data in the desired way. >- >-jpegtran's default behavior when transforming an odd-size image is designed >-to preserve exact reversibility and mathematical consistency of the >-transformation set. As stated, transpose is able to flip the entire image >-area. Horizontal mirroring leaves any partial iMCU column at the right edge >-untouched, but is able to flip all rows of the image. Similarly, vertical >-mirroring leaves any partial iMCU row at the bottom edge untouched, but is >-able to flip all columns. The other transforms can be built up as sequences >-of transpose and flip operations; for consistency, their actions on edge >-pixels are defined to be the same as the end result of the corresponding >-transpose-and-flip sequence. >- >-For practical use, you may prefer to discard any untransformable edge pixels >-rather than having a strange-looking strip along the right and/or bottom edges >-of a transformed image. To do this, add the -trim switch: >- -trim Drop non-transformable edge blocks. >-Obviously, a transformation with -trim is not reversible, so strictly speaking >-jpegtran with this switch is not lossless. Also, the expected mathematical >-equivalences between the transformations no longer hold. For example, >-"-rot 270 -trim" trims only the bottom edge, but "-rot 90 -trim" followed by >-"-rot 180 -trim" trims both edges. >- >-Another not-strictly-lossless transformation switch is: >- -grayscale Force grayscale output. >-This option discards the chrominance channels if the input image is YCbCr >-(ie, a standard color JPEG), resulting in a grayscale JPEG file. The >-luminance channel is preserved exactly, so this is a better method of reducing >-to grayscale than decompression, conversion, and recompression. This switch >-is particularly handy for fixing a monochrome picture that was mistakenly >-encoded as a color JPEG. (In such a case, the space savings from getting rid >-of the near-empty chroma channels won't be large; but the decoding time for >-a grayscale JPEG is substantially less than that for a color JPEG.) >- >-jpegtran also recognizes these switches that control what to do with "extra" >-markers, such as comment blocks: >- -copy none Copy no extra markers from source file. This setting >- suppresses all comments and other excess baggage >- present in the source file. >- -copy comments Copy only comment markers. This setting copies >- comments from the source file, but discards >- any other inessential data. >- -copy all Copy all extra markers. This setting preserves >- miscellaneous markers found in the source file, such >- as JFIF thumbnails and Photoshop settings. In some >- files these extra markers can be sizable. >-The default behavior is -copy comments. (Note: in IJG releases v6 and v6a, >-jpegtran always did the equivalent of -copy none.) >- >-Additional switches recognized by jpegtran are: >- -outfile filename >- -maxmemory N >- -verbose >- -debug >-These work the same as in cjpeg or djpeg. >- >- >-THE COMMENT UTILITIES >- >-The JPEG standard allows "comment" (COM) blocks to occur within a JPEG file. >-Although the standard doesn't actually define what COM blocks are for, they >-are widely used to hold user-supplied text strings. This lets you add >-annotations, titles, index terms, etc to your JPEG files, and later retrieve >-them as text. COM blocks do not interfere with the image stored in the JPEG >-file. The maximum size of a COM block is 64K, but you can have as many of >-them as you like in one JPEG file. >- >-We provide two utility programs to display COM block contents and add COM >-blocks to a JPEG file. >- >-rdjpgcom searches a JPEG file and prints the contents of any COM blocks on >-standard output. The command line syntax is >- rdjpgcom [-verbose] [inputfilename] >-The switch "-verbose" (or just "-v") causes rdjpgcom to also display the JPEG >-image dimensions. If you omit the input file name from the command line, >-the JPEG file is read from standard input. (This may not work on some >-operating systems, if binary data can't be read from stdin.) >- >-wrjpgcom adds a COM block, containing text you provide, to a JPEG file. >-Ordinarily, the COM block is added after any existing COM blocks, but you >-can delete the old COM blocks if you wish. wrjpgcom produces a new JPEG >-file; it does not modify the input file. DO NOT try to overwrite the input >-file by directing wrjpgcom's output back into it; on most systems this will >-just destroy your file. >- >-The command line syntax for wrjpgcom is similar to cjpeg's. On Unix-like >-systems, it is >- wrjpgcom [switches] [inputfilename] >-The output file is written to standard output. The input file comes from >-the named file, or from standard input if no input file is named. >- >-On most non-Unix systems, the syntax is >- wrjpgcom [switches] inputfilename outputfilename >-where both input and output file names must be given explicitly. >- >-wrjpgcom understands three switches: >- -replace Delete any existing COM blocks from the file. >- -comment "Comment text" Supply new COM text on command line. >- -cfile name Read text for new COM block from named file. >-(Switch names can be abbreviated.) If you have only one line of comment text >-to add, you can provide it on the command line with -comment. The comment >-text must be surrounded with quotes so that it is treated as a single >-argument. Longer comments can be read from a text file. >- >-If you give neither -comment nor -cfile, then wrjpgcom will read the comment >-text from standard input. (In this case an input image file name MUST be >-supplied, so that the source JPEG file comes from somewhere else.) You can >-enter multiple lines, up to 64KB worth. Type an end-of-file indicator >-(usually control-D or control-Z) to terminate the comment text entry. >- >-wrjpgcom will not add a COM block if the provided comment string is empty. >-Therefore -replace -comment "" can be used to delete all COM blocks from a >-file. >- >-These utility programs do not depend on the IJG JPEG library. In >-particular, the source code for rdjpgcom is intended as an illustration of >-the minimum amount of code required to parse a JPEG file header correctly. >only in patch2: >--- a/jpeg/wizard.doc >+++ /dev/null >@@ -1,211 +0,0 @@ >-Advanced usage instructions for the Independent JPEG Group's JPEG software >-========================================================================== >- >-This file describes cjpeg's "switches for wizards". >- >-The "wizard" switches are intended for experimentation with JPEG by persons >-who are reasonably knowledgeable about the JPEG standard. If you don't know >-what you are doing, DON'T USE THESE SWITCHES. You'll likely produce files >-with worse image quality and/or poorer compression than you'd get from the >-default settings. Furthermore, these switches must be used with caution >-when making files intended for general use, because not all JPEG decoders >-will support unusual JPEG parameter settings. >- >- >-Quantization Table Adjustment >------------------------------ >- >-Ordinarily, cjpeg starts with a default set of tables (the same ones given >-as examples in the JPEG standard) and scales them up or down according to >-the -quality setting. The details of the scaling algorithm can be found in >-jcparam.c. At very low quality settings, some quantization table entries >-can get scaled up to values exceeding 255. Although 2-byte quantization >-values are supported by the IJG software, this feature is not in baseline >-JPEG and is not supported by all implementations. If you need to ensure >-wide compatibility of low-quality files, you can constrain the scaled >-quantization values to no more than 255 by giving the -baseline switch. >-Note that use of -baseline will result in poorer quality for the same file >-size, since more bits than necessary are expended on higher AC coefficients. >- >-You can substitute a different set of quantization values by using the >--qtables switch: >- >- -qtables file Use the quantization tables given in the named file. >- >-The specified file should be a text file containing decimal quantization >-values. The file should contain one to four tables, each of 64 elements. >-The tables are implicitly numbered 0,1,etc. in order of appearance. Table >-entries appear in normal array order (NOT in the zigzag order in which they >-will be stored in the JPEG file). >- >-Quantization table files are free format, in that arbitrary whitespace can >-appear between numbers. Also, comments can be included: a comment starts >-with '#' and extends to the end of the line. Here is an example file that >-duplicates the default quantization tables: >- >- # Quantization tables given in JPEG spec, section K.1 >- >- # This is table 0 (the luminance table): >- 16 11 10 16 24 40 51 61 >- 12 12 14 19 26 58 60 55 >- 14 13 16 24 40 57 69 56 >- 14 17 22 29 51 87 80 62 >- 18 22 37 56 68 109 103 77 >- 24 35 55 64 81 104 113 92 >- 49 64 78 87 103 121 120 101 >- 72 92 95 98 112 100 103 99 >- >- # This is table 1 (the chrominance table): >- 17 18 24 47 99 99 99 99 >- 18 21 26 66 99 99 99 99 >- 24 26 56 99 99 99 99 99 >- 47 66 99 99 99 99 99 99 >- 99 99 99 99 99 99 99 99 >- 99 99 99 99 99 99 99 99 >- 99 99 99 99 99 99 99 99 >- 99 99 99 99 99 99 99 99 >- >-If the -qtables switch is used without -quality, then the specified tables >-are used exactly as-is. If both -qtables and -quality are used, then the >-tables taken from the file are scaled in the same fashion that the default >-tables would be scaled for that quality setting. If -baseline appears, then >-the quantization values are constrained to the range 1-255. >- >-By default, cjpeg will use quantization table 0 for luminance components and >-table 1 for chrominance components. To override this choice, use the -qslots >-switch: >- >- -qslots N[,...] Select which quantization table to use for >- each color component. >- >-The -qslots switch specifies a quantization table number for each color >-component, in the order in which the components appear in the JPEG SOF marker. >-For example, to create a separate table for each of Y,Cb,Cr, you could >-provide a -qtables file that defines three quantization tables and say >-"-qslots 0,1,2". If -qslots gives fewer table numbers than there are color >-components, then the last table number is repeated as necessary. >- >- >-Sampling Factor Adjustment >--------------------------- >- >-By default, cjpeg uses 2:1 horizontal and vertical downsampling when >-compressing YCbCr data, and no downsampling for all other color spaces. >-You can override this default with the -sample switch: >- >- -sample HxV[,...] Set JPEG sampling factors for each color >- component. >- >-The -sample switch specifies the JPEG sampling factors for each color >-component, in the order in which they appear in the JPEG SOF marker. >-If you specify fewer HxV pairs than there are components, the remaining >-components are set to 1x1 sampling. For example, the default YCbCr setting >-is equivalent to "-sample 2x2,1x1,1x1", which can be abbreviated to >-"-sample 2x2". >- >-There are still some JPEG decoders in existence that support only 2x1 >-sampling (also called 4:2:2 sampling). Compatibility with such decoders can >-be achieved by specifying "-sample 2x1". This is not recommended unless >-really necessary, since it increases file size and encoding/decoding time >-with very little quality gain. >- >- >-Multiple Scan / Progression Control >------------------------------------ >- >-By default, cjpeg emits a single-scan sequential JPEG file. The >--progressive switch generates a progressive JPEG file using a default series >-of progression parameters. You can create multiple-scan sequential JPEG >-files or progressive JPEG files with custom progression parameters by using >-the -scans switch: >- >- -scans file Use the scan sequence given in the named file. >- >-The specified file should be a text file containing a "scan script". >-The script specifies the contents and ordering of the scans to be emitted. >-Each entry in the script defines one scan. A scan definition specifies >-the components to be included in the scan, and for progressive JPEG it also >-specifies the progression parameters Ss,Se,Ah,Al for the scan. Scan >-definitions are separated by semicolons (';'). A semicolon after the last >-scan definition is optional. >- >-Each scan definition contains one to four component indexes, optionally >-followed by a colon (':') and the four progressive-JPEG parameters. The >-component indexes denote which color component(s) are to be transmitted in >-the scan. Components are numbered in the order in which they appear in the >-JPEG SOF marker, with the first component being numbered 0. (Note that these >-indexes are not the "component ID" codes assigned to the components, just >-positional indexes.) >- >-The progression parameters for each scan are: >- Ss Zigzag index of first coefficient included in scan >- Se Zigzag index of last coefficient included in scan >- Ah Zero for first scan of a coefficient, else Al of prior scan >- Al Successive approximation low bit position for scan >-If the progression parameters are omitted, the values 0,63,0,0 are used, >-producing a sequential JPEG file. cjpeg automatically determines whether >-the script represents a progressive or sequential file, by observing whether >-Ss and Se values other than 0 and 63 appear. (The -progressive switch is >-not needed to specify this; in fact, it is ignored when -scans appears.) >-The scan script must meet the JPEG restrictions on progression sequences. >-(cjpeg checks that the spec's requirements are obeyed.) >- >-Scan script files are free format, in that arbitrary whitespace can appear >-between numbers and around punctuation. Also, comments can be included: a >-comment starts with '#' and extends to the end of the line. For additional >-legibility, commas or dashes can be placed between values. (Actually, any >-single punctuation character other than ':' or ';' can be inserted.) For >-example, the following two scan definitions are equivalent: >- 0 1 2: 0 63 0 0; >- 0,1,2 : 0-63, 0,0 ; >- >-Here is an example of a scan script that generates a partially interleaved >-sequential JPEG file: >- >- 0; # Y only in first scan >- 1 2; # Cb and Cr in second scan >- >-Here is an example of a progressive scan script using only spectral selection >-(no successive approximation): >- >- # Interleaved DC scan for Y,Cb,Cr: >- 0,1,2: 0-0, 0, 0 ; >- # AC scans: >- 0: 1-2, 0, 0 ; # First two Y AC coefficients >- 0: 3-5, 0, 0 ; # Three more >- 1: 1-63, 0, 0 ; # All AC coefficients for Cb >- 2: 1-63, 0, 0 ; # All AC coefficients for Cr >- 0: 6-9, 0, 0 ; # More Y coefficients >- 0: 10-63, 0, 0 ; # Remaining Y coefficients >- >-Here is an example of a successive-approximation script. This is equivalent >-to the default script used by "cjpeg -progressive" for YCbCr images: >- >- # Initial DC scan for Y,Cb,Cr (lowest bit not sent) >- 0,1,2: 0-0, 0, 1 ; >- # First AC scan: send first 5 Y AC coefficients, minus 2 lowest bits: >- 0: 1-5, 0, 2 ; >- # Send all Cr,Cb AC coefficients, minus lowest bit: >- # (chroma data is usually too small to be worth subdividing further; >- # but note we send Cr first since eye is least sensitive to Cb) >- 2: 1-63, 0, 1 ; >- 1: 1-63, 0, 1 ; >- # Send remaining Y AC coefficients, minus 2 lowest bits: >- 0: 6-63, 0, 2 ; >- # Send next-to-lowest bit of all Y AC coefficients: >- 0: 1-63, 2, 1 ; >- # At this point we've sent all but the lowest bit of all coefficients. >- # Send lowest bit of DC coefficients >- 0,1,2: 0-0, 1, 0 ; >- # Send lowest bit of AC coefficients >- 2: 1-63, 1, 0 ; >- 1: 1-63, 1, 0 ; >- # Y AC lowest bit scan is last; it's usually the largest scan >- 0: 1-63, 1, 0 ; >- >-It may be worth pointing out that this script is tuned for quality settings >-of around 50 to 75. For lower quality settings, you'd probably want to use >-a script with fewer stages of successive approximation (otherwise the >-initial scans will be really bad). For higher quality settings, you might >-want to use more stages of successive approximation (so that the initial >-scans are not too large).
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
Actions:
View
Attachments on
bug 573948
:
458811
|
463214
|
463217
|
463225
|
463272
|
463675
|
463677
|
463692
|
463695
|
464561
|
471713
|
522445
|
522446
| 522449 |
522459
|
522544
|
522583
|
522674