Update bundled libjpeg from jpeg-8c to jpeg-9a.

git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@10626 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
Albrecht Schlosser 2015-03-16 16:57:13 +00:00
parent 992192dd02
commit 463eb3a181
50 changed files with 2449 additions and 1272 deletions

View File

@ -1,3 +1,6 @@
# *************************************************************************
# FLTK - DO NOT CHANGE when upgrading the JPEG library, unless required. *
# *************************************************************************
# #
# "$Id$" # "$Id$"
# #

View File

@ -1,10 +1,10 @@
The Independent JPEG Group's JPEG software The Independent JPEG Group's JPEG software
========================================== ==========================================
README for release 8c of 16-Jan-2011 README for release 9a of 19-Jan-2014
==================================== ====================================
This distribution contains the eighth public release of the Independent JPEG This distribution contains the ninth public release of the Independent JPEG
Group's free JPEG software. You are welcome to redistribute this software and 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. to use it for any purpose, subject to the conditions under LEGAL ISSUES, below.
@ -13,7 +13,8 @@ Bill Allombert, Jim Boucher, Lee Crocker, Bob Friesenhahn, Ben Jackson,
Julian Minguillon, Luis Ortiz, George Phillips, Davide Rossi, Ge' Weijers, Julian Minguillon, Luis Ortiz, George Phillips, Davide Rossi, Ge' Weijers,
and other members of the Independent JPEG Group. and other members of the Independent JPEG Group.
IJG is not affiliated with the official ISO JPEG standards committee. IJG is not affiliated with the ISO/IEC JTC1/SC29/WG1 standards committee
(previously known as JPEG, together with ITU-T SG16).
DOCUMENTATION ROADMAP DOCUMENTATION ROADMAP
@ -114,7 +115,7 @@ with respect to this software, its quality, accuracy, merchantability, or
fitness for a particular purpose. This software is provided "AS IS", and you, 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. its user, assume the entire risk as to its quality and accuracy.
This software is copyright (C) 1991-2011, Thomas G. Lane, Guido Vollbeding. This software is copyright (C) 1991-2014, Thomas G. Lane, Guido Vollbeding.
All Rights Reserved except as specified below. All Rights Reserved except as specified below.
Permission is hereby granted to use, copy, modify, and distribute this Permission is hereby granted to use, copy, modify, and distribute this
@ -145,15 +146,6 @@ commercial products, provided that all warranty or liability claims are
assumed by the product vendor. assumed by the product vendor.
ansi2knr.c is included in this distribution by permission of L. Peter Deutsch,
sole proprietor of its copyright holder, Aladdin Enterprises of Menlo Park, CA.
ansi2knr.c is NOT covered by the above copyright and conditions, but instead
by the usual distribution terms of the Free Software Foundation; principally,
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. The Unix configuration script "configure" was produced with GNU Autoconf.
It is copyright by the Free Software Foundation but is freely distributable. It is copyright by the Free Software Foundation but is freely distributable.
The same holds for its supporting scripts (config.guess, config.sub, The same holds for its supporting scripts (config.guess, config.sub,
@ -161,11 +153,11 @@ ltmain.sh). Another support script, install-sh, is copyright by X Consortium
but is also freely distributable. but is also freely distributable.
The IJG distribution formerly included code to read and write GIF files. The IJG distribution formerly included code to read and write GIF files.
To avoid entanglement with the Unisys LZW patent, GIF reading support has To avoid entanglement with the Unisys LZW patent (now expired), GIF reading
been removed altogether, and the GIF writer has been simplified to produce support has been removed altogether, and the GIF writer has been simplified
"uncompressed GIFs". This technique does not use the LZW algorithm; the to produce "uncompressed GIFs". This technique does not use the LZW
resulting GIF files are larger than usual, but are readable by all standard algorithm; the resulting GIF files are larger than usual, but are readable
GIF decoders. by all standard GIF decoders.
We are required to state that We are required to state that
"The Graphics Interchange Format(c) is the Copyright property of "The Graphics Interchange Format(c) is the Copyright property of
@ -221,10 +213,16 @@ 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 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 Continuous-tone Still Images, Part 2: Compliance testing" and has document
numbers ISO/IEC IS 10918-2, ITU-T T.83. numbers ISO/IEC IS 10918-2, ITU-T T.83.
IJG JPEG 8 introduces an implementation of the JPEG SmartScale extension IJG JPEG 8 introduced an implementation of the JPEG SmartScale extension
which is specified in a contributed document at ITU and ISO with title "ITU-T which is specified in two documents: A contributed document at ITU and ISO
JPEG-Plus Proposal for Extending ITU-T T.81 for Advanced Image Coding", April with title "ITU-T JPEG-Plus Proposal for Extending ITU-T T.81 for Advanced
2006, Geneva, Switzerland. The latest version of the document is Revision 3. Image Coding", April 2006, Geneva, Switzerland. The latest version of this
document is Revision 3. And a contributed document ISO/IEC JTC1/SC29/WG1 N
5799 with title "Evolution of JPEG", June/July 2011, Berlin, Germany.
IJG JPEG 9 introduces a reversible color transform for improved lossless
compression which is described in a contributed document ISO/IEC JTC1/SC29/
WG1 N 6080 with title "JPEG 9 Lossless Coding", June/July 2012, Paris,
France.
The JPEG standard does not specify all details of an interchangeable file The JPEG standard does not specify all details of an interchangeable file
format. For the omitted details we follow the "JFIF" conventions, revision format. For the omitted details we follow the "JFIF" conventions, revision
@ -254,8 +252,8 @@ ARCHIVE LOCATIONS
The "official" archive site for this software is www.ijg.org. The "official" archive site for this software is www.ijg.org.
The most recent released version can always be found there in The most recent released version can always be found there in
directory "files". This particular version will be archived as directory "files". This particular version will be archived as
http://www.ijg.org/files/jpegsrc.v8c.tar.gz, and in Windows-compatible http://www.ijg.org/files/jpegsrc.v9a.tar.gz, and in Windows-compatible
"zip" archive format as http://www.ijg.org/files/jpegsr8c.zip. "zip" archive format as http://www.ijg.org/files/jpegsr9a.zip.
The JPEG FAQ (Frequently Asked Questions) article is a source of some The JPEG FAQ (Frequently Asked Questions) article is a source of some
general information about JPEG. general information about JPEG.
@ -281,6 +279,10 @@ ITU JPEG (Study Group 16) meeting in Geneva, Switzerland.
Thank to Thomas Wiegand and Gary Sullivan for inviting me to the Thank to Thomas Wiegand and Gary Sullivan for inviting me to the
Joint Video Team (MPEG & ITU) meeting in Geneva, Switzerland. Joint Video Team (MPEG & ITU) meeting in Geneva, Switzerland.
Thank to Thomas Richter and Daniel Lee for inviting me to the
ISO/IEC JTC1/SC29/WG1 (previously known as JPEG, together with ITU-T SG16)
meeting in Berlin, Germany.
Thank to John Korejwa and Massimo Ballerini for inviting me to Thank to John Korejwa and Massimo Ballerini for inviting me to
fruitful consultations in Boston, MA and Milan, Italy. fruitful consultations in Boston, MA and Milan, Italy.
@ -304,23 +306,76 @@ design and development of this singular software package.
FILE FORMAT WARS FILE FORMAT WARS
================ ================
The ISO JPEG standards committee actually promotes different formats like The ISO/IEC JTC1/SC29/WG1 standards committee (previously known as JPEG,
"JPEG 2000" or "JPEG XR" which are incompatible with original DCT-based together with ITU-T SG16) currently promotes different formats containing
JPEG and which are based on faulty technologies. IJG therefore does not the name "JPEG" which is misleading because these formats are incompatible
and will not support such momentary mistakes (see REFERENCES). with original DCT-based JPEG and are based on faulty technologies.
We have little or no sympathy for the promotion of these formats. Indeed, IJG therefore does not and will not support such momentary mistakes
one of the original reasons for developing this free software was to help (see REFERENCES).
force convergence on common, interoperable format standards for JPEG files. There exist also distributions under the name "OpenJPEG" promoting such
kind of formats which is misleading because they don't support original
JPEG images.
We have no sympathy for the promotion of inferior formats. Indeed, one of
the original reasons for developing this free software was to help force
convergence on common, interoperable format standards for JPEG files.
Don't use an incompatible file format! Don't use an incompatible file format!
(In any case, our decoder will remain capable of reading existing JPEG (In any case, our decoder will remain capable of reading existing JPEG
image files indefinitely.) image files indefinitely.)
The ISO committee pretends to be "responsible for the popular JPEG" in their
public reports which is not true because they don't respond to actual
requirements for the maintenance of the original JPEG specification.
Furthermore, the ISO committee pretends to "ensure interoperability" with
their standards which is not true because their "standards" support only
application-specific and proprietary use cases and contain mathematically
incorrect code.
There are currently different distributions in circulation containing the
name "libjpeg" which is misleading because they don't have the features and
are incompatible with formats supported by actual IJG libjpeg distributions.
One of those fakes is released by members of the ISO committee and just uses
the name of libjpeg for misdirection of people, similar to the abuse of the
name JPEG as described above, while having nothing in common with actual IJG
libjpeg distributions and containing mathematically incorrect code.
The other one claims to be a "derivative" or "fork" of the original libjpeg,
but violates the license conditions as described under LEGAL ISSUES above
and violates basic C programming properties.
We have no sympathy for the release of misleading, incorrect and illegal
distributions derived from obsolete code bases.
Don't use an obsolete code base!
According to the UCC (Uniform Commercial Code) law, IJG has the lawful and
legal right to foreclose on certain standardization bodies and other
institutions or corporations that knowingly perform substantial and
systematic deceptive acts and practices, fraud, theft, and damaging of the
value of the people of this planet without their knowing, willing and
intentional consent.
The titles, ownership, and rights of these institutions and all their assets
are now duly secured and held in trust for the free people of this planet.
People of the planet, on every country, may have a financial interest in
the assets of these former principals, agents, and beneficiaries of the
foreclosed institutions and corporations.
IJG asserts what is: that each man, woman, and child has unalienable value
and rights granted and deposited in them by the Creator and not any one of
the people is subordinate to any artificial principality, corporate fiction
or the special interest of another without their appropriate knowing,
willing and intentional consent made by contract or accommodation agreement.
IJG expresses that which already was.
The people have already determined and demanded that public administration
entities, national governments, and their supporting judicial systems must
be fully transparent, accountable, and liable.
IJG has secured the value for all concerned free people of the planet.
A partial list of foreclosed institutions and corporations ("Hall of Shame")
is currently prepared and will be published later.
TO DO TO DO
===== =====
Version 8 is the first release of a new generation JPEG standard Version 9 is the second release of a new generation JPEG standard
to overcome the limitations of the original JPEG specification. to overcome the limitations of the original JPEG specification,
and is the first true source reference JPEG codec.
More features are being prepared for coming releases... More features are being prepared for coming releases...
Please send bug reports, offers of help, etc. to jpeg-info@uc.ag. Please send bug reports, offers of help, etc. to jpeg-info@jpegclub.org.

View File

@ -1,6 +1,89 @@
CHANGE LOG for Independent JPEG Group's JPEG software CHANGE LOG for Independent JPEG Group's JPEG software
Version 9a 19-Jan-2014
-----------------------
Add support for wide gamut color spaces (JFIF version 2).
Improve clarity and accuracy in color conversion modules.
Note: Requires rebuild of test images.
Extend the bit depth support to all values from 8 to 12
(BITS_IN_JSAMPLE configuration option in jmorecfg.h).
jpegtran now supports N bits sample data precision with all N from 8 to 12
in a single instance. Thank to Roland Fassauer for inspiration.
Try to resolve issues with new boolean type definition.
Thank also to v4hn for suggestion.
Enable option to use default Huffman tables for lossless compression
(for hardware solution), and in this case improve lossless RGB compression
with reversible color transform. Thank to Benny Alexandar for hint.
Extend the entropy decoding structure, so that extraneous bytes between
compressed scan data and following marker can be reported correctly.
Thank to Nigel Tao for hint.
Add jpegtran -wipe option and extension for -crop.
Thank to Andrew Senior, David Clunie, and Josef Schmid for suggestion.
Version 9 13-Jan-2013
----------------------
Add cjpeg -rgb1 option to create an RGB JPEG file, and insert
a simple reversible color transform into the processing which
significantly improves the compression.
The recommended command for lossless coding of RGB images is now
cjpeg -rgb1 -block 1 -arithmetic.
As said, this option improves the compression significantly, but
the files are not compatible with JPEG decoders prior to IJG v9
due to the included color transform.
The used color transform and marker signaling is compatible with
other JPEG standards (e.g., JPEG-LS part 2).
Remove the automatic de-ANSI-fication support (Automake 1.12).
Thank also to Nitin A Kamble for suggestion.
Add remark for jpeg_mem_dest() in jdatadst.c.
Thank to Elie-Gregoire Khoury for the hint.
Support files with invalid component identifiers (created
by Adobe PDF). Thank to Robin Watts for the suggestion.
Adapt full buffer case in jcmainct.c for use with scaled DCT.
Thank to Sergii Biloshytskyi for the suggestion.
Add type identifier for declaration of noreturn functions.
Thank to Brett L. Moore for the suggestion.
Correct argument type in format string, avoid compiler warnings.
Thank to Vincent Torri for hint.
Add missing #include directives in configuration checks, avoid
configuration errors. Thank to John Spencer for the hint.
Version 8d 15-Jan-2012
-----------------------
Add cjpeg -rgb option to create RGB JPEG files.
Using this switch suppresses the conversion from RGB
colorspace input to the default YCbCr JPEG colorspace.
This feature allows true lossless JPEG coding of RGB color images.
The recommended command for this purpose is currently
cjpeg -rgb -block 1 -arithmetic.
SmartScale capable decoder (introduced with IJG JPEG 8) required.
Thank to Michael Koch for the initial suggestion.
Add option to disable the region adjustment in the transupp crop code.
Thank to Jeffrey Friedl for the suggestion.
Thank to Richard Jones and Edd Dawson for various minor corrections.
Thank to Akim Demaille for configure.ac cleanup.
Version 8c 16-Jan-2011 Version 8c 16-Jan-2011
----------------------- -----------------------

View File

@ -1,6 +1,6 @@
IJG JPEG LIBRARY: FILE LIST IJG JPEG LIBRARY: FILE LIST
Copyright (C) 1994-2009, Thomas G. Lane, Guido Vollbeding. Copyright (C) 1994-2013, Thomas G. Lane, Guido Vollbeding.
This file is part of the Independent JPEG Group's software. This file is part of the Independent JPEG Group's software.
For conditions of distribution and use, see the accompanying README file. For conditions of distribution and use, see the accompanying README file.
@ -197,6 +197,8 @@ config.guess
config.sub config.sub
depcomp depcomp
missing missing
ar-lib
compile
install-sh Install shell script for those Unix systems lacking one. install-sh Install shell script for those Unix systems lacking one.
Makefile.in Makefile input for configure. Makefile.in Makefile input for configure.
Makefile.am Source file for use with Automake to generate Makefile.in. Makefile.am Source file for use with Automake to generate Makefile.in.
@ -206,8 +208,6 @@ mak*.* Sample makefiles for particular systems.
jconfig.* Sample jconfig.h for particular systems. jconfig.* Sample jconfig.h for particular systems.
libjpeg.map Script to generate shared library with versioned symbols. libjpeg.map Script to generate shared library with versioned symbols.
aclocal.m4 M4 macro definitions for use with Autoconf. aclocal.m4 M4 macro definitions for use with Autoconf.
ansi2knr.c De-ANSIfier for pre-ANSI C compilers (courtesy of
L. Peter Deutsch and Aladdin Enterprises).
Test files (see install.txt for test procedure): Test files (see install.txt for test procedure):

View File

@ -1,6 +1,6 @@
INSTALLATION INSTRUCTIONS for the Independent JPEG Group's JPEG software INSTALLATION INSTRUCTIONS for the Independent JPEG Group's JPEG software
Copyright (C) 1991-2010, Thomas G. Lane, Guido Vollbeding. Copyright (C) 1991-2013, Thomas G. Lane, Guido Vollbeding.
This file is part of the Independent JPEG Group's software. This file is part of the Independent JPEG Group's software.
For conditions of distribution and use, see the accompanying README file. For conditions of distribution and use, see the accompanying README file.
@ -321,9 +321,9 @@ several forms:
testimg.jpg The output of cjpeg testimg.ppm testimg.jpg The output of cjpeg testimg.ppm
testprog.jpg Progressive-mode equivalent of testorig.jpg. testprog.jpg Progressive-mode equivalent of testorig.jpg.
testimgp.jpg The output of cjpeg -progressive -optimize testimg.ppm testimgp.jpg The output of cjpeg -progressive -optimize testimg.ppm
(The first- and second-generation .jpg files aren't identical since JPEG is (The first- and second-generation .jpg files aren't identical since the
lossy.) If you can generate duplicates of the testimg* files then you default compression parameters are lossy.) If you can generate duplicates
probably have working programs. of the testimg* files then you probably have working programs.
With most of the makefiles, "make test" will perform the necessary With most of the makefiles, "make test" will perform the necessary
comparisons. comparisons.
@ -418,54 +418,58 @@ support as follows:
the directory containing the URT "librle.a" file (typically the the directory containing the URT "librle.a" file (typically the
"lib" subdirectory of the URT distribution). "lib" subdirectory of the URT distribution).
Support for 12-bit-deep pixel data: Support for 9-bit to 12-bit deep pixel data:
The JPEG standard allows either 8-bit or 12-bit data precision. (For color, The IJG code currently allows 8, 9, 10, 11, or 12 bits sample data precision.
this means 8 or 12 bits per channel, of course.) If you need to work with (For color, this means 8 to 12 bits per channel, of course.) If you need to
deeper than 8-bit data, you can compile the IJG code for 12-bit operation. work with deeper than 8-bit data, you can compile the IJG code for 9-bit to
12-bit operation.
To do so: To do so:
1. In jmorecfg.h, define BITS_IN_JSAMPLE as 12 rather than 8. 1. In jmorecfg.h, define BITS_IN_JSAMPLE as 9, 10, 11, or 12 rather than 8.
2. In jconfig.h, undefine BMP_SUPPORTED, RLE_SUPPORTED, and TARGA_SUPPORTED, 2. In jconfig.h, undefine BMP_SUPPORTED, RLE_SUPPORTED, and TARGA_SUPPORTED,
because the code for those formats doesn't handle 12-bit data and won't because the code for those formats doesn't handle deeper than 8-bit data
even compile. (The PPM code does work, as explained below. The GIF and won't even compile. (The PPM code does work, as explained below.
code works too; it scales 8-bit GIF data to and from 12-bit depth The GIF code works too; it scales 8-bit GIF data to and from 12-bit
automatically.) depth automatically.)
3. Compile. Don't expect "make test" to pass, since the supplied test 3. Compile. Don't expect "make test" to pass, since the supplied test
files are for 8-bit data. files are for 8-bit data.
Currently, 12-bit support does not work on 16-bit-int machines. Currently, 9-bit to 12-bit support does not work on 16-bit-int machines.
Note that a 12-bit version will not read 8-bit JPEG files, nor vice versa; Run-time selection and conversion of data precision are currently not
so you'll want to keep around a regular 8-bit compilation as well. supported and may be added later.
(Run-time selection of data depth, to allow a single copy that does both, Exception: The transcoding part (jpegtran) supports all settings in a
is possible but would probably slow things down considerably; it's very low single instance, since it operates on the level of DCT coefficients and
on our to-do list.) not sample values.
The PPM reader (rdppm.c) can read 12-bit data from either text-format or The PPM reader (rdppm.c) can read deeper than 8-bit data from either
binary-format PPM and PGM files. Binary-format PPM/PGM files which have a text-format or binary-format PPM and PGM files. Binary-format PPM/PGM files
maxval greater than 255 are assumed to use 2 bytes per sample, MSB first which have a maxval greater than 255 are assumed to use 2 bytes per sample,
(big-endian order). As of early 1995, 2-byte binary format is not MSB first (big-endian order). As of early 1995, 2-byte binary format is not
officially supported by the PBMPLUS library, but it is expected that a officially supported by the PBMPLUS library, but it is expected that a
future release of PBMPLUS will support it. Note that the PPM reader will future release of PBMPLUS will support it. Note that the PPM reader will
read files of any maxval regardless of the BITS_IN_JSAMPLE setting; incoming read files of any maxval regardless of the BITS_IN_JSAMPLE setting; incoming
data is automatically rescaled to either maxval=255 or maxval=4095 as data is automatically rescaled to maxval=MAXJSAMPLE as appropriate for the
appropriate for the cjpeg bit depth. cjpeg bit depth.
The PPM writer (wrppm.c) will normally write 2-byte binary PPM or PGM The PPM writer (wrppm.c) will normally write 2-byte binary PPM or PGM
format, maxval 4095, when compiled with BITS_IN_JSAMPLE=12. Since this format, maxval=MAXJSAMPLE, when compiled with BITS_IN_JSAMPLE>8. Since this
format is not yet widely supported, you can disable it by compiling wrppm.c format is not yet widely supported, you can disable it by compiling wrppm.c
with PPM_NORAWWORD defined; then the data is scaled down to 8 bits to make a with PPM_NORAWWORD defined; then the data is scaled down to 8 bits to make a
standard 1-byte/sample PPM or PGM file. (Yes, this means still another copy standard 1-byte/sample PPM or PGM file. (Yes, this means still another copy
of djpeg to keep around. But hopefully you won't need it for very long. of djpeg to keep around. But hopefully you won't need it for very long.
Poskanzer's supposed to get that new PBMPLUS release out Real Soon Now.) Poskanzer's supposed to get that new PBMPLUS release out Real Soon Now.)
Of course, if you are working with 12-bit data, you probably have it stored Of course, if you are working with 9-bit to 12-bit data, you probably have
in some other, nonstandard format. In that case you'll probably want to it stored in some other, nonstandard format. In that case you'll probably
write your own I/O modules to read and write your format. want to write your own I/O modules to read and write your format.
Note that a 12-bit version of cjpeg always runs in "-optimize" mode, in Note:
order to generate valid Huffman tables. This is necessary because our The standard Huffman tables are only valid for 8-bit data precision. If
default Huffman tables only cover 8-bit data. you selected more than 8-bit data precision, cjpeg uses arithmetic coding
by default. The Huffman encoder normally uses entropy optimization to
compute usable tables for higher precision. Otherwise, you'll have to
supply different default Huffman tables.
Removing code: Removing code:
@ -534,17 +538,17 @@ In general, it's worth trying the maximum optimization level of your compiler,
and experimenting with any optional optimizations such as loop unrolling. and experimenting with any optional optimizations such as loop unrolling.
(Unfortunately, far too many compilers have optimizer bugs ... be prepared to (Unfortunately, far too many compilers have optimizer bugs ... be prepared to
back off if the code fails self-test.) If you do any experimentation along back off if the code fails self-test.) If you do any experimentation along
these lines, please report the optimal settings to jpeg-info@uc.ag so we these lines, please report the optimal settings to jpeg-info@jpegclub.org so
can mention them in future releases. Be sure to specify your machine we can mention them in future releases. Be sure to specify your machine and
and compiler version. compiler version.
HINTS FOR SPECIFIC SYSTEMS HINTS FOR SPECIFIC SYSTEMS
========================== ==========================
We welcome reports on changes needed for systems not mentioned here. Submit We welcome reports on changes needed for systems not mentioned here. Submit
'em to jpeg-info@uc.ag. Also, if configure or ckconfig.c is wrong about how 'em to jpeg-info@jpegclub.org. Also, if configure or ckconfig.c is wrong
to configure the JPEG software for your system, please let us know. about how to configure the JPEG software for your system, please let us know.
Acorn RISC OS: Acorn RISC OS:
@ -848,17 +852,23 @@ with /Oo-.
Microsoft Windows (all versions), generic comments: Microsoft Windows (all versions), generic comments:
Some Windows system include files define typedef boolean as "unsigned char". Some Windows system include files define typedef boolean as "unsigned char".
The IJG code also defines typedef boolean, but we make it "int" by default. The IJG code also defines typedef boolean, but we make it an "enum" by default.
This doesn't affect the IJG programs because we don't import those Windows This doesn't affect the IJG programs because we don't import those Windows
include files. But if you use the JPEG library in your own program, and some include files. But if you use the JPEG library in your own program, and some
of your program's files import one definition of boolean while some import the of your program's files import one definition of boolean while some import the
other, you can get all sorts of mysterious problems. A good preventive step other, you can get all sorts of mysterious problems. A good preventive step
is to make the IJG library use "unsigned char" for boolean. To do that, is to make the IJG library use "unsigned char" for boolean. To do that,
add something like this to your jconfig.h file: add something like this to your jconfig.h file:
/* Define "boolean" as unsigned char, not int, per Windows custom */ /* Define "boolean" as unsigned char, not enum, per Windows custom */
#ifndef __RPCNDR_H__ /* don't conflict if rpcndr.h already read */ #ifndef __RPCNDR_H__ /* don't conflict if rpcndr.h already read */
typedef unsigned char boolean; typedef unsigned char boolean;
#endif #endif
#ifndef FALSE /* in case these macros already exist */
#define FALSE 0 /* values of boolean */
#endif
#ifndef TRUE
#define TRUE 1
#endif
#define HAVE_BOOLEAN /* prevent jmorecfg.h from redefining it */ #define HAVE_BOOLEAN /* prevent jmorecfg.h from redefining it */
(This is already in jconfig.vc, by the way.) (This is already in jconfig.vc, by the way.)

View File

@ -1,16 +1,16 @@
/* /*
* jaricom.c * jaricom.c
* *
* Developed 1997-2009 by Guido Vollbeding. * Developed 1997-2011 by Guido Vollbeding.
* This file is part of the Independent JPEG Group's software. * This file is part of the Independent JPEG Group's software.
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
* This file contains probability estimation tables for common use in * This file contains probability estimation tables for common use in
* arithmetic entropy encoding and decoding routines. * arithmetic entropy encoding and decoding routines.
* *
* This data represents Table D.2 in the JPEG spec (ISO/IEC IS 10918-1 * This data represents Table D.3 in the JPEG spec (D.2 in the draft),
* and CCITT Recommendation ITU-T T.81) and Table 24 in the JBIG spec * ISO/IEC IS 10918-1 and CCITT Recommendation ITU-T T.81, and Table 24
* (ISO/IEC IS 11544 and CCITT Recommendation ITU-T T.82). * in the JBIG spec, ISO/IEC IS 11544 and CCITT Recommendation ITU-T T.82.
*/ */
#define JPEG_INTERNALS #define JPEG_INTERNALS
@ -147,7 +147,7 @@ const INT32 jpeg_aritab[113+1] = {
V( 112, 0x59eb, 112, 111, 1 ), V( 112, 0x59eb, 112, 111, 1 ),
/* /*
* This last entry is used for fixed probability estimate of 0.5 * This last entry is used for fixed probability estimate of 0.5
* as recommended in Section 10.3 Table 5 of ITU-T Rec. T.851. * as suggested in Section 10.3 Table 5 of ITU-T Rec. T.851.
*/ */
V( 113, 0x5a1d, 113, 113, 0 ) V( 113, 0x5a1d, 113, 113, 0 )
}; };

View File

@ -2,6 +2,7 @@
* jcapistd.c * jcapistd.c
* *
* Copyright (C) 1994-1996, Thomas G. Lane. * Copyright (C) 1994-1996, Thomas G. Lane.
* Modified 2013 by Guido Vollbeding.
* This file is part of the Independent JPEG Group's software. * This file is part of the Independent JPEG Group's software.
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
@ -145,7 +146,7 @@ jpeg_write_raw_data (j_compress_ptr cinfo, JSAMPIMAGE data,
(*cinfo->master->pass_startup) (cinfo); (*cinfo->master->pass_startup) (cinfo);
/* Verify that at least one iMCU row has been passed. */ /* Verify that at least one iMCU row has been passed. */
lines_per_iMCU_row = cinfo->max_v_samp_factor * DCTSIZE; lines_per_iMCU_row = cinfo->max_v_samp_factor * cinfo->min_DCT_v_scaled_size;
if (num_lines < lines_per_iMCU_row) if (num_lines < lines_per_iMCU_row)
ERREXIT(cinfo, JERR_BUFFER_SIZE); ERREXIT(cinfo, JERR_BUFFER_SIZE);

View File

@ -1,7 +1,7 @@
/* /*
* jcarith.c * jcarith.c
* *
* Developed 1997-2009 by Guido Vollbeding. * Developed 1997-2013 by Guido Vollbeding.
* This file is part of the Independent JPEG Group's software. * This file is part of the Independent JPEG Group's software.
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
@ -223,7 +223,7 @@ arith_encode (j_compress_ptr cinfo, unsigned char *st, int val)
register INT32 qe, temp; register INT32 qe, temp;
register int sv; register int sv;
/* Fetch values from our compact representation of Table D.2: /* Fetch values from our compact representation of Table D.3(D.2):
* Qe values and probability estimation state machine * Qe values and probability estimation state machine
*/ */
sv = *st; sv = *st;
@ -362,7 +362,6 @@ METHODDEF(boolean)
encode_mcu_DC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data) encode_mcu_DC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
{ {
arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy; arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy;
JBLOCKROW block;
unsigned char *st; unsigned char *st;
int blkn, ci, tbl; int blkn, ci, tbl;
int v, v2, m; int v, v2, m;
@ -381,14 +380,13 @@ encode_mcu_DC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
/* Encode the MCU data blocks */ /* Encode the MCU data blocks */
for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) { for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
block = MCU_data[blkn];
ci = cinfo->MCU_membership[blkn]; ci = cinfo->MCU_membership[blkn];
tbl = cinfo->cur_comp_info[ci]->dc_tbl_no; tbl = cinfo->cur_comp_info[ci]->dc_tbl_no;
/* Compute the DC value after the required point transform by Al. /* Compute the DC value after the required point transform by Al.
* This is simply an arithmetic right shift. * This is simply an arithmetic right shift.
*/ */
m = IRIGHT_SHIFT((int) ((*block)[0]), cinfo->Al); m = IRIGHT_SHIFT((int) (MCU_data[blkn][0][0]), cinfo->Al);
/* Sections F.1.4.1 & F.1.4.4.1: Encoding of DC coefficients */ /* Sections F.1.4.1 & F.1.4.4.1: Encoding of DC coefficients */
@ -453,11 +451,11 @@ METHODDEF(boolean)
encode_mcu_AC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data) encode_mcu_AC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
{ {
arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy; arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy;
const int * natural_order;
JBLOCKROW block; JBLOCKROW block;
unsigned char *st; unsigned char *st;
int tbl, k, ke; int tbl, k, ke;
int v, v2, m; int v, v2, m;
const int * natural_order;
/* Emit restart marker if needed */ /* Emit restart marker if needed */
if (cinfo->restart_interval) { if (cinfo->restart_interval) {
@ -479,7 +477,8 @@ encode_mcu_AC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
/* Sections F.1.4.2 & F.1.4.4.2: Encoding of AC coefficients */ /* Sections F.1.4.2 & F.1.4.4.2: Encoding of AC coefficients */
/* Establish EOB (end-of-block) index */ /* Establish EOB (end-of-block) index */
for (ke = cinfo->Se; ke > 0; ke--) ke = cinfo->Se;
do {
/* We must apply the point transform by Al. For AC coefficients this /* We must apply the point transform by Al. For AC coefficients this
* is an integer division with rounding towards 0. To do this portably * is an integer division with rounding towards 0. To do this portably
* in C, we shift after obtaining the absolute value. * in C, we shift after obtaining the absolute value.
@ -490,13 +489,14 @@ encode_mcu_AC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
v = -v; v = -v;
if (v >>= cinfo->Al) break; if (v >>= cinfo->Al) break;
} }
} while (--ke);
/* Figure F.5: Encode_AC_Coefficients */ /* Figure F.5: Encode_AC_Coefficients */
for (k = cinfo->Ss; k <= ke; k++) { for (k = cinfo->Ss - 1; k < ke;) {
st = entropy->ac_stats[tbl] + 3 * (k - 1); st = entropy->ac_stats[tbl] + 3 * k;
arith_encode(cinfo, st, 0); /* EOB decision */ arith_encode(cinfo, st, 0); /* EOB decision */
for (;;) { for (;;) {
if ((v = (*block)[natural_order[k]]) >= 0) { if ((v = (*block)[natural_order[++k]]) >= 0) {
if (v >>= cinfo->Al) { if (v >>= cinfo->Al) {
arith_encode(cinfo, st + 1, 1); arith_encode(cinfo, st + 1, 1);
arith_encode(cinfo, entropy->fixed_bin, 0); arith_encode(cinfo, entropy->fixed_bin, 0);
@ -510,7 +510,8 @@ encode_mcu_AC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
break; break;
} }
} }
arith_encode(cinfo, st + 1, 0); st += 3; k++; arith_encode(cinfo, st + 1, 0);
st += 3;
} }
st += 2; st += 2;
/* Figure F.8: Encoding the magnitude category of v */ /* Figure F.8: Encoding the magnitude category of v */
@ -537,9 +538,9 @@ encode_mcu_AC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
while (m >>= 1) while (m >>= 1)
arith_encode(cinfo, st, (m & v) ? 1 : 0); arith_encode(cinfo, st, (m & v) ? 1 : 0);
} }
/* Encode EOB decision only if k <= cinfo->Se */ /* Encode EOB decision only if k < cinfo->Se */
if (k <= cinfo->Se) { if (k < cinfo->Se) {
st = entropy->ac_stats[tbl] + 3 * (k - 1); st = entropy->ac_stats[tbl] + 3 * k;
arith_encode(cinfo, st, 1); arith_encode(cinfo, st, 1);
} }
@ -549,6 +550,8 @@ encode_mcu_AC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
/* /*
* MCU encoding for DC successive approximation refinement scan. * MCU encoding for DC successive approximation refinement scan.
* Note: we assume such scans can be multi-component,
* although the spec is not very clear on the point.
*/ */
METHODDEF(boolean) METHODDEF(boolean)
@ -590,11 +593,11 @@ METHODDEF(boolean)
encode_mcu_AC_refine (j_compress_ptr cinfo, JBLOCKROW *MCU_data) encode_mcu_AC_refine (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
{ {
arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy; arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy;
const int * natural_order;
JBLOCKROW block; JBLOCKROW block;
unsigned char *st; unsigned char *st;
int tbl, k, ke, kex; int tbl, k, ke, kex;
int v; int v;
const int * natural_order;
/* Emit restart marker if needed */ /* Emit restart marker if needed */
if (cinfo->restart_interval) { if (cinfo->restart_interval) {
@ -616,7 +619,8 @@ encode_mcu_AC_refine (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
/* Section G.1.3.3: Encoding of AC coefficients */ /* Section G.1.3.3: Encoding of AC coefficients */
/* Establish EOB (end-of-block) index */ /* Establish EOB (end-of-block) index */
for (ke = cinfo->Se; ke > 0; ke--) ke = cinfo->Se;
do {
/* We must apply the point transform by Al. For AC coefficients this /* We must apply the point transform by Al. For AC coefficients this
* is an integer division with rounding towards 0. To do this portably * is an integer division with rounding towards 0. To do this portably
* in C, we shift after obtaining the absolute value. * in C, we shift after obtaining the absolute value.
@ -627,6 +631,7 @@ encode_mcu_AC_refine (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
v = -v; v = -v;
if (v >>= cinfo->Al) break; if (v >>= cinfo->Al) break;
} }
} while (--ke);
/* Establish EOBx (previous stage end-of-block) index */ /* Establish EOBx (previous stage end-of-block) index */
for (kex = ke; kex > 0; kex--) for (kex = ke; kex > 0; kex--)
@ -638,12 +643,12 @@ encode_mcu_AC_refine (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
} }
/* Figure G.10: Encode_AC_Coefficients_SA */ /* Figure G.10: Encode_AC_Coefficients_SA */
for (k = cinfo->Ss; k <= ke; k++) { for (k = cinfo->Ss - 1; k < ke;) {
st = entropy->ac_stats[tbl] + 3 * (k - 1); st = entropy->ac_stats[tbl] + 3 * k;
if (k > kex) if (k >= kex)
arith_encode(cinfo, st, 0); /* EOB decision */ arith_encode(cinfo, st, 0); /* EOB decision */
for (;;) { for (;;) {
if ((v = (*block)[natural_order[k]]) >= 0) { if ((v = (*block)[natural_order[++k]]) >= 0) {
if (v >>= cinfo->Al) { if (v >>= cinfo->Al) {
if (v >> 1) /* previously nonzero coef */ if (v >> 1) /* previously nonzero coef */
arith_encode(cinfo, st + 2, (v & 1)); arith_encode(cinfo, st + 2, (v & 1));
@ -665,12 +670,13 @@ encode_mcu_AC_refine (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
break; break;
} }
} }
arith_encode(cinfo, st + 1, 0); st += 3; k++; arith_encode(cinfo, st + 1, 0);
st += 3;
} }
} }
/* Encode EOB decision only if k <= cinfo->Se */ /* Encode EOB decision only if k < cinfo->Se */
if (k <= cinfo->Se) { if (k < cinfo->Se) {
st = entropy->ac_stats[tbl] + 3 * (k - 1); st = entropy->ac_stats[tbl] + 3 * k;
arith_encode(cinfo, st, 1); arith_encode(cinfo, st, 1);
} }
@ -686,12 +692,13 @@ METHODDEF(boolean)
encode_mcu (j_compress_ptr cinfo, JBLOCKROW *MCU_data) encode_mcu (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
{ {
arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy; arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy;
jpeg_component_info * compptr; const int * natural_order;
JBLOCKROW block; JBLOCKROW block;
unsigned char *st; unsigned char *st;
int blkn, ci, tbl, k, ke; int tbl, k, ke;
int v, v2, m; int v, v2, m;
const int * natural_order; int blkn, ci;
jpeg_component_info * compptr;
/* Emit restart marker if needed */ /* Emit restart marker if needed */
if (cinfo->restart_interval) { if (cinfo->restart_interval) {
@ -765,18 +772,21 @@ encode_mcu (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
/* Sections F.1.4.2 & F.1.4.4.2: Encoding of AC coefficients */ /* Sections F.1.4.2 & F.1.4.4.2: Encoding of AC coefficients */
if ((ke = cinfo->lim_Se) == 0) continue;
tbl = compptr->ac_tbl_no; tbl = compptr->ac_tbl_no;
/* Establish EOB (end-of-block) index */ /* Establish EOB (end-of-block) index */
for (ke = cinfo->lim_Se; ke > 0; ke--) do {
if ((*block)[natural_order[ke]]) break; if ((*block)[natural_order[ke]]) break;
} while (--ke);
/* Figure F.5: Encode_AC_Coefficients */ /* Figure F.5: Encode_AC_Coefficients */
for (k = 1; k <= ke; k++) { for (k = 0; k < ke;) {
st = entropy->ac_stats[tbl] + 3 * (k - 1); st = entropy->ac_stats[tbl] + 3 * k;
arith_encode(cinfo, st, 0); /* EOB decision */ arith_encode(cinfo, st, 0); /* EOB decision */
while ((v = (*block)[natural_order[k]]) == 0) { while ((v = (*block)[natural_order[++k]]) == 0) {
arith_encode(cinfo, st + 1, 0); st += 3; k++; arith_encode(cinfo, st + 1, 0);
st += 3;
} }
arith_encode(cinfo, st + 1, 1); arith_encode(cinfo, st + 1, 1);
/* Figure F.6: Encoding nonzero value v */ /* Figure F.6: Encoding nonzero value v */
@ -812,9 +822,9 @@ encode_mcu (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
while (m >>= 1) while (m >>= 1)
arith_encode(cinfo, st, (m & v) ? 1 : 0); arith_encode(cinfo, st, (m & v) ? 1 : 0);
} }
/* Encode EOB decision only if k <= cinfo->lim_Se */ /* Encode EOB decision only if k < cinfo->lim_Se */
if (k <= cinfo->lim_Se) { if (k < cinfo->lim_Se) {
st = entropy->ac_stats[tbl] + 3 * (k - 1); st = entropy->ac_stats[tbl] + 3 * k;
arith_encode(cinfo, st, 1); arith_encode(cinfo, st, 1);
} }
} }
@ -919,7 +929,7 @@ jinit_arith_encoder (j_compress_ptr cinfo)
entropy = (arith_entropy_ptr) entropy = (arith_entropy_ptr)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
SIZEOF(arith_entropy_encoder)); SIZEOF(arith_entropy_encoder));
cinfo->entropy = (struct jpeg_entropy_encoder *) entropy; cinfo->entropy = &entropy->pub;
entropy->pub.start_pass = start_pass; entropy->pub.start_pass = start_pass;
entropy->pub.finish_pass = finish_pass; entropy->pub.finish_pass = finish_pass;

View File

@ -2,6 +2,7 @@
* jccoefct.c * jccoefct.c
* *
* Copyright (C) 1994-1997, Thomas G. Lane. * Copyright (C) 1994-1997, Thomas G. Lane.
* Modified 2003-2011 by Guido Vollbeding.
* This file is part of the Independent JPEG Group's software. * This file is part of the Independent JPEG Group's software.
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
@ -183,16 +184,16 @@ compress_data (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
ypos, xpos, (JDIMENSION) blockcnt); ypos, xpos, (JDIMENSION) blockcnt);
if (blockcnt < compptr->MCU_width) { if (blockcnt < compptr->MCU_width) {
/* Create some dummy blocks at the right edge of the image. */ /* Create some dummy blocks at the right edge of the image. */
jzero_far((void FAR *) coef->MCU_buffer[blkn + blockcnt], FMEMZERO((void FAR *) coef->MCU_buffer[blkn + blockcnt],
(compptr->MCU_width - blockcnt) * SIZEOF(JBLOCK)); (compptr->MCU_width - blockcnt) * SIZEOF(JBLOCK));
for (bi = blockcnt; bi < compptr->MCU_width; bi++) { for (bi = blockcnt; bi < compptr->MCU_width; bi++) {
coef->MCU_buffer[blkn+bi][0][0] = coef->MCU_buffer[blkn+bi-1][0][0]; coef->MCU_buffer[blkn+bi][0][0] = coef->MCU_buffer[blkn+bi-1][0][0];
} }
} }
} else { } else {
/* Create a row of dummy blocks at the bottom of the image. */ /* Create a row of dummy blocks at the bottom of the image. */
jzero_far((void FAR *) coef->MCU_buffer[blkn], FMEMZERO((void FAR *) coef->MCU_buffer[blkn],
compptr->MCU_width * SIZEOF(JBLOCK)); compptr->MCU_width * SIZEOF(JBLOCK));
for (bi = 0; bi < compptr->MCU_width; bi++) { for (bi = 0; bi < compptr->MCU_width; bi++) {
coef->MCU_buffer[blkn+bi][0][0] = coef->MCU_buffer[blkn-1][0][0]; coef->MCU_buffer[blkn+bi][0][0] = coef->MCU_buffer[blkn-1][0][0];
} }
@ -290,7 +291,7 @@ compress_first_pass (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
if (ndummy > 0) { if (ndummy > 0) {
/* Create dummy blocks at the right edge of the image. */ /* Create dummy blocks at the right edge of the image. */
thisblockrow += blocks_across; /* => first dummy block */ thisblockrow += blocks_across; /* => first dummy block */
jzero_far((void FAR *) thisblockrow, ndummy * SIZEOF(JBLOCK)); FMEMZERO((void FAR *) thisblockrow, ndummy * SIZEOF(JBLOCK));
lastDC = thisblockrow[-1][0]; lastDC = thisblockrow[-1][0];
for (bi = 0; bi < ndummy; bi++) { for (bi = 0; bi < ndummy; bi++) {
thisblockrow[bi][0] = lastDC; thisblockrow[bi][0] = lastDC;
@ -309,8 +310,8 @@ compress_first_pass (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
block_row++) { block_row++) {
thisblockrow = buffer[block_row]; thisblockrow = buffer[block_row];
lastblockrow = buffer[block_row-1]; lastblockrow = buffer[block_row-1];
jzero_far((void FAR *) thisblockrow, FMEMZERO((void FAR *) thisblockrow,
(size_t) (blocks_across * SIZEOF(JBLOCK))); (size_t) (blocks_across * SIZEOF(JBLOCK)));
for (MCUindex = 0; MCUindex < MCUs_across; MCUindex++) { for (MCUindex = 0; MCUindex < MCUs_across; MCUindex++) {
lastDC = lastblockrow[h_samp_factor-1][0]; lastDC = lastblockrow[h_samp_factor-1][0];
for (bi = 0; bi < h_samp_factor; bi++) { for (bi = 0; bi < h_samp_factor; bi++) {

View File

@ -2,6 +2,7 @@
* jccolor.c * jccolor.c
* *
* Copyright (C) 1991-1996, Thomas G. Lane. * Copyright (C) 1991-1996, Thomas G. Lane.
* Modified 2011-2013 by Guido Vollbeding.
* This file is part of the Independent JPEG Group's software. * This file is part of the Independent JPEG Group's software.
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
@ -28,13 +29,25 @@ typedef my_color_converter * my_cconvert_ptr;
/**************** RGB -> YCbCr conversion: most common case **************/ /**************** RGB -> YCbCr conversion: most common case **************/
/* /*
* YCbCr is defined per CCIR 601-1, except that Cb and Cr are * YCbCr is defined per Recommendation ITU-R BT.601-7 (03/2011),
* normalized to the range 0..MAXJSAMPLE rather than -0.5 .. 0.5. * previously known as Recommendation CCIR 601-1, except that Cb and Cr
* The conversion equations to be implemented are therefore * are normalized to the range 0..MAXJSAMPLE rather than -0.5 .. 0.5.
* Y = 0.29900 * R + 0.58700 * G + 0.11400 * B * sRGB (standard RGB color space) is defined per IEC 61966-2-1:1999.
* Cb = -0.16874 * R - 0.33126 * G + 0.50000 * B + CENTERJSAMPLE * sYCC (standard luma-chroma-chroma color space with extended gamut)
* Cr = 0.50000 * R - 0.41869 * G - 0.08131 * B + CENTERJSAMPLE * is defined per IEC 61966-2-1:1999 Amendment A1:2003 Annex F.
* (These numbers are derived from TIFF 6.0 section 21, dated 3-June-92.) * bg-sRGB and bg-sYCC (big gamut standard color spaces)
* are defined per IEC 61966-2-1:1999 Amendment A1:2003 Annex G.
* Note that the derived conversion coefficients given in some of these
* documents are imprecise. The general conversion equations are
* Y = Kr * R + (1 - Kr - Kb) * G + Kb * B
* Cb = 0.5 * (B - Y) / (1 - Kb)
* Cr = 0.5 * (R - Y) / (1 - Kr)
* With Kr = 0.299 and Kb = 0.114 (derived according to SMPTE RP 177-1993
* from the 1953 FCC NTSC primaries and CIE Illuminant C),
* the conversion equations to be implemented are therefore
* Y = 0.299 * R + 0.587 * G + 0.114 * B
* Cb = -0.168735892 * R - 0.331264108 * G + 0.5 * B + CENTERJSAMPLE
* Cr = 0.5 * R - 0.418687589 * G - 0.081312411 * B + CENTERJSAMPLE
* Note: older versions of the IJG code used a zero offset of MAXJSAMPLE/2, * Note: older versions of the IJG code used a zero offset of MAXJSAMPLE/2,
* rather than CENTERJSAMPLE, for Cb and Cr. This gave equal positive and * rather than CENTERJSAMPLE, for Cb and Cr. This gave equal positive and
* negative swings for Cb/Cr, but meant that grayscale values (Cb=Cr=0) * negative swings for Cb/Cr, but meant that grayscale values (Cb=Cr=0)
@ -48,9 +61,9 @@ typedef my_color_converter * my_cconvert_ptr;
* For even more speed, we avoid doing any multiplications in the inner loop * For even more speed, we avoid doing any multiplications in the inner loop
* by precalculating the constants times R,G,B for all possible values. * by precalculating the constants times R,G,B for all possible values.
* For 8-bit JSAMPLEs this is very reasonable (only 256 entries per table); * For 8-bit JSAMPLEs this is very reasonable (only 256 entries per table);
* for 12-bit samples it is still acceptable. It's not very reasonable for * for 9-bit to 12-bit samples it is still acceptable. It's not very
* 16-bit samples, but if you want lossless storage you shouldn't be changing * reasonable for 16-bit samples, but if you want lossless storage you
* colorspace anyway. * shouldn't be changing colorspace anyway.
* The CENTERJSAMPLE offsets and the rounding fudge-factor of 0.5 are included * The CENTERJSAMPLE offsets and the rounding fudge-factor of 0.5 are included
* in the tables to save adding them separately in the inner loop. * in the tables to save adding them separately in the inner loop.
*/ */
@ -95,21 +108,21 @@ rgb_ycc_start (j_compress_ptr cinfo)
(TABLE_SIZE * SIZEOF(INT32))); (TABLE_SIZE * SIZEOF(INT32)));
for (i = 0; i <= MAXJSAMPLE; i++) { for (i = 0; i <= MAXJSAMPLE; i++) {
rgb_ycc_tab[i+R_Y_OFF] = FIX(0.29900) * i; rgb_ycc_tab[i+R_Y_OFF] = FIX(0.299) * i;
rgb_ycc_tab[i+G_Y_OFF] = FIX(0.58700) * i; rgb_ycc_tab[i+G_Y_OFF] = FIX(0.587) * i;
rgb_ycc_tab[i+B_Y_OFF] = FIX(0.11400) * i + ONE_HALF; rgb_ycc_tab[i+B_Y_OFF] = FIX(0.114) * i + ONE_HALF;
rgb_ycc_tab[i+R_CB_OFF] = (-FIX(0.16874)) * i; rgb_ycc_tab[i+R_CB_OFF] = (-FIX(0.168735892)) * i;
rgb_ycc_tab[i+G_CB_OFF] = (-FIX(0.33126)) * i; rgb_ycc_tab[i+G_CB_OFF] = (-FIX(0.331264108)) * i;
/* We use a rounding fudge-factor of 0.5-epsilon for Cb and Cr. /* We use a rounding fudge-factor of 0.5-epsilon for Cb and Cr.
* This ensures that the maximum output will round to MAXJSAMPLE * This ensures that the maximum output will round to MAXJSAMPLE
* not MAXJSAMPLE+1, and thus that we don't have to range-limit. * not MAXJSAMPLE+1, and thus that we don't have to range-limit.
*/ */
rgb_ycc_tab[i+B_CB_OFF] = FIX(0.50000) * i + CBCR_OFFSET + ONE_HALF-1; rgb_ycc_tab[i+B_CB_OFF] = FIX(0.5) * i + CBCR_OFFSET + ONE_HALF-1;
/* B=>Cb and R=>Cr tables are the same /* B=>Cb and R=>Cr tables are the same
rgb_ycc_tab[i+R_CR_OFF] = FIX(0.50000) * i + CBCR_OFFSET + ONE_HALF-1; rgb_ycc_tab[i+R_CR_OFF] = FIX(0.5) * i + CBCR_OFFSET + ONE_HALF-1;
*/ */
rgb_ycc_tab[i+G_CR_OFF] = (-FIX(0.41869)) * i; rgb_ycc_tab[i+G_CR_OFF] = (-FIX(0.418687589)) * i;
rgb_ycc_tab[i+B_CR_OFF] = (-FIX(0.08131)) * i; rgb_ycc_tab[i+B_CR_OFF] = (-FIX(0.081312411)) * i;
} }
} }
@ -132,8 +145,8 @@ rgb_ycc_convert (j_compress_ptr cinfo,
JDIMENSION output_row, int num_rows) JDIMENSION output_row, int num_rows)
{ {
my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert; my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
register int r, g, b;
register INT32 * ctab = cconvert->rgb_ycc_tab; register INT32 * ctab = cconvert->rgb_ycc_tab;
register int r, g, b;
register JSAMPROW inptr; register JSAMPROW inptr;
register JSAMPROW outptr0, outptr1, outptr2; register JSAMPROW outptr0, outptr1, outptr2;
register JDIMENSION col; register JDIMENSION col;
@ -149,7 +162,6 @@ rgb_ycc_convert (j_compress_ptr cinfo,
r = GETJSAMPLE(inptr[RGB_RED]); r = GETJSAMPLE(inptr[RGB_RED]);
g = GETJSAMPLE(inptr[RGB_GREEN]); g = GETJSAMPLE(inptr[RGB_GREEN]);
b = GETJSAMPLE(inptr[RGB_BLUE]); b = GETJSAMPLE(inptr[RGB_BLUE]);
inptr += RGB_PIXELSIZE;
/* If the inputs are 0..MAXJSAMPLE, the outputs of these equations /* If the inputs are 0..MAXJSAMPLE, the outputs of these equations
* must be too; we do not need an explicit range-limiting operation. * must be too; we do not need an explicit range-limiting operation.
* Hence the value being shifted is never negative, and we don't * Hence the value being shifted is never negative, and we don't
@ -167,6 +179,7 @@ rgb_ycc_convert (j_compress_ptr cinfo,
outptr2[col] = (JSAMPLE) outptr2[col] = (JSAMPLE)
((ctab[r+R_CR_OFF] + ctab[g+G_CR_OFF] + ctab[b+B_CR_OFF]) ((ctab[r+R_CR_OFF] + ctab[g+G_CR_OFF] + ctab[b+B_CR_OFF])
>> SCALEBITS); >> SCALEBITS);
inptr += RGB_PIXELSIZE;
} }
} }
} }
@ -188,8 +201,8 @@ rgb_gray_convert (j_compress_ptr cinfo,
JDIMENSION output_row, int num_rows) JDIMENSION output_row, int num_rows)
{ {
my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert; my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
register int r, g, b;
register INT32 * ctab = cconvert->rgb_ycc_tab; register INT32 * ctab = cconvert->rgb_ycc_tab;
register int r, g, b;
register JSAMPROW inptr; register JSAMPROW inptr;
register JSAMPROW outptr; register JSAMPROW outptr;
register JDIMENSION col; register JDIMENSION col;
@ -197,17 +210,16 @@ rgb_gray_convert (j_compress_ptr cinfo,
while (--num_rows >= 0) { while (--num_rows >= 0) {
inptr = *input_buf++; inptr = *input_buf++;
outptr = output_buf[0][output_row]; outptr = output_buf[0][output_row++];
output_row++;
for (col = 0; col < num_cols; col++) { for (col = 0; col < num_cols; col++) {
r = GETJSAMPLE(inptr[RGB_RED]); r = GETJSAMPLE(inptr[RGB_RED]);
g = GETJSAMPLE(inptr[RGB_GREEN]); g = GETJSAMPLE(inptr[RGB_GREEN]);
b = GETJSAMPLE(inptr[RGB_BLUE]); b = GETJSAMPLE(inptr[RGB_BLUE]);
inptr += RGB_PIXELSIZE;
/* Y */ /* Y */
outptr[col] = (JSAMPLE) outptr[col] = (JSAMPLE)
((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF]) ((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])
>> SCALEBITS); >> SCALEBITS);
inptr += RGB_PIXELSIZE;
} }
} }
} }
@ -227,8 +239,8 @@ cmyk_ycck_convert (j_compress_ptr cinfo,
JDIMENSION output_row, int num_rows) JDIMENSION output_row, int num_rows)
{ {
my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert; my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
register int r, g, b;
register INT32 * ctab = cconvert->rgb_ycc_tab; register INT32 * ctab = cconvert->rgb_ycc_tab;
register int r, g, b;
register JSAMPROW inptr; register JSAMPROW inptr;
register JSAMPROW outptr0, outptr1, outptr2, outptr3; register JSAMPROW outptr0, outptr1, outptr2, outptr3;
register JDIMENSION col; register JDIMENSION col;
@ -247,7 +259,6 @@ cmyk_ycck_convert (j_compress_ptr cinfo,
b = MAXJSAMPLE - GETJSAMPLE(inptr[2]); b = MAXJSAMPLE - GETJSAMPLE(inptr[2]);
/* K passes through as-is */ /* K passes through as-is */
outptr3[col] = inptr[3]; /* don't need GETJSAMPLE here */ outptr3[col] = inptr[3]; /* don't need GETJSAMPLE here */
inptr += 4;
/* If the inputs are 0..MAXJSAMPLE, the outputs of these equations /* If the inputs are 0..MAXJSAMPLE, the outputs of these equations
* must be too; we do not need an explicit range-limiting operation. * must be too; we do not need an explicit range-limiting operation.
* Hence the value being shifted is never negative, and we don't * Hence the value being shifted is never negative, and we don't
@ -265,6 +276,49 @@ cmyk_ycck_convert (j_compress_ptr cinfo,
outptr2[col] = (JSAMPLE) outptr2[col] = (JSAMPLE)
((ctab[r+R_CR_OFF] + ctab[g+G_CR_OFF] + ctab[b+B_CR_OFF]) ((ctab[r+R_CR_OFF] + ctab[g+G_CR_OFF] + ctab[b+B_CR_OFF])
>> SCALEBITS); >> SCALEBITS);
inptr += 4;
}
}
}
/*
* Convert some rows of samples to the JPEG colorspace.
* [R,G,B] to [R-G,G,B-G] conversion with modulo calculation
* (forward reversible color transform).
* This can be seen as an adaption of the general RGB->YCbCr
* conversion equation with Kr = Kb = 0, while replacing the
* normalization by modulo calculation.
*/
METHODDEF(void)
rgb_rgb1_convert (j_compress_ptr cinfo,
JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
JDIMENSION output_row, int num_rows)
{
register int r, g, b;
register JSAMPROW inptr;
register JSAMPROW outptr0, outptr1, outptr2;
register JDIMENSION col;
JDIMENSION num_cols = cinfo->image_width;
while (--num_rows >= 0) {
inptr = *input_buf++;
outptr0 = output_buf[0][output_row];
outptr1 = output_buf[1][output_row];
outptr2 = output_buf[2][output_row];
output_row++;
for (col = 0; col < num_cols; col++) {
r = GETJSAMPLE(inptr[RGB_RED]);
g = GETJSAMPLE(inptr[RGB_GREEN]);
b = GETJSAMPLE(inptr[RGB_BLUE]);
/* Assume that MAXJSAMPLE+1 is a power of 2, so that the MOD
* (modulo) operator is equivalent to the bitmask operator AND.
*/
outptr0[col] = (JSAMPLE) ((r - g + CENTERJSAMPLE) & MAXJSAMPLE);
outptr1[col] = (JSAMPLE) g;
outptr2[col] = (JSAMPLE) ((b - g + CENTERJSAMPLE) & MAXJSAMPLE);
inptr += RGB_PIXELSIZE;
} }
} }
} }
@ -273,7 +327,7 @@ cmyk_ycck_convert (j_compress_ptr cinfo,
/* /*
* Convert some rows of samples to the JPEG colorspace. * Convert some rows of samples to the JPEG colorspace.
* This version handles grayscale output with no conversion. * This version handles grayscale output with no conversion.
* The source can be either plain grayscale or YCbCr (since Y == gray). * The source can be either plain grayscale or YCC (since Y == gray).
*/ */
METHODDEF(void) METHODDEF(void)
@ -281,16 +335,15 @@ grayscale_convert (j_compress_ptr cinfo,
JSAMPARRAY input_buf, JSAMPIMAGE output_buf, JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
JDIMENSION output_row, int num_rows) JDIMENSION output_row, int num_rows)
{ {
int instride = cinfo->input_components;
register JSAMPROW inptr; register JSAMPROW inptr;
register JSAMPROW outptr; register JSAMPROW outptr;
register JDIMENSION col; register JDIMENSION col;
JDIMENSION num_cols = cinfo->image_width; JDIMENSION num_cols = cinfo->image_width;
int instride = cinfo->input_components;
while (--num_rows >= 0) { while (--num_rows >= 0) {
inptr = *input_buf++; inptr = *input_buf++;
outptr = output_buf[0][output_row]; outptr = output_buf[0][output_row++];
output_row++;
for (col = 0; col < num_cols; col++) { for (col = 0; col < num_cols; col++) {
outptr[col] = inptr[0]; /* don't need GETJSAMPLE() here */ outptr[col] = inptr[0]; /* don't need GETJSAMPLE() here */
inptr += instride; inptr += instride;
@ -299,6 +352,39 @@ grayscale_convert (j_compress_ptr cinfo,
} }
/*
* Convert some rows of samples to the JPEG colorspace.
* No colorspace conversion, but change from interleaved
* to separate-planes representation.
*/
METHODDEF(void)
rgb_convert (j_compress_ptr cinfo,
JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
JDIMENSION output_row, int num_rows)
{
register JSAMPROW inptr;
register JSAMPROW outptr0, outptr1, outptr2;
register JDIMENSION col;
JDIMENSION num_cols = cinfo->image_width;
while (--num_rows >= 0) {
inptr = *input_buf++;
outptr0 = output_buf[0][output_row];
outptr1 = output_buf[1][output_row];
outptr2 = output_buf[2][output_row];
output_row++;
for (col = 0; col < num_cols; col++) {
/* We can dispense with GETJSAMPLE() here */
outptr0[col] = inptr[RGB_RED];
outptr1[col] = inptr[RGB_GREEN];
outptr2[col] = inptr[RGB_BLUE];
inptr += RGB_PIXELSIZE;
}
}
}
/* /*
* Convert some rows of samples to the JPEG colorspace. * Convert some rows of samples to the JPEG colorspace.
* This version handles multi-component colorspaces without conversion. * This version handles multi-component colorspaces without conversion.
@ -310,20 +396,20 @@ null_convert (j_compress_ptr cinfo,
JSAMPARRAY input_buf, JSAMPIMAGE output_buf, JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
JDIMENSION output_row, int num_rows) JDIMENSION output_row, int num_rows)
{ {
int ci;
register int nc = cinfo->num_components;
register JSAMPROW inptr; register JSAMPROW inptr;
register JSAMPROW outptr; register JSAMPROW outptr;
register JDIMENSION col; register JDIMENSION col;
register int ci;
int nc = cinfo->num_components;
JDIMENSION num_cols = cinfo->image_width; JDIMENSION num_cols = cinfo->image_width;
while (--num_rows >= 0) { while (--num_rows >= 0) {
/* It seems fastest to make a separate pass for each component. */ /* It seems fastest to make a separate pass for each component. */
for (ci = 0; ci < nc; ci++) { for (ci = 0; ci < nc; ci++) {
inptr = *input_buf; inptr = input_buf[0] + ci;
outptr = output_buf[ci][output_row]; outptr = output_buf[ci][output_row];
for (col = 0; col < num_cols; col++) { for (col = 0; col < num_cols; col++) {
outptr[col] = inptr[ci]; /* don't need GETJSAMPLE() here */ *outptr++ = *inptr; /* don't need GETJSAMPLE() here */
inptr += nc; inptr += nc;
} }
} }
@ -356,7 +442,7 @@ jinit_color_converter (j_compress_ptr cinfo)
cconvert = (my_cconvert_ptr) cconvert = (my_cconvert_ptr)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
SIZEOF(my_color_converter)); SIZEOF(my_color_converter));
cinfo->cconvert = (struct jpeg_color_converter *) cconvert; cinfo->cconvert = &cconvert->pub;
/* set start_pass to null method until we find out differently */ /* set start_pass to null method until we find out differently */
cconvert->pub.start_pass = null_method; cconvert->pub.start_pass = null_method;
@ -368,13 +454,13 @@ jinit_color_converter (j_compress_ptr cinfo)
break; break;
case JCS_RGB: case JCS_RGB:
#if RGB_PIXELSIZE != 3 case JCS_BG_RGB:
if (cinfo->input_components != RGB_PIXELSIZE) if (cinfo->input_components != RGB_PIXELSIZE)
ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
break; break;
#endif /* else share code with YCbCr */
case JCS_YCbCr: case JCS_YCbCr:
case JCS_BG_YCC:
if (cinfo->input_components != 3) if (cinfo->input_components != 3)
ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
break; break;
@ -391,41 +477,96 @@ jinit_color_converter (j_compress_ptr cinfo)
break; break;
} }
/* Support color transform only for RGB colorspaces */
if (cinfo->color_transform &&
cinfo->jpeg_color_space != JCS_RGB &&
cinfo->jpeg_color_space != JCS_BG_RGB)
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
/* Check num_components, set conversion method based on requested space */ /* Check num_components, set conversion method based on requested space */
switch (cinfo->jpeg_color_space) { switch (cinfo->jpeg_color_space) {
case JCS_GRAYSCALE: case JCS_GRAYSCALE:
if (cinfo->num_components != 1) if (cinfo->num_components != 1)
ERREXIT(cinfo, JERR_BAD_J_COLORSPACE); ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
if (cinfo->in_color_space == JCS_GRAYSCALE) switch (cinfo->in_color_space) {
case JCS_GRAYSCALE:
case JCS_YCbCr:
case JCS_BG_YCC:
cconvert->pub.color_convert = grayscale_convert; cconvert->pub.color_convert = grayscale_convert;
else if (cinfo->in_color_space == JCS_RGB) { break;
case JCS_RGB:
cconvert->pub.start_pass = rgb_ycc_start; cconvert->pub.start_pass = rgb_ycc_start;
cconvert->pub.color_convert = rgb_gray_convert; cconvert->pub.color_convert = rgb_gray_convert;
} else if (cinfo->in_color_space == JCS_YCbCr) break;
cconvert->pub.color_convert = grayscale_convert; default:
else
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL); ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
}
break; break;
case JCS_RGB: case JCS_RGB:
case JCS_BG_RGB:
if (cinfo->num_components != 3) if (cinfo->num_components != 3)
ERREXIT(cinfo, JERR_BAD_J_COLORSPACE); ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
if (cinfo->in_color_space == JCS_RGB && RGB_PIXELSIZE == 3) if (cinfo->in_color_space == cinfo->jpeg_color_space) {
cconvert->pub.color_convert = null_convert; switch (cinfo->color_transform) {
else case JCT_NONE:
cconvert->pub.color_convert = rgb_convert;
break;
case JCT_SUBTRACT_GREEN:
cconvert->pub.color_convert = rgb_rgb1_convert;
break;
default:
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
}
} else
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL); ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
break; break;
case JCS_YCbCr: case JCS_YCbCr:
if (cinfo->num_components != 3) if (cinfo->num_components != 3)
ERREXIT(cinfo, JERR_BAD_J_COLORSPACE); ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
if (cinfo->in_color_space == JCS_RGB) { switch (cinfo->in_color_space) {
case JCS_RGB:
cconvert->pub.start_pass = rgb_ycc_start; cconvert->pub.start_pass = rgb_ycc_start;
cconvert->pub.color_convert = rgb_ycc_convert; cconvert->pub.color_convert = rgb_ycc_convert;
} else if (cinfo->in_color_space == JCS_YCbCr) break;
case JCS_YCbCr:
cconvert->pub.color_convert = null_convert; cconvert->pub.color_convert = null_convert;
else break;
default:
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL); ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
}
break;
case JCS_BG_YCC:
if (cinfo->num_components != 3)
ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
switch (cinfo->in_color_space) {
case JCS_RGB:
/* For conversion from normal RGB input to BG_YCC representation,
* the Cb/Cr values are first computed as usual, and then
* quantized further after DCT processing by a factor of
* 2 in reference to the nominal quantization factor.
*/
/* need quantization scale by factor of 2 after DCT */
cinfo->comp_info[1].component_needed = TRUE;
cinfo->comp_info[2].component_needed = TRUE;
/* compute normal YCC first */
cconvert->pub.start_pass = rgb_ycc_start;
cconvert->pub.color_convert = rgb_ycc_convert;
break;
case JCS_YCbCr:
/* need quantization scale by factor of 2 after DCT */
cinfo->comp_info[1].component_needed = TRUE;
cinfo->comp_info[2].component_needed = TRUE;
/*FALLTHROUGH*/
case JCS_BG_YCC:
/* Pass through for BG_YCC input */
cconvert->pub.color_convert = null_convert;
break;
default:
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
}
break; break;
case JCS_CMYK: case JCS_CMYK:
@ -440,13 +581,17 @@ jinit_color_converter (j_compress_ptr cinfo)
case JCS_YCCK: case JCS_YCCK:
if (cinfo->num_components != 4) if (cinfo->num_components != 4)
ERREXIT(cinfo, JERR_BAD_J_COLORSPACE); ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
if (cinfo->in_color_space == JCS_CMYK) { switch (cinfo->in_color_space) {
case JCS_CMYK:
cconvert->pub.start_pass = rgb_ycc_start; cconvert->pub.start_pass = rgb_ycc_start;
cconvert->pub.color_convert = cmyk_ycck_convert; cconvert->pub.color_convert = cmyk_ycck_convert;
} else if (cinfo->in_color_space == JCS_YCCK) break;
case JCS_YCCK:
cconvert->pub.color_convert = null_convert; cconvert->pub.color_convert = null_convert;
else break;
default:
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL); ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
}
break; break;
default: /* allow null conversion of JCS_UNKNOWN */ default: /* allow null conversion of JCS_UNKNOWN */

View File

@ -2,6 +2,7 @@
* jcdctmgr.c * jcdctmgr.c
* *
* Copyright (C) 1994-1996, Thomas G. Lane. * Copyright (C) 1994-1996, Thomas G. Lane.
* Modified 2003-2013 by Guido Vollbeding.
* This file is part of the Independent JPEG Group's software. * This file is part of the Independent JPEG Group's software.
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
@ -25,22 +26,30 @@ typedef struct {
/* Pointer to the DCT routine actually in use */ /* Pointer to the DCT routine actually in use */
forward_DCT_method_ptr do_dct[MAX_COMPONENTS]; forward_DCT_method_ptr do_dct[MAX_COMPONENTS];
/* The actual post-DCT divisors --- not identical to the quant table
* entries, because of scaling (especially for an unnormalized DCT).
* Each table is given in normal array order.
*/
DCTELEM * divisors[NUM_QUANT_TBLS];
#ifdef DCT_FLOAT_SUPPORTED #ifdef DCT_FLOAT_SUPPORTED
/* Same as above for the floating-point case. */ /* Same as above for the floating-point case. */
float_DCT_method_ptr do_float_dct[MAX_COMPONENTS]; float_DCT_method_ptr do_float_dct[MAX_COMPONENTS];
FAST_FLOAT * float_divisors[NUM_QUANT_TBLS];
#endif #endif
} my_fdct_controller; } my_fdct_controller;
typedef my_fdct_controller * my_fdct_ptr; typedef my_fdct_controller * my_fdct_ptr;
/* The allocated post-DCT divisor tables -- big enough for any
* supported variant and not identical to the quant table entries,
* because of scaling (especially for an unnormalized DCT) --
* are pointed to by dct_table in the per-component comp_info
* structures. Each table is given in normal array order.
*/
typedef union {
DCTELEM int_array[DCTSIZE2];
#ifdef DCT_FLOAT_SUPPORTED
FAST_FLOAT float_array[DCTSIZE2];
#endif
} divisor_table;
/* The current scaled-DCT routines require ISLOW-style divisor tables, /* The current scaled-DCT routines require ISLOW-style divisor tables,
* so be sure to compile that code if either ISLOW or SCALING is requested. * so be sure to compile that code if either ISLOW or SCALING is requested.
*/ */
@ -71,7 +80,7 @@ forward_DCT (j_compress_ptr cinfo, jpeg_component_info * compptr,
/* This routine is heavily used, so it's worth coding it tightly. */ /* This routine is heavily used, so it's worth coding it tightly. */
my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct; my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct;
forward_DCT_method_ptr do_dct = fdct->do_dct[compptr->component_index]; forward_DCT_method_ptr do_dct = fdct->do_dct[compptr->component_index];
DCTELEM * divisors = fdct->divisors[compptr->quant_tbl_no]; DCTELEM * divisors = (DCTELEM *) compptr->dct_table;
DCTELEM workspace[DCTSIZE2]; /* work area for FDCT subroutine */ DCTELEM workspace[DCTSIZE2]; /* work area for FDCT subroutine */
JDIMENSION bi; JDIMENSION bi;
@ -134,7 +143,7 @@ forward_DCT_float (j_compress_ptr cinfo, jpeg_component_info * compptr,
/* This routine is heavily used, so it's worth coding it tightly. */ /* This routine is heavily used, so it's worth coding it tightly. */
my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct; my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct;
float_DCT_method_ptr do_dct = fdct->do_float_dct[compptr->component_index]; float_DCT_method_ptr do_dct = fdct->do_float_dct[compptr->component_index];
FAST_FLOAT * divisors = fdct->float_divisors[compptr->quant_tbl_no]; FAST_FLOAT * divisors = (FAST_FLOAT *) compptr->dct_table;
FAST_FLOAT workspace[DCTSIZE2]; /* work area for FDCT subroutine */ FAST_FLOAT workspace[DCTSIZE2]; /* work area for FDCT subroutine */
JDIMENSION bi; JDIMENSION bi;
@ -352,22 +361,17 @@ start_pass_fdctmgr (j_compress_ptr cinfo)
cinfo->quant_tbl_ptrs[qtblno] == NULL) cinfo->quant_tbl_ptrs[qtblno] == NULL)
ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, qtblno); ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, qtblno);
qtbl = cinfo->quant_tbl_ptrs[qtblno]; qtbl = cinfo->quant_tbl_ptrs[qtblno];
/* Compute divisors for this quant table */ /* Create divisor table from quant table */
/* We may do this more than once for same table, but it's not a big deal */
switch (method) { switch (method) {
#ifdef PROVIDE_ISLOW_TABLES #ifdef PROVIDE_ISLOW_TABLES
case JDCT_ISLOW: case JDCT_ISLOW:
/* For LL&M IDCT method, divisors are equal to raw quantization /* For LL&M IDCT method, divisors are equal to raw quantization
* coefficients multiplied by 8 (to counteract scaling). * coefficients multiplied by 8 (to counteract scaling).
*/ */
if (fdct->divisors[qtblno] == NULL) { dtbl = (DCTELEM *) compptr->dct_table;
fdct->divisors[qtblno] = (DCTELEM *)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
DCTSIZE2 * SIZEOF(DCTELEM));
}
dtbl = fdct->divisors[qtblno];
for (i = 0; i < DCTSIZE2; i++) { for (i = 0; i < DCTSIZE2; i++) {
dtbl[i] = ((DCTELEM) qtbl->quantval[i]) << 3; dtbl[i] =
((DCTELEM) qtbl->quantval[i]) << (compptr->component_needed ? 4 : 3);
} }
fdct->pub.forward_DCT[ci] = forward_DCT; fdct->pub.forward_DCT[ci] = forward_DCT;
break; break;
@ -395,17 +399,12 @@ start_pass_fdctmgr (j_compress_ptr cinfo)
}; };
SHIFT_TEMPS SHIFT_TEMPS
if (fdct->divisors[qtblno] == NULL) { dtbl = (DCTELEM *) compptr->dct_table;
fdct->divisors[qtblno] = (DCTELEM *)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
DCTSIZE2 * SIZEOF(DCTELEM));
}
dtbl = fdct->divisors[qtblno];
for (i = 0; i < DCTSIZE2; i++) { for (i = 0; i < DCTSIZE2; i++) {
dtbl[i] = (DCTELEM) dtbl[i] = (DCTELEM)
DESCALE(MULTIPLY16V16((INT32) qtbl->quantval[i], DESCALE(MULTIPLY16V16((INT32) qtbl->quantval[i],
(INT32) aanscales[i]), (INT32) aanscales[i]),
CONST_BITS-3); compptr->component_needed ? CONST_BITS-4 : CONST_BITS-3);
} }
} }
fdct->pub.forward_DCT[ci] = forward_DCT; fdct->pub.forward_DCT[ci] = forward_DCT;
@ -422,25 +421,20 @@ start_pass_fdctmgr (j_compress_ptr cinfo)
* What's actually stored is 1/divisor so that the inner loop can * What's actually stored is 1/divisor so that the inner loop can
* use a multiplication rather than a division. * use a multiplication rather than a division.
*/ */
FAST_FLOAT * fdtbl; FAST_FLOAT * fdtbl = (FAST_FLOAT *) compptr->dct_table;
int row, col; int row, col;
static const double aanscalefactor[DCTSIZE] = { static const double aanscalefactor[DCTSIZE] = {
1.0, 1.387039845, 1.306562965, 1.175875602, 1.0, 1.387039845, 1.306562965, 1.175875602,
1.0, 0.785694958, 0.541196100, 0.275899379 1.0, 0.785694958, 0.541196100, 0.275899379
}; };
if (fdct->float_divisors[qtblno] == NULL) {
fdct->float_divisors[qtblno] = (FAST_FLOAT *)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
DCTSIZE2 * SIZEOF(FAST_FLOAT));
}
fdtbl = fdct->float_divisors[qtblno];
i = 0; i = 0;
for (row = 0; row < DCTSIZE; row++) { for (row = 0; row < DCTSIZE; row++) {
for (col = 0; col < DCTSIZE; col++) { for (col = 0; col < DCTSIZE; col++) {
fdtbl[i] = (FAST_FLOAT) fdtbl[i] = (FAST_FLOAT)
(1.0 / (((double) qtbl->quantval[i] * (1.0 / ((double) qtbl->quantval[i] *
aanscalefactor[row] * aanscalefactor[col] * 8.0))); aanscalefactor[row] * aanscalefactor[col] *
(compptr->component_needed ? 16.0 : 8.0)));
i++; i++;
} }
} }
@ -464,19 +458,20 @@ GLOBAL(void)
jinit_forward_dct (j_compress_ptr cinfo) jinit_forward_dct (j_compress_ptr cinfo)
{ {
my_fdct_ptr fdct; my_fdct_ptr fdct;
int i; int ci;
jpeg_component_info *compptr;
fdct = (my_fdct_ptr) fdct = (my_fdct_ptr)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
SIZEOF(my_fdct_controller)); SIZEOF(my_fdct_controller));
cinfo->fdct = (struct jpeg_forward_dct *) fdct; cinfo->fdct = &fdct->pub;
fdct->pub.start_pass = start_pass_fdctmgr; fdct->pub.start_pass = start_pass_fdctmgr;
/* Mark divisor tables unallocated */ for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
for (i = 0; i < NUM_QUANT_TBLS; i++) { ci++, compptr++) {
fdct->divisors[i] = NULL; /* Allocate a divisor table for each component */
#ifdef DCT_FLOAT_SUPPORTED compptr->dct_table =
fdct->float_divisors[i] = NULL; (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
#endif SIZEOF(divisor_table));
} }
} }

View File

@ -2,7 +2,7 @@
* jchuff.c * jchuff.c
* *
* Copyright (C) 1991-1997, Thomas G. Lane. * Copyright (C) 1991-1997, Thomas G. Lane.
* Modified 2006-2009 by Guido Vollbeding. * Modified 2006-2013 by Guido Vollbeding.
* This file is part of the Independent JPEG Group's software. * This file is part of the Independent JPEG Group's software.
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
@ -308,24 +308,27 @@ emit_bits_s (working_state * state, unsigned int code, int size)
/* Emit some bits; return TRUE if successful, FALSE if must suspend */ /* Emit some bits; return TRUE if successful, FALSE if must suspend */
{ {
/* This routine is heavily used, so it's worth coding tightly. */ /* This routine is heavily used, so it's worth coding tightly. */
register INT32 put_buffer = (INT32) code; register INT32 put_buffer;
register int put_bits = state->cur.put_bits; register int put_bits;
/* if size is 0, caller used an invalid Huffman table entry */ /* if size is 0, caller used an invalid Huffman table entry */
if (size == 0) if (size == 0)
ERREXIT(state->cinfo, JERR_HUFF_MISSING_CODE); ERREXIT(state->cinfo, JERR_HUFF_MISSING_CODE);
put_buffer &= (((INT32) 1)<<size) - 1; /* mask off any extra bits in code */ /* mask off any extra bits in code */
put_buffer = ((INT32) code) & ((((INT32) 1) << size) - 1);
put_bits += size; /* new number of bits in buffer */
/* new number of bits in buffer */
put_bits = size + state->cur.put_bits;
put_buffer <<= 24 - put_bits; /* align incoming bits */ put_buffer <<= 24 - put_bits; /* align incoming bits */
put_buffer |= state->cur.put_buffer; /* and merge with old buffer contents */ /* and merge with old buffer contents */
put_buffer |= state->cur.put_buffer;
while (put_bits >= 8) { while (put_bits >= 8) {
int c = (int) ((put_buffer >> 16) & 0xFF); int c = (int) ((put_buffer >> 16) & 0xFF);
emit_byte_s(state, c, return FALSE); emit_byte_s(state, c, return FALSE);
if (c == 0xFF) { /* need to stuff a zero byte? */ if (c == 0xFF) { /* need to stuff a zero byte? */
emit_byte_s(state, 0, return FALSE); emit_byte_s(state, 0, return FALSE);
@ -347,8 +350,8 @@ emit_bits_e (huff_entropy_ptr entropy, unsigned int code, int size)
/* Emit some bits, unless we are in gather mode */ /* Emit some bits, unless we are in gather mode */
{ {
/* This routine is heavily used, so it's worth coding tightly. */ /* This routine is heavily used, so it's worth coding tightly. */
register INT32 put_buffer = (INT32) code; register INT32 put_buffer;
register int put_bits = entropy->saved.put_bits; register int put_bits;
/* if size is 0, caller used an invalid Huffman table entry */ /* if size is 0, caller used an invalid Huffman table entry */
if (size == 0) if (size == 0)
@ -357,9 +360,11 @@ emit_bits_e (huff_entropy_ptr entropy, unsigned int code, int size)
if (entropy->gather_statistics) if (entropy->gather_statistics)
return; /* do nothing if we're only getting stats */ return; /* do nothing if we're only getting stats */
put_buffer &= (((INT32) 1)<<size) - 1; /* mask off any extra bits in code */ /* mask off any extra bits in code */
put_buffer = ((INT32) code) & ((((INT32) 1) << size) - 1);
put_bits += size; /* new number of bits in buffer */
/* new number of bits in buffer */
put_bits = size + entropy->saved.put_bits;
put_buffer <<= 24 - put_bits; /* align incoming bits */ put_buffer <<= 24 - put_bits; /* align incoming bits */
@ -543,10 +548,7 @@ encode_mcu_DC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy; huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
register int temp, temp2; register int temp, temp2;
register int nbits; register int nbits;
int blkn, ci; int blkn, ci, tbl;
int Al = cinfo->Al;
JBLOCKROW block;
jpeg_component_info * compptr;
ISHIFT_TEMPS ISHIFT_TEMPS
entropy->next_output_byte = cinfo->dest->next_output_byte; entropy->next_output_byte = cinfo->dest->next_output_byte;
@ -559,28 +561,27 @@ encode_mcu_DC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
/* Encode the MCU data blocks */ /* Encode the MCU data blocks */
for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) { for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
block = MCU_data[blkn];
ci = cinfo->MCU_membership[blkn]; ci = cinfo->MCU_membership[blkn];
compptr = cinfo->cur_comp_info[ci]; tbl = cinfo->cur_comp_info[ci]->dc_tbl_no;
/* Compute the DC value after the required point transform by Al. /* Compute the DC value after the required point transform by Al.
* This is simply an arithmetic right shift. * This is simply an arithmetic right shift.
*/ */
temp2 = IRIGHT_SHIFT((int) ((*block)[0]), Al); temp = IRIGHT_SHIFT((int) (MCU_data[blkn][0][0]), cinfo->Al);
/* DC differences are figured on the point-transformed values. */ /* DC differences are figured on the point-transformed values. */
temp = temp2 - entropy->saved.last_dc_val[ci]; temp2 = temp - entropy->saved.last_dc_val[ci];
entropy->saved.last_dc_val[ci] = temp2; entropy->saved.last_dc_val[ci] = temp;
/* Encode the DC coefficient difference per section G.1.2.1 */ /* Encode the DC coefficient difference per section G.1.2.1 */
temp2 = temp; temp = temp2;
if (temp < 0) { if (temp < 0) {
temp = -temp; /* temp is abs value of input */ temp = -temp; /* temp is abs value of input */
/* For a negative input, want temp2 = bitwise complement of abs(input) */ /* For a negative input, want temp2 = bitwise complement of abs(input) */
/* This code assumes we are on a two's complement machine */ /* This code assumes we are on a two's complement machine */
temp2--; temp2--;
} }
/* Find the number of bits needed for the magnitude of the coefficient */ /* Find the number of bits needed for the magnitude of the coefficient */
nbits = 0; nbits = 0;
while (temp) { while (temp) {
@ -592,10 +593,10 @@ encode_mcu_DC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
*/ */
if (nbits > MAX_COEF_BITS+1) if (nbits > MAX_COEF_BITS+1)
ERREXIT(cinfo, JERR_BAD_DCT_COEF); ERREXIT(cinfo, JERR_BAD_DCT_COEF);
/* Count/emit the Huffman-coded symbol for the number of bits */ /* Count/emit the Huffman-coded symbol for the number of bits */
emit_dc_symbol(entropy, compptr->dc_tbl_no, nbits); emit_dc_symbol(entropy, tbl, nbits);
/* Emit that number of bits of the value, if positive, */ /* Emit that number of bits of the value, if positive, */
/* or the complement of its magnitude, if negative. */ /* or the complement of its magnitude, if negative. */
if (nbits) /* emit_bits rejects calls with size 0 */ if (nbits) /* emit_bits rejects calls with size 0 */
@ -628,12 +629,12 @@ METHODDEF(boolean)
encode_mcu_AC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data) encode_mcu_AC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
{ {
huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy; huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
const int * natural_order;
JBLOCKROW block;
register int temp, temp2; register int temp, temp2;
register int nbits; register int nbits;
register int r, k; register int r, k;
int Se, Al; int Se, Al;
const int * natural_order;
JBLOCKROW block;
entropy->next_output_byte = cinfo->dest->next_output_byte; entropy->next_output_byte = cinfo->dest->next_output_byte;
entropy->free_in_buffer = cinfo->dest->free_in_buffer; entropy->free_in_buffer = cinfo->dest->free_in_buffer;
@ -731,18 +732,15 @@ encode_mcu_AC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
/* /*
* MCU encoding for DC successive approximation refinement scan. * MCU encoding for DC successive approximation refinement scan.
* Note: we assume such scans can be multi-component, although the spec * Note: we assume such scans can be multi-component,
* is not very clear on the point. * although the spec is not very clear on the point.
*/ */
METHODDEF(boolean) METHODDEF(boolean)
encode_mcu_DC_refine (j_compress_ptr cinfo, JBLOCKROW *MCU_data) encode_mcu_DC_refine (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
{ {
huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy; huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
register int temp; int Al, blkn;
int blkn;
int Al = cinfo->Al;
JBLOCKROW block;
entropy->next_output_byte = cinfo->dest->next_output_byte; entropy->next_output_byte = cinfo->dest->next_output_byte;
entropy->free_in_buffer = cinfo->dest->free_in_buffer; entropy->free_in_buffer = cinfo->dest->free_in_buffer;
@ -752,13 +750,12 @@ encode_mcu_DC_refine (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
if (entropy->restarts_to_go == 0) if (entropy->restarts_to_go == 0)
emit_restart_e(entropy, entropy->next_restart_num); emit_restart_e(entropy, entropy->next_restart_num);
Al = cinfo->Al;
/* Encode the MCU data blocks */ /* Encode the MCU data blocks */
for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) { for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
block = MCU_data[blkn];
/* We simply emit the Al'th bit of the DC coefficient value. */ /* We simply emit the Al'th bit of the DC coefficient value. */
temp = (*block)[0]; emit_bits_e(entropy, (unsigned int) (MCU_data[blkn][0][0] >> Al), 1);
emit_bits_e(entropy, (unsigned int) (temp >> Al), 1);
} }
cinfo->dest->next_output_byte = entropy->next_output_byte; cinfo->dest->next_output_byte = entropy->next_output_byte;
@ -786,14 +783,14 @@ METHODDEF(boolean)
encode_mcu_AC_refine (j_compress_ptr cinfo, JBLOCKROW *MCU_data) encode_mcu_AC_refine (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
{ {
huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy; huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
const int * natural_order;
JBLOCKROW block;
register int temp; register int temp;
register int r, k; register int r, k;
int Se, Al;
int EOB; int EOB;
char *BR_buffer; char *BR_buffer;
unsigned int BR; unsigned int BR;
int Se, Al;
const int * natural_order;
JBLOCKROW block;
int absvalues[DCTSIZE2]; int absvalues[DCTSIZE2];
entropy->next_output_byte = cinfo->dest->next_output_byte; entropy->next_output_byte = cinfo->dest->next_output_byte;
@ -918,7 +915,7 @@ encode_one_block (working_state * state, JCOEFPTR block, int last_dc_val,
{ {
register int temp, temp2; register int temp, temp2;
register int nbits; register int nbits;
register int k, r, i; register int r, k;
int Se = state->cinfo->lim_Se; int Se = state->cinfo->lim_Se;
const int * natural_order = state->cinfo->natural_order; const int * natural_order = state->cinfo->natural_order;
@ -960,7 +957,7 @@ encode_one_block (working_state * state, JCOEFPTR block, int last_dc_val,
r = 0; /* r = run length of zeros */ r = 0; /* r = run length of zeros */
for (k = 1; k <= Se; k++) { for (k = 1; k <= Se; k++) {
if ((temp = block[natural_order[k]]) == 0) { if ((temp2 = block[natural_order[k]]) == 0) {
r++; r++;
} else { } else {
/* if run length > 15, must emit special run-length-16 codes (0xF0) */ /* if run length > 15, must emit special run-length-16 codes (0xF0) */
@ -970,7 +967,7 @@ encode_one_block (working_state * state, JCOEFPTR block, int last_dc_val,
r -= 16; r -= 16;
} }
temp2 = temp; temp = temp2;
if (temp < 0) { if (temp < 0) {
temp = -temp; /* temp is abs value of input */ temp = -temp; /* temp is abs value of input */
/* This code assumes we are on a two's complement machine */ /* This code assumes we are on a two's complement machine */
@ -986,8 +983,8 @@ encode_one_block (working_state * state, JCOEFPTR block, int last_dc_val,
ERREXIT(state->cinfo, JERR_BAD_DCT_COEF); ERREXIT(state->cinfo, JERR_BAD_DCT_COEF);
/* Emit Huffman symbol for run length / number of bits */ /* Emit Huffman symbol for run length / number of bits */
i = (r << 4) + nbits; temp = (r << 4) + nbits;
if (! emit_bits_s(state, actbl->ehufco[i], actbl->ehufsi[i])) if (! emit_bits_s(state, actbl->ehufco[temp], actbl->ehufsi[temp]))
return FALSE; return FALSE;
/* Emit that number of bits of the value, if positive, */ /* Emit that number of bits of the value, if positive, */
@ -1124,16 +1121,16 @@ htest_one_block (j_compress_ptr cinfo, JCOEFPTR block, int last_dc_val,
{ {
register int temp; register int temp;
register int nbits; register int nbits;
register int k, r; register int r, k;
int Se = cinfo->lim_Se; int Se = cinfo->lim_Se;
const int * natural_order = cinfo->natural_order; const int * natural_order = cinfo->natural_order;
/* Encode the DC coefficient difference per section F.1.2.1 */ /* Encode the DC coefficient difference per section F.1.2.1 */
temp = block[0] - last_dc_val; temp = block[0] - last_dc_val;
if (temp < 0) if (temp < 0)
temp = -temp; temp = -temp;
/* Find the number of bits needed for the magnitude of the coefficient */ /* Find the number of bits needed for the magnitude of the coefficient */
nbits = 0; nbits = 0;
while (temp) { while (temp) {
@ -1148,11 +1145,11 @@ htest_one_block (j_compress_ptr cinfo, JCOEFPTR block, int last_dc_val,
/* Count the Huffman symbol for the number of bits */ /* Count the Huffman symbol for the number of bits */
dc_counts[nbits]++; dc_counts[nbits]++;
/* Encode the AC coefficients per section F.1.2.2 */ /* Encode the AC coefficients per section F.1.2.2 */
r = 0; /* r = run length of zeros */ r = 0; /* r = run length of zeros */
for (k = 1; k <= Se; k++) { for (k = 1; k <= Se; k++) {
if ((temp = block[natural_order[k]]) == 0) { if ((temp = block[natural_order[k]]) == 0) {
r++; r++;
@ -1162,11 +1159,11 @@ htest_one_block (j_compress_ptr cinfo, JCOEFPTR block, int last_dc_val,
ac_counts[0xF0]++; ac_counts[0xF0]++;
r -= 16; r -= 16;
} }
/* Find the number of bits needed for the magnitude of the coefficient */ /* Find the number of bits needed for the magnitude of the coefficient */
if (temp < 0) if (temp < 0)
temp = -temp; temp = -temp;
/* Find the number of bits needed for the magnitude of the coefficient */ /* Find the number of bits needed for the magnitude of the coefficient */
nbits = 1; /* there must be at least one 1 bit */ nbits = 1; /* there must be at least one 1 bit */
while ((temp >>= 1)) while ((temp >>= 1))
@ -1174,10 +1171,10 @@ htest_one_block (j_compress_ptr cinfo, JCOEFPTR block, int last_dc_val,
/* Check for out-of-range coefficient values */ /* Check for out-of-range coefficient values */
if (nbits > MAX_COEF_BITS) if (nbits > MAX_COEF_BITS)
ERREXIT(cinfo, JERR_BAD_DCT_COEF); ERREXIT(cinfo, JERR_BAD_DCT_COEF);
/* Count Huffman symbol for run length / number of bits */ /* Count Huffman symbol for run length / number of bits */
ac_counts[(r << 4) + nbits]++; ac_counts[(r << 4) + nbits]++;
r = 0; r = 0;
} }
} }
@ -1562,7 +1559,7 @@ jinit_huff_encoder (j_compress_ptr cinfo)
entropy = (huff_entropy_ptr) entropy = (huff_entropy_ptr)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
SIZEOF(huff_entropy_encoder)); SIZEOF(huff_entropy_encoder));
cinfo->entropy = (struct jpeg_entropy_encoder *) entropy; cinfo->entropy = &entropy->pub;
entropy->pub.start_pass = start_pass_huff; entropy->pub.start_pass = start_pass_huff;
/* Mark tables unallocated */ /* Mark tables unallocated */

View File

@ -2,6 +2,7 @@
* jcinit.c * jcinit.c
* *
* Copyright (C) 1991-1997, Thomas G. Lane. * Copyright (C) 1991-1997, Thomas G. Lane.
* Modified 2003-2013 by Guido Vollbeding.
* This file is part of the Independent JPEG Group's software. * This file is part of the Independent JPEG Group's software.
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
@ -29,6 +30,24 @@
GLOBAL(void) GLOBAL(void)
jinit_compress_master (j_compress_ptr cinfo) jinit_compress_master (j_compress_ptr cinfo)
{ {
long samplesperrow;
JDIMENSION jd_samplesperrow;
/* For now, precision must match compiled-in value... */
if (cinfo->data_precision != BITS_IN_JSAMPLE)
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
/* Sanity check on image dimensions */
if (cinfo->image_height <= 0 || cinfo->image_width <= 0 ||
cinfo->input_components <= 0)
ERREXIT(cinfo, JERR_EMPTY_IMAGE);
/* Width of an input scanline must be representable as JDIMENSION. */
samplesperrow = (long) cinfo->image_width * (long) cinfo->input_components;
jd_samplesperrow = (JDIMENSION) samplesperrow;
if ((long) jd_samplesperrow != samplesperrow)
ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
/* Initialize master control (includes parameter checking/processing) */ /* Initialize master control (includes parameter checking/processing) */
jinit_c_master_control(cinfo, FALSE /* full compression */); jinit_c_master_control(cinfo, FALSE /* full compression */);

View File

@ -2,6 +2,7 @@
* jcmainct.c * jcmainct.c
* *
* Copyright (C) 1994-1996, Thomas G. Lane. * Copyright (C) 1994-1996, Thomas G. Lane.
* Modified 2003-2012 by Guido Vollbeding.
* This file is part of the Independent JPEG Group's software. * This file is part of the Independent JPEG Group's software.
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
@ -181,14 +182,16 @@ process_data_buffer_main (j_compress_ptr cinfo,
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
ci++, compptr++) { ci++, compptr++) {
mainp->buffer[ci] = (*cinfo->mem->access_virt_sarray) mainp->buffer[ci] = (*cinfo->mem->access_virt_sarray)
((j_common_ptr) cinfo, mainp->whole_image[ci], ((j_common_ptr) cinfo, mainp->whole_image[ci], mainp->cur_iMCU_row *
mainp->cur_iMCU_row * (compptr->v_samp_factor * DCTSIZE), ((JDIMENSION) (compptr->v_samp_factor * cinfo->min_DCT_v_scaled_size)),
(JDIMENSION) (compptr->v_samp_factor * DCTSIZE), writing); (JDIMENSION) (compptr->v_samp_factor * cinfo->min_DCT_v_scaled_size),
writing);
} }
/* In a read pass, pretend we just read some source data. */ /* In a read pass, pretend we just read some source data. */
if (! writing) { if (! writing) {
*in_row_ctr += cinfo->max_v_samp_factor * DCTSIZE; *in_row_ctr += (JDIMENSION)
mainp->rowgroup_ctr = DCTSIZE; (cinfo->max_v_samp_factor * cinfo->min_DCT_v_scaled_size);
mainp->rowgroup_ctr = (JDIMENSION) cinfo->min_DCT_v_scaled_size;
} }
} }
@ -198,9 +201,9 @@ process_data_buffer_main (j_compress_ptr cinfo,
(*cinfo->prep->pre_process_data) (cinfo, (*cinfo->prep->pre_process_data) (cinfo,
input_buf, in_row_ctr, in_rows_avail, input_buf, in_row_ctr, in_rows_avail,
mainp->buffer, &mainp->rowgroup_ctr, mainp->buffer, &mainp->rowgroup_ctr,
(JDIMENSION) DCTSIZE); (JDIMENSION) cinfo->min_DCT_v_scaled_size);
/* Return to application if we need more data to fill the iMCU row. */ /* Return to application if we need more data to fill the iMCU row. */
if (mainp->rowgroup_ctr < DCTSIZE) if (mainp->rowgroup_ctr < (JDIMENSION) cinfo->min_DCT_v_scaled_size)
return; return;
} }
@ -251,7 +254,7 @@ jinit_c_main_controller (j_compress_ptr cinfo, boolean need_full_buffer)
mainp = (my_main_ptr) mainp = (my_main_ptr)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
SIZEOF(my_main_controller)); SIZEOF(my_main_controller));
cinfo->main = (struct jpeg_c_main_controller *) mainp; cinfo->main = &mainp->pub;
mainp->pub.start_pass = start_pass_main; mainp->pub.start_pass = start_pass_main;
/* We don't need to create a buffer in raw-data mode. */ /* We don't need to create a buffer in raw-data mode. */
@ -269,9 +272,10 @@ jinit_c_main_controller (j_compress_ptr cinfo, boolean need_full_buffer)
ci++, compptr++) { ci++, compptr++) {
mainp->whole_image[ci] = (*cinfo->mem->request_virt_sarray) mainp->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE, ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE,
compptr->width_in_blocks * compptr->DCT_h_scaled_size, compptr->width_in_blocks * ((JDIMENSION) compptr->DCT_h_scaled_size),
(JDIMENSION) jround_up((long) compptr->height_in_blocks, ((JDIMENSION) jround_up((long) compptr->height_in_blocks,
(long) compptr->v_samp_factor) * DCTSIZE, (long) compptr->v_samp_factor)) *
((JDIMENSION) cinfo->min_DCT_v_scaled_size),
(JDIMENSION) (compptr->v_samp_factor * compptr->DCT_v_scaled_size)); (JDIMENSION) (compptr->v_samp_factor * compptr->DCT_v_scaled_size));
} }
#else #else
@ -286,7 +290,7 @@ jinit_c_main_controller (j_compress_ptr cinfo, boolean need_full_buffer)
ci++, compptr++) { ci++, compptr++) {
mainp->buffer[ci] = (*cinfo->mem->alloc_sarray) mainp->buffer[ci] = (*cinfo->mem->alloc_sarray)
((j_common_ptr) cinfo, JPOOL_IMAGE, ((j_common_ptr) cinfo, JPOOL_IMAGE,
compptr->width_in_blocks * compptr->DCT_h_scaled_size, compptr->width_in_blocks * ((JDIMENSION) compptr->DCT_h_scaled_size),
(JDIMENSION) (compptr->v_samp_factor * compptr->DCT_v_scaled_size)); (JDIMENSION) (compptr->v_samp_factor * compptr->DCT_v_scaled_size));
} }
} }

View File

@ -2,7 +2,7 @@
* jcmarker.c * jcmarker.c
* *
* Copyright (C) 1991-1998, Thomas G. Lane. * Copyright (C) 1991-1998, Thomas G. Lane.
* Modified 2003-2010 by Guido Vollbeding. * Modified 2003-2013 by Guido Vollbeding.
* This file is part of the Independent JPEG Group's software. * This file is part of the Independent JPEG Group's software.
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
@ -19,24 +19,24 @@ typedef enum { /* JPEG marker codes */
M_SOF1 = 0xc1, M_SOF1 = 0xc1,
M_SOF2 = 0xc2, M_SOF2 = 0xc2,
M_SOF3 = 0xc3, M_SOF3 = 0xc3,
M_SOF5 = 0xc5, M_SOF5 = 0xc5,
M_SOF6 = 0xc6, M_SOF6 = 0xc6,
M_SOF7 = 0xc7, M_SOF7 = 0xc7,
M_JPG = 0xc8, M_JPG = 0xc8,
M_SOF9 = 0xc9, M_SOF9 = 0xc9,
M_SOF10 = 0xca, M_SOF10 = 0xca,
M_SOF11 = 0xcb, M_SOF11 = 0xcb,
M_SOF13 = 0xcd, M_SOF13 = 0xcd,
M_SOF14 = 0xce, M_SOF14 = 0xce,
M_SOF15 = 0xcf, M_SOF15 = 0xcf,
M_DHT = 0xc4, M_DHT = 0xc4,
M_DAC = 0xcc, M_DAC = 0xcc,
M_RST0 = 0xd0, M_RST0 = 0xd0,
M_RST1 = 0xd1, M_RST1 = 0xd1,
M_RST2 = 0xd2, M_RST2 = 0xd2,
@ -45,7 +45,7 @@ typedef enum { /* JPEG marker codes */
M_RST5 = 0xd5, M_RST5 = 0xd5,
M_RST6 = 0xd6, M_RST6 = 0xd6,
M_RST7 = 0xd7, M_RST7 = 0xd7,
M_SOI = 0xd8, M_SOI = 0xd8,
M_EOI = 0xd9, M_EOI = 0xd9,
M_SOS = 0xda, M_SOS = 0xda,
@ -54,7 +54,7 @@ typedef enum { /* JPEG marker codes */
M_DRI = 0xdd, M_DRI = 0xdd,
M_DHP = 0xde, M_DHP = 0xde,
M_EXP = 0xdf, M_EXP = 0xdf,
M_APP0 = 0xe0, M_APP0 = 0xe0,
M_APP1 = 0xe1, M_APP1 = 0xe1,
M_APP2 = 0xe2, M_APP2 = 0xe2,
@ -71,13 +71,14 @@ typedef enum { /* JPEG marker codes */
M_APP13 = 0xed, M_APP13 = 0xed,
M_APP14 = 0xee, M_APP14 = 0xee,
M_APP15 = 0xef, M_APP15 = 0xef,
M_JPG0 = 0xf0, M_JPG0 = 0xf0,
M_JPG8 = 0xf8,
M_JPG13 = 0xfd, M_JPG13 = 0xfd,
M_COM = 0xfe, M_COM = 0xfe,
M_TEM = 0x01, M_TEM = 0x01,
M_ERROR = 0x100 M_ERROR = 0x100
} JPEG_MARKER; } JPEG_MARKER;
@ -281,6 +282,37 @@ emit_dri (j_compress_ptr cinfo)
} }
LOCAL(void)
emit_lse_ict (j_compress_ptr cinfo)
/* Emit an LSE inverse color transform specification marker */
{
/* Support only 1 transform */
if (cinfo->color_transform != JCT_SUBTRACT_GREEN ||
cinfo->num_components < 3)
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
emit_marker(cinfo, M_JPG8);
emit_2bytes(cinfo, 24); /* fixed length */
emit_byte(cinfo, 0x0D); /* ID inverse transform specification */
emit_2bytes(cinfo, MAXJSAMPLE); /* MAXTRANS */
emit_byte(cinfo, 3); /* Nt=3 */
emit_byte(cinfo, cinfo->comp_info[1].component_id);
emit_byte(cinfo, cinfo->comp_info[0].component_id);
emit_byte(cinfo, cinfo->comp_info[2].component_id);
emit_byte(cinfo, 0x80); /* F1: CENTER1=1, NORM1=0 */
emit_2bytes(cinfo, 0); /* A(1,1)=0 */
emit_2bytes(cinfo, 0); /* A(1,2)=0 */
emit_byte(cinfo, 0); /* F2: CENTER2=0, NORM2=0 */
emit_2bytes(cinfo, 1); /* A(2,1)=1 */
emit_2bytes(cinfo, 0); /* A(2,2)=0 */
emit_byte(cinfo, 0); /* F3: CENTER3=0, NORM3=0 */
emit_2bytes(cinfo, 1); /* A(3,1)=1 */
emit_2bytes(cinfo, 0); /* A(3,2)=0 */
}
LOCAL(void) LOCAL(void)
emit_sof (j_compress_ptr cinfo, JPEG_MARKER code) emit_sof (j_compress_ptr cinfo, JPEG_MARKER code)
/* Emit a SOF marker */ /* Emit a SOF marker */
@ -476,8 +508,8 @@ write_marker_byte (j_compress_ptr cinfo, int val)
* Write datastream header. * Write datastream header.
* This consists of an SOI and optional APPn markers. * This consists of an SOI and optional APPn markers.
* We recommend use of the JFIF marker, but not the Adobe marker, * We recommend use of the JFIF marker, but not the Adobe marker,
* when using YCbCr or grayscale data. The JFIF marker should NOT * when using YCbCr or grayscale data. The JFIF marker is also used
* be used for any other JPEG colorspace. The Adobe marker is helpful * for other standard JPEG colorspaces. The Adobe marker is helpful
* to distinguish RGB, CMYK, and YCCK colorspaces. * to distinguish RGB, CMYK, and YCCK colorspaces.
* Note that an application can write additional header markers after * Note that an application can write additional header markers after
* jpeg_start_compress returns. * jpeg_start_compress returns.
@ -502,7 +534,8 @@ write_file_header (j_compress_ptr cinfo)
/* /*
* Write frame header. * Write frame header.
* This consists of DQT and SOFn markers, and a conditional pseudo SOS marker. * This consists of DQT and SOFn markers,
* a conditional LSE marker and a conditional pseudo SOS marker.
* Note that we do not emit the SOF until we have emitted the DQT(s). * Note that we do not emit the SOF until we have emitted the DQT(s).
* This avoids compatibility problems with incorrect implementations that * This avoids compatibility problems with incorrect implementations that
* try to error-check the quant table numbers as soon as they see the SOF. * try to error-check the quant table numbers as soon as they see the SOF.
@ -560,6 +593,10 @@ write_frame_header (j_compress_ptr cinfo)
emit_sof(cinfo, M_SOF1); /* SOF code for non-baseline Huffman file */ emit_sof(cinfo, M_SOF1); /* SOF code for non-baseline Huffman file */
} }
/* Check to emit LSE inverse color transform specification marker */
if (cinfo->color_transform)
emit_lse_ict(cinfo);
/* Check to emit pseudo SOS marker */ /* Check to emit pseudo SOS marker */
if (cinfo->progressive_mode && cinfo->block_size != DCTSIZE) if (cinfo->progressive_mode && cinfo->block_size != DCTSIZE)
emit_pseudo_sos(cinfo); emit_pseudo_sos(cinfo);
@ -668,7 +705,7 @@ jinit_marker_writer (j_compress_ptr cinfo)
marker = (my_marker_ptr) marker = (my_marker_ptr)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
SIZEOF(my_marker_writer)); SIZEOF(my_marker_writer));
cinfo->marker = (struct jpeg_marker_writer *) marker; cinfo->marker = &marker->pub;
/* Initialize method pointers */ /* Initialize method pointers */
marker->pub.write_file_header = write_file_header; marker->pub.write_file_header = write_file_header;
marker->pub.write_frame_header = write_frame_header; marker->pub.write_frame_header = write_frame_header;

View File

@ -2,7 +2,7 @@
* jcmaster.c * jcmaster.c
* *
* Copyright (C) 1991-1997, Thomas G. Lane. * Copyright (C) 1991-1997, Thomas G. Lane.
* Modified 2003-2011 by Guido Vollbeding. * Modified 2003-2013 by Guido Vollbeding.
* This file is part of the Independent JPEG Group's software. * This file is part of the Independent JPEG Group's software.
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
@ -222,8 +222,6 @@ initial_setup (j_compress_ptr cinfo, boolean transcode_only)
{ {
int ci, ssize; int ci, ssize;
jpeg_component_info *compptr; jpeg_component_info *compptr;
long samplesperrow;
JDIMENSION jd_samplesperrow;
if (transcode_only) if (transcode_only)
jpeg_calc_trans_dimensions(cinfo); jpeg_calc_trans_dimensions(cinfo);
@ -251,7 +249,7 @@ initial_setup (j_compress_ptr cinfo, boolean transcode_only)
/* Sanity check on image dimensions */ /* Sanity check on image dimensions */
if (cinfo->jpeg_height <= 0 || cinfo->jpeg_width <= 0 || if (cinfo->jpeg_height <= 0 || cinfo->jpeg_width <= 0 ||
cinfo->num_components <= 0 || cinfo->input_components <= 0) cinfo->num_components <= 0)
ERREXIT(cinfo, JERR_EMPTY_IMAGE); ERREXIT(cinfo, JERR_EMPTY_IMAGE);
/* Make sure image isn't bigger than I can handle */ /* Make sure image isn't bigger than I can handle */
@ -259,14 +257,8 @@ initial_setup (j_compress_ptr cinfo, boolean transcode_only)
(long) cinfo->jpeg_width > (long) JPEG_MAX_DIMENSION) (long) cinfo->jpeg_width > (long) JPEG_MAX_DIMENSION)
ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) JPEG_MAX_DIMENSION); ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) JPEG_MAX_DIMENSION);
/* Width of an input scanline must be representable as JDIMENSION. */ /* Only 8 to 12 bits data precision are supported for DCT based JPEG */
samplesperrow = (long) cinfo->image_width * (long) cinfo->input_components; if (cinfo->data_precision < 8 || cinfo->data_precision > 12)
jd_samplesperrow = (JDIMENSION) samplesperrow;
if ((long) jd_samplesperrow != samplesperrow)
ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
/* For now, precision must match compiled-in value... */
if (cinfo->data_precision != BITS_IN_JSAMPLE)
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
/* Check that number of components won't exceed internal array sizes */ /* Check that number of components won't exceed internal array sizes */
@ -339,8 +331,10 @@ initial_setup (j_compress_ptr cinfo, boolean transcode_only)
jdiv_round_up((long) cinfo->jpeg_height * jdiv_round_up((long) cinfo->jpeg_height *
(long) (compptr->v_samp_factor * compptr->DCT_v_scaled_size), (long) (compptr->v_samp_factor * compptr->DCT_v_scaled_size),
(long) (cinfo->max_v_samp_factor * cinfo->block_size)); (long) (cinfo->max_v_samp_factor * cinfo->block_size));
/* Mark component needed (this flag isn't actually used for compression) */ /* Don't need quantization scale after DCT,
compptr->component_needed = TRUE; * until color conversion says otherwise.
*/
compptr->component_needed = FALSE;
} }
/* Compute number of fully interleaved MCU rows (number of times that /* Compute number of fully interleaved MCU rows (number of times that
@ -811,7 +805,7 @@ jinit_c_master_control (j_compress_ptr cinfo, boolean transcode_only)
master = (my_master_ptr) master = (my_master_ptr)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
SIZEOF(my_comp_master)); SIZEOF(my_comp_master));
cinfo->master = (struct jpeg_comp_master *) master; cinfo->master = &master->pub;
master->pub.prepare_for_pass = prepare_for_pass; master->pub.prepare_for_pass = prepare_for_pass;
master->pub.pass_startup = pass_startup; master->pub.pass_startup = pass_startup;
master->pub.finish_pass = finish_pass_master; master->pub.finish_pass = finish_pass_master;
@ -833,10 +827,14 @@ jinit_c_master_control (j_compress_ptr cinfo, boolean transcode_only)
cinfo->num_scans = 1; cinfo->num_scans = 1;
} }
if ((cinfo->progressive_mode || cinfo->block_size < DCTSIZE) && if (cinfo->optimize_coding)
!cinfo->arith_code) /* TEMPORARY HACK ??? */ cinfo->arith_code = FALSE; /* disable arithmetic coding */
/* assume default tables no good for progressive or downscale mode */ else if (! cinfo->arith_code &&
cinfo->optimize_coding = TRUE; (cinfo->progressive_mode ||
(cinfo->block_size > 1 && cinfo->block_size < DCTSIZE)))
/* TEMPORARY HACK ??? */
/* assume default tables no good for progressive or reduced AC mode */
cinfo->optimize_coding = TRUE; /* force Huffman optimization */
/* Initialize my private state */ /* Initialize my private state */
if (transcode_only) { if (transcode_only) {

View File

@ -1,31 +1,49 @@
/* FLTK *************************************************************** */
/* FLTK Comments marked with FLTK show modifications for FLTK which */
/* FLTK should probably be preserved when the JPEG lib is upgraded. */
/* FLTK *************************************************************** */
/* jconfig.h. Generated from jconfig.cfg by configure. */
/* jconfig.cfg --- source file edited by configure script */ /* jconfig.cfg --- source file edited by configure script */
/* see jconfig.doc for explanations */ /* see jconfig.txt for explanations */
#define HAVE_PROTOTYPES #define HAVE_PROTOTYPES 1
#define HAVE_UNSIGNED_CHAR #define HAVE_UNSIGNED_CHAR 1
#define HAVE_UNSIGNED_SHORT #define HAVE_UNSIGNED_SHORT 1
#ifdef __CHAR_UNSIGNED__ /* #undef void */
# define CHAR_IS_UNSIGNED /* #undef const */
#endif /* __CHAR_UNSIGNED__ */ /* #undef CHAR_IS_UNSIGNED */
#define HAVE_STDLIB_H /* #define HAVE_STDDEF_H 1 */ /* FLTK */
#define HAVE_STDLIB_H 1
/* #define HAVE_LOCALE_H 1 */ /* FLTK */
/* #undef NEED_BSD_STRINGS */
/* #undef NEED_SYS_TYPES_H */
/* #undef NEED_FAR_POINTERS */
/* #undef NEED_SHORT_EXTERNAL_NAMES */
/* Define this if you get warnings about undefined structures. */ /* Define this if you get warnings about undefined structures. */
#undef INCOMPLETE_TYPES_BROKEN /* #undef INCOMPLETE_TYPES_BROKEN */
#if defined(WIN32) || defined(__EMX__) /* Define "boolean" as unsigned char, not enum, on Windows systems. */
/* Define "boolean" as unsigned char, not int, per Windows custom */ #ifdef _WIN32
# ifndef __RPCNDR_H__ /* don't conflict if rpcndr.h already read */ #ifndef __RPCNDR_H__ /* don't conflict if rpcndr.h already read */
typedef unsigned char boolean; typedef unsigned char boolean;
# endif #endif
# define HAVE_BOOLEAN /* prevent jmorecfg.h from redefining it */ #ifndef FALSE /* in case these macros already exist */
#endif /* WIN32 || __EMX__ */ #define FALSE 0 /* values of boolean */
#endif
#ifndef TRUE
#define TRUE 1
#endif
#define HAVE_BOOLEAN /* prevent jmorecfg.h from redefining it */
#endif
#ifdef JPEG_INTERNALS #ifdef JPEG_INTERNALS
#undef RIGHT_SHIFT_IS_UNSIGNED /* #undef RIGHT_SHIFT_IS_UNSIGNED */
#undef INLINE /* #define INLINE __inline__ */ /* FLTK */
/* These are for configuring the JPEG memory manager. */ /* These are for configuring the JPEG memory manager. */
#undef DEFAULT_MAX_MEM /* #undef DEFAULT_MAX_MEM */
#undef NO_MKTEMP /* #undef NO_MKTEMP */
#endif /* JPEG_INTERNALS */ #endif /* JPEG_INTERNALS */
@ -34,18 +52,22 @@ typedef unsigned char boolean;
#define BMP_SUPPORTED /* BMP image file format */ #define BMP_SUPPORTED /* BMP image file format */
#define GIF_SUPPORTED /* GIF image file format */ #define GIF_SUPPORTED /* GIF image file format */
#define PPM_SUPPORTED /* PBMPLUS PPM/PGM image file format */ #define PPM_SUPPORTED /* PBMPLUS PPM/PGM image file format */
#undef RLE_SUPPORTED /* Utah RLE image file format */ /* #undef RLE_SUPPORTED */
#define TARGA_SUPPORTED /* Targa image file format */ #define TARGA_SUPPORTED /* Targa image file format */
#undef TWO_FILE_COMMANDLINE /* #undef TWO_FILE_COMMANDLINE */
#undef NEED_SIGNAL_CATCHER /* #undef NEED_SIGNAL_CATCHER */
#undef DONT_USE_B_MODE /* #undef DONT_USE_B_MODE */
#if 0 /* FLTK 1.3.3 (disabled in FLTK 1.3.4) */
#if defined(WIN32) || defined(__EMX__) #if defined(WIN32) || defined(__EMX__)
# define USE_SETMODE # define USE_SETMODE
#endif /* WIN32 || __EMX__ */ #endif /* WIN32 || __EMX__ */
#endif /* FLTK 1.3.3 (disabled in FLTK 1.3.4) */
/* Define this if you want percent-done progress reports from cjpeg/djpeg. */ /* Define this if you want percent-done progress reports from cjpeg/djpeg. */
#undef PROGRESS_REPORT /* #undef PROGRESS_REPORT */
#endif /* JPEG_CJPEG_DJPEG */ #endif /* JPEG_CJPEG_DJPEG */

View File

@ -2,6 +2,7 @@
* jconfig.txt * jconfig.txt
* *
* Copyright (C) 1991-1994, Thomas G. Lane. * Copyright (C) 1991-1994, Thomas G. Lane.
* Modified 2009-2013 by Guido Vollbeding.
* This file is part of the Independent JPEG Group's software. * This file is part of the Independent JPEG Group's software.
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
@ -91,12 +92,18 @@
*/ */
#undef INCOMPLETE_TYPES_BROKEN #undef INCOMPLETE_TYPES_BROKEN
/* Define "boolean" as unsigned char, not int, on Windows systems. /* Define "boolean" as unsigned char, not enum, on Windows systems.
*/ */
#ifdef _WIN32 #ifdef _WIN32
#ifndef __RPCNDR_H__ /* don't conflict if rpcndr.h already read */ #ifndef __RPCNDR_H__ /* don't conflict if rpcndr.h already read */
typedef unsigned char boolean; typedef unsigned char boolean;
#endif #endif
#ifndef FALSE /* in case these macros already exist */
#define FALSE 0 /* values of boolean */
#endif
#ifndef TRUE
#define TRUE 1
#endif
#define HAVE_BOOLEAN /* prevent jmorecfg.h from redefining it */ #define HAVE_BOOLEAN /* prevent jmorecfg.h from redefining it */
#endif #endif

View File

@ -2,7 +2,7 @@
* jcparam.c * jcparam.c
* *
* Copyright (C) 1991-1998, Thomas G. Lane. * Copyright (C) 1991-1998, Thomas G. Lane.
* Modified 2003-2008 by Guido Vollbeding. * Modified 2003-2013 by Guido Vollbeding.
* This file is part of the Independent JPEG Group's software. * This file is part of the Independent JPEG Group's software.
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
@ -150,7 +150,7 @@ jpeg_set_quality (j_compress_ptr cinfo, int quality, boolean force_baseline)
/* Set or change the 'quality' (quantization) setting, using default tables. /* Set or change the 'quality' (quantization) setting, using default tables.
* This is the standard quality-adjusting entry point for typical user * This is the standard quality-adjusting entry point for typical user
* interfaces; only those who want detailed control over quantization tables * interfaces; only those who want detailed control over quantization tables
* would use the preceding three routines directly. * would use the preceding routines directly.
*/ */
{ {
/* Convert user 0-100 rating to percentage scaling */ /* Convert user 0-100 rating to percentage scaling */
@ -323,18 +323,17 @@ jpeg_set_defaults (j_compress_ptr cinfo)
/* Expect normal source image, not raw downsampled data */ /* Expect normal source image, not raw downsampled data */
cinfo->raw_data_in = FALSE; cinfo->raw_data_in = FALSE;
/* Use Huffman coding, not arithmetic coding, by default */ /* The standard Huffman tables are only valid for 8-bit data precision.
cinfo->arith_code = FALSE; * If the precision is higher, use arithmetic coding.
* (Alternatively, using Huffman coding would be possible with forcing
* optimization on so that usable tables will be computed, or by
* supplying default tables that are valid for the desired precision.)
* Otherwise, use Huffman coding by default.
*/
cinfo->arith_code = cinfo->data_precision > 8 ? TRUE : FALSE;
/* By default, don't do extra passes to optimize entropy coding */ /* By default, don't do extra passes to optimize entropy coding */
cinfo->optimize_coding = FALSE; cinfo->optimize_coding = FALSE;
/* The standard Huffman tables are only valid for 8-bit data precision.
* If the precision is higher, force optimization on so that usable
* tables will be computed. This test can be removed if default tables
* 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 */ /* By default, use the simpler non-cosited sampling alignment */
cinfo->CCIR601_sampling = FALSE; cinfo->CCIR601_sampling = FALSE;
@ -360,6 +359,9 @@ jpeg_set_defaults (j_compress_ptr cinfo)
* JFIF_minor_version to 2. We could probably get away with just defaulting * JFIF_minor_version to 2. We could probably get away with just defaulting
* to 1.02, but there may still be some decoders in use that will complain * to 1.02, but there may still be some decoders in use that will complain
* about that; saying 1.01 should minimize compatibility problems. * about that; saying 1.01 should minimize compatibility problems.
*
* For wide gamut colorspaces (BG_RGB and BG_YCC), the major version will be
* overridden by jpeg_set_colorspace and set to 2.
*/ */
cinfo->JFIF_major_version = 1; /* Default JFIF version = 1.01 */ cinfo->JFIF_major_version = 1; /* Default JFIF version = 1.01 */
cinfo->JFIF_minor_version = 1; cinfo->JFIF_minor_version = 1;
@ -367,6 +369,9 @@ jpeg_set_defaults (j_compress_ptr cinfo)
cinfo->X_density = 1; /* Pixel aspect ratio is square by default */ cinfo->X_density = 1; /* Pixel aspect ratio is square by default */
cinfo->Y_density = 1; cinfo->Y_density = 1;
/* No color transform */
cinfo->color_transform = JCT_NONE;
/* Choose JPEG colorspace based on input space, set defaults accordingly */ /* Choose JPEG colorspace based on input space, set defaults accordingly */
jpeg_default_colorspace(cinfo); jpeg_default_colorspace(cinfo);
@ -381,6 +386,9 @@ GLOBAL(void)
jpeg_default_colorspace (j_compress_ptr cinfo) jpeg_default_colorspace (j_compress_ptr cinfo)
{ {
switch (cinfo->in_color_space) { switch (cinfo->in_color_space) {
case JCS_UNKNOWN:
jpeg_set_colorspace(cinfo, JCS_UNKNOWN);
break;
case JCS_GRAYSCALE: case JCS_GRAYSCALE:
jpeg_set_colorspace(cinfo, JCS_GRAYSCALE); jpeg_set_colorspace(cinfo, JCS_GRAYSCALE);
break; break;
@ -396,8 +404,12 @@ jpeg_default_colorspace (j_compress_ptr cinfo)
case JCS_YCCK: case JCS_YCCK:
jpeg_set_colorspace(cinfo, JCS_YCCK); jpeg_set_colorspace(cinfo, JCS_YCCK);
break; break;
case JCS_UNKNOWN: case JCS_BG_RGB:
jpeg_set_colorspace(cinfo, JCS_UNKNOWN); /* No translation for now -- conversion to BG_YCC not yet supportet */
jpeg_set_colorspace(cinfo, JCS_BG_RGB);
break;
case JCS_BG_YCC:
jpeg_set_colorspace(cinfo, JCS_BG_YCC);
break; break;
default: default:
ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE); ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
@ -438,27 +450,40 @@ jpeg_set_colorspace (j_compress_ptr cinfo, J_COLOR_SPACE colorspace)
cinfo->write_Adobe_marker = FALSE; /* write no Adobe marker by default */ cinfo->write_Adobe_marker = FALSE; /* write no Adobe marker by default */
switch (colorspace) { switch (colorspace) {
case JCS_UNKNOWN:
cinfo->num_components = cinfo->input_components;
if (cinfo->num_components < 1 || cinfo->num_components > MAX_COMPONENTS)
ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
MAX_COMPONENTS);
for (ci = 0; ci < cinfo->num_components; ci++) {
SET_COMP(ci, ci, 1,1, 0, 0,0);
}
break;
case JCS_GRAYSCALE: case JCS_GRAYSCALE:
cinfo->write_JFIF_header = TRUE; /* Write a JFIF marker */ cinfo->write_JFIF_header = TRUE; /* Write a JFIF marker */
cinfo->num_components = 1; cinfo->num_components = 1;
/* JFIF specifies component ID 1 */ /* JFIF specifies component ID 1 */
SET_COMP(0, 1, 1,1, 0, 0,0); SET_COMP(0, 0x01, 1,1, 0, 0,0);
break; break;
case JCS_RGB: case JCS_RGB:
cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag RGB */ cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag RGB */
cinfo->num_components = 3; cinfo->num_components = 3;
SET_COMP(0, 0x52 /* 'R' */, 1,1, 0, 0,0); SET_COMP(0, 0x52 /* 'R' */, 1,1, 0,
cinfo->color_transform == JCT_SUBTRACT_GREEN ? 1 : 0,
cinfo->color_transform == JCT_SUBTRACT_GREEN ? 1 : 0);
SET_COMP(1, 0x47 /* 'G' */, 1,1, 0, 0,0); SET_COMP(1, 0x47 /* 'G' */, 1,1, 0, 0,0);
SET_COMP(2, 0x42 /* 'B' */, 1,1, 0, 0,0); SET_COMP(2, 0x42 /* 'B' */, 1,1, 0,
cinfo->color_transform == JCT_SUBTRACT_GREEN ? 1 : 0,
cinfo->color_transform == JCT_SUBTRACT_GREEN ? 1 : 0);
break; break;
case JCS_YCbCr: case JCS_YCbCr:
cinfo->write_JFIF_header = TRUE; /* Write a JFIF marker */ cinfo->write_JFIF_header = TRUE; /* Write a JFIF marker */
cinfo->num_components = 3; cinfo->num_components = 3;
/* JFIF specifies component IDs 1,2,3 */ /* JFIF specifies component IDs 1,2,3 */
/* We default to 2x2 subsamples of chrominance */ /* We default to 2x2 subsamples of chrominance */
SET_COMP(0, 1, 2,2, 0, 0,0); SET_COMP(0, 0x01, 2,2, 0, 0,0);
SET_COMP(1, 2, 1,1, 1, 1,1); SET_COMP(1, 0x02, 1,1, 1, 1,1);
SET_COMP(2, 3, 1,1, 1, 1,1); SET_COMP(2, 0x03, 1,1, 1, 1,1);
break; break;
case JCS_CMYK: case JCS_CMYK:
cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag CMYK */ cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag CMYK */
@ -471,19 +496,33 @@ jpeg_set_colorspace (j_compress_ptr cinfo, J_COLOR_SPACE colorspace)
case JCS_YCCK: case JCS_YCCK:
cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag YCCK */ cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag YCCK */
cinfo->num_components = 4; cinfo->num_components = 4;
SET_COMP(0, 1, 2,2, 0, 0,0); SET_COMP(0, 0x01, 2,2, 0, 0,0);
SET_COMP(1, 2, 1,1, 1, 1,1); SET_COMP(1, 0x02, 1,1, 1, 1,1);
SET_COMP(2, 3, 1,1, 1, 1,1); SET_COMP(2, 0x03, 1,1, 1, 1,1);
SET_COMP(3, 4, 2,2, 0, 0,0); SET_COMP(3, 0x04, 2,2, 0, 0,0);
break; break;
case JCS_UNKNOWN: case JCS_BG_RGB:
cinfo->num_components = cinfo->input_components; cinfo->write_JFIF_header = TRUE; /* Write a JFIF marker */
if (cinfo->num_components < 1 || cinfo->num_components > MAX_COMPONENTS) cinfo->JFIF_major_version = 2; /* Set JFIF major version = 2 */
ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components, cinfo->num_components = 3;
MAX_COMPONENTS); /* Add offset 0x20 to the normal R/G/B component IDs */
for (ci = 0; ci < cinfo->num_components; ci++) { SET_COMP(0, 0x72 /* 'r' */, 1,1, 0,
SET_COMP(ci, ci, 1,1, 0, 0,0); cinfo->color_transform == JCT_SUBTRACT_GREEN ? 1 : 0,
} cinfo->color_transform == JCT_SUBTRACT_GREEN ? 1 : 0);
SET_COMP(1, 0x67 /* 'g' */, 1,1, 0, 0,0);
SET_COMP(2, 0x62 /* 'b' */, 1,1, 0,
cinfo->color_transform == JCT_SUBTRACT_GREEN ? 1 : 0,
cinfo->color_transform == JCT_SUBTRACT_GREEN ? 1 : 0);
break;
case JCS_BG_YCC:
cinfo->write_JFIF_header = TRUE; /* Write a JFIF marker */
cinfo->JFIF_major_version = 2; /* Set JFIF major version = 2 */
cinfo->num_components = 3;
/* Add offset 0x20 to the normal Cb/Cr component IDs */
/* We default to 2x2 subsamples of chrominance */
SET_COMP(0, 0x01, 2,2, 0, 0,0);
SET_COMP(1, 0x22, 1,1, 1, 1,1);
SET_COMP(2, 0x23, 1,1, 1, 1,1);
break; break;
default: default:
ERREXIT(cinfo, JERR_BAD_J_COLORSPACE); ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
@ -567,8 +606,10 @@ jpeg_simple_progression (j_compress_ptr cinfo)
ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
/* Figure space needed for script. Calculation must match code below! */ /* Figure space needed for script. Calculation must match code below! */
if (ncomps == 3 && cinfo->jpeg_color_space == JCS_YCbCr) { if (ncomps == 3 &&
/* Custom script for YCbCr color images. */ (cinfo->jpeg_color_space == JCS_YCbCr ||
cinfo->jpeg_color_space == JCS_BG_YCC)) {
/* Custom script for YCC color images. */
nscans = 10; nscans = 10;
} else { } else {
/* All-purpose script for other color spaces. */ /* All-purpose script for other color spaces. */
@ -583,7 +624,7 @@ jpeg_simple_progression (j_compress_ptr cinfo)
* multiple compressions without changing the settings. To avoid a memory * multiple compressions without changing the settings. To avoid a memory
* leak if jpeg_simple_progression is called repeatedly for the same JPEG * leak if jpeg_simple_progression is called repeatedly for the same JPEG
* object, we try to re-use previously allocated space, and we allocate * object, we try to re-use previously allocated space, and we allocate
* enough space to handle YCbCr even if initially asked for grayscale. * enough space to handle YCC even if initially asked for grayscale.
*/ */
if (cinfo->script_space == NULL || cinfo->script_space_size < nscans) { if (cinfo->script_space == NULL || cinfo->script_space_size < nscans) {
cinfo->script_space_size = MAX(nscans, 10); cinfo->script_space_size = MAX(nscans, 10);
@ -595,8 +636,10 @@ jpeg_simple_progression (j_compress_ptr cinfo)
cinfo->scan_info = scanptr; cinfo->scan_info = scanptr;
cinfo->num_scans = nscans; cinfo->num_scans = nscans;
if (ncomps == 3 && cinfo->jpeg_color_space == JCS_YCbCr) { if (ncomps == 3 &&
/* Custom script for YCbCr color images. */ (cinfo->jpeg_color_space == JCS_YCbCr ||
cinfo->jpeg_color_space == JCS_BG_YCC)) {
/* Custom script for YCC color images. */
/* Initial DC scan */ /* Initial DC scan */
scanptr = fill_dc_scans(scanptr, ncomps, 0, 1); scanptr = fill_dc_scans(scanptr, ncomps, 0, 1);
/* Initial AC scan: get some luma data out in a hurry */ /* Initial AC scan: get some luma data out in a hurry */

View File

@ -2,7 +2,7 @@
* jctrans.c * jctrans.c
* *
* Copyright (C) 1995-1998, Thomas G. Lane. * Copyright (C) 1995-1998, Thomas G. Lane.
* Modified 2000-2009 by Guido Vollbeding. * Modified 2000-2013 by Guido Vollbeding.
* This file is part of the Independent JPEG Group's software. * This file is part of the Independent JPEG Group's software.
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
@ -85,7 +85,10 @@ jpeg_copy_critical_parameters (j_decompress_ptr srcinfo,
jpeg_set_defaults(dstinfo); jpeg_set_defaults(dstinfo);
/* jpeg_set_defaults may choose wrong colorspace, eg YCbCr if input is RGB. /* jpeg_set_defaults may choose wrong colorspace, eg YCbCr if input is RGB.
* Fix it to get the right header markers for the image colorspace. * Fix it to get the right header markers for the image colorspace.
* Note: Entropy table assignment in jpeg_set_colorspace depends
* on color_transform.
*/ */
dstinfo->color_transform = srcinfo->color_transform;
jpeg_set_colorspace(dstinfo, srcinfo->jpeg_color_space); jpeg_set_colorspace(dstinfo, srcinfo->jpeg_color_space);
dstinfo->data_precision = srcinfo->data_precision; dstinfo->data_precision = srcinfo->data_precision;
dstinfo->CCIR601_sampling = srcinfo->CCIR601_sampling; dstinfo->CCIR601_sampling = srcinfo->CCIR601_sampling;
@ -130,7 +133,7 @@ jpeg_copy_critical_parameters (j_decompress_ptr srcinfo,
ERREXIT1(dstinfo, JERR_MISMATCHED_QUANT_TABLE, tblno); ERREXIT1(dstinfo, JERR_MISMATCHED_QUANT_TABLE, tblno);
} }
} }
/* Note: we do not copy the source's Huffman table assignments; /* Note: we do not copy the source's entropy table assignments;
* instead we rely on jpeg_set_colorspace to have made a suitable choice. * instead we rely on jpeg_set_colorspace to have made a suitable choice.
*/ */
} }
@ -140,10 +143,10 @@ jpeg_copy_critical_parameters (j_decompress_ptr srcinfo,
* if the application chooses to copy JFIF 1.02 extension markers from * if the application chooses to copy JFIF 1.02 extension markers from
* the source file, we need to copy the version to make sure we don't * the source file, we need to copy the version to make sure we don't
* emit a file that has 1.02 extensions but a claimed version of 1.01. * emit a file that has 1.02 extensions but a claimed version of 1.01.
* We will *not*, however, copy version info from mislabeled "2.01" files.
*/ */
if (srcinfo->saw_JFIF_marker) { if (srcinfo->saw_JFIF_marker) {
if (srcinfo->JFIF_major_version == 1) { if (srcinfo->JFIF_major_version == 1 ||
srcinfo->JFIF_major_version == 2) {
dstinfo->JFIF_major_version = srcinfo->JFIF_major_version; dstinfo->JFIF_major_version = srcinfo->JFIF_major_version;
dstinfo->JFIF_minor_version = srcinfo->JFIF_minor_version; dstinfo->JFIF_minor_version = srcinfo->JFIF_minor_version;
} }
@ -364,7 +367,7 @@ transencode_coef_controller (j_compress_ptr cinfo,
coef = (my_coef_ptr) coef = (my_coef_ptr)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
SIZEOF(my_coef_controller)); SIZEOF(my_coef_controller));
cinfo->coef = (struct jpeg_c_coef_controller *) coef; cinfo->coef = &coef->pub;
coef->pub.start_pass = start_pass_coef; coef->pub.start_pass = start_pass_coef;
coef->pub.compress_data = compress_output; coef->pub.compress_data = compress_output;
@ -375,7 +378,7 @@ transencode_coef_controller (j_compress_ptr cinfo,
buffer = (JBLOCKROW) buffer = (JBLOCKROW)
(*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
C_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK)); C_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK));
jzero_far((void FAR *) buffer, C_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK)); FMEMZERO((void FAR *) buffer, C_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK));
for (i = 0; i < C_MAX_BLOCKS_IN_MCU; i++) { for (i = 0; i < C_MAX_BLOCKS_IN_MCU; i++) {
coef->dummy_buffer[i] = buffer + i; coef->dummy_buffer[i] = buffer + i;
} }

View File

@ -2,7 +2,7 @@
* jdapimin.c * jdapimin.c
* *
* Copyright (C) 1994-1998, Thomas G. Lane. * Copyright (C) 1994-1998, Thomas G. Lane.
* Modified 2009 by Guido Vollbeding. * Modified 2009-2013 by Guido Vollbeding.
* This file is part of the Independent JPEG Group's software. * This file is part of the Independent JPEG Group's software.
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
@ -114,8 +114,9 @@ jpeg_abort_decompress (j_decompress_ptr cinfo)
LOCAL(void) LOCAL(void)
default_decompress_parms (j_decompress_ptr cinfo) default_decompress_parms (j_decompress_ptr cinfo)
{ {
int cid0, cid1, cid2;
/* Guess the input colorspace, and set output colorspace accordingly. */ /* Guess the input colorspace, and set output colorspace accordingly. */
/* (Wish JPEG committee had provided a real way to specify this...) */
/* Note application may override our guesses. */ /* Note application may override our guesses. */
switch (cinfo->num_components) { switch (cinfo->num_components) {
case 1: case 1:
@ -124,9 +125,22 @@ default_decompress_parms (j_decompress_ptr cinfo)
break; break;
case 3: case 3:
if (cinfo->saw_JFIF_marker) { cid0 = cinfo->comp_info[0].component_id;
cinfo->jpeg_color_space = JCS_YCbCr; /* JFIF implies YCbCr */ cid1 = cinfo->comp_info[1].component_id;
} else if (cinfo->saw_Adobe_marker) { cid2 = cinfo->comp_info[2].component_id;
/* First try to guess from the component IDs */
if (cid0 == 0x01 && cid1 == 0x02 && cid2 == 0x03)
cinfo->jpeg_color_space = JCS_YCbCr;
else if (cid0 == 0x01 && cid1 == 0x22 && cid2 == 0x23)
cinfo->jpeg_color_space = JCS_BG_YCC;
else if (cid0 == 0x52 && cid1 == 0x47 && cid2 == 0x42)
cinfo->jpeg_color_space = JCS_RGB; /* ASCII 'R', 'G', 'B' */
else if (cid0 == 0x72 && cid1 == 0x67 && cid2 == 0x62)
cinfo->jpeg_color_space = JCS_BG_RGB; /* ASCII 'r', 'g', 'b' */
else if (cinfo->saw_JFIF_marker)
cinfo->jpeg_color_space = JCS_YCbCr; /* assume it's YCbCr */
else if (cinfo->saw_Adobe_marker) {
switch (cinfo->Adobe_transform) { switch (cinfo->Adobe_transform) {
case 0: case 0:
cinfo->jpeg_color_space = JCS_RGB; cinfo->jpeg_color_space = JCS_RGB;
@ -136,23 +150,12 @@ default_decompress_parms (j_decompress_ptr cinfo)
break; break;
default: default:
WARNMS1(cinfo, JWRN_ADOBE_XFORM, cinfo->Adobe_transform); WARNMS1(cinfo, JWRN_ADOBE_XFORM, cinfo->Adobe_transform);
cinfo->jpeg_color_space = JCS_YCbCr; /* assume it's YCbCr */ cinfo->jpeg_color_space = JCS_YCbCr; /* assume it's YCbCr */
break; break;
} }
} else { } else {
/* Saw no special markers, try to guess from the component IDs */ TRACEMS3(cinfo, 1, JTRC_UNKNOWN_IDS, cid0, cid1, cid2);
int cid0 = cinfo->comp_info[0].component_id; cinfo->jpeg_color_space = JCS_YCbCr; /* assume it's YCbCr */
int cid1 = cinfo->comp_info[1].component_id;
int cid2 = cinfo->comp_info[2].component_id;
if (cid0 == 1 && cid1 == 2 && cid2 == 3)
cinfo->jpeg_color_space = JCS_YCbCr; /* assume JFIF w/out marker */
else if (cid0 == 82 && cid1 == 71 && cid2 == 66)
cinfo->jpeg_color_space = JCS_RGB; /* ASCII 'R', 'G', 'B' */
else {
TRACEMS3(cinfo, 1, JTRC_UNKNOWN_IDS, cid0, cid1, cid2);
cinfo->jpeg_color_space = JCS_YCbCr; /* assume it's YCbCr */
}
} }
/* Always guess RGB is proper output colorspace. */ /* Always guess RGB is proper output colorspace. */
cinfo->out_color_space = JCS_RGB; cinfo->out_color_space = JCS_RGB;
@ -169,7 +172,7 @@ default_decompress_parms (j_decompress_ptr cinfo)
break; break;
default: default:
WARNMS1(cinfo, JWRN_ADOBE_XFORM, cinfo->Adobe_transform); WARNMS1(cinfo, JWRN_ADOBE_XFORM, cinfo->Adobe_transform);
cinfo->jpeg_color_space = JCS_YCCK; /* assume it's YCCK */ cinfo->jpeg_color_space = JCS_YCCK; /* assume it's YCCK */
break; break;
} }
} else { } else {

View File

@ -2,6 +2,7 @@
* jdapistd.c * jdapistd.c
* *
* Copyright (C) 1994-1996, Thomas G. Lane. * Copyright (C) 1994-1996, Thomas G. Lane.
* Modified 2002-2013 by Guido Vollbeding.
* This file is part of the Independent JPEG Group's software. * This file is part of the Independent JPEG Group's software.
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *

View File

@ -1,7 +1,7 @@
/* /*
* jdarith.c * jdarith.c
* *
* Developed 1997-2009 by Guido Vollbeding. * Developed 1997-2013 by Guido Vollbeding.
* This file is part of the Independent JPEG Group's software. * This file is part of the Independent JPEG Group's software.
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
@ -145,7 +145,7 @@ arith_decode (j_decompress_ptr cinfo, unsigned char *st)
e->a <<= 1; e->a <<= 1;
} }
/* Fetch values from our compact representation of Table D.2: /* Fetch values from our compact representation of Table D.3(D.2):
* Qe values and probability estimation state machine * Qe values and probability estimation state machine
*/ */
sv = *st; sv = *st;
@ -345,12 +345,15 @@ decode_mcu_AC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
/* Sections F.2.4.2 & F.1.4.4.2: Decoding of AC coefficients */ /* Sections F.2.4.2 & F.1.4.4.2: Decoding of AC coefficients */
/* Figure F.20: Decode_AC_coefficients */ /* Figure F.20: Decode_AC_coefficients */
for (k = cinfo->Ss; k <= cinfo->Se; k++) { k = cinfo->Ss - 1;
st = entropy->ac_stats[tbl] + 3 * (k - 1); do {
st = entropy->ac_stats[tbl] + 3 * k;
if (arith_decode(cinfo, st)) break; /* EOB flag */ if (arith_decode(cinfo, st)) break; /* EOB flag */
while (arith_decode(cinfo, st + 1) == 0) { for (;;) {
st += 3; k++; k++;
if (k > cinfo->Se) { if (arith_decode(cinfo, st + 1)) break;
st += 3;
if (k >= cinfo->Se) {
WARNMS(cinfo, JWRN_ARITH_BAD_CODE); WARNMS(cinfo, JWRN_ARITH_BAD_CODE);
entropy->ct = -1; /* spectral overflow */ entropy->ct = -1; /* spectral overflow */
return TRUE; return TRUE;
@ -384,7 +387,7 @@ decode_mcu_AC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
v += 1; if (sign) v = -v; v += 1; if (sign) v = -v;
/* Scale and output coefficient in natural (dezigzagged) order */ /* Scale and output coefficient in natural (dezigzagged) order */
(*block)[natural_order[k]] = (JCOEF) (v << cinfo->Al); (*block)[natural_order[k]] = (JCOEF) (v << cinfo->Al);
} } while (k < cinfo->Se);
return TRUE; return TRUE;
} }
@ -392,6 +395,8 @@ decode_mcu_AC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
/* /*
* MCU decoding for DC successive approximation refinement scan. * MCU decoding for DC successive approximation refinement scan.
* Note: we assume such scans can be multi-component,
* although the spec is not very clear on the point.
*/ */
METHODDEF(boolean) METHODDEF(boolean)
@ -457,15 +462,18 @@ decode_mcu_AC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
m1 = (-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 */ /* Establish EOBx (previous stage end-of-block) index */
for (kex = cinfo->Se; kex > 0; kex--) kex = cinfo->Se;
do {
if ((*block)[natural_order[kex]]) break; if ((*block)[natural_order[kex]]) break;
} while (--kex);
for (k = cinfo->Ss; k <= cinfo->Se; k++) { k = cinfo->Ss - 1;
st = entropy->ac_stats[tbl] + 3 * (k - 1); do {
if (k > kex) st = entropy->ac_stats[tbl] + 3 * k;
if (k >= kex)
if (arith_decode(cinfo, st)) break; /* EOB flag */ if (arith_decode(cinfo, st)) break; /* EOB flag */
for (;;) { for (;;) {
thiscoef = *block + natural_order[k]; thiscoef = *block + natural_order[++k];
if (*thiscoef) { /* previously nonzero coef */ if (*thiscoef) { /* previously nonzero coef */
if (arith_decode(cinfo, st + 2)) { if (arith_decode(cinfo, st + 2)) {
if (*thiscoef < 0) if (*thiscoef < 0)
@ -482,14 +490,14 @@ decode_mcu_AC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
*thiscoef = p1; *thiscoef = p1;
break; break;
} }
st += 3; k++; st += 3;
if (k > cinfo->Se) { if (k >= cinfo->Se) {
WARNMS(cinfo, JWRN_ARITH_BAD_CODE); WARNMS(cinfo, JWRN_ARITH_BAD_CODE);
entropy->ct = -1; /* spectral overflow */ entropy->ct = -1; /* spectral overflow */
return TRUE; return TRUE;
} }
} }
} } while (k < cinfo->Se);
return TRUE; return TRUE;
} }
@ -575,15 +583,19 @@ decode_mcu (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
/* Sections F.2.4.2 & F.1.4.4.2: Decoding of AC coefficients */ /* Sections F.2.4.2 & F.1.4.4.2: Decoding of AC coefficients */
if (cinfo->lim_Se == 0) continue;
tbl = compptr->ac_tbl_no; tbl = compptr->ac_tbl_no;
k = 0;
/* Figure F.20: Decode_AC_coefficients */ /* Figure F.20: Decode_AC_coefficients */
for (k = 1; k <= cinfo->lim_Se; k++) { do {
st = entropy->ac_stats[tbl] + 3 * (k - 1); st = entropy->ac_stats[tbl] + 3 * k;
if (arith_decode(cinfo, st)) break; /* EOB flag */ if (arith_decode(cinfo, st)) break; /* EOB flag */
while (arith_decode(cinfo, st + 1) == 0) { for (;;) {
st += 3; k++; k++;
if (k > cinfo->lim_Se) { if (arith_decode(cinfo, st + 1)) break;
st += 3;
if (k >= cinfo->lim_Se) {
WARNMS(cinfo, JWRN_ARITH_BAD_CODE); WARNMS(cinfo, JWRN_ARITH_BAD_CODE);
entropy->ct = -1; /* spectral overflow */ entropy->ct = -1; /* spectral overflow */
return TRUE; return TRUE;
@ -616,7 +628,7 @@ decode_mcu (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
if (arith_decode(cinfo, st)) v |= m; if (arith_decode(cinfo, st)) v |= m;
v += 1; if (sign) v = -v; v += 1; if (sign) v = -v;
(*block)[natural_order[k]] = (JCOEF) v; (*block)[natural_order[k]] = (JCOEF) v;
} } while (k < cinfo->lim_Se);
} }
return TRUE; return TRUE;
@ -733,6 +745,17 @@ start_pass (j_decompress_ptr cinfo)
} }
/*
* Finish up at the end of an arithmetic-compressed scan.
*/
METHODDEF(void)
finish_pass (j_decompress_ptr cinfo)
{
/* no work necessary here */
}
/* /*
* Module initialization routine for arithmetic entropy decoding. * Module initialization routine for arithmetic entropy decoding.
*/ */
@ -746,8 +769,9 @@ jinit_arith_decoder (j_decompress_ptr cinfo)
entropy = (arith_entropy_ptr) entropy = (arith_entropy_ptr)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
SIZEOF(arith_entropy_decoder)); SIZEOF(arith_entropy_decoder));
cinfo->entropy = (struct jpeg_entropy_decoder *) entropy; cinfo->entropy = &entropy->pub;
entropy->pub.start_pass = start_pass; entropy->pub.start_pass = start_pass;
entropy->pub.finish_pass = finish_pass;
/* Mark tables unallocated */ /* Mark tables unallocated */
for (i = 0; i < NUM_ARITH_TBLS; i++) { for (i = 0; i < NUM_ARITH_TBLS; i++) {

View File

@ -2,7 +2,7 @@
* jdatadst.c * jdatadst.c
* *
* Copyright (C) 1994-1996, Thomas G. Lane. * Copyright (C) 1994-1996, Thomas G. Lane.
* Modified 2009 by Guido Vollbeding. * Modified 2009-2012 by Guido Vollbeding.
* This file is part of the Independent JPEG Group's software. * This file is part of the Independent JPEG Group's software.
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
@ -128,7 +128,7 @@ empty_mem_output_buffer (j_compress_ptr cinfo)
/* Try to allocate new buffer with double size */ /* Try to allocate new buffer with double size */
nextsize = dest->bufsize * 2; nextsize = dest->bufsize * 2;
nextbuffer = malloc(nextsize); nextbuffer = (JOCTET *) malloc(nextsize);
if (nextbuffer == NULL) if (nextbuffer == NULL)
ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, 10); ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, 10);
@ -182,7 +182,7 @@ term_mem_destination (j_compress_ptr cinfo)
my_mem_dest_ptr dest = (my_mem_dest_ptr) cinfo->dest; my_mem_dest_ptr dest = (my_mem_dest_ptr) cinfo->dest;
*dest->outbuffer = dest->buffer; *dest->outbuffer = dest->buffer;
*dest->outsize = (unsigned long) (dest->bufsize - dest->pub.free_in_buffer); *dest->outsize = dest->bufsize - dest->pub.free_in_buffer;
} }
@ -226,6 +226,9 @@ jpeg_stdio_dest (j_compress_ptr cinfo, FILE * outfile)
* larger memory, so the buffer is available to the application after * larger memory, so the buffer is available to the application after
* finishing compression, and then the application is responsible for * finishing compression, and then the application is responsible for
* freeing the requested memory. * freeing the requested memory.
* Note: An initial buffer supplied by the caller is expected to be
* managed by the application. The library does not free such buffer
* when allocating a larger buffer.
*/ */
GLOBAL(void) GLOBAL(void)
@ -256,7 +259,7 @@ jpeg_mem_dest (j_compress_ptr cinfo,
if (*outbuffer == NULL || *outsize == 0) { if (*outbuffer == NULL || *outsize == 0) {
/* Allocate initial buffer */ /* Allocate initial buffer */
dest->newbuffer = *outbuffer = malloc(OUTPUT_BUF_SIZE); dest->newbuffer = *outbuffer = (unsigned char *) malloc(OUTPUT_BUF_SIZE);
if (dest->newbuffer == NULL) if (dest->newbuffer == NULL)
ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, 10); ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, 10);
*outsize = OUTPUT_BUF_SIZE; *outsize = OUTPUT_BUF_SIZE;

View File

@ -2,7 +2,7 @@
* jdatasrc.c * jdatasrc.c
* *
* Copyright (C) 1994-1996, Thomas G. Lane. * Copyright (C) 1994-1996, Thomas G. Lane.
* Modified 2009-2010 by Guido Vollbeding. * Modified 2009-2011 by Guido Vollbeding.
* This file is part of the Independent JPEG Group's software. * This file is part of the Independent JPEG Group's software.
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
@ -121,16 +121,17 @@ fill_input_buffer (j_decompress_ptr cinfo)
METHODDEF(boolean) METHODDEF(boolean)
fill_mem_input_buffer (j_decompress_ptr cinfo) fill_mem_input_buffer (j_decompress_ptr cinfo)
{ {
static JOCTET mybuffer[4]; static const JOCTET mybuffer[4] = {
(JOCTET) 0xFF, (JOCTET) JPEG_EOI, 0, 0
};
/* The whole JPEG data is expected to reside in the supplied memory /* The whole JPEG data is expected to reside in the supplied memory
* buffer, so any request for more data beyond the given buffer size * buffer, so any request for more data beyond the given buffer size
* is treated as an error. * is treated as an error.
*/ */
WARNMS(cinfo, JWRN_JPEG_EOF); WARNMS(cinfo, JWRN_JPEG_EOF);
/* Insert a fake EOI marker */ /* Insert a fake EOI marker */
mybuffer[0] = (JOCTET) 0xFF;
mybuffer[1] = (JOCTET) JPEG_EOI;
cinfo->src->next_input_byte = mybuffer; cinfo->src->next_input_byte = mybuffer;
cinfo->src->bytes_in_buffer = 2; cinfo->src->bytes_in_buffer = 2;

View File

@ -2,6 +2,7 @@
* jdcoefct.c * jdcoefct.c
* *
* Copyright (C) 1994-1997, Thomas G. Lane. * Copyright (C) 1994-1997, Thomas G. Lane.
* Modified 2002-2011 by Guido Vollbeding.
* This file is part of the Independent JPEG Group's software. * This file is part of the Independent JPEG Group's software.
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
@ -162,8 +163,9 @@ decompress_onepass (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
for (MCU_col_num = coef->MCU_ctr; MCU_col_num <= last_MCU_col; for (MCU_col_num = coef->MCU_ctr; MCU_col_num <= last_MCU_col;
MCU_col_num++) { MCU_col_num++) {
/* Try to fetch an MCU. Entropy decoder expects buffer to be zeroed. */ /* Try to fetch an MCU. Entropy decoder expects buffer to be zeroed. */
jzero_far((void FAR *) coef->MCU_buffer[0], if (cinfo->lim_Se) /* can bypass in DC only case */
(size_t) (cinfo->blocks_in_MCU * SIZEOF(JBLOCK))); FMEMZERO((void FAR *) coef->MCU_buffer[0],
(size_t) (cinfo->blocks_in_MCU * SIZEOF(JBLOCK)));
if (! (*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) { if (! (*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) {
/* Suspension forced; update state counters and exit */ /* Suspension forced; update state counters and exit */
coef->MCU_vert_offset = yoffset; coef->MCU_vert_offset = yoffset;
@ -729,6 +731,9 @@ jinit_d_coef_controller (j_decompress_ptr cinfo, boolean need_full_buffer)
for (i = 0; i < D_MAX_BLOCKS_IN_MCU; i++) { for (i = 0; i < D_MAX_BLOCKS_IN_MCU; i++) {
coef->MCU_buffer[i] = buffer + i; coef->MCU_buffer[i] = buffer + i;
} }
if (cinfo->lim_Se == 0) /* DC only case: want to bypass later */
FMEMZERO((void FAR *) buffer,
(size_t) (D_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK)));
coef->pub.consume_data = dummy_consume_data; coef->pub.consume_data = dummy_consume_data;
coef->pub.decompress_data = decompress_onepass; coef->pub.decompress_data = decompress_onepass;
coef->pub.coef_arrays = NULL; /* flag for no virtual arrays */ coef->pub.coef_arrays = NULL; /* flag for no virtual arrays */

View File

@ -2,6 +2,7 @@
* jdcolor.c * jdcolor.c
* *
* Copyright (C) 1991-1997, Thomas G. Lane. * Copyright (C) 1991-1997, Thomas G. Lane.
* Modified 2011-2013 by Guido Vollbeding.
* This file is part of the Independent JPEG Group's software. * This file is part of the Independent JPEG Group's software.
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
@ -18,27 +19,60 @@
typedef struct { typedef struct {
struct jpeg_color_deconverter pub; /* public fields */ struct jpeg_color_deconverter pub; /* public fields */
/* Private state for YCC->RGB conversion */ /* Private state for YCbCr->RGB and BG_YCC->RGB conversion */
int * Cr_r_tab; /* => table for Cr to R conversion */ int * Cr_r_tab; /* => table for Cr to R conversion */
int * Cb_b_tab; /* => table for Cb to B conversion */ int * Cb_b_tab; /* => table for Cb to B conversion */
INT32 * Cr_g_tab; /* => table for Cr to G conversion */ INT32 * Cr_g_tab; /* => table for Cr to G conversion */
INT32 * Cb_g_tab; /* => table for Cb to G conversion */ INT32 * Cb_g_tab; /* => table for Cb to G conversion */
JSAMPLE * range_limit; /* pointer to normal sample range limit table, */
/* or extended sample range limit table for BG_YCC */
/* Private state for RGB->Y conversion */
INT32 * rgb_y_tab; /* => table for RGB to Y conversion */
} my_color_deconverter; } my_color_deconverter;
typedef my_color_deconverter * my_cconvert_ptr; typedef my_color_deconverter * my_cconvert_ptr;
/**************** YCbCr -> RGB conversion: most common case **************/ /*************** YCbCr -> RGB conversion: most common case **************/
/*************** BG_YCC -> RGB conversion: less common case **************/
/*************** RGB -> Y conversion: less common case **************/
/* /*
* YCbCr is defined per CCIR 601-1, except that Cb and Cr are * YCbCr is defined per Recommendation ITU-R BT.601-7 (03/2011),
* normalized to the range 0..MAXJSAMPLE rather than -0.5 .. 0.5. * previously known as Recommendation CCIR 601-1, except that Cb and Cr
* The conversion equations to be implemented are therefore * are normalized to the range 0..MAXJSAMPLE rather than -0.5 .. 0.5.
* R = Y + 1.40200 * Cr * sRGB (standard RGB color space) is defined per IEC 61966-2-1:1999.
* G = Y - 0.34414 * Cb - 0.71414 * Cr * sYCC (standard luma-chroma-chroma color space with extended gamut)
* B = Y + 1.77200 * Cb * is defined per IEC 61966-2-1:1999 Amendment A1:2003 Annex F.
* bg-sRGB and bg-sYCC (big gamut standard color spaces)
* are defined per IEC 61966-2-1:1999 Amendment A1:2003 Annex G.
* Note that the derived conversion coefficients given in some of these
* documents are imprecise. The general conversion equations are
*
* R = Y + K * (1 - Kr) * Cr
* G = Y - K * (Kb * (1 - Kb) * Cb + Kr * (1 - Kr) * Cr) / (1 - Kr - Kb)
* B = Y + K * (1 - Kb) * Cb
*
* Y = Kr * R + (1 - Kr - Kb) * G + Kb * B
*
* With Kr = 0.299 and Kb = 0.114 (derived according to SMPTE RP 177-1993
* from the 1953 FCC NTSC primaries and CIE Illuminant C), K = 2 for sYCC,
* the conversion equations to be implemented are therefore
*
* R = Y + 1.402 * Cr
* G = Y - 0.344136286 * Cb - 0.714136286 * Cr
* B = Y + 1.772 * Cb
*
* Y = 0.299 * R + 0.587 * G + 0.114 * B
*
* where Cb and Cr represent the incoming values less CENTERJSAMPLE. * where Cb and Cr represent the incoming values less CENTERJSAMPLE.
* (These numbers are derived from TIFF 6.0 section 21, dated 3-June-92.) * For bg-sYCC, with K = 4, the equations are
*
* R = Y + 2.804 * Cr
* G = Y - 0.688272572 * Cb - 1.428272572 * Cr
* B = Y + 3.544 * Cb
* *
* To avoid floating-point arithmetic, we represent the fractional constants * To avoid floating-point arithmetic, we represent the fractional constants
* as integers scaled up by 2^16 (about 4 digits precision); we have to divide * as integers scaled up by 2^16 (about 4 digits precision); we have to divide
@ -49,9 +83,9 @@ typedef my_color_deconverter * my_cconvert_ptr;
* For even more speed, we avoid doing any multiplications in the inner loop * For even more speed, we avoid doing any multiplications in the inner loop
* by precalculating the constants times Cb and Cr for all possible values. * by precalculating the constants times Cb and Cr for all possible values.
* For 8-bit JSAMPLEs this is very reasonable (only 256 entries per table); * For 8-bit JSAMPLEs this is very reasonable (only 256 entries per table);
* for 12-bit samples it is still acceptable. It's not very reasonable for * for 9-bit to 12-bit samples it is still acceptable. It's not very
* 16-bit samples, but if you want lossless storage you shouldn't be changing * reasonable for 16-bit samples, but if you want lossless storage you
* colorspace anyway. * shouldn't be changing colorspace anyway.
* The Cr=>R and Cb=>B values can be rounded to integers in advance; the * The Cr=>R and Cb=>B values can be rounded to integers in advance; the
* values for the G calculation are left scaled up, since we must add them * values for the G calculation are left scaled up, since we must add them
* together before rounding. * together before rounding.
@ -61,13 +95,26 @@ typedef my_color_deconverter * my_cconvert_ptr;
#define ONE_HALF ((INT32) 1 << (SCALEBITS-1)) #define ONE_HALF ((INT32) 1 << (SCALEBITS-1))
#define FIX(x) ((INT32) ((x) * (1L<<SCALEBITS) + 0.5)) #define FIX(x) ((INT32) ((x) * (1L<<SCALEBITS) + 0.5))
/* We allocate one big table for RGB->Y conversion and divide it up into
* three parts, instead of doing three alloc_small requests. This lets us
* use a single table base address, which can be held in a register in the
* inner loops on many machines (more than can hold all three addresses,
* anyway).
*/
#define R_Y_OFF 0 /* offset to R => Y section */
#define G_Y_OFF (1*(MAXJSAMPLE+1)) /* offset to G => Y section */
#define B_Y_OFF (2*(MAXJSAMPLE+1)) /* etc. */
#define TABLE_SIZE (3*(MAXJSAMPLE+1))
/* /*
* Initialize tables for YCC->RGB colorspace conversion. * Initialize tables for YCbCr->RGB and BG_YCC->RGB colorspace conversion.
*/ */
LOCAL(void) LOCAL(void)
build_ycc_rgb_table (j_decompress_ptr cinfo) build_ycc_rgb_table (j_decompress_ptr cinfo)
/* Normal case, sYCC */
{ {
my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert; my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
int i; int i;
@ -87,24 +134,84 @@ build_ycc_rgb_table (j_decompress_ptr cinfo)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
(MAXJSAMPLE+1) * SIZEOF(INT32)); (MAXJSAMPLE+1) * SIZEOF(INT32));
cconvert->range_limit = cinfo->sample_range_limit;
for (i = 0, x = -CENTERJSAMPLE; i <= MAXJSAMPLE; i++, x++) { for (i = 0, x = -CENTERJSAMPLE; i <= MAXJSAMPLE; i++, x++) {
/* i is the actual input pixel value, in the range 0..MAXJSAMPLE */ /* i is the actual input pixel value, in the range 0..MAXJSAMPLE */
/* The Cb or Cr value we are thinking of is x = i - CENTERJSAMPLE */ /* The Cb or Cr value we are thinking of is x = i - CENTERJSAMPLE */
/* Cr=>R value is nearest int to 1.40200 * x */ /* Cr=>R value is nearest int to 1.402 * x */
cconvert->Cr_r_tab[i] = (int) cconvert->Cr_r_tab[i] = (int)
RIGHT_SHIFT(FIX(1.40200) * x + ONE_HALF, SCALEBITS); RIGHT_SHIFT(FIX(1.402) * x + ONE_HALF, SCALEBITS);
/* Cb=>B value is nearest int to 1.77200 * x */ /* Cb=>B value is nearest int to 1.772 * x */
cconvert->Cb_b_tab[i] = (int) cconvert->Cb_b_tab[i] = (int)
RIGHT_SHIFT(FIX(1.77200) * x + ONE_HALF, SCALEBITS); RIGHT_SHIFT(FIX(1.772) * x + ONE_HALF, SCALEBITS);
/* Cr=>G value is scaled-up -0.71414 * x */ /* Cr=>G value is scaled-up -0.714136286 * x */
cconvert->Cr_g_tab[i] = (- FIX(0.71414)) * x; cconvert->Cr_g_tab[i] = (- FIX(0.714136286)) * x;
/* Cb=>G value is scaled-up -0.34414 * x */ /* Cb=>G value is scaled-up -0.344136286 * x */
/* We also add in ONE_HALF so that need not do it in inner loop */ /* We also add in ONE_HALF so that need not do it in inner loop */
cconvert->Cb_g_tab[i] = (- FIX(0.34414)) * x + ONE_HALF; cconvert->Cb_g_tab[i] = (- FIX(0.344136286)) * x + ONE_HALF;
} }
} }
LOCAL(void)
build_bg_ycc_rgb_table (j_decompress_ptr cinfo)
/* Wide gamut case, bg-sYCC */
{
my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
int i;
INT32 x;
SHIFT_TEMPS
cconvert->Cr_r_tab = (int *)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
(MAXJSAMPLE+1) * SIZEOF(int));
cconvert->Cb_b_tab = (int *)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
(MAXJSAMPLE+1) * SIZEOF(int));
cconvert->Cr_g_tab = (INT32 *)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
(MAXJSAMPLE+1) * SIZEOF(INT32));
cconvert->Cb_g_tab = (INT32 *)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
(MAXJSAMPLE+1) * SIZEOF(INT32));
cconvert->range_limit = (JSAMPLE *)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
5 * (MAXJSAMPLE+1) * SIZEOF(JSAMPLE));
for (i = 0, x = -CENTERJSAMPLE; i <= MAXJSAMPLE; i++, x++) {
/* i is the actual input pixel value, in the range 0..MAXJSAMPLE */
/* The Cb or Cr value we are thinking of is x = i - CENTERJSAMPLE */
/* Cr=>R value is nearest int to 2.804 * x */
cconvert->Cr_r_tab[i] = (int)
RIGHT_SHIFT(FIX(2.804) * x + ONE_HALF, SCALEBITS);
/* Cb=>B value is nearest int to 3.544 * x */
cconvert->Cb_b_tab[i] = (int)
RIGHT_SHIFT(FIX(3.544) * x + ONE_HALF, SCALEBITS);
/* Cr=>G value is scaled-up -1.428272572 * x */
cconvert->Cr_g_tab[i] = (- FIX(1.428272572)) * x;
/* Cb=>G value is scaled-up -0.688272572 * x */
/* We also add in ONE_HALF so that need not do it in inner loop */
cconvert->Cb_g_tab[i] = (- FIX(0.688272572)) * x + ONE_HALF;
}
/* Cb and Cr portions can extend to double range in wide gamut case,
* so we prepare an appropriate extended range limit table.
*/
/* First segment of range limit table: limit[x] = 0 for x < 0 */
MEMZERO(cconvert->range_limit, 2 * (MAXJSAMPLE+1) * SIZEOF(JSAMPLE));
cconvert->range_limit += 2 * (MAXJSAMPLE+1);
/* Main part of range limit table: limit[x] = x */
for (i = 0; i <= MAXJSAMPLE; i++)
cconvert->range_limit[i] = (JSAMPLE) i;
/* End of range limit table: limit[x] = MAXJSAMPLE for x > MAXJSAMPLE */
for (; i < 3 * (MAXJSAMPLE+1); i++)
cconvert->range_limit[i] = MAXJSAMPLE;
}
/* /*
* Convert some rows of samples to the output colorspace. * Convert some rows of samples to the output colorspace.
* *
@ -128,7 +235,7 @@ ycc_rgb_convert (j_decompress_ptr cinfo,
register JDIMENSION col; register JDIMENSION col;
JDIMENSION num_cols = cinfo->output_width; JDIMENSION num_cols = cinfo->output_width;
/* copy these pointers into registers if possible */ /* copy these pointers into registers if possible */
register JSAMPLE * range_limit = cinfo->sample_range_limit; register JSAMPLE * range_limit = cconvert->range_limit;
register int * Crrtab = cconvert->Cr_r_tab; register int * Crrtab = cconvert->Cr_r_tab;
register int * Cbbtab = cconvert->Cb_b_tab; register int * Cbbtab = cconvert->Cb_b_tab;
register INT32 * Crgtab = cconvert->Cr_g_tab; register INT32 * Crgtab = cconvert->Cr_g_tab;
@ -145,19 +252,196 @@ ycc_rgb_convert (j_decompress_ptr cinfo,
y = GETJSAMPLE(inptr0[col]); y = GETJSAMPLE(inptr0[col]);
cb = GETJSAMPLE(inptr1[col]); cb = GETJSAMPLE(inptr1[col]);
cr = GETJSAMPLE(inptr2[col]); cr = GETJSAMPLE(inptr2[col]);
/* Range-limiting is essential due to noise introduced by DCT losses. */ /* Range-limiting is essential due to noise introduced by DCT losses,
outptr[RGB_RED] = range_limit[y + Crrtab[cr]]; * for extended gamut (sYCC) and wide gamut (bg-sYCC) encodings.
*/
outptr[RGB_RED] = range_limit[y + Crrtab[cr]];
outptr[RGB_GREEN] = range_limit[y + outptr[RGB_GREEN] = range_limit[y +
((int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], ((int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
SCALEBITS))]; SCALEBITS))];
outptr[RGB_BLUE] = range_limit[y + Cbbtab[cb]]; outptr[RGB_BLUE] = range_limit[y + Cbbtab[cb]];
outptr += RGB_PIXELSIZE; outptr += RGB_PIXELSIZE;
} }
} }
} }
/**************** Cases other than YCbCr -> RGB **************/ /**************** Cases other than YCC -> RGB ****************/
/*
* Initialize for RGB->grayscale colorspace conversion.
*/
LOCAL(void)
build_rgb_y_table (j_decompress_ptr cinfo)
{
my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
INT32 * rgb_y_tab;
INT32 i;
/* Allocate and fill in the conversion tables. */
cconvert->rgb_y_tab = rgb_y_tab = (INT32 *)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
(TABLE_SIZE * SIZEOF(INT32)));
for (i = 0; i <= MAXJSAMPLE; i++) {
rgb_y_tab[i+R_Y_OFF] = FIX(0.299) * i;
rgb_y_tab[i+G_Y_OFF] = FIX(0.587) * i;
rgb_y_tab[i+B_Y_OFF] = FIX(0.114) * i + ONE_HALF;
}
}
/*
* Convert RGB to grayscale.
*/
METHODDEF(void)
rgb_gray_convert (j_decompress_ptr cinfo,
JSAMPIMAGE input_buf, JDIMENSION input_row,
JSAMPARRAY output_buf, int num_rows)
{
my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
register INT32 * ctab = cconvert->rgb_y_tab;
register int r, g, b;
register JSAMPROW outptr;
register JSAMPROW inptr0, inptr1, inptr2;
register JDIMENSION col;
JDIMENSION num_cols = cinfo->output_width;
while (--num_rows >= 0) {
inptr0 = input_buf[0][input_row];
inptr1 = input_buf[1][input_row];
inptr2 = input_buf[2][input_row];
input_row++;
outptr = *output_buf++;
for (col = 0; col < num_cols; col++) {
r = GETJSAMPLE(inptr0[col]);
g = GETJSAMPLE(inptr1[col]);
b = GETJSAMPLE(inptr2[col]);
/* Y */
outptr[col] = (JSAMPLE)
((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])
>> SCALEBITS);
}
}
}
/*
* [R-G,G,B-G] to [R,G,B] conversion with modulo calculation
* (inverse color transform).
* This can be seen as an adaption of the general YCbCr->RGB
* conversion equation with Kr = Kb = 0, while replacing the
* normalization by modulo calculation.
*/
METHODDEF(void)
rgb1_rgb_convert (j_decompress_ptr cinfo,
JSAMPIMAGE input_buf, JDIMENSION input_row,
JSAMPARRAY output_buf, int num_rows)
{
register int r, g, b;
register JSAMPROW outptr;
register JSAMPROW inptr0, inptr1, inptr2;
register JDIMENSION col;
JDIMENSION num_cols = cinfo->output_width;
while (--num_rows >= 0) {
inptr0 = input_buf[0][input_row];
inptr1 = input_buf[1][input_row];
inptr2 = input_buf[2][input_row];
input_row++;
outptr = *output_buf++;
for (col = 0; col < num_cols; col++) {
r = GETJSAMPLE(inptr0[col]);
g = GETJSAMPLE(inptr1[col]);
b = GETJSAMPLE(inptr2[col]);
/* Assume that MAXJSAMPLE+1 is a power of 2, so that the MOD
* (modulo) operator is equivalent to the bitmask operator AND.
*/
outptr[RGB_RED] = (JSAMPLE) ((r + g - CENTERJSAMPLE) & MAXJSAMPLE);
outptr[RGB_GREEN] = (JSAMPLE) g;
outptr[RGB_BLUE] = (JSAMPLE) ((b + g - CENTERJSAMPLE) & MAXJSAMPLE);
outptr += RGB_PIXELSIZE;
}
}
}
/*
* [R-G,G,B-G] to grayscale conversion with modulo calculation
* (inverse color transform).
*/
METHODDEF(void)
rgb1_gray_convert (j_decompress_ptr cinfo,
JSAMPIMAGE input_buf, JDIMENSION input_row,
JSAMPARRAY output_buf, int num_rows)
{
my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
register INT32 * ctab = cconvert->rgb_y_tab;
register int r, g, b;
register JSAMPROW outptr;
register JSAMPROW inptr0, inptr1, inptr2;
register JDIMENSION col;
JDIMENSION num_cols = cinfo->output_width;
while (--num_rows >= 0) {
inptr0 = input_buf[0][input_row];
inptr1 = input_buf[1][input_row];
inptr2 = input_buf[2][input_row];
input_row++;
outptr = *output_buf++;
for (col = 0; col < num_cols; col++) {
r = GETJSAMPLE(inptr0[col]);
g = GETJSAMPLE(inptr1[col]);
b = GETJSAMPLE(inptr2[col]);
/* Assume that MAXJSAMPLE+1 is a power of 2, so that the MOD
* (modulo) operator is equivalent to the bitmask operator AND.
*/
r = (r + g - CENTERJSAMPLE) & MAXJSAMPLE;
b = (b + g - CENTERJSAMPLE) & MAXJSAMPLE;
/* Y */
outptr[col] = (JSAMPLE)
((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])
>> SCALEBITS);
}
}
}
/*
* No colorspace change, but conversion from separate-planes
* to interleaved representation.
*/
METHODDEF(void)
rgb_convert (j_decompress_ptr cinfo,
JSAMPIMAGE input_buf, JDIMENSION input_row,
JSAMPARRAY output_buf, int num_rows)
{
register JSAMPROW outptr;
register JSAMPROW inptr0, inptr1, inptr2;
register JDIMENSION col;
JDIMENSION num_cols = cinfo->output_width;
while (--num_rows >= 0) {
inptr0 = input_buf[0][input_row];
inptr1 = input_buf[1][input_row];
inptr2 = input_buf[2][input_row];
input_row++;
outptr = *output_buf++;
for (col = 0; col < num_cols; col++) {
/* We can dispense with GETJSAMPLE() here */
outptr[RGB_RED] = inptr0[col];
outptr[RGB_GREEN] = inptr1[col];
outptr[RGB_BLUE] = inptr2[col];
outptr += RGB_PIXELSIZE;
}
}
}
/* /*
@ -170,19 +454,20 @@ null_convert (j_decompress_ptr cinfo,
JSAMPIMAGE input_buf, JDIMENSION input_row, JSAMPIMAGE input_buf, JDIMENSION input_row,
JSAMPARRAY output_buf, int num_rows) JSAMPARRAY output_buf, int num_rows)
{ {
register JSAMPROW inptr, outptr;
register JDIMENSION count;
register int num_components = cinfo->num_components;
JDIMENSION num_cols = cinfo->output_width;
int ci; int ci;
register int nc = cinfo->num_components;
register JSAMPROW outptr;
register JSAMPROW inptr;
register JDIMENSION col;
JDIMENSION num_cols = cinfo->output_width;
while (--num_rows >= 0) { while (--num_rows >= 0) {
for (ci = 0; ci < num_components; ci++) { for (ci = 0; ci < nc; ci++) {
inptr = input_buf[ci][input_row]; inptr = input_buf[ci][input_row];
outptr = output_buf[0] + ci; outptr = output_buf[0] + ci;
for (count = num_cols; count > 0; count--) { for (col = 0; col < num_cols; col++) {
*outptr = *inptr++; /* needn't bother with GETJSAMPLE() here */ *outptr = *inptr++; /* needn't bother with GETJSAMPLE() here */
outptr += num_components; outptr += nc;
} }
} }
input_row++; input_row++;
@ -193,7 +478,7 @@ null_convert (j_decompress_ptr cinfo,
/* /*
* Color conversion for grayscale: just copy the data. * Color conversion for grayscale: just copy the data.
* This also works for YCbCr -> grayscale conversion, in which * This also works for YCC -> grayscale conversion, in which
* we just copy the Y (luminance) component and ignore chrominance. * we just copy the Y (luminance) component and ignore chrominance.
*/ */
@ -218,7 +503,8 @@ gray_rgb_convert (j_decompress_ptr cinfo,
JSAMPIMAGE input_buf, JDIMENSION input_row, JSAMPIMAGE input_buf, JDIMENSION input_row,
JSAMPARRAY output_buf, int num_rows) JSAMPARRAY output_buf, int num_rows)
{ {
register JSAMPROW inptr, outptr; register JSAMPROW outptr;
register JSAMPROW inptr;
register JDIMENSION col; register JDIMENSION col;
JDIMENSION num_cols = cinfo->output_width; JDIMENSION num_cols = cinfo->output_width;
@ -271,7 +557,9 @@ ycck_cmyk_convert (j_decompress_ptr cinfo,
y = GETJSAMPLE(inptr0[col]); y = GETJSAMPLE(inptr0[col]);
cb = GETJSAMPLE(inptr1[col]); cb = GETJSAMPLE(inptr1[col]);
cr = GETJSAMPLE(inptr2[col]); cr = GETJSAMPLE(inptr2[col]);
/* Range-limiting is essential due to noise introduced by DCT losses. */ /* Range-limiting is essential due to noise introduced by DCT losses,
* and for extended gamut encodings (sYCC).
*/
outptr[0] = range_limit[MAXJSAMPLE - (y + Crrtab[cr])]; /* red */ outptr[0] = range_limit[MAXJSAMPLE - (y + Crrtab[cr])]; /* red */
outptr[1] = range_limit[MAXJSAMPLE - (y + /* green */ outptr[1] = range_limit[MAXJSAMPLE - (y + /* green */
((int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], ((int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
@ -309,7 +597,7 @@ jinit_color_deconverter (j_decompress_ptr cinfo)
cconvert = (my_cconvert_ptr) cconvert = (my_cconvert_ptr)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
SIZEOF(my_color_deconverter)); SIZEOF(my_color_deconverter));
cinfo->cconvert = (struct jpeg_color_deconverter *) cconvert; cinfo->cconvert = &cconvert->pub;
cconvert->pub.start_pass = start_pass_dcolor; cconvert->pub.start_pass = start_pass_dcolor;
/* Make sure num_components agrees with jpeg_color_space */ /* Make sure num_components agrees with jpeg_color_space */
@ -321,6 +609,8 @@ jinit_color_deconverter (j_decompress_ptr cinfo)
case JCS_RGB: case JCS_RGB:
case JCS_YCbCr: case JCS_YCbCr:
case JCS_BG_RGB:
case JCS_BG_YCC:
if (cinfo->num_components != 3) if (cinfo->num_components != 3)
ERREXIT(cinfo, JERR_BAD_J_COLORSPACE); ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
break; break;
@ -337,6 +627,12 @@ jinit_color_deconverter (j_decompress_ptr cinfo)
break; break;
} }
/* Support color transform only for RGB colorspaces */
if (cinfo->color_transform &&
cinfo->jpeg_color_space != JCS_RGB &&
cinfo->jpeg_color_space != JCS_BG_RGB)
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
/* Set out_color_components and conversion method based on requested space. /* Set out_color_components and conversion method based on requested space.
* Also clear the component_needed flags for any unused components, * Also clear the component_needed flags for any unused components,
* so that earlier pipeline stages can avoid useless computation. * so that earlier pipeline stages can avoid useless computation.
@ -345,38 +641,94 @@ jinit_color_deconverter (j_decompress_ptr cinfo)
switch (cinfo->out_color_space) { switch (cinfo->out_color_space) {
case JCS_GRAYSCALE: case JCS_GRAYSCALE:
cinfo->out_color_components = 1; cinfo->out_color_components = 1;
if (cinfo->jpeg_color_space == JCS_GRAYSCALE || switch (cinfo->jpeg_color_space) {
cinfo->jpeg_color_space == JCS_YCbCr) { case JCS_GRAYSCALE:
case JCS_YCbCr:
case JCS_BG_YCC:
cconvert->pub.color_convert = grayscale_convert; cconvert->pub.color_convert = grayscale_convert;
/* For color->grayscale conversion, only the Y (0) component is needed */ /* For color->grayscale conversion, only the Y (0) component is needed */
for (ci = 1; ci < cinfo->num_components; ci++) for (ci = 1; ci < cinfo->num_components; ci++)
cinfo->comp_info[ci].component_needed = FALSE; cinfo->comp_info[ci].component_needed = FALSE;
} else break;
case JCS_RGB:
switch (cinfo->color_transform) {
case JCT_NONE:
cconvert->pub.color_convert = rgb_gray_convert;
break;
case JCT_SUBTRACT_GREEN:
cconvert->pub.color_convert = rgb1_gray_convert;
break;
default:
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
}
build_rgb_y_table(cinfo);
break;
default:
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL); ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
}
break; break;
case JCS_RGB: case JCS_RGB:
cinfo->out_color_components = RGB_PIXELSIZE; cinfo->out_color_components = RGB_PIXELSIZE;
if (cinfo->jpeg_color_space == JCS_YCbCr) { switch (cinfo->jpeg_color_space) {
case JCS_GRAYSCALE:
cconvert->pub.color_convert = gray_rgb_convert;
break;
case JCS_YCbCr:
cconvert->pub.color_convert = ycc_rgb_convert; cconvert->pub.color_convert = ycc_rgb_convert;
build_ycc_rgb_table(cinfo); build_ycc_rgb_table(cinfo);
} else if (cinfo->jpeg_color_space == JCS_GRAYSCALE) { break;
cconvert->pub.color_convert = gray_rgb_convert; case JCS_BG_YCC:
} else if (cinfo->jpeg_color_space == JCS_RGB && RGB_PIXELSIZE == 3) { cconvert->pub.color_convert = ycc_rgb_convert;
cconvert->pub.color_convert = null_convert; build_bg_ycc_rgb_table(cinfo);
break;
case JCS_RGB:
switch (cinfo->color_transform) {
case JCT_NONE:
cconvert->pub.color_convert = rgb_convert;
break;
case JCT_SUBTRACT_GREEN:
cconvert->pub.color_convert = rgb1_rgb_convert;
break;
default:
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
}
break;
default:
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
}
break;
case JCS_BG_RGB:
cinfo->out_color_components = RGB_PIXELSIZE;
if (cinfo->jpeg_color_space == JCS_BG_RGB) {
switch (cinfo->color_transform) {
case JCT_NONE:
cconvert->pub.color_convert = rgb_convert;
break;
case JCT_SUBTRACT_GREEN:
cconvert->pub.color_convert = rgb1_rgb_convert;
break;
default:
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
}
} else } else
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL); ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
break; break;
case JCS_CMYK: case JCS_CMYK:
cinfo->out_color_components = 4; cinfo->out_color_components = 4;
if (cinfo->jpeg_color_space == JCS_YCCK) { switch (cinfo->jpeg_color_space) {
case JCS_YCCK:
cconvert->pub.color_convert = ycck_cmyk_convert; cconvert->pub.color_convert = ycck_cmyk_convert;
build_ycc_rgb_table(cinfo); build_ycc_rgb_table(cinfo);
} else if (cinfo->jpeg_color_space == JCS_CMYK) { break;
case JCS_CMYK:
cconvert->pub.color_convert = null_convert; cconvert->pub.color_convert = null_convert;
} else break;
default:
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL); ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
}
break; break;
default: default:

View File

@ -2,7 +2,7 @@
* jddctmgr.c * jddctmgr.c
* *
* Copyright (C) 1994-1996, Thomas G. Lane. * Copyright (C) 1994-1996, Thomas G. Lane.
* Modified 2002-2010 by Guido Vollbeding. * Modified 2002-2013 by Guido Vollbeding.
* This file is part of the Independent JPEG Group's software. * This file is part of the Independent JPEG Group's software.
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
@ -368,7 +368,7 @@ jinit_inverse_dct (j_decompress_ptr cinfo)
idct = (my_idct_ptr) idct = (my_idct_ptr)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
SIZEOF(my_idct_controller)); SIZEOF(my_idct_controller));
cinfo->idct = (struct jpeg_inverse_dct *) idct; cinfo->idct = &idct->pub;
idct->pub.start_pass = start_pass; idct->pub.start_pass = start_pass;
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;

View File

@ -2,7 +2,7 @@
* jdhuff.c * jdhuff.c
* *
* Copyright (C) 1991-1997, Thomas G. Lane. * Copyright (C) 1991-1997, Thomas G. Lane.
* Modified 2006-2009 by Guido Vollbeding. * Modified 2006-2013 by Guido Vollbeding.
* This file is part of the Independent JPEG Group's software. * This file is part of the Independent JPEG Group's software.
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
@ -627,6 +627,22 @@ jpeg_huff_decode (bitread_working_state * state,
} }
/*
* Finish up at the end of a Huffman-compressed scan.
*/
METHODDEF(void)
finish_pass_huff (j_decompress_ptr cinfo)
{
huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
/* Throw away any unused bits remaining in bit buffer; */
/* include any full bytes in next_marker's count of discarded bytes */
cinfo->marker->discarded_bytes += entropy->bitstate.bits_left / 8;
entropy->bitstate.bits_left = 0;
}
/* /*
* Check for a restart marker & resynchronize decoder. * Check for a restart marker & resynchronize decoder.
* Returns FALSE if must suspend. * Returns FALSE if must suspend.
@ -638,10 +654,7 @@ process_restart (j_decompress_ptr cinfo)
huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy; huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
int ci; int ci;
/* Throw away any unused bits remaining in bit buffer; */ finish_pass_huff(cinfo);
/* include any full bytes in next_marker's count of discarded bytes */
cinfo->marker->discarded_bytes += entropy->bitstate.bits_left / 8;
entropy->bitstate.bits_left = 0;
/* Advance past the RSTn marker */ /* Advance past the RSTn marker */
if (! (*cinfo->marker->read_restart_marker) (cinfo)) if (! (*cinfo->marker->read_restart_marker) (cinfo))
@ -797,7 +810,7 @@ decode_mcu_AC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
/* There is always only one block per MCU */ /* There is always only one block per MCU */
if (EOBRUN > 0) /* if it's a band of zeroes... */ if (EOBRUN) /* if it's a band of zeroes... */
EOBRUN--; /* ...process it now (we do nothing) */ EOBRUN--; /* ...process it now (we do nothing) */
else { else {
BITREAD_LOAD_STATE(cinfo,entropy->bitstate); BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
@ -816,18 +829,17 @@ decode_mcu_AC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
/* Scale and output coefficient in natural (dezigzagged) order */ /* Scale and output coefficient in natural (dezigzagged) order */
(*block)[natural_order[k]] = (JCOEF) (s << Al); (*block)[natural_order[k]] = (JCOEF) (s << Al);
} else { } else {
if (r == 15) { /* ZRL */ if (r != 15) { /* EOBr, run length is 2^r + appended bits */
k += 15; /* skip 15 zeroes in band */
} else { /* EOBr, run length is 2^r + appended bits */
EOBRUN = 1 << r;
if (r) { /* EOBr, r > 0 */ if (r) { /* EOBr, r > 0 */
EOBRUN = 1 << r;
CHECK_BIT_BUFFER(br_state, r, return FALSE); CHECK_BIT_BUFFER(br_state, r, return FALSE);
r = GET_BITS(r); r = GET_BITS(r);
EOBRUN += r; EOBRUN += r;
EOBRUN--; /* this band is processed at this moment */
} }
EOBRUN--; /* this band is processed at this moment */
break; /* force end-of-band */ break; /* force end-of-band */
} }
k += 15; /* ZRL: skip 15 zeroes in band */
} }
} }
@ -847,17 +859,15 @@ decode_mcu_AC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
/* /*
* MCU decoding for DC successive approximation refinement scan. * MCU decoding for DC successive approximation refinement scan.
* Note: we assume such scans can be multi-component, although the spec * Note: we assume such scans can be multi-component,
* is not very clear on the point. * although the spec is not very clear on the point.
*/ */
METHODDEF(boolean) METHODDEF(boolean)
decode_mcu_DC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data) decode_mcu_DC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
{ {
huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy; huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
int p1 = 1 << cinfo->Al; /* 1 in the bit position being coded */ int p1, blkn;
int blkn;
JBLOCKROW block;
BITREAD_STATE_VARS; BITREAD_STATE_VARS;
/* Process restart marker if needed; may have to suspend */ /* Process restart marker if needed; may have to suspend */
@ -874,15 +884,15 @@ decode_mcu_DC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
/* Load up working state */ /* Load up working state */
BITREAD_LOAD_STATE(cinfo,entropy->bitstate); BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
p1 = 1 << cinfo->Al; /* 1 in the bit position being coded */
/* Outer loop handles each block in the MCU */ /* Outer loop handles each block in the MCU */
for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) { for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
block = MCU_data[blkn];
/* Encoded data is simply the next bit of the two's-complement DC value */ /* Encoded data is simply the next bit of the two's-complement DC value */
CHECK_BIT_BUFFER(br_state, 1, return FALSE); CHECK_BIT_BUFFER(br_state, 1, return FALSE);
if (GET_BITS(1)) if (GET_BITS(1))
(*block)[0] |= p1; MCU_data[blkn][0][0] |= p1;
/* Note: since we use |=, repeating the assignment later is safe */ /* Note: since we use |=, repeating the assignment later is safe */
} }
@ -951,7 +961,7 @@ decode_mcu_AC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
k = cinfo->Ss; k = cinfo->Ss;
if (EOBRUN == 0) { if (EOBRUN == 0) {
for (; k <= Se; k++) { do {
HUFF_DECODE(s, br_state, tbl, goto undoit, label3); HUFF_DECODE(s, br_state, tbl, goto undoit, label3);
r = s >> 4; r = s >> 4;
s &= 15; s &= 15;
@ -981,7 +991,7 @@ decode_mcu_AC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
*/ */
do { do {
thiscoef = *block + natural_order[k]; thiscoef = *block + natural_order[k];
if (*thiscoef != 0) { if (*thiscoef) {
CHECK_BIT_BUFFER(br_state, 1, goto undoit); CHECK_BIT_BUFFER(br_state, 1, goto undoit);
if (GET_BITS(1)) { if (GET_BITS(1)) {
if ((*thiscoef & p1) == 0) { /* do nothing if already set it */ if ((*thiscoef & p1) == 0) { /* do nothing if already set it */
@ -1004,18 +1014,19 @@ decode_mcu_AC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
/* Remember its position in case we have to suspend */ /* Remember its position in case we have to suspend */
newnz_pos[num_newnz++] = pos; newnz_pos[num_newnz++] = pos;
} }
} k++;
} while (k <= Se);
} }
if (EOBRUN > 0) { if (EOBRUN) {
/* Scan any remaining coefficient positions after the end-of-band /* Scan any remaining coefficient positions after the end-of-band
* (the last newly nonzero coefficient, if any). Append a correction * (the last newly nonzero coefficient, if any). Append a correction
* bit to each already-nonzero coefficient. A correction bit is 1 * bit to each already-nonzero coefficient. A correction bit is 1
* if the absolute value of the coefficient must be increased. * if the absolute value of the coefficient must be increased.
*/ */
for (; k <= Se; k++) { do {
thiscoef = *block + natural_order[k]; thiscoef = *block + natural_order[k];
if (*thiscoef != 0) { if (*thiscoef) {
CHECK_BIT_BUFFER(br_state, 1, goto undoit); CHECK_BIT_BUFFER(br_state, 1, goto undoit);
if (GET_BITS(1)) { if (GET_BITS(1)) {
if ((*thiscoef & p1) == 0) { /* do nothing if already changed it */ if ((*thiscoef & p1) == 0) { /* do nothing if already changed it */
@ -1026,7 +1037,8 @@ decode_mcu_AC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
} }
} }
} }
} k++;
} while (k <= Se);
/* Count one block completed in EOB run */ /* Count one block completed in EOB run */
EOBRUN--; EOBRUN--;
} }
@ -1043,7 +1055,7 @@ decode_mcu_AC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
undoit: undoit:
/* Re-zero any output coefficients that we made newly nonzero */ /* Re-zero any output coefficients that we made newly nonzero */
while (num_newnz > 0) while (num_newnz)
(*block)[newnz_pos[--num_newnz]] = 0; (*block)[newnz_pos[--num_newnz]] = 0;
return FALSE; return FALSE;
@ -1514,8 +1526,9 @@ jinit_huff_decoder (j_decompress_ptr cinfo)
entropy = (huff_entropy_ptr) entropy = (huff_entropy_ptr)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
SIZEOF(huff_entropy_decoder)); SIZEOF(huff_entropy_decoder));
cinfo->entropy = (struct jpeg_entropy_decoder *) entropy; cinfo->entropy = &entropy->pub;
entropy->pub.start_pass = start_pass_huff_decoder; entropy->pub.start_pass = start_pass_huff_decoder;
entropy->pub.finish_pass = finish_pass_huff;
if (cinfo->progressive_mode) { if (cinfo->progressive_mode) {
/* Create progression status table */ /* Create progression status table */

View File

@ -2,7 +2,7 @@
* jdinput.c * jdinput.c
* *
* Copyright (C) 1991-1997, Thomas G. Lane. * Copyright (C) 1991-1997, Thomas G. Lane.
* Modified 2002-2009 by Guido Vollbeding. * Modified 2002-2013 by Guido Vollbeding.
* This file is part of the Independent JPEG Group's software. * This file is part of the Independent JPEG Group's software.
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
@ -196,7 +196,7 @@ jpeg_core_output_dimensions (j_decompress_ptr cinfo)
/* Hardwire it to "no scaling" */ /* Hardwire it to "no scaling" */
cinfo->output_width = cinfo->image_width; cinfo->output_width = cinfo->image_width;
cinfo->output_height = cinfo->image_height; cinfo->output_height = cinfo->image_height;
/* jdinput.c has already initialized DCT_scaled_size, /* initial_setup has already initialized DCT_scaled_size,
* and has computed unscaled downsampled_width and downsampled_height. * and has computed unscaled downsampled_width and downsampled_height.
*/ */
@ -216,8 +216,8 @@ initial_setup (j_decompress_ptr cinfo)
(long) cinfo->image_width > (long) JPEG_MAX_DIMENSION) (long) cinfo->image_width > (long) JPEG_MAX_DIMENSION)
ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) JPEG_MAX_DIMENSION); ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) JPEG_MAX_DIMENSION);
/* For now, precision must match compiled-in value... */ /* Only 8 to 12 bits data precision are supported for DCT based JPEG */
if (cinfo->data_precision != BITS_IN_JSAMPLE) if (cinfo->data_precision < 8 || cinfo->data_precision > 12)
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
/* Check that number of components won't exceed internal array sizes */ /* Check that number of components won't exceed internal array sizes */
@ -537,6 +537,7 @@ start_input_pass (j_decompress_ptr cinfo)
METHODDEF(void) METHODDEF(void)
finish_input_pass (j_decompress_ptr cinfo) finish_input_pass (j_decompress_ptr cinfo)
{ {
(*cinfo->entropy->finish_pass) (cinfo);
cinfo->inputctl->consume_input = consume_markers; cinfo->inputctl->consume_input = consume_markers;
} }
@ -646,7 +647,7 @@ jinit_input_controller (j_decompress_ptr cinfo)
inputctl = (my_inputctl_ptr) inputctl = (my_inputctl_ptr)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT, (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
SIZEOF(my_input_controller)); SIZEOF(my_input_controller));
cinfo->inputctl = (struct jpeg_input_controller *) inputctl; cinfo->inputctl = &inputctl->pub;
/* Initialize method pointers */ /* Initialize method pointers */
inputctl->pub.consume_input = consume_markers; inputctl->pub.consume_input = consume_markers;
inputctl->pub.reset_input_controller = reset_input_controller; inputctl->pub.reset_input_controller = reset_input_controller;

View File

@ -2,6 +2,7 @@
* jdmainct.c * jdmainct.c
* *
* Copyright (C) 1994-1996, Thomas G. Lane. * Copyright (C) 1994-1996, Thomas G. Lane.
* Modified 2002-2012 by Guido Vollbeding.
* This file is part of the Independent JPEG Group's software. * This file is part of the Independent JPEG Group's software.
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
@ -194,7 +195,7 @@ alloc_funny_pointers (j_decompress_ptr cinfo)
LOCAL(void) LOCAL(void)
make_funny_pointers (j_decompress_ptr cinfo) make_funny_pointers (j_decompress_ptr cinfo)
/* Create the funny pointer lists discussed in the comments above. /* Create the funny pointer lists discussed in the comments above.
* The actual workspace is already allocated (in mainp->buffer), * The actual workspace is already allocated (in main->buffer),
* and the space for the pointer lists is allocated too. * and the space for the pointer lists is allocated too.
* This routine just fills in the curiously ordered lists. * This routine just fills in the curiously ordered lists.
* This will be repeated at the beginning of each pass. * This will be repeated at the beginning of each pass.
@ -482,7 +483,7 @@ jinit_d_main_controller (j_decompress_ptr cinfo, boolean need_full_buffer)
mainp = (my_main_ptr) mainp = (my_main_ptr)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
SIZEOF(my_main_controller)); SIZEOF(my_main_controller));
cinfo->main = (struct jpeg_d_main_controller *) mainp; cinfo->main = &mainp->pub;
mainp->pub.start_pass = start_pass_main; mainp->pub.start_pass = start_pass_main;
if (need_full_buffer) /* shouldn't happen */ if (need_full_buffer) /* shouldn't happen */
@ -505,8 +506,8 @@ jinit_d_main_controller (j_decompress_ptr cinfo, boolean need_full_buffer)
rgroup = (compptr->v_samp_factor * compptr->DCT_v_scaled_size) / rgroup = (compptr->v_samp_factor * compptr->DCT_v_scaled_size) /
cinfo->min_DCT_v_scaled_size; /* height of a row group of component */ cinfo->min_DCT_v_scaled_size; /* height of a row group of component */
mainp->buffer[ci] = (*cinfo->mem->alloc_sarray) mainp->buffer[ci] = (*cinfo->mem->alloc_sarray)
((j_common_ptr) cinfo, JPOOL_IMAGE, ((j_common_ptr) cinfo, JPOOL_IMAGE,
compptr->width_in_blocks * compptr->DCT_h_scaled_size, compptr->width_in_blocks * ((JDIMENSION) compptr->DCT_h_scaled_size),
(JDIMENSION) (rgroup * ngroups)); (JDIMENSION) (rgroup * ngroups));
} }
} }

View File

@ -2,7 +2,7 @@
* jdmarker.c * jdmarker.c
* *
* Copyright (C) 1991-1998, Thomas G. Lane. * Copyright (C) 1991-1998, Thomas G. Lane.
* Modified 2009 by Guido Vollbeding. * Modified 2009-2013 by Guido Vollbeding.
* This file is part of the Independent JPEG Group's software. * This file is part of the Independent JPEG Group's software.
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
@ -23,24 +23,24 @@ typedef enum { /* JPEG marker codes */
M_SOF1 = 0xc1, M_SOF1 = 0xc1,
M_SOF2 = 0xc2, M_SOF2 = 0xc2,
M_SOF3 = 0xc3, M_SOF3 = 0xc3,
M_SOF5 = 0xc5, M_SOF5 = 0xc5,
M_SOF6 = 0xc6, M_SOF6 = 0xc6,
M_SOF7 = 0xc7, M_SOF7 = 0xc7,
M_JPG = 0xc8, M_JPG = 0xc8,
M_SOF9 = 0xc9, M_SOF9 = 0xc9,
M_SOF10 = 0xca, M_SOF10 = 0xca,
M_SOF11 = 0xcb, M_SOF11 = 0xcb,
M_SOF13 = 0xcd, M_SOF13 = 0xcd,
M_SOF14 = 0xce, M_SOF14 = 0xce,
M_SOF15 = 0xcf, M_SOF15 = 0xcf,
M_DHT = 0xc4, M_DHT = 0xc4,
M_DAC = 0xcc, M_DAC = 0xcc,
M_RST0 = 0xd0, M_RST0 = 0xd0,
M_RST1 = 0xd1, M_RST1 = 0xd1,
M_RST2 = 0xd2, M_RST2 = 0xd2,
@ -49,7 +49,7 @@ typedef enum { /* JPEG marker codes */
M_RST5 = 0xd5, M_RST5 = 0xd5,
M_RST6 = 0xd6, M_RST6 = 0xd6,
M_RST7 = 0xd7, M_RST7 = 0xd7,
M_SOI = 0xd8, M_SOI = 0xd8,
M_EOI = 0xd9, M_EOI = 0xd9,
M_SOS = 0xda, M_SOS = 0xda,
@ -58,7 +58,7 @@ typedef enum { /* JPEG marker codes */
M_DRI = 0xdd, M_DRI = 0xdd,
M_DHP = 0xde, M_DHP = 0xde,
M_EXP = 0xdf, M_EXP = 0xdf,
M_APP0 = 0xe0, M_APP0 = 0xe0,
M_APP1 = 0xe1, M_APP1 = 0xe1,
M_APP2 = 0xe2, M_APP2 = 0xe2,
@ -75,13 +75,14 @@ typedef enum { /* JPEG marker codes */
M_APP13 = 0xed, M_APP13 = 0xed,
M_APP14 = 0xee, M_APP14 = 0xee,
M_APP15 = 0xef, M_APP15 = 0xef,
M_JPG0 = 0xf0, M_JPG0 = 0xf0,
M_JPG8 = 0xf8,
M_JPG13 = 0xfd, M_JPG13 = 0xfd,
M_COM = 0xfe, M_COM = 0xfe,
M_TEM = 0x01, M_TEM = 0x01,
M_ERROR = 0x100 M_ERROR = 0x100
} JPEG_MARKER; } JPEG_MARKER;
@ -217,6 +218,7 @@ get_soi (j_decompress_ptr cinfo)
/* Set initial assumptions for colorspace etc */ /* Set initial assumptions for colorspace etc */
cinfo->jpeg_color_space = JCS_UNKNOWN; cinfo->jpeg_color_space = JCS_UNKNOWN;
cinfo->color_transform = JCT_NONE;
cinfo->CCIR601_sampling = FALSE; /* Assume non-CCIR sampling??? */ cinfo->CCIR601_sampling = FALSE; /* Assume non-CCIR sampling??? */
cinfo->saw_JFIF_marker = FALSE; cinfo->saw_JFIF_marker = FALSE;
@ -240,7 +242,7 @@ get_sof (j_decompress_ptr cinfo, boolean is_baseline, boolean is_prog,
/* Process a SOFn marker */ /* Process a SOFn marker */
{ {
INT32 length; INT32 length;
int c, ci; int c, ci, i;
jpeg_component_info * compptr; jpeg_component_info * compptr;
INPUT_VARS(cinfo); INPUT_VARS(cinfo);
@ -267,8 +269,8 @@ get_sof (j_decompress_ptr cinfo, boolean is_baseline, boolean is_prog,
/* We don't support files in which the image height is initially specified */ /* We don't support files in which the image height is initially specified */
/* as 0 and is later redefined by DNL. As long as we have to check that, */ /* as 0 and is later redefined by DNL. As long as we have to check that, */
/* might as well have a general sanity check. */ /* might as well have a general sanity check. */
if (cinfo->image_height <= 0 || cinfo->image_width <= 0 if (cinfo->image_height <= 0 || cinfo->image_width <= 0 ||
|| cinfo->num_components <= 0) cinfo->num_components <= 0)
ERREXIT(cinfo, JERR_EMPTY_IMAGE); ERREXIT(cinfo, JERR_EMPTY_IMAGE);
if (length != (cinfo->num_components * 3)) if (length != (cinfo->num_components * 3))
@ -278,11 +280,27 @@ get_sof (j_decompress_ptr cinfo, boolean is_baseline, boolean is_prog,
cinfo->comp_info = (jpeg_component_info *) (*cinfo->mem->alloc_small) cinfo->comp_info = (jpeg_component_info *) (*cinfo->mem->alloc_small)
((j_common_ptr) cinfo, JPOOL_IMAGE, ((j_common_ptr) cinfo, JPOOL_IMAGE,
cinfo->num_components * SIZEOF(jpeg_component_info)); cinfo->num_components * SIZEOF(jpeg_component_info));
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; for (ci = 0; ci < cinfo->num_components; ci++) {
ci++, compptr++) { INPUT_BYTE(cinfo, c, return FALSE);
/* Check to see whether component id has already been seen */
/* (in violation of the spec, but unfortunately seen in some */
/* files). If so, create "fake" component id equal to the */
/* max id seen so far + 1. */
for (i = 0, compptr = cinfo->comp_info; i < ci; i++, compptr++) {
if (c == compptr->component_id) {
compptr = cinfo->comp_info;
c = compptr->component_id;
compptr++;
for (i = 1; i < ci; i++, compptr++) {
if (compptr->component_id > c) c = compptr->component_id;
}
c++;
break;
}
}
compptr->component_id = c;
compptr->component_index = ci; compptr->component_index = ci;
INPUT_BYTE(cinfo, compptr->component_id, return FALSE);
INPUT_BYTE(cinfo, c, return FALSE); INPUT_BYTE(cinfo, c, return FALSE);
compptr->h_samp_factor = (c >> 4) & 15; compptr->h_samp_factor = (c >> 4) & 15;
compptr->v_samp_factor = (c ) & 15; compptr->v_samp_factor = (c ) & 15;
@ -305,12 +323,12 @@ get_sos (j_decompress_ptr cinfo)
/* Process a SOS marker */ /* Process a SOS marker */
{ {
INT32 length; INT32 length;
int i, ci, n, c, cc; int c, ci, i, n;
jpeg_component_info * compptr; jpeg_component_info * compptr;
INPUT_VARS(cinfo); INPUT_VARS(cinfo);
if (! cinfo->marker->saw_SOF) if (! cinfo->marker->saw_SOF)
ERREXIT(cinfo, JERR_SOS_NO_SOF); ERREXITS(cinfo, JERR_SOF_BEFORE, "SOS");
INPUT_2BYTES(cinfo, length, return FALSE); INPUT_2BYTES(cinfo, length, return FALSE);
@ -328,24 +346,41 @@ get_sos (j_decompress_ptr cinfo)
/* Collect the component-spec parameters */ /* Collect the component-spec parameters */
for (i = 0; i < n; i++) { for (i = 0; i < n; i++) {
INPUT_BYTE(cinfo, cc, return FALSE);
INPUT_BYTE(cinfo, c, return FALSE); INPUT_BYTE(cinfo, c, return FALSE);
/* Detect the case where component id's are not unique, and, if so, */
/* create a fake component id using the same logic as in get_sof. */
/* Note: This also ensures that all of the SOF components are */
/* referenced in the single scan case, which prevents access to */
/* uninitialized memory in later decoding stages. */
for (ci = 0; ci < i; ci++) {
if (c == cinfo->cur_comp_info[ci]->component_id) {
c = cinfo->cur_comp_info[0]->component_id;
for (ci = 1; ci < i; ci++) {
compptr = cinfo->cur_comp_info[ci];
if (compptr->component_id > c) c = compptr->component_id;
}
c++;
break;
}
}
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
ci++, compptr++) { ci++, compptr++) {
if (cc == compptr->component_id) if (c == compptr->component_id)
goto id_found; goto id_found;
} }
ERREXIT1(cinfo, JERR_BAD_COMPONENT_ID, cc); ERREXIT1(cinfo, JERR_BAD_COMPONENT_ID, c);
id_found: id_found:
cinfo->cur_comp_info[i] = compptr; cinfo->cur_comp_info[i] = compptr;
INPUT_BYTE(cinfo, c, return FALSE);
compptr->dc_tbl_no = (c >> 4) & 15; compptr->dc_tbl_no = (c >> 4) & 15;
compptr->ac_tbl_no = (c ) & 15; compptr->ac_tbl_no = (c ) & 15;
TRACEMS3(cinfo, 1, JTRC_SOS_COMPONENT, cc, TRACEMS3(cinfo, 1, JTRC_SOS_COMPONENT, compptr->component_id,
compptr->dc_tbl_no, compptr->ac_tbl_no); compptr->dc_tbl_no, compptr->ac_tbl_no);
} }
@ -461,6 +496,8 @@ get_dht (j_decompress_ptr cinfo)
if (count > 256 || ((INT32) count) > length) if (count > 256 || ((INT32) count) > length)
ERREXIT(cinfo, JERR_BAD_HUFF_TABLE); ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
MEMZERO(huffval, SIZEOF(huffval)); /* pre-zero array for later copy */
for (i = 0; i < count; i++) for (i = 0; i < count; i++)
INPUT_BYTE(cinfo, huffval[i], return FALSE); INPUT_BYTE(cinfo, huffval[i], return FALSE);
@ -605,6 +642,68 @@ get_dri (j_decompress_ptr cinfo)
} }
LOCAL(boolean)
get_lse (j_decompress_ptr cinfo)
/* Process an LSE marker */
{
INT32 length;
unsigned int tmp;
int cid;
INPUT_VARS(cinfo);
if (! cinfo->marker->saw_SOF)
ERREXITS(cinfo, JERR_SOF_BEFORE, "LSE");
if (cinfo->num_components < 3) goto bad;
INPUT_2BYTES(cinfo, length, return FALSE);
if (length != 24)
ERREXIT(cinfo, JERR_BAD_LENGTH);
INPUT_BYTE(cinfo, tmp, return FALSE);
if (tmp != 0x0D) /* ID inverse transform specification */
ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, cinfo->unread_marker);
INPUT_2BYTES(cinfo, tmp, return FALSE);
if (tmp != MAXJSAMPLE) goto bad; /* MAXTRANS */
INPUT_BYTE(cinfo, tmp, return FALSE);
if (tmp != 3) goto bad; /* Nt=3 */
INPUT_BYTE(cinfo, cid, return FALSE);
if (cid != cinfo->comp_info[1].component_id) goto bad;
INPUT_BYTE(cinfo, cid, return FALSE);
if (cid != cinfo->comp_info[0].component_id) goto bad;
INPUT_BYTE(cinfo, cid, return FALSE);
if (cid != cinfo->comp_info[2].component_id) goto bad;
INPUT_BYTE(cinfo, tmp, return FALSE);
if (tmp != 0x80) goto bad; /* F1: CENTER1=1, NORM1=0 */
INPUT_2BYTES(cinfo, tmp, return FALSE);
if (tmp != 0) goto bad; /* A(1,1)=0 */
INPUT_2BYTES(cinfo, tmp, return FALSE);
if (tmp != 0) goto bad; /* A(1,2)=0 */
INPUT_BYTE(cinfo, tmp, return FALSE);
if (tmp != 0) goto bad; /* F2: CENTER2=0, NORM2=0 */
INPUT_2BYTES(cinfo, tmp, return FALSE);
if (tmp != 1) goto bad; /* A(2,1)=1 */
INPUT_2BYTES(cinfo, tmp, return FALSE);
if (tmp != 0) goto bad; /* A(2,2)=0 */
INPUT_BYTE(cinfo, tmp, return FALSE);
if (tmp != 0) goto bad; /* F3: CENTER3=0, NORM3=0 */
INPUT_2BYTES(cinfo, tmp, return FALSE);
if (tmp != 1) goto bad; /* A(3,1)=1 */
INPUT_2BYTES(cinfo, tmp, return FALSE);
if (tmp != 0) { /* A(3,2)=0 */
bad:
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
}
/* OK, valid transform that we can handle. */
cinfo->color_transform = JCT_SUBTRACT_GREEN;
INPUT_SYNC(cinfo);
return TRUE;
}
/* /*
* Routines for processing APPn and COM markers. * Routines for processing APPn and COM markers.
* These are either saved in memory or discarded, per application request. * These are either saved in memory or discarded, per application request.
@ -641,12 +740,13 @@ examine_app0 (j_decompress_ptr cinfo, JOCTET FAR * data,
cinfo->X_density = (GETJOCTET(data[8]) << 8) + GETJOCTET(data[9]); cinfo->X_density = (GETJOCTET(data[8]) << 8) + GETJOCTET(data[9]);
cinfo->Y_density = (GETJOCTET(data[10]) << 8) + GETJOCTET(data[11]); cinfo->Y_density = (GETJOCTET(data[10]) << 8) + GETJOCTET(data[11]);
/* Check version. /* Check version.
* Major version must be 1, anything else signals an incompatible change. * Major version must be 1 or 2, anything else signals an incompatible
* change.
* (We used to treat this as an error, but now it's a nonfatal warning, * (We used to treat this as an error, but now it's a nonfatal warning,
* because some bozo at Hijaak couldn't read the spec.) * because some bozo at Hijaak couldn't read the spec.)
* Minor version should be 0..2, but process anyway if newer. * Minor version should be 0..2, but process anyway if newer.
*/ */
if (cinfo->JFIF_major_version != 1) if (cinfo->JFIF_major_version != 1 && cinfo->JFIF_major_version != 2)
WARNMS2(cinfo, JWRN_JFIF_MAJOR, WARNMS2(cinfo, JWRN_JFIF_MAJOR,
cinfo->JFIF_major_version, cinfo->JFIF_minor_version); cinfo->JFIF_major_version, cinfo->JFIF_minor_version);
/* Generate trace messages */ /* Generate trace messages */
@ -1059,32 +1159,37 @@ read_markers (j_decompress_ptr cinfo)
return JPEG_SUSPENDED; return JPEG_SUSPENDED;
cinfo->unread_marker = 0; /* processed the marker */ cinfo->unread_marker = 0; /* processed the marker */
return JPEG_REACHED_SOS; return JPEG_REACHED_SOS;
case M_EOI: case M_EOI:
TRACEMS(cinfo, 1, JTRC_EOI); TRACEMS(cinfo, 1, JTRC_EOI);
cinfo->unread_marker = 0; /* processed the marker */ cinfo->unread_marker = 0; /* processed the marker */
return JPEG_REACHED_EOI; return JPEG_REACHED_EOI;
case M_DAC: case M_DAC:
if (! get_dac(cinfo)) if (! get_dac(cinfo))
return JPEG_SUSPENDED; return JPEG_SUSPENDED;
break; break;
case M_DHT: case M_DHT:
if (! get_dht(cinfo)) if (! get_dht(cinfo))
return JPEG_SUSPENDED; return JPEG_SUSPENDED;
break; break;
case M_DQT: case M_DQT:
if (! get_dqt(cinfo)) if (! get_dqt(cinfo))
return JPEG_SUSPENDED; return JPEG_SUSPENDED;
break; break;
case M_DRI: case M_DRI:
if (! get_dri(cinfo)) if (! get_dri(cinfo))
return JPEG_SUSPENDED; return JPEG_SUSPENDED;
break; break;
case M_JPG8:
if (! get_lse(cinfo))
return JPEG_SUSPENDED;
break;
case M_APP0: case M_APP0:
case M_APP1: case M_APP1:
case M_APP2: case M_APP2:
@ -1105,7 +1210,7 @@ read_markers (j_decompress_ptr cinfo)
cinfo->unread_marker - (int) M_APP0]) (cinfo)) cinfo->unread_marker - (int) M_APP0]) (cinfo))
return JPEG_SUSPENDED; return JPEG_SUSPENDED;
break; break;
case M_COM: case M_COM:
if (! (*((my_marker_ptr) cinfo->marker)->process_COM) (cinfo)) if (! (*((my_marker_ptr) cinfo->marker)->process_COM) (cinfo))
return JPEG_SUSPENDED; return JPEG_SUSPENDED;
@ -1314,7 +1419,7 @@ jinit_marker_reader (j_decompress_ptr cinfo)
marker = (my_marker_ptr) marker = (my_marker_ptr)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT, (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
SIZEOF(my_marker_reader)); SIZEOF(my_marker_reader));
cinfo->marker = (struct jpeg_marker_reader *) marker; cinfo->marker = &marker->pub;
/* Initialize public method pointers */ /* Initialize public method pointers */
marker->pub.reset_marker_reader = reset_marker_reader; marker->pub.reset_marker_reader = reset_marker_reader;
marker->pub.read_markers = read_markers; marker->pub.read_markers = read_markers;

View File

@ -2,7 +2,7 @@
* jdmaster.c * jdmaster.c
* *
* Copyright (C) 1991-1997, Thomas G. Lane. * Copyright (C) 1991-1997, Thomas G. Lane.
* Modified 2002-2009 by Guido Vollbeding. * Modified 2002-2013 by Guido Vollbeding.
* This file is part of the Independent JPEG Group's software. * This file is part of the Independent JPEG Group's software.
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
@ -51,7 +51,8 @@ use_merged_upsample (j_decompress_ptr cinfo)
/* jdmerge.c only supports YCC=>RGB color conversion */ /* jdmerge.c only supports YCC=>RGB color conversion */
if (cinfo->jpeg_color_space != JCS_YCbCr || cinfo->num_components != 3 || if (cinfo->jpeg_color_space != JCS_YCbCr || cinfo->num_components != 3 ||
cinfo->out_color_space != JCS_RGB || cinfo->out_color_space != JCS_RGB ||
cinfo->out_color_components != RGB_PIXELSIZE) cinfo->out_color_components != RGB_PIXELSIZE ||
cinfo->color_transform)
return FALSE; return FALSE;
/* and it only handles 2h1v or 2h2v sampling ratios */ /* and it only handles 2h1v or 2h2v sampling ratios */
if (cinfo->comp_info[0].h_samp_factor != 2 || if (cinfo->comp_info[0].h_samp_factor != 2 ||
@ -158,11 +159,11 @@ jpeg_calc_output_dimensions (j_decompress_ptr cinfo)
cinfo->out_color_components = 1; cinfo->out_color_components = 1;
break; break;
case JCS_RGB: case JCS_RGB:
#if RGB_PIXELSIZE != 3 case JCS_BG_RGB:
cinfo->out_color_components = RGB_PIXELSIZE; cinfo->out_color_components = RGB_PIXELSIZE;
break; break;
#endif /* else share code with YCbCr */
case JCS_YCbCr: case JCS_YCbCr:
case JCS_BG_YCC:
cinfo->out_color_components = 3; cinfo->out_color_components = 3;
break; break;
case JCS_CMYK: case JCS_CMYK:
@ -275,10 +276,19 @@ master_selection (j_decompress_ptr cinfo)
long samplesperrow; long samplesperrow;
JDIMENSION jd_samplesperrow; JDIMENSION jd_samplesperrow;
/* For now, precision must match compiled-in value... */
if (cinfo->data_precision != BITS_IN_JSAMPLE)
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
/* Initialize dimensions and other stuff */ /* Initialize dimensions and other stuff */
jpeg_calc_output_dimensions(cinfo); jpeg_calc_output_dimensions(cinfo);
prepare_range_limit_table(cinfo); prepare_range_limit_table(cinfo);
/* Sanity check on image dimensions */
if (cinfo->output_height <= 0 || cinfo->output_width <= 0 ||
cinfo->out_color_components <= 0)
ERREXIT(cinfo, JERR_EMPTY_IMAGE);
/* Width of an output scanline must be representable as JDIMENSION. */ /* Width of an output scanline must be representable as JDIMENSION. */
samplesperrow = (long) cinfo->output_width * (long) cinfo->out_color_components; samplesperrow = (long) cinfo->output_width * (long) cinfo->out_color_components;
jd_samplesperrow = (JDIMENSION) samplesperrow; jd_samplesperrow = (JDIMENSION) samplesperrow;
@ -523,7 +533,7 @@ jinit_master_decompress (j_decompress_ptr cinfo)
master = (my_master_ptr) master = (my_master_ptr)
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
SIZEOF(my_decomp_master)); SIZEOF(my_decomp_master));
cinfo->master = (struct jpeg_decomp_master *) master; cinfo->master = &master->pub;
master->pub.prepare_for_output_pass = prepare_for_output_pass; master->pub.prepare_for_output_pass = prepare_for_output_pass;
master->pub.finish_output_pass = finish_output_pass; master->pub.finish_output_pass = finish_output_pass;

View File

@ -2,6 +2,7 @@
* jdmerge.c * jdmerge.c
* *
* Copyright (C) 1994-1996, Thomas G. Lane. * Copyright (C) 1994-1996, Thomas G. Lane.
* Modified 2013 by Guido Vollbeding.
* This file is part of the Independent JPEG Group's software. * This file is part of the Independent JPEG Group's software.
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
@ -103,17 +104,17 @@ build_ycc_rgb_table (j_decompress_ptr cinfo)
for (i = 0, x = -CENTERJSAMPLE; i <= MAXJSAMPLE; i++, x++) { for (i = 0, x = -CENTERJSAMPLE; i <= MAXJSAMPLE; i++, x++) {
/* i is the actual input pixel value, in the range 0..MAXJSAMPLE */ /* i is the actual input pixel value, in the range 0..MAXJSAMPLE */
/* The Cb or Cr value we are thinking of is x = i - CENTERJSAMPLE */ /* The Cb or Cr value we are thinking of is x = i - CENTERJSAMPLE */
/* Cr=>R value is nearest int to 1.40200 * x */ /* Cr=>R value is nearest int to 1.402 * x */
upsample->Cr_r_tab[i] = (int) upsample->Cr_r_tab[i] = (int)
RIGHT_SHIFT(FIX(1.40200) * x + ONE_HALF, SCALEBITS); RIGHT_SHIFT(FIX(1.402) * x + ONE_HALF, SCALEBITS);
/* Cb=>B value is nearest int to 1.77200 * x */ /* Cb=>B value is nearest int to 1.772 * x */
upsample->Cb_b_tab[i] = (int) upsample->Cb_b_tab[i] = (int)
RIGHT_SHIFT(FIX(1.77200) * x + ONE_HALF, SCALEBITS); RIGHT_SHIFT(FIX(1.772) * x + ONE_HALF, SCALEBITS);
/* Cr=>G value is scaled-up -0.71414 * x */ /* Cr=>G value is scaled-up -0.714136286 * x */
upsample->Cr_g_tab[i] = (- FIX(0.71414)) * x; upsample->Cr_g_tab[i] = (- FIX(0.714136286)) * x;
/* Cb=>G value is scaled-up -0.34414 * x */ /* Cb=>G value is scaled-up -0.344136286 * x */
/* We also add in ONE_HALF so that need not do it in inner loop */ /* We also add in ONE_HALF so that need not do it in inner loop */
upsample->Cb_g_tab[i] = (- FIX(0.34414)) * x + ONE_HALF; upsample->Cb_g_tab[i] = (- FIX(0.344136286)) * x + ONE_HALF;
} }
} }

View File

@ -2,6 +2,7 @@
* jerror.c * jerror.c
* *
* Copyright (C) 1991-1998, Thomas G. Lane. * Copyright (C) 1991-1998, Thomas G. Lane.
* Modified 2012 by Guido Vollbeding.
* This file is part of the Independent JPEG Group's software. * This file is part of the Independent JPEG Group's software.
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
@ -66,7 +67,7 @@ const char * const jpeg_std_message_table[] = {
* or jpeg_destroy) at some point. * or jpeg_destroy) at some point.
*/ */
METHODDEF(void) METHODDEF(noreturn_t)
error_exit (j_common_ptr cinfo) error_exit (j_common_ptr cinfo)
{ {
/* Always display the message */ /* Always display the message */

View File

@ -2,7 +2,7 @@
* jerror.h * jerror.h
* *
* Copyright (C) 1994-1997, Thomas G. Lane. * Copyright (C) 1994-1997, Thomas G. Lane.
* Modified 1997-2009 by Guido Vollbeding. * Modified 1997-2012 by Guido Vollbeding.
* This file is part of the Independent JPEG Group's software. * This file is part of the Independent JPEG Group's software.
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
@ -106,11 +106,11 @@ JMESSAGE(JERR_QUANT_COMPONENTS,
"Cannot quantize more than %d color components") "Cannot quantize more than %d color components")
JMESSAGE(JERR_QUANT_FEW_COLORS, "Cannot quantize to fewer than %d colors") JMESSAGE(JERR_QUANT_FEW_COLORS, "Cannot quantize to fewer than %d colors")
JMESSAGE(JERR_QUANT_MANY_COLORS, "Cannot quantize to more than %d colors") JMESSAGE(JERR_QUANT_MANY_COLORS, "Cannot quantize to more than %d colors")
JMESSAGE(JERR_SOF_BEFORE, "Invalid JPEG file structure: %s before SOF")
JMESSAGE(JERR_SOF_DUPLICATE, "Invalid JPEG file structure: two SOF markers") JMESSAGE(JERR_SOF_DUPLICATE, "Invalid JPEG file structure: two SOF markers")
JMESSAGE(JERR_SOF_NO_SOS, "Invalid JPEG file structure: missing SOS marker") JMESSAGE(JERR_SOF_NO_SOS, "Invalid JPEG file structure: missing SOS marker")
JMESSAGE(JERR_SOF_UNSUPPORTED, "Unsupported JPEG process: SOF type 0x%02x") JMESSAGE(JERR_SOF_UNSUPPORTED, "Unsupported JPEG process: SOF type 0x%02x")
JMESSAGE(JERR_SOI_DUPLICATE, "Invalid JPEG file structure: two SOI markers") JMESSAGE(JERR_SOI_DUPLICATE, "Invalid JPEG file structure: two SOI markers")
JMESSAGE(JERR_SOS_NO_SOF, "Invalid JPEG file structure: SOS before SOF")
JMESSAGE(JERR_TFILE_CREATE, "Failed to create temporary file %s") JMESSAGE(JERR_TFILE_CREATE, "Failed to create temporary file %s")
JMESSAGE(JERR_TFILE_READ, "Read failed on temporary file") JMESSAGE(JERR_TFILE_READ, "Read failed on temporary file")
JMESSAGE(JERR_TFILE_SEEK, "Seek failed on temporary file") JMESSAGE(JERR_TFILE_SEEK, "Seek failed on temporary file")

File diff suppressed because it is too large Load Diff

View File

@ -2,7 +2,7 @@
* jidctint.c * jidctint.c
* *
* Copyright (C) 1991-1998, Thomas G. Lane. * Copyright (C) 1991-1998, Thomas G. Lane.
* Modification developed 2002-2009 by Guido Vollbeding. * Modification developed 2002-2013 by Guido Vollbeding.
* This file is part of the Independent JPEG Group's software. * This file is part of the Independent JPEG Group's software.
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
@ -165,6 +165,8 @@
/* /*
* Perform dequantization and inverse DCT on one block of coefficients. * Perform dequantization and inverse DCT on one block of coefficients.
*
* cK represents sqrt(2) * cos(K*pi/16).
*/ */
GLOBAL(void) GLOBAL(void)
@ -184,9 +186,10 @@ jpeg_idct_islow (j_decompress_ptr cinfo, jpeg_component_info * compptr,
int workspace[DCTSIZE2]; /* buffers data between passes */ int workspace[DCTSIZE2]; /* buffers data between passes */
SHIFT_TEMPS SHIFT_TEMPS
/* Pass 1: process columns from input, store into work array. */ /* Pass 1: process columns from input, store into work array.
/* Note results are scaled up by sqrt(8) compared to a true IDCT; */ * Note results are scaled up by sqrt(8) compared to a true IDCT;
/* furthermore, we scale the results by 2**PASS1_BITS. */ * furthermore, we scale the results by 2**PASS1_BITS.
*/
inptr = coef_block; inptr = coef_block;
quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table; quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
@ -223,15 +226,16 @@ jpeg_idct_islow (j_decompress_ptr cinfo, jpeg_component_info * compptr,
continue; continue;
} }
/* Even part: reverse the even part of the forward DCT. */ /* Even part: reverse the even part of the forward DCT.
/* The rotator is sqrt(2)*c(-6). */ * The rotator is c(-6).
*/
z2 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]); z2 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
z3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]); z3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
z1 = MULTIPLY(z2 + z3, FIX_0_541196100); z1 = MULTIPLY(z2 + z3, FIX_0_541196100); /* c6 */
tmp2 = z1 + MULTIPLY(z2, FIX_0_765366865); tmp2 = z1 + MULTIPLY(z2, FIX_0_765366865); /* c2-c6 */
tmp3 = z1 - MULTIPLY(z3, FIX_1_847759065); tmp3 = z1 - MULTIPLY(z3, FIX_1_847759065); /* c2+c6 */
z2 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]); z2 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
z3 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]); z3 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);
@ -256,25 +260,25 @@ jpeg_idct_islow (j_decompress_ptr cinfo, jpeg_component_info * compptr,
tmp1 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]); tmp1 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
tmp2 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]); tmp2 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
tmp3 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]); tmp3 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
z2 = tmp0 + tmp2; z2 = tmp0 + tmp2;
z3 = tmp1 + tmp3; z3 = tmp1 + tmp3;
z1 = MULTIPLY(z2 + z3, FIX_1_175875602); /* sqrt(2) * c3 */ z1 = MULTIPLY(z2 + z3, FIX_1_175875602); /* c3 */
z2 = MULTIPLY(z2, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */ z2 = MULTIPLY(z2, - FIX_1_961570560); /* -c3-c5 */
z3 = MULTIPLY(z3, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */ z3 = MULTIPLY(z3, - FIX_0_390180644); /* -c3+c5 */
z2 += z1; z2 += z1;
z3 += z1; z3 += z1;
z1 = MULTIPLY(tmp0 + tmp3, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */ z1 = MULTIPLY(tmp0 + tmp3, - FIX_0_899976223); /* -c3+c7 */
tmp0 = MULTIPLY(tmp0, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */ tmp0 = MULTIPLY(tmp0, FIX_0_298631336); /* -c1+c3+c5-c7 */
tmp3 = MULTIPLY(tmp3, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */ tmp3 = MULTIPLY(tmp3, FIX_1_501321110); /* c1+c3-c5-c7 */
tmp0 += z1 + z2; tmp0 += z1 + z2;
tmp3 += z1 + z3; tmp3 += z1 + z3;
z1 = MULTIPLY(tmp1 + tmp2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */ z1 = MULTIPLY(tmp1 + tmp2, - FIX_2_562915447); /* -c1-c3 */
tmp1 = MULTIPLY(tmp1, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */ tmp1 = MULTIPLY(tmp1, FIX_2_053119869); /* c1+c3-c5+c7 */
tmp2 = MULTIPLY(tmp2, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */ tmp2 = MULTIPLY(tmp2, FIX_3_072711026); /* c1+c3+c5-c7 */
tmp1 += z1 + z3; tmp1 += z1 + z3;
tmp2 += z1 + z2; tmp2 += z1 + z2;
@ -288,15 +292,16 @@ jpeg_idct_islow (j_decompress_ptr cinfo, jpeg_component_info * compptr,
wsptr[DCTSIZE*5] = (int) RIGHT_SHIFT(tmp12 - tmp1, CONST_BITS-PASS1_BITS); wsptr[DCTSIZE*5] = (int) RIGHT_SHIFT(tmp12 - tmp1, CONST_BITS-PASS1_BITS);
wsptr[DCTSIZE*3] = (int) RIGHT_SHIFT(tmp13 + tmp0, CONST_BITS-PASS1_BITS); wsptr[DCTSIZE*3] = (int) RIGHT_SHIFT(tmp13 + tmp0, CONST_BITS-PASS1_BITS);
wsptr[DCTSIZE*4] = (int) RIGHT_SHIFT(tmp13 - tmp0, CONST_BITS-PASS1_BITS); wsptr[DCTSIZE*4] = (int) RIGHT_SHIFT(tmp13 - tmp0, CONST_BITS-PASS1_BITS);
inptr++; /* advance pointers to next column */ inptr++; /* advance pointers to next column */
quantptr++; quantptr++;
wsptr++; wsptr++;
} }
/* Pass 2: process rows from work array, store into output array. */ /* Pass 2: process rows from work array, store into output array.
/* Note that we must descale the results by a factor of 8 == 2**3, */ * Note that we must descale the results by a factor of 8 == 2**3,
/* and also undo the PASS1_BITS scaling. */ * and also undo the PASS1_BITS scaling.
*/
wsptr = workspace; wsptr = workspace;
for (ctr = 0; ctr < DCTSIZE; ctr++) { for (ctr = 0; ctr < DCTSIZE; ctr++) {
@ -330,15 +335,16 @@ jpeg_idct_islow (j_decompress_ptr cinfo, jpeg_component_info * compptr,
} }
#endif #endif
/* Even part: reverse the even part of the forward DCT. */ /* Even part: reverse the even part of the forward DCT.
/* The rotator is sqrt(2)*c(-6). */ * The rotator is c(-6).
*/
z2 = (INT32) wsptr[2]; z2 = (INT32) wsptr[2];
z3 = (INT32) wsptr[6]; z3 = (INT32) wsptr[6];
z1 = MULTIPLY(z2 + z3, FIX_0_541196100); z1 = MULTIPLY(z2 + z3, FIX_0_541196100); /* c6 */
tmp2 = z1 + MULTIPLY(z2, FIX_0_765366865); tmp2 = z1 + MULTIPLY(z2, FIX_0_765366865); /* c2-c6 */
tmp3 = z1 - MULTIPLY(z3, FIX_1_847759065); tmp3 = z1 - MULTIPLY(z3, FIX_1_847759065); /* c2+c6 */
/* Add fudge factor here for final descale. */ /* Add fudge factor here for final descale. */
z2 = (INT32) wsptr[0] + (ONE << (PASS1_BITS+2)); z2 = (INT32) wsptr[0] + (ONE << (PASS1_BITS+2));
@ -346,7 +352,7 @@ jpeg_idct_islow (j_decompress_ptr cinfo, jpeg_component_info * compptr,
tmp0 = (z2 + z3) << CONST_BITS; tmp0 = (z2 + z3) << CONST_BITS;
tmp1 = (z2 - z3) << CONST_BITS; tmp1 = (z2 - z3) << CONST_BITS;
tmp10 = tmp0 + tmp2; tmp10 = tmp0 + tmp2;
tmp13 = tmp0 - tmp2; tmp13 = tmp0 - tmp2;
tmp11 = tmp1 + tmp3; tmp11 = tmp1 + tmp3;
@ -364,21 +370,21 @@ jpeg_idct_islow (j_decompress_ptr cinfo, jpeg_component_info * compptr,
z2 = tmp0 + tmp2; z2 = tmp0 + tmp2;
z3 = tmp1 + tmp3; z3 = tmp1 + tmp3;
z1 = MULTIPLY(z2 + z3, FIX_1_175875602); /* sqrt(2) * c3 */ z1 = MULTIPLY(z2 + z3, FIX_1_175875602); /* c3 */
z2 = MULTIPLY(z2, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */ z2 = MULTIPLY(z2, - FIX_1_961570560); /* -c3-c5 */
z3 = MULTIPLY(z3, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */ z3 = MULTIPLY(z3, - FIX_0_390180644); /* -c3+c5 */
z2 += z1; z2 += z1;
z3 += z1; z3 += z1;
z1 = MULTIPLY(tmp0 + tmp3, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */ z1 = MULTIPLY(tmp0 + tmp3, - FIX_0_899976223); /* -c3+c7 */
tmp0 = MULTIPLY(tmp0, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */ tmp0 = MULTIPLY(tmp0, FIX_0_298631336); /* -c1+c3+c5-c7 */
tmp3 = MULTIPLY(tmp3, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */ tmp3 = MULTIPLY(tmp3, FIX_1_501321110); /* c1+c3-c5-c7 */
tmp0 += z1 + z2; tmp0 += z1 + z2;
tmp3 += z1 + z3; tmp3 += z1 + z3;
z1 = MULTIPLY(tmp1 + tmp2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */ z1 = MULTIPLY(tmp1 + tmp2, - FIX_2_562915447); /* -c1-c3 */
tmp1 = MULTIPLY(tmp1, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */ tmp1 = MULTIPLY(tmp1, FIX_2_053119869); /* c1+c3-c5+c7 */
tmp2 = MULTIPLY(tmp2, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */ tmp2 = MULTIPLY(tmp2, FIX_3_072711026); /* c1+c3+c5-c7 */
tmp1 += z1 + z3; tmp1 += z1 + z3;
tmp2 += z1 + z2; tmp2 += z1 + z2;
@ -2835,9 +2841,11 @@ jpeg_idct_16x8 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
int workspace[8*8]; /* buffers data between passes */ int workspace[8*8]; /* buffers data between passes */
SHIFT_TEMPS SHIFT_TEMPS
/* Pass 1: process columns from input, store into work array. */ /* Pass 1: process columns from input, store into work array.
/* Note results are scaled up by sqrt(8) compared to a true IDCT; */ * Note results are scaled up by sqrt(8) compared to a true IDCT;
/* furthermore, we scale the results by 2**PASS1_BITS. */ * furthermore, we scale the results by 2**PASS1_BITS.
* 8-point IDCT kernel, cK represents sqrt(2) * cos(K*pi/16).
*/
inptr = coef_block; inptr = coef_block;
quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table; quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
@ -2851,14 +2859,14 @@ jpeg_idct_16x8 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
* With typical images and quantization tables, half or more of the * With typical images and quantization tables, half or more of the
* column DCT calculations can be simplified this way. * column DCT calculations can be simplified this way.
*/ */
if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 && if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 &&
inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*4] == 0 && inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*4] == 0 &&
inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*6] == 0 && inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*6] == 0 &&
inptr[DCTSIZE*7] == 0) { inptr[DCTSIZE*7] == 0) {
/* AC terms all zero */ /* AC terms all zero */
int dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]) << PASS1_BITS; int dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]) << PASS1_BITS;
wsptr[DCTSIZE*0] = dcval; wsptr[DCTSIZE*0] = dcval;
wsptr[DCTSIZE*1] = dcval; wsptr[DCTSIZE*1] = dcval;
wsptr[DCTSIZE*2] = dcval; wsptr[DCTSIZE*2] = dcval;
@ -2867,23 +2875,24 @@ jpeg_idct_16x8 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
wsptr[DCTSIZE*5] = dcval; wsptr[DCTSIZE*5] = dcval;
wsptr[DCTSIZE*6] = dcval; wsptr[DCTSIZE*6] = dcval;
wsptr[DCTSIZE*7] = dcval; wsptr[DCTSIZE*7] = dcval;
inptr++; /* advance pointers to next column */ inptr++; /* advance pointers to next column */
quantptr++; quantptr++;
wsptr++; wsptr++;
continue; continue;
} }
/* Even part: reverse the even part of the forward DCT. */ /* Even part: reverse the even part of the forward DCT.
/* The rotator is sqrt(2)*c(-6). */ * The rotator is c(-6).
*/
z2 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]); z2 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
z3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]); z3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
z1 = MULTIPLY(z2 + z3, FIX_0_541196100); z1 = MULTIPLY(z2 + z3, FIX_0_541196100); /* c6 */
tmp2 = z1 + MULTIPLY(z2, FIX_0_765366865); tmp2 = z1 + MULTIPLY(z2, FIX_0_765366865); /* c2-c6 */
tmp3 = z1 - MULTIPLY(z3, FIX_1_847759065); tmp3 = z1 - MULTIPLY(z3, FIX_1_847759065); /* c2+c6 */
z2 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]); z2 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
z3 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]); z3 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);
z2 <<= CONST_BITS; z2 <<= CONST_BITS;
@ -2893,44 +2902,44 @@ jpeg_idct_16x8 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
tmp0 = z2 + z3; tmp0 = z2 + z3;
tmp1 = z2 - z3; tmp1 = z2 - z3;
tmp10 = tmp0 + tmp2; tmp10 = tmp0 + tmp2;
tmp13 = tmp0 - tmp2; tmp13 = tmp0 - tmp2;
tmp11 = tmp1 + tmp3; tmp11 = tmp1 + tmp3;
tmp12 = tmp1 - tmp3; tmp12 = tmp1 - tmp3;
/* Odd part per figure 8; the matrix is unitary and hence its /* Odd part per figure 8; the matrix is unitary and hence its
* transpose is its inverse. i0..i3 are y7,y5,y3,y1 respectively. * transpose is its inverse. i0..i3 are y7,y5,y3,y1 respectively.
*/ */
tmp0 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]); tmp0 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
tmp1 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]); tmp1 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
tmp2 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]); tmp2 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
tmp3 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]); tmp3 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
z2 = tmp0 + tmp2; z2 = tmp0 + tmp2;
z3 = tmp1 + tmp3; z3 = tmp1 + tmp3;
z1 = MULTIPLY(z2 + z3, FIX_1_175875602); /* sqrt(2) * c3 */ z1 = MULTIPLY(z2 + z3, FIX_1_175875602); /* c3 */
z2 = MULTIPLY(z2, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */ z2 = MULTIPLY(z2, - FIX_1_961570560); /* -c3-c5 */
z3 = MULTIPLY(z3, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */ z3 = MULTIPLY(z3, - FIX_0_390180644); /* -c3+c5 */
z2 += z1; z2 += z1;
z3 += z1; z3 += z1;
z1 = MULTIPLY(tmp0 + tmp3, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */ z1 = MULTIPLY(tmp0 + tmp3, - FIX_0_899976223); /* -c3+c7 */
tmp0 = MULTIPLY(tmp0, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */ tmp0 = MULTIPLY(tmp0, FIX_0_298631336); /* -c1+c3+c5-c7 */
tmp3 = MULTIPLY(tmp3, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */ tmp3 = MULTIPLY(tmp3, FIX_1_501321110); /* c1+c3-c5-c7 */
tmp0 += z1 + z2; tmp0 += z1 + z2;
tmp3 += z1 + z3; tmp3 += z1 + z3;
z1 = MULTIPLY(tmp1 + tmp2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */ z1 = MULTIPLY(tmp1 + tmp2, - FIX_2_562915447); /* -c1-c3 */
tmp1 = MULTIPLY(tmp1, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */ tmp1 = MULTIPLY(tmp1, FIX_2_053119869); /* c1+c3-c5+c7 */
tmp2 = MULTIPLY(tmp2, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */ tmp2 = MULTIPLY(tmp2, FIX_3_072711026); /* c1+c3+c5-c7 */
tmp1 += z1 + z3; tmp1 += z1 + z3;
tmp2 += z1 + z2; tmp2 += z1 + z2;
/* Final output stage: inputs are tmp10..tmp13, tmp0..tmp3 */ /* Final output stage: inputs are tmp10..tmp13, tmp0..tmp3 */
wsptr[DCTSIZE*0] = (int) RIGHT_SHIFT(tmp10 + tmp3, CONST_BITS-PASS1_BITS); wsptr[DCTSIZE*0] = (int) RIGHT_SHIFT(tmp10 + tmp3, CONST_BITS-PASS1_BITS);
wsptr[DCTSIZE*7] = (int) RIGHT_SHIFT(tmp10 - tmp3, CONST_BITS-PASS1_BITS); wsptr[DCTSIZE*7] = (int) RIGHT_SHIFT(tmp10 - tmp3, CONST_BITS-PASS1_BITS);
wsptr[DCTSIZE*1] = (int) RIGHT_SHIFT(tmp11 + tmp2, CONST_BITS-PASS1_BITS); wsptr[DCTSIZE*1] = (int) RIGHT_SHIFT(tmp11 + tmp2, CONST_BITS-PASS1_BITS);
@ -2939,7 +2948,7 @@ jpeg_idct_16x8 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
wsptr[DCTSIZE*5] = (int) RIGHT_SHIFT(tmp12 - tmp1, CONST_BITS-PASS1_BITS); wsptr[DCTSIZE*5] = (int) RIGHT_SHIFT(tmp12 - tmp1, CONST_BITS-PASS1_BITS);
wsptr[DCTSIZE*3] = (int) RIGHT_SHIFT(tmp13 + tmp0, CONST_BITS-PASS1_BITS); wsptr[DCTSIZE*3] = (int) RIGHT_SHIFT(tmp13 + tmp0, CONST_BITS-PASS1_BITS);
wsptr[DCTSIZE*4] = (int) RIGHT_SHIFT(tmp13 - tmp0, CONST_BITS-PASS1_BITS); wsptr[DCTSIZE*4] = (int) RIGHT_SHIFT(tmp13 - tmp0, CONST_BITS-PASS1_BITS);
inptr++; /* advance pointers to next column */ inptr++; /* advance pointers to next column */
quantptr++; quantptr++;
wsptr++; wsptr++;
@ -2948,6 +2957,7 @@ jpeg_idct_16x8 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
/* Pass 2: process 8 rows from work array, store into output array. /* Pass 2: process 8 rows from work array, store into output array.
* 16-point IDCT kernel, cK represents sqrt(2) * cos(K*pi/32). * 16-point IDCT kernel, cK represents sqrt(2) * cos(K*pi/32).
*/ */
wsptr = workspace; wsptr = workspace;
for (ctr = 0; ctr < 8; ctr++) { for (ctr = 0; ctr < 8; ctr++) {
outptr = output_buf[ctr] + output_col; outptr = output_buf[ctr] + output_col;
@ -3109,6 +3119,7 @@ jpeg_idct_14x7 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
/* Pass 1: process columns from input, store into work array. /* Pass 1: process columns from input, store into work array.
* 7-point IDCT kernel, cK represents sqrt(2) * cos(K*pi/14). * 7-point IDCT kernel, cK represents sqrt(2) * cos(K*pi/14).
*/ */
inptr = coef_block; inptr = coef_block;
quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table; quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
wsptr = workspace; wsptr = workspace;
@ -3164,6 +3175,7 @@ jpeg_idct_14x7 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
/* Pass 2: process 7 rows from work array, store into output array. /* Pass 2: process 7 rows from work array, store into output array.
* 14-point IDCT kernel, cK represents sqrt(2) * cos(K*pi/28). * 14-point IDCT kernel, cK represents sqrt(2) * cos(K*pi/28).
*/ */
wsptr = workspace; wsptr = workspace;
for (ctr = 0; ctr < 7; ctr++) { for (ctr = 0; ctr < 7; ctr++) {
outptr = output_buf[ctr] + output_col; outptr = output_buf[ctr] + output_col;
@ -3304,6 +3316,7 @@ jpeg_idct_12x6 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
/* Pass 1: process columns from input, store into work array. /* Pass 1: process columns from input, store into work array.
* 6-point IDCT kernel, cK represents sqrt(2) * cos(K*pi/12). * 6-point IDCT kernel, cK represents sqrt(2) * cos(K*pi/12).
*/ */
inptr = coef_block; inptr = coef_block;
quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table; quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
wsptr = workspace; wsptr = workspace;
@ -3346,6 +3359,7 @@ jpeg_idct_12x6 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
/* Pass 2: process 6 rows from work array, store into output array. /* Pass 2: process 6 rows from work array, store into output array.
* 12-point IDCT kernel, cK represents sqrt(2) * cos(K*pi/24). * 12-point IDCT kernel, cK represents sqrt(2) * cos(K*pi/24).
*/ */
wsptr = workspace; wsptr = workspace;
for (ctr = 0; ctr < 6; ctr++) { for (ctr = 0; ctr < 6; ctr++) {
outptr = output_buf[ctr] + output_col; outptr = output_buf[ctr] + output_col;
@ -3480,6 +3494,7 @@ jpeg_idct_10x5 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
/* Pass 1: process columns from input, store into work array. /* Pass 1: process columns from input, store into work array.
* 5-point IDCT kernel, cK represents sqrt(2) * cos(K*pi/10). * 5-point IDCT kernel, cK represents sqrt(2) * cos(K*pi/10).
*/ */
inptr = coef_block; inptr = coef_block;
quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table; quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
wsptr = workspace; wsptr = workspace;
@ -3520,6 +3535,7 @@ jpeg_idct_10x5 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
/* Pass 2: process 5 rows from work array, store into output array. /* Pass 2: process 5 rows from work array, store into output array.
* 10-point IDCT kernel, cK represents sqrt(2) * cos(K*pi/20). * 10-point IDCT kernel, cK represents sqrt(2) * cos(K*pi/20).
*/ */
wsptr = workspace; wsptr = workspace;
for (ctr = 0; ctr < 5; ctr++) { for (ctr = 0; ctr < 5; ctr++) {
outptr = output_buf[ctr] + output_col; outptr = output_buf[ctr] + output_col;
@ -3639,8 +3655,10 @@ jpeg_idct_8x4 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
SHIFT_TEMPS SHIFT_TEMPS
/* Pass 1: process columns from input, store into work array. /* Pass 1: process columns from input, store into work array.
* 4-point IDCT kernel, cK represents sqrt(2) * cos(K*pi/16). * 4-point IDCT kernel,
* cK represents sqrt(2) * cos(K*pi/16) [refers to 8-point IDCT].
*/ */
inptr = coef_block; inptr = coef_block;
quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table; quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
wsptr = workspace; wsptr = workspace;
@ -3675,31 +3693,34 @@ jpeg_idct_8x4 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
wsptr[8*2] = (int) (tmp12 - tmp2); wsptr[8*2] = (int) (tmp12 - tmp2);
} }
/* Pass 2: process rows from work array, store into output array. */ /* Pass 2: process rows from work array, store into output array.
/* Note that we must descale the results by a factor of 8 == 2**3, */ * Note that we must descale the results by a factor of 8 == 2**3,
/* and also undo the PASS1_BITS scaling. */ * and also undo the PASS1_BITS scaling.
* 8-point IDCT kernel, cK represents sqrt(2) * cos(K*pi/16).
*/
wsptr = workspace; wsptr = workspace;
for (ctr = 0; ctr < 4; ctr++) { for (ctr = 0; ctr < 4; ctr++) {
outptr = output_buf[ctr] + output_col; outptr = output_buf[ctr] + output_col;
/* Even part: reverse the even part of the forward DCT. */ /* Even part: reverse the even part of the forward DCT.
/* The rotator is sqrt(2)*c(-6). */ * The rotator is c(-6).
*/
z2 = (INT32) wsptr[2]; z2 = (INT32) wsptr[2];
z3 = (INT32) wsptr[6]; z3 = (INT32) wsptr[6];
z1 = MULTIPLY(z2 + z3, FIX_0_541196100); z1 = MULTIPLY(z2 + z3, FIX_0_541196100); /* c6 */
tmp2 = z1 + MULTIPLY(z2, FIX_0_765366865); tmp2 = z1 + MULTIPLY(z2, FIX_0_765366865); /* c2-c6 */
tmp3 = z1 - MULTIPLY(z3, FIX_1_847759065); tmp3 = z1 - MULTIPLY(z3, FIX_1_847759065); /* c2+c6 */
/* Add fudge factor here for final descale. */ /* Add fudge factor here for final descale. */
z2 = (INT32) wsptr[0] + (ONE << (PASS1_BITS+2)); z2 = (INT32) wsptr[0] + (ONE << (PASS1_BITS+2));
z3 = (INT32) wsptr[4]; z3 = (INT32) wsptr[4];
tmp0 = (z2 + z3) << CONST_BITS; tmp0 = (z2 + z3) << CONST_BITS;
tmp1 = (z2 - z3) << CONST_BITS; tmp1 = (z2 - z3) << CONST_BITS;
tmp10 = tmp0 + tmp2; tmp10 = tmp0 + tmp2;
tmp13 = tmp0 - tmp2; tmp13 = tmp0 - tmp2;
tmp11 = tmp1 + tmp3; tmp11 = tmp1 + tmp3;
@ -3717,21 +3738,21 @@ jpeg_idct_8x4 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
z2 = tmp0 + tmp2; z2 = tmp0 + tmp2;
z3 = tmp1 + tmp3; z3 = tmp1 + tmp3;
z1 = MULTIPLY(z2 + z3, FIX_1_175875602); /* sqrt(2) * c3 */ z1 = MULTIPLY(z2 + z3, FIX_1_175875602); /* c3 */
z2 = MULTIPLY(z2, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */ z2 = MULTIPLY(z2, - FIX_1_961570560); /* -c3-c5 */
z3 = MULTIPLY(z3, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */ z3 = MULTIPLY(z3, - FIX_0_390180644); /* -c3+c5 */
z2 += z1; z2 += z1;
z3 += z1; z3 += z1;
z1 = MULTIPLY(tmp0 + tmp3, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */ z1 = MULTIPLY(tmp0 + tmp3, - FIX_0_899976223); /* -c3+c7 */
tmp0 = MULTIPLY(tmp0, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */ tmp0 = MULTIPLY(tmp0, FIX_0_298631336); /* -c1+c3+c5-c7 */
tmp3 = MULTIPLY(tmp3, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */ tmp3 = MULTIPLY(tmp3, FIX_1_501321110); /* c1+c3-c5-c7 */
tmp0 += z1 + z2; tmp0 += z1 + z2;
tmp3 += z1 + z3; tmp3 += z1 + z3;
z1 = MULTIPLY(tmp1 + tmp2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */ z1 = MULTIPLY(tmp1 + tmp2, - FIX_2_562915447); /* -c1-c3 */
tmp1 = MULTIPLY(tmp1, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */ tmp1 = MULTIPLY(tmp1, FIX_2_053119869); /* c1+c3-c5+c7 */
tmp2 = MULTIPLY(tmp2, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */ tmp2 = MULTIPLY(tmp2, FIX_3_072711026); /* c1+c3+c5-c7 */
tmp1 += z1 + z3; tmp1 += z1 + z3;
tmp2 += z1 + z2; tmp2 += z1 + z2;
@ -3793,6 +3814,7 @@ jpeg_idct_6x3 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
/* Pass 1: process columns from input, store into work array. /* Pass 1: process columns from input, store into work array.
* 3-point IDCT kernel, cK represents sqrt(2) * cos(K*pi/6). * 3-point IDCT kernel, cK represents sqrt(2) * cos(K*pi/6).
*/ */
inptr = coef_block; inptr = coef_block;
quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table; quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
wsptr = workspace; wsptr = workspace;
@ -3823,6 +3845,7 @@ jpeg_idct_6x3 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
/* Pass 2: process 3 rows from work array, store into output array. /* Pass 2: process 3 rows from work array, store into output array.
* 6-point IDCT kernel, cK represents sqrt(2) * cos(K*pi/12). * 6-point IDCT kernel, cK represents sqrt(2) * cos(K*pi/12).
*/ */
wsptr = workspace; wsptr = workspace;
for (ctr = 0; ctr < 3; ctr++) { for (ctr = 0; ctr < 3; ctr++) {
outptr = output_buf[ctr] + output_col; outptr = output_buf[ctr] + output_col;
@ -3924,6 +3947,7 @@ jpeg_idct_4x2 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
* 4-point IDCT kernel, * 4-point IDCT kernel,
* cK represents sqrt(2) * cos(K*pi/16) [refers to 8-point IDCT]. * cK represents sqrt(2) * cos(K*pi/16) [refers to 8-point IDCT].
*/ */
wsptr = workspace; wsptr = workspace;
for (ctr = 0; ctr < 2; ctr++) { for (ctr = 0; ctr < 2; ctr++) {
outptr = output_buf[ctr] + output_col; outptr = output_buf[ctr] + output_col;
@ -3979,7 +4003,7 @@ jpeg_idct_2x1 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
JCOEFPTR coef_block, JCOEFPTR coef_block,
JSAMPARRAY output_buf, JDIMENSION output_col) JSAMPARRAY output_buf, JDIMENSION output_col)
{ {
INT32 tmp0, tmp10; INT32 tmp0, tmp1;
ISLOW_MULT_TYPE * quantptr; ISLOW_MULT_TYPE * quantptr;
JSAMPROW outptr; JSAMPROW outptr;
JSAMPLE *range_limit = IDCT_range_limit(cinfo); JSAMPLE *range_limit = IDCT_range_limit(cinfo);
@ -3994,18 +4018,18 @@ jpeg_idct_2x1 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
/* Even part */ /* Even part */
tmp10 = DEQUANTIZE(coef_block[0], quantptr[0]); tmp0 = DEQUANTIZE(coef_block[0], quantptr[0]);
/* Add fudge factor here for final descale. */ /* Add fudge factor here for final descale. */
tmp10 += ONE << 2; tmp0 += ONE << 2;
/* Odd part */ /* Odd part */
tmp0 = DEQUANTIZE(coef_block[1], quantptr[1]); tmp1 = DEQUANTIZE(coef_block[1], quantptr[1]);
/* Final output stage */ /* Final output stage */
outptr[0] = range_limit[(int) RIGHT_SHIFT(tmp10 + tmp0, 3) & RANGE_MASK]; outptr[0] = range_limit[(int) RIGHT_SHIFT(tmp0 + tmp1, 3) & RANGE_MASK];
outptr[1] = range_limit[(int) RIGHT_SHIFT(tmp10 - tmp0, 3) & RANGE_MASK]; outptr[1] = range_limit[(int) RIGHT_SHIFT(tmp0 - tmp1, 3) & RANGE_MASK];
} }
@ -4036,6 +4060,7 @@ jpeg_idct_8x16 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
/* Pass 1: process columns from input, store into work array. /* Pass 1: process columns from input, store into work array.
* 16-point IDCT kernel, cK represents sqrt(2) * cos(K*pi/32). * 16-point IDCT kernel, cK represents sqrt(2) * cos(K*pi/32).
*/ */
inptr = coef_block; inptr = coef_block;
quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table; quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
wsptr = workspace; wsptr = workspace;
@ -4134,69 +4159,72 @@ jpeg_idct_8x16 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
wsptr[8*7] = (int) RIGHT_SHIFT(tmp27 + tmp13, CONST_BITS-PASS1_BITS); wsptr[8*7] = (int) RIGHT_SHIFT(tmp27 + tmp13, CONST_BITS-PASS1_BITS);
wsptr[8*8] = (int) RIGHT_SHIFT(tmp27 - tmp13, CONST_BITS-PASS1_BITS); wsptr[8*8] = (int) RIGHT_SHIFT(tmp27 - tmp13, CONST_BITS-PASS1_BITS);
} }
/* Pass 2: process rows from work array, store into output array. */ /* Pass 2: process rows from work array, store into output array.
/* Note that we must descale the results by a factor of 8 == 2**3, */ * Note that we must descale the results by a factor of 8 == 2**3,
/* and also undo the PASS1_BITS scaling. */ * and also undo the PASS1_BITS scaling.
* 8-point IDCT kernel, cK represents sqrt(2) * cos(K*pi/16).
*/
wsptr = workspace; wsptr = workspace;
for (ctr = 0; ctr < 16; ctr++) { for (ctr = 0; ctr < 16; ctr++) {
outptr = output_buf[ctr] + output_col; outptr = output_buf[ctr] + output_col;
/* Even part: reverse the even part of the forward DCT. */ /* Even part: reverse the even part of the forward DCT.
/* The rotator is sqrt(2)*c(-6). */ * The rotator is c(-6).
*/
z2 = (INT32) wsptr[2]; z2 = (INT32) wsptr[2];
z3 = (INT32) wsptr[6]; z3 = (INT32) wsptr[6];
z1 = MULTIPLY(z2 + z3, FIX_0_541196100); z1 = MULTIPLY(z2 + z3, FIX_0_541196100); /* c6 */
tmp2 = z1 + MULTIPLY(z2, FIX_0_765366865); tmp2 = z1 + MULTIPLY(z2, FIX_0_765366865); /* c2-c6 */
tmp3 = z1 - MULTIPLY(z3, FIX_1_847759065); tmp3 = z1 - MULTIPLY(z3, FIX_1_847759065); /* c2+c6 */
/* Add fudge factor here for final descale. */ /* Add fudge factor here for final descale. */
z2 = (INT32) wsptr[0] + (ONE << (PASS1_BITS+2)); z2 = (INT32) wsptr[0] + (ONE << (PASS1_BITS+2));
z3 = (INT32) wsptr[4]; z3 = (INT32) wsptr[4];
tmp0 = (z2 + z3) << CONST_BITS; tmp0 = (z2 + z3) << CONST_BITS;
tmp1 = (z2 - z3) << CONST_BITS; tmp1 = (z2 - z3) << CONST_BITS;
tmp10 = tmp0 + tmp2; tmp10 = tmp0 + tmp2;
tmp13 = tmp0 - tmp2; tmp13 = tmp0 - tmp2;
tmp11 = tmp1 + tmp3; tmp11 = tmp1 + tmp3;
tmp12 = tmp1 - tmp3; tmp12 = tmp1 - tmp3;
/* Odd part per figure 8; the matrix is unitary and hence its /* Odd part per figure 8; the matrix is unitary and hence its
* transpose is its inverse. i0..i3 are y7,y5,y3,y1 respectively. * transpose is its inverse. i0..i3 are y7,y5,y3,y1 respectively.
*/ */
tmp0 = (INT32) wsptr[7]; tmp0 = (INT32) wsptr[7];
tmp1 = (INT32) wsptr[5]; tmp1 = (INT32) wsptr[5];
tmp2 = (INT32) wsptr[3]; tmp2 = (INT32) wsptr[3];
tmp3 = (INT32) wsptr[1]; tmp3 = (INT32) wsptr[1];
z2 = tmp0 + tmp2; z2 = tmp0 + tmp2;
z3 = tmp1 + tmp3; z3 = tmp1 + tmp3;
z1 = MULTIPLY(z2 + z3, FIX_1_175875602); /* sqrt(2) * c3 */ z1 = MULTIPLY(z2 + z3, FIX_1_175875602); /* c3 */
z2 = MULTIPLY(z2, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */ z2 = MULTIPLY(z2, - FIX_1_961570560); /* -c3-c5 */
z3 = MULTIPLY(z3, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */ z3 = MULTIPLY(z3, - FIX_0_390180644); /* -c3+c5 */
z2 += z1; z2 += z1;
z3 += z1; z3 += z1;
z1 = MULTIPLY(tmp0 + tmp3, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */ z1 = MULTIPLY(tmp0 + tmp3, - FIX_0_899976223); /* -c3+c7 */
tmp0 = MULTIPLY(tmp0, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */ tmp0 = MULTIPLY(tmp0, FIX_0_298631336); /* -c1+c3+c5-c7 */
tmp3 = MULTIPLY(tmp3, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */ tmp3 = MULTIPLY(tmp3, FIX_1_501321110); /* c1+c3-c5-c7 */
tmp0 += z1 + z2; tmp0 += z1 + z2;
tmp3 += z1 + z3; tmp3 += z1 + z3;
z1 = MULTIPLY(tmp1 + tmp2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */ z1 = MULTIPLY(tmp1 + tmp2, - FIX_2_562915447); /* -c1-c3 */
tmp1 = MULTIPLY(tmp1, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */ tmp1 = MULTIPLY(tmp1, FIX_2_053119869); /* c1+c3-c5+c7 */
tmp2 = MULTIPLY(tmp2, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */ tmp2 = MULTIPLY(tmp2, FIX_3_072711026); /* c1+c3+c5-c7 */
tmp1 += z1 + z3; tmp1 += z1 + z3;
tmp2 += z1 + z2; tmp2 += z1 + z2;
/* Final output stage: inputs are tmp10..tmp13, tmp0..tmp3 */ /* Final output stage: inputs are tmp10..tmp13, tmp0..tmp3 */
outptr[0] = range_limit[(int) RIGHT_SHIFT(tmp10 + tmp3, outptr[0] = range_limit[(int) RIGHT_SHIFT(tmp10 + tmp3,
CONST_BITS+PASS1_BITS+3) CONST_BITS+PASS1_BITS+3)
& RANGE_MASK]; & RANGE_MASK];
@ -4221,7 +4249,7 @@ jpeg_idct_8x16 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
outptr[4] = range_limit[(int) RIGHT_SHIFT(tmp13 - tmp0, outptr[4] = range_limit[(int) RIGHT_SHIFT(tmp13 - tmp0,
CONST_BITS+PASS1_BITS+3) CONST_BITS+PASS1_BITS+3)
& RANGE_MASK]; & RANGE_MASK];
wsptr += DCTSIZE; /* advance pointer to next row */ wsptr += DCTSIZE; /* advance pointer to next row */
} }
} }
@ -4254,6 +4282,7 @@ jpeg_idct_7x14 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
/* Pass 1: process columns from input, store into work array. /* Pass 1: process columns from input, store into work array.
* 14-point IDCT kernel, cK represents sqrt(2) * cos(K*pi/28). * 14-point IDCT kernel, cK represents sqrt(2) * cos(K*pi/28).
*/ */
inptr = coef_block; inptr = coef_block;
quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table; quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
wsptr = workspace; wsptr = workspace;
@ -4341,6 +4370,7 @@ jpeg_idct_7x14 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
/* Pass 2: process 14 rows from work array, store into output array. /* Pass 2: process 14 rows from work array, store into output array.
* 7-point IDCT kernel, cK represents sqrt(2) * cos(K*pi/14). * 7-point IDCT kernel, cK represents sqrt(2) * cos(K*pi/14).
*/ */
wsptr = workspace; wsptr = workspace;
for (ctr = 0; ctr < 14; ctr++) { for (ctr = 0; ctr < 14; ctr++) {
outptr = output_buf[ctr] + output_col; outptr = output_buf[ctr] + output_col;
@ -4437,6 +4467,7 @@ jpeg_idct_6x12 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
/* Pass 1: process columns from input, store into work array. /* Pass 1: process columns from input, store into work array.
* 12-point IDCT kernel, cK represents sqrt(2) * cos(K*pi/24). * 12-point IDCT kernel, cK represents sqrt(2) * cos(K*pi/24).
*/ */
inptr = coef_block; inptr = coef_block;
quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table; quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
wsptr = workspace; wsptr = workspace;
@ -4520,6 +4551,7 @@ jpeg_idct_6x12 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
/* Pass 2: process 12 rows from work array, store into output array. /* Pass 2: process 12 rows from work array, store into output array.
* 6-point IDCT kernel, cK represents sqrt(2) * cos(K*pi/12). * 6-point IDCT kernel, cK represents sqrt(2) * cos(K*pi/12).
*/ */
wsptr = workspace; wsptr = workspace;
for (ctr = 0; ctr < 12; ctr++) { for (ctr = 0; ctr < 12; ctr++) {
outptr = output_buf[ctr] + output_col; outptr = output_buf[ctr] + output_col;
@ -4601,6 +4633,7 @@ jpeg_idct_5x10 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
/* Pass 1: process columns from input, store into work array. /* Pass 1: process columns from input, store into work array.
* 10-point IDCT kernel, cK represents sqrt(2) * cos(K*pi/20). * 10-point IDCT kernel, cK represents sqrt(2) * cos(K*pi/20).
*/ */
inptr = coef_block; inptr = coef_block;
quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table; quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
wsptr = workspace; wsptr = workspace;
@ -4676,6 +4709,7 @@ jpeg_idct_5x10 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
/* Pass 2: process 10 rows from work array, store into output array. /* Pass 2: process 10 rows from work array, store into output array.
* 5-point IDCT kernel, cK represents sqrt(2) * cos(K*pi/10). * 5-point IDCT kernel, cK represents sqrt(2) * cos(K*pi/10).
*/ */
wsptr = workspace; wsptr = workspace;
for (ctr = 0; ctr < 10; ctr++) { for (ctr = 0; ctr < 10; ctr++) {
outptr = output_buf[ctr] + output_col; outptr = output_buf[ctr] + output_col;
@ -4750,9 +4784,11 @@ jpeg_idct_4x8 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
int workspace[4*8]; /* buffers data between passes */ int workspace[4*8]; /* buffers data between passes */
SHIFT_TEMPS SHIFT_TEMPS
/* Pass 1: process columns from input, store into work array. */ /* Pass 1: process columns from input, store into work array.
/* Note results are scaled up by sqrt(8) compared to a true IDCT; */ * Note results are scaled up by sqrt(8) compared to a true IDCT;
/* furthermore, we scale the results by 2**PASS1_BITS. */ * furthermore, we scale the results by 2**PASS1_BITS.
* 8-point IDCT kernel, cK represents sqrt(2) * cos(K*pi/16).
*/
inptr = coef_block; inptr = coef_block;
quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table; quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
@ -4789,16 +4825,17 @@ jpeg_idct_4x8 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
continue; continue;
} }
/* Even part: reverse the even part of the forward DCT. */ /* Even part: reverse the even part of the forward DCT.
/* The rotator is sqrt(2)*c(-6). */ * The rotator is c(-6).
*/
z2 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]); z2 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
z3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]); z3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
z1 = MULTIPLY(z2 + z3, FIX_0_541196100); z1 = MULTIPLY(z2 + z3, FIX_0_541196100); /* c6 */
tmp2 = z1 + MULTIPLY(z2, FIX_0_765366865); tmp2 = z1 + MULTIPLY(z2, FIX_0_765366865); /* c2-c6 */
tmp3 = z1 - MULTIPLY(z3, FIX_1_847759065); tmp3 = z1 - MULTIPLY(z3, FIX_1_847759065); /* c2+c6 */
z2 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]); z2 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
z3 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]); z3 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);
z2 <<= CONST_BITS; z2 <<= CONST_BITS;
@ -4808,7 +4845,7 @@ jpeg_idct_4x8 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
tmp0 = z2 + z3; tmp0 = z2 + z3;
tmp1 = z2 - z3; tmp1 = z2 - z3;
tmp10 = tmp0 + tmp2; tmp10 = tmp0 + tmp2;
tmp13 = tmp0 - tmp2; tmp13 = tmp0 - tmp2;
tmp11 = tmp1 + tmp3; tmp11 = tmp1 + tmp3;
@ -4826,21 +4863,21 @@ jpeg_idct_4x8 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
z2 = tmp0 + tmp2; z2 = tmp0 + tmp2;
z3 = tmp1 + tmp3; z3 = tmp1 + tmp3;
z1 = MULTIPLY(z2 + z3, FIX_1_175875602); /* sqrt(2) * c3 */ z1 = MULTIPLY(z2 + z3, FIX_1_175875602); /* c3 */
z2 = MULTIPLY(z2, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */ z2 = MULTIPLY(z2, - FIX_1_961570560); /* -c3-c5 */
z3 = MULTIPLY(z3, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */ z3 = MULTIPLY(z3, - FIX_0_390180644); /* -c3+c5 */
z2 += z1; z2 += z1;
z3 += z1; z3 += z1;
z1 = MULTIPLY(tmp0 + tmp3, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */ z1 = MULTIPLY(tmp0 + tmp3, - FIX_0_899976223); /* -c3+c7 */
tmp0 = MULTIPLY(tmp0, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */ tmp0 = MULTIPLY(tmp0, FIX_0_298631336); /* -c1+c3+c5-c7 */
tmp3 = MULTIPLY(tmp3, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */ tmp3 = MULTIPLY(tmp3, FIX_1_501321110); /* c1+c3-c5-c7 */
tmp0 += z1 + z2; tmp0 += z1 + z2;
tmp3 += z1 + z3; tmp3 += z1 + z3;
z1 = MULTIPLY(tmp1 + tmp2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */ z1 = MULTIPLY(tmp1 + tmp2, - FIX_2_562915447); /* -c1-c3 */
tmp1 = MULTIPLY(tmp1, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */ tmp1 = MULTIPLY(tmp1, FIX_2_053119869); /* c1+c3-c5+c7 */
tmp2 = MULTIPLY(tmp2, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */ tmp2 = MULTIPLY(tmp2, FIX_3_072711026); /* c1+c3+c5-c7 */
tmp1 += z1 + z3; tmp1 += z1 + z3;
tmp2 += z1 + z2; tmp2 += z1 + z2;
@ -4861,8 +4898,10 @@ jpeg_idct_4x8 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
} }
/* Pass 2: process 8 rows from work array, store into output array. /* Pass 2: process 8 rows from work array, store into output array.
* 4-point IDCT kernel, cK represents sqrt(2) * cos(K*pi/16). * 4-point IDCT kernel,
* cK represents sqrt(2) * cos(K*pi/16) [refers to 8-point IDCT].
*/ */
wsptr = workspace; wsptr = workspace;
for (ctr = 0; ctr < 8; ctr++) { for (ctr = 0; ctr < 8; ctr++) {
outptr = output_buf[ctr] + output_col; outptr = output_buf[ctr] + output_col;
@ -4900,7 +4939,7 @@ jpeg_idct_4x8 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
outptr[2] = range_limit[(int) RIGHT_SHIFT(tmp12 - tmp2, outptr[2] = range_limit[(int) RIGHT_SHIFT(tmp12 - tmp2,
CONST_BITS+PASS1_BITS+3) CONST_BITS+PASS1_BITS+3)
& RANGE_MASK]; & RANGE_MASK];
wsptr += 4; /* advance pointer to next row */ wsptr += 4; /* advance pointer to next row */
} }
} }
@ -4932,6 +4971,7 @@ jpeg_idct_3x6 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
/* Pass 1: process columns from input, store into work array. /* Pass 1: process columns from input, store into work array.
* 6-point IDCT kernel, cK represents sqrt(2) * cos(K*pi/12). * 6-point IDCT kernel, cK represents sqrt(2) * cos(K*pi/12).
*/ */
inptr = coef_block; inptr = coef_block;
quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table; quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
wsptr = workspace; wsptr = workspace;
@ -4974,6 +5014,7 @@ jpeg_idct_3x6 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
/* Pass 2: process 6 rows from work array, store into output array. /* Pass 2: process 6 rows from work array, store into output array.
* 3-point IDCT kernel, cK represents sqrt(2) * cos(K*pi/6). * 3-point IDCT kernel, cK represents sqrt(2) * cos(K*pi/6).
*/ */
wsptr = workspace; wsptr = workspace;
for (ctr = 0; ctr < 6; ctr++) { for (ctr = 0; ctr < 6; ctr++) {
outptr = output_buf[ctr] + output_col; outptr = output_buf[ctr] + output_col;
@ -5037,6 +5078,7 @@ jpeg_idct_2x4 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
* 4-point IDCT kernel, * 4-point IDCT kernel,
* cK represents sqrt(2) * cos(K*pi/16) [refers to 8-point IDCT]. * cK represents sqrt(2) * cos(K*pi/16) [refers to 8-point IDCT].
*/ */
inptr = coef_block; inptr = coef_block;
quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table; quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
wsptr = workspace; wsptr = workspace;
@ -5106,7 +5148,7 @@ jpeg_idct_1x2 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
JCOEFPTR coef_block, JCOEFPTR coef_block,
JSAMPARRAY output_buf, JDIMENSION output_col) JSAMPARRAY output_buf, JDIMENSION output_col)
{ {
INT32 tmp0, tmp10; INT32 tmp0, tmp1;
ISLOW_MULT_TYPE * quantptr; ISLOW_MULT_TYPE * quantptr;
JSAMPLE *range_limit = IDCT_range_limit(cinfo); JSAMPLE *range_limit = IDCT_range_limit(cinfo);
SHIFT_TEMPS SHIFT_TEMPS
@ -5117,19 +5159,19 @@ jpeg_idct_1x2 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
/* Even part */ /* Even part */
tmp10 = DEQUANTIZE(coef_block[DCTSIZE*0], quantptr[DCTSIZE*0]); tmp0 = DEQUANTIZE(coef_block[DCTSIZE*0], quantptr[DCTSIZE*0]);
/* Add fudge factor here for final descale. */ /* Add fudge factor here for final descale. */
tmp10 += ONE << 2; tmp0 += ONE << 2;
/* Odd part */ /* Odd part */
tmp0 = DEQUANTIZE(coef_block[DCTSIZE*1], quantptr[DCTSIZE*1]); tmp1 = DEQUANTIZE(coef_block[DCTSIZE*1], quantptr[DCTSIZE*1]);
/* Final output stage */ /* Final output stage */
output_buf[0][output_col] = range_limit[(int) RIGHT_SHIFT(tmp10 + tmp0, 3) output_buf[0][output_col] = range_limit[(int) RIGHT_SHIFT(tmp0 + tmp1, 3)
& RANGE_MASK]; & RANGE_MASK];
output_buf[1][output_col] = range_limit[(int) RIGHT_SHIFT(tmp10 - tmp0, 3) output_buf[1][output_col] = range_limit[(int) RIGHT_SHIFT(tmp0 - tmp1, 3)
& RANGE_MASK]; & RANGE_MASK];
} }

View File

@ -2,6 +2,7 @@
* jmemmgr.c * jmemmgr.c
* *
* Copyright (C) 1991-1997, Thomas G. Lane. * Copyright (C) 1991-1997, Thomas G. Lane.
* Modified 2011-2012 by Guido Vollbeding.
* This file is part of the Independent JPEG Group's software. * This file is part of the Independent JPEG Group's software.
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
@ -213,7 +214,7 @@ print_mem_stats (j_common_ptr cinfo, int pool_id)
#endif /* MEM_STATS */ #endif /* MEM_STATS */
LOCAL(void) LOCAL(noreturn_t)
out_of_memory (j_common_ptr cinfo, int which) out_of_memory (j_common_ptr cinfo, int which)
/* Report an out-of-memory error and stop execution */ /* Report an out-of-memory error and stop execution */
/* If we compiled MEM_STATS support, report alloc requests before dying */ /* If we compiled MEM_STATS support, report alloc requests before dying */
@ -303,7 +304,7 @@ alloc_small (j_common_ptr cinfo, int pool_id, size_t sizeofobject)
if (slop < MIN_SLOP) /* give up when it gets real small */ if (slop < MIN_SLOP) /* give up when it gets real small */
out_of_memory(cinfo, 2); /* jpeg_get_small failed */ out_of_memory(cinfo, 2); /* jpeg_get_small failed */
} }
mem->total_space_allocated += (long) (min_request + slop); mem->total_space_allocated += min_request + slop;
/* Success, initialize the new pool header and add to end of list */ /* Success, initialize the new pool header and add to end of list */
hdr_ptr->hdr.next = NULL; hdr_ptr->hdr.next = NULL;
hdr_ptr->hdr.bytes_used = 0; hdr_ptr->hdr.bytes_used = 0;
@ -363,7 +364,7 @@ alloc_large (j_common_ptr cinfo, int pool_id, size_t sizeofobject)
SIZEOF(large_pool_hdr)); SIZEOF(large_pool_hdr));
if (hdr_ptr == NULL) if (hdr_ptr == NULL)
out_of_memory(cinfo, 4); /* jpeg_get_large failed */ out_of_memory(cinfo, 4); /* jpeg_get_large failed */
mem->total_space_allocated += (long) (sizeofobject + SIZEOF(large_pool_hdr)); mem->total_space_allocated += sizeofobject + SIZEOF(large_pool_hdr);
/* Success, initialize the new pool header and add to list */ /* Success, initialize the new pool header and add to list */
hdr_ptr->hdr.next = mem->large_list[pool_id]; hdr_ptr->hdr.next = mem->large_list[pool_id];
@ -821,7 +822,7 @@ access_virt_sarray (j_common_ptr cinfo, jvirt_sarray_ptr ptr,
undef_row -= ptr->cur_start_row; /* make indexes relative to buffer */ undef_row -= ptr->cur_start_row; /* make indexes relative to buffer */
end_row -= ptr->cur_start_row; end_row -= ptr->cur_start_row;
while (undef_row < end_row) { while (undef_row < end_row) {
jzero_far((void FAR *) ptr->mem_buffer[undef_row], bytesperrow); FMEMZERO((void FAR *) ptr->mem_buffer[undef_row], bytesperrow);
undef_row++; undef_row++;
} }
} else { } else {
@ -906,7 +907,7 @@ access_virt_barray (j_common_ptr cinfo, jvirt_barray_ptr ptr,
undef_row -= ptr->cur_start_row; /* make indexes relative to buffer */ undef_row -= ptr->cur_start_row; /* make indexes relative to buffer */
end_row -= ptr->cur_start_row; end_row -= ptr->cur_start_row;
while (undef_row < end_row) { while (undef_row < end_row) {
jzero_far((void FAR *) ptr->mem_buffer[undef_row], bytesperrow); FMEMZERO((void FAR *) ptr->mem_buffer[undef_row], bytesperrow);
undef_row++; undef_row++;
} }
} else { } else {
@ -973,7 +974,7 @@ free_pool (j_common_ptr cinfo, int pool_id)
lhdr_ptr->hdr.bytes_left + lhdr_ptr->hdr.bytes_left +
SIZEOF(large_pool_hdr); SIZEOF(large_pool_hdr);
jpeg_free_large(cinfo, (void FAR *) lhdr_ptr, space_freed); jpeg_free_large(cinfo, (void FAR *) lhdr_ptr, space_freed);
mem->total_space_allocated -= (long) space_freed; mem->total_space_allocated -= space_freed;
lhdr_ptr = next_lhdr_ptr; lhdr_ptr = next_lhdr_ptr;
} }
@ -987,7 +988,7 @@ free_pool (j_common_ptr cinfo, int pool_id)
shdr_ptr->hdr.bytes_left + shdr_ptr->hdr.bytes_left +
SIZEOF(small_pool_hdr); SIZEOF(small_pool_hdr);
jpeg_free_small(cinfo, (void *) shdr_ptr, space_freed); jpeg_free_small(cinfo, (void *) shdr_ptr, space_freed);
mem->total_space_allocated -= (long) space_freed; mem->total_space_allocated -= space_freed;
shdr_ptr = next_shdr_ptr; shdr_ptr = next_shdr_ptr;
} }
} }

View File

@ -2,7 +2,7 @@
* jmorecfg.h * jmorecfg.h
* *
* Copyright (C) 1991-1997, Thomas G. Lane. * Copyright (C) 1991-1997, Thomas G. Lane.
* Modified 1997-2009 by Guido Vollbeding. * Modified 1997-2013 by Guido Vollbeding.
* This file is part of the Independent JPEG Group's software. * This file is part of the Independent JPEG Group's software.
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
@ -15,13 +15,22 @@
/* /*
* Define BITS_IN_JSAMPLE as either * Define BITS_IN_JSAMPLE as either
* 8 for 8-bit sample values (the usual setting) * 8 for 8-bit sample values (the usual setting)
* 9 for 9-bit sample values
* 10 for 10-bit sample values
* 11 for 11-bit sample values
* 12 for 12-bit sample values * 12 for 12-bit sample values
* Only 8 and 12 are legal data precisions for lossy JPEG according to the * Only 8, 9, 10, 11, and 12 bits sample data precision are supported for
* JPEG standard, and the IJG code does not support anything else! * full-feature DCT processing. Further depths up to 16-bit may be added
* We do not support run-time selection of data precision, sorry. * later for the lossless modes of operation.
* Run-time selection and conversion of data precision will be added later
* and are currently not supported, sorry.
* Exception: The transcoding part (jpegtran) supports all settings in a
* single instance, since it operates on the level of DCT coefficients and
* not sample values. The DCT coefficients are of the same type (16 bits)
* in all cases (see below).
*/ */
#define BITS_IN_JSAMPLE 8 /* use 8 or 12 */ #define BITS_IN_JSAMPLE 8 /* use 8, 9, 10, 11, or 12 */
/* /*
@ -77,6 +86,48 @@ typedef char JSAMPLE;
#endif /* BITS_IN_JSAMPLE == 8 */ #endif /* BITS_IN_JSAMPLE == 8 */
#if BITS_IN_JSAMPLE == 9
/* JSAMPLE should be the smallest type that will hold the values 0..511.
* On nearly all machines "short" will do nicely.
*/
typedef short JSAMPLE;
#define GETJSAMPLE(value) ((int) (value))
#define MAXJSAMPLE 511
#define CENTERJSAMPLE 256
#endif /* BITS_IN_JSAMPLE == 9 */
#if BITS_IN_JSAMPLE == 10
/* JSAMPLE should be the smallest type that will hold the values 0..1023.
* On nearly all machines "short" will do nicely.
*/
typedef short JSAMPLE;
#define GETJSAMPLE(value) ((int) (value))
#define MAXJSAMPLE 1023
#define CENTERJSAMPLE 512
#endif /* BITS_IN_JSAMPLE == 10 */
#if BITS_IN_JSAMPLE == 11
/* JSAMPLE should be the smallest type that will hold the values 0..2047.
* On nearly all machines "short" will do nicely.
*/
typedef short JSAMPLE;
#define GETJSAMPLE(value) ((int) (value))
#define MAXJSAMPLE 2047
#define CENTERJSAMPLE 1024
#endif /* BITS_IN_JSAMPLE == 11 */
#if BITS_IN_JSAMPLE == 12 #if BITS_IN_JSAMPLE == 12
/* JSAMPLE should be the smallest type that will hold the values 0..4095. /* JSAMPLE should be the smallest type that will hold the values 0..4095.
* On nearly all machines "short" will do nicely. * On nearly all machines "short" will do nicely.
@ -210,6 +261,26 @@ typedef unsigned int JDIMENSION;
#endif #endif
/* The noreturn type identifier is used to declare functions
* which cannot return.
* Compilers can thus create more optimized code and perform
* better checks for warnings and errors.
* Static analyzer tools can make improved inferences about
* execution paths and are prevented from giving false alerts.
*
* Unfortunately, the proposed specifications of corresponding
* extensions in the Dec 2011 ISO C standard revision (C11),
* GCC, MSVC, etc. are not viable.
* Thus we introduce a user defined type to declare noreturn
* functions at least for clarity. A proper compiler would
* have a suitable noreturn type to match in place of void.
*/
#ifndef HAVE_NORETURN_T
typedef void noreturn_t;
#endif
/* Here is the pseudo-keyword for declaring pointers that must be "far" /* Here is the pseudo-keyword for declaring pointers that must be "far"
* on 80x86 machines. Most of the specialized coding for 80x86 is handled * on 80x86 machines. Most of the specialized coding for 80x86 is handled
* by just saying "FAR *" where such a pointer is needed. In a few places * by just saying "FAR *" where such a pointer is needed. In a few places
@ -233,14 +304,19 @@ typedef unsigned int JDIMENSION;
*/ */
#ifndef HAVE_BOOLEAN #ifndef HAVE_BOOLEAN
#if defined FALSE || defined TRUE || defined QGLOBAL_H
/* Qt3 defines FALSE and TRUE as "const" variables in qglobal.h */
typedef int boolean; typedef int boolean;
#endif
#ifndef FALSE /* in case these macros already exist */ #ifndef FALSE /* in case these macros already exist */
#define FALSE 0 /* values of boolean */ #define FALSE 0 /* values of boolean */
#endif #endif
#ifndef TRUE #ifndef TRUE
#define TRUE 1 #define TRUE 1
#endif #endif
#else
typedef enum { FALSE = 0, TRUE = 1 } boolean;
#endif
#endif
/* /*
@ -278,11 +354,12 @@ typedef int boolean;
#define C_PROGRESSIVE_SUPPORTED /* Progressive JPEG? (Requires MULTISCAN)*/ #define C_PROGRESSIVE_SUPPORTED /* Progressive JPEG? (Requires MULTISCAN)*/
#define DCT_SCALING_SUPPORTED /* Input rescaling via DCT? (Requires DCT_ISLOW)*/ #define DCT_SCALING_SUPPORTED /* Input rescaling via DCT? (Requires DCT_ISLOW)*/
#define ENTROPY_OPT_SUPPORTED /* Optimization of entropy coding parms? */ #define ENTROPY_OPT_SUPPORTED /* Optimization of entropy coding parms? */
/* Note: if you selected 12-bit data precision, it is dangerous to turn off /* Note: if you selected more than 8-bit data precision, it is dangerous to
* ENTROPY_OPT_SUPPORTED. The standard Huffman tables are only good for 8-bit * turn off ENTROPY_OPT_SUPPORTED. The standard Huffman tables are only
* precision, so jchuff.c normally uses entropy optimization to compute * good for 8-bit precision, so arithmetic coding is recommended for higher
* usable tables for higher precision. If you don't want to do optimization, * precision. The Huffman encoder normally uses entropy optimization to
* you'll have to supply different default Huffman tables. * compute usable tables for higher precision. Otherwise, you'll have to
* supply different default Huffman tables.
* The exact same statements apply for progressive JPEG: the default tables * The exact same statements apply for progressive JPEG: the default tables
* don't work for progressive mode. (This may get fixed, however.) * don't work for progressive mode. (This may get fixed, however.)
*/ */
@ -293,7 +370,7 @@ typedef int boolean;
#define D_ARITH_CODING_SUPPORTED /* Arithmetic coding back end? */ #define D_ARITH_CODING_SUPPORTED /* Arithmetic coding back end? */
#define D_MULTISCAN_FILES_SUPPORTED /* Multiple-scan JPEG files? */ #define D_MULTISCAN_FILES_SUPPORTED /* Multiple-scan JPEG files? */
#define D_PROGRESSIVE_SUPPORTED /* Progressive JPEG? (Requires MULTISCAN)*/ #define D_PROGRESSIVE_SUPPORTED /* Progressive JPEG? (Requires MULTISCAN)*/
#define IDCT_SCALING_SUPPORTED /* Output rescaling via IDCT? */ #define IDCT_SCALING_SUPPORTED /* Output rescaling via IDCT? (Requires DCT_ISLOW)*/
#define SAVE_MARKERS_SUPPORTED /* jpeg_save_markers() needed? */ #define SAVE_MARKERS_SUPPORTED /* jpeg_save_markers() needed? */
#define BLOCK_SMOOTHING_SUPPORTED /* Block smoothing? (Progressive only) */ #define BLOCK_SMOOTHING_SUPPORTED /* Block smoothing? (Progressive only) */
#undef UPSAMPLE_SCALING_SUPPORTED /* Output rescaling at upsample stage? */ #undef UPSAMPLE_SCALING_SUPPORTED /* Output rescaling at upsample stage? */
@ -312,9 +389,7 @@ typedef int boolean;
* the offsets will also change the order in which colormap data is organized. * the offsets will also change the order in which colormap data is organized.
* RESTRICTIONS: * RESTRICTIONS:
* 1. The sample applications cjpeg,djpeg do NOT support modified RGB formats. * 1. The sample applications cjpeg,djpeg do NOT support modified RGB formats.
* 2. These macros only affect RGB<=>YCbCr color conversion, so they are not * 2. The color quantizer modules will not behave desirably if RGB_PIXELSIZE
* useful if you are using JPEG color spaces other than YCbCr or grayscale.
* 3. The color quantizer modules will not behave desirably if RGB_PIXELSIZE
* is not 3 (they don't understand about dummy color components!). So you * is not 3 (they don't understand about dummy color components!). So you
* can't use color quantization if you change that value. * can't use color quantization if you change that value.
*/ */

View File

@ -2,7 +2,7 @@
* jpegint.h * jpegint.h
* *
* Copyright (C) 1991-1997, Thomas G. Lane. * Copyright (C) 1991-1997, Thomas G. Lane.
* Modified 1997-2009 by Guido Vollbeding. * Modified 1997-2013 by Guido Vollbeding.
* This file is part of the Independent JPEG Group's software. * This file is part of the Independent JPEG Group's software.
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
@ -211,8 +211,8 @@ struct jpeg_marker_reader {
/* Entropy decoding */ /* Entropy decoding */
struct jpeg_entropy_decoder { struct jpeg_entropy_decoder {
JMETHOD(void, start_pass, (j_decompress_ptr cinfo)); JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
JMETHOD(boolean, decode_mcu, (j_decompress_ptr cinfo, JMETHOD(boolean, decode_mcu, (j_decompress_ptr cinfo, JBLOCKROW *MCU_data));
JBLOCKROW *MCU_data)); JMETHOD(void, finish_pass, (j_decompress_ptr cinfo));
}; };
/* Inverse DCT (also performs dequantization) */ /* Inverse DCT (also performs dequantization) */
@ -321,21 +321,41 @@ struct jpeg_color_quantizer {
#define jinit_memory_mgr jIMemMgr #define jinit_memory_mgr jIMemMgr
#define jdiv_round_up jDivRound #define jdiv_round_up jDivRound
#define jround_up jRound #define jround_up jRound
#define jzero_far jZeroFar
#define jcopy_sample_rows jCopySamples #define jcopy_sample_rows jCopySamples
#define jcopy_block_row jCopyBlocks #define jcopy_block_row jCopyBlocks
#define jzero_far jZeroFar
#define jpeg_zigzag_order jZIGTable #define jpeg_zigzag_order jZIGTable
#define jpeg_natural_order jZAGTable #define jpeg_natural_order jZAGTable
#define jpeg_natural_order7 jZAGTable7 #define jpeg_natural_order7 jZAG7Table
#define jpeg_natural_order6 jZAGTable6 #define jpeg_natural_order6 jZAG6Table
#define jpeg_natural_order5 jZAGTable5 #define jpeg_natural_order5 jZAG5Table
#define jpeg_natural_order4 jZAGTable4 #define jpeg_natural_order4 jZAG4Table
#define jpeg_natural_order3 jZAGTable3 #define jpeg_natural_order3 jZAG3Table
#define jpeg_natural_order2 jZAGTable2 #define jpeg_natural_order2 jZAG2Table
#define jpeg_aritab jAriTab #define jpeg_aritab jAriTab
#endif /* NEED_SHORT_EXTERNAL_NAMES */ #endif /* NEED_SHORT_EXTERNAL_NAMES */
/* On normal machines we can apply MEMCOPY() and MEMZERO() to sample arrays
* and coefficient-block arrays. This won't work on 80x86 because the arrays
* are FAR and we're assuming a small-pointer memory model. However, some
* DOS compilers provide far-pointer versions of memcpy() and memset() even
* in the small-model libraries. These will be used if USE_FMEM is defined.
* Otherwise, the routines in jutils.c do it the hard way.
*/
#ifndef NEED_FAR_POINTERS /* normal case, same as regular macro */
#define FMEMZERO(target,size) MEMZERO(target,size)
#else /* 80x86 case */
#ifdef USE_FMEM
#define FMEMZERO(target,size) _fmemset((void FAR *)(target), 0, (size_t)(size))
#else
EXTERN(void) jzero_far JPP((void FAR * target, size_t bytestozero));
#define FMEMZERO(target,size) jzero_far(target, size)
#endif
#endif
/* Compression module initialization routines */ /* Compression module initialization routines */
EXTERN(void) jinit_compress_master JPP((j_compress_ptr cinfo)); EXTERN(void) jinit_compress_master JPP((j_compress_ptr cinfo));
EXTERN(void) jinit_c_master_control JPP((j_compress_ptr cinfo, EXTERN(void) jinit_c_master_control JPP((j_compress_ptr cinfo,
@ -381,7 +401,6 @@ EXTERN(void) jcopy_sample_rows JPP((JSAMPARRAY input_array, int source_row,
int num_rows, JDIMENSION num_cols)); int num_rows, JDIMENSION num_cols));
EXTERN(void) jcopy_block_row JPP((JBLOCKROW input_row, JBLOCKROW output_row, EXTERN(void) jcopy_block_row JPP((JBLOCKROW input_row, JBLOCKROW output_row,
JDIMENSION num_blocks)); JDIMENSION num_blocks));
EXTERN(void) jzero_far JPP((void FAR * target, size_t bytestozero));
/* Constant tables in jutils.c */ /* Constant tables in jutils.c */
#if 0 /* This table is not actually needed in v6a */ #if 0 /* This table is not actually needed in v6a */
extern const int jpeg_zigzag_order[]; /* natural coef order to zigzag order */ extern const int jpeg_zigzag_order[]; /* natural coef order to zigzag order */

View File

@ -2,7 +2,7 @@
* jpeglib.h * jpeglib.h
* *
* Copyright (C) 1991-1998, Thomas G. Lane. * Copyright (C) 1991-1998, Thomas G. Lane.
* Modified 2002-2010 by Guido Vollbeding. * Modified 2002-2013 by Guido Vollbeding.
* This file is part of the Independent JPEG Group's software. * This file is part of the Independent JPEG Group's software.
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
@ -34,20 +34,20 @@ extern "C" {
#endif #endif
/* Version IDs for the JPEG library. /* Version IDs for the JPEG library.
* Might be useful for tests like "#if JPEG_LIB_VERSION >= 80". * Might be useful for tests like "#if JPEG_LIB_VERSION >= 90".
*/ */
#define JPEG_LIB_VERSION 80 /* Compatibility version 8.0 */ #define JPEG_LIB_VERSION 90 /* Compatibility version 9.0 */
#define JPEG_LIB_VERSION_MAJOR 8 #define JPEG_LIB_VERSION_MAJOR 9
#define JPEG_LIB_VERSION_MINOR 3 #define JPEG_LIB_VERSION_MINOR 1
/* Various constants determining the sizes of things. /* Various constants determining the sizes of things.
* All of these are specified by the JPEG standard, so don't change them * All of these are specified by the JPEG standard,
* if you want to be compatible. * so don't change them if you want to be compatible.
*/ */
#define DCTSIZE 8 /* The basic DCT block is 8x8 samples */ #define DCTSIZE 8 /* The basic DCT block is 8x8 coefficients */
#define DCTSIZE2 64 /* DCTSIZE squared; # of elements in a block */ #define DCTSIZE2 64 /* DCTSIZE squared; # of elements in a block */
#define NUM_QUANT_TBLS 4 /* Quantization tables are numbered 0..3 */ #define NUM_QUANT_TBLS 4 /* Quantization tables are numbered 0..3 */
#define NUM_HUFF_TBLS 4 /* Huffman tables are numbered 0..3 */ #define NUM_HUFF_TBLS 4 /* Huffman tables are numbered 0..3 */
@ -157,16 +157,21 @@ typedef struct {
/* The downsampled dimensions are the component's actual, unpadded number /* The downsampled dimensions are the component's actual, unpadded number
* of samples at the main buffer (preprocessing/compression interface); * of samples at the main buffer (preprocessing/compression interface);
* DCT scaling is included, so * DCT scaling is included, so
* downsampled_width = ceil(image_width * Hi/Hmax * DCT_h_scaled_size/DCTSIZE) * downsampled_width =
* ceil(image_width * Hi/Hmax * DCT_h_scaled_size/block_size)
* and similarly for height. * and similarly for height.
*/ */
JDIMENSION downsampled_width; /* actual width in samples */ JDIMENSION downsampled_width; /* actual width in samples */
JDIMENSION downsampled_height; /* actual height in samples */ JDIMENSION downsampled_height; /* actual height in samples */
/* This flag is used only for decompression. In cases where some of the /* For decompression, in cases where some of the components will be
* components will be ignored (eg grayscale output from YCbCr image), * ignored (eg grayscale output from YCbCr image), we can skip most
* we can skip most computations for the unused components. * computations for the unused components.
* For compression, some of the components will need further quantization
* scale by factor of 2 after DCT (eg BG_YCC output from normal RGB input).
* The field is first set TRUE for decompression, FALSE for compression
* in initial_setup, and then adapted in color conversion setup.
*/ */
boolean component_needed; /* do we need the value of this component? */ boolean component_needed;
/* These values are computed before starting a scan of the component. */ /* These values are computed before starting a scan of the component. */
/* The decompressor output side may not use these variables. */ /* The decompressor output side may not use these variables. */
@ -215,12 +220,21 @@ struct jpeg_marker_struct {
typedef enum { typedef enum {
JCS_UNKNOWN, /* error/unspecified */ JCS_UNKNOWN, /* error/unspecified */
JCS_GRAYSCALE, /* monochrome */ JCS_GRAYSCALE, /* monochrome */
JCS_RGB, /* red/green/blue */ JCS_RGB, /* red/green/blue, standard RGB (sRGB) */
JCS_YCbCr, /* Y/Cb/Cr (also known as YUV) */ JCS_YCbCr, /* Y/Cb/Cr (also known as YUV), standard YCC */
JCS_CMYK, /* C/M/Y/K */ JCS_CMYK, /* C/M/Y/K */
JCS_YCCK /* Y/Cb/Cr/K */ JCS_YCCK, /* Y/Cb/Cr/K */
JCS_BG_RGB, /* big gamut red/green/blue, bg-sRGB */
JCS_BG_YCC /* big gamut Y/Cb/Cr, bg-sYCC */
} J_COLOR_SPACE; } J_COLOR_SPACE;
/* Supported color transforms. */
typedef enum {
JCT_NONE = 0,
JCT_SUBTRACT_GREEN = 1
} J_COLOR_TRANSFORM;
/* DCT/IDCT algorithm options. */ /* DCT/IDCT algorithm options. */
typedef enum { typedef enum {
@ -369,7 +383,10 @@ struct jpeg_compress_struct {
UINT16 X_density; /* Horizontal pixel density */ UINT16 X_density; /* Horizontal pixel density */
UINT16 Y_density; /* Vertical pixel density */ UINT16 Y_density; /* Vertical pixel density */
boolean write_Adobe_marker; /* should an Adobe marker be written? */ boolean write_Adobe_marker; /* should an Adobe marker be written? */
J_COLOR_TRANSFORM color_transform;
/* Color transform identifier, writes LSE marker if nonzero */
/* State variable: index of next scanline to be written to /* State variable: index of next scanline to be written to
* jpeg_write_scanlines(). Application may use this to control its * jpeg_write_scanlines(). Application may use this to control its
* processing loop, e.g., "while (next_scanline < image_height)". * processing loop, e.g., "while (next_scanline < image_height)".
@ -589,6 +606,9 @@ struct jpeg_decompress_struct {
boolean saw_Adobe_marker; /* TRUE iff an Adobe APP14 marker was found */ boolean saw_Adobe_marker; /* TRUE iff an Adobe APP14 marker was found */
UINT8 Adobe_transform; /* Color transform code from Adobe marker */ UINT8 Adobe_transform; /* Color transform code from Adobe marker */
J_COLOR_TRANSFORM color_transform;
/* Color transform identifier derived from LSE marker, otherwise zero */
boolean CCIR601_sampling; /* TRUE=first samples are cosited */ boolean CCIR601_sampling; /* TRUE=first samples are cosited */
/* Aside from the specific data retained from APPn markers known to the /* Aside from the specific data retained from APPn markers known to the
@ -681,7 +701,7 @@ struct jpeg_decompress_struct {
struct jpeg_error_mgr { struct jpeg_error_mgr {
/* Error exit handler: does not return to caller */ /* Error exit handler: does not return to caller */
JMETHOD(void, error_exit, (j_common_ptr cinfo)); JMETHOD(noreturn_t, error_exit, (j_common_ptr cinfo));
/* Conditionally emit a trace or warning message */ /* Conditionally emit a trace or warning message */
JMETHOD(void, emit_message, (j_common_ptr cinfo, int msg_level)); JMETHOD(void, emit_message, (j_common_ptr cinfo, int msg_level));
/* Routine that actually outputs a trace or error message */ /* Routine that actually outputs a trace or error message */

View File

@ -2,6 +2,7 @@
* jquant1.c * jquant1.c
* *
* Copyright (C) 1991-1996, Thomas G. Lane. * Copyright (C) 1991-1996, Thomas G. Lane.
* Modified 2011 by Guido Vollbeding.
* This file is part of the Independent JPEG Group's software. * This file is part of the Independent JPEG Group's software.
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
@ -530,8 +531,8 @@ quantize_ord_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
for (row = 0; row < num_rows; row++) { for (row = 0; row < num_rows; row++) {
/* Initialize output values to 0 so can process components separately */ /* Initialize output values to 0 so can process components separately */
jzero_far((void FAR *) output_buf[row], FMEMZERO((void FAR *) output_buf[row],
(size_t) (width * SIZEOF(JSAMPLE))); (size_t) (width * SIZEOF(JSAMPLE)));
row_index = cquantize->row_index; row_index = cquantize->row_index;
for (ci = 0; ci < nc; ci++) { for (ci = 0; ci < nc; ci++) {
input_ptr = input_buf[row] + ci; input_ptr = input_buf[row] + ci;
@ -635,8 +636,8 @@ quantize_fs_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
for (row = 0; row < num_rows; row++) { for (row = 0; row < num_rows; row++) {
/* Initialize output values to 0 so can process components separately */ /* Initialize output values to 0 so can process components separately */
jzero_far((void FAR *) output_buf[row], FMEMZERO((void FAR *) output_buf[row],
(size_t) (width * SIZEOF(JSAMPLE))); (size_t) (width * SIZEOF(JSAMPLE)));
for (ci = 0; ci < nc; ci++) { for (ci = 0; ci < nc; ci++) {
input_ptr = input_buf[row] + ci; input_ptr = input_buf[row] + ci;
output_ptr = output_buf[row]; output_ptr = output_buf[row];
@ -781,7 +782,7 @@ start_pass_1_quant (j_decompress_ptr cinfo, boolean is_pre_scan)
/* Initialize the propagated errors to zero. */ /* Initialize the propagated errors to zero. */
arraysize = (size_t) ((cinfo->output_width + 2) * SIZEOF(FSERROR)); arraysize = (size_t) ((cinfo->output_width + 2) * SIZEOF(FSERROR));
for (i = 0; i < cinfo->out_color_components; i++) for (i = 0; i < cinfo->out_color_components; i++)
jzero_far((void FAR *) cquantize->fserrors[i], arraysize); FMEMZERO((void FAR *) cquantize->fserrors[i], arraysize);
break; break;
default: default:
ERREXIT(cinfo, JERR_NOT_COMPILED); ERREXIT(cinfo, JERR_NOT_COMPILED);

View File

@ -2,6 +2,7 @@
* jquant2.c * jquant2.c
* *
* Copyright (C) 1991-1996, Thomas G. Lane. * Copyright (C) 1991-1996, Thomas G. Lane.
* Modified 2011 by Guido Vollbeding.
* This file is part of the Independent JPEG Group's software. * This file is part of the Independent JPEG Group's software.
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
@ -1203,7 +1204,7 @@ start_pass_2_quant (j_decompress_ptr cinfo, boolean is_pre_scan)
cquantize->fserrors = (FSERRPTR) (*cinfo->mem->alloc_large) cquantize->fserrors = (FSERRPTR) (*cinfo->mem->alloc_large)
((j_common_ptr) cinfo, JPOOL_IMAGE, arraysize); ((j_common_ptr) cinfo, JPOOL_IMAGE, arraysize);
/* Initialize the propagated errors to zero. */ /* Initialize the propagated errors to zero. */
jzero_far((void FAR *) cquantize->fserrors, arraysize); FMEMZERO((void FAR *) cquantize->fserrors, arraysize);
/* Make the error-limit table if we didn't already. */ /* Make the error-limit table if we didn't already. */
if (cquantize->error_limiter == NULL) if (cquantize->error_limiter == NULL)
init_error_limit(cinfo); init_error_limit(cinfo);
@ -1214,8 +1215,8 @@ start_pass_2_quant (j_decompress_ptr cinfo, boolean is_pre_scan)
/* Zero the histogram or inverse color map, if necessary */ /* Zero the histogram or inverse color map, if necessary */
if (cquantize->needs_zeroed) { if (cquantize->needs_zeroed) {
for (i = 0; i < HIST_C0_ELEMS; i++) { for (i = 0; i < HIST_C0_ELEMS; i++) {
jzero_far((void FAR *) histogram[i], FMEMZERO((void FAR *) histogram[i],
HIST_C1_ELEMS*HIST_C2_ELEMS * SIZEOF(histcell)); HIST_C1_ELEMS*HIST_C2_ELEMS * SIZEOF(histcell));
} }
cquantize->needs_zeroed = FALSE; cquantize->needs_zeroed = FALSE;
} }

View File

@ -2,7 +2,7 @@
* jutils.c * jutils.c
* *
* Copyright (C) 1991-1996, Thomas G. Lane. * Copyright (C) 1991-1996, Thomas G. Lane.
* Modified 2009 by Guido Vollbeding. * Modified 2009-2011 by Guido Vollbeding.
* This file is part of the Independent JPEG Group's software. * This file is part of the Independent JPEG Group's software.
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
@ -148,13 +148,27 @@ jround_up (long a, long b)
* is not all that great, because these routines aren't very heavily used.) * is not all that great, because these routines aren't very heavily used.)
*/ */
#ifndef NEED_FAR_POINTERS /* normal case, same as regular macros */ #ifndef NEED_FAR_POINTERS /* normal case, same as regular macro */
#define FMEMCOPY(dest,src,size) MEMCOPY(dest,src,size) #define FMEMCOPY(dest,src,size) MEMCOPY(dest,src,size)
#define FMEMZERO(target,size) MEMZERO(target,size)
#else /* 80x86 case, define if we can */ #else /* 80x86 case, define if we can */
#ifdef USE_FMEM #ifdef USE_FMEM
#define FMEMCOPY(dest,src,size) _fmemcpy((void FAR *)(dest), (const void FAR *)(src), (size_t)(size)) #define FMEMCOPY(dest,src,size) _fmemcpy((void FAR *)(dest), (const void FAR *)(src), (size_t)(size))
#define FMEMZERO(target,size) _fmemset((void FAR *)(target), 0, (size_t)(size)) #else
/* This function is for use by the FMEMZERO macro defined in jpegint.h.
* Do not call this function directly, use the FMEMZERO macro instead.
*/
GLOBAL(void)
jzero_far (void FAR * target, size_t bytestozero)
/* Zero out a chunk of FAR memory. */
/* This might be sample-array data, block-array data, or alloc_large data. */
{
register char FAR * ptr = (char FAR *) target;
register size_t count;
for (count = bytestozero; count > 0; count--) {
*ptr++ = 0;
}
}
#endif #endif
#endif #endif
@ -211,21 +225,3 @@ jcopy_block_row (JBLOCKROW input_row, JBLOCKROW output_row,
} }
#endif #endif
} }
GLOBAL(void)
jzero_far (void FAR * target, size_t bytestozero)
/* Zero out a chunk of FAR memory. */
/* This might be sample-array data, block-array data, or alloc_large data. */
{
#ifdef FMEMZERO
FMEMZERO(target, bytestozero);
#else
register char FAR * ptr = (char FAR *) target;
register size_t count;
for (count = bytestozero; count > 0; count--) {
*ptr++ = 0;
}
#endif
}

View File

@ -1,7 +1,7 @@
/* /*
* jversion.h * jversion.h
* *
* Copyright (C) 1991-2011, Thomas G. Lane, Guido Vollbeding. * Copyright (C) 1991-2014, Thomas G. Lane, Guido Vollbeding.
* This file is part of the Independent JPEG Group's software. * This file is part of the Independent JPEG Group's software.
* For conditions of distribution and use, see the accompanying README file. * For conditions of distribution and use, see the accompanying README file.
* *
@ -9,6 +9,6 @@
*/ */
#define JVERSION "8c 16-Jan-2011" #define JVERSION "9a 19-Jan-2014"
#define JCOPYRIGHT "Copyright (C) 2011, Thomas G. Lane, Guido Vollbeding" #define JCOPYRIGHT "Copyright (C) 2014, Thomas G. Lane, Guido Vollbeding"

View File

@ -1,6 +1,6 @@
USING THE IJG JPEG LIBRARY USING THE IJG JPEG LIBRARY
Copyright (C) 1994-2010, Thomas G. Lane, Guido Vollbeding. Copyright (C) 1994-2013, Thomas G. Lane, Guido Vollbeding.
This file is part of the Independent JPEG Group's software. This file is part of the Independent JPEG Group's software.
For conditions of distribution and use, see the accompanying README file. For conditions of distribution and use, see the accompanying README file.
@ -95,8 +95,8 @@ use.) Unsupported ISO options include:
* Lossless JPEG * Lossless JPEG
* DNL marker * DNL marker
* Nonintegral subsampling ratios * Nonintegral subsampling ratios
We support both 8- and 12-bit data precision, but this is a compile-time We support 8-bit to 12-bit data precision, but this is a compile-time choice
choice rather than a run-time choice; hence it is difficult to use both rather than a run-time choice; hence it is difficult to use different
precisions in a single application. precisions in a single application.
By itself, the library handles only interchange JPEG datastreams --- in By itself, the library handles only interchange JPEG datastreams --- in
@ -225,7 +225,7 @@ For best results, source data values should have the precision specified by
BITS_IN_JSAMPLE (normally 8 bits). For instance, if you choose to compress BITS_IN_JSAMPLE (normally 8 bits). For instance, if you choose to compress
data that's only 6 bits/channel, you should left-justify each value in a data that's only 6 bits/channel, you should left-justify each value in a
byte before passing it to the compressor. If you need to compress data byte before passing it to the compressor. If you need to compress data
that has more than 8 bits/channel, compile with BITS_IN_JSAMPLE = 12. that has more than 8 bits/channel, compile with BITS_IN_JSAMPLE = 9 to 12.
(See "Library compile-time options", later.) (See "Library compile-time options", later.)
@ -876,6 +876,10 @@ jpeg_simple_progression (j_compress_ptr cinfo)
Compression parameters (cinfo fields) include: Compression parameters (cinfo fields) include:
boolean arith_code
If TRUE, use arithmetic coding.
If FALSE, use Huffman coding.
int block_size int block_size
Set DCT block size. All N from 1 to 16 are possible. Set DCT block size. All N from 1 to 16 are possible.
Default is 8 (baseline format). Default is 8 (baseline format).
@ -916,7 +920,16 @@ J_COLOR_SPACE jpeg_color_space
int num_components int num_components
The JPEG color space and corresponding number of components; see The JPEG color space and corresponding number of components; see
"Special color spaces", below, for more info. We recommend using "Special color spaces", below, for more info. We recommend using
jpeg_set_color_space() if you want to change these. jpeg_set_colorspace() if you want to change these.
J_COLOR_TRANSFORM color_transform
Internal color transform identifier, writes LSE marker if nonzero
(requires decoder with inverse color transform support, introduced
with IJG JPEG 9).
Two values are currently possible: JCT_NONE and JCT_SUBTRACT_GREEN.
Set this value for lossless RGB application *before* calling
jpeg_set_colorspace(), because entropy table assignment in
jpeg_set_colorspace() depends on color_transform.
boolean optimize_coding boolean optimize_coding
TRUE causes the compressor to compute optimal Huffman coding tables TRUE causes the compressor to compute optimal Huffman coding tables
@ -1260,9 +1273,10 @@ Special color spaces
The JPEG standard itself is "color blind" and doesn't specify any particular The JPEG standard itself is "color blind" and doesn't specify any particular
color space. It is customary to convert color data to a luminance/chrominance color space. It is customary to convert color data to a luminance/chrominance
color space before compressing, since this permits greater compression. The color space before compressing, since this permits greater compression. The
existing de-facto JPEG file format standards specify YCbCr or grayscale data existing JPEG file interchange format standards specify YCbCr or GRAYSCALE
(JFIF), or grayscale, RGB, YCbCr, CMYK, or YCCK (Adobe). For special data (JFIF version 1), GRAYSCALE, RGB, YCbCr, CMYK, or YCCK (Adobe), or BG_RGB
applications such as multispectral images, other color spaces can be used, or BG_YCC (big gamut color spaces, JFIF version 2). For special applications
such as multispectral images, other color spaces can be used,
but it must be understood that such files will be unportable. but it must be understood that such files will be unportable.
The JPEG library can handle the most common colorspace conversions (namely The JPEG library can handle the most common colorspace conversions (namely
@ -1279,22 +1293,25 @@ jpeg_set_colorspace(). Of course you must select a supported transformation.
jccolor.c currently supports the following transformations: jccolor.c currently supports the following transformations:
RGB => YCbCr RGB => YCbCr
RGB => GRAYSCALE RGB => GRAYSCALE
RGB => BG_YCC
YCbCr => GRAYSCALE YCbCr => GRAYSCALE
YCbCr => BG_YCC
CMYK => YCCK CMYK => YCCK
plus the null transforms: GRAYSCALE => GRAYSCALE, RGB => RGB, plus the null transforms: GRAYSCALE => GRAYSCALE, RGB => RGB,
YCbCr => YCbCr, CMYK => CMYK, YCCK => YCCK, and UNKNOWN => UNKNOWN. BG_RGB => BG_RGB, YCbCr => YCbCr, BG_YCC => BG_YCC, CMYK => CMYK,
YCCK => YCCK, and UNKNOWN => UNKNOWN.
The de-facto file format standards (JFIF and Adobe) specify APPn markers that The file interchange format standards (JFIF and Adobe) specify APPn markers
indicate the color space of the JPEG file. It is important to ensure that that indicate the color space of the JPEG file. It is important to ensure
these are written correctly, or omitted if the JPEG file's color space is not that these are written correctly, or omitted if the JPEG file's color space
one of the ones supported by the de-facto standards. jpeg_set_colorspace() is not one of the ones supported by the interchange standards.
will set the compression parameters to include or omit the APPn markers jpeg_set_colorspace() will set the compression parameters to include or omit
properly, so long as it is told the truth about the JPEG color space. the APPn markers properly, so long as it is told the truth about the JPEG
For example, if you are writing some random 3-component color space without color space. For example, if you are writing some random 3-component color
conversion, don't try to fake out the library by setting in_color_space and space without conversion, don't try to fake out the library by setting
jpeg_color_space to JCS_YCbCr; use JCS_UNKNOWN. You may want to write an in_color_space and jpeg_color_space to JCS_YCbCr; use JCS_UNKNOWN.
APPn marker of your own devising to identify the colorspace --- see "Special You may want to write an APPn marker of your own devising to identify
markers", below. the colorspace --- see "Special markers", below.
When told that the color space is UNKNOWN, the library will default to using When told that the color space is UNKNOWN, the library will default to using
luminance-quality compression parameters for all color components. You may luminance-quality compression parameters for all color components. You may
@ -1310,8 +1327,11 @@ jpeg_read_header's guess by setting jpeg_color_space. jpeg_read_header also
selects a default output color space based on (its guess of) jpeg_color_space; selects a default output color space based on (its guess of) jpeg_color_space;
set out_color_space to override this. Again, you must select a supported set out_color_space to override this. Again, you must select a supported
transformation. jdcolor.c currently supports transformation. jdcolor.c currently supports
YCbCr => GRAYSCALE
YCbCr => RGB YCbCr => RGB
YCbCr => GRAYSCALE
BG_YCC => RGB
BG_YCC => GRAYSCALE
RGB => GRAYSCALE
GRAYSCALE => RGB GRAYSCALE => RGB
YCCK => CMYK YCCK => CMYK
as well as the null transforms. (Since GRAYSCALE=>RGB is provided, an as well as the null transforms. (Since GRAYSCALE=>RGB is provided, an
@ -2571,10 +2591,10 @@ different sizes. If the image dimensions are not a multiple of the MCU size,
you must also pad the data correctly (usually, this is done by replicating you must also pad the data correctly (usually, this is done by replicating
the last column and/or row). The data must be padded to a multiple of a DCT the last column and/or row). The data must be padded to a multiple of a DCT
block in each component: that is, each downsampled row must contain a block in each component: that is, each downsampled row must contain a
multiple of 8 valid samples, and there must be a multiple of 8 sample rows multiple of block_size valid samples, and there must be a multiple of
for each component. (For applications such as conversion of digital TV block_size sample rows for each component. (For applications such as
images, the standard image size is usually a multiple of the DCT block size, conversion of digital TV images, the standard image size is usually a
so that no padding need actually be done.) multiple of the DCT block size, so that no padding need actually be done.)
The procedure for compression of raw data is basically the same as normal The procedure for compression of raw data is basically the same as normal
compression, except that you call jpeg_write_raw_data() in place of compression, except that you call jpeg_write_raw_data() in place of
@ -2600,22 +2620,22 @@ The scanlines count passed to and returned from jpeg_write_raw_data is
measured in terms of the component with the largest v_samp_factor. measured in terms of the component with the largest v_samp_factor.
jpeg_write_raw_data() processes one MCU row per call, which is to say jpeg_write_raw_data() processes one MCU row per call, which is to say
v_samp_factor*DCTSIZE sample rows of each component. The passed num_lines v_samp_factor*block_size sample rows of each component. The passed num_lines
value must be at least max_v_samp_factor*DCTSIZE, and the return value will value must be at least max_v_samp_factor*block_size, and the return value
be exactly that amount (or possibly some multiple of that amount, in future will be exactly that amount (or possibly some multiple of that amount, in
library versions). This is true even on the last call at the bottom of the future library versions). This is true even on the last call at the bottom
image; don't forget to pad your data as necessary. of the image; don't forget to pad your data as necessary.
The required dimensions of the supplied data can be computed for each The required dimensions of the supplied data can be computed for each
component as component as
cinfo->comp_info[i].width_in_blocks*DCTSIZE samples per row cinfo->comp_info[i].width_in_blocks*block_size samples per row
cinfo->comp_info[i].height_in_blocks*DCTSIZE rows in image cinfo->comp_info[i].height_in_blocks*block_size rows in image
after jpeg_start_compress() has initialized those fields. If the valid data after jpeg_start_compress() has initialized those fields. If the valid data
is smaller than this, it must be padded appropriately. For some sampling is smaller than this, it must be padded appropriately. For some sampling
factors and image sizes, additional dummy DCT blocks are inserted to make factors and image sizes, additional dummy DCT blocks are inserted to make
the image a multiple of the MCU dimensions. The library creates such dummy the image a multiple of the MCU dimensions. The library creates such dummy
blocks itself; it does not read them from your supplied data. Therefore you blocks itself; it does not read them from your supplied data. Therefore you
need never pad by more than DCTSIZE samples. An example may help here. need never pad by more than block_size samples. An example may help here.
Assume 2h2v downsampling of YCbCr data, that is Assume 2h2v downsampling of YCbCr data, that is
cinfo->comp_info[0].h_samp_factor = 2 for Y cinfo->comp_info[0].h_samp_factor = 2 for Y
cinfo->comp_info[0].v_samp_factor = 2 cinfo->comp_info[0].v_samp_factor = 2
@ -2657,8 +2677,8 @@ Then call jpeg_read_raw_data() in place of jpeg_read_scanlines(). The
decompression process is otherwise the same as usual. decompression process is otherwise the same as usual.
jpeg_read_raw_data() returns one MCU row per call, and thus you must pass a jpeg_read_raw_data() returns one MCU row per call, and thus you must pass a
buffer of at least max_v_samp_factor*DCTSIZE scanlines (scanline counting is buffer of at least max_v_samp_factor*block_size scanlines (scanline counting
the same as for raw-data compression). The buffer you pass must be large is the same as for raw-data compression). The buffer you pass must be large
enough to hold the actual data plus padding to DCT-block boundaries. As with enough to hold the actual data plus padding to DCT-block boundaries. As with
compression, any entirely dummy DCT blocks are not processed so you need not compression, any entirely dummy DCT blocks are not processed so you need not
allocate space for them, but the total scanline count includes them. The allocate space for them, but the total scanline count includes them. The
@ -2914,10 +2934,10 @@ This does not count any memory allocated by the application, such as a
buffer to hold the final output image. buffer to hold the final output image.
The above figures are valid for 8-bit JPEG data precision and a machine with The above figures are valid for 8-bit JPEG data precision and a machine with
32-bit ints. For 12-bit JPEG data, double the size of the strip buffers and 32-bit ints. For 9-bit to 12-bit JPEG data, double the size of the strip
quantization pixel buffer. The "fixed-size" data will be somewhat smaller buffers and quantization pixel buffer. The "fixed-size" data will be
with 16-bit ints, larger with 64-bit ints. Also, CMYK or other unusual somewhat smaller with 16-bit ints, larger with 64-bit ints. Also, CMYK
color spaces will require different amounts of space. or other unusual color spaces will require different amounts of space.
The full-image coefficient and pixel buffers, if needed at all, do not The full-image coefficient and pixel buffers, if needed at all, do not
have to be fully RAM resident; you can have the library use temporary have to be fully RAM resident; you can have the library use temporary
@ -2939,27 +2959,34 @@ Library compile-time options
A number of compile-time options are available by modifying jmorecfg.h. A number of compile-time options are available by modifying jmorecfg.h.
The JPEG standard provides for both the baseline 8-bit DCT process and The IJG code currently supports 8-bit to 12-bit sample data precision by
a 12-bit DCT process. The IJG code supports 12-bit lossy JPEG if you define defining BITS_IN_JSAMPLE as 8, 9, 10, 11, or 12.
BITS_IN_JSAMPLE as 12 rather than 8. Note that this causes JSAMPLE to be Note that a value larger than 8 causes JSAMPLE to be larger than a char,
larger than a char, so it affects the surrounding application's image data. so it affects the surrounding application's image data.
The sample applications cjpeg and djpeg can support 12-bit mode only for PPM The sample applications cjpeg and djpeg can support deeper than 8-bit data
and GIF file formats; you must disable the other file formats to compile a only for PPM and GIF file formats; you must disable the other file formats
12-bit cjpeg or djpeg. (install.txt has more information about that.) to compile a 9-bit to 12-bit cjpeg or djpeg. (install.txt has more
At present, a 12-bit library can handle *only* 12-bit images, not both information about that.)
precisions. (If you need to include both 8- and 12-bit libraries in a single Run-time selection and conversion of data precision are currently not
application, you could probably do it by defining NEED_SHORT_EXTERNAL_NAMES supported and may be added later.
for just one of the copies. You'd have to access the 8-bit and 12-bit copies Exception: The transcoding part (jpegtran) supports all settings in a
from separate application source files. This is untested ... if you try it, single instance, since it operates on the level of DCT coefficients and
we'd like to hear whether it works!) not sample values.
(If you need to include an 8-bit library and a 9-bit to 12-bit library for
compression or decompression in a single application, you could probably do
it by defining NEED_SHORT_EXTERNAL_NAMES for just one of the copies. You'd
have to access the 8-bit and the 9-bit to 12-bit copies from separate
application source files. This is untested ... if you try it, we'd like to
hear whether it works!)
Note that a 12-bit library always compresses in Huffman optimization mode, Note that the standard Huffman tables are only valid for 8-bit data precision.
in order to generate valid Huffman tables. This is necessary because our If you selected more than 8-bit data precision, cjpeg uses arithmetic coding
default Huffman tables only cover 8-bit data. If you need to output 12-bit by default. The Huffman encoder normally uses entropy optimization to
files in one pass, you'll have to supply suitable default Huffman tables. compute usable tables for higher precision. Otherwise, you'll have to
You may also want to supply your own DCT quantization tables; the existing supply different default Huffman tables. You may also want to supply your
quality-scaling code has been developed for 8-bit use, and probably doesn't own DCT quantization tables; the existing quality-scaling code has been
generate especially good tables for 12-bit. developed for 8-bit use, and probably doesn't generate especially good tables
for 9-bit to 12-bit.
The maximum number of components (color channels) in the image is determined The maximum number of components (color channels) in the image is determined
by MAX_COMPONENTS. The JPEG standard allows up to 255 components, but we by MAX_COMPONENTS. The JPEG standard allows up to 255 components, but we

View File

@ -1,60 +0,0 @@
#
# "$Id$"
#
# JPEG library makefile for the Fast Light Toolkit (FLTK).
#
# Copyright 1997-2004 by Easy Software Products.
#
# This library is free software. Distribution and use rights are outlined in
# the file "COPYING" which should have been included with this file. If this
# file is missing or damaged, see the license at:
#
# http://www.fltk.org/COPYING.php
#
# Please report all bugs and problems on the following page:
#
# http://www.fltk.org/str.php
#
LIBNAMEROOT=ftlk_jpeg
!include ../watcom.mif
#
# Object files...
#
LIBOBJS = jmemnobs.obj &
jcapimin.obj jcapistd.obj jccoefct.obj jccolor.obj jcdctmgr.obj &
jchuff.obj jcinit.obj jcmainct.obj jcmarker.obj jcmaster.obj jcomapi.obj &
jcparam.obj jcphuff.obj jcprepct.obj jcsample.obj jctrans.obj &
jdapimin.obj jdapistd.obj jdatadst.obj jdatasrc.obj jdcoefct.obj &
jdcolor.obj jddctmgr.obj jdhuff.obj jdinput.obj jdmainct.obj jdmarker.obj &
jdmaster.obj jdmerge.obj jdphuff.obj jdpostct.obj jdsample.obj &
jdtrans.obj jerror.obj jfdctflt.obj jfdctfst.obj jfdctint.obj &
jidctflt.obj jidctfst.obj jidctint.obj jidctred.obj jquant1.obj &
jquant2.obj jutils.obj jmemmgr.obj
#
# Make all targets...
#
all: $(LIBNAME)
$(LIBNAME): $(LIBOBJS)
$(LIB) $(LIBOPTS) $@ $<
#
# Clean all directories
#
clean : .SYMBOLIC
@echo Cleaning up.
CLEANEXTS = obj
@for %a in ($(CLEANEXTS)) do -rm -f $(ODIR)\*.%a
-rm -f *.err
-rm -f $(LIBNAME)
#
# End of "$Id$".
#

View File

@ -1,6 +1,6 @@
IJG JPEG LIBRARY: SYSTEM ARCHITECTURE IJG JPEG LIBRARY: SYSTEM ARCHITECTURE
Copyright (C) 1991-2009, Thomas G. Lane, Guido Vollbeding. Copyright (C) 1991-2013, Thomas G. Lane, Guido Vollbeding.
This file is part of the Independent JPEG Group's software. This file is part of the Independent JPEG Group's software.
For conditions of distribution and use, see the accompanying README file. For conditions of distribution and use, see the accompanying README file.
@ -20,7 +20,7 @@ In this document, JPEG-specific terminology follows the JPEG standard:
A "component" means a color channel, e.g., Red or Luminance. A "component" means a color channel, e.g., Red or Luminance.
A "sample" is a single component value (i.e., one number in the image data). A "sample" is a single component value (i.e., one number in the image data).
A "coefficient" is a frequency coefficient (a DCT transform output number). A "coefficient" is a frequency coefficient (a DCT transform output number).
A "block" is an 8x8 group of samples or coefficients. A "block" is an array of samples or coefficients.
An "MCU" (minimum coded unit) is an interleaved set of blocks of size An "MCU" (minimum coded unit) is an interleaved set of blocks of size
determined by the sampling factors, or a single block in a determined by the sampling factors, or a single block in a
noninterleaved scan. noninterleaved scan.
@ -43,13 +43,8 @@ command-line user interface and I/O routines for several uncompressed image
formats. This document concentrates on the library itself. formats. This document concentrates on the library itself.
We desire the library to be capable of supporting all JPEG baseline, extended We desire the library to be capable of supporting all JPEG baseline, extended
sequential, and progressive DCT processes. Hierarchical processes are not sequential, and progressive DCT processes. The library does not support the
supported. hierarchical or lossless processes defined in the standard.
The library does not support the lossless (spatial) JPEG process. Lossless
JPEG shares little or no code with lossy JPEG, and would normally be used
without the extensive pre- and post-processing provided by this library.
We feel that lossless JPEG is better handled by a separate library.
Within these limits, any set of compression parameters allowed by the JPEG Within these limits, any set of compression parameters allowed by the JPEG
spec should be readable for decompression. (We can be more restrictive about spec should be readable for decompression. (We can be more restrictive about
@ -175,16 +170,16 @@ can be simplified a little if they work on padded data: it's not necessary to
have special cases at the right and bottom edges. Therefore the interface have special cases at the right and bottom edges. Therefore the interface
buffer is always an integral number of blocks wide and high, and we expect buffer is always an integral number of blocks wide and high, and we expect
compression preprocessing to pad the source data properly. Padding will occur compression preprocessing to pad the source data properly. Padding will occur
only to the next block (8-sample) boundary. In an interleaved-scan situation, only to the next block (block_size-sample) boundary. In an interleaved-scan
additional dummy blocks may be used to fill out MCUs, but the MCU assembly and situation, additional dummy blocks may be used to fill out MCUs, but the MCU
disassembly logic will create or discard these blocks internally. (This is assembly and disassembly logic will create or discard these blocks internally.
advantageous for speed reasons, since we avoid DCTing the dummy blocks. (This is advantageous for speed reasons, since we avoid DCTing the dummy
It also permits a small reduction in file size, because the compressor can blocks. It also permits a small reduction in file size, because the
choose dummy block contents so as to minimize their size in compressed form. compressor can choose dummy block contents so as to minimize their size
Finally, it makes the interface buffer specification independent of whether in compressed form. Finally, it makes the interface buffer specification
the file is actually interleaved or not.) Applications that wish to deal independent of whether the file is actually interleaved or not.)
directly with the downsampled data must provide similar buffering and padding Applications that wish to deal directly with the downsampled data must
for odd-sized images. provide similar buffering and padding for odd-sized images.
*** Poor man's object-oriented programming *** *** Poor man's object-oriented programming ***
@ -350,9 +345,10 @@ The objects shown above are:
require context rows above and below the current row group; the require context rows above and below the current row group; the
preprocessing controller is responsible for supplying these rows via proper preprocessing controller is responsible for supplying these rows via proper
buffering. The downsampler is responsible for edge expansion at the right buffering. The downsampler is responsible for edge expansion at the right
edge (i.e., extending each sample row to a multiple of 8 samples); but the edge (i.e., extending each sample row to a multiple of block_size samples);
preprocessing controller is responsible for vertical edge expansion (i.e., but the preprocessing controller is responsible for vertical edge expansion
duplicating the bottom sample row as needed to make a multiple of 8 rows). (i.e., duplicating the bottom sample row as needed to make a multiple of
block_size rows).
* Coefficient controller: buffer controller for the DCT-coefficient data. * Coefficient controller: buffer controller for the DCT-coefficient data.
This controller handles MCU assembly, including insertion of dummy DCT This controller handles MCU assembly, including insertion of dummy DCT
@ -385,8 +381,9 @@ objects:
* Data destination manager: writes the output JPEG datastream to its final * Data destination manager: writes the output JPEG datastream to its final
destination (e.g., a file). The destination manager supplied with the destination (e.g., a file). The destination manager supplied with the
library knows how to write to a stdio stream; for other behaviors, the library knows how to write to a stdio stream or to a memory buffer;
surrounding application may provide its own destination manager. for other behaviors, the surrounding application may provide its own
destination manager.
* Memory manager: allocates and releases memory, controls virtual arrays * Memory manager: allocates and releases memory, controls virtual arrays
(with backing store management, where required). (with backing store management, where required).
@ -504,9 +501,9 @@ objects:
* Marker reading: decodes JPEG markers (except for RSTn). * Marker reading: decodes JPEG markers (except for RSTn).
* Data source manager: supplies the input JPEG datastream. The source * Data source manager: supplies the input JPEG datastream. The source
manager supplied with the library knows how to read from a stdio stream; manager supplied with the library knows how to read from a stdio stream
for other behaviors, the surrounding application may provide its own source or from a memory buffer; for other behaviors, the surrounding application
manager. may provide its own source manager.
* Memory manager: same as for compression library. * Memory manager: same as for compression library.
@ -654,9 +651,9 @@ contain quantized coefficients everywhere outside the DCT/IDCT subsystems.
(This latter decision may need to be revisited to support variable (This latter decision may need to be revisited to support variable
quantization a la JPEG Part 3.) quantization a la JPEG Part 3.)
Notice that the allocation unit is now a row of 8x8 blocks, corresponding to Notice that the allocation unit is now a row of 8x8 coefficient blocks,
eight rows of samples. Otherwise the structure is much the same as for corresponding to block_size rows of samples. Otherwise the structure
samples, and for the same reasons. is much the same as for samples, and for the same reasons.
On machines where malloc() can't handle a request bigger than 64Kb, this data On machines where malloc() can't handle a request bigger than 64Kb, this data
structure limits us to rows of less than 512 JBLOCKs, or a picture width of structure limits us to rows of less than 512 JBLOCKs, or a picture width of

View File

@ -77,6 +77,13 @@ The basic command line switches for cjpeg are:
saying -grayscale, you'll get a smaller JPEG file that saying -grayscale, you'll get a smaller JPEG file that
takes less time to process. takes less time to process.
-rgb Create RGB JPEG file.
Using this switch suppresses the conversion from RGB
colorspace input to the default YCbCr JPEG colorspace.
You can use this switch in combination with the
-block N switch (see below) for lossless JPEG coding.
See also the -rgb1 switch below.
-optimize Perform optimization of entropy encoding parameters. -optimize Perform optimization of entropy encoding parameters.
Without this, default encoding parameters are used. Without this, default encoding parameters are used.
-optimize usually makes the JPEG file a little smaller, -optimize usually makes the JPEG file a little smaller,
@ -151,6 +158,11 @@ file size is about the same --- often a little smaller.
Switches for advanced users: Switches for advanced users:
-arithmetic Use arithmetic coding.
CAUTION: arithmetic coded JPEG is not yet widely
implemented, so many decoders will be unable to
view an arithmetic coded JPEG file at all.
-block N Set DCT block size. All N from 1 to 16 are possible. -block N Set DCT block size. All N from 1 to 16 are possible.
Default is 8 (baseline format). Default is 8 (baseline format).
Larger values produce higher compression, Larger values produce higher compression,
@ -164,6 +176,37 @@ Switches for advanced users:
decoders will be unable to view a SmartScale extended decoders will be unable to view a SmartScale extended
JPEG file at all. JPEG file at all.
-rgb1 Create RGB JPEG file with reversible color transform.
Works like the -rgb switch (see above) and inserts a
simple reversible color transform into the processing
which significantly improves the compression.
Use this switch in combination with the -block N
switch (see above) for lossless JPEG coding.
CAUTION: A decoder with inverse color transform
support is required for this feature. Reversible
color transform support is not yet widely implemented,
so many decoders will be unable to view a reversible
color transformed JPEG file at all.
-bgycc Create big gamut YCC JPEG file.
In this type of encoding the color difference
components are quantized further by a factor of 2
compared to the normal Cb/Cr values, thus creating
space to allow larger color values with higher
saturation than the normal gamut limits to be encoded.
In order to compensate for the loss of color fidelity
compared to a normal YCC encoded file, the color
quantization tables can be adjusted accordingly.
For example, cjpeg -bgycc -quality 80,90 will give
similar results as cjpeg -quality 80.
CAUTION: For correct decompression a decoder with big
gamut YCC support (JFIF version 2) is required.
An old decoder may or may not display a big gamut YCC
encoded JPEG file, depending on JFIF version check
and corresponding warning/error configuration.
In case of a granted decompression the old decoder
will display the image with half saturated colors.
-dct int Use integer DCT method (default). -dct int Use integer DCT method (default).
-dct fast Use fast integer DCT (less accurate). -dct fast Use fast integer DCT (less accurate).
-dct float Use floating-point DCT method. -dct float Use floating-point DCT method.
@ -210,11 +253,6 @@ factor will visibly blur the image, however.
Switches for wizards: Switches for wizards:
-arithmetic Use arithmetic coding. CAUTION: arithmetic coded JPEG
is not yet widely implemented, so many decoders will
be unable to view an arithmetic coded JPEG file at
all.
-baseline Force baseline-compatible quantization tables to be -baseline Force baseline-compatible quantization tables to be
generated. This clamps quantization values to 8 bits generated. This clamps quantization values to 8 bits
even at low quality settings. (This switch is poorly even at low quality settings. (This switch is poorly
@ -368,7 +406,8 @@ quality settings to make very small JPEG files; the percentage improvement
is often a lot more than it is on larger files. (At present, -optimize is often a lot more than it is on larger files. (At present, -optimize
mode is always selected when generating progressive JPEG files.) mode is always selected when generating progressive JPEG files.)
GIF input files are no longer supported, to avoid the Unisys LZW patent. GIF input files are no longer supported, to avoid the Unisys LZW patent
(now expired).
(Conversion of GIF files to JPEG is usually a bad idea anyway.) (Conversion of GIF files to JPEG is usually a bad idea anyway.)
@ -396,8 +435,9 @@ it may run out of memory even with -maxmemory 0. In that case you can still
decompress, with some loss of image quality, by specifying -onepass for decompress, with some loss of image quality, by specifying -onepass for
one-pass quantization. one-pass quantization.
To avoid the Unisys LZW patent, djpeg produces uncompressed GIF files. These To avoid the Unisys LZW patent (now expired), djpeg produces uncompressed GIF
are larger than they should be, but are readable by standard GIF decoders. files. These are larger than they should be, but are readable by standard GIF
decoders.
HINTS FOR BOTH PROGRAMS HINTS FOR BOTH PROGRAMS
@ -459,9 +499,9 @@ To specify the coded JPEG representation used in the output file,
jpegtran accepts a subset of the switches recognized by cjpeg: jpegtran accepts a subset of the switches recognized by cjpeg:
-optimize Perform optimization of entropy encoding parameters. -optimize Perform optimization of entropy encoding parameters.
-progressive Create progressive JPEG file. -progressive Create progressive JPEG file.
-arithmetic Use arithmetic coding.
-restart N Emit a JPEG restart marker every N MCU rows, or every -restart N Emit a JPEG restart marker every N MCU rows, or every
N MCU blocks if "B" is attached to the number. N MCU blocks if "B" is attached to the number.
-arithmetic Use arithmetic coding.
-scans file Use the scan script given in the specified text file. -scans file Use the scan script given in the specified text file.
See the previous discussion of cjpeg for more details about these switches. See the previous discussion of cjpeg for more details about these switches.
If you specify none of these switches, you get a plain baseline-JPEG output If you specify none of these switches, you get a plain baseline-JPEG output
@ -514,14 +554,20 @@ image region but losslessly preserves what is inside. Like the rotate and
flip transforms, lossless crop is restricted by the current JPEG format: the flip transforms, lossless crop is restricted by the current JPEG format: the
upper left corner of the selected region must fall on an iMCU boundary. If 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 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 left corner up and/or left to make it so, simultaneously increasing the
dimensions to keep the lower right crop corner unchanged. (Thus, the output region dimensions to keep the lower right crop corner unchanged. (Thus, the
image covers at least the requested region, but may cover more.) output image covers at least the requested region, but may cover more.)
The adjustment of the region dimensions may be optionally disabled.
The image can be losslessly cropped by giving the switch: The image can be losslessly cropped by giving the switch:
-crop WxH+X+Y Crop to a rectangular subarea of width W, height H -crop WxH+X+Y Crop to a rectangular subarea of width W, height H
starting at point X,Y. starting at point X,Y.
A complementary lossless-wipe option is provided to discard (gray out) data
inside a given image region while losslessly preserving what is outside:
-wipe WxH+X+Y Wipe (gray out) a rectangular subarea of
width W, height H starting at point X,Y.
Other not-strictly-lossless transformation switches are: Other not-strictly-lossless transformation switches are:
-grayscale Force grayscale output. -grayscale Force grayscale output.