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 522459 Details for
Bug 573948
Interdiff v1.3.1 -> v2.0 part 1 without deleted files
interdiff-small (text/plain), 195.00 KB, created by
Justin Lebar (not reading bugmail)
(
hide
)
Description:
Interdiff v1.3.1 -> v2.0 part 1 without deleted files
Filename:
MIME Type:
Creator:
Justin Lebar (not reading bugmail)
Size:
195.00 KB
patch
obsolete
>--- b/jpeg/BUILDING.txt > File deleted. > >--- b/jpeg/ChangeLog.txt > File deleted. > >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 > File deleted. > >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 > File deleted. > >--- b/jpeg/cjpeg.1 > File deleted. > >--- b/jpeg/configure.ac > File deleted. > >--- b/jpeg/djpeg.1 > File deleted. > >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 > File deleted. > >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. > */ > > > /* > * 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 > File deleted. > >--- b/jpeg/jpegtran.c > File deleted. > >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 > File deleted. > >--- b/jpeg/rdcolmap.c > File deleted. > >--- b/jpeg/rdgif.c > File deleted. > >--- b/jpeg/rdjpgcom.1 > File deleted. > >--- b/jpeg/rdjpgcom.c > File deleted. > >--- b/jpeg/rdppm.c > File deleted. > >--- b/jpeg/rdrle.c > File deleted. > >--- b/jpeg/rdswitch.c > File deleted. > >--- b/jpeg/rdtarga.c > File deleted. > >--- b/jpeg/simd/Makefile.am > File deleted. > >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 > File deleted. > >--- b/jpeg/transupp.c > File deleted. > >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 > File deleted. > >--- b/jpeg/wrbmp.c > File deleted. > >--- b/jpeg/wrgif.c > File deleted. > >--- b/jpeg/wrjpgcom.1 > File deleted. > >--- b/jpeg/wrjpgcom.c > File deleted. > >--- b/jpeg/wrppm.c > File deleted. > >--- b/jpeg/wrrle.c > File deleted. > >--- b/jpeg/wrtarga.c > File deleted. > >--- 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 > File deleted. > >--- 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 > File deleted. > >--- a/jpeg/cjpeg.c > File deleted. > >--- a/jpeg/coderules.doc > File deleted. > >--- a/jpeg/djpeg.c > File deleted. > >--- a/jpeg/example.c > File deleted. > >--- a/jpeg/filelist.doc > File deleted. > >--- a/jpeg/install.doc > File deleted. > >--- 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 > File deleted. > >--- 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 > File deleted. > >--- a/jpeg/structure.doc > File deleted. > >--- a/jpeg/usage.doc > File deleted. > >--- a/jpeg/wizard.doc > File deleted. >
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