mirror of
https://github.com/opencv/opencv.git
synced 2024-11-27 20:50:25 +08:00
Update libjpeg to "Version 9 13-Jan-2013"
This commit is contained in:
parent
084b1c7969
commit
9e3570260b
7
3rdparty/libjpeg/CMakeLists.txt
vendored
7
3rdparty/libjpeg/CMakeLists.txt
vendored
@ -9,6 +9,12 @@ ocv_include_directories(${CMAKE_CURRENT_SOURCE_DIR})
|
||||
file(GLOB lib_srcs *.c)
|
||||
file(GLOB lib_hdrs *.h)
|
||||
|
||||
if(ANDROID OR IOS)
|
||||
ocv_list_filterout(lib_srcs jmemansi.c)
|
||||
else()
|
||||
ocv_list_filterout(lib_srcs jmemnobs.c)
|
||||
endif()
|
||||
|
||||
# ----------------------------------------------------------------------------------
|
||||
# Define the library target:
|
||||
# ----------------------------------------------------------------------------------
|
||||
@ -27,6 +33,7 @@ endif()
|
||||
|
||||
ocv_warnings_disable(CMAKE_C_FLAGS -Wcast-align -Wshadow -Wunused)
|
||||
ocv_warnings_disable(CMAKE_C_FLAGS -Wunused-parameter) # clang
|
||||
ocv_warnings_disable(CMAKE_C_FLAGS /wd4013 /wd4244 /wd4267) # vs2005
|
||||
|
||||
set_target_properties(${JPEG_LIBRARY}
|
||||
PROPERTIES OUTPUT_NAME ${JPEG_LIBRARY}
|
||||
|
321
3rdparty/libjpeg/README
vendored
321
3rdparty/libjpeg/README
vendored
@ -1,24 +1,20 @@
|
||||
The Independent JPEG Group's JPEG software
|
||||
==========================================
|
||||
|
||||
README for release 6b of 27-Mar-1998
|
||||
====================================
|
||||
README for release 9 of 13-Jan-2013
|
||||
===================================
|
||||
|
||||
This distribution contains the sixth 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
|
||||
to use it for any purpose, subject to the conditions under LEGAL ISSUES, below.
|
||||
|
||||
Serious users of this software (particularly those incorporating it into
|
||||
larger programs) should contact IJG at jpeg-info@uunet.uu.net to be added to
|
||||
our electronic mailing list. Mailing list members are notified of updates
|
||||
and have a chance to participate in technical discussions, etc.
|
||||
This software is the work of Tom Lane, Guido Vollbeding, Philip Gladstone,
|
||||
Bill Allombert, Jim Boucher, Lee Crocker, Bob Friesenhahn, Ben Jackson,
|
||||
Julian Minguillon, Luis Ortiz, George Phillips, Davide Rossi, Ge' Weijers,
|
||||
and other members of the Independent JPEG Group.
|
||||
|
||||
This software is the work of Tom Lane, Philip Gladstone, Jim Boucher,
|
||||
Lee Crocker, Julian Minguillon, Luis Ortiz, George Phillips, Davide Rossi,
|
||||
Guido Vollbeding, Ge' Weijers, and other members of the Independent JPEG
|
||||
Group.
|
||||
|
||||
IJG is not affiliated with the official ISO JPEG standards committee.
|
||||
IJG is not affiliated with the ISO/IEC JTC1/SC29/WG1 standards committee
|
||||
(also known as JPEG, together with ITU-T SG16).
|
||||
|
||||
|
||||
DOCUMENTATION ROADMAP
|
||||
@ -30,27 +26,27 @@ OVERVIEW General description of JPEG and the IJG software.
|
||||
LEGAL ISSUES Copyright, lack of warranty, terms of distribution.
|
||||
REFERENCES Where to learn more about JPEG.
|
||||
ARCHIVE LOCATIONS Where to find newer versions of this software.
|
||||
RELATED SOFTWARE Other stuff you should get.
|
||||
ACKNOWLEDGMENTS Special thanks.
|
||||
FILE FORMAT WARS Software *not* to get.
|
||||
TO DO Plans for future IJG releases.
|
||||
|
||||
Other documentation files in the distribution are:
|
||||
|
||||
User documentation:
|
||||
install.doc How to configure and install the IJG software.
|
||||
usage.doc Usage instructions for cjpeg, djpeg, jpegtran,
|
||||
install.txt How to configure and install the IJG software.
|
||||
usage.txt Usage instructions for cjpeg, djpeg, jpegtran,
|
||||
rdjpgcom, and wrjpgcom.
|
||||
*.1 Unix-style man pages for programs (same info as usage.doc).
|
||||
wizard.doc Advanced usage instructions for JPEG wizards only.
|
||||
*.1 Unix-style man pages for programs (same info as usage.txt).
|
||||
wizard.txt Advanced usage instructions for JPEG wizards only.
|
||||
change.log Version-to-version change highlights.
|
||||
Programmer and internal documentation:
|
||||
libjpeg.doc How to use the JPEG library in your own programs.
|
||||
libjpeg.txt How to use the JPEG library in your own programs.
|
||||
example.c Sample code for calling the JPEG library.
|
||||
structure.doc Overview of the JPEG library's internal structure.
|
||||
filelist.doc Road map of IJG files.
|
||||
coderules.doc Coding style rules --- please read if you contribute code.
|
||||
structure.txt Overview of the JPEG library's internal structure.
|
||||
filelist.txt Road map of IJG files.
|
||||
coderules.txt Coding style rules --- please read if you contribute code.
|
||||
|
||||
Please read at least the files install.doc and usage.doc. Useful information
|
||||
Please read at least the files install.txt and usage.txt. Some information
|
||||
can also be found in the JPEG FAQ (Frequently Asked Questions) article. See
|
||||
ARCHIVE LOCATIONS below to find out where to obtain the FAQ article.
|
||||
|
||||
@ -62,24 +58,15 @@ the order listed) before diving into the code.
|
||||
OVERVIEW
|
||||
========
|
||||
|
||||
This package contains C software to implement JPEG image compression and
|
||||
decompression. JPEG (pronounced "jay-peg") is a standardized compression
|
||||
method for full-color and gray-scale images. JPEG is intended for compressing
|
||||
"real-world" scenes; line drawings, cartoons and other non-realistic images
|
||||
are not its strong suit. JPEG is lossy, meaning that the output image is not
|
||||
exactly identical to the input image. Hence you must not use JPEG if you
|
||||
have to have identical output bits. However, on typical photographic images,
|
||||
very good compression levels can be obtained with no visible change, and
|
||||
remarkably high compression levels are possible if you can tolerate a
|
||||
low-quality image. For more details, see the references, or just experiment
|
||||
with various compression settings.
|
||||
This package contains C software to implement JPEG image encoding, decoding,
|
||||
and transcoding. JPEG (pronounced "jay-peg") is a standardized compression
|
||||
method for full-color and gray-scale images.
|
||||
|
||||
This software implements JPEG baseline, extended-sequential, and progressive
|
||||
compression processes. Provision is made for supporting all variants of these
|
||||
processes, although some uncommon parameter settings aren't implemented yet.
|
||||
For legal reasons, we are not distributing code for the arithmetic-coding
|
||||
variants of JPEG; see LEGAL ISSUES. We have made no provision for supporting
|
||||
the hierarchical or lossless processes defined in the standard.
|
||||
We have made no provision for supporting the hierarchical or lossless
|
||||
processes defined in the standard.
|
||||
|
||||
We provide a set of library routines for reading and writing JPEG image files,
|
||||
plus two sample applications "cjpeg" and "djpeg", which use the library to
|
||||
@ -91,10 +78,11 @@ considerable functionality beyond the bare JPEG coding/decoding capability;
|
||||
for example, the color quantization modules are not strictly part of JPEG
|
||||
decoding, but they are essential for output to colormapped file formats or
|
||||
colormapped displays. These extra functions can be compiled out of the
|
||||
library if not required for a particular application. We have also included
|
||||
"jpegtran", a utility for lossless transcoding between different JPEG
|
||||
processes, and "rdjpgcom" and "wrjpgcom", two simple applications for
|
||||
inserting and extracting textual comments in JFIF files.
|
||||
library if not required for a particular application.
|
||||
|
||||
We have also included "jpegtran", a utility for lossless transcoding between
|
||||
different JPEG processes, and "rdjpgcom" and "wrjpgcom", two simple
|
||||
applications for inserting and extracting textual comments in JFIF files.
|
||||
|
||||
The emphasis in designing this software has been on achieving portability and
|
||||
flexibility, while also making it fast enough to be useful. In particular,
|
||||
@ -127,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,
|
||||
its user, assume the entire risk as to its quality and accuracy.
|
||||
|
||||
This software is copyright (C) 1991-1998, Thomas G. Lane.
|
||||
This software is copyright (C) 1991-2013, Thomas G. Lane, Guido Vollbeding.
|
||||
All Rights Reserved except as specified below.
|
||||
|
||||
Permission is hereby granted to use, copy, modify, and distribute this
|
||||
@ -158,29 +146,11 @@ commercial products, provided that all warranty or liability claims are
|
||||
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.
|
||||
It is copyright by the Free Software Foundation but is freely distributable.
|
||||
The same holds for its supporting scripts (config.guess, config.sub,
|
||||
ltconfig, ltmain.sh). Another support script, install-sh, is copyright
|
||||
by M.I.T. but is also freely distributable.
|
||||
|
||||
It appears that the arithmetic coding option of the JPEG spec is covered by
|
||||
patents owned by IBM, AT&T, and Mitsubishi. Hence arithmetic coding cannot
|
||||
legally be used without obtaining one or more licenses. For this reason,
|
||||
support for arithmetic coding has been removed from the free JPEG software.
|
||||
(Since arithmetic coding provides only a marginal gain over the unpatented
|
||||
Huffman mode, it is unlikely that very many implementations will support it.)
|
||||
So far as we are aware, there are no patent restrictions on the remaining
|
||||
code.
|
||||
ltmain.sh). Another support script, install-sh, is copyright by X Consortium
|
||||
but is also freely distributable.
|
||||
|
||||
The IJG distribution formerly included code to read and write GIF files.
|
||||
To avoid entanglement with the Unisys LZW patent, GIF reading support has
|
||||
@ -198,7 +168,7 @@ We are required to state that
|
||||
REFERENCES
|
||||
==========
|
||||
|
||||
We highly recommend reading one or more of these references before trying to
|
||||
We recommend reading one or more of these references before trying to
|
||||
understand the innards of the JPEG software.
|
||||
|
||||
The best short technical introduction to the JPEG compression algorithm is
|
||||
@ -207,7 +177,7 @@ The best short technical introduction to the JPEG compression algorithm is
|
||||
(Adjacent articles in that issue discuss MPEG motion picture compression,
|
||||
applications of JPEG, and related topics.) If you don't have the CACM issue
|
||||
handy, a PostScript file containing a revised version of Wallace's article is
|
||||
available at ftp://ftp.uu.net/graphics/jpeg/wallace.ps.gz. The file (actually
|
||||
available at http://www.ijg.org/files/wallace.ps.gz. The file (actually
|
||||
a preprint for an article that appeared in IEEE Trans. Consumer Electronics)
|
||||
omits the sample images that appeared in CACM, but it includes corrections
|
||||
and some added material. Note: the Wallace article is copyright ACM and IEEE,
|
||||
@ -222,82 +192,71 @@ code but don't know much about data compression in general. The book's JPEG
|
||||
sample code is far from industrial-strength, but when you are ready to look
|
||||
at a full implementation, you've got one here...
|
||||
|
||||
The best full description of JPEG is the textbook "JPEG Still Image Data
|
||||
Compression Standard" by William B. Pennebaker and Joan L. Mitchell, published
|
||||
by Van Nostrand Reinhold, 1993, ISBN 0-442-01272-1. Price US$59.95, 638 pp.
|
||||
The book includes the complete text of the ISO JPEG standards (DIS 10918-1
|
||||
and draft DIS 10918-2). This is by far the most complete exposition of JPEG
|
||||
in existence, and we highly recommend it.
|
||||
The best currently available description of JPEG is the textbook "JPEG Still
|
||||
Image Data Compression Standard" by William B. Pennebaker and Joan L.
|
||||
Mitchell, published by Van Nostrand Reinhold, 1993, ISBN 0-442-01272-1.
|
||||
Price US$59.95, 638 pp. The book includes the complete text of the ISO JPEG
|
||||
standards (DIS 10918-1 and draft DIS 10918-2).
|
||||
Although this is by far the most detailed and comprehensive exposition of
|
||||
JPEG publicly available, we point out that it is still missing an explanation
|
||||
of the most essential properties and algorithms of the underlying DCT
|
||||
technology.
|
||||
If you think that you know about DCT-based JPEG after reading this book,
|
||||
then you are in delusion. The real fundamentals and corresponding potential
|
||||
of DCT-based JPEG are not publicly known so far, and that is the reason for
|
||||
all the mistaken developments taking place in the image coding domain.
|
||||
|
||||
The JPEG standard itself is not available electronically; you must order a
|
||||
paper copy through ISO or ITU. (Unless you feel a need to own a certified
|
||||
official copy, we recommend buying the Pennebaker and Mitchell book instead;
|
||||
it's much cheaper and includes a great deal of useful explanatory material.)
|
||||
In the USA, copies of the standard may be ordered from ANSI Sales at (212)
|
||||
642-4900, or from Global Engineering Documents at (800) 854-7179. (ANSI
|
||||
doesn't take credit card orders, but Global does.) It's not cheap: as of
|
||||
1992, ANSI was charging $95 for Part 1 and $47 for Part 2, plus 7%
|
||||
shipping/handling. The standard is divided into two parts, Part 1 being the
|
||||
actual specification, while Part 2 covers compliance testing methods. Part 1
|
||||
is titled "Digital Compression and Coding of Continuous-tone Still Images,
|
||||
The original JPEG standard is divided into two parts, Part 1 being the actual
|
||||
specification, while Part 2 covers compliance testing methods. Part 1 is
|
||||
titled "Digital Compression and Coding of Continuous-tone Still Images,
|
||||
Part 1: Requirements and guidelines" and has document numbers ISO/IEC IS
|
||||
10918-1, ITU-T T.81. Part 2 is titled "Digital Compression and Coding of
|
||||
Continuous-tone Still Images, Part 2: Compliance testing" and has document
|
||||
numbers ISO/IEC IS 10918-2, ITU-T T.83.
|
||||
|
||||
Some extensions to the original JPEG standard are defined in JPEG Part 3,
|
||||
a newer ISO standard numbered ISO/IEC IS 10918-3 and ITU-T T.84. IJG
|
||||
currently does not support any Part 3 extensions.
|
||||
IJG JPEG 8 introduced an implementation of the JPEG SmartScale extension
|
||||
which is specified in two documents: A contributed document at ITU and ISO
|
||||
with title "ITU-T JPEG-Plus Proposal for Extending ITU-T T.81 for Advanced
|
||||
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
|
||||
format. For the omitted details we follow the "JFIF" conventions, revision
|
||||
1.02. A copy of the JFIF spec is available from:
|
||||
Literature Department
|
||||
C-Cube Microsystems, Inc.
|
||||
1778 McCarthy Blvd.
|
||||
Milpitas, CA 95035
|
||||
phone (408) 944-6300, fax (408) 944-6314
|
||||
A PostScript version of this document is available by FTP at
|
||||
ftp://ftp.uu.net/graphics/jpeg/jfif.ps.gz. There is also a plain text
|
||||
version at ftp://ftp.uu.net/graphics/jpeg/jfif.txt.gz, but it is missing
|
||||
the figures.
|
||||
1.02. JFIF 1.02 has been adopted as an Ecma International Technical Report
|
||||
and thus received a formal publication status. It is available as a free
|
||||
download in PDF format from
|
||||
http://www.ecma-international.org/publications/techreports/E-TR-098.htm.
|
||||
A PostScript version of the JFIF document is available at
|
||||
http://www.ijg.org/files/jfif.ps.gz. There is also a plain text version at
|
||||
http://www.ijg.org/files/jfif.txt.gz, but it is missing the figures.
|
||||
|
||||
The TIFF 6.0 file format specification can be obtained by FTP from
|
||||
ftp://ftp.sgi.com/graphics/tiff/TIFF6.ps.gz. The JPEG incorporation scheme
|
||||
found in the TIFF 6.0 spec of 3-June-92 has a number of serious problems.
|
||||
IJG does not recommend use of the TIFF 6.0 design (TIFF Compression tag 6).
|
||||
Instead, we recommend the JPEG design proposed by TIFF Technical Note #2
|
||||
(Compression tag 7). Copies of this Note can be obtained from ftp.sgi.com or
|
||||
from ftp://ftp.uu.net/graphics/jpeg/. It is expected that the next revision
|
||||
(Compression tag 7). Copies of this Note can be obtained from
|
||||
http://www.ijg.org/files/. It is expected that the next revision
|
||||
of the TIFF spec will replace the 6.0 JPEG design with the Note's design.
|
||||
Although IJG's own code does not support TIFF/JPEG, the free libtiff library
|
||||
uses our library to implement TIFF/JPEG per the Note. libtiff is available
|
||||
from ftp://ftp.sgi.com/graphics/tiff/.
|
||||
uses our library to implement TIFF/JPEG per the Note.
|
||||
|
||||
|
||||
ARCHIVE LOCATIONS
|
||||
=================
|
||||
|
||||
The "official" archive site for this software is ftp.uu.net (Internet
|
||||
address 192.48.96.9). The most recent released version can always be found
|
||||
there in directory graphics/jpeg. This particular version will be archived
|
||||
as ftp://ftp.uu.net/graphics/jpeg/jpegsrc.v6b.tar.gz. If you don't have
|
||||
direct Internet access, UUNET's archives are also available via UUCP; contact
|
||||
help@uunet.uu.net for information on retrieving files that way.
|
||||
The "official" archive site for this software is www.ijg.org.
|
||||
The most recent released version can always be found there in
|
||||
directory "files". This particular version will be archived as
|
||||
http://www.ijg.org/files/jpegsrc.v9.tar.gz, and in Windows-compatible
|
||||
"zip" archive format as http://www.ijg.org/files/jpegsr9.zip.
|
||||
|
||||
Numerous Internet sites maintain copies of the UUNET files. However, only
|
||||
ftp.uu.net is guaranteed to have the latest official version.
|
||||
|
||||
You can also obtain this software in DOS-compatible "zip" archive format from
|
||||
the SimTel archives (ftp://ftp.simtel.net/pub/simtelnet/msdos/graphics/), or
|
||||
on CompuServe in the Graphics Support forum (GO CIS:GRAPHSUP), library 12
|
||||
"JPEG Tools". Again, these versions may sometimes lag behind the ftp.uu.net
|
||||
release.
|
||||
|
||||
The JPEG FAQ (Frequently Asked Questions) article is a useful source of
|
||||
general information about JPEG. It is updated constantly and therefore is
|
||||
not included in this distribution. The FAQ is posted every two weeks to
|
||||
Usenet newsgroups comp.graphics.misc, news.answers, and other groups.
|
||||
The JPEG FAQ (Frequently Asked Questions) article is a source of some
|
||||
general information about JPEG.
|
||||
It is available on the World Wide Web at http://www.faqs.org/faqs/jpeg-faq/
|
||||
and other news.answers archive sites, including the official news.answers
|
||||
archive at rtfm.mit.edu: ftp://rtfm.mit.edu/pub/usenet/news.answers/jpeg-faq/.
|
||||
@ -307,79 +266,85 @@ with body
|
||||
send usenet/news.answers/jpeg-faq/part2
|
||||
|
||||
|
||||
RELATED SOFTWARE
|
||||
================
|
||||
ACKNOWLEDGMENTS
|
||||
===============
|
||||
|
||||
Numerous viewing and image manipulation programs now support JPEG. (Quite a
|
||||
few of them use this library to do so.) The JPEG FAQ described above lists
|
||||
some of the more popular free and shareware viewers, and tells where to
|
||||
obtain them on Internet.
|
||||
Thank to Juergen Bruder for providing me with a copy of the common DCT
|
||||
algorithm article, only to find out that I had come to the same result
|
||||
in a more direct and comprehensible way with a more generative approach.
|
||||
|
||||
If you are on a Unix machine, we highly recommend Jef Poskanzer's free
|
||||
PBMPLUS software, which provides many useful operations on PPM-format image
|
||||
files. In particular, it can convert PPM images to and from a wide range of
|
||||
other formats, thus making cjpeg/djpeg considerably more useful. The latest
|
||||
version is distributed by the NetPBM group, and is available from numerous
|
||||
sites, notably ftp://wuarchive.wustl.edu/graphics/graphics/packages/NetPBM/.
|
||||
Unfortunately PBMPLUS/NETPBM is not nearly as portable as the IJG software is;
|
||||
you are likely to have difficulty making it work on any non-Unix machine.
|
||||
Thank to Istvan Sebestyen and Joan L. Mitchell for inviting me to the
|
||||
ITU JPEG (Study Group 16) meeting in Geneva, Switzerland.
|
||||
|
||||
A different free JPEG implementation, written by the PVRG group at Stanford,
|
||||
is available from ftp://havefun.stanford.edu/pub/jpeg/. This program
|
||||
is designed for research and experimentation rather than production use;
|
||||
it is slower, harder to use, and less portable than the IJG code, but it
|
||||
is easier to read and modify. Also, the PVRG code supports lossless JPEG,
|
||||
which we do not. (On the other hand, it doesn't do progressive JPEG.)
|
||||
Thank to Thomas Wiegand and Gary Sullivan for inviting me to the
|
||||
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 (also known as JPEG, together with ITU-T SG16)
|
||||
meeting in Berlin, Germany.
|
||||
|
||||
Thank to John Korejwa and Massimo Ballerini for inviting me to
|
||||
fruitful consultations in Boston, MA and Milan, Italy.
|
||||
|
||||
Thank to Hendrik Elstner, Roland Fassauer, Simone Zuck, Guenther
|
||||
Maier-Gerber, Walter Stoeber, Fred Schmitz, and Norbert Braunagel
|
||||
for corresponding business development.
|
||||
|
||||
Thank to Nico Zschach and Dirk Stelling of the technical support team
|
||||
at the Digital Images company in Halle for providing me with extra
|
||||
equipment for configuration tests.
|
||||
|
||||
Thank to Richard F. Lyon (then of Foveon Inc.) for fruitful
|
||||
communication about JPEG configuration in Sigma Photo Pro software.
|
||||
|
||||
Thank to Andrew Finkenstadt for hosting the ijg.org site.
|
||||
|
||||
Last but not least special thank to Thomas G. Lane for the original
|
||||
design and development of this singular software package.
|
||||
|
||||
|
||||
FILE FORMAT WARS
|
||||
================
|
||||
|
||||
Some JPEG programs produce files that are not compatible with our library.
|
||||
The root of the problem is that the ISO JPEG committee failed to specify a
|
||||
concrete file format. Some vendors "filled in the blanks" on their own,
|
||||
creating proprietary formats that no one else could read. (For example, none
|
||||
of the early commercial JPEG implementations for the Macintosh were able to
|
||||
exchange compressed files.)
|
||||
The ISO/IEC JTC1/SC29/WG1 standards committee (also known as JPEG, together
|
||||
with ITU-T SG16) currently promotes different formats containing the name
|
||||
"JPEG" which is misleading because these formats are incompatible with
|
||||
original DCT-based JPEG and are based on faulty technologies.
|
||||
IJG therefore does not and will not support such momentary mistakes
|
||||
(see REFERENCES).
|
||||
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!
|
||||
(In any case, our decoder will remain capable of reading existing JPEG
|
||||
image files indefinitely.)
|
||||
|
||||
The file format we have adopted is called JFIF (see REFERENCES). This format
|
||||
has been agreed to by a number of major commercial JPEG vendors, and it has
|
||||
become the de facto standard. JFIF is a minimal or "low end" representation.
|
||||
We recommend the use of TIFF/JPEG (TIFF revision 6.0 as modified by TIFF
|
||||
Technical Note #2) for "high end" applications that need to record a lot of
|
||||
additional data about an image. TIFF/JPEG is fairly new and not yet widely
|
||||
supported, unfortunately.
|
||||
Furthermore, 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.
|
||||
|
||||
The upcoming JPEG Part 3 standard defines a file format called SPIFF.
|
||||
SPIFF is interoperable with JFIF, in the sense that most JFIF decoders should
|
||||
be able to read the most common variant of SPIFF. SPIFF has some technical
|
||||
advantages over JFIF, but its major claim to fame is simply that it is an
|
||||
official standard rather than an informal one. At this point it is unclear
|
||||
whether SPIFF will supersede JFIF or whether JFIF will remain the de-facto
|
||||
standard. IJG intends to support SPIFF once the standard is frozen, but we
|
||||
have not decided whether it should become our default output format or not.
|
||||
(In any case, our decoder will remain capable of reading JFIF indefinitely.)
|
||||
|
||||
Various proprietary file formats incorporating JPEG compression also exist.
|
||||
We have little or no sympathy for the existence of these formats. Indeed,
|
||||
one of the original reasons for developing this free software was to help
|
||||
force convergence on common, open format standards for JPEG files. Don't
|
||||
use a proprietary file format!
|
||||
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.
|
||||
The other one claims to be a "derivative" or "fork" of the original libjpeg
|
||||
and violates the license conditions as described under LEGAL ISSUES above.
|
||||
We have no sympathy for the release of misleading and illegal distributions
|
||||
derived from obsolete code bases.
|
||||
Don't use an obsolete code base!
|
||||
|
||||
|
||||
TO DO
|
||||
=====
|
||||
|
||||
The major thrust for v7 will probably be improvement of visual quality.
|
||||
The current method for scaling the quantization tables is known not to be
|
||||
very good at low Q values. We also intend to investigate block boundary
|
||||
smoothing, "poor man's variable quantization", and other means of improving
|
||||
quality-vs-file-size performance without sacrificing compatibility.
|
||||
Version 9 is the second release of a new generation JPEG standard
|
||||
to overcome the limitations of the original JPEG specification.
|
||||
More features are being prepared for coming releases...
|
||||
|
||||
In future versions, we are considering supporting some of the upcoming JPEG
|
||||
Part 3 extensions --- principally, variable quantization and the SPIFF file
|
||||
format.
|
||||
|
||||
As always, speeding things up is of great interest.
|
||||
|
||||
Please send bug reports, offers of help, etc. to jpeg-info@uunet.uu.net.
|
||||
Please send bug reports, offers of help, etc. to jpeg-info@jpegclub.org.
|
||||
|
382
3rdparty/libjpeg/change.log
vendored
Normal file
382
3rdparty/libjpeg/change.log
vendored
Normal file
@ -0,0 +1,382 @@
|
||||
CHANGE LOG for Independent JPEG Group's JPEG software
|
||||
|
||||
|
||||
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
|
||||
-----------------------
|
||||
|
||||
Add option to compression library and cjpeg (-block N) to use
|
||||
different DCT block size.
|
||||
All N from 1 to 16 are possible. Default is 8 (baseline format).
|
||||
Larger values produce higher compression,
|
||||
smaller values produce higher quality.
|
||||
SmartScale capable decoder (introduced with IJG JPEG 8) required.
|
||||
|
||||
|
||||
Version 8b 16-May-2010
|
||||
-----------------------
|
||||
|
||||
Repair problem in new memory source manager with corrupt JPEG data.
|
||||
Thank to Ted Campbell and Samuel Chun for the report.
|
||||
|
||||
Repair problem in Makefile.am test target.
|
||||
Thank to anonymous user for the report.
|
||||
|
||||
Support MinGW installation with automatic configure.
|
||||
Thank to Volker Grabsch for the suggestion.
|
||||
|
||||
|
||||
Version 8a 28-Feb-2010
|
||||
-----------------------
|
||||
|
||||
Writing tables-only datastreams via jpeg_write_tables works again.
|
||||
|
||||
Support 32-bit BMPs (RGB image with Alpha channel) for read in cjpeg.
|
||||
Thank to Brett Blackham for the suggestion.
|
||||
|
||||
Improve accuracy in floating point IDCT calculation.
|
||||
Thank to Robert Hooke for the hint.
|
||||
|
||||
|
||||
Version 8 10-Jan-2010
|
||||
----------------------
|
||||
|
||||
jpegtran now supports the same -scale option as djpeg for "lossless" resize.
|
||||
An implementation of the JPEG SmartScale extension is required for this
|
||||
feature. A (draft) specification of the JPEG SmartScale extension is
|
||||
available as a contributed document at ITU and ISO. Revision 2 or later
|
||||
of the document is required (latest document version is Revision 3).
|
||||
The SmartScale extension will enable more features beside lossless resize
|
||||
in future implementations, as described in the document (new compression
|
||||
options).
|
||||
|
||||
Add sanity check in BMP reader module to avoid cjpeg crash for empty input
|
||||
image (thank to Isaev Ildar of ISP RAS, Moscow, RU for reporting this error).
|
||||
|
||||
Add data source and destination managers for read from and write to
|
||||
memory buffers. New API functions jpeg_mem_src and jpeg_mem_dest.
|
||||
Thank to Roberto Boni from Italy for the suggestion.
|
||||
|
||||
|
||||
Version 7 27-Jun-2009
|
||||
----------------------
|
||||
|
||||
New scaled DCTs implemented.
|
||||
djpeg now supports scalings N/8 with all N from 1 to 16.
|
||||
cjpeg now supports scalings 8/N with all N from 1 to 16.
|
||||
Scaled DCTs with size larger than 8 are now also used for resolving the
|
||||
common 2x2 chroma subsampling case without additional spatial resampling.
|
||||
Separate spatial resampling for those kind of files is now only necessary
|
||||
for N>8 scaling cases.
|
||||
Furthermore, separate scaled DCT functions are provided for direct resolving
|
||||
of the common asymmetric subsampling cases (2x1 and 1x2) without additional
|
||||
spatial resampling.
|
||||
|
||||
cjpeg -quality option has been extended for support of separate quality
|
||||
settings for luminance and chrominance (or in general, for every provided
|
||||
quantization table slot).
|
||||
New API function jpeg_default_qtables() and q_scale_factor array in library.
|
||||
|
||||
Added -nosmooth option to cjpeg, complementary to djpeg.
|
||||
New variable "do_fancy_downsampling" in library, complement to fancy
|
||||
upsampling. Fancy upsampling now uses direct DCT scaling with sizes
|
||||
larger than 8. The old method is not reversible and has been removed.
|
||||
|
||||
Support arithmetic entropy encoding and decoding.
|
||||
Added files jaricom.c, jcarith.c, jdarith.c.
|
||||
|
||||
Straighten the file structure:
|
||||
Removed files jidctred.c, jcphuff.c, jchuff.h, jdphuff.c, jdhuff.h.
|
||||
|
||||
jpegtran has a new "lossless" cropping feature.
|
||||
|
||||
Implement -perfect option in jpegtran, new API function
|
||||
jtransform_perfect_transform() in transupp. (DP 204_perfect.dpatch)
|
||||
|
||||
Better error messages for jpegtran fopen failure.
|
||||
(DP 203_jpegtran_errmsg.dpatch)
|
||||
|
||||
Fix byte order issue with 16bit PPM/PGM files in rdppm.c/wrppm.c:
|
||||
according to Netpbm, the de facto standard implementation of the PNM formats,
|
||||
the most significant byte is first. (DP 203_rdppm.dpatch)
|
||||
|
||||
Add -raw option to rdjpgcom not to mangle the output.
|
||||
(DP 205_rdjpgcom_raw.dpatch)
|
||||
|
||||
Make rdjpgcom locale aware. (DP 201_rdjpgcom_locale.dpatch)
|
||||
|
||||
Add extern "C" to jpeglib.h.
|
||||
This avoids the need to put extern "C" { ... } around #include "jpeglib.h"
|
||||
in your C++ application. Defining the symbol DONT_USE_EXTERN_C in the
|
||||
configuration prevents this. (DP 202_jpeglib.h_c++.dpatch)
|
||||
|
||||
|
||||
Version 6b 27-Mar-1998
|
||||
-----------------------
|
||||
|
||||
jpegtran has new features for lossless image transformations (rotation
|
||||
and flipping) as well as "lossless" reduction to grayscale.
|
||||
|
||||
jpegtran now copies comments by default; it has a -copy switch to enable
|
||||
copying all APPn blocks as well, or to suppress comments. (Formerly it
|
||||
always suppressed comments and APPn blocks.) jpegtran now also preserves
|
||||
JFIF version and resolution information.
|
||||
|
||||
New decompressor library feature: COM and APPn markers found in the input
|
||||
file can be saved in memory for later use by the application. (Before,
|
||||
you had to code this up yourself with a custom marker processor.)
|
||||
|
||||
There is an unused field "void * client_data" now in compress and decompress
|
||||
parameter structs; this may be useful in some applications.
|
||||
|
||||
JFIF version number information is now saved by the decoder and accepted by
|
||||
the encoder. jpegtran uses this to copy the source file's version number,
|
||||
to ensure "jpegtran -copy all" won't create bogus files that contain JFXX
|
||||
extensions but claim to be version 1.01. Applications that generate their
|
||||
own JFXX extension markers also (finally) have a supported way to cause the
|
||||
encoder to emit JFIF version number 1.02.
|
||||
|
||||
djpeg's trace mode reports JFIF 1.02 thumbnail images as such, rather
|
||||
than as unknown APP0 markers.
|
||||
|
||||
In -verbose mode, djpeg and rdjpgcom will try to print the contents of
|
||||
APP12 markers as text. Some digital cameras store useful text information
|
||||
in APP12 markers.
|
||||
|
||||
Handling of truncated data streams is more robust: blocks beyond the one in
|
||||
which the error occurs will be output as uniform gray, or left unchanged
|
||||
if decoding a progressive JPEG. The appearance no longer depends on the
|
||||
Huffman tables being used.
|
||||
|
||||
Huffman tables are checked for validity much more carefully than before.
|
||||
|
||||
To avoid the Unisys LZW patent, djpeg's GIF output capability has been
|
||||
changed to produce "uncompressed GIFs", and cjpeg's GIF input capability
|
||||
has been removed altogether. We're not happy about it either, but there
|
||||
seems to be no good alternative.
|
||||
|
||||
The configure script now supports building libjpeg as a shared library
|
||||
on many flavors of Unix (all the ones that GNU libtool knows how to
|
||||
build shared libraries for). Use "./configure --enable-shared" to
|
||||
try this out.
|
||||
|
||||
New jconfig file and makefiles for Microsoft Visual C++ and Developer Studio.
|
||||
Also, a jconfig file and a build script for Metrowerks CodeWarrior
|
||||
on Apple Macintosh. makefile.dj has been updated for DJGPP v2, and there
|
||||
are miscellaneous other minor improvements in the makefiles.
|
||||
|
||||
jmemmac.c now knows how to create temporary files following Mac System 7
|
||||
conventions.
|
||||
|
||||
djpeg's -map switch is now able to read raw-format PPM files reliably.
|
||||
|
||||
cjpeg -progressive -restart no longer generates any unnecessary DRI markers.
|
||||
|
||||
Multiple calls to jpeg_simple_progression for a single JPEG object
|
||||
no longer leak memory.
|
||||
|
||||
|
||||
Version 6a 7-Feb-96
|
||||
--------------------
|
||||
|
||||
Library initialization sequence modified to detect version mismatches
|
||||
and struct field packing mismatches between library and calling application.
|
||||
This change requires applications to be recompiled, but does not require
|
||||
any application source code change.
|
||||
|
||||
All routine declarations changed to the style "GLOBAL(type) name ...",
|
||||
that is, GLOBAL, LOCAL, METHODDEF, EXTERN are now macros taking the
|
||||
routine's return type as an argument. This makes it possible to add
|
||||
Microsoft-style linkage keywords to all the routines by changing just
|
||||
these macros. Note that any application code that was using these macros
|
||||
will have to be changed.
|
||||
|
||||
DCT coefficient quantization tables are now stored in normal array order
|
||||
rather than zigzag order. Application code that calls jpeg_add_quant_table,
|
||||
or otherwise manipulates quantization tables directly, will need to be
|
||||
changed. If you need to make such code work with either older or newer
|
||||
versions of the library, a test like "#if JPEG_LIB_VERSION >= 61" is
|
||||
recommended.
|
||||
|
||||
djpeg's trace capability now dumps DQT tables in natural order, not zigzag
|
||||
order. This allows the trace output to be made into a "-qtables" file
|
||||
more easily.
|
||||
|
||||
New system-dependent memory manager module for use on Apple Macintosh.
|
||||
|
||||
Fix bug in cjpeg's -smooth option: last one or two scanlines would be
|
||||
duplicates of the prior line unless the image height mod 16 was 1 or 2.
|
||||
|
||||
Repair minor problems in VMS, BCC, MC6 makefiles.
|
||||
|
||||
New configure script based on latest GNU Autoconf.
|
||||
|
||||
Correct the list of include files needed by MetroWerks C for ccommand().
|
||||
|
||||
Numerous small documentation updates.
|
||||
|
||||
|
||||
Version 6 2-Aug-95
|
||||
-------------------
|
||||
|
||||
Progressive JPEG support: library can read and write full progressive JPEG
|
||||
files. A "buffered image" mode supports incremental decoding for on-the-fly
|
||||
display of progressive images. Simply recompiling an existing IJG-v5-based
|
||||
decoder with v6 should allow it to read progressive files, though of course
|
||||
without any special progressive display.
|
||||
|
||||
New "jpegtran" application performs lossless transcoding between different
|
||||
JPEG formats; primarily, it can be used to convert baseline to progressive
|
||||
JPEG and vice versa. In support of jpegtran, the library now allows lossless
|
||||
reading and writing of JPEG files as DCT coefficient arrays. This ability
|
||||
may be of use in other applications.
|
||||
|
||||
Notes for programmers:
|
||||
* We changed jpeg_start_decompress() to be able to suspend; this makes all
|
||||
decoding modes available to suspending-input applications. However,
|
||||
existing applications that use suspending input will need to be changed
|
||||
to check the return value from jpeg_start_decompress(). You don't need to
|
||||
do anything if you don't use a suspending data source.
|
||||
* We changed the interface to the virtual array routines: access_virt_array
|
||||
routines now take a count of the number of rows to access this time. The
|
||||
last parameter to request_virt_array routines is now interpreted as the
|
||||
maximum number of rows that may be accessed at once, but not necessarily
|
||||
the height of every access.
|
||||
|
||||
|
||||
Version 5b 15-Mar-95
|
||||
---------------------
|
||||
|
||||
Correct bugs with grayscale images having v_samp_factor > 1.
|
||||
|
||||
jpeg_write_raw_data() now supports output suspension.
|
||||
|
||||
Correct bugs in "configure" script for case of compiling in
|
||||
a directory other than the one containing the source files.
|
||||
|
||||
Repair bug in jquant1.c: sometimes didn't use as many colors as it could.
|
||||
|
||||
Borland C makefile and jconfig file work under either MS-DOS or OS/2.
|
||||
|
||||
Miscellaneous improvements to documentation.
|
||||
|
||||
|
||||
Version 5a 7-Dec-94
|
||||
--------------------
|
||||
|
||||
Changed color conversion roundoff behavior so that grayscale values are
|
||||
represented exactly. (This causes test image files to change.)
|
||||
|
||||
Make ordered dither use 16x16 instead of 4x4 pattern for a small quality
|
||||
improvement.
|
||||
|
||||
New configure script based on latest GNU Autoconf.
|
||||
Fix configure script to handle CFLAGS correctly.
|
||||
Rename *.auto files to *.cfg, so that configure script still works if
|
||||
file names have been truncated for DOS.
|
||||
|
||||
Fix bug in rdbmp.c: didn't allow for extra data between header and image.
|
||||
|
||||
Modify rdppm.c/wrppm.c to handle 2-byte raw PPM/PGM formats for 12-bit data.
|
||||
|
||||
Fix several bugs in rdrle.c.
|
||||
|
||||
NEED_SHORT_EXTERNAL_NAMES option was broken.
|
||||
|
||||
Revise jerror.h/jerror.c for more flexibility in message table.
|
||||
|
||||
Repair oversight in jmemname.c NO_MKTEMP case: file could be there
|
||||
but unreadable.
|
||||
|
||||
|
||||
Version 5 24-Sep-94
|
||||
--------------------
|
||||
|
||||
Version 5 represents a nearly complete redesign and rewrite of the IJG
|
||||
software. Major user-visible changes include:
|
||||
* Automatic configuration simplifies installation for most Unix systems.
|
||||
* A range of speed vs. image quality tradeoffs are supported.
|
||||
This includes resizing of an image during decompression: scaling down
|
||||
by a factor of 1/2, 1/4, or 1/8 is handled very efficiently.
|
||||
* New programs rdjpgcom and wrjpgcom allow insertion and extraction
|
||||
of text comments in a JPEG file.
|
||||
|
||||
The application programmer's interface to the library has changed completely.
|
||||
Notable improvements include:
|
||||
* We have eliminated the use of callback routines for handling the
|
||||
uncompressed image data. The application now sees the library as a
|
||||
set of routines that it calls to read or write image data on a
|
||||
scanline-by-scanline basis.
|
||||
* The application image data is represented in a conventional interleaved-
|
||||
pixel format, rather than as a separate array for each color channel.
|
||||
This can save a copying step in many programs.
|
||||
* The handling of compressed data has been cleaned up: the application can
|
||||
supply routines to source or sink the compressed data. It is possible to
|
||||
suspend processing on source/sink buffer overrun, although this is not
|
||||
supported in all operating modes.
|
||||
* All static state has been eliminated from the library, so that multiple
|
||||
instances of compression or decompression can be active concurrently.
|
||||
* JPEG abbreviated datastream formats are supported, ie, quantization and
|
||||
Huffman tables can be stored separately from the image data.
|
||||
* And not only that, but the documentation of the library has improved
|
||||
considerably!
|
||||
|
||||
|
||||
The last widely used release before the version 5 rewrite was version 4A of
|
||||
18-Feb-93. Change logs before that point have been discarded, since they
|
||||
are not of much interest after the rewrite.
|
153
3rdparty/libjpeg/jaricom.c
vendored
Normal file
153
3rdparty/libjpeg/jaricom.c
vendored
Normal file
@ -0,0 +1,153 @@
|
||||
/*
|
||||
* jaricom.c
|
||||
*
|
||||
* Developed 1997-2011 by Guido Vollbeding.
|
||||
* This file is part of the Independent JPEG Group's software.
|
||||
* For conditions of distribution and use, see the accompanying README file.
|
||||
*
|
||||
* This file contains probability estimation tables for common use in
|
||||
* arithmetic entropy encoding and decoding routines.
|
||||
*
|
||||
* This data represents Table D.3 in the JPEG spec (D.2 in the draft),
|
||||
* ISO/IEC IS 10918-1 and CCITT Recommendation ITU-T T.81, and Table 24
|
||||
* in the JBIG spec, ISO/IEC IS 11544 and CCITT Recommendation ITU-T T.82.
|
||||
*/
|
||||
|
||||
#define JPEG_INTERNALS
|
||||
#include "jinclude.h"
|
||||
#include "jpeglib.h"
|
||||
|
||||
/* The following #define specifies the packing of the four components
|
||||
* into the compact INT32 representation.
|
||||
* Note that this formula must match the actual arithmetic encoder
|
||||
* and decoder implementation. The implementation has to be changed
|
||||
* if this formula is changed.
|
||||
* The current organization is leaned on Markus Kuhn's JBIG
|
||||
* implementation (jbig_tab.c).
|
||||
*/
|
||||
|
||||
#define V(i,a,b,c,d) (((INT32)a << 16) | ((INT32)c << 8) | ((INT32)d << 7) | b)
|
||||
|
||||
const INT32 jpeg_aritab[113+1] = {
|
||||
/*
|
||||
* Index, Qe_Value, Next_Index_LPS, Next_Index_MPS, Switch_MPS
|
||||
*/
|
||||
V( 0, 0x5a1d, 1, 1, 1 ),
|
||||
V( 1, 0x2586, 14, 2, 0 ),
|
||||
V( 2, 0x1114, 16, 3, 0 ),
|
||||
V( 3, 0x080b, 18, 4, 0 ),
|
||||
V( 4, 0x03d8, 20, 5, 0 ),
|
||||
V( 5, 0x01da, 23, 6, 0 ),
|
||||
V( 6, 0x00e5, 25, 7, 0 ),
|
||||
V( 7, 0x006f, 28, 8, 0 ),
|
||||
V( 8, 0x0036, 30, 9, 0 ),
|
||||
V( 9, 0x001a, 33, 10, 0 ),
|
||||
V( 10, 0x000d, 35, 11, 0 ),
|
||||
V( 11, 0x0006, 9, 12, 0 ),
|
||||
V( 12, 0x0003, 10, 13, 0 ),
|
||||
V( 13, 0x0001, 12, 13, 0 ),
|
||||
V( 14, 0x5a7f, 15, 15, 1 ),
|
||||
V( 15, 0x3f25, 36, 16, 0 ),
|
||||
V( 16, 0x2cf2, 38, 17, 0 ),
|
||||
V( 17, 0x207c, 39, 18, 0 ),
|
||||
V( 18, 0x17b9, 40, 19, 0 ),
|
||||
V( 19, 0x1182, 42, 20, 0 ),
|
||||
V( 20, 0x0cef, 43, 21, 0 ),
|
||||
V( 21, 0x09a1, 45, 22, 0 ),
|
||||
V( 22, 0x072f, 46, 23, 0 ),
|
||||
V( 23, 0x055c, 48, 24, 0 ),
|
||||
V( 24, 0x0406, 49, 25, 0 ),
|
||||
V( 25, 0x0303, 51, 26, 0 ),
|
||||
V( 26, 0x0240, 52, 27, 0 ),
|
||||
V( 27, 0x01b1, 54, 28, 0 ),
|
||||
V( 28, 0x0144, 56, 29, 0 ),
|
||||
V( 29, 0x00f5, 57, 30, 0 ),
|
||||
V( 30, 0x00b7, 59, 31, 0 ),
|
||||
V( 31, 0x008a, 60, 32, 0 ),
|
||||
V( 32, 0x0068, 62, 33, 0 ),
|
||||
V( 33, 0x004e, 63, 34, 0 ),
|
||||
V( 34, 0x003b, 32, 35, 0 ),
|
||||
V( 35, 0x002c, 33, 9, 0 ),
|
||||
V( 36, 0x5ae1, 37, 37, 1 ),
|
||||
V( 37, 0x484c, 64, 38, 0 ),
|
||||
V( 38, 0x3a0d, 65, 39, 0 ),
|
||||
V( 39, 0x2ef1, 67, 40, 0 ),
|
||||
V( 40, 0x261f, 68, 41, 0 ),
|
||||
V( 41, 0x1f33, 69, 42, 0 ),
|
||||
V( 42, 0x19a8, 70, 43, 0 ),
|
||||
V( 43, 0x1518, 72, 44, 0 ),
|
||||
V( 44, 0x1177, 73, 45, 0 ),
|
||||
V( 45, 0x0e74, 74, 46, 0 ),
|
||||
V( 46, 0x0bfb, 75, 47, 0 ),
|
||||
V( 47, 0x09f8, 77, 48, 0 ),
|
||||
V( 48, 0x0861, 78, 49, 0 ),
|
||||
V( 49, 0x0706, 79, 50, 0 ),
|
||||
V( 50, 0x05cd, 48, 51, 0 ),
|
||||
V( 51, 0x04de, 50, 52, 0 ),
|
||||
V( 52, 0x040f, 50, 53, 0 ),
|
||||
V( 53, 0x0363, 51, 54, 0 ),
|
||||
V( 54, 0x02d4, 52, 55, 0 ),
|
||||
V( 55, 0x025c, 53, 56, 0 ),
|
||||
V( 56, 0x01f8, 54, 57, 0 ),
|
||||
V( 57, 0x01a4, 55, 58, 0 ),
|
||||
V( 58, 0x0160, 56, 59, 0 ),
|
||||
V( 59, 0x0125, 57, 60, 0 ),
|
||||
V( 60, 0x00f6, 58, 61, 0 ),
|
||||
V( 61, 0x00cb, 59, 62, 0 ),
|
||||
V( 62, 0x00ab, 61, 63, 0 ),
|
||||
V( 63, 0x008f, 61, 32, 0 ),
|
||||
V( 64, 0x5b12, 65, 65, 1 ),
|
||||
V( 65, 0x4d04, 80, 66, 0 ),
|
||||
V( 66, 0x412c, 81, 67, 0 ),
|
||||
V( 67, 0x37d8, 82, 68, 0 ),
|
||||
V( 68, 0x2fe8, 83, 69, 0 ),
|
||||
V( 69, 0x293c, 84, 70, 0 ),
|
||||
V( 70, 0x2379, 86, 71, 0 ),
|
||||
V( 71, 0x1edf, 87, 72, 0 ),
|
||||
V( 72, 0x1aa9, 87, 73, 0 ),
|
||||
V( 73, 0x174e, 72, 74, 0 ),
|
||||
V( 74, 0x1424, 72, 75, 0 ),
|
||||
V( 75, 0x119c, 74, 76, 0 ),
|
||||
V( 76, 0x0f6b, 74, 77, 0 ),
|
||||
V( 77, 0x0d51, 75, 78, 0 ),
|
||||
V( 78, 0x0bb6, 77, 79, 0 ),
|
||||
V( 79, 0x0a40, 77, 48, 0 ),
|
||||
V( 80, 0x5832, 80, 81, 1 ),
|
||||
V( 81, 0x4d1c, 88, 82, 0 ),
|
||||
V( 82, 0x438e, 89, 83, 0 ),
|
||||
V( 83, 0x3bdd, 90, 84, 0 ),
|
||||
V( 84, 0x34ee, 91, 85, 0 ),
|
||||
V( 85, 0x2eae, 92, 86, 0 ),
|
||||
V( 86, 0x299a, 93, 87, 0 ),
|
||||
V( 87, 0x2516, 86, 71, 0 ),
|
||||
V( 88, 0x5570, 88, 89, 1 ),
|
||||
V( 89, 0x4ca9, 95, 90, 0 ),
|
||||
V( 90, 0x44d9, 96, 91, 0 ),
|
||||
V( 91, 0x3e22, 97, 92, 0 ),
|
||||
V( 92, 0x3824, 99, 93, 0 ),
|
||||
V( 93, 0x32b4, 99, 94, 0 ),
|
||||
V( 94, 0x2e17, 93, 86, 0 ),
|
||||
V( 95, 0x56a8, 95, 96, 1 ),
|
||||
V( 96, 0x4f46, 101, 97, 0 ),
|
||||
V( 97, 0x47e5, 102, 98, 0 ),
|
||||
V( 98, 0x41cf, 103, 99, 0 ),
|
||||
V( 99, 0x3c3d, 104, 100, 0 ),
|
||||
V( 100, 0x375e, 99, 93, 0 ),
|
||||
V( 101, 0x5231, 105, 102, 0 ),
|
||||
V( 102, 0x4c0f, 106, 103, 0 ),
|
||||
V( 103, 0x4639, 107, 104, 0 ),
|
||||
V( 104, 0x415e, 103, 99, 0 ),
|
||||
V( 105, 0x5627, 105, 106, 1 ),
|
||||
V( 106, 0x50e7, 108, 107, 0 ),
|
||||
V( 107, 0x4b85, 109, 103, 0 ),
|
||||
V( 108, 0x5597, 110, 109, 0 ),
|
||||
V( 109, 0x504f, 111, 107, 0 ),
|
||||
V( 110, 0x5a10, 110, 111, 1 ),
|
||||
V( 111, 0x5522, 112, 109, 0 ),
|
||||
V( 112, 0x59eb, 112, 111, 1 ),
|
||||
/*
|
||||
* This last entry is used for fixed probability estimate of 0.5
|
||||
* as suggested in Section 10.3 Table 5 of ITU-T Rec. T.851.
|
||||
*/
|
||||
V( 113, 0x5a1d, 113, 113, 0 )
|
||||
};
|
22
3rdparty/libjpeg/jcapimin.c
vendored
22
3rdparty/libjpeg/jcapimin.c
vendored
@ -2,6 +2,7 @@
|
||||
* jcapimin.c
|
||||
*
|
||||
* Copyright (C) 1994-1998, Thomas G. Lane.
|
||||
* Modified 2003-2010 by Guido Vollbeding.
|
||||
* This file is part of the Independent JPEG Group's software.
|
||||
* For conditions of distribution and use, see the accompanying README file.
|
||||
*
|
||||
@ -37,7 +38,7 @@ jpeg_CreateCompress (j_compress_ptr cinfo, int version, size_t structsize)
|
||||
ERREXIT2(cinfo, JERR_BAD_LIB_VERSION, JPEG_LIB_VERSION, version);
|
||||
if (structsize != SIZEOF(struct jpeg_compress_struct))
|
||||
ERREXIT2(cinfo, JERR_BAD_STRUCT_SIZE,
|
||||
(int) SIZEOF(struct jpeg_compress_struct), (int) structsize);
|
||||
(int) SIZEOF(struct jpeg_compress_struct), (int) structsize);
|
||||
|
||||
/* For debugging purposes, we zero the whole master structure.
|
||||
* But the application has already set the err pointer, and may have set
|
||||
@ -63,14 +64,21 @@ jpeg_CreateCompress (j_compress_ptr cinfo, int version, size_t structsize)
|
||||
|
||||
cinfo->comp_info = NULL;
|
||||
|
||||
for (i = 0; i < NUM_QUANT_TBLS; i++)
|
||||
for (i = 0; i < NUM_QUANT_TBLS; i++) {
|
||||
cinfo->quant_tbl_ptrs[i] = NULL;
|
||||
cinfo->q_scale_factor[i] = 100;
|
||||
}
|
||||
|
||||
for (i = 0; i < NUM_HUFF_TBLS; i++) {
|
||||
cinfo->dc_huff_tbl_ptrs[i] = NULL;
|
||||
cinfo->ac_huff_tbl_ptrs[i] = NULL;
|
||||
}
|
||||
|
||||
/* Must do it here for emit_dqt in case jpeg_write_tables is used */
|
||||
cinfo->block_size = DCTSIZE;
|
||||
cinfo->natural_order = jpeg_natural_order;
|
||||
cinfo->lim_Se = DCTSIZE2-1;
|
||||
|
||||
cinfo->script_space = NULL;
|
||||
|
||||
cinfo->input_gamma = 1.0; /* in case application forgets */
|
||||
@ -161,15 +169,15 @@ jpeg_finish_compress (j_compress_ptr cinfo)
|
||||
(*cinfo->master->prepare_for_pass) (cinfo);
|
||||
for (iMCU_row = 0; iMCU_row < cinfo->total_iMCU_rows; iMCU_row++) {
|
||||
if (cinfo->progress != NULL) {
|
||||
cinfo->progress->pass_counter = (long) iMCU_row;
|
||||
cinfo->progress->pass_limit = (long) cinfo->total_iMCU_rows;
|
||||
(*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
|
||||
cinfo->progress->pass_counter = (long) iMCU_row;
|
||||
cinfo->progress->pass_limit = (long) cinfo->total_iMCU_rows;
|
||||
(*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
|
||||
}
|
||||
/* We bypass the main controller and invoke coef controller directly;
|
||||
* all work is being done from the coefficient buffer.
|
||||
*/
|
||||
if (! (*cinfo->coef->compress_data) (cinfo, (JSAMPIMAGE) NULL))
|
||||
ERREXIT(cinfo, JERR_CANT_SUSPEND);
|
||||
ERREXIT(cinfo, JERR_CANT_SUSPEND);
|
||||
}
|
||||
(*cinfo->master->finish_pass) (cinfo);
|
||||
}
|
||||
@ -190,7 +198,7 @@ jpeg_finish_compress (j_compress_ptr cinfo)
|
||||
|
||||
GLOBAL(void)
|
||||
jpeg_write_marker (j_compress_ptr cinfo, int marker,
|
||||
const JOCTET *dataptr, unsigned int datalen)
|
||||
const JOCTET *dataptr, unsigned int datalen)
|
||||
{
|
||||
JMETHOD(void, write_marker_byte, (j_compress_ptr info, int val));
|
||||
|
||||
|
4
3rdparty/libjpeg/jcapistd.c
vendored
4
3rdparty/libjpeg/jcapistd.c
vendored
@ -75,7 +75,7 @@ jpeg_start_compress (j_compress_ptr cinfo, boolean write_all_tables)
|
||||
|
||||
GLOBAL(JDIMENSION)
|
||||
jpeg_write_scanlines (j_compress_ptr cinfo, JSAMPARRAY scanlines,
|
||||
JDIMENSION num_lines)
|
||||
JDIMENSION num_lines)
|
||||
{
|
||||
JDIMENSION row_ctr, rows_left;
|
||||
|
||||
@ -118,7 +118,7 @@ jpeg_write_scanlines (j_compress_ptr cinfo, JSAMPARRAY scanlines,
|
||||
|
||||
GLOBAL(JDIMENSION)
|
||||
jpeg_write_raw_data (j_compress_ptr cinfo, JSAMPIMAGE data,
|
||||
JDIMENSION num_lines)
|
||||
JDIMENSION num_lines)
|
||||
{
|
||||
JDIMENSION lines_per_iMCU_row;
|
||||
|
||||
|
943
3rdparty/libjpeg/jcarith.c
vendored
Normal file
943
3rdparty/libjpeg/jcarith.c
vendored
Normal file
@ -0,0 +1,943 @@
|
||||
/*
|
||||
* jcarith.c
|
||||
*
|
||||
* Developed 1997-2012 by Guido Vollbeding.
|
||||
* This file is part of the Independent JPEG Group's software.
|
||||
* For conditions of distribution and use, see the accompanying README file.
|
||||
*
|
||||
* This file contains portable arithmetic entropy encoding routines for JPEG
|
||||
* (implementing the ISO/IEC IS 10918-1 and CCITT Recommendation ITU-T T.81).
|
||||
*
|
||||
* Both sequential and progressive modes are supported in this single module.
|
||||
*
|
||||
* Suspension is not currently supported in this module.
|
||||
*/
|
||||
|
||||
#define JPEG_INTERNALS
|
||||
#include "jinclude.h"
|
||||
#include "jpeglib.h"
|
||||
|
||||
|
||||
/* Expanded entropy encoder object for arithmetic encoding. */
|
||||
|
||||
typedef struct {
|
||||
struct jpeg_entropy_encoder pub; /* public fields */
|
||||
|
||||
INT32 c; /* C register, base of coding interval, layout as in sec. D.1.3 */
|
||||
INT32 a; /* A register, normalized size of coding interval */
|
||||
INT32 sc; /* counter for stacked 0xFF values which might overflow */
|
||||
INT32 zc; /* counter for pending 0x00 output values which might *
|
||||
* be discarded at the end ("Pacman" termination) */
|
||||
int ct; /* bit shift counter, determines when next byte will be written */
|
||||
int buffer; /* buffer for most recent output byte != 0xFF */
|
||||
|
||||
int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
|
||||
int dc_context[MAX_COMPS_IN_SCAN]; /* context index for DC conditioning */
|
||||
|
||||
unsigned int restarts_to_go; /* MCUs left in this restart interval */
|
||||
int next_restart_num; /* next restart number to write (0-7) */
|
||||
|
||||
/* Pointers to statistics areas (these workspaces have image lifespan) */
|
||||
unsigned char * dc_stats[NUM_ARITH_TBLS];
|
||||
unsigned char * ac_stats[NUM_ARITH_TBLS];
|
||||
|
||||
/* Statistics bin for coding with fixed probability 0.5 */
|
||||
unsigned char fixed_bin[4];
|
||||
} arith_entropy_encoder;
|
||||
|
||||
typedef arith_entropy_encoder * arith_entropy_ptr;
|
||||
|
||||
/* The following two definitions specify the allocation chunk size
|
||||
* for the statistics area.
|
||||
* According to sections F.1.4.4.1.3 and F.1.4.4.2, we need at least
|
||||
* 49 statistics bins for DC, and 245 statistics bins for AC coding.
|
||||
*
|
||||
* We use a compact representation with 1 byte per statistics bin,
|
||||
* thus the numbers directly represent byte sizes.
|
||||
* This 1 byte per statistics bin contains the meaning of the MPS
|
||||
* (more probable symbol) in the highest bit (mask 0x80), and the
|
||||
* index into the probability estimation state machine table
|
||||
* in the lower bits (mask 0x7F).
|
||||
*/
|
||||
|
||||
#define DC_STAT_BINS 64
|
||||
#define AC_STAT_BINS 256
|
||||
|
||||
/* NOTE: Uncomment the following #define if you want to use the
|
||||
* given formula for calculating the AC conditioning parameter Kx
|
||||
* for spectral selection progressive coding in section G.1.3.2
|
||||
* of the spec (Kx = Kmin + SRL (8 + Se - Kmin) 4).
|
||||
* Although the spec and P&M authors claim that this "has proven
|
||||
* to give good results for 8 bit precision samples", I'm not
|
||||
* convinced yet that this is really beneficial.
|
||||
* Early tests gave only very marginal compression enhancements
|
||||
* (a few - around 5 or so - bytes even for very large files),
|
||||
* which would turn out rather negative if we'd suppress the
|
||||
* DAC (Define Arithmetic Conditioning) marker segments for
|
||||
* the default parameters in the future.
|
||||
* Note that currently the marker writing module emits 12-byte
|
||||
* DAC segments for a full-component scan in a color image.
|
||||
* This is not worth worrying about IMHO. However, since the
|
||||
* spec defines the default values to be used if the tables
|
||||
* are omitted (unlike Huffman tables, which are required
|
||||
* anyway), one might optimize this behaviour in the future,
|
||||
* and then it would be disadvantageous to use custom tables if
|
||||
* they don't provide sufficient gain to exceed the DAC size.
|
||||
*
|
||||
* On the other hand, I'd consider it as a reasonable result
|
||||
* that the conditioning has no significant influence on the
|
||||
* compression performance. This means that the basic
|
||||
* statistical model is already rather stable.
|
||||
*
|
||||
* Thus, at the moment, we use the default conditioning values
|
||||
* anyway, and do not use the custom formula.
|
||||
*
|
||||
#define CALCULATE_SPECTRAL_CONDITIONING
|
||||
*/
|
||||
|
||||
/* IRIGHT_SHIFT is like RIGHT_SHIFT, but works on int rather than INT32.
|
||||
* We assume that int right shift is unsigned if INT32 right shift is,
|
||||
* which should be safe.
|
||||
*/
|
||||
|
||||
#ifdef RIGHT_SHIFT_IS_UNSIGNED
|
||||
#define ISHIFT_TEMPS int ishift_temp;
|
||||
#define IRIGHT_SHIFT(x,shft) \
|
||||
((ishift_temp = (x)) < 0 ? \
|
||||
(ishift_temp >> (shft)) | ((~0) << (16-(shft))) : \
|
||||
(ishift_temp >> (shft)))
|
||||
#else
|
||||
#define ISHIFT_TEMPS
|
||||
#define IRIGHT_SHIFT(x,shft) ((x) >> (shft))
|
||||
#endif
|
||||
|
||||
|
||||
LOCAL(void)
|
||||
emit_byte (int val, j_compress_ptr cinfo)
|
||||
/* Write next output byte; we do not support suspension in this module. */
|
||||
{
|
||||
struct jpeg_destination_mgr * dest = cinfo->dest;
|
||||
|
||||
*dest->next_output_byte++ = (JOCTET) val;
|
||||
if (--dest->free_in_buffer == 0)
|
||||
if (! (*dest->empty_output_buffer) (cinfo))
|
||||
ERREXIT(cinfo, JERR_CANT_SUSPEND);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Finish up at the end of an arithmetic-compressed scan.
|
||||
*/
|
||||
|
||||
METHODDEF(void)
|
||||
finish_pass (j_compress_ptr cinfo)
|
||||
{
|
||||
arith_entropy_ptr e = (arith_entropy_ptr) cinfo->entropy;
|
||||
INT32 temp;
|
||||
|
||||
/* Section D.1.8: Termination of encoding */
|
||||
|
||||
/* Find the e->c in the coding interval with the largest
|
||||
* number of trailing zero bits */
|
||||
if ((temp = (e->a - 1 + e->c) & 0xFFFF0000L) < e->c)
|
||||
e->c = temp + 0x8000L;
|
||||
else
|
||||
e->c = temp;
|
||||
/* Send remaining bytes to output */
|
||||
e->c <<= e->ct;
|
||||
if (e->c & 0xF8000000L) {
|
||||
/* One final overflow has to be handled */
|
||||
if (e->buffer >= 0) {
|
||||
if (e->zc)
|
||||
do emit_byte(0x00, cinfo);
|
||||
while (--e->zc);
|
||||
emit_byte(e->buffer + 1, cinfo);
|
||||
if (e->buffer + 1 == 0xFF)
|
||||
emit_byte(0x00, cinfo);
|
||||
}
|
||||
e->zc += e->sc; /* carry-over converts stacked 0xFF bytes to 0x00 */
|
||||
e->sc = 0;
|
||||
} else {
|
||||
if (e->buffer == 0)
|
||||
++e->zc;
|
||||
else if (e->buffer >= 0) {
|
||||
if (e->zc)
|
||||
do emit_byte(0x00, cinfo);
|
||||
while (--e->zc);
|
||||
emit_byte(e->buffer, cinfo);
|
||||
}
|
||||
if (e->sc) {
|
||||
if (e->zc)
|
||||
do emit_byte(0x00, cinfo);
|
||||
while (--e->zc);
|
||||
do {
|
||||
emit_byte(0xFF, cinfo);
|
||||
emit_byte(0x00, cinfo);
|
||||
} while (--e->sc);
|
||||
}
|
||||
}
|
||||
/* Output final bytes only if they are not 0x00 */
|
||||
if (e->c & 0x7FFF800L) {
|
||||
if (e->zc) /* output final pending zero bytes */
|
||||
do emit_byte(0x00, cinfo);
|
||||
while (--e->zc);
|
||||
emit_byte((e->c >> 19) & 0xFF, cinfo);
|
||||
if (((e->c >> 19) & 0xFF) == 0xFF)
|
||||
emit_byte(0x00, cinfo);
|
||||
if (e->c & 0x7F800L) {
|
||||
emit_byte((e->c >> 11) & 0xFF, cinfo);
|
||||
if (((e->c >> 11) & 0xFF) == 0xFF)
|
||||
emit_byte(0x00, cinfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* The core arithmetic encoding routine (common in JPEG and JBIG).
|
||||
* This needs to go as fast as possible.
|
||||
* Machine-dependent optimization facilities
|
||||
* are not utilized in this portable implementation.
|
||||
* However, this code should be fairly efficient and
|
||||
* may be a good base for further optimizations anyway.
|
||||
*
|
||||
* Parameter 'val' to be encoded may be 0 or 1 (binary decision).
|
||||
*
|
||||
* Note: I've added full "Pacman" termination support to the
|
||||
* byte output routines, which is equivalent to the optional
|
||||
* Discard_final_zeros procedure (Figure D.15) in the spec.
|
||||
* Thus, we always produce the shortest possible output
|
||||
* stream compliant to the spec (no trailing zero bytes,
|
||||
* except for FF stuffing).
|
||||
*
|
||||
* I've also introduced a new scheme for accessing
|
||||
* the probability estimation state machine table,
|
||||
* derived from Markus Kuhn's JBIG implementation.
|
||||
*/
|
||||
|
||||
LOCAL(void)
|
||||
arith_encode (j_compress_ptr cinfo, unsigned char *st, int val)
|
||||
{
|
||||
register arith_entropy_ptr e = (arith_entropy_ptr) cinfo->entropy;
|
||||
register unsigned char nl, nm;
|
||||
register INT32 qe, temp;
|
||||
register int sv;
|
||||
|
||||
/* Fetch values from our compact representation of Table D.3(D.2):
|
||||
* Qe values and probability estimation state machine
|
||||
*/
|
||||
sv = *st;
|
||||
qe = jpeg_aritab[sv & 0x7F]; /* => Qe_Value */
|
||||
nl = qe & 0xFF; qe >>= 8; /* Next_Index_LPS + Switch_MPS */
|
||||
nm = qe & 0xFF; qe >>= 8; /* Next_Index_MPS */
|
||||
|
||||
/* Encode & estimation procedures per sections D.1.4 & D.1.5 */
|
||||
e->a -= qe;
|
||||
if (val != (sv >> 7)) {
|
||||
/* Encode the less probable symbol */
|
||||
if (e->a >= qe) {
|
||||
/* If the interval size (qe) for the less probable symbol (LPS)
|
||||
* is larger than the interval size for the MPS, then exchange
|
||||
* the two symbols for coding efficiency, otherwise code the LPS
|
||||
* as usual: */
|
||||
e->c += e->a;
|
||||
e->a = qe;
|
||||
}
|
||||
*st = (sv & 0x80) ^ nl; /* Estimate_after_LPS */
|
||||
} else {
|
||||
/* Encode the more probable symbol */
|
||||
if (e->a >= 0x8000L)
|
||||
return; /* A >= 0x8000 -> ready, no renormalization required */
|
||||
if (e->a < qe) {
|
||||
/* If the interval size (qe) for the less probable symbol (LPS)
|
||||
* is larger than the interval size for the MPS, then exchange
|
||||
* the two symbols for coding efficiency: */
|
||||
e->c += e->a;
|
||||
e->a = qe;
|
||||
}
|
||||
*st = (sv & 0x80) ^ nm; /* Estimate_after_MPS */
|
||||
}
|
||||
|
||||
/* Renormalization & data output per section D.1.6 */
|
||||
do {
|
||||
e->a <<= 1;
|
||||
e->c <<= 1;
|
||||
if (--e->ct == 0) {
|
||||
/* Another byte is ready for output */
|
||||
temp = e->c >> 19;
|
||||
if (temp > 0xFF) {
|
||||
/* Handle overflow over all stacked 0xFF bytes */
|
||||
if (e->buffer >= 0) {
|
||||
if (e->zc)
|
||||
do emit_byte(0x00, cinfo);
|
||||
while (--e->zc);
|
||||
emit_byte(e->buffer + 1, cinfo);
|
||||
if (e->buffer + 1 == 0xFF)
|
||||
emit_byte(0x00, cinfo);
|
||||
}
|
||||
e->zc += e->sc; /* carry-over converts stacked 0xFF bytes to 0x00 */
|
||||
e->sc = 0;
|
||||
/* Note: The 3 spacer bits in the C register guarantee
|
||||
* that the new buffer byte can't be 0xFF here
|
||||
* (see page 160 in the P&M JPEG book). */
|
||||
e->buffer = temp & 0xFF; /* new output byte, might overflow later */
|
||||
} else if (temp == 0xFF) {
|
||||
++e->sc; /* stack 0xFF byte (which might overflow later) */
|
||||
} else {
|
||||
/* Output all stacked 0xFF bytes, they will not overflow any more */
|
||||
if (e->buffer == 0)
|
||||
++e->zc;
|
||||
else if (e->buffer >= 0) {
|
||||
if (e->zc)
|
||||
do emit_byte(0x00, cinfo);
|
||||
while (--e->zc);
|
||||
emit_byte(e->buffer, cinfo);
|
||||
}
|
||||
if (e->sc) {
|
||||
if (e->zc)
|
||||
do emit_byte(0x00, cinfo);
|
||||
while (--e->zc);
|
||||
do {
|
||||
emit_byte(0xFF, cinfo);
|
||||
emit_byte(0x00, cinfo);
|
||||
} while (--e->sc);
|
||||
}
|
||||
e->buffer = temp & 0xFF; /* new output byte (can still overflow) */
|
||||
}
|
||||
e->c &= 0x7FFFFL;
|
||||
e->ct += 8;
|
||||
}
|
||||
} while (e->a < 0x8000L);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Emit a restart marker & resynchronize predictions.
|
||||
*/
|
||||
|
||||
LOCAL(void)
|
||||
emit_restart (j_compress_ptr cinfo, int restart_num)
|
||||
{
|
||||
arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy;
|
||||
int ci;
|
||||
jpeg_component_info * compptr;
|
||||
|
||||
finish_pass(cinfo);
|
||||
|
||||
emit_byte(0xFF, cinfo);
|
||||
emit_byte(JPEG_RST0 + restart_num, cinfo);
|
||||
|
||||
/* Re-initialize statistics areas */
|
||||
for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
|
||||
compptr = cinfo->cur_comp_info[ci];
|
||||
/* DC needs no table for refinement scan */
|
||||
if (cinfo->Ss == 0 && cinfo->Ah == 0) {
|
||||
MEMZERO(entropy->dc_stats[compptr->dc_tbl_no], DC_STAT_BINS);
|
||||
/* Reset DC predictions to 0 */
|
||||
entropy->last_dc_val[ci] = 0;
|
||||
entropy->dc_context[ci] = 0;
|
||||
}
|
||||
/* AC needs no table when not present */
|
||||
if (cinfo->Se) {
|
||||
MEMZERO(entropy->ac_stats[compptr->ac_tbl_no], AC_STAT_BINS);
|
||||
}
|
||||
}
|
||||
|
||||
/* Reset arithmetic encoding variables */
|
||||
entropy->c = 0;
|
||||
entropy->a = 0x10000L;
|
||||
entropy->sc = 0;
|
||||
entropy->zc = 0;
|
||||
entropy->ct = 11;
|
||||
entropy->buffer = -1; /* empty */
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* MCU encoding for DC initial scan (either spectral selection,
|
||||
* or first pass of successive approximation).
|
||||
*/
|
||||
|
||||
METHODDEF(boolean)
|
||||
encode_mcu_DC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
|
||||
{
|
||||
arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy;
|
||||
JBLOCKROW block;
|
||||
unsigned char *st;
|
||||
int blkn, ci, tbl;
|
||||
int v, v2, m;
|
||||
ISHIFT_TEMPS
|
||||
|
||||
/* Emit restart marker if needed */
|
||||
if (cinfo->restart_interval) {
|
||||
if (entropy->restarts_to_go == 0) {
|
||||
emit_restart(cinfo, entropy->next_restart_num);
|
||||
entropy->restarts_to_go = cinfo->restart_interval;
|
||||
entropy->next_restart_num++;
|
||||
entropy->next_restart_num &= 7;
|
||||
}
|
||||
entropy->restarts_to_go--;
|
||||
}
|
||||
|
||||
/* Encode the MCU data blocks */
|
||||
for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
|
||||
block = MCU_data[blkn];
|
||||
ci = cinfo->MCU_membership[blkn];
|
||||
tbl = cinfo->cur_comp_info[ci]->dc_tbl_no;
|
||||
|
||||
/* Compute the DC value after the required point transform by Al.
|
||||
* This is simply an arithmetic right shift.
|
||||
*/
|
||||
m = IRIGHT_SHIFT((int) ((*block)[0]), cinfo->Al);
|
||||
|
||||
/* Sections F.1.4.1 & F.1.4.4.1: Encoding of DC coefficients */
|
||||
|
||||
/* Table F.4: Point to statistics bin S0 for DC coefficient coding */
|
||||
st = entropy->dc_stats[tbl] + entropy->dc_context[ci];
|
||||
|
||||
/* Figure F.4: Encode_DC_DIFF */
|
||||
if ((v = m - entropy->last_dc_val[ci]) == 0) {
|
||||
arith_encode(cinfo, st, 0);
|
||||
entropy->dc_context[ci] = 0; /* zero diff category */
|
||||
} else {
|
||||
entropy->last_dc_val[ci] = m;
|
||||
arith_encode(cinfo, st, 1);
|
||||
/* Figure F.6: Encoding nonzero value v */
|
||||
/* Figure F.7: Encoding the sign of v */
|
||||
if (v > 0) {
|
||||
arith_encode(cinfo, st + 1, 0); /* Table F.4: SS = S0 + 1 */
|
||||
st += 2; /* Table F.4: SP = S0 + 2 */
|
||||
entropy->dc_context[ci] = 4; /* small positive diff category */
|
||||
} else {
|
||||
v = -v;
|
||||
arith_encode(cinfo, st + 1, 1); /* Table F.4: SS = S0 + 1 */
|
||||
st += 3; /* Table F.4: SN = S0 + 3 */
|
||||
entropy->dc_context[ci] = 8; /* small negative diff category */
|
||||
}
|
||||
/* Figure F.8: Encoding the magnitude category of v */
|
||||
m = 0;
|
||||
if (v -= 1) {
|
||||
arith_encode(cinfo, st, 1);
|
||||
m = 1;
|
||||
v2 = v;
|
||||
st = entropy->dc_stats[tbl] + 20; /* Table F.4: X1 = 20 */
|
||||
while (v2 >>= 1) {
|
||||
arith_encode(cinfo, st, 1);
|
||||
m <<= 1;
|
||||
st += 1;
|
||||
}
|
||||
}
|
||||
arith_encode(cinfo, st, 0);
|
||||
/* Section F.1.4.4.1.2: Establish dc_context conditioning category */
|
||||
if (m < (int) ((1L << cinfo->arith_dc_L[tbl]) >> 1))
|
||||
entropy->dc_context[ci] = 0; /* zero diff category */
|
||||
else if (m > (int) ((1L << cinfo->arith_dc_U[tbl]) >> 1))
|
||||
entropy->dc_context[ci] += 8; /* large diff category */
|
||||
/* Figure F.9: Encoding the magnitude bit pattern of v */
|
||||
st += 14;
|
||||
while (m >>= 1)
|
||||
arith_encode(cinfo, st, (m & v) ? 1 : 0);
|
||||
}
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* MCU encoding for AC initial scan (either spectral selection,
|
||||
* or first pass of successive approximation).
|
||||
*/
|
||||
|
||||
METHODDEF(boolean)
|
||||
encode_mcu_AC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
|
||||
{
|
||||
arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy;
|
||||
JBLOCKROW block;
|
||||
unsigned char *st;
|
||||
int tbl, k, ke;
|
||||
int v, v2, m;
|
||||
const int * natural_order;
|
||||
|
||||
/* Emit restart marker if needed */
|
||||
if (cinfo->restart_interval) {
|
||||
if (entropy->restarts_to_go == 0) {
|
||||
emit_restart(cinfo, entropy->next_restart_num);
|
||||
entropy->restarts_to_go = cinfo->restart_interval;
|
||||
entropy->next_restart_num++;
|
||||
entropy->next_restart_num &= 7;
|
||||
}
|
||||
entropy->restarts_to_go--;
|
||||
}
|
||||
|
||||
natural_order = cinfo->natural_order;
|
||||
|
||||
/* Encode the MCU data block */
|
||||
block = MCU_data[0];
|
||||
tbl = cinfo->cur_comp_info[0]->ac_tbl_no;
|
||||
|
||||
/* Sections F.1.4.2 & F.1.4.4.2: Encoding of AC coefficients */
|
||||
|
||||
/* Establish EOB (end-of-block) index */
|
||||
ke = cinfo->Se;
|
||||
do {
|
||||
/* We must apply the point transform by Al. For AC coefficients this
|
||||
* is an integer division with rounding towards 0. To do this portably
|
||||
* in C, we shift after obtaining the absolute value.
|
||||
*/
|
||||
if ((v = (*block)[natural_order[ke]]) >= 0) {
|
||||
if (v >>= cinfo->Al) break;
|
||||
} else {
|
||||
v = -v;
|
||||
if (v >>= cinfo->Al) break;
|
||||
}
|
||||
} while (--ke);
|
||||
|
||||
/* Figure F.5: Encode_AC_Coefficients */
|
||||
for (k = cinfo->Ss - 1; k < ke;) {
|
||||
st = entropy->ac_stats[tbl] + 3 * k;
|
||||
arith_encode(cinfo, st, 0); /* EOB decision */
|
||||
for (;;) {
|
||||
if ((v = (*block)[natural_order[++k]]) >= 0) {
|
||||
if (v >>= cinfo->Al) {
|
||||
arith_encode(cinfo, st + 1, 1);
|
||||
arith_encode(cinfo, entropy->fixed_bin, 0);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
v = -v;
|
||||
if (v >>= cinfo->Al) {
|
||||
arith_encode(cinfo, st + 1, 1);
|
||||
arith_encode(cinfo, entropy->fixed_bin, 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
arith_encode(cinfo, st + 1, 0);
|
||||
st += 3;
|
||||
}
|
||||
st += 2;
|
||||
/* Figure F.8: Encoding the magnitude category of v */
|
||||
m = 0;
|
||||
if (v -= 1) {
|
||||
arith_encode(cinfo, st, 1);
|
||||
m = 1;
|
||||
v2 = v;
|
||||
if (v2 >>= 1) {
|
||||
arith_encode(cinfo, st, 1);
|
||||
m <<= 1;
|
||||
st = entropy->ac_stats[tbl] +
|
||||
(k <= cinfo->arith_ac_K[tbl] ? 189 : 217);
|
||||
while (v2 >>= 1) {
|
||||
arith_encode(cinfo, st, 1);
|
||||
m <<= 1;
|
||||
st += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
arith_encode(cinfo, st, 0);
|
||||
/* Figure F.9: Encoding the magnitude bit pattern of v */
|
||||
st += 14;
|
||||
while (m >>= 1)
|
||||
arith_encode(cinfo, st, (m & v) ? 1 : 0);
|
||||
}
|
||||
/* Encode EOB decision only if k < cinfo->Se */
|
||||
if (k < cinfo->Se) {
|
||||
st = entropy->ac_stats[tbl] + 3 * k;
|
||||
arith_encode(cinfo, st, 1);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* MCU encoding for DC successive approximation refinement scan.
|
||||
*/
|
||||
|
||||
METHODDEF(boolean)
|
||||
encode_mcu_DC_refine (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
|
||||
{
|
||||
arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy;
|
||||
unsigned char *st;
|
||||
int Al, blkn;
|
||||
|
||||
/* Emit restart marker if needed */
|
||||
if (cinfo->restart_interval) {
|
||||
if (entropy->restarts_to_go == 0) {
|
||||
emit_restart(cinfo, entropy->next_restart_num);
|
||||
entropy->restarts_to_go = cinfo->restart_interval;
|
||||
entropy->next_restart_num++;
|
||||
entropy->next_restart_num &= 7;
|
||||
}
|
||||
entropy->restarts_to_go--;
|
||||
}
|
||||
|
||||
st = entropy->fixed_bin; /* use fixed probability estimation */
|
||||
Al = cinfo->Al;
|
||||
|
||||
/* Encode the MCU data blocks */
|
||||
for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
|
||||
/* We simply emit the Al'th bit of the DC coefficient value. */
|
||||
arith_encode(cinfo, st, (MCU_data[blkn][0][0] >> Al) & 1);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* MCU encoding for AC successive approximation refinement scan.
|
||||
*/
|
||||
|
||||
METHODDEF(boolean)
|
||||
encode_mcu_AC_refine (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
|
||||
{
|
||||
arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy;
|
||||
JBLOCKROW block;
|
||||
unsigned char *st;
|
||||
int tbl, k, ke, kex;
|
||||
int v;
|
||||
const int * natural_order;
|
||||
|
||||
/* Emit restart marker if needed */
|
||||
if (cinfo->restart_interval) {
|
||||
if (entropy->restarts_to_go == 0) {
|
||||
emit_restart(cinfo, entropy->next_restart_num);
|
||||
entropy->restarts_to_go = cinfo->restart_interval;
|
||||
entropy->next_restart_num++;
|
||||
entropy->next_restart_num &= 7;
|
||||
}
|
||||
entropy->restarts_to_go--;
|
||||
}
|
||||
|
||||
natural_order = cinfo->natural_order;
|
||||
|
||||
/* Encode the MCU data block */
|
||||
block = MCU_data[0];
|
||||
tbl = cinfo->cur_comp_info[0]->ac_tbl_no;
|
||||
|
||||
/* Section G.1.3.3: Encoding of AC coefficients */
|
||||
|
||||
/* Establish EOB (end-of-block) index */
|
||||
ke = cinfo->Se;
|
||||
do {
|
||||
/* We must apply the point transform by Al. For AC coefficients this
|
||||
* is an integer division with rounding towards 0. To do this portably
|
||||
* in C, we shift after obtaining the absolute value.
|
||||
*/
|
||||
if ((v = (*block)[natural_order[ke]]) >= 0) {
|
||||
if (v >>= cinfo->Al) break;
|
||||
} else {
|
||||
v = -v;
|
||||
if (v >>= cinfo->Al) break;
|
||||
}
|
||||
} while (--ke);
|
||||
|
||||
/* Establish EOBx (previous stage end-of-block) index */
|
||||
for (kex = ke; kex > 0; kex--)
|
||||
if ((v = (*block)[natural_order[kex]]) >= 0) {
|
||||
if (v >>= cinfo->Ah) break;
|
||||
} else {
|
||||
v = -v;
|
||||
if (v >>= cinfo->Ah) break;
|
||||
}
|
||||
|
||||
/* Figure G.10: Encode_AC_Coefficients_SA */
|
||||
for (k = cinfo->Ss - 1; k < ke;) {
|
||||
st = entropy->ac_stats[tbl] + 3 * k;
|
||||
if (k >= kex)
|
||||
arith_encode(cinfo, st, 0); /* EOB decision */
|
||||
for (;;) {
|
||||
if ((v = (*block)[natural_order[++k]]) >= 0) {
|
||||
if (v >>= cinfo->Al) {
|
||||
if (v >> 1) /* previously nonzero coef */
|
||||
arith_encode(cinfo, st + 2, (v & 1));
|
||||
else { /* newly nonzero coef */
|
||||
arith_encode(cinfo, st + 1, 1);
|
||||
arith_encode(cinfo, entropy->fixed_bin, 0);
|
||||
}
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
v = -v;
|
||||
if (v >>= cinfo->Al) {
|
||||
if (v >> 1) /* previously nonzero coef */
|
||||
arith_encode(cinfo, st + 2, (v & 1));
|
||||
else { /* newly nonzero coef */
|
||||
arith_encode(cinfo, st + 1, 1);
|
||||
arith_encode(cinfo, entropy->fixed_bin, 1);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
arith_encode(cinfo, st + 1, 0);
|
||||
st += 3;
|
||||
}
|
||||
}
|
||||
/* Encode EOB decision only if k < cinfo->Se */
|
||||
if (k < cinfo->Se) {
|
||||
st = entropy->ac_stats[tbl] + 3 * k;
|
||||
arith_encode(cinfo, st, 1);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Encode and output one MCU's worth of arithmetic-compressed coefficients.
|
||||
*/
|
||||
|
||||
METHODDEF(boolean)
|
||||
encode_mcu (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
|
||||
{
|
||||
arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy;
|
||||
jpeg_component_info * compptr;
|
||||
JBLOCKROW block;
|
||||
unsigned char *st;
|
||||
int blkn, ci, tbl, k, ke;
|
||||
int v, v2, m;
|
||||
const int * natural_order;
|
||||
|
||||
/* Emit restart marker if needed */
|
||||
if (cinfo->restart_interval) {
|
||||
if (entropy->restarts_to_go == 0) {
|
||||
emit_restart(cinfo, entropy->next_restart_num);
|
||||
entropy->restarts_to_go = cinfo->restart_interval;
|
||||
entropy->next_restart_num++;
|
||||
entropy->next_restart_num &= 7;
|
||||
}
|
||||
entropy->restarts_to_go--;
|
||||
}
|
||||
|
||||
natural_order = cinfo->natural_order;
|
||||
|
||||
/* Encode the MCU data blocks */
|
||||
for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
|
||||
block = MCU_data[blkn];
|
||||
ci = cinfo->MCU_membership[blkn];
|
||||
compptr = cinfo->cur_comp_info[ci];
|
||||
|
||||
/* Sections F.1.4.1 & F.1.4.4.1: Encoding of DC coefficients */
|
||||
|
||||
tbl = compptr->dc_tbl_no;
|
||||
|
||||
/* Table F.4: Point to statistics bin S0 for DC coefficient coding */
|
||||
st = entropy->dc_stats[tbl] + entropy->dc_context[ci];
|
||||
|
||||
/* Figure F.4: Encode_DC_DIFF */
|
||||
if ((v = (*block)[0] - entropy->last_dc_val[ci]) == 0) {
|
||||
arith_encode(cinfo, st, 0);
|
||||
entropy->dc_context[ci] = 0; /* zero diff category */
|
||||
} else {
|
||||
entropy->last_dc_val[ci] = (*block)[0];
|
||||
arith_encode(cinfo, st, 1);
|
||||
/* Figure F.6: Encoding nonzero value v */
|
||||
/* Figure F.7: Encoding the sign of v */
|
||||
if (v > 0) {
|
||||
arith_encode(cinfo, st + 1, 0); /* Table F.4: SS = S0 + 1 */
|
||||
st += 2; /* Table F.4: SP = S0 + 2 */
|
||||
entropy->dc_context[ci] = 4; /* small positive diff category */
|
||||
} else {
|
||||
v = -v;
|
||||
arith_encode(cinfo, st + 1, 1); /* Table F.4: SS = S0 + 1 */
|
||||
st += 3; /* Table F.4: SN = S0 + 3 */
|
||||
entropy->dc_context[ci] = 8; /* small negative diff category */
|
||||
}
|
||||
/* Figure F.8: Encoding the magnitude category of v */
|
||||
m = 0;
|
||||
if (v -= 1) {
|
||||
arith_encode(cinfo, st, 1);
|
||||
m = 1;
|
||||
v2 = v;
|
||||
st = entropy->dc_stats[tbl] + 20; /* Table F.4: X1 = 20 */
|
||||
while (v2 >>= 1) {
|
||||
arith_encode(cinfo, st, 1);
|
||||
m <<= 1;
|
||||
st += 1;
|
||||
}
|
||||
}
|
||||
arith_encode(cinfo, st, 0);
|
||||
/* Section F.1.4.4.1.2: Establish dc_context conditioning category */
|
||||
if (m < (int) ((1L << cinfo->arith_dc_L[tbl]) >> 1))
|
||||
entropy->dc_context[ci] = 0; /* zero diff category */
|
||||
else if (m > (int) ((1L << cinfo->arith_dc_U[tbl]) >> 1))
|
||||
entropy->dc_context[ci] += 8; /* large diff category */
|
||||
/* Figure F.9: Encoding the magnitude bit pattern of v */
|
||||
st += 14;
|
||||
while (m >>= 1)
|
||||
arith_encode(cinfo, st, (m & v) ? 1 : 0);
|
||||
}
|
||||
|
||||
/* Sections F.1.4.2 & F.1.4.4.2: Encoding of AC coefficients */
|
||||
|
||||
if ((ke = cinfo->lim_Se) == 0) continue;
|
||||
tbl = compptr->ac_tbl_no;
|
||||
|
||||
/* Establish EOB (end-of-block) index */
|
||||
do {
|
||||
if ((*block)[natural_order[ke]]) break;
|
||||
} while (--ke);
|
||||
|
||||
/* Figure F.5: Encode_AC_Coefficients */
|
||||
for (k = 0; k < ke;) {
|
||||
st = entropy->ac_stats[tbl] + 3 * k;
|
||||
arith_encode(cinfo, st, 0); /* EOB decision */
|
||||
while ((v = (*block)[natural_order[++k]]) == 0) {
|
||||
arith_encode(cinfo, st + 1, 0);
|
||||
st += 3;
|
||||
}
|
||||
arith_encode(cinfo, st + 1, 1);
|
||||
/* Figure F.6: Encoding nonzero value v */
|
||||
/* Figure F.7: Encoding the sign of v */
|
||||
if (v > 0) {
|
||||
arith_encode(cinfo, entropy->fixed_bin, 0);
|
||||
} else {
|
||||
v = -v;
|
||||
arith_encode(cinfo, entropy->fixed_bin, 1);
|
||||
}
|
||||
st += 2;
|
||||
/* Figure F.8: Encoding the magnitude category of v */
|
||||
m = 0;
|
||||
if (v -= 1) {
|
||||
arith_encode(cinfo, st, 1);
|
||||
m = 1;
|
||||
v2 = v;
|
||||
if (v2 >>= 1) {
|
||||
arith_encode(cinfo, st, 1);
|
||||
m <<= 1;
|
||||
st = entropy->ac_stats[tbl] +
|
||||
(k <= cinfo->arith_ac_K[tbl] ? 189 : 217);
|
||||
while (v2 >>= 1) {
|
||||
arith_encode(cinfo, st, 1);
|
||||
m <<= 1;
|
||||
st += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
arith_encode(cinfo, st, 0);
|
||||
/* Figure F.9: Encoding the magnitude bit pattern of v */
|
||||
st += 14;
|
||||
while (m >>= 1)
|
||||
arith_encode(cinfo, st, (m & v) ? 1 : 0);
|
||||
}
|
||||
/* Encode EOB decision only if k < cinfo->lim_Se */
|
||||
if (k < cinfo->lim_Se) {
|
||||
st = entropy->ac_stats[tbl] + 3 * k;
|
||||
arith_encode(cinfo, st, 1);
|
||||
}
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Initialize for an arithmetic-compressed scan.
|
||||
*/
|
||||
|
||||
METHODDEF(void)
|
||||
start_pass (j_compress_ptr cinfo, boolean gather_statistics)
|
||||
{
|
||||
arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy;
|
||||
int ci, tbl;
|
||||
jpeg_component_info * compptr;
|
||||
|
||||
if (gather_statistics)
|
||||
/* Make sure to avoid that in the master control logic!
|
||||
* We are fully adaptive here and need no extra
|
||||
* statistics gathering pass!
|
||||
*/
|
||||
ERREXIT(cinfo, JERR_NOT_COMPILED);
|
||||
|
||||
/* We assume jcmaster.c already validated the progressive scan parameters. */
|
||||
|
||||
/* Select execution routines */
|
||||
if (cinfo->progressive_mode) {
|
||||
if (cinfo->Ah == 0) {
|
||||
if (cinfo->Ss == 0)
|
||||
entropy->pub.encode_mcu = encode_mcu_DC_first;
|
||||
else
|
||||
entropy->pub.encode_mcu = encode_mcu_AC_first;
|
||||
} else {
|
||||
if (cinfo->Ss == 0)
|
||||
entropy->pub.encode_mcu = encode_mcu_DC_refine;
|
||||
else
|
||||
entropy->pub.encode_mcu = encode_mcu_AC_refine;
|
||||
}
|
||||
} else
|
||||
entropy->pub.encode_mcu = encode_mcu;
|
||||
|
||||
/* Allocate & initialize requested statistics areas */
|
||||
for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
|
||||
compptr = cinfo->cur_comp_info[ci];
|
||||
/* DC needs no table for refinement scan */
|
||||
if (cinfo->Ss == 0 && cinfo->Ah == 0) {
|
||||
tbl = compptr->dc_tbl_no;
|
||||
if (tbl < 0 || tbl >= NUM_ARITH_TBLS)
|
||||
ERREXIT1(cinfo, JERR_NO_ARITH_TABLE, tbl);
|
||||
if (entropy->dc_stats[tbl] == NULL)
|
||||
entropy->dc_stats[tbl] = (unsigned char *) (*cinfo->mem->alloc_small)
|
||||
((j_common_ptr) cinfo, JPOOL_IMAGE, DC_STAT_BINS);
|
||||
MEMZERO(entropy->dc_stats[tbl], DC_STAT_BINS);
|
||||
/* Initialize DC predictions to 0 */
|
||||
entropy->last_dc_val[ci] = 0;
|
||||
entropy->dc_context[ci] = 0;
|
||||
}
|
||||
/* AC needs no table when not present */
|
||||
if (cinfo->Se) {
|
||||
tbl = compptr->ac_tbl_no;
|
||||
if (tbl < 0 || tbl >= NUM_ARITH_TBLS)
|
||||
ERREXIT1(cinfo, JERR_NO_ARITH_TABLE, tbl);
|
||||
if (entropy->ac_stats[tbl] == NULL)
|
||||
entropy->ac_stats[tbl] = (unsigned char *) (*cinfo->mem->alloc_small)
|
||||
((j_common_ptr) cinfo, JPOOL_IMAGE, AC_STAT_BINS);
|
||||
MEMZERO(entropy->ac_stats[tbl], AC_STAT_BINS);
|
||||
#ifdef CALCULATE_SPECTRAL_CONDITIONING
|
||||
if (cinfo->progressive_mode)
|
||||
/* Section G.1.3.2: Set appropriate arithmetic conditioning value Kx */
|
||||
cinfo->arith_ac_K[tbl] = cinfo->Ss + ((8 + cinfo->Se - cinfo->Ss) >> 4);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
/* Initialize arithmetic encoding variables */
|
||||
entropy->c = 0;
|
||||
entropy->a = 0x10000L;
|
||||
entropy->sc = 0;
|
||||
entropy->zc = 0;
|
||||
entropy->ct = 11;
|
||||
entropy->buffer = -1; /* empty */
|
||||
|
||||
/* Initialize restart stuff */
|
||||
entropy->restarts_to_go = cinfo->restart_interval;
|
||||
entropy->next_restart_num = 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Module initialization routine for arithmetic entropy encoding.
|
||||
*/
|
||||
|
||||
GLOBAL(void)
|
||||
jinit_arith_encoder (j_compress_ptr cinfo)
|
||||
{
|
||||
arith_entropy_ptr entropy;
|
||||
int i;
|
||||
|
||||
entropy = (arith_entropy_ptr)
|
||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
||||
SIZEOF(arith_entropy_encoder));
|
||||
cinfo->entropy = &entropy->pub;
|
||||
entropy->pub.start_pass = start_pass;
|
||||
entropy->pub.finish_pass = finish_pass;
|
||||
|
||||
/* Mark tables unallocated */
|
||||
for (i = 0; i < NUM_ARITH_TBLS; i++) {
|
||||
entropy->dc_stats[i] = NULL;
|
||||
entropy->ac_stats[i] = NULL;
|
||||
}
|
||||
|
||||
/* Initialize index for fixed probability estimation */
|
||||
entropy->fixed_bin[0] = 113;
|
||||
}
|
165
3rdparty/libjpeg/jccoefct.c
vendored
165
3rdparty/libjpeg/jccoefct.c
vendored
@ -2,6 +2,7 @@
|
||||
* jccoefct.c
|
||||
*
|
||||
* Copyright (C) 1994-1997, Thomas G. Lane.
|
||||
* Modified 2003-2011 by Guido Vollbeding.
|
||||
* This file is part of the Independent JPEG Group's software.
|
||||
* For conditions of distribution and use, see the accompanying README file.
|
||||
*
|
||||
@ -149,12 +150,13 @@ compress_data (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
|
||||
int blkn, bi, ci, yindex, yoffset, blockcnt;
|
||||
JDIMENSION ypos, xpos;
|
||||
jpeg_component_info *compptr;
|
||||
forward_DCT_ptr forward_DCT;
|
||||
|
||||
/* Loop to write as much as one whole iMCU row */
|
||||
for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
|
||||
yoffset++) {
|
||||
for (MCU_col_num = coef->mcu_ctr; MCU_col_num <= last_MCU_col;
|
||||
MCU_col_num++) {
|
||||
MCU_col_num++) {
|
||||
/* Determine where data comes from in input_buf and do the DCT thing.
|
||||
* Each call on forward_DCT processes a horizontal row of DCT blocks
|
||||
* as wide as an MCU; we rely on having allocated the MCU_buffer[] blocks
|
||||
@ -166,46 +168,48 @@ compress_data (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
|
||||
*/
|
||||
blkn = 0;
|
||||
for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
|
||||
compptr = cinfo->cur_comp_info[ci];
|
||||
blockcnt = (MCU_col_num < last_MCU_col) ? compptr->MCU_width
|
||||
: compptr->last_col_width;
|
||||
xpos = MCU_col_num * compptr->MCU_sample_width;
|
||||
ypos = yoffset * DCTSIZE; /* ypos == (yoffset+yindex) * DCTSIZE */
|
||||
for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
|
||||
if (coef->iMCU_row_num < last_iMCU_row ||
|
||||
yoffset+yindex < compptr->last_row_height) {
|
||||
(*cinfo->fdct->forward_DCT) (cinfo, compptr,
|
||||
input_buf[compptr->component_index],
|
||||
coef->MCU_buffer[blkn],
|
||||
ypos, xpos, (JDIMENSION) blockcnt);
|
||||
if (blockcnt < compptr->MCU_width) {
|
||||
/* Create some dummy blocks at the right edge of the image. */
|
||||
jzero_far((void FAR *) coef->MCU_buffer[blkn + blockcnt],
|
||||
(compptr->MCU_width - blockcnt) * SIZEOF(JBLOCK));
|
||||
for (bi = blockcnt; bi < compptr->MCU_width; bi++) {
|
||||
coef->MCU_buffer[blkn+bi][0][0] = coef->MCU_buffer[blkn+bi-1][0][0];
|
||||
compptr = cinfo->cur_comp_info[ci];
|
||||
forward_DCT = cinfo->fdct->forward_DCT[compptr->component_index];
|
||||
blockcnt = (MCU_col_num < last_MCU_col) ? compptr->MCU_width
|
||||
: compptr->last_col_width;
|
||||
xpos = MCU_col_num * compptr->MCU_sample_width;
|
||||
ypos = yoffset * compptr->DCT_v_scaled_size;
|
||||
/* ypos == (yoffset+yindex) * DCTSIZE */
|
||||
for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
|
||||
if (coef->iMCU_row_num < last_iMCU_row ||
|
||||
yoffset+yindex < compptr->last_row_height) {
|
||||
(*forward_DCT) (cinfo, compptr,
|
||||
input_buf[compptr->component_index],
|
||||
coef->MCU_buffer[blkn],
|
||||
ypos, xpos, (JDIMENSION) blockcnt);
|
||||
if (blockcnt < compptr->MCU_width) {
|
||||
/* Create some dummy blocks at the right edge of the image. */
|
||||
FMEMZERO((void FAR *) coef->MCU_buffer[blkn + blockcnt],
|
||||
(compptr->MCU_width - blockcnt) * SIZEOF(JBLOCK));
|
||||
for (bi = blockcnt; bi < compptr->MCU_width; bi++) {
|
||||
coef->MCU_buffer[blkn+bi][0][0] = coef->MCU_buffer[blkn+bi-1][0][0];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
/* Create a row of dummy blocks at the bottom of the image. */
|
||||
FMEMZERO((void FAR *) coef->MCU_buffer[blkn],
|
||||
compptr->MCU_width * SIZEOF(JBLOCK));
|
||||
for (bi = 0; bi < compptr->MCU_width; bi++) {
|
||||
coef->MCU_buffer[blkn+bi][0][0] = coef->MCU_buffer[blkn-1][0][0];
|
||||
}
|
||||
}
|
||||
blkn += compptr->MCU_width;
|
||||
ypos += compptr->DCT_v_scaled_size;
|
||||
}
|
||||
} else {
|
||||
/* Create a row of dummy blocks at the bottom of the image. */
|
||||
jzero_far((void FAR *) coef->MCU_buffer[blkn],
|
||||
compptr->MCU_width * SIZEOF(JBLOCK));
|
||||
for (bi = 0; bi < compptr->MCU_width; bi++) {
|
||||
coef->MCU_buffer[blkn+bi][0][0] = coef->MCU_buffer[blkn-1][0][0];
|
||||
}
|
||||
}
|
||||
blkn += compptr->MCU_width;
|
||||
ypos += DCTSIZE;
|
||||
}
|
||||
}
|
||||
/* Try to write the MCU. In event of a suspension failure, we will
|
||||
* re-DCT the MCU on restart (a bit inefficient, could be fixed...)
|
||||
*/
|
||||
if (! (*cinfo->entropy->encode_mcu) (cinfo, coef->MCU_buffer)) {
|
||||
/* Suspension forced; update state counters and exit */
|
||||
coef->MCU_vert_offset = yoffset;
|
||||
coef->mcu_ctr = MCU_col_num;
|
||||
return FALSE;
|
||||
/* Suspension forced; update state counters and exit */
|
||||
coef->MCU_vert_offset = yoffset;
|
||||
coef->mcu_ctr = MCU_col_num;
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
/* Completed an MCU row, but perhaps not an iMCU row */
|
||||
@ -252,6 +256,7 @@ compress_first_pass (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
|
||||
jpeg_component_info *compptr;
|
||||
JBLOCKARRAY buffer;
|
||||
JBLOCKROW thisblockrow, lastblockrow;
|
||||
forward_DCT_ptr forward_DCT;
|
||||
|
||||
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
|
||||
ci++, compptr++) {
|
||||
@ -274,23 +279,23 @@ compress_first_pass (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
|
||||
ndummy = (int) (blocks_across % h_samp_factor);
|
||||
if (ndummy > 0)
|
||||
ndummy = h_samp_factor - ndummy;
|
||||
forward_DCT = cinfo->fdct->forward_DCT[ci];
|
||||
/* Perform DCT for all non-dummy blocks in this iMCU row. Each call
|
||||
* on forward_DCT processes a complete horizontal row of DCT blocks.
|
||||
*/
|
||||
for (block_row = 0; block_row < block_rows; block_row++) {
|
||||
thisblockrow = buffer[block_row];
|
||||
(*cinfo->fdct->forward_DCT) (cinfo, compptr,
|
||||
input_buf[ci], thisblockrow,
|
||||
(JDIMENSION) (block_row * DCTSIZE),
|
||||
(JDIMENSION) 0, blocks_across);
|
||||
(*forward_DCT) (cinfo, compptr, input_buf[ci], thisblockrow,
|
||||
(JDIMENSION) (block_row * compptr->DCT_v_scaled_size),
|
||||
(JDIMENSION) 0, blocks_across);
|
||||
if (ndummy > 0) {
|
||||
/* Create dummy blocks at the right edge of the image. */
|
||||
thisblockrow += blocks_across; /* => first dummy block */
|
||||
jzero_far((void FAR *) thisblockrow, ndummy * SIZEOF(JBLOCK));
|
||||
lastDC = thisblockrow[-1][0];
|
||||
for (bi = 0; bi < ndummy; bi++) {
|
||||
thisblockrow[bi][0] = lastDC;
|
||||
}
|
||||
/* Create dummy blocks at the right edge of the image. */
|
||||
thisblockrow += blocks_across; /* => first dummy block */
|
||||
FMEMZERO((void FAR *) thisblockrow, ndummy * SIZEOF(JBLOCK));
|
||||
lastDC = thisblockrow[-1][0];
|
||||
for (bi = 0; bi < ndummy; bi++) {
|
||||
thisblockrow[bi][0] = lastDC;
|
||||
}
|
||||
}
|
||||
}
|
||||
/* If at end of image, create dummy block rows as needed.
|
||||
@ -302,19 +307,19 @@ compress_first_pass (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
|
||||
blocks_across += ndummy; /* include lower right corner */
|
||||
MCUs_across = blocks_across / h_samp_factor;
|
||||
for (block_row = block_rows; block_row < compptr->v_samp_factor;
|
||||
block_row++) {
|
||||
thisblockrow = buffer[block_row];
|
||||
lastblockrow = buffer[block_row-1];
|
||||
jzero_far((void FAR *) thisblockrow,
|
||||
(size_t) (blocks_across * SIZEOF(JBLOCK)));
|
||||
for (MCUindex = 0; MCUindex < MCUs_across; MCUindex++) {
|
||||
lastDC = lastblockrow[h_samp_factor-1][0];
|
||||
for (bi = 0; bi < h_samp_factor; bi++) {
|
||||
thisblockrow[bi][0] = lastDC;
|
||||
}
|
||||
thisblockrow += h_samp_factor; /* advance to next MCU in row */
|
||||
lastblockrow += h_samp_factor;
|
||||
}
|
||||
block_row++) {
|
||||
thisblockrow = buffer[block_row];
|
||||
lastblockrow = buffer[block_row-1];
|
||||
FMEMZERO((void FAR *) thisblockrow,
|
||||
(size_t) (blocks_across * SIZEOF(JBLOCK)));
|
||||
for (MCUindex = 0; MCUindex < MCUs_across; MCUindex++) {
|
||||
lastDC = lastblockrow[h_samp_factor-1][0];
|
||||
for (bi = 0; bi < h_samp_factor; bi++) {
|
||||
thisblockrow[bi][0] = lastDC;
|
||||
}
|
||||
thisblockrow += h_samp_factor; /* advance to next MCU in row */
|
||||
lastblockrow += h_samp_factor;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -364,25 +369,25 @@ compress_output (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
|
||||
for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
|
||||
yoffset++) {
|
||||
for (MCU_col_num = coef->mcu_ctr; MCU_col_num < cinfo->MCUs_per_row;
|
||||
MCU_col_num++) {
|
||||
MCU_col_num++) {
|
||||
/* Construct list of pointers to DCT blocks belonging to this MCU */
|
||||
blkn = 0; /* index of current DCT block within MCU */
|
||||
for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
|
||||
compptr = cinfo->cur_comp_info[ci];
|
||||
start_col = MCU_col_num * compptr->MCU_width;
|
||||
for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
|
||||
buffer_ptr = buffer[ci][yindex+yoffset] + start_col;
|
||||
for (xindex = 0; xindex < compptr->MCU_width; xindex++) {
|
||||
coef->MCU_buffer[blkn++] = buffer_ptr++;
|
||||
}
|
||||
}
|
||||
compptr = cinfo->cur_comp_info[ci];
|
||||
start_col = MCU_col_num * compptr->MCU_width;
|
||||
for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
|
||||
buffer_ptr = buffer[ci][yindex+yoffset] + start_col;
|
||||
for (xindex = 0; xindex < compptr->MCU_width; xindex++) {
|
||||
coef->MCU_buffer[blkn++] = buffer_ptr++;
|
||||
}
|
||||
}
|
||||
}
|
||||
/* Try to write the MCU. */
|
||||
if (! (*cinfo->entropy->encode_mcu) (cinfo, coef->MCU_buffer)) {
|
||||
/* Suspension forced; update state counters and exit */
|
||||
coef->MCU_vert_offset = yoffset;
|
||||
coef->mcu_ctr = MCU_col_num;
|
||||
return FALSE;
|
||||
/* Suspension forced; update state counters and exit */
|
||||
coef->MCU_vert_offset = yoffset;
|
||||
coef->mcu_ctr = MCU_col_num;
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
/* Completed an MCU row, but perhaps not an iMCU row */
|
||||
@ -408,7 +413,7 @@ jinit_c_coef_controller (j_compress_ptr cinfo, boolean need_full_buffer)
|
||||
|
||||
coef = (my_coef_ptr)
|
||||
(*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;
|
||||
coef->pub.start_pass = start_pass_coef;
|
||||
|
||||
@ -421,14 +426,14 @@ jinit_c_coef_controller (j_compress_ptr cinfo, boolean need_full_buffer)
|
||||
jpeg_component_info *compptr;
|
||||
|
||||
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
|
||||
ci++, compptr++) {
|
||||
ci++, compptr++) {
|
||||
coef->whole_image[ci] = (*cinfo->mem->request_virt_barray)
|
||||
((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE,
|
||||
(JDIMENSION) jround_up((long) compptr->width_in_blocks,
|
||||
(long) compptr->h_samp_factor),
|
||||
(JDIMENSION) jround_up((long) compptr->height_in_blocks,
|
||||
(long) compptr->v_samp_factor),
|
||||
(JDIMENSION) compptr->v_samp_factor);
|
||||
((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE,
|
||||
(JDIMENSION) jround_up((long) compptr->width_in_blocks,
|
||||
(long) compptr->h_samp_factor),
|
||||
(JDIMENSION) jround_up((long) compptr->height_in_blocks,
|
||||
(long) compptr->v_samp_factor),
|
||||
(JDIMENSION) compptr->v_samp_factor);
|
||||
}
|
||||
#else
|
||||
ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
|
||||
@ -440,7 +445,7 @@ jinit_c_coef_controller (j_compress_ptr cinfo, boolean need_full_buffer)
|
||||
|
||||
buffer = (JBLOCKROW)
|
||||
(*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
||||
C_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK));
|
||||
C_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK));
|
||||
for (i = 0; i < C_MAX_BLOCKS_IN_MCU; i++) {
|
||||
coef->MCU_buffer[i] = buffer + i;
|
||||
}
|
||||
|
188
3rdparty/libjpeg/jccolor.c
vendored
188
3rdparty/libjpeg/jccolor.c
vendored
@ -2,6 +2,7 @@
|
||||
* jccolor.c
|
||||
*
|
||||
* Copyright (C) 1991-1996, Thomas G. Lane.
|
||||
* Modified 2011-2012 by Guido Vollbeding.
|
||||
* This file is part of the Independent JPEG Group's software.
|
||||
* For conditions of distribution and use, see the accompanying README file.
|
||||
*
|
||||
@ -92,7 +93,7 @@ rgb_ycc_start (j_compress_ptr cinfo)
|
||||
/* Allocate and fill in the conversion tables. */
|
||||
cconvert->rgb_ycc_tab = rgb_ycc_tab = (INT32 *)
|
||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
||||
(TABLE_SIZE * SIZEOF(INT32)));
|
||||
(TABLE_SIZE * SIZEOF(INT32)));
|
||||
|
||||
for (i = 0; i <= MAXJSAMPLE; i++) {
|
||||
rgb_ycc_tab[i+R_Y_OFF] = FIX(0.29900) * i;
|
||||
@ -128,12 +129,12 @@ rgb_ycc_start (j_compress_ptr cinfo)
|
||||
|
||||
METHODDEF(void)
|
||||
rgb_ycc_convert (j_compress_ptr cinfo,
|
||||
JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
|
||||
JDIMENSION output_row, int num_rows)
|
||||
JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
|
||||
JDIMENSION output_row, int num_rows)
|
||||
{
|
||||
my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
|
||||
register int r, g, b;
|
||||
register INT32 * ctab = cconvert->rgb_ycc_tab;
|
||||
register int r, g, b;
|
||||
register JSAMPROW inptr;
|
||||
register JSAMPROW outptr0, outptr1, outptr2;
|
||||
register JDIMENSION col;
|
||||
@ -149,7 +150,6 @@ rgb_ycc_convert (j_compress_ptr cinfo,
|
||||
r = GETJSAMPLE(inptr[RGB_RED]);
|
||||
g = GETJSAMPLE(inptr[RGB_GREEN]);
|
||||
b = GETJSAMPLE(inptr[RGB_BLUE]);
|
||||
inptr += RGB_PIXELSIZE;
|
||||
/* If the inputs are 0..MAXJSAMPLE, the outputs of these equations
|
||||
* must be too; we do not need an explicit range-limiting operation.
|
||||
* Hence the value being shifted is never negative, and we don't
|
||||
@ -157,16 +157,17 @@ rgb_ycc_convert (j_compress_ptr cinfo,
|
||||
*/
|
||||
/* Y */
|
||||
outptr0[col] = (JSAMPLE)
|
||||
((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])
|
||||
>> SCALEBITS);
|
||||
((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])
|
||||
>> SCALEBITS);
|
||||
/* Cb */
|
||||
outptr1[col] = (JSAMPLE)
|
||||
((ctab[r+R_CB_OFF] + ctab[g+G_CB_OFF] + ctab[b+B_CB_OFF])
|
||||
>> SCALEBITS);
|
||||
((ctab[r+R_CB_OFF] + ctab[g+G_CB_OFF] + ctab[b+B_CB_OFF])
|
||||
>> SCALEBITS);
|
||||
/* Cr */
|
||||
outptr2[col] = (JSAMPLE)
|
||||
((ctab[r+R_CR_OFF] + ctab[g+G_CR_OFF] + ctab[b+B_CR_OFF])
|
||||
>> SCALEBITS);
|
||||
((ctab[r+R_CR_OFF] + ctab[g+G_CR_OFF] + ctab[b+B_CR_OFF])
|
||||
>> SCALEBITS);
|
||||
inptr += RGB_PIXELSIZE;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -184,12 +185,12 @@ rgb_ycc_convert (j_compress_ptr cinfo,
|
||||
|
||||
METHODDEF(void)
|
||||
rgb_gray_convert (j_compress_ptr cinfo,
|
||||
JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
|
||||
JDIMENSION output_row, int num_rows)
|
||||
JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
|
||||
JDIMENSION output_row, int num_rows)
|
||||
{
|
||||
my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
|
||||
register int r, g, b;
|
||||
register INT32 * ctab = cconvert->rgb_ycc_tab;
|
||||
register int r, g, b;
|
||||
register JSAMPROW inptr;
|
||||
register JSAMPROW outptr;
|
||||
register JDIMENSION col;
|
||||
@ -197,17 +198,16 @@ rgb_gray_convert (j_compress_ptr cinfo,
|
||||
|
||||
while (--num_rows >= 0) {
|
||||
inptr = *input_buf++;
|
||||
outptr = output_buf[0][output_row];
|
||||
output_row++;
|
||||
outptr = output_buf[0][output_row++];
|
||||
for (col = 0; col < num_cols; col++) {
|
||||
r = GETJSAMPLE(inptr[RGB_RED]);
|
||||
g = GETJSAMPLE(inptr[RGB_GREEN]);
|
||||
b = GETJSAMPLE(inptr[RGB_BLUE]);
|
||||
inptr += RGB_PIXELSIZE;
|
||||
/* Y */
|
||||
outptr[col] = (JSAMPLE)
|
||||
((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])
|
||||
>> SCALEBITS);
|
||||
((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])
|
||||
>> SCALEBITS);
|
||||
inptr += RGB_PIXELSIZE;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -223,12 +223,12 @@ rgb_gray_convert (j_compress_ptr cinfo,
|
||||
|
||||
METHODDEF(void)
|
||||
cmyk_ycck_convert (j_compress_ptr cinfo,
|
||||
JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
|
||||
JDIMENSION output_row, int num_rows)
|
||||
JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
|
||||
JDIMENSION output_row, int num_rows)
|
||||
{
|
||||
my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
|
||||
register int r, g, b;
|
||||
register INT32 * ctab = cconvert->rgb_ycc_tab;
|
||||
register int r, g, b;
|
||||
register JSAMPROW inptr;
|
||||
register JSAMPROW outptr0, outptr1, outptr2, outptr3;
|
||||
register JDIMENSION col;
|
||||
@ -247,7 +247,6 @@ cmyk_ycck_convert (j_compress_ptr cinfo,
|
||||
b = MAXJSAMPLE - GETJSAMPLE(inptr[2]);
|
||||
/* K passes through as-is */
|
||||
outptr3[col] = inptr[3]; /* don't need GETJSAMPLE here */
|
||||
inptr += 4;
|
||||
/* If the inputs are 0..MAXJSAMPLE, the outputs of these equations
|
||||
* must be too; we do not need an explicit range-limiting operation.
|
||||
* Hence the value being shifted is never negative, and we don't
|
||||
@ -255,16 +254,56 @@ cmyk_ycck_convert (j_compress_ptr cinfo,
|
||||
*/
|
||||
/* Y */
|
||||
outptr0[col] = (JSAMPLE)
|
||||
((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])
|
||||
>> SCALEBITS);
|
||||
((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])
|
||||
>> SCALEBITS);
|
||||
/* Cb */
|
||||
outptr1[col] = (JSAMPLE)
|
||||
((ctab[r+R_CB_OFF] + ctab[g+G_CB_OFF] + ctab[b+B_CB_OFF])
|
||||
>> SCALEBITS);
|
||||
((ctab[r+R_CB_OFF] + ctab[g+G_CB_OFF] + ctab[b+B_CB_OFF])
|
||||
>> SCALEBITS);
|
||||
/* Cr */
|
||||
outptr2[col] = (JSAMPLE)
|
||||
((ctab[r+R_CR_OFF] + ctab[g+G_CR_OFF] + ctab[b+B_CR_OFF])
|
||||
>> SCALEBITS);
|
||||
((ctab[r+R_CR_OFF] + ctab[g+G_CR_OFF] + ctab[b+B_CR_OFF])
|
||||
>> 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).
|
||||
*/
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -278,19 +317,18 @@ cmyk_ycck_convert (j_compress_ptr cinfo,
|
||||
|
||||
METHODDEF(void)
|
||||
grayscale_convert (j_compress_ptr cinfo,
|
||||
JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
|
||||
JDIMENSION output_row, int num_rows)
|
||||
JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
|
||||
JDIMENSION output_row, int num_rows)
|
||||
{
|
||||
int instride = cinfo->input_components;
|
||||
register JSAMPROW inptr;
|
||||
register JSAMPROW outptr;
|
||||
register JDIMENSION col;
|
||||
JDIMENSION num_cols = cinfo->image_width;
|
||||
int instride = cinfo->input_components;
|
||||
|
||||
while (--num_rows >= 0) {
|
||||
inptr = *input_buf++;
|
||||
outptr = output_buf[0][output_row];
|
||||
output_row++;
|
||||
outptr = output_buf[0][output_row++];
|
||||
for (col = 0; col < num_cols; col++) {
|
||||
outptr[col] = inptr[0]; /* don't need GETJSAMPLE() here */
|
||||
inptr += instride;
|
||||
@ -299,6 +337,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.
|
||||
* This version handles multi-component colorspaces without conversion.
|
||||
@ -307,24 +378,24 @@ grayscale_convert (j_compress_ptr cinfo,
|
||||
|
||||
METHODDEF(void)
|
||||
null_convert (j_compress_ptr cinfo,
|
||||
JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
|
||||
JDIMENSION output_row, int num_rows)
|
||||
JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
|
||||
JDIMENSION output_row, int num_rows)
|
||||
{
|
||||
int ci;
|
||||
register int nc = cinfo->num_components;
|
||||
register JSAMPROW inptr;
|
||||
register JSAMPROW outptr;
|
||||
register JDIMENSION col;
|
||||
register int ci;
|
||||
int nc = cinfo->num_components;
|
||||
JDIMENSION num_cols = cinfo->image_width;
|
||||
|
||||
while (--num_rows >= 0) {
|
||||
/* It seems fastest to make a separate pass for each component. */
|
||||
for (ci = 0; ci < nc; ci++) {
|
||||
inptr = *input_buf;
|
||||
inptr = input_buf[0] + ci;
|
||||
outptr = output_buf[ci][output_row];
|
||||
for (col = 0; col < num_cols; col++) {
|
||||
outptr[col] = inptr[ci]; /* don't need GETJSAMPLE() here */
|
||||
inptr += nc;
|
||||
*outptr++ = *inptr; /* don't need GETJSAMPLE() here */
|
||||
inptr += nc;
|
||||
}
|
||||
}
|
||||
input_buf++;
|
||||
@ -355,8 +426,8 @@ jinit_color_converter (j_compress_ptr cinfo)
|
||||
|
||||
cconvert = (my_cconvert_ptr)
|
||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
||||
SIZEOF(my_color_converter));
|
||||
cinfo->cconvert = (struct jpeg_color_converter *) cconvert;
|
||||
SIZEOF(my_color_converter));
|
||||
cinfo->cconvert = &cconvert->pub;
|
||||
/* set start_pass to null method until we find out differently */
|
||||
cconvert->pub.start_pass = null_method;
|
||||
|
||||
@ -368,11 +439,9 @@ jinit_color_converter (j_compress_ptr cinfo)
|
||||
break;
|
||||
|
||||
case JCS_RGB:
|
||||
#if RGB_PIXELSIZE != 3
|
||||
if (cinfo->input_components != RGB_PIXELSIZE)
|
||||
ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
|
||||
break;
|
||||
#endif /* else share code with YCbCr */
|
||||
|
||||
case JCS_YCbCr:
|
||||
if (cinfo->input_components != 3)
|
||||
@ -391,28 +460,41 @@ jinit_color_converter (j_compress_ptr cinfo)
|
||||
break;
|
||||
}
|
||||
|
||||
/* Support color transform only for RGB colorspace */
|
||||
if (cinfo->color_transform && cinfo->jpeg_color_space != JCS_RGB)
|
||||
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
|
||||
|
||||
/* Check num_components, set conversion method based on requested space */
|
||||
switch (cinfo->jpeg_color_space) {
|
||||
case JCS_GRAYSCALE:
|
||||
if (cinfo->num_components != 1)
|
||||
ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
|
||||
if (cinfo->in_color_space == JCS_GRAYSCALE)
|
||||
if (cinfo->in_color_space == JCS_GRAYSCALE ||
|
||||
cinfo->in_color_space == JCS_YCbCr)
|
||||
cconvert->pub.color_convert = grayscale_convert;
|
||||
else if (cinfo->in_color_space == JCS_RGB) {
|
||||
cconvert->pub.start_pass = rgb_ycc_start;
|
||||
cconvert->pub.color_convert = rgb_gray_convert;
|
||||
} else if (cinfo->in_color_space == JCS_YCbCr)
|
||||
cconvert->pub.color_convert = grayscale_convert;
|
||||
else
|
||||
} else
|
||||
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
|
||||
break;
|
||||
|
||||
case JCS_RGB:
|
||||
if (cinfo->num_components != 3)
|
||||
ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
|
||||
if (cinfo->in_color_space == JCS_RGB && RGB_PIXELSIZE == 3)
|
||||
cconvert->pub.color_convert = null_convert;
|
||||
else
|
||||
if (cinfo->in_color_space == JCS_RGB) {
|
||||
switch (cinfo->color_transform) {
|
||||
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);
|
||||
break;
|
||||
}
|
||||
} else
|
||||
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
|
||||
break;
|
||||
|
||||
@ -451,7 +533,7 @@ jinit_color_converter (j_compress_ptr cinfo)
|
||||
|
||||
default: /* allow null conversion of JCS_UNKNOWN */
|
||||
if (cinfo->jpeg_color_space != cinfo->in_color_space ||
|
||||
cinfo->num_components != cinfo->input_components)
|
||||
cinfo->num_components != cinfo->input_components)
|
||||
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
|
||||
cconvert->pub.color_convert = null_convert;
|
||||
break;
|
||||
|
619
3rdparty/libjpeg/jcdctmgr.c
vendored
619
3rdparty/libjpeg/jcdctmgr.c
vendored
@ -23,7 +23,7 @@ typedef struct {
|
||||
struct jpeg_forward_dct pub; /* public fields */
|
||||
|
||||
/* Pointer to the DCT routine actually in use */
|
||||
forward_DCT_method_ptr do_dct;
|
||||
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).
|
||||
@ -33,7 +33,7 @@ typedef struct {
|
||||
|
||||
#ifdef DCT_FLOAT_SUPPORTED
|
||||
/* Same as above for the floating-point case. */
|
||||
float_DCT_method_ptr do_float_dct;
|
||||
float_DCT_method_ptr do_float_dct[MAX_COMPONENTS];
|
||||
FAST_FLOAT * float_divisors[NUM_QUANT_TBLS];
|
||||
#endif
|
||||
} my_fdct_controller;
|
||||
@ -41,6 +41,132 @@ typedef struct {
|
||||
typedef my_fdct_controller * my_fdct_ptr;
|
||||
|
||||
|
||||
/* The current scaled-DCT routines require ISLOW-style divisor tables,
|
||||
* so be sure to compile that code if either ISLOW or SCALING is requested.
|
||||
*/
|
||||
#ifdef DCT_ISLOW_SUPPORTED
|
||||
#define PROVIDE_ISLOW_TABLES
|
||||
#else
|
||||
#ifdef DCT_SCALING_SUPPORTED
|
||||
#define PROVIDE_ISLOW_TABLES
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* Perform forward DCT on one or more blocks of a component.
|
||||
*
|
||||
* The input samples are taken from the sample_data[] array starting at
|
||||
* position start_row/start_col, and moving to the right for any additional
|
||||
* blocks. The quantized coefficients are returned in coef_blocks[].
|
||||
*/
|
||||
|
||||
METHODDEF(void)
|
||||
forward_DCT (j_compress_ptr cinfo, jpeg_component_info * compptr,
|
||||
JSAMPARRAY sample_data, JBLOCKROW coef_blocks,
|
||||
JDIMENSION start_row, JDIMENSION start_col,
|
||||
JDIMENSION num_blocks)
|
||||
/* This version is used for integer DCT implementations. */
|
||||
{
|
||||
/* This routine is heavily used, so it's worth coding it tightly. */
|
||||
my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct;
|
||||
forward_DCT_method_ptr do_dct = fdct->do_dct[compptr->component_index];
|
||||
DCTELEM * divisors = fdct->divisors[compptr->quant_tbl_no];
|
||||
DCTELEM workspace[DCTSIZE2]; /* work area for FDCT subroutine */
|
||||
JDIMENSION bi;
|
||||
|
||||
sample_data += start_row; /* fold in the vertical offset once */
|
||||
|
||||
for (bi = 0; bi < num_blocks; bi++, start_col += compptr->DCT_h_scaled_size) {
|
||||
/* Perform the DCT */
|
||||
(*do_dct) (workspace, sample_data, start_col);
|
||||
|
||||
/* Quantize/descale the coefficients, and store into coef_blocks[] */
|
||||
{ register DCTELEM temp, qval;
|
||||
register int i;
|
||||
register JCOEFPTR output_ptr = coef_blocks[bi];
|
||||
|
||||
for (i = 0; i < DCTSIZE2; i++) {
|
||||
qval = divisors[i];
|
||||
temp = workspace[i];
|
||||
/* Divide the coefficient value by qval, ensuring proper rounding.
|
||||
* Since C does not specify the direction of rounding for negative
|
||||
* quotients, we have to force the dividend positive for portability.
|
||||
*
|
||||
* In most files, at least half of the output values will be zero
|
||||
* (at default quantization settings, more like three-quarters...)
|
||||
* so we should ensure that this case is fast. On many machines,
|
||||
* a comparison is enough cheaper than a divide to make a special test
|
||||
* a win. Since both inputs will be nonnegative, we need only test
|
||||
* for a < b to discover whether a/b is 0.
|
||||
* If your machine's division is fast enough, define FAST_DIVIDE.
|
||||
*/
|
||||
#ifdef FAST_DIVIDE
|
||||
#define DIVIDE_BY(a,b) a /= b
|
||||
#else
|
||||
#define DIVIDE_BY(a,b) if (a >= b) a /= b; else a = 0
|
||||
#endif
|
||||
if (temp < 0) {
|
||||
temp = -temp;
|
||||
temp += qval>>1; /* for rounding */
|
||||
DIVIDE_BY(temp, qval);
|
||||
temp = -temp;
|
||||
} else {
|
||||
temp += qval>>1; /* for rounding */
|
||||
DIVIDE_BY(temp, qval);
|
||||
}
|
||||
output_ptr[i] = (JCOEF) temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#ifdef DCT_FLOAT_SUPPORTED
|
||||
|
||||
METHODDEF(void)
|
||||
forward_DCT_float (j_compress_ptr cinfo, jpeg_component_info * compptr,
|
||||
JSAMPARRAY sample_data, JBLOCKROW coef_blocks,
|
||||
JDIMENSION start_row, JDIMENSION start_col,
|
||||
JDIMENSION num_blocks)
|
||||
/* This version is used for floating-point DCT implementations. */
|
||||
{
|
||||
/* This routine is heavily used, so it's worth coding it tightly. */
|
||||
my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct;
|
||||
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 workspace[DCTSIZE2]; /* work area for FDCT subroutine */
|
||||
JDIMENSION bi;
|
||||
|
||||
sample_data += start_row; /* fold in the vertical offset once */
|
||||
|
||||
for (bi = 0; bi < num_blocks; bi++, start_col += compptr->DCT_h_scaled_size) {
|
||||
/* Perform the DCT */
|
||||
(*do_dct) (workspace, sample_data, start_col);
|
||||
|
||||
/* Quantize/descale the coefficients, and store into coef_blocks[] */
|
||||
{ register FAST_FLOAT temp;
|
||||
register int i;
|
||||
register JCOEFPTR output_ptr = coef_blocks[bi];
|
||||
|
||||
for (i = 0; i < DCTSIZE2; i++) {
|
||||
/* Apply the quantization and scaling factor */
|
||||
temp = workspace[i] * divisors[i];
|
||||
/* Round to nearest integer.
|
||||
* Since C does not specify the direction of rounding for negative
|
||||
* quotients, we have to force the dividend positive for portability.
|
||||
* The maximum coefficient size is +-16K (for 12-bit data), so this
|
||||
* code should work for either 16-bit or 32-bit ints.
|
||||
*/
|
||||
output_ptr[i] = (JCOEF) ((int) (temp + (FAST_FLOAT) 16384.5) - 16384);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* DCT_FLOAT_SUPPORTED */
|
||||
|
||||
|
||||
/*
|
||||
* Initialize for a processing pass.
|
||||
* Verify that all referenced Q-tables are present, and set up
|
||||
@ -56,108 +182,270 @@ start_pass_fdctmgr (j_compress_ptr cinfo)
|
||||
my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct;
|
||||
int ci, qtblno, i;
|
||||
jpeg_component_info *compptr;
|
||||
int method = 0;
|
||||
JQUANT_TBL * qtbl;
|
||||
DCTELEM * dtbl;
|
||||
|
||||
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
|
||||
ci++, compptr++) {
|
||||
/* Select the proper DCT routine for this component's scaling */
|
||||
switch ((compptr->DCT_h_scaled_size << 8) + compptr->DCT_v_scaled_size) {
|
||||
#ifdef DCT_SCALING_SUPPORTED
|
||||
case ((1 << 8) + 1):
|
||||
fdct->do_dct[ci] = jpeg_fdct_1x1;
|
||||
method = JDCT_ISLOW; /* jfdctint uses islow-style table */
|
||||
break;
|
||||
case ((2 << 8) + 2):
|
||||
fdct->do_dct[ci] = jpeg_fdct_2x2;
|
||||
method = JDCT_ISLOW; /* jfdctint uses islow-style table */
|
||||
break;
|
||||
case ((3 << 8) + 3):
|
||||
fdct->do_dct[ci] = jpeg_fdct_3x3;
|
||||
method = JDCT_ISLOW; /* jfdctint uses islow-style table */
|
||||
break;
|
||||
case ((4 << 8) + 4):
|
||||
fdct->do_dct[ci] = jpeg_fdct_4x4;
|
||||
method = JDCT_ISLOW; /* jfdctint uses islow-style table */
|
||||
break;
|
||||
case ((5 << 8) + 5):
|
||||
fdct->do_dct[ci] = jpeg_fdct_5x5;
|
||||
method = JDCT_ISLOW; /* jfdctint uses islow-style table */
|
||||
break;
|
||||
case ((6 << 8) + 6):
|
||||
fdct->do_dct[ci] = jpeg_fdct_6x6;
|
||||
method = JDCT_ISLOW; /* jfdctint uses islow-style table */
|
||||
break;
|
||||
case ((7 << 8) + 7):
|
||||
fdct->do_dct[ci] = jpeg_fdct_7x7;
|
||||
method = JDCT_ISLOW; /* jfdctint uses islow-style table */
|
||||
break;
|
||||
case ((9 << 8) + 9):
|
||||
fdct->do_dct[ci] = jpeg_fdct_9x9;
|
||||
method = JDCT_ISLOW; /* jfdctint uses islow-style table */
|
||||
break;
|
||||
case ((10 << 8) + 10):
|
||||
fdct->do_dct[ci] = jpeg_fdct_10x10;
|
||||
method = JDCT_ISLOW; /* jfdctint uses islow-style table */
|
||||
break;
|
||||
case ((11 << 8) + 11):
|
||||
fdct->do_dct[ci] = jpeg_fdct_11x11;
|
||||
method = JDCT_ISLOW; /* jfdctint uses islow-style table */
|
||||
break;
|
||||
case ((12 << 8) + 12):
|
||||
fdct->do_dct[ci] = jpeg_fdct_12x12;
|
||||
method = JDCT_ISLOW; /* jfdctint uses islow-style table */
|
||||
break;
|
||||
case ((13 << 8) + 13):
|
||||
fdct->do_dct[ci] = jpeg_fdct_13x13;
|
||||
method = JDCT_ISLOW; /* jfdctint uses islow-style table */
|
||||
break;
|
||||
case ((14 << 8) + 14):
|
||||
fdct->do_dct[ci] = jpeg_fdct_14x14;
|
||||
method = JDCT_ISLOW; /* jfdctint uses islow-style table */
|
||||
break;
|
||||
case ((15 << 8) + 15):
|
||||
fdct->do_dct[ci] = jpeg_fdct_15x15;
|
||||
method = JDCT_ISLOW; /* jfdctint uses islow-style table */
|
||||
break;
|
||||
case ((16 << 8) + 16):
|
||||
fdct->do_dct[ci] = jpeg_fdct_16x16;
|
||||
method = JDCT_ISLOW; /* jfdctint uses islow-style table */
|
||||
break;
|
||||
case ((16 << 8) + 8):
|
||||
fdct->do_dct[ci] = jpeg_fdct_16x8;
|
||||
method = JDCT_ISLOW; /* jfdctint uses islow-style table */
|
||||
break;
|
||||
case ((14 << 8) + 7):
|
||||
fdct->do_dct[ci] = jpeg_fdct_14x7;
|
||||
method = JDCT_ISLOW; /* jfdctint uses islow-style table */
|
||||
break;
|
||||
case ((12 << 8) + 6):
|
||||
fdct->do_dct[ci] = jpeg_fdct_12x6;
|
||||
method = JDCT_ISLOW; /* jfdctint uses islow-style table */
|
||||
break;
|
||||
case ((10 << 8) + 5):
|
||||
fdct->do_dct[ci] = jpeg_fdct_10x5;
|
||||
method = JDCT_ISLOW; /* jfdctint uses islow-style table */
|
||||
break;
|
||||
case ((8 << 8) + 4):
|
||||
fdct->do_dct[ci] = jpeg_fdct_8x4;
|
||||
method = JDCT_ISLOW; /* jfdctint uses islow-style table */
|
||||
break;
|
||||
case ((6 << 8) + 3):
|
||||
fdct->do_dct[ci] = jpeg_fdct_6x3;
|
||||
method = JDCT_ISLOW; /* jfdctint uses islow-style table */
|
||||
break;
|
||||
case ((4 << 8) + 2):
|
||||
fdct->do_dct[ci] = jpeg_fdct_4x2;
|
||||
method = JDCT_ISLOW; /* jfdctint uses islow-style table */
|
||||
break;
|
||||
case ((2 << 8) + 1):
|
||||
fdct->do_dct[ci] = jpeg_fdct_2x1;
|
||||
method = JDCT_ISLOW; /* jfdctint uses islow-style table */
|
||||
break;
|
||||
case ((8 << 8) + 16):
|
||||
fdct->do_dct[ci] = jpeg_fdct_8x16;
|
||||
method = JDCT_ISLOW; /* jfdctint uses islow-style table */
|
||||
break;
|
||||
case ((7 << 8) + 14):
|
||||
fdct->do_dct[ci] = jpeg_fdct_7x14;
|
||||
method = JDCT_ISLOW; /* jfdctint uses islow-style table */
|
||||
break;
|
||||
case ((6 << 8) + 12):
|
||||
fdct->do_dct[ci] = jpeg_fdct_6x12;
|
||||
method = JDCT_ISLOW; /* jfdctint uses islow-style table */
|
||||
break;
|
||||
case ((5 << 8) + 10):
|
||||
fdct->do_dct[ci] = jpeg_fdct_5x10;
|
||||
method = JDCT_ISLOW; /* jfdctint uses islow-style table */
|
||||
break;
|
||||
case ((4 << 8) + 8):
|
||||
fdct->do_dct[ci] = jpeg_fdct_4x8;
|
||||
method = JDCT_ISLOW; /* jfdctint uses islow-style table */
|
||||
break;
|
||||
case ((3 << 8) + 6):
|
||||
fdct->do_dct[ci] = jpeg_fdct_3x6;
|
||||
method = JDCT_ISLOW; /* jfdctint uses islow-style table */
|
||||
break;
|
||||
case ((2 << 8) + 4):
|
||||
fdct->do_dct[ci] = jpeg_fdct_2x4;
|
||||
method = JDCT_ISLOW; /* jfdctint uses islow-style table */
|
||||
break;
|
||||
case ((1 << 8) + 2):
|
||||
fdct->do_dct[ci] = jpeg_fdct_1x2;
|
||||
method = JDCT_ISLOW; /* jfdctint uses islow-style table */
|
||||
break;
|
||||
#endif
|
||||
case ((DCTSIZE << 8) + DCTSIZE):
|
||||
switch (cinfo->dct_method) {
|
||||
#ifdef DCT_ISLOW_SUPPORTED
|
||||
case JDCT_ISLOW:
|
||||
fdct->do_dct[ci] = jpeg_fdct_islow;
|
||||
method = JDCT_ISLOW;
|
||||
break;
|
||||
#endif
|
||||
#ifdef DCT_IFAST_SUPPORTED
|
||||
case JDCT_IFAST:
|
||||
fdct->do_dct[ci] = jpeg_fdct_ifast;
|
||||
method = JDCT_IFAST;
|
||||
break;
|
||||
#endif
|
||||
#ifdef DCT_FLOAT_SUPPORTED
|
||||
case JDCT_FLOAT:
|
||||
fdct->do_float_dct[ci] = jpeg_fdct_float;
|
||||
method = JDCT_FLOAT;
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
ERREXIT(cinfo, JERR_NOT_COMPILED);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
ERREXIT2(cinfo, JERR_BAD_DCTSIZE,
|
||||
compptr->DCT_h_scaled_size, compptr->DCT_v_scaled_size);
|
||||
break;
|
||||
}
|
||||
qtblno = compptr->quant_tbl_no;
|
||||
/* Make sure specified quantization table is present */
|
||||
if (qtblno < 0 || qtblno >= NUM_QUANT_TBLS ||
|
||||
cinfo->quant_tbl_ptrs[qtblno] == NULL)
|
||||
cinfo->quant_tbl_ptrs[qtblno] == NULL)
|
||||
ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, qtblno);
|
||||
qtbl = cinfo->quant_tbl_ptrs[qtblno];
|
||||
/* Compute divisors for this quant table */
|
||||
/* We may do this more than once for same table, but it's not a big deal */
|
||||
switch (cinfo->dct_method) {
|
||||
#ifdef DCT_ISLOW_SUPPORTED
|
||||
switch (method) {
|
||||
#ifdef PROVIDE_ISLOW_TABLES
|
||||
case JDCT_ISLOW:
|
||||
/* For LL&M IDCT method, divisors are equal to raw quantization
|
||||
* coefficients multiplied by 8 (to counteract scaling).
|
||||
*/
|
||||
if (fdct->divisors[qtblno] == NULL) {
|
||||
fdct->divisors[qtblno] = (DCTELEM *)
|
||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
||||
DCTSIZE2 * SIZEOF(DCTELEM));
|
||||
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++) {
|
||||
dtbl[i] = ((DCTELEM) qtbl->quantval[i]) << 3;
|
||||
dtbl[i] = ((DCTELEM) qtbl->quantval[i]) << 3;
|
||||
}
|
||||
fdct->pub.forward_DCT[ci] = forward_DCT;
|
||||
break;
|
||||
#endif
|
||||
#ifdef DCT_IFAST_SUPPORTED
|
||||
case JDCT_IFAST:
|
||||
{
|
||||
/* For AA&N IDCT method, divisors are equal to quantization
|
||||
* coefficients scaled by scalefactor[row]*scalefactor[col], where
|
||||
* scalefactor[0] = 1
|
||||
* scalefactor[k] = cos(k*PI/16) * sqrt(2) for k=1..7
|
||||
* We apply a further scale factor of 8.
|
||||
*/
|
||||
/* For AA&N IDCT method, divisors are equal to quantization
|
||||
* coefficients scaled by scalefactor[row]*scalefactor[col], where
|
||||
* scalefactor[0] = 1
|
||||
* scalefactor[k] = cos(k*PI/16) * sqrt(2) for k=1..7
|
||||
* We apply a further scale factor of 8.
|
||||
*/
|
||||
#define CONST_BITS 14
|
||||
static const INT16 aanscales[DCTSIZE2] = {
|
||||
/* precomputed values scaled up by 14 bits */
|
||||
16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
|
||||
22725, 31521, 29692, 26722, 22725, 17855, 12299, 6270,
|
||||
21407, 29692, 27969, 25172, 21407, 16819, 11585, 5906,
|
||||
19266, 26722, 25172, 22654, 19266, 15137, 10426, 5315,
|
||||
16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
|
||||
12873, 17855, 16819, 15137, 12873, 10114, 6967, 3552,
|
||||
8867, 12299, 11585, 10426, 8867, 6967, 4799, 2446,
|
||||
4520, 6270, 5906, 5315, 4520, 3552, 2446, 1247
|
||||
};
|
||||
SHIFT_TEMPS
|
||||
static const INT16 aanscales[DCTSIZE2] = {
|
||||
/* precomputed values scaled up by 14 bits */
|
||||
16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
|
||||
22725, 31521, 29692, 26722, 22725, 17855, 12299, 6270,
|
||||
21407, 29692, 27969, 25172, 21407, 16819, 11585, 5906,
|
||||
19266, 26722, 25172, 22654, 19266, 15137, 10426, 5315,
|
||||
16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
|
||||
12873, 17855, 16819, 15137, 12873, 10114, 6967, 3552,
|
||||
8867, 12299, 11585, 10426, 8867, 6967, 4799, 2446,
|
||||
4520, 6270, 5906, 5315, 4520, 3552, 2446, 1247
|
||||
};
|
||||
SHIFT_TEMPS
|
||||
|
||||
if (fdct->divisors[qtblno] == NULL) {
|
||||
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++) {
|
||||
dtbl[i] = (DCTELEM)
|
||||
DESCALE(MULTIPLY16V16((INT32) qtbl->quantval[i],
|
||||
(INT32) aanscales[i]),
|
||||
CONST_BITS-3);
|
||||
}
|
||||
if (fdct->divisors[qtblno] == NULL) {
|
||||
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++) {
|
||||
dtbl[i] = (DCTELEM)
|
||||
DESCALE(MULTIPLY16V16((INT32) qtbl->quantval[i],
|
||||
(INT32) aanscales[i]),
|
||||
CONST_BITS-3);
|
||||
}
|
||||
}
|
||||
fdct->pub.forward_DCT[ci] = forward_DCT;
|
||||
break;
|
||||
#endif
|
||||
#ifdef DCT_FLOAT_SUPPORTED
|
||||
case JDCT_FLOAT:
|
||||
{
|
||||
/* For float AA&N IDCT method, divisors are equal to quantization
|
||||
* coefficients scaled by scalefactor[row]*scalefactor[col], where
|
||||
* scalefactor[0] = 1
|
||||
* scalefactor[k] = cos(k*PI/16) * sqrt(2) for k=1..7
|
||||
* We apply a further scale factor of 8.
|
||||
* What's actually stored is 1/divisor so that the inner loop can
|
||||
* use a multiplication rather than a division.
|
||||
*/
|
||||
FAST_FLOAT * fdtbl;
|
||||
int row, col;
|
||||
static const double aanscalefactor[DCTSIZE] = {
|
||||
1.0, 1.387039845, 1.306562965, 1.175875602,
|
||||
1.0, 0.785694958, 0.541196100, 0.275899379
|
||||
};
|
||||
/* For float AA&N IDCT method, divisors are equal to quantization
|
||||
* coefficients scaled by scalefactor[row]*scalefactor[col], where
|
||||
* scalefactor[0] = 1
|
||||
* scalefactor[k] = cos(k*PI/16) * sqrt(2) for k=1..7
|
||||
* We apply a further scale factor of 8.
|
||||
* What's actually stored is 1/divisor so that the inner loop can
|
||||
* use a multiplication rather than a division.
|
||||
*/
|
||||
FAST_FLOAT * fdtbl;
|
||||
int row, col;
|
||||
static const double aanscalefactor[DCTSIZE] = {
|
||||
1.0, 1.387039845, 1.306562965, 1.175875602,
|
||||
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;
|
||||
for (row = 0; row < DCTSIZE; row++) {
|
||||
for (col = 0; col < DCTSIZE; col++) {
|
||||
fdtbl[i] = (FAST_FLOAT)
|
||||
(1.0 / (((double) qtbl->quantval[i] *
|
||||
aanscalefactor[row] * aanscalefactor[col] * 8.0)));
|
||||
i++;
|
||||
}
|
||||
}
|
||||
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;
|
||||
for (row = 0; row < DCTSIZE; row++) {
|
||||
for (col = 0; col < DCTSIZE; col++) {
|
||||
fdtbl[i] = (FAST_FLOAT)
|
||||
(1.0 / (((double) qtbl->quantval[i] *
|
||||
aanscalefactor[row] * aanscalefactor[col] * 8.0)));
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
fdct->pub.forward_DCT[ci] = forward_DCT_float;
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
@ -168,175 +456,6 @@ start_pass_fdctmgr (j_compress_ptr cinfo)
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Perform forward DCT on one or more blocks of a component.
|
||||
*
|
||||
* The input samples are taken from the sample_data[] array starting at
|
||||
* position start_row/start_col, and moving to the right for any additional
|
||||
* blocks. The quantized coefficients are returned in coef_blocks[].
|
||||
*/
|
||||
|
||||
METHODDEF(void)
|
||||
forward_DCT (j_compress_ptr cinfo, jpeg_component_info * compptr,
|
||||
JSAMPARRAY sample_data, JBLOCKROW coef_blocks,
|
||||
JDIMENSION start_row, JDIMENSION start_col,
|
||||
JDIMENSION num_blocks)
|
||||
/* This version is used for integer DCT implementations. */
|
||||
{
|
||||
/* This routine is heavily used, so it's worth coding it tightly. */
|
||||
my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct;
|
||||
forward_DCT_method_ptr do_dct = fdct->do_dct;
|
||||
DCTELEM * divisors = fdct->divisors[compptr->quant_tbl_no];
|
||||
DCTELEM workspace[DCTSIZE2]; /* work area for FDCT subroutine */
|
||||
JDIMENSION bi;
|
||||
|
||||
sample_data += start_row; /* fold in the vertical offset once */
|
||||
|
||||
for (bi = 0; bi < num_blocks; bi++, start_col += DCTSIZE) {
|
||||
/* Load data into workspace, applying unsigned->signed conversion */
|
||||
{ register DCTELEM *workspaceptr;
|
||||
register JSAMPROW elemptr;
|
||||
register int elemr;
|
||||
|
||||
workspaceptr = workspace;
|
||||
for (elemr = 0; elemr < DCTSIZE; elemr++) {
|
||||
elemptr = sample_data[elemr] + start_col;
|
||||
#if DCTSIZE == 8 /* unroll the inner loop */
|
||||
*workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
|
||||
*workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
|
||||
*workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
|
||||
*workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
|
||||
*workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
|
||||
*workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
|
||||
*workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
|
||||
*workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
|
||||
#else
|
||||
{ register int elemc;
|
||||
for (elemc = DCTSIZE; elemc > 0; elemc--) {
|
||||
*workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
/* Perform the DCT */
|
||||
(*do_dct) (workspace);
|
||||
|
||||
/* Quantize/descale the coefficients, and store into coef_blocks[] */
|
||||
{ register DCTELEM temp, qval;
|
||||
register int i;
|
||||
register JCOEFPTR output_ptr = coef_blocks[bi];
|
||||
|
||||
for (i = 0; i < DCTSIZE2; i++) {
|
||||
qval = divisors[i];
|
||||
temp = workspace[i];
|
||||
/* Divide the coefficient value by qval, ensuring proper rounding.
|
||||
* Since C does not specify the direction of rounding for negative
|
||||
* quotients, we have to force the dividend positive for portability.
|
||||
*
|
||||
* In most files, at least half of the output values will be zero
|
||||
* (at default quantization settings, more like three-quarters...)
|
||||
* so we should ensure that this case is fast. On many machines,
|
||||
* a comparison is enough cheaper than a divide to make a special test
|
||||
* a win. Since both inputs will be nonnegative, we need only test
|
||||
* for a < b to discover whether a/b is 0.
|
||||
* If your machine's division is fast enough, define FAST_DIVIDE.
|
||||
*/
|
||||
#ifdef FAST_DIVIDE
|
||||
#define DIVIDE_BY(a,b) a /= b
|
||||
#else
|
||||
#define DIVIDE_BY(a,b) if (a >= b) a /= b; else a = 0
|
||||
#endif
|
||||
if (temp < 0) {
|
||||
temp = -temp;
|
||||
temp += qval>>1; /* for rounding */
|
||||
DIVIDE_BY(temp, qval);
|
||||
temp = -temp;
|
||||
} else {
|
||||
temp += qval>>1; /* for rounding */
|
||||
DIVIDE_BY(temp, qval);
|
||||
}
|
||||
output_ptr[i] = (JCOEF) temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#ifdef DCT_FLOAT_SUPPORTED
|
||||
|
||||
METHODDEF(void)
|
||||
forward_DCT_float (j_compress_ptr cinfo, jpeg_component_info * compptr,
|
||||
JSAMPARRAY sample_data, JBLOCKROW coef_blocks,
|
||||
JDIMENSION start_row, JDIMENSION start_col,
|
||||
JDIMENSION num_blocks)
|
||||
/* This version is used for floating-point DCT implementations. */
|
||||
{
|
||||
/* This routine is heavily used, so it's worth coding it tightly. */
|
||||
my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct;
|
||||
float_DCT_method_ptr do_dct = fdct->do_float_dct;
|
||||
FAST_FLOAT * divisors = fdct->float_divisors[compptr->quant_tbl_no];
|
||||
FAST_FLOAT workspace[DCTSIZE2]; /* work area for FDCT subroutine */
|
||||
JDIMENSION bi;
|
||||
|
||||
sample_data += start_row; /* fold in the vertical offset once */
|
||||
|
||||
for (bi = 0; bi < num_blocks; bi++, start_col += DCTSIZE) {
|
||||
/* Load data into workspace, applying unsigned->signed conversion */
|
||||
{ register FAST_FLOAT *workspaceptr;
|
||||
register JSAMPROW elemptr;
|
||||
register int elemr;
|
||||
|
||||
workspaceptr = workspace;
|
||||
for (elemr = 0; elemr < DCTSIZE; elemr++) {
|
||||
elemptr = sample_data[elemr] + start_col;
|
||||
#if DCTSIZE == 8 /* unroll the inner loop */
|
||||
*workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
|
||||
*workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
|
||||
*workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
|
||||
*workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
|
||||
*workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
|
||||
*workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
|
||||
*workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
|
||||
*workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
|
||||
#else
|
||||
{ register int elemc;
|
||||
for (elemc = DCTSIZE; elemc > 0; elemc--) {
|
||||
*workspaceptr++ = (FAST_FLOAT)
|
||||
(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
/* Perform the DCT */
|
||||
(*do_dct) (workspace);
|
||||
|
||||
/* Quantize/descale the coefficients, and store into coef_blocks[] */
|
||||
{ register FAST_FLOAT temp;
|
||||
register int i;
|
||||
register JCOEFPTR output_ptr = coef_blocks[bi];
|
||||
|
||||
for (i = 0; i < DCTSIZE2; i++) {
|
||||
/* Apply the quantization and scaling factor */
|
||||
temp = workspace[i] * divisors[i];
|
||||
/* Round to nearest integer.
|
||||
* Since C does not specify the direction of rounding for negative
|
||||
* quotients, we have to force the dividend positive for portability.
|
||||
* The maximum coefficient size is +-16K (for 12-bit data), so this
|
||||
* code should work for either 16-bit or 32-bit ints.
|
||||
*/
|
||||
output_ptr[i] = (JCOEF) ((int) (temp + (FAST_FLOAT) 16384.5) - 16384);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* DCT_FLOAT_SUPPORTED */
|
||||
|
||||
|
||||
/*
|
||||
* Initialize FDCT manager.
|
||||
*/
|
||||
@ -349,34 +468,10 @@ jinit_forward_dct (j_compress_ptr cinfo)
|
||||
|
||||
fdct = (my_fdct_ptr)
|
||||
(*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;
|
||||
fdct->pub.start_pass = start_pass_fdctmgr;
|
||||
|
||||
switch (cinfo->dct_method) {
|
||||
#ifdef DCT_ISLOW_SUPPORTED
|
||||
case JDCT_ISLOW:
|
||||
fdct->pub.forward_DCT = forward_DCT;
|
||||
fdct->do_dct = jpeg_fdct_islow;
|
||||
break;
|
||||
#endif
|
||||
#ifdef DCT_IFAST_SUPPORTED
|
||||
case JDCT_IFAST:
|
||||
fdct->pub.forward_DCT = forward_DCT;
|
||||
fdct->do_dct = jpeg_fdct_ifast;
|
||||
break;
|
||||
#endif
|
||||
#ifdef DCT_FLOAT_SUPPORTED
|
||||
case JDCT_FLOAT:
|
||||
fdct->pub.forward_DCT = forward_DCT_float;
|
||||
fdct->do_float_dct = jpeg_fdct_float;
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
ERREXIT(cinfo, JERR_NOT_COMPILED);
|
||||
break;
|
||||
}
|
||||
|
||||
/* Mark divisor tables unallocated */
|
||||
for (i = 0; i < NUM_QUANT_TBLS; i++) {
|
||||
fdct->divisors[i] = NULL;
|
||||
|
1083
3rdparty/libjpeg/jchuff.c
vendored
1083
3rdparty/libjpeg/jchuff.c
vendored
File diff suppressed because it is too large
Load Diff
47
3rdparty/libjpeg/jchuff.h
vendored
47
3rdparty/libjpeg/jchuff.h
vendored
@ -1,47 +0,0 @@
|
||||
/*
|
||||
* jchuff.h
|
||||
*
|
||||
* Copyright (C) 1991-1997, Thomas G. Lane.
|
||||
* This file is part of the Independent JPEG Group's software.
|
||||
* For conditions of distribution and use, see the accompanying README file.
|
||||
*
|
||||
* This file contains declarations for Huffman entropy encoding routines
|
||||
* that are shared between the sequential encoder (jchuff.c) and the
|
||||
* progressive encoder (jcphuff.c). No other modules need to see these.
|
||||
*/
|
||||
|
||||
/* The legal range of a DCT coefficient is
|
||||
* -1024 .. +1023 for 8-bit data;
|
||||
* -16384 .. +16383 for 12-bit data.
|
||||
* Hence the magnitude should always fit in 10 or 14 bits respectively.
|
||||
*/
|
||||
|
||||
#if BITS_IN_JSAMPLE == 8
|
||||
#define MAX_COEF_BITS 10
|
||||
#else
|
||||
#define MAX_COEF_BITS 14
|
||||
#endif
|
||||
|
||||
/* Derived data constructed for each Huffman table */
|
||||
|
||||
typedef struct {
|
||||
unsigned int ehufco[256]; /* code for each symbol */
|
||||
char ehufsi[256]; /* length of code for each symbol */
|
||||
/* If no code has been allocated for a symbol S, ehufsi[S] contains 0 */
|
||||
} c_derived_tbl;
|
||||
|
||||
/* Short forms of external names for systems with brain-damaged linkers. */
|
||||
|
||||
#ifdef NEED_SHORT_EXTERNAL_NAMES
|
||||
#define jpeg_make_c_derived_tbl jMkCDerived
|
||||
#define jpeg_gen_optimal_table jGenOptTbl
|
||||
#endif /* NEED_SHORT_EXTERNAL_NAMES */
|
||||
|
||||
/* Expand a Huffman table definition into the derived format */
|
||||
EXTERN(void) jpeg_make_c_derived_tbl
|
||||
JPP((j_compress_ptr cinfo, boolean isDC, int tblno,
|
||||
c_derived_tbl ** pdtbl));
|
||||
|
||||
/* Generate an optimal table definition given the specified counts */
|
||||
EXTERN(void) jpeg_gen_optimal_table
|
||||
JPP((j_compress_ptr cinfo, JHUFF_TBL * htbl, long freq[]));
|
17
3rdparty/libjpeg/jcinit.c
vendored
17
3rdparty/libjpeg/jcinit.c
vendored
@ -41,22 +41,15 @@ jinit_compress_master (j_compress_ptr cinfo)
|
||||
/* Forward DCT */
|
||||
jinit_forward_dct(cinfo);
|
||||
/* Entropy encoding: either Huffman or arithmetic coding. */
|
||||
if (cinfo->arith_code) {
|
||||
ERREXIT(cinfo, JERR_ARITH_NOTIMPL);
|
||||
} else {
|
||||
if (cinfo->progressive_mode) {
|
||||
#ifdef C_PROGRESSIVE_SUPPORTED
|
||||
jinit_phuff_encoder(cinfo);
|
||||
#else
|
||||
ERREXIT(cinfo, JERR_NOT_COMPILED);
|
||||
#endif
|
||||
} else
|
||||
jinit_huff_encoder(cinfo);
|
||||
if (cinfo->arith_code)
|
||||
jinit_arith_encoder(cinfo);
|
||||
else {
|
||||
jinit_huff_encoder(cinfo);
|
||||
}
|
||||
|
||||
/* Need a full-image coefficient buffer in any multi-pass mode. */
|
||||
jinit_c_coef_controller(cinfo,
|
||||
(boolean) (cinfo->num_scans > 1 || cinfo->optimize_coding));
|
||||
(boolean) (cinfo->num_scans > 1 || cinfo->optimize_coding));
|
||||
jinit_c_main_controller(cinfo, FALSE /* never need full buffer here */);
|
||||
|
||||
jinit_marker_writer(cinfo);
|
||||
|
184
3rdparty/libjpeg/jcmainct.c
vendored
184
3rdparty/libjpeg/jcmainct.c
vendored
@ -2,11 +2,12 @@
|
||||
* jcmainct.c
|
||||
*
|
||||
* Copyright (C) 1994-1996, Thomas G. Lane.
|
||||
* Modified 2003-2012 by Guido Vollbeding.
|
||||
* This file is part of the Independent JPEG Group's software.
|
||||
* For conditions of distribution and use, see the accompanying README file.
|
||||
*
|
||||
* This file contains the main_ptr buffer controller for compression.
|
||||
* The main_ptr buffer lies between the pre-processor and the JPEG
|
||||
* This file contains the main buffer controller for compression.
|
||||
* The main buffer lies between the pre-processor and the JPEG
|
||||
* compressor proper; it holds downsampled data in the JPEG colorspace.
|
||||
*/
|
||||
|
||||
@ -52,12 +53,12 @@ typedef my_main_controller * my_main_ptr;
|
||||
|
||||
/* Forward declarations */
|
||||
METHODDEF(void) process_data_simple_main
|
||||
JPP((j_compress_ptr cinfo, JSAMPARRAY input_buf,
|
||||
JDIMENSION *in_row_ctr, JDIMENSION in_rows_avail));
|
||||
JPP((j_compress_ptr cinfo, JSAMPARRAY input_buf,
|
||||
JDIMENSION *in_row_ctr, JDIMENSION in_rows_avail));
|
||||
#ifdef FULL_MAIN_BUFFER_SUPPORTED
|
||||
METHODDEF(void) process_data_buffer_main
|
||||
JPP((j_compress_ptr cinfo, JSAMPARRAY input_buf,
|
||||
JDIMENSION *in_row_ctr, JDIMENSION in_rows_avail));
|
||||
JPP((j_compress_ptr cinfo, JSAMPARRAY input_buf,
|
||||
JDIMENSION *in_row_ctr, JDIMENSION in_rows_avail));
|
||||
#endif
|
||||
|
||||
|
||||
@ -68,32 +69,32 @@ METHODDEF(void) process_data_buffer_main
|
||||
METHODDEF(void)
|
||||
start_pass_main (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
|
||||
{
|
||||
my_main_ptr main_ptr = (my_main_ptr) cinfo->main;
|
||||
my_main_ptr mainp = (my_main_ptr) cinfo->main;
|
||||
|
||||
/* Do nothing in raw-data mode. */
|
||||
if (cinfo->raw_data_in)
|
||||
return;
|
||||
|
||||
main_ptr->cur_iMCU_row = 0; /* initialize counters */
|
||||
main_ptr->rowgroup_ctr = 0;
|
||||
main_ptr->suspended = FALSE;
|
||||
main_ptr->pass_mode = pass_mode; /* save mode for use by process_data */
|
||||
mainp->cur_iMCU_row = 0; /* initialize counters */
|
||||
mainp->rowgroup_ctr = 0;
|
||||
mainp->suspended = FALSE;
|
||||
mainp->pass_mode = pass_mode; /* save mode for use by process_data */
|
||||
|
||||
switch (pass_mode) {
|
||||
case JBUF_PASS_THRU:
|
||||
#ifdef FULL_MAIN_BUFFER_SUPPORTED
|
||||
if (main_ptr->whole_image[0] != NULL)
|
||||
if (mainp->whole_image[0] != NULL)
|
||||
ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
|
||||
#endif
|
||||
main_ptr->pub.process_data = process_data_simple_main;
|
||||
mainp->pub.process_data = process_data_simple_main;
|
||||
break;
|
||||
#ifdef FULL_MAIN_BUFFER_SUPPORTED
|
||||
case JBUF_SAVE_SOURCE:
|
||||
case JBUF_CRANK_DEST:
|
||||
case JBUF_SAVE_AND_PASS:
|
||||
if (main_ptr->whole_image[0] == NULL)
|
||||
if (mainp->whole_image[0] == NULL)
|
||||
ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
|
||||
main_ptr->pub.process_data = process_data_buffer_main;
|
||||
mainp->pub.process_data = process_data_buffer_main;
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
@ -111,49 +112,49 @@ start_pass_main (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
|
||||
|
||||
METHODDEF(void)
|
||||
process_data_simple_main (j_compress_ptr cinfo,
|
||||
JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
|
||||
JDIMENSION in_rows_avail)
|
||||
JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
|
||||
JDIMENSION in_rows_avail)
|
||||
{
|
||||
my_main_ptr main_ptr = (my_main_ptr) cinfo->main;
|
||||
my_main_ptr mainp = (my_main_ptr) cinfo->main;
|
||||
|
||||
while (main_ptr->cur_iMCU_row < cinfo->total_iMCU_rows) {
|
||||
/* Read input data if we haven't filled the main_ptr buffer yet */
|
||||
if (main_ptr->rowgroup_ctr < DCTSIZE)
|
||||
while (mainp->cur_iMCU_row < cinfo->total_iMCU_rows) {
|
||||
/* Read input data if we haven't filled the main buffer yet */
|
||||
if (mainp->rowgroup_ctr < (JDIMENSION) cinfo->min_DCT_v_scaled_size)
|
||||
(*cinfo->prep->pre_process_data) (cinfo,
|
||||
input_buf, in_row_ctr, in_rows_avail,
|
||||
main_ptr->buffer, &main_ptr->rowgroup_ctr,
|
||||
(JDIMENSION) DCTSIZE);
|
||||
input_buf, in_row_ctr, in_rows_avail,
|
||||
mainp->buffer, &mainp->rowgroup_ctr,
|
||||
(JDIMENSION) cinfo->min_DCT_v_scaled_size);
|
||||
|
||||
/* If we don't have a full iMCU row buffered, return to application for
|
||||
* more data. Note that preprocessor will always pad to fill the iMCU row
|
||||
* at the bottom of the image.
|
||||
*/
|
||||
if (main_ptr->rowgroup_ctr != DCTSIZE)
|
||||
if (mainp->rowgroup_ctr != (JDIMENSION) cinfo->min_DCT_v_scaled_size)
|
||||
return;
|
||||
|
||||
/* Send the completed row to the compressor */
|
||||
if (! (*cinfo->coef->compress_data) (cinfo, main_ptr->buffer)) {
|
||||
if (! (*cinfo->coef->compress_data) (cinfo, mainp->buffer)) {
|
||||
/* If compressor did not consume the whole row, then we must need to
|
||||
* suspend processing and return to the application. In this situation
|
||||
* we pretend we didn't yet consume the last input row; otherwise, if
|
||||
* it happened to be the last row of the image, the application would
|
||||
* think we were done.
|
||||
*/
|
||||
if (! main_ptr->suspended) {
|
||||
(*in_row_ctr)--;
|
||||
main_ptr->suspended = TRUE;
|
||||
if (! mainp->suspended) {
|
||||
(*in_row_ctr)--;
|
||||
mainp->suspended = TRUE;
|
||||
}
|
||||
return;
|
||||
}
|
||||
/* We did finish the row. Undo our little suspension hack if a previous
|
||||
* call suspended; then mark the main_ptr buffer empty.
|
||||
* call suspended; then mark the main buffer empty.
|
||||
*/
|
||||
if (main_ptr->suspended) {
|
||||
if (mainp->suspended) {
|
||||
(*in_row_ctr)++;
|
||||
main_ptr->suspended = FALSE;
|
||||
mainp->suspended = FALSE;
|
||||
}
|
||||
main_ptr->rowgroup_ctr = 0;
|
||||
main_ptr->cur_iMCU_row++;
|
||||
mainp->rowgroup_ctr = 0;
|
||||
mainp->cur_iMCU_row++;
|
||||
}
|
||||
}
|
||||
|
||||
@ -167,28 +168,30 @@ process_data_simple_main (j_compress_ptr cinfo,
|
||||
|
||||
METHODDEF(void)
|
||||
process_data_buffer_main (j_compress_ptr cinfo,
|
||||
JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
|
||||
JDIMENSION in_rows_avail)
|
||||
JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
|
||||
JDIMENSION in_rows_avail)
|
||||
{
|
||||
my_main_ptr main_ptr = (my_main_ptr) cinfo->main;
|
||||
my_main_ptr mainp = (my_main_ptr) cinfo->main;
|
||||
int ci;
|
||||
jpeg_component_info *compptr;
|
||||
boolean writing = (main_ptr->pass_mode != JBUF_CRANK_DEST);
|
||||
boolean writing = (mainp->pass_mode != JBUF_CRANK_DEST);
|
||||
|
||||
while (main_ptr->cur_iMCU_row < cinfo->total_iMCU_rows) {
|
||||
while (mainp->cur_iMCU_row < cinfo->total_iMCU_rows) {
|
||||
/* Realign the virtual buffers if at the start of an iMCU row. */
|
||||
if (main_ptr->rowgroup_ctr == 0) {
|
||||
if (mainp->rowgroup_ctr == 0) {
|
||||
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
|
||||
ci++, compptr++) {
|
||||
main_ptr->buffer[ci] = (*cinfo->mem->access_virt_sarray)
|
||||
((j_common_ptr) cinfo, main_ptr->whole_image[ci],
|
||||
main_ptr->cur_iMCU_row * (compptr->v_samp_factor * DCTSIZE),
|
||||
(JDIMENSION) (compptr->v_samp_factor * DCTSIZE), writing);
|
||||
ci++, compptr++) {
|
||||
mainp->buffer[ci] = (*cinfo->mem->access_virt_sarray)
|
||||
((j_common_ptr) cinfo, mainp->whole_image[ci], mainp->cur_iMCU_row *
|
||||
((JDIMENSION) (compptr->v_samp_factor * cinfo->min_DCT_v_scaled_size)),
|
||||
(JDIMENSION) (compptr->v_samp_factor * cinfo->min_DCT_v_scaled_size),
|
||||
writing);
|
||||
}
|
||||
/* In a read pass, pretend we just read some source data. */
|
||||
if (! writing) {
|
||||
*in_row_ctr += cinfo->max_v_samp_factor * DCTSIZE;
|
||||
main_ptr->rowgroup_ctr = DCTSIZE;
|
||||
*in_row_ctr += (JDIMENSION)
|
||||
(cinfo->max_v_samp_factor * cinfo->min_DCT_v_scaled_size);
|
||||
mainp->rowgroup_ctr = (JDIMENSION) cinfo->min_DCT_v_scaled_size;
|
||||
}
|
||||
}
|
||||
|
||||
@ -196,41 +199,41 @@ process_data_buffer_main (j_compress_ptr cinfo,
|
||||
/* Note: preprocessor will pad if necessary to fill the last iMCU row. */
|
||||
if (writing) {
|
||||
(*cinfo->prep->pre_process_data) (cinfo,
|
||||
input_buf, in_row_ctr, in_rows_avail,
|
||||
main_ptr->buffer, &main_ptr->rowgroup_ctr,
|
||||
(JDIMENSION) DCTSIZE);
|
||||
input_buf, in_row_ctr, in_rows_avail,
|
||||
mainp->buffer, &mainp->rowgroup_ctr,
|
||||
(JDIMENSION) cinfo->min_DCT_v_scaled_size);
|
||||
/* Return to application if we need more data to fill the iMCU row. */
|
||||
if (main_ptr->rowgroup_ctr < DCTSIZE)
|
||||
return;
|
||||
if (mainp->rowgroup_ctr < (JDIMENSION) cinfo->min_DCT_v_scaled_size)
|
||||
return;
|
||||
}
|
||||
|
||||
/* Emit data, unless this is a sink-only pass. */
|
||||
if (main_ptr->pass_mode != JBUF_SAVE_SOURCE) {
|
||||
if (! (*cinfo->coef->compress_data) (cinfo, main_ptr->buffer)) {
|
||||
/* If compressor did not consume the whole row, then we must need to
|
||||
* suspend processing and return to the application. In this situation
|
||||
* we pretend we didn't yet consume the last input row; otherwise, if
|
||||
* it happened to be the last row of the image, the application would
|
||||
* think we were done.
|
||||
*/
|
||||
if (! main_ptr->suspended) {
|
||||
(*in_row_ctr)--;
|
||||
main_ptr->suspended = TRUE;
|
||||
}
|
||||
return;
|
||||
if (mainp->pass_mode != JBUF_SAVE_SOURCE) {
|
||||
if (! (*cinfo->coef->compress_data) (cinfo, mainp->buffer)) {
|
||||
/* If compressor did not consume the whole row, then we must need to
|
||||
* suspend processing and return to the application. In this situation
|
||||
* we pretend we didn't yet consume the last input row; otherwise, if
|
||||
* it happened to be the last row of the image, the application would
|
||||
* think we were done.
|
||||
*/
|
||||
if (! mainp->suspended) {
|
||||
(*in_row_ctr)--;
|
||||
mainp->suspended = TRUE;
|
||||
}
|
||||
return;
|
||||
}
|
||||
/* We did finish the row. Undo our little suspension hack if a previous
|
||||
* call suspended; then mark the main_ptr buffer empty.
|
||||
* call suspended; then mark the main buffer empty.
|
||||
*/
|
||||
if (main_ptr->suspended) {
|
||||
(*in_row_ctr)++;
|
||||
main_ptr->suspended = FALSE;
|
||||
if (mainp->suspended) {
|
||||
(*in_row_ctr)++;
|
||||
mainp->suspended = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
/* If get here, we are done with this iMCU row. Mark buffer empty. */
|
||||
main_ptr->rowgroup_ctr = 0;
|
||||
main_ptr->cur_iMCU_row++;
|
||||
mainp->rowgroup_ctr = 0;
|
||||
mainp->cur_iMCU_row++;
|
||||
}
|
||||
}
|
||||
|
||||
@ -238,21 +241,21 @@ process_data_buffer_main (j_compress_ptr cinfo,
|
||||
|
||||
|
||||
/*
|
||||
* Initialize main_ptr buffer controller.
|
||||
* Initialize main buffer controller.
|
||||
*/
|
||||
|
||||
GLOBAL(void)
|
||||
jinit_c_main_controller (j_compress_ptr cinfo, boolean need_full_buffer)
|
||||
{
|
||||
my_main_ptr main_ptr;
|
||||
my_main_ptr mainp;
|
||||
int ci;
|
||||
jpeg_component_info *compptr;
|
||||
|
||||
main_ptr = (my_main_ptr)
|
||||
mainp = (my_main_ptr)
|
||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
||||
SIZEOF(my_main_controller));
|
||||
cinfo->main = (struct jpeg_c_main_controller *) main_ptr;
|
||||
main_ptr->pub.start_pass = start_pass_main;
|
||||
SIZEOF(my_main_controller));
|
||||
cinfo->main = &mainp->pub;
|
||||
mainp->pub.start_pass = start_pass_main;
|
||||
|
||||
/* We don't need to create a buffer in raw-data mode. */
|
||||
if (cinfo->raw_data_in)
|
||||
@ -266,28 +269,29 @@ jinit_c_main_controller (j_compress_ptr cinfo, boolean need_full_buffer)
|
||||
/* Allocate a full-image virtual array for each component */
|
||||
/* Note we pad the bottom to a multiple of the iMCU height */
|
||||
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
|
||||
ci++, compptr++) {
|
||||
main_ptr->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
|
||||
((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE,
|
||||
compptr->width_in_blocks * DCTSIZE,
|
||||
(JDIMENSION) jround_up((long) compptr->height_in_blocks,
|
||||
(long) compptr->v_samp_factor) * DCTSIZE,
|
||||
(JDIMENSION) (compptr->v_samp_factor * DCTSIZE));
|
||||
ci++, compptr++) {
|
||||
mainp->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
|
||||
((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE,
|
||||
compptr->width_in_blocks * ((JDIMENSION) compptr->DCT_h_scaled_size),
|
||||
((JDIMENSION) jround_up((long) compptr->height_in_blocks,
|
||||
(long) compptr->v_samp_factor)) *
|
||||
((JDIMENSION) cinfo->min_DCT_v_scaled_size),
|
||||
(JDIMENSION) (compptr->v_samp_factor * compptr->DCT_v_scaled_size));
|
||||
}
|
||||
#else
|
||||
ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
|
||||
#endif
|
||||
} else {
|
||||
#ifdef FULL_MAIN_BUFFER_SUPPORTED
|
||||
main_ptr->whole_image[0] = NULL; /* flag for no virtual arrays */
|
||||
mainp->whole_image[0] = NULL; /* flag for no virtual arrays */
|
||||
#endif
|
||||
/* Allocate a strip buffer for each component */
|
||||
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
|
||||
ci++, compptr++) {
|
||||
main_ptr->buffer[ci] = (*cinfo->mem->alloc_sarray)
|
||||
((j_common_ptr) cinfo, JPOOL_IMAGE,
|
||||
compptr->width_in_blocks * DCTSIZE,
|
||||
(JDIMENSION) (compptr->v_samp_factor * DCTSIZE));
|
||||
ci++, compptr++) {
|
||||
mainp->buffer[ci] = (*cinfo->mem->alloc_sarray)
|
||||
((j_common_ptr) cinfo, JPOOL_IMAGE,
|
||||
compptr->width_in_blocks * ((JDIMENSION) compptr->DCT_h_scaled_size),
|
||||
(JDIMENSION) (compptr->v_samp_factor * compptr->DCT_v_scaled_size));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
173
3rdparty/libjpeg/jcmarker.c
vendored
173
3rdparty/libjpeg/jcmarker.c
vendored
@ -2,6 +2,7 @@
|
||||
* jcmarker.c
|
||||
*
|
||||
* Copyright (C) 1991-1998, Thomas G. Lane.
|
||||
* Modified 2003-2012 by Guido Vollbeding.
|
||||
* This file is part of the Independent JPEG Group's software.
|
||||
* For conditions of distribution and use, see the accompanying README file.
|
||||
*
|
||||
@ -72,6 +73,7 @@ typedef enum { /* JPEG marker codes */
|
||||
M_APP15 = 0xef,
|
||||
|
||||
M_JPG0 = 0xf0,
|
||||
M_JPG8 = 0xf8,
|
||||
M_JPG13 = 0xfd,
|
||||
M_COM = 0xfe,
|
||||
|
||||
@ -153,23 +155,24 @@ emit_dqt (j_compress_ptr cinfo, int index)
|
||||
ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, index);
|
||||
|
||||
prec = 0;
|
||||
for (i = 0; i < DCTSIZE2; i++) {
|
||||
if (qtbl->quantval[i] > 255)
|
||||
for (i = 0; i <= cinfo->lim_Se; i++) {
|
||||
if (qtbl->quantval[cinfo->natural_order[i]] > 255)
|
||||
prec = 1;
|
||||
}
|
||||
|
||||
if (! qtbl->sent_table) {
|
||||
emit_marker(cinfo, M_DQT);
|
||||
|
||||
emit_2bytes(cinfo, prec ? DCTSIZE2*2 + 1 + 2 : DCTSIZE2 + 1 + 2);
|
||||
emit_2bytes(cinfo,
|
||||
prec ? cinfo->lim_Se * 2 + 2 + 1 + 2 : cinfo->lim_Se + 1 + 1 + 2);
|
||||
|
||||
emit_byte(cinfo, index + (prec<<4));
|
||||
|
||||
for (i = 0; i < DCTSIZE2; i++) {
|
||||
for (i = 0; i <= cinfo->lim_Se; i++) {
|
||||
/* The table entries must be emitted in zigzag order. */
|
||||
unsigned int qval = qtbl->quantval[jpeg_natural_order[i]];
|
||||
unsigned int qval = qtbl->quantval[cinfo->natural_order[i]];
|
||||
if (prec)
|
||||
emit_byte(cinfo, (int) (qval >> 8));
|
||||
emit_byte(cinfo, (int) (qval >> 8));
|
||||
emit_byte(cinfo, (int) (qval & 0xFF));
|
||||
}
|
||||
|
||||
@ -235,26 +238,32 @@ emit_dac (j_compress_ptr cinfo)
|
||||
|
||||
for (i = 0; i < cinfo->comps_in_scan; i++) {
|
||||
compptr = cinfo->cur_comp_info[i];
|
||||
dc_in_use[compptr->dc_tbl_no] = 1;
|
||||
ac_in_use[compptr->ac_tbl_no] = 1;
|
||||
/* DC needs no table for refinement scan */
|
||||
if (cinfo->Ss == 0 && cinfo->Ah == 0)
|
||||
dc_in_use[compptr->dc_tbl_no] = 1;
|
||||
/* AC needs no table when not present */
|
||||
if (cinfo->Se)
|
||||
ac_in_use[compptr->ac_tbl_no] = 1;
|
||||
}
|
||||
|
||||
length = 0;
|
||||
for (i = 0; i < NUM_ARITH_TBLS; i++)
|
||||
length += dc_in_use[i] + ac_in_use[i];
|
||||
|
||||
emit_marker(cinfo, M_DAC);
|
||||
if (length) {
|
||||
emit_marker(cinfo, M_DAC);
|
||||
|
||||
emit_2bytes(cinfo, length*2 + 2);
|
||||
emit_2bytes(cinfo, length*2 + 2);
|
||||
|
||||
for (i = 0; i < NUM_ARITH_TBLS; i++) {
|
||||
if (dc_in_use[i]) {
|
||||
emit_byte(cinfo, i);
|
||||
emit_byte(cinfo, cinfo->arith_dc_L[i] + (cinfo->arith_dc_U[i]<<4));
|
||||
}
|
||||
if (ac_in_use[i]) {
|
||||
emit_byte(cinfo, i + 0x10);
|
||||
emit_byte(cinfo, cinfo->arith_ac_K[i]);
|
||||
for (i = 0; i < NUM_ARITH_TBLS; i++) {
|
||||
if (dc_in_use[i]) {
|
||||
emit_byte(cinfo, i);
|
||||
emit_byte(cinfo, cinfo->arith_dc_L[i] + (cinfo->arith_dc_U[i]<<4));
|
||||
}
|
||||
if (ac_in_use[i]) {
|
||||
emit_byte(cinfo, i + 0x10);
|
||||
emit_byte(cinfo, cinfo->arith_ac_K[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif /* C_ARITH_CODING_SUPPORTED */
|
||||
@ -273,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)
|
||||
emit_sof (j_compress_ptr cinfo, JPEG_MARKER code)
|
||||
/* Emit a SOF marker */
|
||||
@ -285,13 +325,13 @@ emit_sof (j_compress_ptr cinfo, JPEG_MARKER code)
|
||||
emit_2bytes(cinfo, 3 * cinfo->num_components + 2 + 5 + 1); /* length */
|
||||
|
||||
/* Make sure image isn't bigger than SOF field can handle */
|
||||
if ((long) cinfo->image_height > 65535L ||
|
||||
(long) cinfo->image_width > 65535L)
|
||||
if ((long) cinfo->jpeg_height > 65535L ||
|
||||
(long) cinfo->jpeg_width > 65535L)
|
||||
ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) 65535);
|
||||
|
||||
emit_byte(cinfo, cinfo->data_precision);
|
||||
emit_2bytes(cinfo, (int) cinfo->image_height);
|
||||
emit_2bytes(cinfo, (int) cinfo->image_width);
|
||||
emit_2bytes(cinfo, (int) cinfo->jpeg_height);
|
||||
emit_2bytes(cinfo, (int) cinfo->jpeg_width);
|
||||
|
||||
emit_byte(cinfo, cinfo->num_components);
|
||||
|
||||
@ -320,22 +360,16 @@ emit_sos (j_compress_ptr cinfo)
|
||||
for (i = 0; i < cinfo->comps_in_scan; i++) {
|
||||
compptr = cinfo->cur_comp_info[i];
|
||||
emit_byte(cinfo, compptr->component_id);
|
||||
td = compptr->dc_tbl_no;
|
||||
ta = compptr->ac_tbl_no;
|
||||
if (cinfo->progressive_mode) {
|
||||
/* Progressive mode: only DC or only AC tables are used in one scan;
|
||||
* furthermore, Huffman coding of DC refinement uses no table at all.
|
||||
* We emit 0 for unused field(s); this is recommended by the P&M text
|
||||
* but does not seem to be specified in the standard.
|
||||
*/
|
||||
if (cinfo->Ss == 0) {
|
||||
ta = 0; /* DC scan */
|
||||
if (cinfo->Ah != 0 && !cinfo->arith_code)
|
||||
td = 0; /* no DC table either */
|
||||
} else {
|
||||
td = 0; /* AC scan */
|
||||
}
|
||||
}
|
||||
|
||||
/* We emit 0 for unused field(s); this is recommended by the P&M text
|
||||
* but does not seem to be specified in the standard.
|
||||
*/
|
||||
|
||||
/* DC needs no table for refinement scan */
|
||||
td = cinfo->Ss == 0 && cinfo->Ah == 0 ? compptr->dc_tbl_no : 0;
|
||||
/* AC needs no table when not present */
|
||||
ta = cinfo->Se ? compptr->ac_tbl_no : 0;
|
||||
|
||||
emit_byte(cinfo, (td << 4) + ta);
|
||||
}
|
||||
|
||||
@ -345,6 +379,22 @@ emit_sos (j_compress_ptr cinfo)
|
||||
}
|
||||
|
||||
|
||||
LOCAL(void)
|
||||
emit_pseudo_sos (j_compress_ptr cinfo)
|
||||
/* Emit a pseudo SOS marker */
|
||||
{
|
||||
emit_marker(cinfo, M_SOS);
|
||||
|
||||
emit_2bytes(cinfo, 2 + 1 + 3); /* length */
|
||||
|
||||
emit_byte(cinfo, 0); /* Ns */
|
||||
|
||||
emit_byte(cinfo, 0); /* Ss */
|
||||
emit_byte(cinfo, cinfo->block_size * cinfo->block_size - 1); /* Se */
|
||||
emit_byte(cinfo, 0); /* Ah/Al */
|
||||
}
|
||||
|
||||
|
||||
LOCAL(void)
|
||||
emit_jfif_app0 (j_compress_ptr cinfo)
|
||||
/* Emit a JFIF-compliant APP0 marker */
|
||||
@ -484,7 +534,8 @@ write_file_header (j_compress_ptr cinfo)
|
||||
|
||||
/*
|
||||
* Write frame header.
|
||||
* This consists of DQT and SOFn markers.
|
||||
* 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).
|
||||
* This avoids compatibility problems with incorrect implementations that
|
||||
* try to error-check the quant table numbers as soon as they see the SOF.
|
||||
@ -511,14 +562,14 @@ write_frame_header (j_compress_ptr cinfo)
|
||||
* Note we assume that Huffman table numbers won't be changed later.
|
||||
*/
|
||||
if (cinfo->arith_code || cinfo->progressive_mode ||
|
||||
cinfo->data_precision != 8) {
|
||||
cinfo->data_precision != 8 || cinfo->block_size != DCTSIZE) {
|
||||
is_baseline = FALSE;
|
||||
} else {
|
||||
is_baseline = TRUE;
|
||||
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
|
||||
ci++, compptr++) {
|
||||
ci++, compptr++) {
|
||||
if (compptr->dc_tbl_no > 1 || compptr->ac_tbl_no > 1)
|
||||
is_baseline = FALSE;
|
||||
is_baseline = FALSE;
|
||||
}
|
||||
if (prec && is_baseline) {
|
||||
is_baseline = FALSE;
|
||||
@ -529,7 +580,10 @@ write_frame_header (j_compress_ptr cinfo)
|
||||
|
||||
/* Emit the proper SOF marker */
|
||||
if (cinfo->arith_code) {
|
||||
emit_sof(cinfo, M_SOF9); /* SOF code for arithmetic coding */
|
||||
if (cinfo->progressive_mode)
|
||||
emit_sof(cinfo, M_SOF10); /* SOF code for progressive arithmetic */
|
||||
else
|
||||
emit_sof(cinfo, M_SOF9); /* SOF code for sequential arithmetic */
|
||||
} else {
|
||||
if (cinfo->progressive_mode)
|
||||
emit_sof(cinfo, M_SOF2); /* SOF code for progressive Huffman */
|
||||
@ -538,6 +592,14 @@ write_frame_header (j_compress_ptr cinfo)
|
||||
else
|
||||
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 */
|
||||
if (cinfo->progressive_mode && cinfo->block_size != DCTSIZE)
|
||||
emit_pseudo_sos(cinfo);
|
||||
}
|
||||
|
||||
|
||||
@ -566,19 +628,12 @@ write_scan_header (j_compress_ptr cinfo)
|
||||
*/
|
||||
for (i = 0; i < cinfo->comps_in_scan; i++) {
|
||||
compptr = cinfo->cur_comp_info[i];
|
||||
if (cinfo->progressive_mode) {
|
||||
/* Progressive mode: only DC or only AC tables are used in one scan */
|
||||
if (cinfo->Ss == 0) {
|
||||
if (cinfo->Ah == 0) /* DC needs no table for refinement scan */
|
||||
/* DC needs no table for refinement scan */
|
||||
if (cinfo->Ss == 0 && cinfo->Ah == 0)
|
||||
emit_dht(cinfo, compptr->dc_tbl_no, FALSE);
|
||||
} else {
|
||||
emit_dht(cinfo, compptr->ac_tbl_no, TRUE);
|
||||
}
|
||||
} else {
|
||||
/* Sequential mode: need both DC and AC tables */
|
||||
emit_dht(cinfo, compptr->dc_tbl_no, FALSE);
|
||||
emit_dht(cinfo, compptr->ac_tbl_no, TRUE);
|
||||
}
|
||||
/* AC needs no table when not present */
|
||||
if (cinfo->Se)
|
||||
emit_dht(cinfo, compptr->ac_tbl_no, TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
@ -627,9 +682,9 @@ write_tables_only (j_compress_ptr cinfo)
|
||||
if (! cinfo->arith_code) {
|
||||
for (i = 0; i < NUM_HUFF_TBLS; i++) {
|
||||
if (cinfo->dc_huff_tbl_ptrs[i] != NULL)
|
||||
emit_dht(cinfo, i, FALSE);
|
||||
emit_dht(cinfo, i, FALSE);
|
||||
if (cinfo->ac_huff_tbl_ptrs[i] != NULL)
|
||||
emit_dht(cinfo, i, TRUE);
|
||||
emit_dht(cinfo, i, TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
@ -649,8 +704,8 @@ jinit_marker_writer (j_compress_ptr cinfo)
|
||||
/* Create the subobject */
|
||||
marker = (my_marker_ptr)
|
||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
||||
SIZEOF(my_marker_writer));
|
||||
cinfo->marker = (struct jpeg_marker_writer *) marker;
|
||||
SIZEOF(my_marker_writer));
|
||||
cinfo->marker = &marker->pub;
|
||||
/* Initialize method pointers */
|
||||
marker->pub.write_file_header = write_file_header;
|
||||
marker->pub.write_frame_header = write_frame_header;
|
||||
|
432
3rdparty/libjpeg/jcmaster.c
vendored
432
3rdparty/libjpeg/jcmaster.c
vendored
@ -2,6 +2,7 @@
|
||||
* jcmaster.c
|
||||
*
|
||||
* Copyright (C) 1991-1997, Thomas G. Lane.
|
||||
* Modified 2003-2011 by Guido Vollbeding.
|
||||
* This file is part of the Independent JPEG Group's software.
|
||||
* For conditions of distribution and use, see the accompanying README file.
|
||||
*
|
||||
@ -19,9 +20,9 @@
|
||||
/* Private state */
|
||||
|
||||
typedef enum {
|
||||
main_pass, /* input data, also do first output step */
|
||||
huff_opt_pass, /* Huffman code optimization pass */
|
||||
output_pass /* data output pass */
|
||||
main_pass, /* input data, also do first output step */
|
||||
huff_opt_pass, /* Huffman code optimization pass */
|
||||
output_pass /* data output pass */
|
||||
} c_pass_type;
|
||||
|
||||
typedef struct {
|
||||
@ -42,23 +43,220 @@ typedef my_comp_master * my_master_ptr;
|
||||
* Support routines that do various essential calculations.
|
||||
*/
|
||||
|
||||
LOCAL(void)
|
||||
initial_setup (j_compress_ptr cinfo)
|
||||
/*
|
||||
* Compute JPEG image dimensions and related values.
|
||||
* NOTE: this is exported for possible use by application.
|
||||
* Hence it mustn't do anything that can't be done twice.
|
||||
*/
|
||||
|
||||
GLOBAL(void)
|
||||
jpeg_calc_jpeg_dimensions (j_compress_ptr cinfo)
|
||||
/* Do computations that are needed before master selection phase */
|
||||
{
|
||||
int ci;
|
||||
#ifdef DCT_SCALING_SUPPORTED
|
||||
|
||||
/* Sanity check on input image dimensions to prevent overflow in
|
||||
* following calculation.
|
||||
* We do check jpeg_width and jpeg_height in initial_setup below,
|
||||
* but image_width and image_height can come from arbitrary data,
|
||||
* and we need some space for multiplication by block_size.
|
||||
*/
|
||||
if (((long) cinfo->image_width >> 24) || ((long) cinfo->image_height >> 24))
|
||||
ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) JPEG_MAX_DIMENSION);
|
||||
|
||||
/* Compute actual JPEG image dimensions and DCT scaling choices. */
|
||||
if (cinfo->scale_num >= cinfo->scale_denom * cinfo->block_size) {
|
||||
/* Provide block_size/1 scaling */
|
||||
cinfo->jpeg_width = cinfo->image_width * cinfo->block_size;
|
||||
cinfo->jpeg_height = cinfo->image_height * cinfo->block_size;
|
||||
cinfo->min_DCT_h_scaled_size = 1;
|
||||
cinfo->min_DCT_v_scaled_size = 1;
|
||||
} else if (cinfo->scale_num * 2 >= cinfo->scale_denom * cinfo->block_size) {
|
||||
/* Provide block_size/2 scaling */
|
||||
cinfo->jpeg_width = (JDIMENSION)
|
||||
jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 2L);
|
||||
cinfo->jpeg_height = (JDIMENSION)
|
||||
jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 2L);
|
||||
cinfo->min_DCT_h_scaled_size = 2;
|
||||
cinfo->min_DCT_v_scaled_size = 2;
|
||||
} else if (cinfo->scale_num * 3 >= cinfo->scale_denom * cinfo->block_size) {
|
||||
/* Provide block_size/3 scaling */
|
||||
cinfo->jpeg_width = (JDIMENSION)
|
||||
jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 3L);
|
||||
cinfo->jpeg_height = (JDIMENSION)
|
||||
jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 3L);
|
||||
cinfo->min_DCT_h_scaled_size = 3;
|
||||
cinfo->min_DCT_v_scaled_size = 3;
|
||||
} else if (cinfo->scale_num * 4 >= cinfo->scale_denom * cinfo->block_size) {
|
||||
/* Provide block_size/4 scaling */
|
||||
cinfo->jpeg_width = (JDIMENSION)
|
||||
jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 4L);
|
||||
cinfo->jpeg_height = (JDIMENSION)
|
||||
jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 4L);
|
||||
cinfo->min_DCT_h_scaled_size = 4;
|
||||
cinfo->min_DCT_v_scaled_size = 4;
|
||||
} else if (cinfo->scale_num * 5 >= cinfo->scale_denom * cinfo->block_size) {
|
||||
/* Provide block_size/5 scaling */
|
||||
cinfo->jpeg_width = (JDIMENSION)
|
||||
jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 5L);
|
||||
cinfo->jpeg_height = (JDIMENSION)
|
||||
jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 5L);
|
||||
cinfo->min_DCT_h_scaled_size = 5;
|
||||
cinfo->min_DCT_v_scaled_size = 5;
|
||||
} else if (cinfo->scale_num * 6 >= cinfo->scale_denom * cinfo->block_size) {
|
||||
/* Provide block_size/6 scaling */
|
||||
cinfo->jpeg_width = (JDIMENSION)
|
||||
jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 6L);
|
||||
cinfo->jpeg_height = (JDIMENSION)
|
||||
jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 6L);
|
||||
cinfo->min_DCT_h_scaled_size = 6;
|
||||
cinfo->min_DCT_v_scaled_size = 6;
|
||||
} else if (cinfo->scale_num * 7 >= cinfo->scale_denom * cinfo->block_size) {
|
||||
/* Provide block_size/7 scaling */
|
||||
cinfo->jpeg_width = (JDIMENSION)
|
||||
jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 7L);
|
||||
cinfo->jpeg_height = (JDIMENSION)
|
||||
jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 7L);
|
||||
cinfo->min_DCT_h_scaled_size = 7;
|
||||
cinfo->min_DCT_v_scaled_size = 7;
|
||||
} else if (cinfo->scale_num * 8 >= cinfo->scale_denom * cinfo->block_size) {
|
||||
/* Provide block_size/8 scaling */
|
||||
cinfo->jpeg_width = (JDIMENSION)
|
||||
jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 8L);
|
||||
cinfo->jpeg_height = (JDIMENSION)
|
||||
jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 8L);
|
||||
cinfo->min_DCT_h_scaled_size = 8;
|
||||
cinfo->min_DCT_v_scaled_size = 8;
|
||||
} else if (cinfo->scale_num * 9 >= cinfo->scale_denom * cinfo->block_size) {
|
||||
/* Provide block_size/9 scaling */
|
||||
cinfo->jpeg_width = (JDIMENSION)
|
||||
jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 9L);
|
||||
cinfo->jpeg_height = (JDIMENSION)
|
||||
jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 9L);
|
||||
cinfo->min_DCT_h_scaled_size = 9;
|
||||
cinfo->min_DCT_v_scaled_size = 9;
|
||||
} else if (cinfo->scale_num * 10 >= cinfo->scale_denom * cinfo->block_size) {
|
||||
/* Provide block_size/10 scaling */
|
||||
cinfo->jpeg_width = (JDIMENSION)
|
||||
jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 10L);
|
||||
cinfo->jpeg_height = (JDIMENSION)
|
||||
jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 10L);
|
||||
cinfo->min_DCT_h_scaled_size = 10;
|
||||
cinfo->min_DCT_v_scaled_size = 10;
|
||||
} else if (cinfo->scale_num * 11 >= cinfo->scale_denom * cinfo->block_size) {
|
||||
/* Provide block_size/11 scaling */
|
||||
cinfo->jpeg_width = (JDIMENSION)
|
||||
jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 11L);
|
||||
cinfo->jpeg_height = (JDIMENSION)
|
||||
jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 11L);
|
||||
cinfo->min_DCT_h_scaled_size = 11;
|
||||
cinfo->min_DCT_v_scaled_size = 11;
|
||||
} else if (cinfo->scale_num * 12 >= cinfo->scale_denom * cinfo->block_size) {
|
||||
/* Provide block_size/12 scaling */
|
||||
cinfo->jpeg_width = (JDIMENSION)
|
||||
jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 12L);
|
||||
cinfo->jpeg_height = (JDIMENSION)
|
||||
jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 12L);
|
||||
cinfo->min_DCT_h_scaled_size = 12;
|
||||
cinfo->min_DCT_v_scaled_size = 12;
|
||||
} else if (cinfo->scale_num * 13 >= cinfo->scale_denom * cinfo->block_size) {
|
||||
/* Provide block_size/13 scaling */
|
||||
cinfo->jpeg_width = (JDIMENSION)
|
||||
jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 13L);
|
||||
cinfo->jpeg_height = (JDIMENSION)
|
||||
jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 13L);
|
||||
cinfo->min_DCT_h_scaled_size = 13;
|
||||
cinfo->min_DCT_v_scaled_size = 13;
|
||||
} else if (cinfo->scale_num * 14 >= cinfo->scale_denom * cinfo->block_size) {
|
||||
/* Provide block_size/14 scaling */
|
||||
cinfo->jpeg_width = (JDIMENSION)
|
||||
jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 14L);
|
||||
cinfo->jpeg_height = (JDIMENSION)
|
||||
jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 14L);
|
||||
cinfo->min_DCT_h_scaled_size = 14;
|
||||
cinfo->min_DCT_v_scaled_size = 14;
|
||||
} else if (cinfo->scale_num * 15 >= cinfo->scale_denom * cinfo->block_size) {
|
||||
/* Provide block_size/15 scaling */
|
||||
cinfo->jpeg_width = (JDIMENSION)
|
||||
jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 15L);
|
||||
cinfo->jpeg_height = (JDIMENSION)
|
||||
jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 15L);
|
||||
cinfo->min_DCT_h_scaled_size = 15;
|
||||
cinfo->min_DCT_v_scaled_size = 15;
|
||||
} else {
|
||||
/* Provide block_size/16 scaling */
|
||||
cinfo->jpeg_width = (JDIMENSION)
|
||||
jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 16L);
|
||||
cinfo->jpeg_height = (JDIMENSION)
|
||||
jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 16L);
|
||||
cinfo->min_DCT_h_scaled_size = 16;
|
||||
cinfo->min_DCT_v_scaled_size = 16;
|
||||
}
|
||||
|
||||
#else /* !DCT_SCALING_SUPPORTED */
|
||||
|
||||
/* Hardwire it to "no scaling" */
|
||||
cinfo->jpeg_width = cinfo->image_width;
|
||||
cinfo->jpeg_height = cinfo->image_height;
|
||||
cinfo->min_DCT_h_scaled_size = DCTSIZE;
|
||||
cinfo->min_DCT_v_scaled_size = DCTSIZE;
|
||||
|
||||
#endif /* DCT_SCALING_SUPPORTED */
|
||||
}
|
||||
|
||||
|
||||
LOCAL(void)
|
||||
jpeg_calc_trans_dimensions (j_compress_ptr cinfo)
|
||||
{
|
||||
if (cinfo->min_DCT_h_scaled_size != cinfo->min_DCT_v_scaled_size)
|
||||
ERREXIT2(cinfo, JERR_BAD_DCTSIZE,
|
||||
cinfo->min_DCT_h_scaled_size, cinfo->min_DCT_v_scaled_size);
|
||||
|
||||
cinfo->block_size = cinfo->min_DCT_h_scaled_size;
|
||||
}
|
||||
|
||||
|
||||
LOCAL(void)
|
||||
initial_setup (j_compress_ptr cinfo, boolean transcode_only)
|
||||
/* Do computations that are needed before master selection phase */
|
||||
{
|
||||
int ci, ssize;
|
||||
jpeg_component_info *compptr;
|
||||
long samplesperrow;
|
||||
JDIMENSION jd_samplesperrow;
|
||||
|
||||
if (transcode_only)
|
||||
jpeg_calc_trans_dimensions(cinfo);
|
||||
else
|
||||
jpeg_calc_jpeg_dimensions(cinfo);
|
||||
|
||||
/* Sanity check on block_size */
|
||||
if (cinfo->block_size < 1 || cinfo->block_size > 16)
|
||||
ERREXIT2(cinfo, JERR_BAD_DCTSIZE, cinfo->block_size, cinfo->block_size);
|
||||
|
||||
/* Derive natural_order from block_size */
|
||||
switch (cinfo->block_size) {
|
||||
case 2: cinfo->natural_order = jpeg_natural_order2; break;
|
||||
case 3: cinfo->natural_order = jpeg_natural_order3; break;
|
||||
case 4: cinfo->natural_order = jpeg_natural_order4; break;
|
||||
case 5: cinfo->natural_order = jpeg_natural_order5; break;
|
||||
case 6: cinfo->natural_order = jpeg_natural_order6; break;
|
||||
case 7: cinfo->natural_order = jpeg_natural_order7; break;
|
||||
default: cinfo->natural_order = jpeg_natural_order; break;
|
||||
}
|
||||
|
||||
/* Derive lim_Se from block_size */
|
||||
cinfo->lim_Se = cinfo->block_size < DCTSIZE ?
|
||||
cinfo->block_size * cinfo->block_size - 1 : DCTSIZE2-1;
|
||||
|
||||
/* Sanity check on image dimensions */
|
||||
if (cinfo->image_height <= 0 || cinfo->image_width <= 0
|
||||
|| cinfo->num_components <= 0 || cinfo->input_components <= 0)
|
||||
if (cinfo->jpeg_height <= 0 || cinfo->jpeg_width <= 0 ||
|
||||
cinfo->num_components <= 0 || cinfo->input_components <= 0)
|
||||
ERREXIT(cinfo, JERR_EMPTY_IMAGE);
|
||||
|
||||
/* Make sure image isn't bigger than I can handle */
|
||||
if ((long) cinfo->image_height > (long) JPEG_MAX_DIMENSION ||
|
||||
(long) cinfo->image_width > (long) JPEG_MAX_DIMENSION)
|
||||
if ((long) cinfo->jpeg_height > (long) JPEG_MAX_DIMENSION ||
|
||||
(long) cinfo->jpeg_width > (long) JPEG_MAX_DIMENSION)
|
||||
ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) JPEG_MAX_DIMENSION);
|
||||
|
||||
/* Width of an input scanline must be representable as JDIMENSION. */
|
||||
@ -74,7 +272,7 @@ initial_setup (j_compress_ptr cinfo)
|
||||
/* Check that number of components won't exceed internal array sizes */
|
||||
if (cinfo->num_components > MAX_COMPONENTS)
|
||||
ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
|
||||
MAX_COMPONENTS);
|
||||
MAX_COMPONENTS);
|
||||
|
||||
/* Compute maximum sampling factors; check factor validity */
|
||||
cinfo->max_h_samp_factor = 1;
|
||||
@ -82,12 +280,12 @@ initial_setup (j_compress_ptr cinfo)
|
||||
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
|
||||
ci++, compptr++) {
|
||||
if (compptr->h_samp_factor<=0 || compptr->h_samp_factor>MAX_SAMP_FACTOR ||
|
||||
compptr->v_samp_factor<=0 || compptr->v_samp_factor>MAX_SAMP_FACTOR)
|
||||
compptr->v_samp_factor<=0 || compptr->v_samp_factor>MAX_SAMP_FACTOR)
|
||||
ERREXIT(cinfo, JERR_BAD_SAMPLING);
|
||||
cinfo->max_h_samp_factor = MAX(cinfo->max_h_samp_factor,
|
||||
compptr->h_samp_factor);
|
||||
compptr->h_samp_factor);
|
||||
cinfo->max_v_samp_factor = MAX(cinfo->max_v_samp_factor,
|
||||
compptr->v_samp_factor);
|
||||
compptr->v_samp_factor);
|
||||
}
|
||||
|
||||
/* Compute dimensions of components */
|
||||
@ -95,22 +293,52 @@ initial_setup (j_compress_ptr cinfo)
|
||||
ci++, compptr++) {
|
||||
/* Fill in the correct component_index value; don't rely on application */
|
||||
compptr->component_index = ci;
|
||||
/* For compression, we never do DCT scaling. */
|
||||
compptr->DCT_scaled_size = DCTSIZE;
|
||||
/* In selecting the actual DCT scaling for each component, we try to
|
||||
* scale down the chroma components via DCT scaling rather than downsampling.
|
||||
* This saves time if the downsampler gets to use 1:1 scaling.
|
||||
* Note this code adapts subsampling ratios which are powers of 2.
|
||||
*/
|
||||
ssize = 1;
|
||||
#ifdef DCT_SCALING_SUPPORTED
|
||||
while (cinfo->min_DCT_h_scaled_size * ssize <=
|
||||
(cinfo->do_fancy_downsampling ? DCTSIZE : DCTSIZE / 2) &&
|
||||
(cinfo->max_h_samp_factor % (compptr->h_samp_factor * ssize * 2)) == 0) {
|
||||
ssize = ssize * 2;
|
||||
}
|
||||
#endif
|
||||
compptr->DCT_h_scaled_size = cinfo->min_DCT_h_scaled_size * ssize;
|
||||
ssize = 1;
|
||||
#ifdef DCT_SCALING_SUPPORTED
|
||||
while (cinfo->min_DCT_v_scaled_size * ssize <=
|
||||
(cinfo->do_fancy_downsampling ? DCTSIZE : DCTSIZE / 2) &&
|
||||
(cinfo->max_v_samp_factor % (compptr->v_samp_factor * ssize * 2)) == 0) {
|
||||
ssize = ssize * 2;
|
||||
}
|
||||
#endif
|
||||
compptr->DCT_v_scaled_size = cinfo->min_DCT_v_scaled_size * ssize;
|
||||
|
||||
/* We don't support DCT ratios larger than 2. */
|
||||
if (compptr->DCT_h_scaled_size > compptr->DCT_v_scaled_size * 2)
|
||||
compptr->DCT_h_scaled_size = compptr->DCT_v_scaled_size * 2;
|
||||
else if (compptr->DCT_v_scaled_size > compptr->DCT_h_scaled_size * 2)
|
||||
compptr->DCT_v_scaled_size = compptr->DCT_h_scaled_size * 2;
|
||||
|
||||
/* Size in DCT blocks */
|
||||
compptr->width_in_blocks = (JDIMENSION)
|
||||
jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor,
|
||||
(long) (cinfo->max_h_samp_factor * DCTSIZE));
|
||||
jdiv_round_up((long) cinfo->jpeg_width * (long) compptr->h_samp_factor,
|
||||
(long) (cinfo->max_h_samp_factor * cinfo->block_size));
|
||||
compptr->height_in_blocks = (JDIMENSION)
|
||||
jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor,
|
||||
(long) (cinfo->max_v_samp_factor * DCTSIZE));
|
||||
jdiv_round_up((long) cinfo->jpeg_height * (long) compptr->v_samp_factor,
|
||||
(long) (cinfo->max_v_samp_factor * cinfo->block_size));
|
||||
/* Size in samples */
|
||||
compptr->downsampled_width = (JDIMENSION)
|
||||
jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor,
|
||||
(long) cinfo->max_h_samp_factor);
|
||||
jdiv_round_up((long) cinfo->jpeg_width *
|
||||
(long) (compptr->h_samp_factor * compptr->DCT_h_scaled_size),
|
||||
(long) (cinfo->max_h_samp_factor * cinfo->block_size));
|
||||
compptr->downsampled_height = (JDIMENSION)
|
||||
jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor,
|
||||
(long) cinfo->max_v_samp_factor);
|
||||
jdiv_round_up((long) cinfo->jpeg_height *
|
||||
(long) (compptr->v_samp_factor * compptr->DCT_v_scaled_size),
|
||||
(long) (cinfo->max_v_samp_factor * cinfo->block_size));
|
||||
/* Mark component needed (this flag isn't actually used for compression) */
|
||||
compptr->component_needed = TRUE;
|
||||
}
|
||||
@ -119,8 +347,8 @@ initial_setup (j_compress_ptr cinfo)
|
||||
* main controller will call coefficient controller).
|
||||
*/
|
||||
cinfo->total_iMCU_rows = (JDIMENSION)
|
||||
jdiv_round_up((long) cinfo->image_height,
|
||||
(long) (cinfo->max_v_samp_factor*DCTSIZE));
|
||||
jdiv_round_up((long) cinfo->jpeg_height,
|
||||
(long) (cinfo->max_v_samp_factor * cinfo->block_size));
|
||||
}
|
||||
|
||||
|
||||
@ -155,7 +383,7 @@ validate_script (j_compress_ptr cinfo)
|
||||
last_bitpos_ptr = & last_bitpos[0][0];
|
||||
for (ci = 0; ci < cinfo->num_components; ci++)
|
||||
for (coefi = 0; coefi < DCTSIZE2; coefi++)
|
||||
*last_bitpos_ptr++ = -1;
|
||||
*last_bitpos_ptr++ = -1;
|
||||
#else
|
||||
ERREXIT(cinfo, JERR_NOT_COMPILED);
|
||||
#endif
|
||||
@ -173,10 +401,10 @@ validate_script (j_compress_ptr cinfo)
|
||||
for (ci = 0; ci < ncomps; ci++) {
|
||||
thisi = scanptr->component_index[ci];
|
||||
if (thisi < 0 || thisi >= cinfo->num_components)
|
||||
ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, scanno);
|
||||
ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, scanno);
|
||||
/* Components must appear in SOF order within each scan */
|
||||
if (ci > 0 && thisi <= scanptr->component_index[ci-1])
|
||||
ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, scanno);
|
||||
ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, scanno);
|
||||
}
|
||||
/* Validate progression parameters */
|
||||
Ss = scanptr->Ss;
|
||||
@ -198,43 +426,43 @@ validate_script (j_compress_ptr cinfo)
|
||||
#define MAX_AH_AL 13
|
||||
#endif
|
||||
if (Ss < 0 || Ss >= DCTSIZE2 || Se < Ss || Se >= DCTSIZE2 ||
|
||||
Ah < 0 || Ah > MAX_AH_AL || Al < 0 || Al > MAX_AH_AL)
|
||||
ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
|
||||
Ah < 0 || Ah > MAX_AH_AL || Al < 0 || Al > MAX_AH_AL)
|
||||
ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
|
||||
if (Ss == 0) {
|
||||
if (Se != 0) /* DC and AC together not OK */
|
||||
ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
|
||||
if (Se != 0) /* DC and AC together not OK */
|
||||
ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
|
||||
} else {
|
||||
if (ncomps != 1) /* AC scans must be for only one component */
|
||||
ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
|
||||
if (ncomps != 1) /* AC scans must be for only one component */
|
||||
ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
|
||||
}
|
||||
for (ci = 0; ci < ncomps; ci++) {
|
||||
last_bitpos_ptr = & last_bitpos[scanptr->component_index[ci]][0];
|
||||
if (Ss != 0 && last_bitpos_ptr[0] < 0) /* AC without prior DC scan */
|
||||
ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
|
||||
for (coefi = Ss; coefi <= Se; coefi++) {
|
||||
if (last_bitpos_ptr[coefi] < 0) {
|
||||
/* first scan of this coefficient */
|
||||
if (Ah != 0)
|
||||
last_bitpos_ptr = & last_bitpos[scanptr->component_index[ci]][0];
|
||||
if (Ss != 0 && last_bitpos_ptr[0] < 0) /* AC without prior DC scan */
|
||||
ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
|
||||
} else {
|
||||
/* not first scan */
|
||||
if (Ah != last_bitpos_ptr[coefi] || Al != Ah-1)
|
||||
ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
|
||||
}
|
||||
last_bitpos_ptr[coefi] = Al;
|
||||
}
|
||||
for (coefi = Ss; coefi <= Se; coefi++) {
|
||||
if (last_bitpos_ptr[coefi] < 0) {
|
||||
/* first scan of this coefficient */
|
||||
if (Ah != 0)
|
||||
ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
|
||||
} else {
|
||||
/* not first scan */
|
||||
if (Ah != last_bitpos_ptr[coefi] || Al != Ah-1)
|
||||
ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
|
||||
}
|
||||
last_bitpos_ptr[coefi] = Al;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
} else {
|
||||
/* For sequential JPEG, all progression parameters must be these: */
|
||||
if (Ss != 0 || Se != DCTSIZE2-1 || Ah != 0 || Al != 0)
|
||||
ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
|
||||
ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
|
||||
/* Make sure components are not sent twice */
|
||||
for (ci = 0; ci < ncomps; ci++) {
|
||||
thisi = scanptr->component_index[ci];
|
||||
if (component_sent[thisi])
|
||||
ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, scanno);
|
||||
component_sent[thisi] = TRUE;
|
||||
thisi = scanptr->component_index[ci];
|
||||
if (component_sent[thisi])
|
||||
ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, scanno);
|
||||
component_sent[thisi] = TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -249,17 +477,50 @@ validate_script (j_compress_ptr cinfo)
|
||||
*/
|
||||
for (ci = 0; ci < cinfo->num_components; ci++) {
|
||||
if (last_bitpos[ci][0] < 0)
|
||||
ERREXIT(cinfo, JERR_MISSING_DATA);
|
||||
ERREXIT(cinfo, JERR_MISSING_DATA);
|
||||
}
|
||||
#endif
|
||||
} else {
|
||||
for (ci = 0; ci < cinfo->num_components; ci++) {
|
||||
if (! component_sent[ci])
|
||||
ERREXIT(cinfo, JERR_MISSING_DATA);
|
||||
ERREXIT(cinfo, JERR_MISSING_DATA);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
LOCAL(void)
|
||||
reduce_script (j_compress_ptr cinfo)
|
||||
/* Adapt scan script for use with reduced block size;
|
||||
* assume that script has been validated before.
|
||||
*/
|
||||
{
|
||||
jpeg_scan_info * scanptr;
|
||||
int idxout, idxin;
|
||||
|
||||
/* Circumvent const declaration for this function */
|
||||
scanptr = (jpeg_scan_info *) cinfo->scan_info;
|
||||
idxout = 0;
|
||||
|
||||
for (idxin = 0; idxin < cinfo->num_scans; idxin++) {
|
||||
/* After skipping, idxout becomes smaller than idxin */
|
||||
if (idxin != idxout)
|
||||
/* Copy rest of data;
|
||||
* note we stay in given chunk of allocated memory.
|
||||
*/
|
||||
scanptr[idxout] = scanptr[idxin];
|
||||
if (scanptr[idxout].Ss > cinfo->lim_Se)
|
||||
/* Entire scan out of range - skip this entry */
|
||||
continue;
|
||||
if (scanptr[idxout].Se > cinfo->lim_Se)
|
||||
/* Limit scan to end of block */
|
||||
scanptr[idxout].Se = cinfo->lim_Se;
|
||||
idxout++;
|
||||
}
|
||||
|
||||
cinfo->num_scans = idxout;
|
||||
}
|
||||
|
||||
#endif /* C_MULTISCAN_FILES_SUPPORTED */
|
||||
|
||||
|
||||
@ -278,12 +539,15 @@ select_scan_parameters (j_compress_ptr cinfo)
|
||||
cinfo->comps_in_scan = scanptr->comps_in_scan;
|
||||
for (ci = 0; ci < scanptr->comps_in_scan; ci++) {
|
||||
cinfo->cur_comp_info[ci] =
|
||||
&cinfo->comp_info[scanptr->component_index[ci]];
|
||||
&cinfo->comp_info[scanptr->component_index[ci]];
|
||||
}
|
||||
if (cinfo->progressive_mode) {
|
||||
cinfo->Ss = scanptr->Ss;
|
||||
cinfo->Se = scanptr->Se;
|
||||
cinfo->Ah = scanptr->Ah;
|
||||
cinfo->Al = scanptr->Al;
|
||||
return;
|
||||
}
|
||||
cinfo->Ss = scanptr->Ss;
|
||||
cinfo->Se = scanptr->Se;
|
||||
cinfo->Ah = scanptr->Ah;
|
||||
cinfo->Al = scanptr->Al;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
@ -291,16 +555,16 @@ select_scan_parameters (j_compress_ptr cinfo)
|
||||
/* Prepare for single sequential-JPEG scan containing all components */
|
||||
if (cinfo->num_components > MAX_COMPS_IN_SCAN)
|
||||
ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
|
||||
MAX_COMPS_IN_SCAN);
|
||||
MAX_COMPS_IN_SCAN);
|
||||
cinfo->comps_in_scan = cinfo->num_components;
|
||||
for (ci = 0; ci < cinfo->num_components; ci++) {
|
||||
cinfo->cur_comp_info[ci] = &cinfo->comp_info[ci];
|
||||
}
|
||||
cinfo->Ss = 0;
|
||||
cinfo->Se = DCTSIZE2-1;
|
||||
cinfo->Ah = 0;
|
||||
cinfo->Al = 0;
|
||||
}
|
||||
cinfo->Ss = 0;
|
||||
cinfo->Se = cinfo->block_size * cinfo->block_size - 1;
|
||||
cinfo->Ah = 0;
|
||||
cinfo->Al = 0;
|
||||
}
|
||||
|
||||
|
||||
@ -325,7 +589,7 @@ per_scan_setup (j_compress_ptr cinfo)
|
||||
compptr->MCU_width = 1;
|
||||
compptr->MCU_height = 1;
|
||||
compptr->MCU_blocks = 1;
|
||||
compptr->MCU_sample_width = DCTSIZE;
|
||||
compptr->MCU_sample_width = compptr->DCT_h_scaled_size;
|
||||
compptr->last_col_width = 1;
|
||||
/* For noninterleaved scans, it is convenient to define last_row_height
|
||||
* as the number of block rows present in the last iMCU row.
|
||||
@ -343,15 +607,15 @@ per_scan_setup (j_compress_ptr cinfo)
|
||||
/* Interleaved (multi-component) scan */
|
||||
if (cinfo->comps_in_scan <= 0 || cinfo->comps_in_scan > MAX_COMPS_IN_SCAN)
|
||||
ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->comps_in_scan,
|
||||
MAX_COMPS_IN_SCAN);
|
||||
MAX_COMPS_IN_SCAN);
|
||||
|
||||
/* Overall image size in MCUs */
|
||||
cinfo->MCUs_per_row = (JDIMENSION)
|
||||
jdiv_round_up((long) cinfo->image_width,
|
||||
(long) (cinfo->max_h_samp_factor*DCTSIZE));
|
||||
jdiv_round_up((long) cinfo->jpeg_width,
|
||||
(long) (cinfo->max_h_samp_factor * cinfo->block_size));
|
||||
cinfo->MCU_rows_in_scan = (JDIMENSION)
|
||||
jdiv_round_up((long) cinfo->image_height,
|
||||
(long) (cinfo->max_v_samp_factor*DCTSIZE));
|
||||
jdiv_round_up((long) cinfo->jpeg_height,
|
||||
(long) (cinfo->max_v_samp_factor * cinfo->block_size));
|
||||
|
||||
cinfo->blocks_in_MCU = 0;
|
||||
|
||||
@ -361,7 +625,7 @@ per_scan_setup (j_compress_ptr cinfo)
|
||||
compptr->MCU_width = compptr->h_samp_factor;
|
||||
compptr->MCU_height = compptr->v_samp_factor;
|
||||
compptr->MCU_blocks = compptr->MCU_width * compptr->MCU_height;
|
||||
compptr->MCU_sample_width = compptr->MCU_width * DCTSIZE;
|
||||
compptr->MCU_sample_width = compptr->MCU_width * compptr->DCT_h_scaled_size;
|
||||
/* Figure number of non-dummy blocks in last MCU column & row */
|
||||
tmp = (int) (compptr->width_in_blocks % compptr->MCU_width);
|
||||
if (tmp == 0) tmp = compptr->MCU_width;
|
||||
@ -372,9 +636,9 @@ per_scan_setup (j_compress_ptr cinfo)
|
||||
/* Prepare array describing MCU composition */
|
||||
mcublks = compptr->MCU_blocks;
|
||||
if (cinfo->blocks_in_MCU + mcublks > C_MAX_BLOCKS_IN_MCU)
|
||||
ERREXIT(cinfo, JERR_BAD_MCU_SIZE);
|
||||
ERREXIT(cinfo, JERR_BAD_MCU_SIZE);
|
||||
while (mcublks-- > 0) {
|
||||
cinfo->MCU_membership[cinfo->blocks_in_MCU++] = ci;
|
||||
cinfo->MCU_membership[cinfo->blocks_in_MCU++] = ci;
|
||||
}
|
||||
}
|
||||
|
||||
@ -417,8 +681,8 @@ prepare_for_pass (j_compress_ptr cinfo)
|
||||
(*cinfo->fdct->start_pass) (cinfo);
|
||||
(*cinfo->entropy->start_pass) (cinfo, cinfo->optimize_coding);
|
||||
(*cinfo->coef->start_pass) (cinfo,
|
||||
(master->total_passes > 1 ?
|
||||
JBUF_SAVE_AND_PASS : JBUF_PASS_THRU));
|
||||
(master->total_passes > 1 ?
|
||||
JBUF_SAVE_AND_PASS : JBUF_PASS_THRU));
|
||||
(*cinfo->main->start_pass) (cinfo, JBUF_PASS_THRU);
|
||||
if (cinfo->optimize_coding) {
|
||||
/* No immediate data output; postpone writing frame/scan headers */
|
||||
@ -433,7 +697,7 @@ prepare_for_pass (j_compress_ptr cinfo)
|
||||
/* Do Huffman optimization for a scan after the first one. */
|
||||
select_scan_parameters(cinfo);
|
||||
per_scan_setup(cinfo);
|
||||
if (cinfo->Ss != 0 || cinfo->Ah == 0 || cinfo->arith_code) {
|
||||
if (cinfo->Ss != 0 || cinfo->Ah == 0) {
|
||||
(*cinfo->entropy->start_pass) (cinfo, TRUE);
|
||||
(*cinfo->coef->start_pass) (cinfo, JBUF_CRANK_DEST);
|
||||
master->pub.call_pass_startup = FALSE;
|
||||
@ -546,7 +810,7 @@ jinit_c_master_control (j_compress_ptr cinfo, boolean transcode_only)
|
||||
|
||||
master = (my_master_ptr)
|
||||
(*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;
|
||||
master->pub.prepare_for_pass = prepare_for_pass;
|
||||
master->pub.pass_startup = pass_startup;
|
||||
@ -554,11 +818,13 @@ jinit_c_master_control (j_compress_ptr cinfo, boolean transcode_only)
|
||||
master->pub.is_last_pass = FALSE;
|
||||
|
||||
/* Validate parameters, determine derived values */
|
||||
initial_setup(cinfo);
|
||||
initial_setup(cinfo, transcode_only);
|
||||
|
||||
if (cinfo->scan_info != NULL) {
|
||||
#ifdef C_MULTISCAN_FILES_SUPPORTED
|
||||
validate_script(cinfo);
|
||||
if (cinfo->block_size < DCTSIZE)
|
||||
reduce_script(cinfo);
|
||||
#else
|
||||
ERREXIT(cinfo, JERR_NOT_COMPILED);
|
||||
#endif
|
||||
@ -567,8 +833,10 @@ jinit_c_master_control (j_compress_ptr cinfo, boolean transcode_only)
|
||||
cinfo->num_scans = 1;
|
||||
}
|
||||
|
||||
if (cinfo->progressive_mode) /* TEMPORARY HACK ??? */
|
||||
cinfo->optimize_coding = TRUE; /* assume default tables no good for progressive mode */
|
||||
if ((cinfo->progressive_mode || cinfo->block_size < DCTSIZE) &&
|
||||
!cinfo->arith_code) /* TEMPORARY HACK ??? */
|
||||
/* assume default tables no good for progressive or downscale mode */
|
||||
cinfo->optimize_coding = TRUE;
|
||||
|
||||
/* Initialize my private state */
|
||||
if (transcode_only) {
|
||||
|
91
3rdparty/libjpeg/jconfig.h
vendored
91
3rdparty/libjpeg/jconfig.h
vendored
@ -1,40 +1,83 @@
|
||||
/* jconfig.h. Generated automatically by configure. */
|
||||
/* jconfig.cfg --- source file edited by configure script */
|
||||
/* see jconfig.doc for explanations */
|
||||
|
||||
#define HAVE_PROTOTYPES
|
||||
#define HAVE_UNSIGNED_CHAR
|
||||
#define HAVE_UNSIGNED_SHORT
|
||||
/*#undef void*/
|
||||
/*#undef const*/
|
||||
|
||||
/* Define this if an ordinary "char" type is unsigned.
|
||||
* If you're not sure, leaving it undefined will work at some cost in speed.
|
||||
* If you defined HAVE_UNSIGNED_CHAR then the speed difference is minimal.
|
||||
*/
|
||||
#undef CHAR_IS_UNSIGNED
|
||||
|
||||
#if defined __MINGW__ || defined __MINGW32__ || (!defined WIN32 && !defined _WIN32)
|
||||
/* Define this if your system has an ANSI-conforming <stddef.h> file.
|
||||
*/
|
||||
#define HAVE_STDDEF_H
|
||||
|
||||
/* Define this if your system has an ANSI-conforming <stdlib.h> file.
|
||||
*/
|
||||
#define HAVE_STDLIB_H
|
||||
#endif
|
||||
|
||||
/* Define this if your system does not have an ANSI/SysV <string.h>,
|
||||
* but does have a BSD-style <strings.h>.
|
||||
*/
|
||||
#undef NEED_BSD_STRINGS
|
||||
|
||||
/* Define this if your system does not provide typedef size_t in any of the
|
||||
* ANSI-standard places (stddef.h, stdlib.h, or stdio.h), but places it in
|
||||
* <sys/types.h> instead.
|
||||
*/
|
||||
#undef NEED_SYS_TYPES_H
|
||||
|
||||
/* For 80x86 machines, you need to define NEED_FAR_POINTERS,
|
||||
* unless you are using a large-data memory model or 80386 flat-memory mode.
|
||||
* On less brain-damaged CPUs this symbol must not be defined.
|
||||
* (Defining this symbol causes large data structures to be referenced through
|
||||
* "far" pointers and to be allocated with a special version of malloc.)
|
||||
*/
|
||||
#undef NEED_FAR_POINTERS
|
||||
|
||||
/* Define this if your linker needs global names to be unique in less
|
||||
* than the first 15 characters.
|
||||
*/
|
||||
#undef NEED_SHORT_EXTERNAL_NAMES
|
||||
/* Define this if you get warnings about undefined structures. */
|
||||
|
||||
/* Although a real ANSI C compiler can deal perfectly well with pointers to
|
||||
* unspecified structures (see "incomplete types" in the spec), a few pre-ANSI
|
||||
* and pseudo-ANSI compilers get confused. To keep one of these bozos happy,
|
||||
* define INCOMPLETE_TYPES_BROKEN. This is not recommended unless you
|
||||
* actually get "missing structure definition" warnings or errors while
|
||||
* compiling the JPEG code.
|
||||
*/
|
||||
#undef INCOMPLETE_TYPES_BROKEN
|
||||
|
||||
#if defined WIN32 || defined _WIN32
|
||||
/* Define "boolean" as unsigned char, not int, per Windows custom */
|
||||
/* Define "boolean" as unsigned char, not int, on Windows systems.
|
||||
*/
|
||||
#ifdef _WIN32
|
||||
#ifndef __RPCNDR_H__ /* don't conflict if rpcndr.h already read */
|
||||
typedef unsigned char boolean;
|
||||
#endif
|
||||
#define HAVE_BOOLEAN /* prevent jmorecfg.h from redefining it */
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* The following options affect code selection within the JPEG library,
|
||||
* but they don't need to be visible to applications using the library.
|
||||
* To minimize application namespace pollution, the symbols won't be
|
||||
* defined unless JPEG_INTERNALS has been defined.
|
||||
*/
|
||||
|
||||
#ifdef JPEG_INTERNALS
|
||||
|
||||
/* Define this if your compiler implements ">>" on signed values as a logical
|
||||
* (unsigned) shift; leave it undefined if ">>" is a signed (arithmetic) shift,
|
||||
* which is the normal and rational definition.
|
||||
*/
|
||||
#undef RIGHT_SHIFT_IS_UNSIGNED
|
||||
|
||||
/* These are for configuring the JPEG memory manager. */
|
||||
#define DEFAULT_MAX_MEM 1073741824
|
||||
#define DEFAULT_MAX_MEM 1073741824 /*1Gb*/
|
||||
|
||||
#if !defined WIN32 && !defined _WIN32
|
||||
#define INLINE __inline__
|
||||
@ -43,14 +86,28 @@ typedef unsigned char boolean;
|
||||
|
||||
#endif /* JPEG_INTERNALS */
|
||||
|
||||
|
||||
/*
|
||||
* The remaining options do not affect the JPEG library proper,
|
||||
* but only the sample applications cjpeg/djpeg (see cjpeg.c, djpeg.c).
|
||||
* Other applications can ignore these.
|
||||
*/
|
||||
|
||||
#ifdef JPEG_CJPEG_DJPEG
|
||||
|
||||
/* These defines indicate which image (non-JPEG) file formats are allowed. */
|
||||
|
||||
#define BMP_SUPPORTED /* BMP image file format */
|
||||
#define GIF_SUPPORTED /* GIF image file format */
|
||||
#define PPM_SUPPORTED /* PBMPLUS PPM/PGM image file format */
|
||||
#undef RLE_SUPPORTED /* Utah RLE image file format */
|
||||
#define TARGA_SUPPORTED /* Targa image file format */
|
||||
|
||||
/* Define this if you want to name both input and output files on the command
|
||||
* line, rather than using stdout and optionally stdin. You MUST do this if
|
||||
* your system can't cope with binary I/O to stdin/stdout. See comments at
|
||||
* head of cjpeg.c or djpeg.c.
|
||||
*/
|
||||
#if defined WIN32 || defined _WIN32
|
||||
#define TWO_FILE_COMMANDLINE /* optional */
|
||||
#define USE_SETMODE /* Microsoft has setmode() */
|
||||
@ -58,10 +115,22 @@ typedef unsigned char boolean;
|
||||
#undef TWO_FILE_COMMANDLINE
|
||||
#endif
|
||||
|
||||
/* Define this if your system needs explicit cleanup of temporary files.
|
||||
* This is crucial under MS-DOS, where the temporary "files" may be areas
|
||||
* of extended memory; on most other systems it's not as important.
|
||||
*/
|
||||
#undef NEED_SIGNAL_CATCHER
|
||||
|
||||
/* By default, we open image files with fopen(...,"rb") or fopen(...,"wb").
|
||||
* This is necessary on systems that distinguish text files from binary files,
|
||||
* and is harmless on most systems that don't. If you have one of the rare
|
||||
* systems that complains about the "b" spec, define this symbol.
|
||||
*/
|
||||
#undef DONT_USE_B_MODE
|
||||
|
||||
/* Define this if you want percent-done progress reports from cjpeg/djpeg. */
|
||||
/* Define this if you want percent-done progress reports from cjpeg/djpeg.
|
||||
*/
|
||||
#undef PROGRESS_REPORT
|
||||
|
||||
|
||||
#endif /* JPEG_CJPEG_DJPEG */
|
||||
|
111
3rdparty/libjpeg/jcparam.c
vendored
111
3rdparty/libjpeg/jcparam.c
vendored
@ -2,6 +2,7 @@
|
||||
* jcparam.c
|
||||
*
|
||||
* Copyright (C) 1991-1998, Thomas G. Lane.
|
||||
* Modified 2003-2012 by Guido Vollbeding.
|
||||
* This file is part of the Independent JPEG Group's software.
|
||||
* For conditions of distribution and use, see the accompanying README file.
|
||||
*
|
||||
@ -21,8 +22,8 @@
|
||||
|
||||
GLOBAL(void)
|
||||
jpeg_add_quant_table (j_compress_ptr cinfo, int which_tbl,
|
||||
const unsigned int *basic_table,
|
||||
int scale_factor, boolean force_baseline)
|
||||
const unsigned int *basic_table,
|
||||
int scale_factor, boolean force_baseline)
|
||||
/* Define a quantization table equal to the basic_table times
|
||||
* a scale factor (given as a percentage).
|
||||
* If force_baseline is TRUE, the computed quantization table entries
|
||||
@ -60,45 +61,61 @@ jpeg_add_quant_table (j_compress_ptr cinfo, int which_tbl,
|
||||
}
|
||||
|
||||
|
||||
/* These are the sample quantization tables given in JPEG spec section K.1.
|
||||
* The spec says that the values given produce "good" quality, and
|
||||
* when divided by 2, "very good" quality.
|
||||
*/
|
||||
static const unsigned int std_luminance_quant_tbl[DCTSIZE2] = {
|
||||
16, 11, 10, 16, 24, 40, 51, 61,
|
||||
12, 12, 14, 19, 26, 58, 60, 55,
|
||||
14, 13, 16, 24, 40, 57, 69, 56,
|
||||
14, 17, 22, 29, 51, 87, 80, 62,
|
||||
18, 22, 37, 56, 68, 109, 103, 77,
|
||||
24, 35, 55, 64, 81, 104, 113, 92,
|
||||
49, 64, 78, 87, 103, 121, 120, 101,
|
||||
72, 92, 95, 98, 112, 100, 103, 99
|
||||
};
|
||||
static const unsigned int std_chrominance_quant_tbl[DCTSIZE2] = {
|
||||
17, 18, 24, 47, 99, 99, 99, 99,
|
||||
18, 21, 26, 66, 99, 99, 99, 99,
|
||||
24, 26, 56, 99, 99, 99, 99, 99,
|
||||
47, 66, 99, 99, 99, 99, 99, 99,
|
||||
99, 99, 99, 99, 99, 99, 99, 99,
|
||||
99, 99, 99, 99, 99, 99, 99, 99,
|
||||
99, 99, 99, 99, 99, 99, 99, 99,
|
||||
99, 99, 99, 99, 99, 99, 99, 99
|
||||
};
|
||||
|
||||
|
||||
GLOBAL(void)
|
||||
jpeg_default_qtables (j_compress_ptr cinfo, boolean force_baseline)
|
||||
/* Set or change the 'quality' (quantization) setting, using default tables
|
||||
* and straight percentage-scaling quality scales.
|
||||
* This entry point allows different scalings for luminance and chrominance.
|
||||
*/
|
||||
{
|
||||
/* Set up two quantization tables using the specified scaling */
|
||||
jpeg_add_quant_table(cinfo, 0, std_luminance_quant_tbl,
|
||||
cinfo->q_scale_factor[0], force_baseline);
|
||||
jpeg_add_quant_table(cinfo, 1, std_chrominance_quant_tbl,
|
||||
cinfo->q_scale_factor[1], force_baseline);
|
||||
}
|
||||
|
||||
|
||||
GLOBAL(void)
|
||||
jpeg_set_linear_quality (j_compress_ptr cinfo, int scale_factor,
|
||||
boolean force_baseline)
|
||||
boolean force_baseline)
|
||||
/* Set or change the 'quality' (quantization) setting, using default tables
|
||||
* and a straight percentage-scaling quality scale. In most cases it's better
|
||||
* to use jpeg_set_quality (below); this entry point is provided for
|
||||
* applications that insist on a linear percentage scaling.
|
||||
*/
|
||||
{
|
||||
/* These are the sample quantization tables given in JPEG spec section K.1.
|
||||
* The spec says that the values given produce "good" quality, and
|
||||
* when divided by 2, "very good" quality.
|
||||
*/
|
||||
static const unsigned int std_luminance_quant_tbl[DCTSIZE2] = {
|
||||
16, 11, 10, 16, 24, 40, 51, 61,
|
||||
12, 12, 14, 19, 26, 58, 60, 55,
|
||||
14, 13, 16, 24, 40, 57, 69, 56,
|
||||
14, 17, 22, 29, 51, 87, 80, 62,
|
||||
18, 22, 37, 56, 68, 109, 103, 77,
|
||||
24, 35, 55, 64, 81, 104, 113, 92,
|
||||
49, 64, 78, 87, 103, 121, 120, 101,
|
||||
72, 92, 95, 98, 112, 100, 103, 99
|
||||
};
|
||||
static const unsigned int std_chrominance_quant_tbl[DCTSIZE2] = {
|
||||
17, 18, 24, 47, 99, 99, 99, 99,
|
||||
18, 21, 26, 66, 99, 99, 99, 99,
|
||||
24, 26, 56, 99, 99, 99, 99, 99,
|
||||
47, 66, 99, 99, 99, 99, 99, 99,
|
||||
99, 99, 99, 99, 99, 99, 99, 99,
|
||||
99, 99, 99, 99, 99, 99, 99, 99,
|
||||
99, 99, 99, 99, 99, 99, 99, 99,
|
||||
99, 99, 99, 99, 99, 99, 99, 99
|
||||
};
|
||||
|
||||
/* Set up two quantization tables using the specified scaling */
|
||||
jpeg_add_quant_table(cinfo, 0, std_luminance_quant_tbl,
|
||||
scale_factor, force_baseline);
|
||||
scale_factor, force_baseline);
|
||||
jpeg_add_quant_table(cinfo, 1, std_chrominance_quant_tbl,
|
||||
scale_factor, force_baseline);
|
||||
scale_factor, force_baseline);
|
||||
}
|
||||
|
||||
|
||||
@ -133,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.
|
||||
* This is the standard quality-adjusting entry point for typical user
|
||||
* 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 */
|
||||
@ -150,7 +167,7 @@ jpeg_set_quality (j_compress_ptr cinfo, int quality, boolean force_baseline)
|
||||
|
||||
LOCAL(void)
|
||||
add_huff_table (j_compress_ptr cinfo,
|
||||
JHUFF_TBL **htblptr, const UINT8 *bits, const UINT8 *val)
|
||||
JHUFF_TBL **htblptr, const UINT8 *bits, const UINT8 *val)
|
||||
/* Define a Huffman table */
|
||||
{
|
||||
int nsymbols, len;
|
||||
@ -244,13 +261,13 @@ std_huff_tables (j_compress_ptr cinfo)
|
||||
0xf9, 0xfa };
|
||||
|
||||
add_huff_table(cinfo, &cinfo->dc_huff_tbl_ptrs[0],
|
||||
bits_dc_luminance, val_dc_luminance);
|
||||
bits_dc_luminance, val_dc_luminance);
|
||||
add_huff_table(cinfo, &cinfo->ac_huff_tbl_ptrs[0],
|
||||
bits_ac_luminance, val_ac_luminance);
|
||||
bits_ac_luminance, val_ac_luminance);
|
||||
add_huff_table(cinfo, &cinfo->dc_huff_tbl_ptrs[1],
|
||||
bits_dc_chrominance, val_dc_chrominance);
|
||||
bits_dc_chrominance, val_dc_chrominance);
|
||||
add_huff_table(cinfo, &cinfo->ac_huff_tbl_ptrs[1],
|
||||
bits_ac_chrominance, val_ac_chrominance);
|
||||
bits_ac_chrominance, val_ac_chrominance);
|
||||
}
|
||||
|
||||
|
||||
@ -280,10 +297,12 @@ jpeg_set_defaults (j_compress_ptr cinfo)
|
||||
if (cinfo->comp_info == NULL)
|
||||
cinfo->comp_info = (jpeg_component_info *)
|
||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
|
||||
MAX_COMPONENTS * SIZEOF(jpeg_component_info));
|
||||
MAX_COMPONENTS * SIZEOF(jpeg_component_info));
|
||||
|
||||
/* Initialize everything not dependent on the color space */
|
||||
|
||||
cinfo->scale_num = 1; /* 1:1 scaling */
|
||||
cinfo->scale_denom = 1;
|
||||
cinfo->data_precision = BITS_IN_JSAMPLE;
|
||||
/* Set up two quantization tables using default quality of 75 */
|
||||
jpeg_set_quality(cinfo, 75, TRUE);
|
||||
@ -320,6 +339,9 @@ jpeg_set_defaults (j_compress_ptr cinfo)
|
||||
/* By default, use the simpler non-cosited sampling alignment */
|
||||
cinfo->CCIR601_sampling = FALSE;
|
||||
|
||||
/* By default, apply fancy downsampling */
|
||||
cinfo->do_fancy_downsampling = TRUE;
|
||||
|
||||
/* No input smoothing */
|
||||
cinfo->smoothing_factor = 0;
|
||||
|
||||
@ -345,6 +367,9 @@ jpeg_set_defaults (j_compress_ptr cinfo)
|
||||
cinfo->X_density = 1; /* Pixel aspect ratio is square by default */
|
||||
cinfo->Y_density = 1;
|
||||
|
||||
/* No color transform */
|
||||
cinfo->color_transform = JCT_NONE;
|
||||
|
||||
/* Choose JPEG colorspace based on input space, set defaults accordingly */
|
||||
|
||||
jpeg_default_colorspace(cinfo);
|
||||
@ -426,7 +451,9 @@ jpeg_set_colorspace (j_compress_ptr cinfo, J_COLOR_SPACE colorspace)
|
||||
cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag RGB */
|
||||
cinfo->num_components = 3;
|
||||
SET_COMP(0, 0x52 /* 'R' */, 1,1, 0, 0,0);
|
||||
SET_COMP(1, 0x47 /* 'G' */, 1,1, 0, 0,0);
|
||||
SET_COMP(1, 0x47 /* 'G' */, 1,1, 0,
|
||||
cinfo->color_transform == JCT_SUBTRACT_GREEN ? 1 : 0,
|
||||
cinfo->color_transform == JCT_SUBTRACT_GREEN ? 1 : 0);
|
||||
SET_COMP(2, 0x42 /* 'B' */, 1,1, 0, 0,0);
|
||||
break;
|
||||
case JCS_YCbCr:
|
||||
@ -458,7 +485,7 @@ jpeg_set_colorspace (j_compress_ptr cinfo, J_COLOR_SPACE colorspace)
|
||||
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);
|
||||
MAX_COMPONENTS);
|
||||
for (ci = 0; ci < cinfo->num_components; ci++) {
|
||||
SET_COMP(ci, ci, 1,1, 0, 0,0);
|
||||
}
|
||||
@ -473,7 +500,7 @@ jpeg_set_colorspace (j_compress_ptr cinfo, J_COLOR_SPACE colorspace)
|
||||
|
||||
LOCAL(jpeg_scan_info *)
|
||||
fill_a_scan (jpeg_scan_info * scanptr, int ci,
|
||||
int Ss, int Se, int Ah, int Al)
|
||||
int Ss, int Se, int Ah, int Al)
|
||||
/* Support routine: generate one scan for specified component */
|
||||
{
|
||||
scanptr->comps_in_scan = 1;
|
||||
@ -488,7 +515,7 @@ fill_a_scan (jpeg_scan_info * scanptr, int ci,
|
||||
|
||||
LOCAL(jpeg_scan_info *)
|
||||
fill_scans (jpeg_scan_info * scanptr, int ncomps,
|
||||
int Ss, int Se, int Ah, int Al)
|
||||
int Ss, int Se, int Ah, int Al)
|
||||
/* Support routine: generate one scan for each component */
|
||||
{
|
||||
int ci;
|
||||
@ -567,7 +594,7 @@ jpeg_simple_progression (j_compress_ptr cinfo)
|
||||
cinfo->script_space_size = MAX(nscans, 10);
|
||||
cinfo->script_space = (jpeg_scan_info *)
|
||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
|
||||
cinfo->script_space_size * SIZEOF(jpeg_scan_info));
|
||||
cinfo->script_space_size * SIZEOF(jpeg_scan_info));
|
||||
}
|
||||
scanptr = cinfo->script_space;
|
||||
cinfo->scan_info = scanptr;
|
||||
|
833
3rdparty/libjpeg/jcphuff.c
vendored
833
3rdparty/libjpeg/jcphuff.c
vendored
@ -1,833 +0,0 @@
|
||||
/*
|
||||
* jcphuff.c
|
||||
*
|
||||
* Copyright (C) 1995-1997, Thomas G. Lane.
|
||||
* This file is part of the Independent JPEG Group's software.
|
||||
* For conditions of distribution and use, see the accompanying README file.
|
||||
*
|
||||
* This file contains Huffman entropy encoding routines for progressive JPEG.
|
||||
*
|
||||
* We do not support output suspension in this module, since the library
|
||||
* currently does not allow multiple-scan files to be written with output
|
||||
* suspension.
|
||||
*/
|
||||
|
||||
#define JPEG_INTERNALS
|
||||
#include "jinclude.h"
|
||||
#include "jpeglib.h"
|
||||
#include "jchuff.h" /* Declarations shared with jchuff.c */
|
||||
|
||||
#ifdef C_PROGRESSIVE_SUPPORTED
|
||||
|
||||
/* Expanded entropy encoder object for progressive Huffman encoding. */
|
||||
|
||||
typedef struct {
|
||||
struct jpeg_entropy_encoder pub; /* public fields */
|
||||
|
||||
/* Mode flag: TRUE for optimization, FALSE for actual data output */
|
||||
boolean gather_statistics;
|
||||
|
||||
/* Bit-level coding status.
|
||||
* next_output_byte/free_in_buffer are local copies of cinfo->dest fields.
|
||||
*/
|
||||
JOCTET * next_output_byte; /* => next byte to write in buffer */
|
||||
size_t free_in_buffer; /* # of byte spaces remaining in buffer */
|
||||
INT32 put_buffer; /* current bit-accumulation buffer */
|
||||
int put_bits; /* # of bits now in it */
|
||||
j_compress_ptr cinfo; /* link to cinfo (needed for dump_buffer) */
|
||||
|
||||
/* Coding status for DC components */
|
||||
int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
|
||||
|
||||
/* Coding status for AC components */
|
||||
int ac_tbl_no; /* the table number of the single component */
|
||||
unsigned int EOBRUN; /* run length of EOBs */
|
||||
unsigned int BE; /* # of buffered correction bits before MCU */
|
||||
char * bit_buffer; /* buffer for correction bits (1 per char) */
|
||||
/* packing correction bits tightly would save some space but cost time... */
|
||||
|
||||
unsigned int restarts_to_go; /* MCUs left in this restart interval */
|
||||
int next_restart_num; /* next restart number to write (0-7) */
|
||||
|
||||
/* Pointers to derived tables (these workspaces have image lifespan).
|
||||
* Since any one scan codes only DC or only AC, we only need one set
|
||||
* of tables, not one for DC and one for AC.
|
||||
*/
|
||||
c_derived_tbl * derived_tbls[NUM_HUFF_TBLS];
|
||||
|
||||
/* Statistics tables for optimization; again, one set is enough */
|
||||
long * count_ptrs[NUM_HUFF_TBLS];
|
||||
} phuff_entropy_encoder;
|
||||
|
||||
typedef phuff_entropy_encoder * phuff_entropy_ptr;
|
||||
|
||||
/* MAX_CORR_BITS is the number of bits the AC refinement correction-bit
|
||||
* buffer can hold. Larger sizes may slightly improve compression, but
|
||||
* 1000 is already well into the realm of overkill.
|
||||
* The minimum safe size is 64 bits.
|
||||
*/
|
||||
|
||||
#define MAX_CORR_BITS 1000 /* Max # of correction bits I can buffer */
|
||||
|
||||
/* IRIGHT_SHIFT is like RIGHT_SHIFT, but works on int rather than INT32.
|
||||
* We assume that int right shift is unsigned if INT32 right shift is,
|
||||
* which should be safe.
|
||||
*/
|
||||
|
||||
#ifdef RIGHT_SHIFT_IS_UNSIGNED
|
||||
#define ISHIFT_TEMPS int ishift_temp;
|
||||
#define IRIGHT_SHIFT(x,shft) \
|
||||
((ishift_temp = (x)) < 0 ? \
|
||||
(ishift_temp >> (shft)) | ((~0) << (16-(shft))) : \
|
||||
(ishift_temp >> (shft)))
|
||||
#else
|
||||
#define ISHIFT_TEMPS
|
||||
#define IRIGHT_SHIFT(x,shft) ((x) >> (shft))
|
||||
#endif
|
||||
|
||||
/* Forward declarations */
|
||||
METHODDEF(boolean) encode_mcu_DC_first JPP((j_compress_ptr cinfo,
|
||||
JBLOCKROW *MCU_data));
|
||||
METHODDEF(boolean) encode_mcu_AC_first JPP((j_compress_ptr cinfo,
|
||||
JBLOCKROW *MCU_data));
|
||||
METHODDEF(boolean) encode_mcu_DC_refine JPP((j_compress_ptr cinfo,
|
||||
JBLOCKROW *MCU_data));
|
||||
METHODDEF(boolean) encode_mcu_AC_refine JPP((j_compress_ptr cinfo,
|
||||
JBLOCKROW *MCU_data));
|
||||
METHODDEF(void) finish_pass_phuff JPP((j_compress_ptr cinfo));
|
||||
METHODDEF(void) finish_pass_gather_phuff JPP((j_compress_ptr cinfo));
|
||||
|
||||
|
||||
/*
|
||||
* Initialize for a Huffman-compressed scan using progressive JPEG.
|
||||
*/
|
||||
|
||||
METHODDEF(void)
|
||||
start_pass_phuff (j_compress_ptr cinfo, boolean gather_statistics)
|
||||
{
|
||||
phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
|
||||
boolean is_DC_band;
|
||||
int ci, tbl;
|
||||
jpeg_component_info * compptr;
|
||||
|
||||
entropy->cinfo = cinfo;
|
||||
entropy->gather_statistics = gather_statistics;
|
||||
|
||||
is_DC_band = (cinfo->Ss == 0);
|
||||
|
||||
/* We assume jcmaster.c already validated the scan parameters. */
|
||||
|
||||
/* Select execution routines */
|
||||
if (cinfo->Ah == 0) {
|
||||
if (is_DC_band)
|
||||
entropy->pub.encode_mcu = encode_mcu_DC_first;
|
||||
else
|
||||
entropy->pub.encode_mcu = encode_mcu_AC_first;
|
||||
} else {
|
||||
if (is_DC_band)
|
||||
entropy->pub.encode_mcu = encode_mcu_DC_refine;
|
||||
else {
|
||||
entropy->pub.encode_mcu = encode_mcu_AC_refine;
|
||||
/* AC refinement needs a correction bit buffer */
|
||||
if (entropy->bit_buffer == NULL)
|
||||
entropy->bit_buffer = (char *)
|
||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
||||
MAX_CORR_BITS * SIZEOF(char));
|
||||
}
|
||||
}
|
||||
if (gather_statistics)
|
||||
entropy->pub.finish_pass = finish_pass_gather_phuff;
|
||||
else
|
||||
entropy->pub.finish_pass = finish_pass_phuff;
|
||||
|
||||
/* Only DC coefficients may be interleaved, so cinfo->comps_in_scan = 1
|
||||
* for AC coefficients.
|
||||
*/
|
||||
for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
|
||||
compptr = cinfo->cur_comp_info[ci];
|
||||
/* Initialize DC predictions to 0 */
|
||||
entropy->last_dc_val[ci] = 0;
|
||||
/* Get table index */
|
||||
if (is_DC_band) {
|
||||
if (cinfo->Ah != 0) /* DC refinement needs no table */
|
||||
continue;
|
||||
tbl = compptr->dc_tbl_no;
|
||||
} else {
|
||||
entropy->ac_tbl_no = tbl = compptr->ac_tbl_no;
|
||||
}
|
||||
if (gather_statistics) {
|
||||
/* Check for invalid table index */
|
||||
/* (make_c_derived_tbl does this in the other path) */
|
||||
if (tbl < 0 || tbl >= NUM_HUFF_TBLS)
|
||||
ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tbl);
|
||||
/* Allocate and zero the statistics tables */
|
||||
/* Note that jpeg_gen_optimal_table expects 257 entries in each table! */
|
||||
if (entropy->count_ptrs[tbl] == NULL)
|
||||
entropy->count_ptrs[tbl] = (long *)
|
||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
||||
257 * SIZEOF(long));
|
||||
MEMZERO(entropy->count_ptrs[tbl], 257 * SIZEOF(long));
|
||||
} else {
|
||||
/* Compute derived values for Huffman table */
|
||||
/* We may do this more than once for a table, but it's not expensive */
|
||||
jpeg_make_c_derived_tbl(cinfo, is_DC_band, tbl,
|
||||
& entropy->derived_tbls[tbl]);
|
||||
}
|
||||
}
|
||||
|
||||
/* Initialize AC stuff */
|
||||
entropy->EOBRUN = 0;
|
||||
entropy->BE = 0;
|
||||
|
||||
/* Initialize bit buffer to empty */
|
||||
entropy->put_buffer = 0;
|
||||
entropy->put_bits = 0;
|
||||
|
||||
/* Initialize restart stuff */
|
||||
entropy->restarts_to_go = cinfo->restart_interval;
|
||||
entropy->next_restart_num = 0;
|
||||
}
|
||||
|
||||
|
||||
/* Outputting bytes to the file.
|
||||
* NB: these must be called only when actually outputting,
|
||||
* that is, entropy->gather_statistics == FALSE.
|
||||
*/
|
||||
|
||||
/* Emit a byte */
|
||||
#define emit_byte(entropy,val) \
|
||||
{ *(entropy)->next_output_byte++ = (JOCTET) (val); \
|
||||
if (--(entropy)->free_in_buffer == 0) \
|
||||
dump_buffer(entropy); }
|
||||
|
||||
|
||||
LOCAL(void)
|
||||
dump_buffer (phuff_entropy_ptr entropy)
|
||||
/* Empty the output buffer; we do not support suspension in this module. */
|
||||
{
|
||||
struct jpeg_destination_mgr * dest = entropy->cinfo->dest;
|
||||
|
||||
if (! (*dest->empty_output_buffer) (entropy->cinfo))
|
||||
ERREXIT(entropy->cinfo, JERR_CANT_SUSPEND);
|
||||
/* After a successful buffer dump, must reset buffer pointers */
|
||||
entropy->next_output_byte = dest->next_output_byte;
|
||||
entropy->free_in_buffer = dest->free_in_buffer;
|
||||
}
|
||||
|
||||
|
||||
/* Outputting bits to the file */
|
||||
|
||||
/* Only the right 24 bits of put_buffer are used; the valid bits are
|
||||
* left-justified in this part. At most 16 bits can be passed to emit_bits
|
||||
* in one call, and we never retain more than 7 bits in put_buffer
|
||||
* between calls, so 24 bits are sufficient.
|
||||
*/
|
||||
|
||||
INLINE
|
||||
LOCAL(void)
|
||||
emit_bits (phuff_entropy_ptr entropy, unsigned int code, int size)
|
||||
/* Emit some bits, unless we are in gather mode */
|
||||
{
|
||||
/* This routine is heavily used, so it's worth coding tightly. */
|
||||
register INT32 put_buffer = (INT32) code;
|
||||
register int put_bits = entropy->put_bits;
|
||||
|
||||
/* if size is 0, caller used an invalid Huffman table entry */
|
||||
if (size == 0)
|
||||
ERREXIT(entropy->cinfo, JERR_HUFF_MISSING_CODE);
|
||||
|
||||
if (entropy->gather_statistics)
|
||||
return; /* do nothing if we're only getting stats */
|
||||
|
||||
put_buffer &= (((INT32) 1)<<size) - 1; /* mask off any extra bits in code */
|
||||
|
||||
put_bits += size; /* new number of bits in buffer */
|
||||
|
||||
put_buffer <<= 24 - put_bits; /* align incoming bits */
|
||||
|
||||
put_buffer |= entropy->put_buffer; /* and merge with old buffer contents */
|
||||
|
||||
while (put_bits >= 8) {
|
||||
int c = (int) ((put_buffer >> 16) & 0xFF);
|
||||
|
||||
emit_byte(entropy, c);
|
||||
if (c == 0xFF) { /* need to stuff a zero byte? */
|
||||
emit_byte(entropy, 0);
|
||||
}
|
||||
put_buffer <<= 8;
|
||||
put_bits -= 8;
|
||||
}
|
||||
|
||||
entropy->put_buffer = put_buffer; /* update variables */
|
||||
entropy->put_bits = put_bits;
|
||||
}
|
||||
|
||||
|
||||
LOCAL(void)
|
||||
flush_bits (phuff_entropy_ptr entropy)
|
||||
{
|
||||
emit_bits(entropy, 0x7F, 7); /* fill any partial byte with ones */
|
||||
entropy->put_buffer = 0; /* and reset bit-buffer to empty */
|
||||
entropy->put_bits = 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Emit (or just count) a Huffman symbol.
|
||||
*/
|
||||
|
||||
INLINE
|
||||
LOCAL(void)
|
||||
emit_symbol (phuff_entropy_ptr entropy, int tbl_no, int symbol)
|
||||
{
|
||||
if (entropy->gather_statistics)
|
||||
entropy->count_ptrs[tbl_no][symbol]++;
|
||||
else {
|
||||
c_derived_tbl * tbl = entropy->derived_tbls[tbl_no];
|
||||
emit_bits(entropy, tbl->ehufco[symbol], tbl->ehufsi[symbol]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Emit bits from a correction bit buffer.
|
||||
*/
|
||||
|
||||
LOCAL(void)
|
||||
emit_buffered_bits (phuff_entropy_ptr entropy, char * bufstart,
|
||||
unsigned int nbits)
|
||||
{
|
||||
if (entropy->gather_statistics)
|
||||
return; /* no real work */
|
||||
|
||||
while (nbits > 0) {
|
||||
emit_bits(entropy, (unsigned int) (*bufstart), 1);
|
||||
bufstart++;
|
||||
nbits--;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Emit any pending EOBRUN symbol.
|
||||
*/
|
||||
|
||||
LOCAL(void)
|
||||
emit_eobrun (phuff_entropy_ptr entropy)
|
||||
{
|
||||
register int temp, nbits;
|
||||
|
||||
if (entropy->EOBRUN > 0) { /* if there is any pending EOBRUN */
|
||||
temp = entropy->EOBRUN;
|
||||
nbits = 0;
|
||||
while ((temp >>= 1))
|
||||
nbits++;
|
||||
/* safety check: shouldn't happen given limited correction-bit buffer */
|
||||
if (nbits > 14)
|
||||
ERREXIT(entropy->cinfo, JERR_HUFF_MISSING_CODE);
|
||||
|
||||
emit_symbol(entropy, entropy->ac_tbl_no, nbits << 4);
|
||||
if (nbits)
|
||||
emit_bits(entropy, entropy->EOBRUN, nbits);
|
||||
|
||||
entropy->EOBRUN = 0;
|
||||
|
||||
/* Emit any buffered correction bits */
|
||||
emit_buffered_bits(entropy, entropy->bit_buffer, entropy->BE);
|
||||
entropy->BE = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Emit a restart marker & resynchronize predictions.
|
||||
*/
|
||||
|
||||
LOCAL(void)
|
||||
emit_restart (phuff_entropy_ptr entropy, int restart_num)
|
||||
{
|
||||
int ci;
|
||||
|
||||
emit_eobrun(entropy);
|
||||
|
||||
if (! entropy->gather_statistics) {
|
||||
flush_bits(entropy);
|
||||
emit_byte(entropy, 0xFF);
|
||||
emit_byte(entropy, JPEG_RST0 + restart_num);
|
||||
}
|
||||
|
||||
if (entropy->cinfo->Ss == 0) {
|
||||
/* Re-initialize DC predictions to 0 */
|
||||
for (ci = 0; ci < entropy->cinfo->comps_in_scan; ci++)
|
||||
entropy->last_dc_val[ci] = 0;
|
||||
} else {
|
||||
/* Re-initialize all AC-related fields to 0 */
|
||||
entropy->EOBRUN = 0;
|
||||
entropy->BE = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* MCU encoding for DC initial scan (either spectral selection,
|
||||
* or first pass of successive approximation).
|
||||
*/
|
||||
|
||||
METHODDEF(boolean)
|
||||
encode_mcu_DC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
|
||||
{
|
||||
phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
|
||||
register int temp, temp2;
|
||||
register int nbits;
|
||||
int blkn, ci;
|
||||
int Al = cinfo->Al;
|
||||
JBLOCKROW block;
|
||||
jpeg_component_info * compptr;
|
||||
ISHIFT_TEMPS
|
||||
|
||||
entropy->next_output_byte = cinfo->dest->next_output_byte;
|
||||
entropy->free_in_buffer = cinfo->dest->free_in_buffer;
|
||||
|
||||
/* Emit restart marker if needed */
|
||||
if (cinfo->restart_interval)
|
||||
if (entropy->restarts_to_go == 0)
|
||||
emit_restart(entropy, entropy->next_restart_num);
|
||||
|
||||
/* Encode the MCU data blocks */
|
||||
for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
|
||||
block = MCU_data[blkn];
|
||||
ci = cinfo->MCU_membership[blkn];
|
||||
compptr = cinfo->cur_comp_info[ci];
|
||||
|
||||
/* Compute the DC value after the required point transform by Al.
|
||||
* This is simply an arithmetic right shift.
|
||||
*/
|
||||
temp2 = IRIGHT_SHIFT((int) ((*block)[0]), Al);
|
||||
|
||||
/* DC differences are figured on the point-transformed values. */
|
||||
temp = temp2 - entropy->last_dc_val[ci];
|
||||
entropy->last_dc_val[ci] = temp2;
|
||||
|
||||
/* Encode the DC coefficient difference per section G.1.2.1 */
|
||||
temp2 = temp;
|
||||
if (temp < 0) {
|
||||
temp = -temp; /* temp is abs value of input */
|
||||
/* For a negative input, want temp2 = bitwise complement of abs(input) */
|
||||
/* This code assumes we are on a two's complement machine */
|
||||
temp2--;
|
||||
}
|
||||
|
||||
/* Find the number of bits needed for the magnitude of the coefficient */
|
||||
nbits = 0;
|
||||
while (temp) {
|
||||
nbits++;
|
||||
temp >>= 1;
|
||||
}
|
||||
/* Check for out-of-range coefficient values.
|
||||
* Since we're encoding a difference, the range limit is twice as much.
|
||||
*/
|
||||
if (nbits > MAX_COEF_BITS+1)
|
||||
ERREXIT(cinfo, JERR_BAD_DCT_COEF);
|
||||
|
||||
/* Count/emit the Huffman-coded symbol for the number of bits */
|
||||
emit_symbol(entropy, compptr->dc_tbl_no, nbits);
|
||||
|
||||
/* Emit that number of bits of the value, if positive, */
|
||||
/* or the complement of its magnitude, if negative. */
|
||||
if (nbits) /* emit_bits rejects calls with size 0 */
|
||||
emit_bits(entropy, (unsigned int) temp2, nbits);
|
||||
}
|
||||
|
||||
cinfo->dest->next_output_byte = entropy->next_output_byte;
|
||||
cinfo->dest->free_in_buffer = entropy->free_in_buffer;
|
||||
|
||||
/* Update restart-interval state too */
|
||||
if (cinfo->restart_interval) {
|
||||
if (entropy->restarts_to_go == 0) {
|
||||
entropy->restarts_to_go = cinfo->restart_interval;
|
||||
entropy->next_restart_num++;
|
||||
entropy->next_restart_num &= 7;
|
||||
}
|
||||
entropy->restarts_to_go--;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* MCU encoding for AC initial scan (either spectral selection,
|
||||
* or first pass of successive approximation).
|
||||
*/
|
||||
|
||||
METHODDEF(boolean)
|
||||
encode_mcu_AC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
|
||||
{
|
||||
phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
|
||||
register int temp, temp2;
|
||||
register int nbits;
|
||||
register int r, k;
|
||||
int Se = cinfo->Se;
|
||||
int Al = cinfo->Al;
|
||||
JBLOCKROW block;
|
||||
|
||||
entropy->next_output_byte = cinfo->dest->next_output_byte;
|
||||
entropy->free_in_buffer = cinfo->dest->free_in_buffer;
|
||||
|
||||
/* Emit restart marker if needed */
|
||||
if (cinfo->restart_interval)
|
||||
if (entropy->restarts_to_go == 0)
|
||||
emit_restart(entropy, entropy->next_restart_num);
|
||||
|
||||
/* Encode the MCU data block */
|
||||
block = MCU_data[0];
|
||||
|
||||
/* Encode the AC coefficients per section G.1.2.2, fig. G.3 */
|
||||
|
||||
r = 0; /* r = run length of zeros */
|
||||
|
||||
for (k = cinfo->Ss; k <= Se; k++) {
|
||||
if ((temp = (*block)[jpeg_natural_order[k]]) == 0) {
|
||||
r++;
|
||||
continue;
|
||||
}
|
||||
/* We must apply the point transform by Al. For AC coefficients this
|
||||
* is an integer division with rounding towards 0. To do this portably
|
||||
* in C, we shift after obtaining the absolute value; so the code is
|
||||
* interwoven with finding the abs value (temp) and output bits (temp2).
|
||||
*/
|
||||
if (temp < 0) {
|
||||
temp = -temp; /* temp is abs value of input */
|
||||
temp >>= Al; /* apply the point transform */
|
||||
/* For a negative coef, want temp2 = bitwise complement of abs(coef) */
|
||||
temp2 = ~temp;
|
||||
} else {
|
||||
temp >>= Al; /* apply the point transform */
|
||||
temp2 = temp;
|
||||
}
|
||||
/* Watch out for case that nonzero coef is zero after point transform */
|
||||
if (temp == 0) {
|
||||
r++;
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Emit any pending EOBRUN */
|
||||
if (entropy->EOBRUN > 0)
|
||||
emit_eobrun(entropy);
|
||||
/* if run length > 15, must emit special run-length-16 codes (0xF0) */
|
||||
while (r > 15) {
|
||||
emit_symbol(entropy, entropy->ac_tbl_no, 0xF0);
|
||||
r -= 16;
|
||||
}
|
||||
|
||||
/* Find the number of bits needed for the magnitude of the coefficient */
|
||||
nbits = 1; /* there must be at least one 1 bit */
|
||||
while ((temp >>= 1))
|
||||
nbits++;
|
||||
/* Check for out-of-range coefficient values */
|
||||
if (nbits > MAX_COEF_BITS)
|
||||
ERREXIT(cinfo, JERR_BAD_DCT_COEF);
|
||||
|
||||
/* Count/emit Huffman symbol for run length / number of bits */
|
||||
emit_symbol(entropy, entropy->ac_tbl_no, (r << 4) + nbits);
|
||||
|
||||
/* Emit that number of bits of the value, if positive, */
|
||||
/* or the complement of its magnitude, if negative. */
|
||||
emit_bits(entropy, (unsigned int) temp2, nbits);
|
||||
|
||||
r = 0; /* reset zero run length */
|
||||
}
|
||||
|
||||
if (r > 0) { /* If there are trailing zeroes, */
|
||||
entropy->EOBRUN++; /* count an EOB */
|
||||
if (entropy->EOBRUN == 0x7FFF)
|
||||
emit_eobrun(entropy); /* force it out to avoid overflow */
|
||||
}
|
||||
|
||||
cinfo->dest->next_output_byte = entropy->next_output_byte;
|
||||
cinfo->dest->free_in_buffer = entropy->free_in_buffer;
|
||||
|
||||
/* Update restart-interval state too */
|
||||
if (cinfo->restart_interval) {
|
||||
if (entropy->restarts_to_go == 0) {
|
||||
entropy->restarts_to_go = cinfo->restart_interval;
|
||||
entropy->next_restart_num++;
|
||||
entropy->next_restart_num &= 7;
|
||||
}
|
||||
entropy->restarts_to_go--;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 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)
|
||||
encode_mcu_DC_refine (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
|
||||
{
|
||||
phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
|
||||
register int temp;
|
||||
int blkn;
|
||||
int Al = cinfo->Al;
|
||||
JBLOCKROW block;
|
||||
|
||||
entropy->next_output_byte = cinfo->dest->next_output_byte;
|
||||
entropy->free_in_buffer = cinfo->dest->free_in_buffer;
|
||||
|
||||
/* Emit restart marker if needed */
|
||||
if (cinfo->restart_interval)
|
||||
if (entropy->restarts_to_go == 0)
|
||||
emit_restart(entropy, entropy->next_restart_num);
|
||||
|
||||
/* Encode the MCU data blocks */
|
||||
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. */
|
||||
temp = (*block)[0];
|
||||
emit_bits(entropy, (unsigned int) (temp >> Al), 1);
|
||||
}
|
||||
|
||||
cinfo->dest->next_output_byte = entropy->next_output_byte;
|
||||
cinfo->dest->free_in_buffer = entropy->free_in_buffer;
|
||||
|
||||
/* Update restart-interval state too */
|
||||
if (cinfo->restart_interval) {
|
||||
if (entropy->restarts_to_go == 0) {
|
||||
entropy->restarts_to_go = cinfo->restart_interval;
|
||||
entropy->next_restart_num++;
|
||||
entropy->next_restart_num &= 7;
|
||||
}
|
||||
entropy->restarts_to_go--;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* MCU encoding for AC successive approximation refinement scan.
|
||||
*/
|
||||
|
||||
METHODDEF(boolean)
|
||||
encode_mcu_AC_refine (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
|
||||
{
|
||||
phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
|
||||
register int temp;
|
||||
register int r, k;
|
||||
int EOB;
|
||||
char *BR_buffer;
|
||||
unsigned int BR;
|
||||
int Se = cinfo->Se;
|
||||
int Al = cinfo->Al;
|
||||
JBLOCKROW block;
|
||||
int absvalues[DCTSIZE2];
|
||||
|
||||
entropy->next_output_byte = cinfo->dest->next_output_byte;
|
||||
entropy->free_in_buffer = cinfo->dest->free_in_buffer;
|
||||
|
||||
/* Emit restart marker if needed */
|
||||
if (cinfo->restart_interval)
|
||||
if (entropy->restarts_to_go == 0)
|
||||
emit_restart(entropy, entropy->next_restart_num);
|
||||
|
||||
/* Encode the MCU data block */
|
||||
block = MCU_data[0];
|
||||
|
||||
/* It is convenient to make a pre-pass to determine the transformed
|
||||
* coefficients' absolute values and the EOB position.
|
||||
*/
|
||||
EOB = 0;
|
||||
for (k = cinfo->Ss; k <= Se; k++) {
|
||||
temp = (*block)[jpeg_natural_order[k]];
|
||||
/* We must apply the point transform by Al. For AC coefficients this
|
||||
* is an integer division with rounding towards 0. To do this portably
|
||||
* in C, we shift after obtaining the absolute value.
|
||||
*/
|
||||
if (temp < 0)
|
||||
temp = -temp; /* temp is abs value of input */
|
||||
temp >>= Al; /* apply the point transform */
|
||||
absvalues[k] = temp; /* save abs value for main pass */
|
||||
if (temp == 1)
|
||||
EOB = k; /* EOB = index of last newly-nonzero coef */
|
||||
}
|
||||
|
||||
/* Encode the AC coefficients per section G.1.2.3, fig. G.7 */
|
||||
|
||||
r = 0; /* r = run length of zeros */
|
||||
BR = 0; /* BR = count of buffered bits added now */
|
||||
BR_buffer = entropy->bit_buffer + entropy->BE; /* Append bits to buffer */
|
||||
|
||||
for (k = cinfo->Ss; k <= Se; k++) {
|
||||
if ((temp = absvalues[k]) == 0) {
|
||||
r++;
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Emit any required ZRLs, but not if they can be folded into EOB */
|
||||
while (r > 15 && k <= EOB) {
|
||||
/* emit any pending EOBRUN and the BE correction bits */
|
||||
emit_eobrun(entropy);
|
||||
/* Emit ZRL */
|
||||
emit_symbol(entropy, entropy->ac_tbl_no, 0xF0);
|
||||
r -= 16;
|
||||
/* Emit buffered correction bits that must be associated with ZRL */
|
||||
emit_buffered_bits(entropy, BR_buffer, BR);
|
||||
BR_buffer = entropy->bit_buffer; /* BE bits are gone now */
|
||||
BR = 0;
|
||||
}
|
||||
|
||||
/* If the coef was previously nonzero, it only needs a correction bit.
|
||||
* NOTE: a straight translation of the spec's figure G.7 would suggest
|
||||
* that we also need to test r > 15. But if r > 15, we can only get here
|
||||
* if k > EOB, which implies that this coefficient is not 1.
|
||||
*/
|
||||
if (temp > 1) {
|
||||
/* The correction bit is the next bit of the absolute value. */
|
||||
BR_buffer[BR++] = (char) (temp & 1);
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Emit any pending EOBRUN and the BE correction bits */
|
||||
emit_eobrun(entropy);
|
||||
|
||||
/* Count/emit Huffman symbol for run length / number of bits */
|
||||
emit_symbol(entropy, entropy->ac_tbl_no, (r << 4) + 1);
|
||||
|
||||
/* Emit output bit for newly-nonzero coef */
|
||||
temp = ((*block)[jpeg_natural_order[k]] < 0) ? 0 : 1;
|
||||
emit_bits(entropy, (unsigned int) temp, 1);
|
||||
|
||||
/* Emit buffered correction bits that must be associated with this code */
|
||||
emit_buffered_bits(entropy, BR_buffer, BR);
|
||||
BR_buffer = entropy->bit_buffer; /* BE bits are gone now */
|
||||
BR = 0;
|
||||
r = 0; /* reset zero run length */
|
||||
}
|
||||
|
||||
if (r > 0 || BR > 0) { /* If there are trailing zeroes, */
|
||||
entropy->EOBRUN++; /* count an EOB */
|
||||
entropy->BE += BR; /* concat my correction bits to older ones */
|
||||
/* We force out the EOB if we risk either:
|
||||
* 1. overflow of the EOB counter;
|
||||
* 2. overflow of the correction bit buffer during the next MCU.
|
||||
*/
|
||||
if (entropy->EOBRUN == 0x7FFF || entropy->BE > (MAX_CORR_BITS-DCTSIZE2+1))
|
||||
emit_eobrun(entropy);
|
||||
}
|
||||
|
||||
cinfo->dest->next_output_byte = entropy->next_output_byte;
|
||||
cinfo->dest->free_in_buffer = entropy->free_in_buffer;
|
||||
|
||||
/* Update restart-interval state too */
|
||||
if (cinfo->restart_interval) {
|
||||
if (entropy->restarts_to_go == 0) {
|
||||
entropy->restarts_to_go = cinfo->restart_interval;
|
||||
entropy->next_restart_num++;
|
||||
entropy->next_restart_num &= 7;
|
||||
}
|
||||
entropy->restarts_to_go--;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Finish up at the end of a Huffman-compressed progressive scan.
|
||||
*/
|
||||
|
||||
METHODDEF(void)
|
||||
finish_pass_phuff (j_compress_ptr cinfo)
|
||||
{
|
||||
phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
|
||||
|
||||
entropy->next_output_byte = cinfo->dest->next_output_byte;
|
||||
entropy->free_in_buffer = cinfo->dest->free_in_buffer;
|
||||
|
||||
/* Flush out any buffered data */
|
||||
emit_eobrun(entropy);
|
||||
flush_bits(entropy);
|
||||
|
||||
cinfo->dest->next_output_byte = entropy->next_output_byte;
|
||||
cinfo->dest->free_in_buffer = entropy->free_in_buffer;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Finish up a statistics-gathering pass and create the new Huffman tables.
|
||||
*/
|
||||
|
||||
METHODDEF(void)
|
||||
finish_pass_gather_phuff (j_compress_ptr cinfo)
|
||||
{
|
||||
phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
|
||||
boolean is_DC_band;
|
||||
int ci, tbl;
|
||||
jpeg_component_info * compptr;
|
||||
JHUFF_TBL **htblptr;
|
||||
boolean did[NUM_HUFF_TBLS];
|
||||
|
||||
/* Flush out buffered data (all we care about is counting the EOB symbol) */
|
||||
emit_eobrun(entropy);
|
||||
|
||||
is_DC_band = (cinfo->Ss == 0);
|
||||
|
||||
/* It's important not to apply jpeg_gen_optimal_table more than once
|
||||
* per table, because it clobbers the input frequency counts!
|
||||
*/
|
||||
MEMZERO(did, SIZEOF(did));
|
||||
|
||||
for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
|
||||
compptr = cinfo->cur_comp_info[ci];
|
||||
if (is_DC_band) {
|
||||
if (cinfo->Ah != 0) /* DC refinement needs no table */
|
||||
continue;
|
||||
tbl = compptr->dc_tbl_no;
|
||||
} else {
|
||||
tbl = compptr->ac_tbl_no;
|
||||
}
|
||||
if (! did[tbl]) {
|
||||
if (is_DC_band)
|
||||
htblptr = & cinfo->dc_huff_tbl_ptrs[tbl];
|
||||
else
|
||||
htblptr = & cinfo->ac_huff_tbl_ptrs[tbl];
|
||||
if (*htblptr == NULL)
|
||||
*htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
|
||||
jpeg_gen_optimal_table(cinfo, *htblptr, entropy->count_ptrs[tbl]);
|
||||
did[tbl] = TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Module initialization routine for progressive Huffman entropy encoding.
|
||||
*/
|
||||
|
||||
GLOBAL(void)
|
||||
jinit_phuff_encoder (j_compress_ptr cinfo)
|
||||
{
|
||||
phuff_entropy_ptr entropy;
|
||||
int i;
|
||||
|
||||
entropy = (phuff_entropy_ptr)
|
||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
||||
SIZEOF(phuff_entropy_encoder));
|
||||
cinfo->entropy = (struct jpeg_entropy_encoder *) entropy;
|
||||
entropy->pub.start_pass = start_pass_phuff;
|
||||
|
||||
/* Mark tables unallocated */
|
||||
for (i = 0; i < NUM_HUFF_TBLS; i++) {
|
||||
entropy->derived_tbls[i] = NULL;
|
||||
entropy->count_ptrs[i] = NULL;
|
||||
}
|
||||
entropy->bit_buffer = NULL; /* needed only in AC refinement scan */
|
||||
}
|
||||
|
||||
#endif /* C_PROGRESSIVE_SUPPORTED */
|
120
3rdparty/libjpeg/jcprepct.c
vendored
120
3rdparty/libjpeg/jcprepct.c
vendored
@ -104,13 +104,13 @@ start_pass_prep (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
|
||||
|
||||
LOCAL(void)
|
||||
expand_bottom_edge (JSAMPARRAY image_data, JDIMENSION num_cols,
|
||||
int input_rows, int output_rows)
|
||||
int input_rows, int output_rows)
|
||||
{
|
||||
register int row;
|
||||
|
||||
for (row = input_rows; row < output_rows; row++) {
|
||||
jcopy_sample_rows(image_data, input_rows-1, image_data, row,
|
||||
1, num_cols);
|
||||
1, num_cols);
|
||||
}
|
||||
}
|
||||
|
||||
@ -126,10 +126,10 @@ expand_bottom_edge (JSAMPARRAY image_data, JDIMENSION num_cols,
|
||||
|
||||
METHODDEF(void)
|
||||
pre_process_data (j_compress_ptr cinfo,
|
||||
JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
|
||||
JDIMENSION in_rows_avail,
|
||||
JSAMPIMAGE output_buf, JDIMENSION *out_row_group_ctr,
|
||||
JDIMENSION out_row_groups_avail)
|
||||
JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
|
||||
JDIMENSION in_rows_avail,
|
||||
JSAMPIMAGE output_buf, JDIMENSION *out_row_group_ctr,
|
||||
JDIMENSION out_row_groups_avail)
|
||||
{
|
||||
my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
|
||||
int numrows, ci;
|
||||
@ -137,32 +137,32 @@ pre_process_data (j_compress_ptr cinfo,
|
||||
jpeg_component_info * compptr;
|
||||
|
||||
while (*in_row_ctr < in_rows_avail &&
|
||||
*out_row_group_ctr < out_row_groups_avail) {
|
||||
*out_row_group_ctr < out_row_groups_avail) {
|
||||
/* Do color conversion to fill the conversion buffer. */
|
||||
inrows = in_rows_avail - *in_row_ctr;
|
||||
numrows = cinfo->max_v_samp_factor - prep->next_buf_row;
|
||||
numrows = (int) MIN((JDIMENSION) numrows, inrows);
|
||||
(*cinfo->cconvert->color_convert) (cinfo, input_buf + *in_row_ctr,
|
||||
prep->color_buf,
|
||||
(JDIMENSION) prep->next_buf_row,
|
||||
numrows);
|
||||
prep->color_buf,
|
||||
(JDIMENSION) prep->next_buf_row,
|
||||
numrows);
|
||||
*in_row_ctr += numrows;
|
||||
prep->next_buf_row += numrows;
|
||||
prep->rows_to_go -= numrows;
|
||||
/* If at bottom of image, pad to fill the conversion buffer. */
|
||||
if (prep->rows_to_go == 0 &&
|
||||
prep->next_buf_row < cinfo->max_v_samp_factor) {
|
||||
prep->next_buf_row < cinfo->max_v_samp_factor) {
|
||||
for (ci = 0; ci < cinfo->num_components; ci++) {
|
||||
expand_bottom_edge(prep->color_buf[ci], cinfo->image_width,
|
||||
prep->next_buf_row, cinfo->max_v_samp_factor);
|
||||
expand_bottom_edge(prep->color_buf[ci], cinfo->image_width,
|
||||
prep->next_buf_row, cinfo->max_v_samp_factor);
|
||||
}
|
||||
prep->next_buf_row = cinfo->max_v_samp_factor;
|
||||
}
|
||||
/* If we've filled the conversion buffer, empty it. */
|
||||
if (prep->next_buf_row == cinfo->max_v_samp_factor) {
|
||||
(*cinfo->downsample->downsample) (cinfo,
|
||||
prep->color_buf, (JDIMENSION) 0,
|
||||
output_buf, *out_row_group_ctr);
|
||||
prep->color_buf, (JDIMENSION) 0,
|
||||
output_buf, *out_row_group_ctr);
|
||||
prep->next_buf_row = 0;
|
||||
(*out_row_group_ctr)++;
|
||||
}
|
||||
@ -170,13 +170,15 @@ pre_process_data (j_compress_ptr cinfo,
|
||||
* Note we assume the caller is providing a one-iMCU-height output buffer!
|
||||
*/
|
||||
if (prep->rows_to_go == 0 &&
|
||||
*out_row_group_ctr < out_row_groups_avail) {
|
||||
*out_row_group_ctr < out_row_groups_avail) {
|
||||
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
|
||||
ci++, compptr++) {
|
||||
expand_bottom_edge(output_buf[ci],
|
||||
compptr->width_in_blocks * DCTSIZE,
|
||||
(int) (*out_row_group_ctr * compptr->v_samp_factor),
|
||||
(int) (out_row_groups_avail * compptr->v_samp_factor));
|
||||
ci++, compptr++) {
|
||||
numrows = (compptr->v_samp_factor * compptr->DCT_v_scaled_size) /
|
||||
cinfo->min_DCT_v_scaled_size;
|
||||
expand_bottom_edge(output_buf[ci],
|
||||
compptr->width_in_blocks * compptr->DCT_h_scaled_size,
|
||||
(int) (*out_row_group_ctr * numrows),
|
||||
(int) (out_row_groups_avail * numrows));
|
||||
}
|
||||
*out_row_group_ctr = out_row_groups_avail;
|
||||
break; /* can exit outer loop without test */
|
||||
@ -193,10 +195,10 @@ pre_process_data (j_compress_ptr cinfo,
|
||||
|
||||
METHODDEF(void)
|
||||
pre_process_context (j_compress_ptr cinfo,
|
||||
JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
|
||||
JDIMENSION in_rows_avail,
|
||||
JSAMPIMAGE output_buf, JDIMENSION *out_row_group_ctr,
|
||||
JDIMENSION out_row_groups_avail)
|
||||
JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
|
||||
JDIMENSION in_rows_avail,
|
||||
JSAMPIMAGE output_buf, JDIMENSION *out_row_group_ctr,
|
||||
JDIMENSION out_row_groups_avail)
|
||||
{
|
||||
my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
|
||||
int numrows, ci;
|
||||
@ -210,19 +212,19 @@ pre_process_context (j_compress_ptr cinfo,
|
||||
numrows = prep->next_buf_stop - prep->next_buf_row;
|
||||
numrows = (int) MIN((JDIMENSION) numrows, inrows);
|
||||
(*cinfo->cconvert->color_convert) (cinfo, input_buf + *in_row_ctr,
|
||||
prep->color_buf,
|
||||
(JDIMENSION) prep->next_buf_row,
|
||||
numrows);
|
||||
prep->color_buf,
|
||||
(JDIMENSION) prep->next_buf_row,
|
||||
numrows);
|
||||
/* Pad at top of image, if first time through */
|
||||
if (prep->rows_to_go == cinfo->image_height) {
|
||||
for (ci = 0; ci < cinfo->num_components; ci++) {
|
||||
int row;
|
||||
for (row = 1; row <= cinfo->max_v_samp_factor; row++) {
|
||||
jcopy_sample_rows(prep->color_buf[ci], 0,
|
||||
prep->color_buf[ci], -row,
|
||||
1, cinfo->image_width);
|
||||
}
|
||||
}
|
||||
for (ci = 0; ci < cinfo->num_components; ci++) {
|
||||
int row;
|
||||
for (row = 1; row <= cinfo->max_v_samp_factor; row++) {
|
||||
jcopy_sample_rows(prep->color_buf[ci], 0,
|
||||
prep->color_buf[ci], -row,
|
||||
1, cinfo->image_width);
|
||||
}
|
||||
}
|
||||
}
|
||||
*in_row_ctr += numrows;
|
||||
prep->next_buf_row += numrows;
|
||||
@ -230,29 +232,29 @@ pre_process_context (j_compress_ptr cinfo,
|
||||
} else {
|
||||
/* Return for more data, unless we are at the bottom of the image. */
|
||||
if (prep->rows_to_go != 0)
|
||||
break;
|
||||
break;
|
||||
/* When at bottom of image, pad to fill the conversion buffer. */
|
||||
if (prep->next_buf_row < prep->next_buf_stop) {
|
||||
for (ci = 0; ci < cinfo->num_components; ci++) {
|
||||
expand_bottom_edge(prep->color_buf[ci], cinfo->image_width,
|
||||
prep->next_buf_row, prep->next_buf_stop);
|
||||
}
|
||||
prep->next_buf_row = prep->next_buf_stop;
|
||||
for (ci = 0; ci < cinfo->num_components; ci++) {
|
||||
expand_bottom_edge(prep->color_buf[ci], cinfo->image_width,
|
||||
prep->next_buf_row, prep->next_buf_stop);
|
||||
}
|
||||
prep->next_buf_row = prep->next_buf_stop;
|
||||
}
|
||||
}
|
||||
/* If we've gotten enough data, downsample a row group. */
|
||||
if (prep->next_buf_row == prep->next_buf_stop) {
|
||||
(*cinfo->downsample->downsample) (cinfo,
|
||||
prep->color_buf,
|
||||
(JDIMENSION) prep->this_row_group,
|
||||
output_buf, *out_row_group_ctr);
|
||||
prep->color_buf,
|
||||
(JDIMENSION) prep->this_row_group,
|
||||
output_buf, *out_row_group_ctr);
|
||||
(*out_row_group_ctr)++;
|
||||
/* Advance pointers with wraparound as necessary. */
|
||||
prep->this_row_group += cinfo->max_v_samp_factor;
|
||||
if (prep->this_row_group >= buf_height)
|
||||
prep->this_row_group = 0;
|
||||
prep->this_row_group = 0;
|
||||
if (prep->next_buf_row >= buf_height)
|
||||
prep->next_buf_row = 0;
|
||||
prep->next_buf_row = 0;
|
||||
prep->next_buf_stop = prep->next_buf_row + cinfo->max_v_samp_factor;
|
||||
}
|
||||
}
|
||||
@ -277,8 +279,8 @@ create_context_buffer (j_compress_ptr cinfo)
|
||||
*/
|
||||
fake_buffer = (JSAMPARRAY)
|
||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
||||
(cinfo->num_components * 5 * rgroup_height) *
|
||||
SIZEOF(JSAMPROW));
|
||||
(cinfo->num_components * 5 * rgroup_height) *
|
||||
SIZEOF(JSAMPROW));
|
||||
|
||||
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
|
||||
ci++, compptr++) {
|
||||
@ -288,12 +290,13 @@ create_context_buffer (j_compress_ptr cinfo)
|
||||
*/
|
||||
true_buffer = (*cinfo->mem->alloc_sarray)
|
||||
((j_common_ptr) cinfo, JPOOL_IMAGE,
|
||||
(JDIMENSION) (((long) compptr->width_in_blocks * DCTSIZE *
|
||||
cinfo->max_h_samp_factor) / compptr->h_samp_factor),
|
||||
(JDIMENSION) (((long) compptr->width_in_blocks *
|
||||
cinfo->min_DCT_h_scaled_size *
|
||||
cinfo->max_h_samp_factor) / compptr->h_samp_factor),
|
||||
(JDIMENSION) (3 * rgroup_height));
|
||||
/* Copy true buffer row pointers into the middle of the fake row array */
|
||||
MEMCOPY(fake_buffer + rgroup_height, true_buffer,
|
||||
3 * rgroup_height * SIZEOF(JSAMPROW));
|
||||
3 * rgroup_height * SIZEOF(JSAMPROW));
|
||||
/* Fill in the above and below wraparound pointers */
|
||||
for (i = 0; i < rgroup_height; i++) {
|
||||
fake_buffer[i] = true_buffer[2 * rgroup_height + i];
|
||||
@ -323,7 +326,7 @@ jinit_c_prep_controller (j_compress_ptr cinfo, boolean need_full_buffer)
|
||||
|
||||
prep = (my_prep_ptr)
|
||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
||||
SIZEOF(my_prep_controller));
|
||||
SIZEOF(my_prep_controller));
|
||||
cinfo->prep = (struct jpeg_c_prep_controller *) prep;
|
||||
prep->pub.start_pass = start_pass_prep;
|
||||
|
||||
@ -343,12 +346,13 @@ jinit_c_prep_controller (j_compress_ptr cinfo, boolean need_full_buffer)
|
||||
/* No context, just make it tall enough for one row group */
|
||||
prep->pub.pre_process_data = pre_process_data;
|
||||
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
|
||||
ci++, compptr++) {
|
||||
ci++, compptr++) {
|
||||
prep->color_buf[ci] = (*cinfo->mem->alloc_sarray)
|
||||
((j_common_ptr) cinfo, JPOOL_IMAGE,
|
||||
(JDIMENSION) (((long) compptr->width_in_blocks * DCTSIZE *
|
||||
cinfo->max_h_samp_factor) / compptr->h_samp_factor),
|
||||
(JDIMENSION) cinfo->max_v_samp_factor);
|
||||
((j_common_ptr) cinfo, JPOOL_IMAGE,
|
||||
(JDIMENSION) (((long) compptr->width_in_blocks *
|
||||
cinfo->min_DCT_h_scaled_size *
|
||||
cinfo->max_h_samp_factor) / compptr->h_samp_factor),
|
||||
(JDIMENSION) cinfo->max_v_samp_factor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
196
3rdparty/libjpeg/jcsample.c
vendored
196
3rdparty/libjpeg/jcsample.c
vendored
@ -52,8 +52,8 @@
|
||||
|
||||
/* Pointer to routine to downsample a single component */
|
||||
typedef JMETHOD(void, downsample1_ptr,
|
||||
(j_compress_ptr cinfo, jpeg_component_info * compptr,
|
||||
JSAMPARRAY input_data, JSAMPARRAY output_data));
|
||||
(j_compress_ptr cinfo, jpeg_component_info * compptr,
|
||||
JSAMPARRAY input_data, JSAMPARRAY output_data));
|
||||
|
||||
/* Private subobject */
|
||||
|
||||
@ -62,6 +62,15 @@ typedef struct {
|
||||
|
||||
/* Downsampling method pointers, one per component */
|
||||
downsample1_ptr methods[MAX_COMPONENTS];
|
||||
|
||||
/* Height of an output row group for each component. */
|
||||
int rowgroup_height[MAX_COMPONENTS];
|
||||
|
||||
/* These arrays save pixel expansion factors so that int_downsample need not
|
||||
* recompute them each time. They are unused for other downsampling methods.
|
||||
*/
|
||||
UINT8 h_expand[MAX_COMPONENTS];
|
||||
UINT8 v_expand[MAX_COMPONENTS];
|
||||
} my_downsampler;
|
||||
|
||||
typedef my_downsampler * my_downsample_ptr;
|
||||
@ -85,7 +94,7 @@ start_pass_downsample (j_compress_ptr cinfo)
|
||||
|
||||
LOCAL(void)
|
||||
expand_right_edge (JSAMPARRAY image_data, int num_rows,
|
||||
JDIMENSION input_cols, JDIMENSION output_cols)
|
||||
JDIMENSION input_cols, JDIMENSION output_cols)
|
||||
{
|
||||
register JSAMPROW ptr;
|
||||
register JSAMPLE pixval;
|
||||
@ -98,7 +107,7 @@ expand_right_edge (JSAMPARRAY image_data, int num_rows,
|
||||
ptr = image_data[row] + input_cols;
|
||||
pixval = ptr[-1]; /* don't need GETJSAMPLE() here */
|
||||
for (count = numcols; count > 0; count--)
|
||||
*ptr++ = pixval;
|
||||
*ptr++ = pixval;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -112,8 +121,8 @@ expand_right_edge (JSAMPARRAY image_data, int num_rows,
|
||||
|
||||
METHODDEF(void)
|
||||
sep_downsample (j_compress_ptr cinfo,
|
||||
JSAMPIMAGE input_buf, JDIMENSION in_row_index,
|
||||
JSAMPIMAGE output_buf, JDIMENSION out_row_group_index)
|
||||
JSAMPIMAGE input_buf, JDIMENSION in_row_index,
|
||||
JSAMPIMAGE output_buf, JDIMENSION out_row_group_index)
|
||||
{
|
||||
my_downsample_ptr downsample = (my_downsample_ptr) cinfo->downsample;
|
||||
int ci;
|
||||
@ -123,7 +132,8 @@ sep_downsample (j_compress_ptr cinfo,
|
||||
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
|
||||
ci++, compptr++) {
|
||||
in_ptr = input_buf[ci] + in_row_index;
|
||||
out_ptr = output_buf[ci] + (out_row_group_index * compptr->v_samp_factor);
|
||||
out_ptr = output_buf[ci] +
|
||||
(out_row_group_index * downsample->rowgroup_height[ci]);
|
||||
(*downsample->methods[ci]) (cinfo, compptr, in_ptr, out_ptr);
|
||||
}
|
||||
}
|
||||
@ -138,16 +148,17 @@ sep_downsample (j_compress_ptr cinfo,
|
||||
|
||||
METHODDEF(void)
|
||||
int_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
|
||||
JSAMPARRAY input_data, JSAMPARRAY output_data)
|
||||
JSAMPARRAY input_data, JSAMPARRAY output_data)
|
||||
{
|
||||
my_downsample_ptr downsample = (my_downsample_ptr) cinfo->downsample;
|
||||
int inrow, outrow, h_expand, v_expand, numpix, numpix2, h, v;
|
||||
JDIMENSION outcol, outcol_h; /* outcol_h == outcol*h_expand */
|
||||
JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
|
||||
JDIMENSION output_cols = compptr->width_in_blocks * compptr->DCT_h_scaled_size;
|
||||
JSAMPROW inptr, outptr;
|
||||
INT32 outvalue;
|
||||
|
||||
h_expand = cinfo->max_h_samp_factor / compptr->h_samp_factor;
|
||||
v_expand = cinfo->max_v_samp_factor / compptr->v_samp_factor;
|
||||
h_expand = downsample->h_expand[compptr->component_index];
|
||||
v_expand = downsample->v_expand[compptr->component_index];
|
||||
numpix = h_expand * v_expand;
|
||||
numpix2 = numpix/2;
|
||||
|
||||
@ -156,23 +167,24 @@ int_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
|
||||
* efficient.
|
||||
*/
|
||||
expand_right_edge(input_data, cinfo->max_v_samp_factor,
|
||||
cinfo->image_width, output_cols * h_expand);
|
||||
cinfo->image_width, output_cols * h_expand);
|
||||
|
||||
inrow = 0;
|
||||
for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
|
||||
inrow = outrow = 0;
|
||||
while (inrow < cinfo->max_v_samp_factor) {
|
||||
outptr = output_data[outrow];
|
||||
for (outcol = 0, outcol_h = 0; outcol < output_cols;
|
||||
outcol++, outcol_h += h_expand) {
|
||||
outcol++, outcol_h += h_expand) {
|
||||
outvalue = 0;
|
||||
for (v = 0; v < v_expand; v++) {
|
||||
inptr = input_data[inrow+v] + outcol_h;
|
||||
for (h = 0; h < h_expand; h++) {
|
||||
outvalue += (INT32) GETJSAMPLE(*inptr++);
|
||||
}
|
||||
inptr = input_data[inrow+v] + outcol_h;
|
||||
for (h = 0; h < h_expand; h++) {
|
||||
outvalue += (INT32) GETJSAMPLE(*inptr++);
|
||||
}
|
||||
}
|
||||
*outptr++ = (JSAMPLE) ((outvalue + numpix2) / numpix);
|
||||
}
|
||||
inrow += v_expand;
|
||||
outrow++;
|
||||
}
|
||||
}
|
||||
|
||||
@ -185,14 +197,14 @@ int_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
|
||||
|
||||
METHODDEF(void)
|
||||
fullsize_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
|
||||
JSAMPARRAY input_data, JSAMPARRAY output_data)
|
||||
JSAMPARRAY input_data, JSAMPARRAY output_data)
|
||||
{
|
||||
/* Copy the data */
|
||||
jcopy_sample_rows(input_data, 0, output_data, 0,
|
||||
cinfo->max_v_samp_factor, cinfo->image_width);
|
||||
cinfo->max_v_samp_factor, cinfo->image_width);
|
||||
/* Edge-expand */
|
||||
expand_right_edge(output_data, cinfo->max_v_samp_factor,
|
||||
cinfo->image_width, compptr->width_in_blocks * DCTSIZE);
|
||||
expand_right_edge(output_data, cinfo->max_v_samp_factor, cinfo->image_width,
|
||||
compptr->width_in_blocks * compptr->DCT_h_scaled_size);
|
||||
}
|
||||
|
||||
|
||||
@ -210,11 +222,11 @@ fullsize_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
|
||||
|
||||
METHODDEF(void)
|
||||
h2v1_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
|
||||
JSAMPARRAY input_data, JSAMPARRAY output_data)
|
||||
JSAMPARRAY input_data, JSAMPARRAY output_data)
|
||||
{
|
||||
int outrow;
|
||||
int inrow;
|
||||
JDIMENSION outcol;
|
||||
JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
|
||||
JDIMENSION output_cols = compptr->width_in_blocks * compptr->DCT_h_scaled_size;
|
||||
register JSAMPROW inptr, outptr;
|
||||
register int bias;
|
||||
|
||||
@ -223,15 +235,15 @@ h2v1_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
|
||||
* efficient.
|
||||
*/
|
||||
expand_right_edge(input_data, cinfo->max_v_samp_factor,
|
||||
cinfo->image_width, output_cols * 2);
|
||||
cinfo->image_width, output_cols * 2);
|
||||
|
||||
for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
|
||||
outptr = output_data[outrow];
|
||||
inptr = input_data[outrow];
|
||||
for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) {
|
||||
outptr = output_data[inrow];
|
||||
inptr = input_data[inrow];
|
||||
bias = 0; /* bias = 0,1,0,1,... for successive samples */
|
||||
for (outcol = 0; outcol < output_cols; outcol++) {
|
||||
*outptr++ = (JSAMPLE) ((GETJSAMPLE(*inptr) + GETJSAMPLE(inptr[1])
|
||||
+ bias) >> 1);
|
||||
+ bias) >> 1);
|
||||
bias ^= 1; /* 0=>1, 1=>0 */
|
||||
inptr += 2;
|
||||
}
|
||||
@ -247,11 +259,11 @@ h2v1_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
|
||||
|
||||
METHODDEF(void)
|
||||
h2v2_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
|
||||
JSAMPARRAY input_data, JSAMPARRAY output_data)
|
||||
JSAMPARRAY input_data, JSAMPARRAY output_data)
|
||||
{
|
||||
int inrow, outrow;
|
||||
JDIMENSION outcol;
|
||||
JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
|
||||
JDIMENSION output_cols = compptr->width_in_blocks * compptr->DCT_h_scaled_size;
|
||||
register JSAMPROW inptr0, inptr1, outptr;
|
||||
register int bias;
|
||||
|
||||
@ -260,22 +272,23 @@ h2v2_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
|
||||
* efficient.
|
||||
*/
|
||||
expand_right_edge(input_data, cinfo->max_v_samp_factor,
|
||||
cinfo->image_width, output_cols * 2);
|
||||
cinfo->image_width, output_cols * 2);
|
||||
|
||||
inrow = 0;
|
||||
for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
|
||||
inrow = outrow = 0;
|
||||
while (inrow < cinfo->max_v_samp_factor) {
|
||||
outptr = output_data[outrow];
|
||||
inptr0 = input_data[inrow];
|
||||
inptr1 = input_data[inrow+1];
|
||||
bias = 1; /* bias = 1,2,1,2,... for successive samples */
|
||||
for (outcol = 0; outcol < output_cols; outcol++) {
|
||||
*outptr++ = (JSAMPLE) ((GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
|
||||
GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1])
|
||||
+ bias) >> 2);
|
||||
GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1])
|
||||
+ bias) >> 2);
|
||||
bias ^= 3; /* 1=>2, 2=>1 */
|
||||
inptr0 += 2; inptr1 += 2;
|
||||
}
|
||||
inrow += 2;
|
||||
outrow++;
|
||||
}
|
||||
}
|
||||
|
||||
@ -290,11 +303,11 @@ h2v2_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
|
||||
|
||||
METHODDEF(void)
|
||||
h2v2_smooth_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
|
||||
JSAMPARRAY input_data, JSAMPARRAY output_data)
|
||||
JSAMPARRAY input_data, JSAMPARRAY output_data)
|
||||
{
|
||||
int inrow, outrow;
|
||||
JDIMENSION colctr;
|
||||
JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
|
||||
JDIMENSION output_cols = compptr->width_in_blocks * compptr->DCT_h_scaled_size;
|
||||
register JSAMPROW inptr0, inptr1, above_ptr, below_ptr, outptr;
|
||||
INT32 membersum, neighsum, memberscale, neighscale;
|
||||
|
||||
@ -303,7 +316,7 @@ h2v2_smooth_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
|
||||
* efficient.
|
||||
*/
|
||||
expand_right_edge(input_data - 1, cinfo->max_v_samp_factor + 2,
|
||||
cinfo->image_width, output_cols * 2);
|
||||
cinfo->image_width, output_cols * 2);
|
||||
|
||||
/* We don't bother to form the individual "smoothed" input pixel values;
|
||||
* we can directly compute the output which is the average of the four
|
||||
@ -321,8 +334,8 @@ h2v2_smooth_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
|
||||
memberscale = 16384 - cinfo->smoothing_factor * 80; /* scaled (1-5*SF)/4 */
|
||||
neighscale = cinfo->smoothing_factor * 16; /* scaled SF/4 */
|
||||
|
||||
inrow = 0;
|
||||
for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
|
||||
inrow = outrow = 0;
|
||||
while (inrow < cinfo->max_v_samp_factor) {
|
||||
outptr = output_data[outrow];
|
||||
inptr0 = input_data[inrow];
|
||||
inptr1 = input_data[inrow+1];
|
||||
@ -331,14 +344,14 @@ h2v2_smooth_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
|
||||
|
||||
/* Special case for first column: pretend column -1 is same as column 0 */
|
||||
membersum = GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
|
||||
GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]);
|
||||
GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]);
|
||||
neighsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[1]) +
|
||||
GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[1]) +
|
||||
GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[2]) +
|
||||
GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[2]);
|
||||
GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[1]) +
|
||||
GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[2]) +
|
||||
GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[2]);
|
||||
neighsum += neighsum;
|
||||
neighsum += GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[2]) +
|
||||
GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[2]);
|
||||
GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[2]);
|
||||
membersum = membersum * memberscale + neighsum * neighscale;
|
||||
*outptr++ = (JSAMPLE) ((membersum + 32768) >> 16);
|
||||
inptr0 += 2; inptr1 += 2; above_ptr += 2; below_ptr += 2;
|
||||
@ -346,17 +359,17 @@ h2v2_smooth_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
|
||||
for (colctr = output_cols - 2; colctr > 0; colctr--) {
|
||||
/* sum of pixels directly mapped to this output element */
|
||||
membersum = GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
|
||||
GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]);
|
||||
GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]);
|
||||
/* sum of edge-neighbor pixels */
|
||||
neighsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[1]) +
|
||||
GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[1]) +
|
||||
GETJSAMPLE(inptr0[-1]) + GETJSAMPLE(inptr0[2]) +
|
||||
GETJSAMPLE(inptr1[-1]) + GETJSAMPLE(inptr1[2]);
|
||||
GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[1]) +
|
||||
GETJSAMPLE(inptr0[-1]) + GETJSAMPLE(inptr0[2]) +
|
||||
GETJSAMPLE(inptr1[-1]) + GETJSAMPLE(inptr1[2]);
|
||||
/* The edge-neighbors count twice as much as corner-neighbors */
|
||||
neighsum += neighsum;
|
||||
/* Add in the corner-neighbors */
|
||||
neighsum += GETJSAMPLE(above_ptr[-1]) + GETJSAMPLE(above_ptr[2]) +
|
||||
GETJSAMPLE(below_ptr[-1]) + GETJSAMPLE(below_ptr[2]);
|
||||
GETJSAMPLE(below_ptr[-1]) + GETJSAMPLE(below_ptr[2]);
|
||||
/* form final output scaled up by 2^16 */
|
||||
membersum = membersum * memberscale + neighsum * neighscale;
|
||||
/* round, descale and output it */
|
||||
@ -366,18 +379,19 @@ h2v2_smooth_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
|
||||
|
||||
/* Special case for last column */
|
||||
membersum = GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
|
||||
GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]);
|
||||
GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]);
|
||||
neighsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[1]) +
|
||||
GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[1]) +
|
||||
GETJSAMPLE(inptr0[-1]) + GETJSAMPLE(inptr0[1]) +
|
||||
GETJSAMPLE(inptr1[-1]) + GETJSAMPLE(inptr1[1]);
|
||||
GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[1]) +
|
||||
GETJSAMPLE(inptr0[-1]) + GETJSAMPLE(inptr0[1]) +
|
||||
GETJSAMPLE(inptr1[-1]) + GETJSAMPLE(inptr1[1]);
|
||||
neighsum += neighsum;
|
||||
neighsum += GETJSAMPLE(above_ptr[-1]) + GETJSAMPLE(above_ptr[1]) +
|
||||
GETJSAMPLE(below_ptr[-1]) + GETJSAMPLE(below_ptr[1]);
|
||||
GETJSAMPLE(below_ptr[-1]) + GETJSAMPLE(below_ptr[1]);
|
||||
membersum = membersum * memberscale + neighsum * neighscale;
|
||||
*outptr = (JSAMPLE) ((membersum + 32768) >> 16);
|
||||
|
||||
inrow += 2;
|
||||
outrow++;
|
||||
}
|
||||
}
|
||||
|
||||
@ -390,11 +404,11 @@ h2v2_smooth_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
|
||||
|
||||
METHODDEF(void)
|
||||
fullsize_smooth_downsample (j_compress_ptr cinfo, jpeg_component_info *compptr,
|
||||
JSAMPARRAY input_data, JSAMPARRAY output_data)
|
||||
JSAMPARRAY input_data, JSAMPARRAY output_data)
|
||||
{
|
||||
int outrow;
|
||||
int inrow;
|
||||
JDIMENSION colctr;
|
||||
JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
|
||||
JDIMENSION output_cols = compptr->width_in_blocks * compptr->DCT_h_scaled_size;
|
||||
register JSAMPROW inptr, above_ptr, below_ptr, outptr;
|
||||
INT32 membersum, neighsum, memberscale, neighscale;
|
||||
int colsum, lastcolsum, nextcolsum;
|
||||
@ -404,7 +418,7 @@ fullsize_smooth_downsample (j_compress_ptr cinfo, jpeg_component_info *compptr,
|
||||
* efficient.
|
||||
*/
|
||||
expand_right_edge(input_data - 1, cinfo->max_v_samp_factor + 2,
|
||||
cinfo->image_width, output_cols);
|
||||
cinfo->image_width, output_cols);
|
||||
|
||||
/* Each of the eight neighbor pixels contributes a fraction SF to the
|
||||
* smoothed pixel, while the main pixel contributes (1-8*SF). In order
|
||||
@ -415,18 +429,18 @@ fullsize_smooth_downsample (j_compress_ptr cinfo, jpeg_component_info *compptr,
|
||||
memberscale = 65536L - cinfo->smoothing_factor * 512L; /* scaled 1-8*SF */
|
||||
neighscale = cinfo->smoothing_factor * 64; /* scaled SF */
|
||||
|
||||
for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
|
||||
outptr = output_data[outrow];
|
||||
inptr = input_data[outrow];
|
||||
above_ptr = input_data[outrow-1];
|
||||
below_ptr = input_data[outrow+1];
|
||||
for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) {
|
||||
outptr = output_data[inrow];
|
||||
inptr = input_data[inrow];
|
||||
above_ptr = input_data[inrow-1];
|
||||
below_ptr = input_data[inrow+1];
|
||||
|
||||
/* Special case for first column */
|
||||
colsum = GETJSAMPLE(*above_ptr++) + GETJSAMPLE(*below_ptr++) +
|
||||
GETJSAMPLE(*inptr);
|
||||
GETJSAMPLE(*inptr);
|
||||
membersum = GETJSAMPLE(*inptr++);
|
||||
nextcolsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(*below_ptr) +
|
||||
GETJSAMPLE(*inptr);
|
||||
GETJSAMPLE(*inptr);
|
||||
neighsum = colsum + (colsum - membersum) + nextcolsum;
|
||||
membersum = membersum * memberscale + neighsum * neighscale;
|
||||
*outptr++ = (JSAMPLE) ((membersum + 32768) >> 16);
|
||||
@ -436,7 +450,7 @@ fullsize_smooth_downsample (j_compress_ptr cinfo, jpeg_component_info *compptr,
|
||||
membersum = GETJSAMPLE(*inptr++);
|
||||
above_ptr++; below_ptr++;
|
||||
nextcolsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(*below_ptr) +
|
||||
GETJSAMPLE(*inptr);
|
||||
GETJSAMPLE(*inptr);
|
||||
neighsum = lastcolsum + (colsum - membersum) + nextcolsum;
|
||||
membersum = membersum * memberscale + neighsum * neighscale;
|
||||
*outptr++ = (JSAMPLE) ((membersum + 32768) >> 16);
|
||||
@ -467,10 +481,11 @@ jinit_downsampler (j_compress_ptr cinfo)
|
||||
int ci;
|
||||
jpeg_component_info * compptr;
|
||||
boolean smoothok = TRUE;
|
||||
int h_in_group, v_in_group, h_out_group, v_out_group;
|
||||
|
||||
downsample = (my_downsample_ptr)
|
||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
||||
SIZEOF(my_downsampler));
|
||||
SIZEOF(my_downsampler));
|
||||
cinfo->downsample = (struct jpeg_downsampler *) downsample;
|
||||
downsample->pub.start_pass = start_pass_downsample;
|
||||
downsample->pub.downsample = sep_downsample;
|
||||
@ -482,32 +497,43 @@ jinit_downsampler (j_compress_ptr cinfo)
|
||||
/* Verify we can handle the sampling factors, and set up method pointers */
|
||||
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
|
||||
ci++, compptr++) {
|
||||
if (compptr->h_samp_factor == cinfo->max_h_samp_factor &&
|
||||
compptr->v_samp_factor == cinfo->max_v_samp_factor) {
|
||||
/* Compute size of an "output group" for DCT scaling. This many samples
|
||||
* are to be converted from max_h_samp_factor * max_v_samp_factor pixels.
|
||||
*/
|
||||
h_out_group = (compptr->h_samp_factor * compptr->DCT_h_scaled_size) /
|
||||
cinfo->min_DCT_h_scaled_size;
|
||||
v_out_group = (compptr->v_samp_factor * compptr->DCT_v_scaled_size) /
|
||||
cinfo->min_DCT_v_scaled_size;
|
||||
h_in_group = cinfo->max_h_samp_factor;
|
||||
v_in_group = cinfo->max_v_samp_factor;
|
||||
downsample->rowgroup_height[ci] = v_out_group; /* save for use later */
|
||||
if (h_in_group == h_out_group && v_in_group == v_out_group) {
|
||||
#ifdef INPUT_SMOOTHING_SUPPORTED
|
||||
if (cinfo->smoothing_factor) {
|
||||
downsample->methods[ci] = fullsize_smooth_downsample;
|
||||
downsample->pub.need_context_rows = TRUE;
|
||||
downsample->methods[ci] = fullsize_smooth_downsample;
|
||||
downsample->pub.need_context_rows = TRUE;
|
||||
} else
|
||||
#endif
|
||||
downsample->methods[ci] = fullsize_downsample;
|
||||
} else if (compptr->h_samp_factor * 2 == cinfo->max_h_samp_factor &&
|
||||
compptr->v_samp_factor == cinfo->max_v_samp_factor) {
|
||||
downsample->methods[ci] = fullsize_downsample;
|
||||
} else if (h_in_group == h_out_group * 2 &&
|
||||
v_in_group == v_out_group) {
|
||||
smoothok = FALSE;
|
||||
downsample->methods[ci] = h2v1_downsample;
|
||||
} else if (compptr->h_samp_factor * 2 == cinfo->max_h_samp_factor &&
|
||||
compptr->v_samp_factor * 2 == cinfo->max_v_samp_factor) {
|
||||
} else if (h_in_group == h_out_group * 2 &&
|
||||
v_in_group == v_out_group * 2) {
|
||||
#ifdef INPUT_SMOOTHING_SUPPORTED
|
||||
if (cinfo->smoothing_factor) {
|
||||
downsample->methods[ci] = h2v2_smooth_downsample;
|
||||
downsample->pub.need_context_rows = TRUE;
|
||||
downsample->methods[ci] = h2v2_smooth_downsample;
|
||||
downsample->pub.need_context_rows = TRUE;
|
||||
} else
|
||||
#endif
|
||||
downsample->methods[ci] = h2v2_downsample;
|
||||
} else if ((cinfo->max_h_samp_factor % compptr->h_samp_factor) == 0 &&
|
||||
(cinfo->max_v_samp_factor % compptr->v_samp_factor) == 0) {
|
||||
downsample->methods[ci] = h2v2_downsample;
|
||||
} else if ((h_in_group % h_out_group) == 0 &&
|
||||
(v_in_group % v_out_group) == 0) {
|
||||
smoothok = FALSE;
|
||||
downsample->methods[ci] = int_downsample;
|
||||
downsample->h_expand[ci] = (UINT8) (h_in_group / h_out_group);
|
||||
downsample->v_expand[ci] = (UINT8) (v_in_group / v_out_group);
|
||||
} else
|
||||
ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL);
|
||||
}
|
||||
|
125
3rdparty/libjpeg/jctrans.c
vendored
125
3rdparty/libjpeg/jctrans.c
vendored
@ -2,6 +2,7 @@
|
||||
* jctrans.c
|
||||
*
|
||||
* Copyright (C) 1995-1998, Thomas G. Lane.
|
||||
* Modified 2000-2012 by Guido Vollbeding.
|
||||
* This file is part of the Independent JPEG Group's software.
|
||||
* For conditions of distribution and use, see the accompanying README file.
|
||||
*
|
||||
@ -17,9 +18,9 @@
|
||||
|
||||
/* Forward declarations */
|
||||
LOCAL(void) transencode_master_selection
|
||||
JPP((j_compress_ptr cinfo, jvirt_barray_ptr * coef_arrays));
|
||||
JPP((j_compress_ptr cinfo, jvirt_barray_ptr * coef_arrays));
|
||||
LOCAL(void) transencode_coef_controller
|
||||
JPP((j_compress_ptr cinfo, jvirt_barray_ptr * coef_arrays));
|
||||
JPP((j_compress_ptr cinfo, jvirt_barray_ptr * coef_arrays));
|
||||
|
||||
|
||||
/*
|
||||
@ -61,7 +62,7 @@ jpeg_write_coefficients (j_compress_ptr cinfo, jvirt_barray_ptr * coef_arrays)
|
||||
|
||||
GLOBAL(void)
|
||||
jpeg_copy_critical_parameters (j_decompress_ptr srcinfo,
|
||||
j_compress_ptr dstinfo)
|
||||
j_compress_ptr dstinfo)
|
||||
{
|
||||
JQUANT_TBL ** qtblptr;
|
||||
jpeg_component_info *incomp, *outcomp;
|
||||
@ -76,11 +77,18 @@ jpeg_copy_critical_parameters (j_decompress_ptr srcinfo,
|
||||
dstinfo->image_height = srcinfo->image_height;
|
||||
dstinfo->input_components = srcinfo->num_components;
|
||||
dstinfo->in_color_space = srcinfo->jpeg_color_space;
|
||||
dstinfo->jpeg_width = srcinfo->output_width;
|
||||
dstinfo->jpeg_height = srcinfo->output_height;
|
||||
dstinfo->min_DCT_h_scaled_size = srcinfo->min_DCT_h_scaled_size;
|
||||
dstinfo->min_DCT_v_scaled_size = srcinfo->min_DCT_v_scaled_size;
|
||||
/* Initialize all parameters to default values */
|
||||
jpeg_set_defaults(dstinfo);
|
||||
/* jpeg_set_defaults may choose wrong colorspace, eg YCbCr if input is RGB.
|
||||
* Fix it to get the right header markers for the image colorspace.
|
||||
* 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);
|
||||
dstinfo->data_precision = srcinfo->data_precision;
|
||||
dstinfo->CCIR601_sampling = srcinfo->CCIR601_sampling;
|
||||
@ -89,10 +97,10 @@ jpeg_copy_critical_parameters (j_decompress_ptr srcinfo,
|
||||
if (srcinfo->quant_tbl_ptrs[tblno] != NULL) {
|
||||
qtblptr = & dstinfo->quant_tbl_ptrs[tblno];
|
||||
if (*qtblptr == NULL)
|
||||
*qtblptr = jpeg_alloc_quant_table((j_common_ptr) dstinfo);
|
||||
*qtblptr = jpeg_alloc_quant_table((j_common_ptr) dstinfo);
|
||||
MEMCOPY((*qtblptr)->quantval,
|
||||
srcinfo->quant_tbl_ptrs[tblno]->quantval,
|
||||
SIZEOF((*qtblptr)->quantval));
|
||||
srcinfo->quant_tbl_ptrs[tblno]->quantval,
|
||||
SIZEOF((*qtblptr)->quantval));
|
||||
(*qtblptr)->sent_table = FALSE;
|
||||
}
|
||||
}
|
||||
@ -102,7 +110,7 @@ jpeg_copy_critical_parameters (j_decompress_ptr srcinfo,
|
||||
dstinfo->num_components = srcinfo->num_components;
|
||||
if (dstinfo->num_components < 1 || dstinfo->num_components > MAX_COMPONENTS)
|
||||
ERREXIT2(dstinfo, JERR_COMPONENT_COUNT, dstinfo->num_components,
|
||||
MAX_COMPONENTS);
|
||||
MAX_COMPONENTS);
|
||||
for (ci = 0, incomp = srcinfo->comp_info, outcomp = dstinfo->comp_info;
|
||||
ci < dstinfo->num_components; ci++, incomp++, outcomp++) {
|
||||
outcomp->component_id = incomp->component_id;
|
||||
@ -115,17 +123,17 @@ jpeg_copy_critical_parameters (j_decompress_ptr srcinfo,
|
||||
*/
|
||||
tblno = outcomp->quant_tbl_no;
|
||||
if (tblno < 0 || tblno >= NUM_QUANT_TBLS ||
|
||||
srcinfo->quant_tbl_ptrs[tblno] == NULL)
|
||||
srcinfo->quant_tbl_ptrs[tblno] == NULL)
|
||||
ERREXIT1(dstinfo, JERR_NO_QUANT_TABLE, tblno);
|
||||
slot_quant = srcinfo->quant_tbl_ptrs[tblno];
|
||||
c_quant = incomp->quant_table;
|
||||
if (c_quant != NULL) {
|
||||
for (coefi = 0; coefi < DCTSIZE2; coefi++) {
|
||||
if (c_quant->quantval[coefi] != slot_quant->quantval[coefi])
|
||||
ERREXIT1(dstinfo, JERR_MISMATCHED_QUANT_TABLE, tblno);
|
||||
if (c_quant->quantval[coefi] != slot_quant->quantval[coefi])
|
||||
ERREXIT1(dstinfo, JERR_MISMATCHED_QUANT_TABLE, tblno);
|
||||
}
|
||||
}
|
||||
/* Note: we do not copy the source's Huffman table assignments;
|
||||
/* Note: we do not copy the source's entropy table assignments;
|
||||
* instead we rely on jpeg_set_colorspace to have made a suitable choice.
|
||||
*/
|
||||
}
|
||||
@ -156,27 +164,16 @@ jpeg_copy_critical_parameters (j_decompress_ptr srcinfo,
|
||||
|
||||
LOCAL(void)
|
||||
transencode_master_selection (j_compress_ptr cinfo,
|
||||
jvirt_barray_ptr * coef_arrays)
|
||||
jvirt_barray_ptr * coef_arrays)
|
||||
{
|
||||
/* Although we don't actually use input_components for transcoding,
|
||||
* jcmaster.c's initial_setup will complain if input_components is 0.
|
||||
*/
|
||||
cinfo->input_components = 1;
|
||||
/* Initialize master control (includes parameter checking/processing) */
|
||||
jinit_c_master_control(cinfo, TRUE /* transcode only */);
|
||||
|
||||
/* Entropy encoding: either Huffman or arithmetic coding. */
|
||||
if (cinfo->arith_code) {
|
||||
ERREXIT(cinfo, JERR_ARITH_NOTIMPL);
|
||||
} else {
|
||||
if (cinfo->progressive_mode) {
|
||||
#ifdef C_PROGRESSIVE_SUPPORTED
|
||||
jinit_phuff_encoder(cinfo);
|
||||
#else
|
||||
ERREXIT(cinfo, JERR_NOT_COMPILED);
|
||||
#endif
|
||||
} else
|
||||
jinit_huff_encoder(cinfo);
|
||||
if (cinfo->arith_code)
|
||||
jinit_arith_encoder(cinfo);
|
||||
else {
|
||||
jinit_huff_encoder(cinfo);
|
||||
}
|
||||
|
||||
/* We need a special coefficient buffer controller. */
|
||||
@ -301,44 +298,44 @@ compress_output (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
|
||||
for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
|
||||
yoffset++) {
|
||||
for (MCU_col_num = coef->mcu_ctr; MCU_col_num < cinfo->MCUs_per_row;
|
||||
MCU_col_num++) {
|
||||
MCU_col_num++) {
|
||||
/* Construct list of pointers to DCT blocks belonging to this MCU */
|
||||
blkn = 0; /* index of current DCT block within MCU */
|
||||
for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
|
||||
compptr = cinfo->cur_comp_info[ci];
|
||||
start_col = MCU_col_num * compptr->MCU_width;
|
||||
blockcnt = (MCU_col_num < last_MCU_col) ? compptr->MCU_width
|
||||
: compptr->last_col_width;
|
||||
for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
|
||||
if (coef->iMCU_row_num < last_iMCU_row ||
|
||||
yindex+yoffset < compptr->last_row_height) {
|
||||
/* Fill in pointers to real blocks in this row */
|
||||
buffer_ptr = buffer[ci][yindex+yoffset] + start_col;
|
||||
for (xindex = 0; xindex < blockcnt; xindex++)
|
||||
MCU_buffer[blkn++] = buffer_ptr++;
|
||||
} else {
|
||||
/* At bottom of image, need a whole row of dummy blocks */
|
||||
xindex = 0;
|
||||
}
|
||||
/* Fill in any dummy blocks needed in this row.
|
||||
* Dummy blocks are filled in the same way as in jccoefct.c:
|
||||
* all zeroes in the AC entries, DC entries equal to previous
|
||||
* block's DC value. The init routine has already zeroed the
|
||||
* AC entries, so we need only set the DC entries correctly.
|
||||
*/
|
||||
for (; xindex < compptr->MCU_width; xindex++) {
|
||||
MCU_buffer[blkn] = coef->dummy_buffer[blkn];
|
||||
MCU_buffer[blkn][0][0] = MCU_buffer[blkn-1][0][0];
|
||||
blkn++;
|
||||
}
|
||||
}
|
||||
compptr = cinfo->cur_comp_info[ci];
|
||||
start_col = MCU_col_num * compptr->MCU_width;
|
||||
blockcnt = (MCU_col_num < last_MCU_col) ? compptr->MCU_width
|
||||
: compptr->last_col_width;
|
||||
for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
|
||||
if (coef->iMCU_row_num < last_iMCU_row ||
|
||||
yindex+yoffset < compptr->last_row_height) {
|
||||
/* Fill in pointers to real blocks in this row */
|
||||
buffer_ptr = buffer[ci][yindex+yoffset] + start_col;
|
||||
for (xindex = 0; xindex < blockcnt; xindex++)
|
||||
MCU_buffer[blkn++] = buffer_ptr++;
|
||||
} else {
|
||||
/* At bottom of image, need a whole row of dummy blocks */
|
||||
xindex = 0;
|
||||
}
|
||||
/* Fill in any dummy blocks needed in this row.
|
||||
* Dummy blocks are filled in the same way as in jccoefct.c:
|
||||
* all zeroes in the AC entries, DC entries equal to previous
|
||||
* block's DC value. The init routine has already zeroed the
|
||||
* AC entries, so we need only set the DC entries correctly.
|
||||
*/
|
||||
for (; xindex < compptr->MCU_width; xindex++) {
|
||||
MCU_buffer[blkn] = coef->dummy_buffer[blkn];
|
||||
MCU_buffer[blkn][0][0] = MCU_buffer[blkn-1][0][0];
|
||||
blkn++;
|
||||
}
|
||||
}
|
||||
}
|
||||
/* Try to write the MCU. */
|
||||
if (! (*cinfo->entropy->encode_mcu) (cinfo, MCU_buffer)) {
|
||||
/* Suspension forced; update state counters and exit */
|
||||
coef->MCU_vert_offset = yoffset;
|
||||
coef->mcu_ctr = MCU_col_num;
|
||||
return FALSE;
|
||||
/* Suspension forced; update state counters and exit */
|
||||
coef->MCU_vert_offset = yoffset;
|
||||
coef->mcu_ctr = MCU_col_num;
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
/* Completed an MCU row, but perhaps not an iMCU row */
|
||||
@ -361,7 +358,7 @@ compress_output (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
|
||||
|
||||
LOCAL(void)
|
||||
transencode_coef_controller (j_compress_ptr cinfo,
|
||||
jvirt_barray_ptr * coef_arrays)
|
||||
jvirt_barray_ptr * coef_arrays)
|
||||
{
|
||||
my_coef_ptr coef;
|
||||
JBLOCKROW buffer;
|
||||
@ -369,8 +366,8 @@ transencode_coef_controller (j_compress_ptr cinfo,
|
||||
|
||||
coef = (my_coef_ptr)
|
||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
||||
SIZEOF(my_coef_controller));
|
||||
cinfo->coef = (struct jpeg_c_coef_controller *) coef;
|
||||
SIZEOF(my_coef_controller));
|
||||
cinfo->coef = &coef->pub;
|
||||
coef->pub.start_pass = start_pass_coef;
|
||||
coef->pub.compress_data = compress_output;
|
||||
|
||||
@ -380,8 +377,8 @@ transencode_coef_controller (j_compress_ptr cinfo,
|
||||
/* Allocate and pre-zero space for dummy DCT blocks. */
|
||||
buffer = (JBLOCKROW)
|
||||
(*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
||||
C_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK));
|
||||
jzero_far((void FAR *) buffer, C_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK));
|
||||
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++) {
|
||||
coef->dummy_buffer[i] = buffer + i;
|
||||
}
|
||||
|
43
3rdparty/libjpeg/jdapimin.c
vendored
43
3rdparty/libjpeg/jdapimin.c
vendored
@ -2,6 +2,7 @@
|
||||
* jdapimin.c
|
||||
*
|
||||
* Copyright (C) 1994-1998, Thomas G. Lane.
|
||||
* Modified 2009 by Guido Vollbeding.
|
||||
* This file is part of the Independent JPEG Group's software.
|
||||
* For conditions of distribution and use, see the accompanying README file.
|
||||
*
|
||||
@ -37,7 +38,7 @@ jpeg_CreateDecompress (j_decompress_ptr cinfo, int version, size_t structsize)
|
||||
ERREXIT2(cinfo, JERR_BAD_LIB_VERSION, JPEG_LIB_VERSION, version);
|
||||
if (structsize != SIZEOF(struct jpeg_decompress_struct))
|
||||
ERREXIT2(cinfo, JERR_BAD_STRUCT_SIZE,
|
||||
(int) SIZEOF(struct jpeg_decompress_struct), (int) structsize);
|
||||
(int) SIZEOF(struct jpeg_decompress_struct), (int) structsize);
|
||||
|
||||
/* For debugging purposes, we zero the whole master structure.
|
||||
* But the application has already set the err pointer, and may have set
|
||||
@ -128,15 +129,15 @@ default_decompress_parms (j_decompress_ptr cinfo)
|
||||
} else if (cinfo->saw_Adobe_marker) {
|
||||
switch (cinfo->Adobe_transform) {
|
||||
case 0:
|
||||
cinfo->jpeg_color_space = JCS_RGB;
|
||||
break;
|
||||
cinfo->jpeg_color_space = JCS_RGB;
|
||||
break;
|
||||
case 1:
|
||||
cinfo->jpeg_color_space = JCS_YCbCr;
|
||||
break;
|
||||
cinfo->jpeg_color_space = JCS_YCbCr;
|
||||
break;
|
||||
default:
|
||||
WARNMS1(cinfo, JWRN_ADOBE_XFORM, cinfo->Adobe_transform);
|
||||
cinfo->jpeg_color_space = JCS_YCbCr; /* assume it's YCbCr */
|
||||
break;
|
||||
WARNMS1(cinfo, JWRN_ADOBE_XFORM, cinfo->Adobe_transform);
|
||||
cinfo->jpeg_color_space = JCS_YCbCr; /* assume it's YCbCr */
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
/* Saw no special markers, try to guess from the component IDs */
|
||||
@ -145,12 +146,12 @@ default_decompress_parms (j_decompress_ptr cinfo)
|
||||
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 */
|
||||
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' */
|
||||
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 */
|
||||
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. */
|
||||
@ -161,15 +162,15 @@ default_decompress_parms (j_decompress_ptr cinfo)
|
||||
if (cinfo->saw_Adobe_marker) {
|
||||
switch (cinfo->Adobe_transform) {
|
||||
case 0:
|
||||
cinfo->jpeg_color_space = JCS_CMYK;
|
||||
break;
|
||||
cinfo->jpeg_color_space = JCS_CMYK;
|
||||
break;
|
||||
case 2:
|
||||
cinfo->jpeg_color_space = JCS_YCCK;
|
||||
break;
|
||||
cinfo->jpeg_color_space = JCS_YCCK;
|
||||
break;
|
||||
default:
|
||||
WARNMS1(cinfo, JWRN_ADOBE_XFORM, cinfo->Adobe_transform);
|
||||
cinfo->jpeg_color_space = JCS_YCCK; /* assume it's YCCK */
|
||||
break;
|
||||
WARNMS1(cinfo, JWRN_ADOBE_XFORM, cinfo->Adobe_transform);
|
||||
cinfo->jpeg_color_space = JCS_YCCK; /* assume it's YCCK */
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
/* No special markers, assume straight CMYK. */
|
||||
@ -185,8 +186,8 @@ default_decompress_parms (j_decompress_ptr cinfo)
|
||||
}
|
||||
|
||||
/* Set defaults for other decompression parameters. */
|
||||
cinfo->scale_num = 1; /* 1:1 scaling */
|
||||
cinfo->scale_denom = 1;
|
||||
cinfo->scale_num = cinfo->block_size; /* 1:1 scaling */
|
||||
cinfo->scale_denom = cinfo->block_size;
|
||||
cinfo->output_gamma = 1.0;
|
||||
cinfo->buffered_image = FALSE;
|
||||
cinfo->raw_data_out = FALSE;
|
||||
|
54
3rdparty/libjpeg/jdapistd.c
vendored
54
3rdparty/libjpeg/jdapistd.c
vendored
@ -52,24 +52,24 @@ jpeg_start_decompress (j_decompress_ptr cinfo)
|
||||
if (cinfo->inputctl->has_multiple_scans) {
|
||||
#ifdef D_MULTISCAN_FILES_SUPPORTED
|
||||
for (;;) {
|
||||
int retcode;
|
||||
/* Call progress monitor hook if present */
|
||||
if (cinfo->progress != NULL)
|
||||
(*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
|
||||
/* Absorb some more input */
|
||||
retcode = (*cinfo->inputctl->consume_input) (cinfo);
|
||||
if (retcode == JPEG_SUSPENDED)
|
||||
return FALSE;
|
||||
if (retcode == JPEG_REACHED_EOI)
|
||||
break;
|
||||
/* Advance progress counter if appropriate */
|
||||
if (cinfo->progress != NULL &&
|
||||
(retcode == JPEG_ROW_COMPLETED || retcode == JPEG_REACHED_SOS)) {
|
||||
if (++cinfo->progress->pass_counter >= cinfo->progress->pass_limit) {
|
||||
/* jdmaster underestimated number of scans; ratchet up one scan */
|
||||
cinfo->progress->pass_limit += (long) cinfo->total_iMCU_rows;
|
||||
}
|
||||
}
|
||||
int retcode;
|
||||
/* Call progress monitor hook if present */
|
||||
if (cinfo->progress != NULL)
|
||||
(*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
|
||||
/* Absorb some more input */
|
||||
retcode = (*cinfo->inputctl->consume_input) (cinfo);
|
||||
if (retcode == JPEG_SUSPENDED)
|
||||
return FALSE;
|
||||
if (retcode == JPEG_REACHED_EOI)
|
||||
break;
|
||||
/* Advance progress counter if appropriate */
|
||||
if (cinfo->progress != NULL &&
|
||||
(retcode == JPEG_ROW_COMPLETED || retcode == JPEG_REACHED_SOS)) {
|
||||
if (++cinfo->progress->pass_counter >= cinfo->progress->pass_limit) {
|
||||
/* jdmaster underestimated number of scans; ratchet up one scan */
|
||||
cinfo->progress->pass_limit += (long) cinfo->total_iMCU_rows;
|
||||
}
|
||||
}
|
||||
}
|
||||
#else
|
||||
ERREXIT(cinfo, JERR_NOT_COMPILED);
|
||||
@ -108,16 +108,16 @@ output_pass_setup (j_decompress_ptr cinfo)
|
||||
JDIMENSION last_scanline;
|
||||
/* Call progress monitor hook if present */
|
||||
if (cinfo->progress != NULL) {
|
||||
cinfo->progress->pass_counter = (long) cinfo->output_scanline;
|
||||
cinfo->progress->pass_limit = (long) cinfo->output_height;
|
||||
(*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
|
||||
cinfo->progress->pass_counter = (long) cinfo->output_scanline;
|
||||
cinfo->progress->pass_limit = (long) cinfo->output_height;
|
||||
(*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
|
||||
}
|
||||
/* Process some data */
|
||||
last_scanline = cinfo->output_scanline;
|
||||
(*cinfo->main->process_data) (cinfo, (JSAMPARRAY) NULL,
|
||||
&cinfo->output_scanline, (JDIMENSION) 0);
|
||||
&cinfo->output_scanline, (JDIMENSION) 0);
|
||||
if (cinfo->output_scanline == last_scanline)
|
||||
return FALSE; /* No progress made, must suspend */
|
||||
return FALSE; /* No progress made, must suspend */
|
||||
}
|
||||
/* Finish up dummy pass, and set up for another one */
|
||||
(*cinfo->master->finish_output_pass) (cinfo);
|
||||
@ -150,7 +150,7 @@ output_pass_setup (j_decompress_ptr cinfo)
|
||||
|
||||
GLOBAL(JDIMENSION)
|
||||
jpeg_read_scanlines (j_decompress_ptr cinfo, JSAMPARRAY scanlines,
|
||||
JDIMENSION max_lines)
|
||||
JDIMENSION max_lines)
|
||||
{
|
||||
JDIMENSION row_ctr;
|
||||
|
||||
@ -183,7 +183,7 @@ jpeg_read_scanlines (j_decompress_ptr cinfo, JSAMPARRAY scanlines,
|
||||
|
||||
GLOBAL(JDIMENSION)
|
||||
jpeg_read_raw_data (j_decompress_ptr cinfo, JSAMPIMAGE data,
|
||||
JDIMENSION max_lines)
|
||||
JDIMENSION max_lines)
|
||||
{
|
||||
JDIMENSION lines_per_iMCU_row;
|
||||
|
||||
@ -202,7 +202,7 @@ jpeg_read_raw_data (j_decompress_ptr cinfo, JSAMPIMAGE data,
|
||||
}
|
||||
|
||||
/* Verify that at least one iMCU row can be returned. */
|
||||
lines_per_iMCU_row = cinfo->max_v_samp_factor * cinfo->min_DCT_scaled_size;
|
||||
lines_per_iMCU_row = cinfo->max_v_samp_factor * cinfo->min_DCT_v_scaled_size;
|
||||
if (max_lines < lines_per_iMCU_row)
|
||||
ERREXIT(cinfo, JERR_BUFFER_SIZE);
|
||||
|
||||
@ -264,7 +264,7 @@ jpeg_finish_output (j_decompress_ptr cinfo)
|
||||
}
|
||||
/* Read markers looking for SOS or EOI */
|
||||
while (cinfo->input_scan_number <= cinfo->output_scan_number &&
|
||||
! cinfo->inputctl->eoi_reached) {
|
||||
! cinfo->inputctl->eoi_reached) {
|
||||
if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
|
||||
return FALSE; /* Suspend, come back later */
|
||||
}
|
||||
|
782
3rdparty/libjpeg/jdarith.c
vendored
Normal file
782
3rdparty/libjpeg/jdarith.c
vendored
Normal file
@ -0,0 +1,782 @@
|
||||
/*
|
||||
* jdarith.c
|
||||
*
|
||||
* Developed 1997-2012 by Guido Vollbeding.
|
||||
* This file is part of the Independent JPEG Group's software.
|
||||
* For conditions of distribution and use, see the accompanying README file.
|
||||
*
|
||||
* This file contains portable arithmetic entropy decoding routines for JPEG
|
||||
* (implementing the ISO/IEC IS 10918-1 and CCITT Recommendation ITU-T T.81).
|
||||
*
|
||||
* Both sequential and progressive modes are supported in this single module.
|
||||
*
|
||||
* Suspension is not currently supported in this module.
|
||||
*/
|
||||
|
||||
#define JPEG_INTERNALS
|
||||
#include "jinclude.h"
|
||||
#include "jpeglib.h"
|
||||
|
||||
|
||||
/* Expanded entropy decoder object for arithmetic decoding. */
|
||||
|
||||
typedef struct {
|
||||
struct jpeg_entropy_decoder pub; /* public fields */
|
||||
|
||||
INT32 c; /* C register, base of coding interval + input bit buffer */
|
||||
INT32 a; /* A register, normalized size of coding interval */
|
||||
int ct; /* bit shift counter, # of bits left in bit buffer part of C */
|
||||
/* init: ct = -16 */
|
||||
/* run: ct = 0..7 */
|
||||
/* error: ct = -1 */
|
||||
int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
|
||||
int dc_context[MAX_COMPS_IN_SCAN]; /* context index for DC conditioning */
|
||||
|
||||
unsigned int restarts_to_go; /* MCUs left in this restart interval */
|
||||
|
||||
/* Pointers to statistics areas (these workspaces have image lifespan) */
|
||||
unsigned char * dc_stats[NUM_ARITH_TBLS];
|
||||
unsigned char * ac_stats[NUM_ARITH_TBLS];
|
||||
|
||||
/* Statistics bin for coding with fixed probability 0.5 */
|
||||
unsigned char fixed_bin[4];
|
||||
} arith_entropy_decoder;
|
||||
|
||||
typedef arith_entropy_decoder * arith_entropy_ptr;
|
||||
|
||||
/* The following two definitions specify the allocation chunk size
|
||||
* for the statistics area.
|
||||
* According to sections F.1.4.4.1.3 and F.1.4.4.2, we need at least
|
||||
* 49 statistics bins for DC, and 245 statistics bins for AC coding.
|
||||
*
|
||||
* We use a compact representation with 1 byte per statistics bin,
|
||||
* thus the numbers directly represent byte sizes.
|
||||
* This 1 byte per statistics bin contains the meaning of the MPS
|
||||
* (more probable symbol) in the highest bit (mask 0x80), and the
|
||||
* index into the probability estimation state machine table
|
||||
* in the lower bits (mask 0x7F).
|
||||
*/
|
||||
|
||||
#define DC_STAT_BINS 64
|
||||
#define AC_STAT_BINS 256
|
||||
|
||||
|
||||
LOCAL(int)
|
||||
get_byte (j_decompress_ptr cinfo)
|
||||
/* Read next input byte; we do not support suspension in this module. */
|
||||
{
|
||||
struct jpeg_source_mgr * src = cinfo->src;
|
||||
|
||||
if (src->bytes_in_buffer == 0)
|
||||
if (! (*src->fill_input_buffer) (cinfo))
|
||||
ERREXIT(cinfo, JERR_CANT_SUSPEND);
|
||||
src->bytes_in_buffer--;
|
||||
return GETJOCTET(*src->next_input_byte++);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* The core arithmetic decoding routine (common in JPEG and JBIG).
|
||||
* This needs to go as fast as possible.
|
||||
* Machine-dependent optimization facilities
|
||||
* are not utilized in this portable implementation.
|
||||
* However, this code should be fairly efficient and
|
||||
* may be a good base for further optimizations anyway.
|
||||
*
|
||||
* Return value is 0 or 1 (binary decision).
|
||||
*
|
||||
* Note: I've changed the handling of the code base & bit
|
||||
* buffer register C compared to other implementations
|
||||
* based on the standards layout & procedures.
|
||||
* While it also contains both the actual base of the
|
||||
* coding interval (16 bits) and the next-bits buffer,
|
||||
* the cut-point between these two parts is floating
|
||||
* (instead of fixed) with the bit shift counter CT.
|
||||
* Thus, we also need only one (variable instead of
|
||||
* fixed size) shift for the LPS/MPS decision, and
|
||||
* we can get away with any renormalization update
|
||||
* of C (except for new data insertion, of course).
|
||||
*
|
||||
* I've also introduced a new scheme for accessing
|
||||
* the probability estimation state machine table,
|
||||
* derived from Markus Kuhn's JBIG implementation.
|
||||
*/
|
||||
|
||||
LOCAL(int)
|
||||
arith_decode (j_decompress_ptr cinfo, unsigned char *st)
|
||||
{
|
||||
register arith_entropy_ptr e = (arith_entropy_ptr) cinfo->entropy;
|
||||
register unsigned char nl, nm;
|
||||
register INT32 qe, temp;
|
||||
register int sv, data;
|
||||
|
||||
/* Renormalization & data input per section D.2.6 */
|
||||
while (e->a < 0x8000L) {
|
||||
if (--e->ct < 0) {
|
||||
/* Need to fetch next data byte */
|
||||
if (cinfo->unread_marker)
|
||||
data = 0; /* stuff zero data */
|
||||
else {
|
||||
data = get_byte(cinfo); /* read next input byte */
|
||||
if (data == 0xFF) { /* zero stuff or marker code */
|
||||
do data = get_byte(cinfo);
|
||||
while (data == 0xFF); /* swallow extra 0xFF bytes */
|
||||
if (data == 0)
|
||||
data = 0xFF; /* discard stuffed zero byte */
|
||||
else {
|
||||
/* Note: Different from the Huffman decoder, hitting
|
||||
* a marker while processing the compressed data
|
||||
* segment is legal in arithmetic coding.
|
||||
* The convention is to supply zero data
|
||||
* then until decoding is complete.
|
||||
*/
|
||||
cinfo->unread_marker = data;
|
||||
data = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
e->c = (e->c << 8) | data; /* insert data into C register */
|
||||
if ((e->ct += 8) < 0) /* update bit shift counter */
|
||||
/* Need more initial bytes */
|
||||
if (++e->ct == 0)
|
||||
/* Got 2 initial bytes -> re-init A and exit loop */
|
||||
e->a = 0x8000L; /* => e->a = 0x10000L after loop exit */
|
||||
}
|
||||
e->a <<= 1;
|
||||
}
|
||||
|
||||
/* Fetch values from our compact representation of Table D.3(D.2):
|
||||
* Qe values and probability estimation state machine
|
||||
*/
|
||||
sv = *st;
|
||||
qe = jpeg_aritab[sv & 0x7F]; /* => Qe_Value */
|
||||
nl = qe & 0xFF; qe >>= 8; /* Next_Index_LPS + Switch_MPS */
|
||||
nm = qe & 0xFF; qe >>= 8; /* Next_Index_MPS */
|
||||
|
||||
/* Decode & estimation procedures per sections D.2.4 & D.2.5 */
|
||||
temp = e->a - qe;
|
||||
e->a = temp;
|
||||
temp <<= e->ct;
|
||||
if (e->c >= temp) {
|
||||
e->c -= temp;
|
||||
/* Conditional LPS (less probable symbol) exchange */
|
||||
if (e->a < qe) {
|
||||
e->a = qe;
|
||||
*st = (sv & 0x80) ^ nm; /* Estimate_after_MPS */
|
||||
} else {
|
||||
e->a = qe;
|
||||
*st = (sv & 0x80) ^ nl; /* Estimate_after_LPS */
|
||||
sv ^= 0x80; /* Exchange LPS/MPS */
|
||||
}
|
||||
} else if (e->a < 0x8000L) {
|
||||
/* Conditional MPS (more probable symbol) exchange */
|
||||
if (e->a < qe) {
|
||||
*st = (sv & 0x80) ^ nl; /* Estimate_after_LPS */
|
||||
sv ^= 0x80; /* Exchange LPS/MPS */
|
||||
} else {
|
||||
*st = (sv & 0x80) ^ nm; /* Estimate_after_MPS */
|
||||
}
|
||||
}
|
||||
|
||||
return sv >> 7;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Check for a restart marker & resynchronize decoder.
|
||||
*/
|
||||
|
||||
LOCAL(void)
|
||||
process_restart (j_decompress_ptr cinfo)
|
||||
{
|
||||
arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy;
|
||||
int ci;
|
||||
jpeg_component_info * compptr;
|
||||
|
||||
/* Advance past the RSTn marker */
|
||||
if (! (*cinfo->marker->read_restart_marker) (cinfo))
|
||||
ERREXIT(cinfo, JERR_CANT_SUSPEND);
|
||||
|
||||
/* Re-initialize statistics areas */
|
||||
for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
|
||||
compptr = cinfo->cur_comp_info[ci];
|
||||
if (! cinfo->progressive_mode || (cinfo->Ss == 0 && cinfo->Ah == 0)) {
|
||||
MEMZERO(entropy->dc_stats[compptr->dc_tbl_no], DC_STAT_BINS);
|
||||
/* Reset DC predictions to 0 */
|
||||
entropy->last_dc_val[ci] = 0;
|
||||
entropy->dc_context[ci] = 0;
|
||||
}
|
||||
if ((! cinfo->progressive_mode && cinfo->lim_Se) ||
|
||||
(cinfo->progressive_mode && cinfo->Ss)) {
|
||||
MEMZERO(entropy->ac_stats[compptr->ac_tbl_no], AC_STAT_BINS);
|
||||
}
|
||||
}
|
||||
|
||||
/* Reset arithmetic decoding variables */
|
||||
entropy->c = 0;
|
||||
entropy->a = 0;
|
||||
entropy->ct = -16; /* force reading 2 initial bytes to fill C */
|
||||
|
||||
/* Reset restart counter */
|
||||
entropy->restarts_to_go = cinfo->restart_interval;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Arithmetic MCU decoding.
|
||||
* Each of these routines decodes and returns one MCU's worth of
|
||||
* arithmetic-compressed coefficients.
|
||||
* The coefficients are reordered from zigzag order into natural array order,
|
||||
* but are not dequantized.
|
||||
*
|
||||
* The i'th block of the MCU is stored into the block pointed to by
|
||||
* MCU_data[i]. WE ASSUME THIS AREA IS INITIALLY ZEROED BY THE CALLER.
|
||||
*/
|
||||
|
||||
/*
|
||||
* MCU decoding for DC initial scan (either spectral selection,
|
||||
* or first pass of successive approximation).
|
||||
*/
|
||||
|
||||
METHODDEF(boolean)
|
||||
decode_mcu_DC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
|
||||
{
|
||||
arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy;
|
||||
JBLOCKROW block;
|
||||
unsigned char *st;
|
||||
int blkn, ci, tbl, sign;
|
||||
int v, m;
|
||||
|
||||
/* Process restart marker if needed */
|
||||
if (cinfo->restart_interval) {
|
||||
if (entropy->restarts_to_go == 0)
|
||||
process_restart(cinfo);
|
||||
entropy->restarts_to_go--;
|
||||
}
|
||||
|
||||
if (entropy->ct == -1) return TRUE; /* if error do nothing */
|
||||
|
||||
/* Outer loop handles each block in the MCU */
|
||||
|
||||
for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
|
||||
block = MCU_data[blkn];
|
||||
ci = cinfo->MCU_membership[blkn];
|
||||
tbl = cinfo->cur_comp_info[ci]->dc_tbl_no;
|
||||
|
||||
/* Sections F.2.4.1 & F.1.4.4.1: Decoding of DC coefficients */
|
||||
|
||||
/* Table F.4: Point to statistics bin S0 for DC coefficient coding */
|
||||
st = entropy->dc_stats[tbl] + entropy->dc_context[ci];
|
||||
|
||||
/* Figure F.19: Decode_DC_DIFF */
|
||||
if (arith_decode(cinfo, st) == 0)
|
||||
entropy->dc_context[ci] = 0;
|
||||
else {
|
||||
/* Figure F.21: Decoding nonzero value v */
|
||||
/* Figure F.22: Decoding the sign of v */
|
||||
sign = arith_decode(cinfo, st + 1);
|
||||
st += 2; st += sign;
|
||||
/* Figure F.23: Decoding the magnitude category of v */
|
||||
if ((m = arith_decode(cinfo, st)) != 0) {
|
||||
st = entropy->dc_stats[tbl] + 20; /* Table F.4: X1 = 20 */
|
||||
while (arith_decode(cinfo, st)) {
|
||||
if ((m <<= 1) == 0x8000) {
|
||||
WARNMS(cinfo, JWRN_ARITH_BAD_CODE);
|
||||
entropy->ct = -1; /* magnitude overflow */
|
||||
return TRUE;
|
||||
}
|
||||
st += 1;
|
||||
}
|
||||
}
|
||||
/* Section F.1.4.4.1.2: Establish dc_context conditioning category */
|
||||
if (m < (int) ((1L << cinfo->arith_dc_L[tbl]) >> 1))
|
||||
entropy->dc_context[ci] = 0; /* zero diff category */
|
||||
else if (m > (int) ((1L << cinfo->arith_dc_U[tbl]) >> 1))
|
||||
entropy->dc_context[ci] = 12 + (sign * 4); /* large diff category */
|
||||
else
|
||||
entropy->dc_context[ci] = 4 + (sign * 4); /* small diff category */
|
||||
v = m;
|
||||
/* Figure F.24: Decoding the magnitude bit pattern of v */
|
||||
st += 14;
|
||||
while (m >>= 1)
|
||||
if (arith_decode(cinfo, st)) v |= m;
|
||||
v += 1; if (sign) v = -v;
|
||||
entropy->last_dc_val[ci] += v;
|
||||
}
|
||||
|
||||
/* Scale and output the DC coefficient (assumes jpeg_natural_order[0]=0) */
|
||||
(*block)[0] = (JCOEF) (entropy->last_dc_val[ci] << cinfo->Al);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* MCU decoding for AC initial scan (either spectral selection,
|
||||
* or first pass of successive approximation).
|
||||
*/
|
||||
|
||||
METHODDEF(boolean)
|
||||
decode_mcu_AC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
|
||||
{
|
||||
arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy;
|
||||
JBLOCKROW block;
|
||||
unsigned char *st;
|
||||
int tbl, sign, k;
|
||||
int v, m;
|
||||
const int * natural_order;
|
||||
|
||||
/* Process restart marker if needed */
|
||||
if (cinfo->restart_interval) {
|
||||
if (entropy->restarts_to_go == 0)
|
||||
process_restart(cinfo);
|
||||
entropy->restarts_to_go--;
|
||||
}
|
||||
|
||||
if (entropy->ct == -1) return TRUE; /* if error do nothing */
|
||||
|
||||
natural_order = cinfo->natural_order;
|
||||
|
||||
/* There is always only one block per MCU */
|
||||
block = MCU_data[0];
|
||||
tbl = cinfo->cur_comp_info[0]->ac_tbl_no;
|
||||
|
||||
/* Sections F.2.4.2 & F.1.4.4.2: Decoding of AC coefficients */
|
||||
|
||||
/* Figure F.20: Decode_AC_coefficients */
|
||||
k = cinfo->Ss - 1;
|
||||
do {
|
||||
st = entropy->ac_stats[tbl] + 3 * k;
|
||||
if (arith_decode(cinfo, st)) break; /* EOB flag */
|
||||
for (;;) {
|
||||
k++;
|
||||
if (arith_decode(cinfo, st + 1)) break;
|
||||
st += 3;
|
||||
if (k >= cinfo->Se) {
|
||||
WARNMS(cinfo, JWRN_ARITH_BAD_CODE);
|
||||
entropy->ct = -1; /* spectral overflow */
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
/* Figure F.21: Decoding nonzero value v */
|
||||
/* Figure F.22: Decoding the sign of v */
|
||||
sign = arith_decode(cinfo, entropy->fixed_bin);
|
||||
st += 2;
|
||||
/* Figure F.23: Decoding the magnitude category of v */
|
||||
if ((m = arith_decode(cinfo, st)) != 0) {
|
||||
if (arith_decode(cinfo, st)) {
|
||||
m <<= 1;
|
||||
st = entropy->ac_stats[tbl] +
|
||||
(k <= cinfo->arith_ac_K[tbl] ? 189 : 217);
|
||||
while (arith_decode(cinfo, st)) {
|
||||
if ((m <<= 1) == 0x8000) {
|
||||
WARNMS(cinfo, JWRN_ARITH_BAD_CODE);
|
||||
entropy->ct = -1; /* magnitude overflow */
|
||||
return TRUE;
|
||||
}
|
||||
st += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
v = m;
|
||||
/* Figure F.24: Decoding the magnitude bit pattern of v */
|
||||
st += 14;
|
||||
while (m >>= 1)
|
||||
if (arith_decode(cinfo, st)) v |= m;
|
||||
v += 1; if (sign) v = -v;
|
||||
/* Scale and output coefficient in natural (dezigzagged) order */
|
||||
(*block)[natural_order[k]] = (JCOEF) (v << cinfo->Al);
|
||||
} while (k < cinfo->Se);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* MCU decoding for DC successive approximation refinement scan.
|
||||
*/
|
||||
|
||||
METHODDEF(boolean)
|
||||
decode_mcu_DC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
|
||||
{
|
||||
arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy;
|
||||
unsigned char *st;
|
||||
int p1, blkn;
|
||||
|
||||
/* Process restart marker if needed */
|
||||
if (cinfo->restart_interval) {
|
||||
if (entropy->restarts_to_go == 0)
|
||||
process_restart(cinfo);
|
||||
entropy->restarts_to_go--;
|
||||
}
|
||||
|
||||
st = entropy->fixed_bin; /* use fixed probability estimation */
|
||||
p1 = 1 << cinfo->Al; /* 1 in the bit position being coded */
|
||||
|
||||
/* Outer loop handles each block in the MCU */
|
||||
|
||||
for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
|
||||
/* Encoded data is simply the next bit of the two's-complement DC value */
|
||||
if (arith_decode(cinfo, st))
|
||||
MCU_data[blkn][0][0] |= p1;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* MCU decoding for AC successive approximation refinement scan.
|
||||
*/
|
||||
|
||||
METHODDEF(boolean)
|
||||
decode_mcu_AC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
|
||||
{
|
||||
arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy;
|
||||
JBLOCKROW block;
|
||||
JCOEFPTR thiscoef;
|
||||
unsigned char *st;
|
||||
int tbl, k, kex;
|
||||
int p1, m1;
|
||||
const int * natural_order;
|
||||
|
||||
/* Process restart marker if needed */
|
||||
if (cinfo->restart_interval) {
|
||||
if (entropy->restarts_to_go == 0)
|
||||
process_restart(cinfo);
|
||||
entropy->restarts_to_go--;
|
||||
}
|
||||
|
||||
if (entropy->ct == -1) return TRUE; /* if error do nothing */
|
||||
|
||||
natural_order = cinfo->natural_order;
|
||||
|
||||
/* There is always only one block per MCU */
|
||||
block = MCU_data[0];
|
||||
tbl = cinfo->cur_comp_info[0]->ac_tbl_no;
|
||||
|
||||
p1 = 1 << cinfo->Al; /* 1 in the bit position being coded */
|
||||
m1 = (-1) << cinfo->Al; /* -1 in the bit position being coded */
|
||||
|
||||
/* Establish EOBx (previous stage end-of-block) index */
|
||||
kex = cinfo->Se;
|
||||
do {
|
||||
if ((*block)[natural_order[kex]]) break;
|
||||
} while (--kex);
|
||||
|
||||
k = cinfo->Ss - 1;
|
||||
do {
|
||||
st = entropy->ac_stats[tbl] + 3 * k;
|
||||
if (k >= kex)
|
||||
if (arith_decode(cinfo, st)) break; /* EOB flag */
|
||||
for (;;) {
|
||||
thiscoef = *block + natural_order[++k];
|
||||
if (*thiscoef) { /* previously nonzero coef */
|
||||
if (arith_decode(cinfo, st + 2)) {
|
||||
if (*thiscoef < 0)
|
||||
*thiscoef += m1;
|
||||
else
|
||||
*thiscoef += p1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (arith_decode(cinfo, st + 1)) { /* newly nonzero coef */
|
||||
if (arith_decode(cinfo, entropy->fixed_bin))
|
||||
*thiscoef = m1;
|
||||
else
|
||||
*thiscoef = p1;
|
||||
break;
|
||||
}
|
||||
st += 3;
|
||||
if (k >= cinfo->Se) {
|
||||
WARNMS(cinfo, JWRN_ARITH_BAD_CODE);
|
||||
entropy->ct = -1; /* spectral overflow */
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
} while (k < cinfo->Se);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Decode one MCU's worth of arithmetic-compressed coefficients.
|
||||
*/
|
||||
|
||||
METHODDEF(boolean)
|
||||
decode_mcu (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
|
||||
{
|
||||
arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy;
|
||||
jpeg_component_info * compptr;
|
||||
JBLOCKROW block;
|
||||
unsigned char *st;
|
||||
int blkn, ci, tbl, sign, k;
|
||||
int v, m;
|
||||
const int * natural_order;
|
||||
|
||||
/* Process restart marker if needed */
|
||||
if (cinfo->restart_interval) {
|
||||
if (entropy->restarts_to_go == 0)
|
||||
process_restart(cinfo);
|
||||
entropy->restarts_to_go--;
|
||||
}
|
||||
|
||||
if (entropy->ct == -1) return TRUE; /* if error do nothing */
|
||||
|
||||
natural_order = cinfo->natural_order;
|
||||
|
||||
/* Outer loop handles each block in the MCU */
|
||||
|
||||
for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
|
||||
block = MCU_data[blkn];
|
||||
ci = cinfo->MCU_membership[blkn];
|
||||
compptr = cinfo->cur_comp_info[ci];
|
||||
|
||||
/* Sections F.2.4.1 & F.1.4.4.1: Decoding of DC coefficients */
|
||||
|
||||
tbl = compptr->dc_tbl_no;
|
||||
|
||||
/* Table F.4: Point to statistics bin S0 for DC coefficient coding */
|
||||
st = entropy->dc_stats[tbl] + entropy->dc_context[ci];
|
||||
|
||||
/* Figure F.19: Decode_DC_DIFF */
|
||||
if (arith_decode(cinfo, st) == 0)
|
||||
entropy->dc_context[ci] = 0;
|
||||
else {
|
||||
/* Figure F.21: Decoding nonzero value v */
|
||||
/* Figure F.22: Decoding the sign of v */
|
||||
sign = arith_decode(cinfo, st + 1);
|
||||
st += 2; st += sign;
|
||||
/* Figure F.23: Decoding the magnitude category of v */
|
||||
if ((m = arith_decode(cinfo, st)) != 0) {
|
||||
st = entropy->dc_stats[tbl] + 20; /* Table F.4: X1 = 20 */
|
||||
while (arith_decode(cinfo, st)) {
|
||||
if ((m <<= 1) == 0x8000) {
|
||||
WARNMS(cinfo, JWRN_ARITH_BAD_CODE);
|
||||
entropy->ct = -1; /* magnitude overflow */
|
||||
return TRUE;
|
||||
}
|
||||
st += 1;
|
||||
}
|
||||
}
|
||||
/* Section F.1.4.4.1.2: Establish dc_context conditioning category */
|
||||
if (m < (int) ((1L << cinfo->arith_dc_L[tbl]) >> 1))
|
||||
entropy->dc_context[ci] = 0; /* zero diff category */
|
||||
else if (m > (int) ((1L << cinfo->arith_dc_U[tbl]) >> 1))
|
||||
entropy->dc_context[ci] = 12 + (sign * 4); /* large diff category */
|
||||
else
|
||||
entropy->dc_context[ci] = 4 + (sign * 4); /* small diff category */
|
||||
v = m;
|
||||
/* Figure F.24: Decoding the magnitude bit pattern of v */
|
||||
st += 14;
|
||||
while (m >>= 1)
|
||||
if (arith_decode(cinfo, st)) v |= m;
|
||||
v += 1; if (sign) v = -v;
|
||||
entropy->last_dc_val[ci] += v;
|
||||
}
|
||||
|
||||
(*block)[0] = (JCOEF) entropy->last_dc_val[ci];
|
||||
|
||||
/* Sections F.2.4.2 & F.1.4.4.2: Decoding of AC coefficients */
|
||||
|
||||
if (cinfo->lim_Se == 0) continue;
|
||||
tbl = compptr->ac_tbl_no;
|
||||
k = 0;
|
||||
|
||||
/* Figure F.20: Decode_AC_coefficients */
|
||||
do {
|
||||
st = entropy->ac_stats[tbl] + 3 * k;
|
||||
if (arith_decode(cinfo, st)) break; /* EOB flag */
|
||||
for (;;) {
|
||||
k++;
|
||||
if (arith_decode(cinfo, st + 1)) break;
|
||||
st += 3;
|
||||
if (k >= cinfo->lim_Se) {
|
||||
WARNMS(cinfo, JWRN_ARITH_BAD_CODE);
|
||||
entropy->ct = -1; /* spectral overflow */
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
/* Figure F.21: Decoding nonzero value v */
|
||||
/* Figure F.22: Decoding the sign of v */
|
||||
sign = arith_decode(cinfo, entropy->fixed_bin);
|
||||
st += 2;
|
||||
/* Figure F.23: Decoding the magnitude category of v */
|
||||
if ((m = arith_decode(cinfo, st)) != 0) {
|
||||
if (arith_decode(cinfo, st)) {
|
||||
m <<= 1;
|
||||
st = entropy->ac_stats[tbl] +
|
||||
(k <= cinfo->arith_ac_K[tbl] ? 189 : 217);
|
||||
while (arith_decode(cinfo, st)) {
|
||||
if ((m <<= 1) == 0x8000) {
|
||||
WARNMS(cinfo, JWRN_ARITH_BAD_CODE);
|
||||
entropy->ct = -1; /* magnitude overflow */
|
||||
return TRUE;
|
||||
}
|
||||
st += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
v = m;
|
||||
/* Figure F.24: Decoding the magnitude bit pattern of v */
|
||||
st += 14;
|
||||
while (m >>= 1)
|
||||
if (arith_decode(cinfo, st)) v |= m;
|
||||
v += 1; if (sign) v = -v;
|
||||
(*block)[natural_order[k]] = (JCOEF) v;
|
||||
} while (k < cinfo->lim_Se);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Initialize for an arithmetic-compressed scan.
|
||||
*/
|
||||
|
||||
METHODDEF(void)
|
||||
start_pass (j_decompress_ptr cinfo)
|
||||
{
|
||||
arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy;
|
||||
int ci, tbl;
|
||||
jpeg_component_info * compptr;
|
||||
|
||||
if (cinfo->progressive_mode) {
|
||||
/* Validate progressive scan parameters */
|
||||
if (cinfo->Ss == 0) {
|
||||
if (cinfo->Se != 0)
|
||||
goto bad;
|
||||
} else {
|
||||
/* need not check Ss/Se < 0 since they came from unsigned bytes */
|
||||
if (cinfo->Se < cinfo->Ss || cinfo->Se > cinfo->lim_Se)
|
||||
goto bad;
|
||||
/* AC scans may have only one component */
|
||||
if (cinfo->comps_in_scan != 1)
|
||||
goto bad;
|
||||
}
|
||||
if (cinfo->Ah != 0) {
|
||||
/* Successive approximation refinement scan: must have Al = Ah-1. */
|
||||
if (cinfo->Ah-1 != cinfo->Al)
|
||||
goto bad;
|
||||
}
|
||||
if (cinfo->Al > 13) { /* need not check for < 0 */
|
||||
bad:
|
||||
ERREXIT4(cinfo, JERR_BAD_PROGRESSION,
|
||||
cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al);
|
||||
}
|
||||
/* Update progression status, and verify that scan order is legal.
|
||||
* Note that inter-scan inconsistencies are treated as warnings
|
||||
* not fatal errors ... not clear if this is right way to behave.
|
||||
*/
|
||||
for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
|
||||
int coefi, cindex = cinfo->cur_comp_info[ci]->component_index;
|
||||
int *coef_bit_ptr = & cinfo->coef_bits[cindex][0];
|
||||
if (cinfo->Ss && coef_bit_ptr[0] < 0) /* AC without prior DC scan */
|
||||
WARNMS2(cinfo, JWRN_BOGUS_PROGRESSION, cindex, 0);
|
||||
for (coefi = cinfo->Ss; coefi <= cinfo->Se; coefi++) {
|
||||
int expected = (coef_bit_ptr[coefi] < 0) ? 0 : coef_bit_ptr[coefi];
|
||||
if (cinfo->Ah != expected)
|
||||
WARNMS2(cinfo, JWRN_BOGUS_PROGRESSION, cindex, coefi);
|
||||
coef_bit_ptr[coefi] = cinfo->Al;
|
||||
}
|
||||
}
|
||||
/* Select MCU decoding routine */
|
||||
if (cinfo->Ah == 0) {
|
||||
if (cinfo->Ss == 0)
|
||||
entropy->pub.decode_mcu = decode_mcu_DC_first;
|
||||
else
|
||||
entropy->pub.decode_mcu = decode_mcu_AC_first;
|
||||
} else {
|
||||
if (cinfo->Ss == 0)
|
||||
entropy->pub.decode_mcu = decode_mcu_DC_refine;
|
||||
else
|
||||
entropy->pub.decode_mcu = decode_mcu_AC_refine;
|
||||
}
|
||||
} else {
|
||||
/* Check that the scan parameters Ss, Se, Ah/Al are OK for sequential JPEG.
|
||||
* This ought to be an error condition, but we make it a warning.
|
||||
*/
|
||||
if (cinfo->Ss != 0 || cinfo->Ah != 0 || cinfo->Al != 0 ||
|
||||
(cinfo->Se < DCTSIZE2 && cinfo->Se != cinfo->lim_Se))
|
||||
WARNMS(cinfo, JWRN_NOT_SEQUENTIAL);
|
||||
/* Select MCU decoding routine */
|
||||
entropy->pub.decode_mcu = decode_mcu;
|
||||
}
|
||||
|
||||
/* Allocate & initialize requested statistics areas */
|
||||
for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
|
||||
compptr = cinfo->cur_comp_info[ci];
|
||||
if (! cinfo->progressive_mode || (cinfo->Ss == 0 && cinfo->Ah == 0)) {
|
||||
tbl = compptr->dc_tbl_no;
|
||||
if (tbl < 0 || tbl >= NUM_ARITH_TBLS)
|
||||
ERREXIT1(cinfo, JERR_NO_ARITH_TABLE, tbl);
|
||||
if (entropy->dc_stats[tbl] == NULL)
|
||||
entropy->dc_stats[tbl] = (unsigned char *) (*cinfo->mem->alloc_small)
|
||||
((j_common_ptr) cinfo, JPOOL_IMAGE, DC_STAT_BINS);
|
||||
MEMZERO(entropy->dc_stats[tbl], DC_STAT_BINS);
|
||||
/* Initialize DC predictions to 0 */
|
||||
entropy->last_dc_val[ci] = 0;
|
||||
entropy->dc_context[ci] = 0;
|
||||
}
|
||||
if ((! cinfo->progressive_mode && cinfo->lim_Se) ||
|
||||
(cinfo->progressive_mode && cinfo->Ss)) {
|
||||
tbl = compptr->ac_tbl_no;
|
||||
if (tbl < 0 || tbl >= NUM_ARITH_TBLS)
|
||||
ERREXIT1(cinfo, JERR_NO_ARITH_TABLE, tbl);
|
||||
if (entropy->ac_stats[tbl] == NULL)
|
||||
entropy->ac_stats[tbl] = (unsigned char *) (*cinfo->mem->alloc_small)
|
||||
((j_common_ptr) cinfo, JPOOL_IMAGE, AC_STAT_BINS);
|
||||
MEMZERO(entropy->ac_stats[tbl], AC_STAT_BINS);
|
||||
}
|
||||
}
|
||||
|
||||
/* Initialize arithmetic decoding variables */
|
||||
entropy->c = 0;
|
||||
entropy->a = 0;
|
||||
entropy->ct = -16; /* force reading 2 initial bytes to fill C */
|
||||
|
||||
/* Initialize restart counter */
|
||||
entropy->restarts_to_go = cinfo->restart_interval;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Module initialization routine for arithmetic entropy decoding.
|
||||
*/
|
||||
|
||||
GLOBAL(void)
|
||||
jinit_arith_decoder (j_decompress_ptr cinfo)
|
||||
{
|
||||
arith_entropy_ptr entropy;
|
||||
int i;
|
||||
|
||||
entropy = (arith_entropy_ptr)
|
||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
||||
SIZEOF(arith_entropy_decoder));
|
||||
cinfo->entropy = &entropy->pub;
|
||||
entropy->pub.start_pass = start_pass;
|
||||
|
||||
/* Mark tables unallocated */
|
||||
for (i = 0; i < NUM_ARITH_TBLS; i++) {
|
||||
entropy->dc_stats[i] = NULL;
|
||||
entropy->ac_stats[i] = NULL;
|
||||
}
|
||||
|
||||
/* Initialize index for fixed probability estimation */
|
||||
entropy->fixed_bin[0] = 113;
|
||||
|
||||
if (cinfo->progressive_mode) {
|
||||
/* Create progression status table */
|
||||
int *coef_bit_ptr, ci;
|
||||
cinfo->coef_bits = (int (*)[DCTSIZE2])
|
||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
||||
cinfo->num_components*DCTSIZE2*SIZEOF(int));
|
||||
coef_bit_ptr = & cinfo->coef_bits[0][0];
|
||||
for (ci = 0; ci < cinfo->num_components; ci++)
|
||||
for (i = 0; i < DCTSIZE2; i++)
|
||||
*coef_bit_ptr++ = -1;
|
||||
}
|
||||
}
|
129
3rdparty/libjpeg/jdatadst.c
vendored
129
3rdparty/libjpeg/jdatadst.c
vendored
@ -2,13 +2,14 @@
|
||||
* jdatadst.c
|
||||
*
|
||||
* Copyright (C) 1994-1996, Thomas G. Lane.
|
||||
* Modified 2009-2012 by Guido Vollbeding.
|
||||
* This file is part of the Independent JPEG Group's software.
|
||||
* For conditions of distribution and use, see the accompanying README file.
|
||||
*
|
||||
* This file contains compression data destination routines for the case of
|
||||
* emitting JPEG data to a file (or any stdio stream). While these routines
|
||||
* are sufficient for most applications, some will want to use a different
|
||||
* destination manager.
|
||||
* emitting JPEG data to memory or to a file (or any stdio stream).
|
||||
* While these routines are sufficient for most applications,
|
||||
* some will want to use a different destination manager.
|
||||
* IMPORTANT: we assume that fwrite() will correctly transcribe an array of
|
||||
* JOCTETs into 8-bit-wide elements on external storage. If char is wider
|
||||
* than 8 bits on your machine, you may need to do some tweaking.
|
||||
@ -19,6 +20,11 @@
|
||||
#include "jpeglib.h"
|
||||
#include "jerror.h"
|
||||
|
||||
#ifndef HAVE_STDLIB_H /* <stdlib.h> should declare malloc(),free() */
|
||||
extern void * malloc JPP((size_t size));
|
||||
extern void free JPP((void *ptr));
|
||||
#endif
|
||||
|
||||
|
||||
/* Expanded data destination object for stdio output */
|
||||
|
||||
@ -34,6 +40,21 @@ typedef my_destination_mgr * my_dest_ptr;
|
||||
#define OUTPUT_BUF_SIZE 4096 /* choose an efficiently fwrite'able size */
|
||||
|
||||
|
||||
/* Expanded data destination object for memory output */
|
||||
|
||||
typedef struct {
|
||||
struct jpeg_destination_mgr pub; /* public fields */
|
||||
|
||||
unsigned char ** outbuffer; /* target buffer */
|
||||
unsigned long * outsize;
|
||||
unsigned char * newbuffer; /* newly allocated buffer */
|
||||
JOCTET * buffer; /* start of buffer */
|
||||
size_t bufsize;
|
||||
} my_mem_destination_mgr;
|
||||
|
||||
typedef my_mem_destination_mgr * my_mem_dest_ptr;
|
||||
|
||||
|
||||
/*
|
||||
* Initialize destination --- called by jpeg_start_compress
|
||||
* before any data is actually written.
|
||||
@ -47,12 +68,18 @@ init_destination (j_compress_ptr cinfo)
|
||||
/* Allocate the output buffer --- it will be released when done with image */
|
||||
dest->buffer = (JOCTET *)
|
||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
||||
OUTPUT_BUF_SIZE * SIZEOF(JOCTET));
|
||||
OUTPUT_BUF_SIZE * SIZEOF(JOCTET));
|
||||
|
||||
dest->pub.next_output_byte = dest->buffer;
|
||||
dest->pub.free_in_buffer = OUTPUT_BUF_SIZE;
|
||||
}
|
||||
|
||||
METHODDEF(void)
|
||||
init_mem_destination (j_compress_ptr cinfo)
|
||||
{
|
||||
/* no work necessary here */
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Empty the output buffer --- called whenever buffer fills up.
|
||||
@ -92,6 +119,36 @@ empty_output_buffer (j_compress_ptr cinfo)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
METHODDEF(boolean)
|
||||
empty_mem_output_buffer (j_compress_ptr cinfo)
|
||||
{
|
||||
size_t nextsize;
|
||||
JOCTET * nextbuffer;
|
||||
my_mem_dest_ptr dest = (my_mem_dest_ptr) cinfo->dest;
|
||||
|
||||
/* Try to allocate new buffer with double size */
|
||||
nextsize = dest->bufsize * 2;
|
||||
nextbuffer = (JOCTET *) malloc(nextsize);
|
||||
|
||||
if (nextbuffer == NULL)
|
||||
ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, 10);
|
||||
|
||||
MEMCOPY(nextbuffer, dest->buffer, dest->bufsize);
|
||||
|
||||
if (dest->newbuffer != NULL)
|
||||
free(dest->newbuffer);
|
||||
|
||||
dest->newbuffer = nextbuffer;
|
||||
|
||||
dest->pub.next_output_byte = nextbuffer + dest->bufsize;
|
||||
dest->pub.free_in_buffer = dest->bufsize;
|
||||
|
||||
dest->buffer = nextbuffer;
|
||||
dest->bufsize = nextsize;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Terminate destination --- called by jpeg_finish_compress
|
||||
@ -119,6 +176,15 @@ term_destination (j_compress_ptr cinfo)
|
||||
ERREXIT(cinfo, JERR_FILE_WRITE);
|
||||
}
|
||||
|
||||
METHODDEF(void)
|
||||
term_mem_destination (j_compress_ptr cinfo)
|
||||
{
|
||||
my_mem_dest_ptr dest = (my_mem_dest_ptr) cinfo->dest;
|
||||
|
||||
*dest->outbuffer = dest->buffer;
|
||||
*dest->outsize = dest->bufsize - dest->pub.free_in_buffer;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Prepare for output to a stdio stream.
|
||||
@ -140,7 +206,7 @@ jpeg_stdio_dest (j_compress_ptr cinfo, FILE * outfile)
|
||||
if (cinfo->dest == NULL) { /* first time for this JPEG object? */
|
||||
cinfo->dest = (struct jpeg_destination_mgr *)
|
||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
|
||||
SIZEOF(my_destination_mgr));
|
||||
SIZEOF(my_destination_mgr));
|
||||
}
|
||||
|
||||
dest = (my_dest_ptr) cinfo->dest;
|
||||
@ -149,3 +215,56 @@ jpeg_stdio_dest (j_compress_ptr cinfo, FILE * outfile)
|
||||
dest->pub.term_destination = term_destination;
|
||||
dest->outfile = outfile;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Prepare for output to a memory buffer.
|
||||
* The caller may supply an own initial buffer with appropriate size.
|
||||
* Otherwise, or when the actual data output exceeds the given size,
|
||||
* the library adapts the buffer size as necessary.
|
||||
* The standard library functions malloc/free are used for allocating
|
||||
* larger memory, so the buffer is available to the application after
|
||||
* finishing compression, and then the application is responsible for
|
||||
* freeing the requested memory.
|
||||
* 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)
|
||||
jpeg_mem_dest (j_compress_ptr cinfo,
|
||||
unsigned char ** outbuffer, unsigned long * outsize)
|
||||
{
|
||||
my_mem_dest_ptr dest;
|
||||
|
||||
if (outbuffer == NULL || outsize == NULL) /* sanity check */
|
||||
ERREXIT(cinfo, JERR_BUFFER_SIZE);
|
||||
|
||||
/* The destination object is made permanent so that multiple JPEG images
|
||||
* can be written to the same buffer without re-executing jpeg_mem_dest.
|
||||
*/
|
||||
if (cinfo->dest == NULL) { /* first time for this JPEG object? */
|
||||
cinfo->dest = (struct jpeg_destination_mgr *)
|
||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
|
||||
SIZEOF(my_mem_destination_mgr));
|
||||
}
|
||||
|
||||
dest = (my_mem_dest_ptr) cinfo->dest;
|
||||
dest->pub.init_destination = init_mem_destination;
|
||||
dest->pub.empty_output_buffer = empty_mem_output_buffer;
|
||||
dest->pub.term_destination = term_mem_destination;
|
||||
dest->outbuffer = outbuffer;
|
||||
dest->outsize = outsize;
|
||||
dest->newbuffer = NULL;
|
||||
|
||||
if (*outbuffer == NULL || *outsize == 0) {
|
||||
/* Allocate initial buffer */
|
||||
dest->newbuffer = *outbuffer = (unsigned char *) malloc(OUTPUT_BUF_SIZE);
|
||||
if (dest->newbuffer == NULL)
|
||||
ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, 10);
|
||||
*outsize = OUTPUT_BUF_SIZE;
|
||||
}
|
||||
|
||||
dest->pub.next_output_byte = dest->buffer = *outbuffer;
|
||||
dest->pub.free_in_buffer = dest->bufsize = *outsize;
|
||||
}
|
||||
|
85
3rdparty/libjpeg/jdatasrc.c
vendored
85
3rdparty/libjpeg/jdatasrc.c
vendored
@ -2,13 +2,14 @@
|
||||
* jdatasrc.c
|
||||
*
|
||||
* Copyright (C) 1994-1996, Thomas G. Lane.
|
||||
* Modified 2009-2011 by Guido Vollbeding.
|
||||
* This file is part of the Independent JPEG Group's software.
|
||||
* For conditions of distribution and use, see the accompanying README file.
|
||||
*
|
||||
* This file contains decompression data source routines for the case of
|
||||
* reading JPEG data from a file (or any stdio stream). While these routines
|
||||
* are sufficient for most applications, some will want to use a different
|
||||
* source manager.
|
||||
* reading JPEG data from memory or from a file (or any stdio stream).
|
||||
* While these routines are sufficient for most applications,
|
||||
* some will want to use a different source manager.
|
||||
* IMPORTANT: we assume that fread() will correctly transcribe an array of
|
||||
* JOCTETs from 8-bit-wide elements on external storage. If char is wider
|
||||
* than 8 bits on your machine, you may need to do some tweaking.
|
||||
@ -52,6 +53,12 @@ init_source (j_decompress_ptr cinfo)
|
||||
src->start_of_file = TRUE;
|
||||
}
|
||||
|
||||
METHODDEF(void)
|
||||
init_mem_source (j_decompress_ptr cinfo)
|
||||
{
|
||||
/* no work necessary here */
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Fill the input buffer --- called whenever buffer is emptied.
|
||||
@ -111,6 +118,27 @@ fill_input_buffer (j_decompress_ptr cinfo)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
METHODDEF(boolean)
|
||||
fill_mem_input_buffer (j_decompress_ptr cinfo)
|
||||
{
|
||||
static const JOCTET mybuffer[4] = {
|
||||
(JOCTET) 0xFF, (JOCTET) JPEG_EOI, 0, 0
|
||||
};
|
||||
|
||||
/* The whole JPEG data is expected to reside in the supplied memory
|
||||
* buffer, so any request for more data beyond the given buffer size
|
||||
* is treated as an error.
|
||||
*/
|
||||
WARNMS(cinfo, JWRN_JPEG_EOF);
|
||||
|
||||
/* Insert a fake EOI marker */
|
||||
|
||||
cinfo->src->next_input_byte = mybuffer;
|
||||
cinfo->src->bytes_in_buffer = 2;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Skip data --- used to skip over a potentially large amount of
|
||||
@ -127,22 +155,22 @@ fill_input_buffer (j_decompress_ptr cinfo)
|
||||
METHODDEF(void)
|
||||
skip_input_data (j_decompress_ptr cinfo, long num_bytes)
|
||||
{
|
||||
my_src_ptr src = (my_src_ptr) cinfo->src;
|
||||
struct jpeg_source_mgr * src = cinfo->src;
|
||||
|
||||
/* Just a dumb implementation for now. Could use fseek() except
|
||||
* it doesn't work on pipes. Not clear that being smart is worth
|
||||
* any trouble anyway --- large skips are infrequent.
|
||||
*/
|
||||
if (num_bytes > 0) {
|
||||
while (num_bytes > (long) src->pub.bytes_in_buffer) {
|
||||
num_bytes -= (long) src->pub.bytes_in_buffer;
|
||||
(void) fill_input_buffer(cinfo);
|
||||
while (num_bytes > (long) src->bytes_in_buffer) {
|
||||
num_bytes -= (long) src->bytes_in_buffer;
|
||||
(void) (*src->fill_input_buffer) (cinfo);
|
||||
/* note we assume that fill_input_buffer will never return FALSE,
|
||||
* so suspension need not be handled.
|
||||
*/
|
||||
}
|
||||
src->pub.next_input_byte += (size_t) num_bytes;
|
||||
src->pub.bytes_in_buffer -= (size_t) num_bytes;
|
||||
src->next_input_byte += (size_t) num_bytes;
|
||||
src->bytes_in_buffer -= (size_t) num_bytes;
|
||||
}
|
||||
}
|
||||
|
||||
@ -193,11 +221,11 @@ jpeg_stdio_src (j_decompress_ptr cinfo, FILE * infile)
|
||||
if (cinfo->src == NULL) { /* first time for this JPEG object? */
|
||||
cinfo->src = (struct jpeg_source_mgr *)
|
||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
|
||||
SIZEOF(my_source_mgr));
|
||||
SIZEOF(my_source_mgr));
|
||||
src = (my_src_ptr) cinfo->src;
|
||||
src->buffer = (JOCTET *)
|
||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
|
||||
INPUT_BUF_SIZE * SIZEOF(JOCTET));
|
||||
INPUT_BUF_SIZE * SIZEOF(JOCTET));
|
||||
}
|
||||
|
||||
src = (my_src_ptr) cinfo->src;
|
||||
@ -210,3 +238,38 @@ jpeg_stdio_src (j_decompress_ptr cinfo, FILE * infile)
|
||||
src->pub.bytes_in_buffer = 0; /* forces fill_input_buffer on first read */
|
||||
src->pub.next_input_byte = NULL; /* until buffer loaded */
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Prepare for input from a supplied memory buffer.
|
||||
* The buffer must contain the whole JPEG data.
|
||||
*/
|
||||
|
||||
GLOBAL(void)
|
||||
jpeg_mem_src (j_decompress_ptr cinfo,
|
||||
unsigned char * inbuffer, unsigned long insize)
|
||||
{
|
||||
struct jpeg_source_mgr * src;
|
||||
|
||||
if (inbuffer == NULL || insize == 0) /* Treat empty input as fatal error */
|
||||
ERREXIT(cinfo, JERR_INPUT_EMPTY);
|
||||
|
||||
/* The source object is made permanent so that a series of JPEG images
|
||||
* can be read from the same buffer by calling jpeg_mem_src only before
|
||||
* the first one.
|
||||
*/
|
||||
if (cinfo->src == NULL) { /* first time for this JPEG object? */
|
||||
cinfo->src = (struct jpeg_source_mgr *)
|
||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
|
||||
SIZEOF(struct jpeg_source_mgr));
|
||||
}
|
||||
|
||||
src = cinfo->src;
|
||||
src->init_source = init_mem_source;
|
||||
src->fill_input_buffer = fill_mem_input_buffer;
|
||||
src->skip_input_data = skip_input_data;
|
||||
src->resync_to_restart = jpeg_resync_to_restart; /* use default method */
|
||||
src->term_source = term_source;
|
||||
src->bytes_in_buffer = (size_t) insize;
|
||||
src->next_input_byte = (JOCTET *) inbuffer;
|
||||
}
|
||||
|
367
3rdparty/libjpeg/jdcoefct.c
vendored
367
3rdparty/libjpeg/jdcoefct.c
vendored
@ -2,6 +2,7 @@
|
||||
* jdcoefct.c
|
||||
*
|
||||
* Copyright (C) 1994-1997, Thomas G. Lane.
|
||||
* Modified 2002-2011 by Guido Vollbeding.
|
||||
* This file is part of the Independent JPEG Group's software.
|
||||
* For conditions of distribution and use, see the accompanying README file.
|
||||
*
|
||||
@ -63,15 +64,15 @@ typedef my_coef_controller * my_coef_ptr;
|
||||
|
||||
/* Forward declarations */
|
||||
METHODDEF(int) decompress_onepass
|
||||
JPP((j_decompress_ptr cinfo, JSAMPIMAGE output_buf));
|
||||
JPP((j_decompress_ptr cinfo, JSAMPIMAGE output_buf));
|
||||
#ifdef D_MULTISCAN_FILES_SUPPORTED
|
||||
METHODDEF(int) decompress_data
|
||||
JPP((j_decompress_ptr cinfo, JSAMPIMAGE output_buf));
|
||||
JPP((j_decompress_ptr cinfo, JSAMPIMAGE output_buf));
|
||||
#endif
|
||||
#ifdef BLOCK_SMOOTHING_SUPPORTED
|
||||
LOCAL(boolean) smoothing_ok JPP((j_decompress_ptr cinfo));
|
||||
METHODDEF(int) decompress_smooth_data
|
||||
JPP((j_decompress_ptr cinfo, JSAMPIMAGE output_buf));
|
||||
JPP((j_decompress_ptr cinfo, JSAMPIMAGE output_buf));
|
||||
#endif
|
||||
|
||||
|
||||
@ -160,15 +161,16 @@ decompress_onepass (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
|
||||
for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
|
||||
yoffset++) {
|
||||
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. */
|
||||
jzero_far((void FAR *) coef->MCU_buffer[0],
|
||||
(size_t) (cinfo->blocks_in_MCU * SIZEOF(JBLOCK)));
|
||||
if (cinfo->lim_Se) /* can bypass in DC only case */
|
||||
FMEMZERO((void FAR *) coef->MCU_buffer[0],
|
||||
(size_t) (cinfo->blocks_in_MCU * SIZEOF(JBLOCK)));
|
||||
if (! (*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) {
|
||||
/* Suspension forced; update state counters and exit */
|
||||
coef->MCU_vert_offset = yoffset;
|
||||
coef->MCU_ctr = MCU_col_num;
|
||||
return JPEG_SUSPENDED;
|
||||
/* Suspension forced; update state counters and exit */
|
||||
coef->MCU_vert_offset = yoffset;
|
||||
coef->MCU_ctr = MCU_col_num;
|
||||
return JPEG_SUSPENDED;
|
||||
}
|
||||
/* Determine where data should go in output_buf and do the IDCT thing.
|
||||
* We skip dummy blocks at the right and bottom edges (but blkn gets
|
||||
@ -177,32 +179,32 @@ decompress_onepass (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
|
||||
*/
|
||||
blkn = 0; /* index of current DCT block within MCU */
|
||||
for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
|
||||
compptr = cinfo->cur_comp_info[ci];
|
||||
/* Don't bother to IDCT an uninteresting component. */
|
||||
if (! compptr->component_needed) {
|
||||
blkn += compptr->MCU_blocks;
|
||||
continue;
|
||||
}
|
||||
inverse_DCT = cinfo->idct->inverse_DCT[compptr->component_index];
|
||||
useful_width = (MCU_col_num < last_MCU_col) ? compptr->MCU_width
|
||||
: compptr->last_col_width;
|
||||
output_ptr = output_buf[compptr->component_index] +
|
||||
yoffset * compptr->DCT_scaled_size;
|
||||
start_col = MCU_col_num * compptr->MCU_sample_width;
|
||||
for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
|
||||
if (cinfo->input_iMCU_row < last_iMCU_row ||
|
||||
yoffset+yindex < compptr->last_row_height) {
|
||||
output_col = start_col;
|
||||
for (xindex = 0; xindex < useful_width; xindex++) {
|
||||
(*inverse_DCT) (cinfo, compptr,
|
||||
(JCOEFPTR) coef->MCU_buffer[blkn+xindex],
|
||||
output_ptr, output_col);
|
||||
output_col += compptr->DCT_scaled_size;
|
||||
compptr = cinfo->cur_comp_info[ci];
|
||||
/* Don't bother to IDCT an uninteresting component. */
|
||||
if (! compptr->component_needed) {
|
||||
blkn += compptr->MCU_blocks;
|
||||
continue;
|
||||
}
|
||||
inverse_DCT = cinfo->idct->inverse_DCT[compptr->component_index];
|
||||
useful_width = (MCU_col_num < last_MCU_col) ? compptr->MCU_width
|
||||
: compptr->last_col_width;
|
||||
output_ptr = output_buf[compptr->component_index] +
|
||||
yoffset * compptr->DCT_v_scaled_size;
|
||||
start_col = MCU_col_num * compptr->MCU_sample_width;
|
||||
for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
|
||||
if (cinfo->input_iMCU_row < last_iMCU_row ||
|
||||
yoffset+yindex < compptr->last_row_height) {
|
||||
output_col = start_col;
|
||||
for (xindex = 0; xindex < useful_width; xindex++) {
|
||||
(*inverse_DCT) (cinfo, compptr,
|
||||
(JCOEFPTR) coef->MCU_buffer[blkn+xindex],
|
||||
output_ptr, output_col);
|
||||
output_col += compptr->DCT_h_scaled_size;
|
||||
}
|
||||
}
|
||||
blkn += compptr->MCU_width;
|
||||
output_ptr += compptr->DCT_v_scaled_size;
|
||||
}
|
||||
}
|
||||
blkn += compptr->MCU_width;
|
||||
output_ptr += compptr->DCT_scaled_size;
|
||||
}
|
||||
}
|
||||
}
|
||||
/* Completed an MCU row, but perhaps not an iMCU row */
|
||||
@ -268,25 +270,25 @@ consume_data (j_decompress_ptr cinfo)
|
||||
for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
|
||||
yoffset++) {
|
||||
for (MCU_col_num = coef->MCU_ctr; MCU_col_num < cinfo->MCUs_per_row;
|
||||
MCU_col_num++) {
|
||||
MCU_col_num++) {
|
||||
/* Construct list of pointers to DCT blocks belonging to this MCU */
|
||||
blkn = 0; /* index of current DCT block within MCU */
|
||||
for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
|
||||
compptr = cinfo->cur_comp_info[ci];
|
||||
start_col = MCU_col_num * compptr->MCU_width;
|
||||
for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
|
||||
buffer_ptr = buffer[ci][yindex+yoffset] + start_col;
|
||||
for (xindex = 0; xindex < compptr->MCU_width; xindex++) {
|
||||
coef->MCU_buffer[blkn++] = buffer_ptr++;
|
||||
}
|
||||
}
|
||||
compptr = cinfo->cur_comp_info[ci];
|
||||
start_col = MCU_col_num * compptr->MCU_width;
|
||||
for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
|
||||
buffer_ptr = buffer[ci][yindex+yoffset] + start_col;
|
||||
for (xindex = 0; xindex < compptr->MCU_width; xindex++) {
|
||||
coef->MCU_buffer[blkn++] = buffer_ptr++;
|
||||
}
|
||||
}
|
||||
}
|
||||
/* Try to fetch the MCU. */
|
||||
if (! (*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) {
|
||||
/* Suspension forced; update state counters and exit */
|
||||
coef->MCU_vert_offset = yoffset;
|
||||
coef->MCU_ctr = MCU_col_num;
|
||||
return JPEG_SUSPENDED;
|
||||
/* Suspension forced; update state counters and exit */
|
||||
coef->MCU_vert_offset = yoffset;
|
||||
coef->MCU_ctr = MCU_col_num;
|
||||
return JPEG_SUSPENDED;
|
||||
}
|
||||
}
|
||||
/* Completed an MCU row, but perhaps not an iMCU row */
|
||||
@ -327,8 +329,8 @@ decompress_data (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
|
||||
|
||||
/* Force some input to be done if we are getting ahead of the input. */
|
||||
while (cinfo->input_scan_number < cinfo->output_scan_number ||
|
||||
(cinfo->input_scan_number == cinfo->output_scan_number &&
|
||||
cinfo->input_iMCU_row <= cinfo->output_iMCU_row)) {
|
||||
(cinfo->input_scan_number == cinfo->output_scan_number &&
|
||||
cinfo->input_iMCU_row <= cinfo->output_iMCU_row)) {
|
||||
if ((*cinfo->inputctl->consume_input)(cinfo) == JPEG_SUSPENDED)
|
||||
return JPEG_SUSPENDED;
|
||||
}
|
||||
@ -359,12 +361,12 @@ decompress_data (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
|
||||
buffer_ptr = buffer[block_row];
|
||||
output_col = 0;
|
||||
for (block_num = 0; block_num < compptr->width_in_blocks; block_num++) {
|
||||
(*inverse_DCT) (cinfo, compptr, (JCOEFPTR) buffer_ptr,
|
||||
output_ptr, output_col);
|
||||
buffer_ptr++;
|
||||
output_col += compptr->DCT_scaled_size;
|
||||
(*inverse_DCT) (cinfo, compptr, (JCOEFPTR) buffer_ptr,
|
||||
output_ptr, output_col);
|
||||
buffer_ptr++;
|
||||
output_col += compptr->DCT_h_scaled_size;
|
||||
}
|
||||
output_ptr += compptr->DCT_scaled_size;
|
||||
output_ptr += compptr->DCT_v_scaled_size;
|
||||
}
|
||||
}
|
||||
|
||||
@ -419,8 +421,8 @@ smoothing_ok (j_decompress_ptr cinfo)
|
||||
if (coef->coef_bits_latch == NULL)
|
||||
coef->coef_bits_latch = (int *)
|
||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
||||
cinfo->num_components *
|
||||
(SAVED_COEFS * SIZEOF(int)));
|
||||
cinfo->num_components *
|
||||
(SAVED_COEFS * SIZEOF(int)));
|
||||
coef_bits_latch = coef->coef_bits_latch;
|
||||
|
||||
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
|
||||
@ -430,11 +432,11 @@ smoothing_ok (j_decompress_ptr cinfo)
|
||||
return FALSE;
|
||||
/* Verify DC & first 5 AC quantizers are nonzero to avoid zero-divide. */
|
||||
if (qtable->quantval[0] == 0 ||
|
||||
qtable->quantval[Q01_POS] == 0 ||
|
||||
qtable->quantval[Q10_POS] == 0 ||
|
||||
qtable->quantval[Q20_POS] == 0 ||
|
||||
qtable->quantval[Q11_POS] == 0 ||
|
||||
qtable->quantval[Q02_POS] == 0)
|
||||
qtable->quantval[Q01_POS] == 0 ||
|
||||
qtable->quantval[Q10_POS] == 0 ||
|
||||
qtable->quantval[Q20_POS] == 0 ||
|
||||
qtable->quantval[Q11_POS] == 0 ||
|
||||
qtable->quantval[Q02_POS] == 0)
|
||||
return FALSE;
|
||||
/* DC values must be at least partly known for all components. */
|
||||
coef_bits = cinfo->coef_bits[ci];
|
||||
@ -444,7 +446,7 @@ smoothing_ok (j_decompress_ptr cinfo)
|
||||
for (coefi = 1; coefi <= 5; coefi++) {
|
||||
coef_bits_latch[coefi] = coef_bits[coefi];
|
||||
if (coef_bits[coefi] != 0)
|
||||
smoothing_useful = TRUE;
|
||||
smoothing_useful = TRUE;
|
||||
}
|
||||
coef_bits_latch += SAVED_COEFS;
|
||||
}
|
||||
@ -480,7 +482,7 @@ decompress_smooth_data (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
|
||||
|
||||
/* Force some input to be done if we are getting ahead of the input. */
|
||||
while (cinfo->input_scan_number <= cinfo->output_scan_number &&
|
||||
! cinfo->inputctl->eoi_reached) {
|
||||
! cinfo->inputctl->eoi_reached) {
|
||||
if (cinfo->input_scan_number == cinfo->output_scan_number) {
|
||||
/* If input is working on current scan, we ordinarily want it to
|
||||
* have completed the current row. But if input scan is DC,
|
||||
@ -489,7 +491,7 @@ decompress_smooth_data (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
|
||||
*/
|
||||
JDIMENSION delta = (cinfo->Ss == 0) ? 1 : 0;
|
||||
if (cinfo->input_iMCU_row > cinfo->output_iMCU_row+delta)
|
||||
break;
|
||||
break;
|
||||
}
|
||||
if ((*cinfo->inputctl->consume_input)(cinfo) == JPEG_SUSPENDED)
|
||||
return JPEG_SUSPENDED;
|
||||
@ -517,15 +519,15 @@ decompress_smooth_data (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
|
||||
if (cinfo->output_iMCU_row > 0) {
|
||||
access_rows += compptr->v_samp_factor; /* prior iMCU row too */
|
||||
buffer = (*cinfo->mem->access_virt_barray)
|
||||
((j_common_ptr) cinfo, coef->whole_image[ci],
|
||||
(cinfo->output_iMCU_row - 1) * compptr->v_samp_factor,
|
||||
(JDIMENSION) access_rows, FALSE);
|
||||
((j_common_ptr) cinfo, coef->whole_image[ci],
|
||||
(cinfo->output_iMCU_row - 1) * compptr->v_samp_factor,
|
||||
(JDIMENSION) access_rows, FALSE);
|
||||
buffer += compptr->v_samp_factor; /* point to current iMCU row */
|
||||
first_row = FALSE;
|
||||
} else {
|
||||
buffer = (*cinfo->mem->access_virt_barray)
|
||||
((j_common_ptr) cinfo, coef->whole_image[ci],
|
||||
(JDIMENSION) 0, (JDIMENSION) access_rows, FALSE);
|
||||
((j_common_ptr) cinfo, coef->whole_image[ci],
|
||||
(JDIMENSION) 0, (JDIMENSION) access_rows, FALSE);
|
||||
first_row = TRUE;
|
||||
}
|
||||
/* Fetch component-dependent info */
|
||||
@ -543,13 +545,13 @@ decompress_smooth_data (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
|
||||
for (block_row = 0; block_row < block_rows; block_row++) {
|
||||
buffer_ptr = buffer[block_row];
|
||||
if (first_row && block_row == 0)
|
||||
prev_block_row = buffer_ptr;
|
||||
prev_block_row = buffer_ptr;
|
||||
else
|
||||
prev_block_row = buffer[block_row-1];
|
||||
prev_block_row = buffer[block_row-1];
|
||||
if (last_row && block_row == block_rows-1)
|
||||
next_block_row = buffer_ptr;
|
||||
next_block_row = buffer_ptr;
|
||||
else
|
||||
next_block_row = buffer[block_row+1];
|
||||
next_block_row = buffer[block_row+1];
|
||||
/* We fetch the surrounding DC values using a sliding-register approach.
|
||||
* Initialize all nine here so as to do the right thing on narrow pics.
|
||||
*/
|
||||
@ -559,104 +561,104 @@ decompress_smooth_data (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
|
||||
output_col = 0;
|
||||
last_block_column = compptr->width_in_blocks - 1;
|
||||
for (block_num = 0; block_num <= last_block_column; block_num++) {
|
||||
/* Fetch current DCT block into workspace so we can modify it. */
|
||||
jcopy_block_row(buffer_ptr, (JBLOCKROW) workspace, (JDIMENSION) 1);
|
||||
/* Update DC values */
|
||||
if (block_num < last_block_column) {
|
||||
DC3 = (int) prev_block_row[1][0];
|
||||
DC6 = (int) buffer_ptr[1][0];
|
||||
DC9 = (int) next_block_row[1][0];
|
||||
}
|
||||
/* Compute coefficient estimates per K.8.
|
||||
* An estimate is applied only if coefficient is still zero,
|
||||
* and is not known to be fully accurate.
|
||||
*/
|
||||
/* AC01 */
|
||||
if ((Al=coef_bits[1]) != 0 && workspace[1] == 0) {
|
||||
num = 36 * Q00 * (DC4 - DC6);
|
||||
if (num >= 0) {
|
||||
pred = (int) (((Q01<<7) + num) / (Q01<<8));
|
||||
if (Al > 0 && pred >= (1<<Al))
|
||||
pred = (1<<Al)-1;
|
||||
} else {
|
||||
pred = (int) (((Q01<<7) - num) / (Q01<<8));
|
||||
if (Al > 0 && pred >= (1<<Al))
|
||||
pred = (1<<Al)-1;
|
||||
pred = -pred;
|
||||
/* Fetch current DCT block into workspace so we can modify it. */
|
||||
jcopy_block_row(buffer_ptr, (JBLOCKROW) workspace, (JDIMENSION) 1);
|
||||
/* Update DC values */
|
||||
if (block_num < last_block_column) {
|
||||
DC3 = (int) prev_block_row[1][0];
|
||||
DC6 = (int) buffer_ptr[1][0];
|
||||
DC9 = (int) next_block_row[1][0];
|
||||
}
|
||||
/* Compute coefficient estimates per K.8.
|
||||
* An estimate is applied only if coefficient is still zero,
|
||||
* and is not known to be fully accurate.
|
||||
*/
|
||||
/* AC01 */
|
||||
if ((Al=coef_bits[1]) != 0 && workspace[1] == 0) {
|
||||
num = 36 * Q00 * (DC4 - DC6);
|
||||
if (num >= 0) {
|
||||
pred = (int) (((Q01<<7) + num) / (Q01<<8));
|
||||
if (Al > 0 && pred >= (1<<Al))
|
||||
pred = (1<<Al)-1;
|
||||
} else {
|
||||
pred = (int) (((Q01<<7) - num) / (Q01<<8));
|
||||
if (Al > 0 && pred >= (1<<Al))
|
||||
pred = (1<<Al)-1;
|
||||
pred = -pred;
|
||||
}
|
||||
workspace[1] = (JCOEF) pred;
|
||||
}
|
||||
/* AC10 */
|
||||
if ((Al=coef_bits[2]) != 0 && workspace[8] == 0) {
|
||||
num = 36 * Q00 * (DC2 - DC8);
|
||||
if (num >= 0) {
|
||||
pred = (int) (((Q10<<7) + num) / (Q10<<8));
|
||||
if (Al > 0 && pred >= (1<<Al))
|
||||
pred = (1<<Al)-1;
|
||||
} else {
|
||||
pred = (int) (((Q10<<7) - num) / (Q10<<8));
|
||||
if (Al > 0 && pred >= (1<<Al))
|
||||
pred = (1<<Al)-1;
|
||||
pred = -pred;
|
||||
}
|
||||
workspace[8] = (JCOEF) pred;
|
||||
}
|
||||
/* AC20 */
|
||||
if ((Al=coef_bits[3]) != 0 && workspace[16] == 0) {
|
||||
num = 9 * Q00 * (DC2 + DC8 - 2*DC5);
|
||||
if (num >= 0) {
|
||||
pred = (int) (((Q20<<7) + num) / (Q20<<8));
|
||||
if (Al > 0 && pred >= (1<<Al))
|
||||
pred = (1<<Al)-1;
|
||||
} else {
|
||||
pred = (int) (((Q20<<7) - num) / (Q20<<8));
|
||||
if (Al > 0 && pred >= (1<<Al))
|
||||
pred = (1<<Al)-1;
|
||||
pred = -pred;
|
||||
}
|
||||
workspace[16] = (JCOEF) pred;
|
||||
}
|
||||
/* AC11 */
|
||||
if ((Al=coef_bits[4]) != 0 && workspace[9] == 0) {
|
||||
num = 5 * Q00 * (DC1 - DC3 - DC7 + DC9);
|
||||
if (num >= 0) {
|
||||
pred = (int) (((Q11<<7) + num) / (Q11<<8));
|
||||
if (Al > 0 && pred >= (1<<Al))
|
||||
pred = (1<<Al)-1;
|
||||
} else {
|
||||
pred = (int) (((Q11<<7) - num) / (Q11<<8));
|
||||
if (Al > 0 && pred >= (1<<Al))
|
||||
pred = (1<<Al)-1;
|
||||
pred = -pred;
|
||||
}
|
||||
workspace[9] = (JCOEF) pred;
|
||||
}
|
||||
/* AC02 */
|
||||
if ((Al=coef_bits[5]) != 0 && workspace[2] == 0) {
|
||||
num = 9 * Q00 * (DC4 + DC6 - 2*DC5);
|
||||
if (num >= 0) {
|
||||
pred = (int) (((Q02<<7) + num) / (Q02<<8));
|
||||
if (Al > 0 && pred >= (1<<Al))
|
||||
pred = (1<<Al)-1;
|
||||
} else {
|
||||
pred = (int) (((Q02<<7) - num) / (Q02<<8));
|
||||
if (Al > 0 && pred >= (1<<Al))
|
||||
pred = (1<<Al)-1;
|
||||
pred = -pred;
|
||||
}
|
||||
workspace[2] = (JCOEF) pred;
|
||||
}
|
||||
/* OK, do the IDCT */
|
||||
(*inverse_DCT) (cinfo, compptr, (JCOEFPTR) workspace,
|
||||
output_ptr, output_col);
|
||||
/* Advance for next column */
|
||||
DC1 = DC2; DC2 = DC3;
|
||||
DC4 = DC5; DC5 = DC6;
|
||||
DC7 = DC8; DC8 = DC9;
|
||||
buffer_ptr++, prev_block_row++, next_block_row++;
|
||||
output_col += compptr->DCT_h_scaled_size;
|
||||
}
|
||||
workspace[1] = (JCOEF) pred;
|
||||
}
|
||||
/* AC10 */
|
||||
if ((Al=coef_bits[2]) != 0 && workspace[8] == 0) {
|
||||
num = 36 * Q00 * (DC2 - DC8);
|
||||
if (num >= 0) {
|
||||
pred = (int) (((Q10<<7) + num) / (Q10<<8));
|
||||
if (Al > 0 && pred >= (1<<Al))
|
||||
pred = (1<<Al)-1;
|
||||
} else {
|
||||
pred = (int) (((Q10<<7) - num) / (Q10<<8));
|
||||
if (Al > 0 && pred >= (1<<Al))
|
||||
pred = (1<<Al)-1;
|
||||
pred = -pred;
|
||||
}
|
||||
workspace[8] = (JCOEF) pred;
|
||||
}
|
||||
/* AC20 */
|
||||
if ((Al=coef_bits[3]) != 0 && workspace[16] == 0) {
|
||||
num = 9 * Q00 * (DC2 + DC8 - 2*DC5);
|
||||
if (num >= 0) {
|
||||
pred = (int) (((Q20<<7) + num) / (Q20<<8));
|
||||
if (Al > 0 && pred >= (1<<Al))
|
||||
pred = (1<<Al)-1;
|
||||
} else {
|
||||
pred = (int) (((Q20<<7) - num) / (Q20<<8));
|
||||
if (Al > 0 && pred >= (1<<Al))
|
||||
pred = (1<<Al)-1;
|
||||
pred = -pred;
|
||||
}
|
||||
workspace[16] = (JCOEF) pred;
|
||||
}
|
||||
/* AC11 */
|
||||
if ((Al=coef_bits[4]) != 0 && workspace[9] == 0) {
|
||||
num = 5 * Q00 * (DC1 - DC3 - DC7 + DC9);
|
||||
if (num >= 0) {
|
||||
pred = (int) (((Q11<<7) + num) / (Q11<<8));
|
||||
if (Al > 0 && pred >= (1<<Al))
|
||||
pred = (1<<Al)-1;
|
||||
} else {
|
||||
pred = (int) (((Q11<<7) - num) / (Q11<<8));
|
||||
if (Al > 0 && pred >= (1<<Al))
|
||||
pred = (1<<Al)-1;
|
||||
pred = -pred;
|
||||
}
|
||||
workspace[9] = (JCOEF) pred;
|
||||
}
|
||||
/* AC02 */
|
||||
if ((Al=coef_bits[5]) != 0 && workspace[2] == 0) {
|
||||
num = 9 * Q00 * (DC4 + DC6 - 2*DC5);
|
||||
if (num >= 0) {
|
||||
pred = (int) (((Q02<<7) + num) / (Q02<<8));
|
||||
if (Al > 0 && pred >= (1<<Al))
|
||||
pred = (1<<Al)-1;
|
||||
} else {
|
||||
pred = (int) (((Q02<<7) - num) / (Q02<<8));
|
||||
if (Al > 0 && pred >= (1<<Al))
|
||||
pred = (1<<Al)-1;
|
||||
pred = -pred;
|
||||
}
|
||||
workspace[2] = (JCOEF) pred;
|
||||
}
|
||||
/* OK, do the IDCT */
|
||||
(*inverse_DCT) (cinfo, compptr, (JCOEFPTR) workspace,
|
||||
output_ptr, output_col);
|
||||
/* Advance for next column */
|
||||
DC1 = DC2; DC2 = DC3;
|
||||
DC4 = DC5; DC5 = DC6;
|
||||
DC7 = DC8; DC8 = DC9;
|
||||
buffer_ptr++, prev_block_row++, next_block_row++;
|
||||
output_col += compptr->DCT_scaled_size;
|
||||
}
|
||||
output_ptr += compptr->DCT_scaled_size;
|
||||
output_ptr += compptr->DCT_v_scaled_size;
|
||||
}
|
||||
}
|
||||
|
||||
@ -679,7 +681,7 @@ jinit_d_coef_controller (j_decompress_ptr cinfo, boolean need_full_buffer)
|
||||
|
||||
coef = (my_coef_ptr)
|
||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
||||
SIZEOF(my_coef_controller));
|
||||
SIZEOF(my_coef_controller));
|
||||
cinfo->coef = (struct jpeg_d_coef_controller *) coef;
|
||||
coef->pub.start_input_pass = start_input_pass;
|
||||
coef->pub.start_output_pass = start_output_pass;
|
||||
@ -697,20 +699,20 @@ jinit_d_coef_controller (j_decompress_ptr cinfo, boolean need_full_buffer)
|
||||
jpeg_component_info *compptr;
|
||||
|
||||
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
|
||||
ci++, compptr++) {
|
||||
ci++, compptr++) {
|
||||
access_rows = compptr->v_samp_factor;
|
||||
#ifdef BLOCK_SMOOTHING_SUPPORTED
|
||||
/* If block smoothing could be used, need a bigger window */
|
||||
if (cinfo->progressive_mode)
|
||||
access_rows *= 3;
|
||||
access_rows *= 3;
|
||||
#endif
|
||||
coef->whole_image[ci] = (*cinfo->mem->request_virt_barray)
|
||||
((j_common_ptr) cinfo, JPOOL_IMAGE, TRUE,
|
||||
(JDIMENSION) jround_up((long) compptr->width_in_blocks,
|
||||
(long) compptr->h_samp_factor),
|
||||
(JDIMENSION) jround_up((long) compptr->height_in_blocks,
|
||||
(long) compptr->v_samp_factor),
|
||||
(JDIMENSION) access_rows);
|
||||
((j_common_ptr) cinfo, JPOOL_IMAGE, TRUE,
|
||||
(JDIMENSION) jround_up((long) compptr->width_in_blocks,
|
||||
(long) compptr->h_samp_factor),
|
||||
(JDIMENSION) jround_up((long) compptr->height_in_blocks,
|
||||
(long) compptr->v_samp_factor),
|
||||
(JDIMENSION) access_rows);
|
||||
}
|
||||
coef->pub.consume_data = consume_data;
|
||||
coef->pub.decompress_data = decompress_data;
|
||||
@ -725,10 +727,13 @@ jinit_d_coef_controller (j_decompress_ptr cinfo, boolean need_full_buffer)
|
||||
|
||||
buffer = (JBLOCKROW)
|
||||
(*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
||||
D_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK));
|
||||
D_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK));
|
||||
for (i = 0; i < D_MAX_BLOCKS_IN_MCU; 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.decompress_data = decompress_onepass;
|
||||
coef->pub.coef_arrays = NULL; /* flag for no virtual arrays */
|
||||
|
294
3rdparty/libjpeg/jdcolor.c
vendored
294
3rdparty/libjpeg/jdcolor.c
vendored
@ -2,6 +2,7 @@
|
||||
* jdcolor.c
|
||||
*
|
||||
* Copyright (C) 1991-1997, Thomas G. Lane.
|
||||
* Modified 2011-2012 by Guido Vollbeding.
|
||||
* This file is part of the Independent JPEG Group's software.
|
||||
* For conditions of distribution and use, see the accompanying README file.
|
||||
*
|
||||
@ -23,20 +24,28 @@ typedef struct {
|
||||
int * Cb_b_tab; /* => table for Cb to B conversion */
|
||||
INT32 * Cr_g_tab; /* => table for Cr to G conversion */
|
||||
INT32 * Cb_g_tab; /* => table for Cb to G conversion */
|
||||
|
||||
/* Private state for RGB->Y conversion */
|
||||
INT32 * rgb_y_tab; /* => table for RGB to Y conversion */
|
||||
} my_color_deconverter;
|
||||
|
||||
typedef my_color_deconverter * my_cconvert_ptr;
|
||||
|
||||
|
||||
/**************** YCbCr -> RGB conversion: most common case **************/
|
||||
/**************** RGB -> Y conversion: less common case **************/
|
||||
|
||||
/*
|
||||
* YCbCr is defined per CCIR 601-1, except that Cb and Cr are
|
||||
* normalized to the range 0..MAXJSAMPLE rather than -0.5 .. 0.5.
|
||||
* The conversion equations to be implemented are therefore
|
||||
*
|
||||
* R = Y + 1.40200 * Cr
|
||||
* G = Y - 0.34414 * Cb - 0.71414 * Cr
|
||||
* B = Y + 1.77200 * Cb
|
||||
*
|
||||
* Y = 0.29900 * R + 0.58700 * G + 0.11400 * B
|
||||
*
|
||||
* where Cb and Cr represent the incoming values less CENTERJSAMPLE.
|
||||
* (These numbers are derived from TIFF 6.0 section 21, dated 3-June-92.)
|
||||
*
|
||||
@ -61,6 +70,18 @@ typedef my_color_deconverter * my_cconvert_ptr;
|
||||
#define ONE_HALF ((INT32) 1 << (SCALEBITS-1))
|
||||
#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.
|
||||
@ -76,26 +97,26 @@ build_ycc_rgb_table (j_decompress_ptr cinfo)
|
||||
|
||||
cconvert->Cr_r_tab = (int *)
|
||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
||||
(MAXJSAMPLE+1) * SIZEOF(int));
|
||||
(MAXJSAMPLE+1) * SIZEOF(int));
|
||||
cconvert->Cb_b_tab = (int *)
|
||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
||||
(MAXJSAMPLE+1) * SIZEOF(int));
|
||||
(MAXJSAMPLE+1) * SIZEOF(int));
|
||||
cconvert->Cr_g_tab = (INT32 *)
|
||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
||||
(MAXJSAMPLE+1) * SIZEOF(INT32));
|
||||
(MAXJSAMPLE+1) * SIZEOF(INT32));
|
||||
cconvert->Cb_g_tab = (INT32 *)
|
||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
||||
(MAXJSAMPLE+1) * SIZEOF(INT32));
|
||||
(MAXJSAMPLE+1) * SIZEOF(INT32));
|
||||
|
||||
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 1.40200 * x */
|
||||
cconvert->Cr_r_tab[i] = (int)
|
||||
RIGHT_SHIFT(FIX(1.40200) * x + ONE_HALF, SCALEBITS);
|
||||
RIGHT_SHIFT(FIX(1.40200) * x + ONE_HALF, SCALEBITS);
|
||||
/* Cb=>B value is nearest int to 1.77200 * x */
|
||||
cconvert->Cb_b_tab[i] = (int)
|
||||
RIGHT_SHIFT(FIX(1.77200) * x + ONE_HALF, SCALEBITS);
|
||||
RIGHT_SHIFT(FIX(1.77200) * x + ONE_HALF, SCALEBITS);
|
||||
/* Cr=>G value is scaled-up -0.71414 * x */
|
||||
cconvert->Cr_g_tab[i] = (- FIX(0.71414)) * x;
|
||||
/* Cb=>G value is scaled-up -0.34414 * x */
|
||||
@ -118,8 +139,8 @@ build_ycc_rgb_table (j_decompress_ptr cinfo)
|
||||
|
||||
METHODDEF(void)
|
||||
ycc_rgb_convert (j_decompress_ptr cinfo,
|
||||
JSAMPIMAGE input_buf, JDIMENSION input_row,
|
||||
JSAMPARRAY output_buf, int num_rows)
|
||||
JSAMPIMAGE input_buf, JDIMENSION input_row,
|
||||
JSAMPARRAY output_buf, int num_rows)
|
||||
{
|
||||
my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
|
||||
register int y, cb, cr;
|
||||
@ -148,8 +169,8 @@ ycc_rgb_convert (j_decompress_ptr cinfo,
|
||||
/* Range-limiting is essential due to noise introduced by DCT losses. */
|
||||
outptr[RGB_RED] = range_limit[y + Crrtab[cr]];
|
||||
outptr[RGB_GREEN] = range_limit[y +
|
||||
((int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
|
||||
SCALEBITS))];
|
||||
((int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
|
||||
SCALEBITS))];
|
||||
outptr[RGB_BLUE] = range_limit[y + Cbbtab[cb]];
|
||||
outptr += RGB_PIXELSIZE;
|
||||
}
|
||||
@ -160,6 +181,178 @@ ycc_rgb_convert (j_decompress_ptr cinfo,
|
||||
/**************** Cases other than YCbCr -> 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.29900) * i;
|
||||
rgb_y_tab[i+G_Y_OFF] = FIX(0.58700) * i;
|
||||
rgb_y_tab[i+B_Y_OFF] = FIX(0.11400) * 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).
|
||||
*/
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Color conversion for no colorspace change: just copy the data,
|
||||
* converting from separate-planes to interleaved representation.
|
||||
@ -167,22 +360,23 @@ ycc_rgb_convert (j_decompress_ptr cinfo,
|
||||
|
||||
METHODDEF(void)
|
||||
null_convert (j_decompress_ptr cinfo,
|
||||
JSAMPIMAGE input_buf, JDIMENSION input_row,
|
||||
JSAMPARRAY output_buf, int num_rows)
|
||||
JSAMPIMAGE input_buf, JDIMENSION input_row,
|
||||
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;
|
||||
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) {
|
||||
for (ci = 0; ci < num_components; ci++) {
|
||||
for (ci = 0; ci < nc; ci++) {
|
||||
inptr = input_buf[ci][input_row];
|
||||
outptr = output_buf[0] + ci;
|
||||
for (count = num_cols; count > 0; count--) {
|
||||
*outptr = *inptr++; /* needn't bother with GETJSAMPLE() here */
|
||||
outptr += num_components;
|
||||
for (col = 0; col < num_cols; col++) {
|
||||
*outptr = *inptr++; /* needn't bother with GETJSAMPLE() here */
|
||||
outptr += nc;
|
||||
}
|
||||
}
|
||||
input_row++;
|
||||
@ -199,11 +393,11 @@ null_convert (j_decompress_ptr cinfo,
|
||||
|
||||
METHODDEF(void)
|
||||
grayscale_convert (j_decompress_ptr cinfo,
|
||||
JSAMPIMAGE input_buf, JDIMENSION input_row,
|
||||
JSAMPARRAY output_buf, int num_rows)
|
||||
JSAMPIMAGE input_buf, JDIMENSION input_row,
|
||||
JSAMPARRAY output_buf, int num_rows)
|
||||
{
|
||||
jcopy_sample_rows(input_buf[0], (int) input_row, output_buf, 0,
|
||||
num_rows, cinfo->output_width);
|
||||
num_rows, cinfo->output_width);
|
||||
}
|
||||
|
||||
|
||||
@ -215,10 +409,11 @@ grayscale_convert (j_decompress_ptr cinfo,
|
||||
|
||||
METHODDEF(void)
|
||||
gray_rgb_convert (j_decompress_ptr cinfo,
|
||||
JSAMPIMAGE input_buf, JDIMENSION input_row,
|
||||
JSAMPARRAY output_buf, int num_rows)
|
||||
JSAMPIMAGE input_buf, JDIMENSION input_row,
|
||||
JSAMPARRAY output_buf, int num_rows)
|
||||
{
|
||||
register JSAMPROW inptr, outptr;
|
||||
register JSAMPROW outptr;
|
||||
register JSAMPROW inptr;
|
||||
register JDIMENSION col;
|
||||
JDIMENSION num_cols = cinfo->output_width;
|
||||
|
||||
@ -243,8 +438,8 @@ gray_rgb_convert (j_decompress_ptr cinfo,
|
||||
|
||||
METHODDEF(void)
|
||||
ycck_cmyk_convert (j_decompress_ptr cinfo,
|
||||
JSAMPIMAGE input_buf, JDIMENSION input_row,
|
||||
JSAMPARRAY output_buf, int num_rows)
|
||||
JSAMPIMAGE input_buf, JDIMENSION input_row,
|
||||
JSAMPARRAY output_buf, int num_rows)
|
||||
{
|
||||
my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
|
||||
register int y, cb, cr;
|
||||
@ -274,8 +469,8 @@ ycck_cmyk_convert (j_decompress_ptr cinfo,
|
||||
/* Range-limiting is essential due to noise introduced by DCT losses. */
|
||||
outptr[0] = range_limit[MAXJSAMPLE - (y + Crrtab[cr])]; /* red */
|
||||
outptr[1] = range_limit[MAXJSAMPLE - (y + /* green */
|
||||
((int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
|
||||
SCALEBITS)))];
|
||||
((int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
|
||||
SCALEBITS)))];
|
||||
outptr[2] = range_limit[MAXJSAMPLE - (y + Cbbtab[cb])]; /* blue */
|
||||
/* K passes through unchanged */
|
||||
outptr[3] = inptr3[col]; /* don't need GETJSAMPLE here */
|
||||
@ -308,8 +503,8 @@ jinit_color_deconverter (j_decompress_ptr cinfo)
|
||||
|
||||
cconvert = (my_cconvert_ptr)
|
||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
||||
SIZEOF(my_color_deconverter));
|
||||
cinfo->cconvert = (struct jpeg_color_deconverter *) cconvert;
|
||||
SIZEOF(my_color_deconverter));
|
||||
cinfo->cconvert = &cconvert->pub;
|
||||
cconvert->pub.start_pass = start_pass_dcolor;
|
||||
|
||||
/* Make sure num_components agrees with jpeg_color_space */
|
||||
@ -337,6 +532,10 @@ jinit_color_deconverter (j_decompress_ptr cinfo)
|
||||
break;
|
||||
}
|
||||
|
||||
/* Support color transform only for RGB colorspace */
|
||||
if (cinfo->color_transform && cinfo->jpeg_color_space != JCS_RGB)
|
||||
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
|
||||
|
||||
/* Set out_color_components and conversion method based on requested space.
|
||||
* Also clear the component_needed flags for any unused components,
|
||||
* so that earlier pipeline stages can avoid useless computation.
|
||||
@ -346,11 +545,24 @@ jinit_color_deconverter (j_decompress_ptr cinfo)
|
||||
case JCS_GRAYSCALE:
|
||||
cinfo->out_color_components = 1;
|
||||
if (cinfo->jpeg_color_space == JCS_GRAYSCALE ||
|
||||
cinfo->jpeg_color_space == JCS_YCbCr) {
|
||||
cinfo->jpeg_color_space == JCS_YCbCr) {
|
||||
cconvert->pub.color_convert = grayscale_convert;
|
||||
/* For color->grayscale conversion, only the Y (0) component is needed */
|
||||
for (ci = 1; ci < cinfo->num_components; ci++)
|
||||
cinfo->comp_info[ci].component_needed = FALSE;
|
||||
cinfo->comp_info[ci].component_needed = FALSE;
|
||||
} else if (cinfo->jpeg_color_space == 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);
|
||||
break;
|
||||
}
|
||||
build_rgb_y_table(cinfo);
|
||||
} else
|
||||
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
|
||||
break;
|
||||
@ -362,8 +574,18 @@ jinit_color_deconverter (j_decompress_ptr cinfo)
|
||||
build_ycc_rgb_table(cinfo);
|
||||
} else if (cinfo->jpeg_color_space == JCS_GRAYSCALE) {
|
||||
cconvert->pub.color_convert = gray_rgb_convert;
|
||||
} else if (cinfo->jpeg_color_space == JCS_RGB && RGB_PIXELSIZE == 3) {
|
||||
cconvert->pub.color_convert = null_convert;
|
||||
} else if (cinfo->jpeg_color_space == 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;
|
||||
}
|
||||
} else
|
||||
ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
|
||||
break;
|
||||
|
251
3rdparty/libjpeg/jdct.h
vendored
251
3rdparty/libjpeg/jdct.h
vendored
@ -14,11 +14,16 @@
|
||||
|
||||
|
||||
/*
|
||||
* A forward DCT routine is given a pointer to a work area of type DCTELEM[];
|
||||
* the DCT is to be performed in-place in that buffer. Type DCTELEM is int
|
||||
* for 8-bit samples, INT32 for 12-bit samples. (NOTE: Floating-point DCT
|
||||
* implementations use an array of type FAST_FLOAT, instead.)
|
||||
* The DCT inputs are expected to be signed (range +-CENTERJSAMPLE).
|
||||
* A forward DCT routine is given a pointer to an input sample array and
|
||||
* a pointer to a work area of type DCTELEM[]; the DCT is to be performed
|
||||
* in-place in that buffer. Type DCTELEM is int for 8-bit samples, INT32
|
||||
* for 12-bit samples. (NOTE: Floating-point DCT implementations use an
|
||||
* array of type FAST_FLOAT, instead.)
|
||||
* The input data is to be fetched from the sample array starting at a
|
||||
* specified column. (Any row offset needed will be applied to the array
|
||||
* pointer before it is passed to the FDCT code.)
|
||||
* Note that the number of samples fetched by the FDCT routine is
|
||||
* DCT_h_scaled_size * DCT_v_scaled_size.
|
||||
* The DCT outputs are returned scaled up by a factor of 8; they therefore
|
||||
* have a range of +-8K for 8-bit data, +-128K for 12-bit data. This
|
||||
* convention improves accuracy in integer implementations and saves some
|
||||
@ -32,8 +37,12 @@ typedef int DCTELEM; /* 16 or 32 bits is fine */
|
||||
typedef INT32 DCTELEM; /* must have 32 bits */
|
||||
#endif
|
||||
|
||||
typedef JMETHOD(void, forward_DCT_method_ptr, (DCTELEM * data));
|
||||
typedef JMETHOD(void, float_DCT_method_ptr, (FAST_FLOAT * data));
|
||||
typedef JMETHOD(void, forward_DCT_method_ptr, (DCTELEM * data,
|
||||
JSAMPARRAY sample_data,
|
||||
JDIMENSION start_col));
|
||||
typedef JMETHOD(void, float_DCT_method_ptr, (FAST_FLOAT * data,
|
||||
JSAMPARRAY sample_data,
|
||||
JDIMENSION start_col));
|
||||
|
||||
|
||||
/*
|
||||
@ -44,7 +53,7 @@ typedef JMETHOD(void, float_DCT_method_ptr, (FAST_FLOAT * data));
|
||||
* sample array starting at a specified column. (Any row offset needed will
|
||||
* be applied to the array pointer before it is passed to the IDCT code.)
|
||||
* Note that the number of samples emitted by the IDCT routine is
|
||||
* DCT_scaled_size * DCT_scaled_size.
|
||||
* DCT_h_scaled_size * DCT_v_scaled_size.
|
||||
*/
|
||||
|
||||
/* typedef inverse_DCT_method_ptr is declared in jpegint.h */
|
||||
@ -84,38 +93,246 @@ typedef FAST_FLOAT FLOAT_MULT_TYPE; /* preferred floating type */
|
||||
#define jpeg_fdct_islow jFDislow
|
||||
#define jpeg_fdct_ifast jFDifast
|
||||
#define jpeg_fdct_float jFDfloat
|
||||
#define jpeg_fdct_7x7 jFD7x7
|
||||
#define jpeg_fdct_6x6 jFD6x6
|
||||
#define jpeg_fdct_5x5 jFD5x5
|
||||
#define jpeg_fdct_4x4 jFD4x4
|
||||
#define jpeg_fdct_3x3 jFD3x3
|
||||
#define jpeg_fdct_2x2 jFD2x2
|
||||
#define jpeg_fdct_1x1 jFD1x1
|
||||
#define jpeg_fdct_9x9 jFD9x9
|
||||
#define jpeg_fdct_10x10 jFD10x10
|
||||
#define jpeg_fdct_11x11 jFD11x11
|
||||
#define jpeg_fdct_12x12 jFD12x12
|
||||
#define jpeg_fdct_13x13 jFD13x13
|
||||
#define jpeg_fdct_14x14 jFD14x14
|
||||
#define jpeg_fdct_15x15 jFD15x15
|
||||
#define jpeg_fdct_16x16 jFD16x16
|
||||
#define jpeg_fdct_16x8 jFD16x8
|
||||
#define jpeg_fdct_14x7 jFD14x7
|
||||
#define jpeg_fdct_12x6 jFD12x6
|
||||
#define jpeg_fdct_10x5 jFD10x5
|
||||
#define jpeg_fdct_8x4 jFD8x4
|
||||
#define jpeg_fdct_6x3 jFD6x3
|
||||
#define jpeg_fdct_4x2 jFD4x2
|
||||
#define jpeg_fdct_2x1 jFD2x1
|
||||
#define jpeg_fdct_8x16 jFD8x16
|
||||
#define jpeg_fdct_7x14 jFD7x14
|
||||
#define jpeg_fdct_6x12 jFD6x12
|
||||
#define jpeg_fdct_5x10 jFD5x10
|
||||
#define jpeg_fdct_4x8 jFD4x8
|
||||
#define jpeg_fdct_3x6 jFD3x6
|
||||
#define jpeg_fdct_2x4 jFD2x4
|
||||
#define jpeg_fdct_1x2 jFD1x2
|
||||
#define jpeg_idct_islow jRDislow
|
||||
#define jpeg_idct_ifast jRDifast
|
||||
#define jpeg_idct_float jRDfloat
|
||||
#define jpeg_idct_7x7 jRD7x7
|
||||
#define jpeg_idct_6x6 jRD6x6
|
||||
#define jpeg_idct_5x5 jRD5x5
|
||||
#define jpeg_idct_4x4 jRD4x4
|
||||
#define jpeg_idct_3x3 jRD3x3
|
||||
#define jpeg_idct_2x2 jRD2x2
|
||||
#define jpeg_idct_1x1 jRD1x1
|
||||
#define jpeg_idct_9x9 jRD9x9
|
||||
#define jpeg_idct_10x10 jRD10x10
|
||||
#define jpeg_idct_11x11 jRD11x11
|
||||
#define jpeg_idct_12x12 jRD12x12
|
||||
#define jpeg_idct_13x13 jRD13x13
|
||||
#define jpeg_idct_14x14 jRD14x14
|
||||
#define jpeg_idct_15x15 jRD15x15
|
||||
#define jpeg_idct_16x16 jRD16x16
|
||||
#define jpeg_idct_16x8 jRD16x8
|
||||
#define jpeg_idct_14x7 jRD14x7
|
||||
#define jpeg_idct_12x6 jRD12x6
|
||||
#define jpeg_idct_10x5 jRD10x5
|
||||
#define jpeg_idct_8x4 jRD8x4
|
||||
#define jpeg_idct_6x3 jRD6x3
|
||||
#define jpeg_idct_4x2 jRD4x2
|
||||
#define jpeg_idct_2x1 jRD2x1
|
||||
#define jpeg_idct_8x16 jRD8x16
|
||||
#define jpeg_idct_7x14 jRD7x14
|
||||
#define jpeg_idct_6x12 jRD6x12
|
||||
#define jpeg_idct_5x10 jRD5x10
|
||||
#define jpeg_idct_4x8 jRD4x8
|
||||
#define jpeg_idct_3x6 jRD3x8
|
||||
#define jpeg_idct_2x4 jRD2x4
|
||||
#define jpeg_idct_1x2 jRD1x2
|
||||
#endif /* NEED_SHORT_EXTERNAL_NAMES */
|
||||
|
||||
/* Extern declarations for the forward and inverse DCT routines. */
|
||||
|
||||
EXTERN(void) jpeg_fdct_islow JPP((DCTELEM * data));
|
||||
EXTERN(void) jpeg_fdct_ifast JPP((DCTELEM * data));
|
||||
EXTERN(void) jpeg_fdct_float JPP((FAST_FLOAT * data));
|
||||
EXTERN(void) jpeg_fdct_islow
|
||||
JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));
|
||||
EXTERN(void) jpeg_fdct_ifast
|
||||
JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));
|
||||
EXTERN(void) jpeg_fdct_float
|
||||
JPP((FAST_FLOAT * data, JSAMPARRAY sample_data, JDIMENSION start_col));
|
||||
EXTERN(void) jpeg_fdct_7x7
|
||||
JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));
|
||||
EXTERN(void) jpeg_fdct_6x6
|
||||
JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));
|
||||
EXTERN(void) jpeg_fdct_5x5
|
||||
JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));
|
||||
EXTERN(void) jpeg_fdct_4x4
|
||||
JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));
|
||||
EXTERN(void) jpeg_fdct_3x3
|
||||
JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));
|
||||
EXTERN(void) jpeg_fdct_2x2
|
||||
JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));
|
||||
EXTERN(void) jpeg_fdct_1x1
|
||||
JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));
|
||||
EXTERN(void) jpeg_fdct_9x9
|
||||
JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));
|
||||
EXTERN(void) jpeg_fdct_10x10
|
||||
JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));
|
||||
EXTERN(void) jpeg_fdct_11x11
|
||||
JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));
|
||||
EXTERN(void) jpeg_fdct_12x12
|
||||
JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));
|
||||
EXTERN(void) jpeg_fdct_13x13
|
||||
JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));
|
||||
EXTERN(void) jpeg_fdct_14x14
|
||||
JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));
|
||||
EXTERN(void) jpeg_fdct_15x15
|
||||
JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));
|
||||
EXTERN(void) jpeg_fdct_16x16
|
||||
JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));
|
||||
EXTERN(void) jpeg_fdct_16x8
|
||||
JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));
|
||||
EXTERN(void) jpeg_fdct_14x7
|
||||
JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));
|
||||
EXTERN(void) jpeg_fdct_12x6
|
||||
JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));
|
||||
EXTERN(void) jpeg_fdct_10x5
|
||||
JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));
|
||||
EXTERN(void) jpeg_fdct_8x4
|
||||
JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));
|
||||
EXTERN(void) jpeg_fdct_6x3
|
||||
JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));
|
||||
EXTERN(void) jpeg_fdct_4x2
|
||||
JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));
|
||||
EXTERN(void) jpeg_fdct_2x1
|
||||
JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));
|
||||
EXTERN(void) jpeg_fdct_8x16
|
||||
JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));
|
||||
EXTERN(void) jpeg_fdct_7x14
|
||||
JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));
|
||||
EXTERN(void) jpeg_fdct_6x12
|
||||
JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));
|
||||
EXTERN(void) jpeg_fdct_5x10
|
||||
JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));
|
||||
EXTERN(void) jpeg_fdct_4x8
|
||||
JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));
|
||||
EXTERN(void) jpeg_fdct_3x6
|
||||
JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));
|
||||
EXTERN(void) jpeg_fdct_2x4
|
||||
JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));
|
||||
EXTERN(void) jpeg_fdct_1x2
|
||||
JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));
|
||||
|
||||
EXTERN(void) jpeg_idct_islow
|
||||
JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
||||
JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
|
||||
JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
|
||||
EXTERN(void) jpeg_idct_ifast
|
||||
JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
||||
JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
|
||||
JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
|
||||
EXTERN(void) jpeg_idct_float
|
||||
JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
||||
JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
|
||||
JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
|
||||
EXTERN(void) jpeg_idct_7x7
|
||||
JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
||||
JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
|
||||
EXTERN(void) jpeg_idct_6x6
|
||||
JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
||||
JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
|
||||
EXTERN(void) jpeg_idct_5x5
|
||||
JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
||||
JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
|
||||
EXTERN(void) jpeg_idct_4x4
|
||||
JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
||||
JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
|
||||
JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
|
||||
EXTERN(void) jpeg_idct_3x3
|
||||
JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
||||
JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
|
||||
EXTERN(void) jpeg_idct_2x2
|
||||
JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
||||
JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
|
||||
JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
|
||||
EXTERN(void) jpeg_idct_1x1
|
||||
JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
||||
JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
|
||||
JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
|
||||
EXTERN(void) jpeg_idct_9x9
|
||||
JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
||||
JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
|
||||
EXTERN(void) jpeg_idct_10x10
|
||||
JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
||||
JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
|
||||
EXTERN(void) jpeg_idct_11x11
|
||||
JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
||||
JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
|
||||
EXTERN(void) jpeg_idct_12x12
|
||||
JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
||||
JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
|
||||
EXTERN(void) jpeg_idct_13x13
|
||||
JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
||||
JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
|
||||
EXTERN(void) jpeg_idct_14x14
|
||||
JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
||||
JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
|
||||
EXTERN(void) jpeg_idct_15x15
|
||||
JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
||||
JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
|
||||
EXTERN(void) jpeg_idct_16x16
|
||||
JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
||||
JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
|
||||
EXTERN(void) jpeg_idct_16x8
|
||||
JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
||||
JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
|
||||
EXTERN(void) jpeg_idct_14x7
|
||||
JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
||||
JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
|
||||
EXTERN(void) jpeg_idct_12x6
|
||||
JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
||||
JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
|
||||
EXTERN(void) jpeg_idct_10x5
|
||||
JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
||||
JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
|
||||
EXTERN(void) jpeg_idct_8x4
|
||||
JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
||||
JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
|
||||
EXTERN(void) jpeg_idct_6x3
|
||||
JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
||||
JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
|
||||
EXTERN(void) jpeg_idct_4x2
|
||||
JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
||||
JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
|
||||
EXTERN(void) jpeg_idct_2x1
|
||||
JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
||||
JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
|
||||
EXTERN(void) jpeg_idct_8x16
|
||||
JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
||||
JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
|
||||
EXTERN(void) jpeg_idct_7x14
|
||||
JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
||||
JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
|
||||
EXTERN(void) jpeg_idct_6x12
|
||||
JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
||||
JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
|
||||
EXTERN(void) jpeg_idct_5x10
|
||||
JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
||||
JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
|
||||
EXTERN(void) jpeg_idct_4x8
|
||||
JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
||||
JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
|
||||
EXTERN(void) jpeg_idct_3x6
|
||||
JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
||||
JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
|
||||
EXTERN(void) jpeg_idct_2x4
|
||||
JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
||||
JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
|
||||
EXTERN(void) jpeg_idct_1x2
|
||||
JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
||||
JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
|
||||
|
||||
|
||||
/*
|
||||
|
265
3rdparty/libjpeg/jddctmgr.c
vendored
265
3rdparty/libjpeg/jddctmgr.c
vendored
@ -2,6 +2,7 @@
|
||||
* jddctmgr.c
|
||||
*
|
||||
* Copyright (C) 1994-1996, Thomas G. Lane.
|
||||
* Modified 2002-2010 by Guido Vollbeding.
|
||||
* This file is part of the Independent JPEG Group's software.
|
||||
* For conditions of distribution and use, see the accompanying README file.
|
||||
*
|
||||
@ -98,48 +99,161 @@ start_pass (j_decompress_ptr cinfo)
|
||||
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
|
||||
ci++, compptr++) {
|
||||
/* Select the proper IDCT routine for this component's scaling */
|
||||
switch (compptr->DCT_scaled_size) {
|
||||
switch ((compptr->DCT_h_scaled_size << 8) + compptr->DCT_v_scaled_size) {
|
||||
#ifdef IDCT_SCALING_SUPPORTED
|
||||
case 1:
|
||||
case ((1 << 8) + 1):
|
||||
method_ptr = jpeg_idct_1x1;
|
||||
method = JDCT_ISLOW; /* jidctred uses islow-style table */
|
||||
method = JDCT_ISLOW; /* jidctint uses islow-style table */
|
||||
break;
|
||||
case 2:
|
||||
case ((2 << 8) + 2):
|
||||
method_ptr = jpeg_idct_2x2;
|
||||
method = JDCT_ISLOW; /* jidctred uses islow-style table */
|
||||
method = JDCT_ISLOW; /* jidctint uses islow-style table */
|
||||
break;
|
||||
case 4:
|
||||
case ((3 << 8) + 3):
|
||||
method_ptr = jpeg_idct_3x3;
|
||||
method = JDCT_ISLOW; /* jidctint uses islow-style table */
|
||||
break;
|
||||
case ((4 << 8) + 4):
|
||||
method_ptr = jpeg_idct_4x4;
|
||||
method = JDCT_ISLOW; /* jidctred uses islow-style table */
|
||||
method = JDCT_ISLOW; /* jidctint uses islow-style table */
|
||||
break;
|
||||
case ((5 << 8) + 5):
|
||||
method_ptr = jpeg_idct_5x5;
|
||||
method = JDCT_ISLOW; /* jidctint uses islow-style table */
|
||||
break;
|
||||
case ((6 << 8) + 6):
|
||||
method_ptr = jpeg_idct_6x6;
|
||||
method = JDCT_ISLOW; /* jidctint uses islow-style table */
|
||||
break;
|
||||
case ((7 << 8) + 7):
|
||||
method_ptr = jpeg_idct_7x7;
|
||||
method = JDCT_ISLOW; /* jidctint uses islow-style table */
|
||||
break;
|
||||
case ((9 << 8) + 9):
|
||||
method_ptr = jpeg_idct_9x9;
|
||||
method = JDCT_ISLOW; /* jidctint uses islow-style table */
|
||||
break;
|
||||
case ((10 << 8) + 10):
|
||||
method_ptr = jpeg_idct_10x10;
|
||||
method = JDCT_ISLOW; /* jidctint uses islow-style table */
|
||||
break;
|
||||
case ((11 << 8) + 11):
|
||||
method_ptr = jpeg_idct_11x11;
|
||||
method = JDCT_ISLOW; /* jidctint uses islow-style table */
|
||||
break;
|
||||
case ((12 << 8) + 12):
|
||||
method_ptr = jpeg_idct_12x12;
|
||||
method = JDCT_ISLOW; /* jidctint uses islow-style table */
|
||||
break;
|
||||
case ((13 << 8) + 13):
|
||||
method_ptr = jpeg_idct_13x13;
|
||||
method = JDCT_ISLOW; /* jidctint uses islow-style table */
|
||||
break;
|
||||
case ((14 << 8) + 14):
|
||||
method_ptr = jpeg_idct_14x14;
|
||||
method = JDCT_ISLOW; /* jidctint uses islow-style table */
|
||||
break;
|
||||
case ((15 << 8) + 15):
|
||||
method_ptr = jpeg_idct_15x15;
|
||||
method = JDCT_ISLOW; /* jidctint uses islow-style table */
|
||||
break;
|
||||
case ((16 << 8) + 16):
|
||||
method_ptr = jpeg_idct_16x16;
|
||||
method = JDCT_ISLOW; /* jidctint uses islow-style table */
|
||||
break;
|
||||
case ((16 << 8) + 8):
|
||||
method_ptr = jpeg_idct_16x8;
|
||||
method = JDCT_ISLOW; /* jidctint uses islow-style table */
|
||||
break;
|
||||
case ((14 << 8) + 7):
|
||||
method_ptr = jpeg_idct_14x7;
|
||||
method = JDCT_ISLOW; /* jidctint uses islow-style table */
|
||||
break;
|
||||
case ((12 << 8) + 6):
|
||||
method_ptr = jpeg_idct_12x6;
|
||||
method = JDCT_ISLOW; /* jidctint uses islow-style table */
|
||||
break;
|
||||
case ((10 << 8) + 5):
|
||||
method_ptr = jpeg_idct_10x5;
|
||||
method = JDCT_ISLOW; /* jidctint uses islow-style table */
|
||||
break;
|
||||
case ((8 << 8) + 4):
|
||||
method_ptr = jpeg_idct_8x4;
|
||||
method = JDCT_ISLOW; /* jidctint uses islow-style table */
|
||||
break;
|
||||
case ((6 << 8) + 3):
|
||||
method_ptr = jpeg_idct_6x3;
|
||||
method = JDCT_ISLOW; /* jidctint uses islow-style table */
|
||||
break;
|
||||
case ((4 << 8) + 2):
|
||||
method_ptr = jpeg_idct_4x2;
|
||||
method = JDCT_ISLOW; /* jidctint uses islow-style table */
|
||||
break;
|
||||
case ((2 << 8) + 1):
|
||||
method_ptr = jpeg_idct_2x1;
|
||||
method = JDCT_ISLOW; /* jidctint uses islow-style table */
|
||||
break;
|
||||
case ((8 << 8) + 16):
|
||||
method_ptr = jpeg_idct_8x16;
|
||||
method = JDCT_ISLOW; /* jidctint uses islow-style table */
|
||||
break;
|
||||
case ((7 << 8) + 14):
|
||||
method_ptr = jpeg_idct_7x14;
|
||||
method = JDCT_ISLOW; /* jidctint uses islow-style table */
|
||||
break;
|
||||
case ((6 << 8) + 12):
|
||||
method_ptr = jpeg_idct_6x12;
|
||||
method = JDCT_ISLOW; /* jidctint uses islow-style table */
|
||||
break;
|
||||
case ((5 << 8) + 10):
|
||||
method_ptr = jpeg_idct_5x10;
|
||||
method = JDCT_ISLOW; /* jidctint uses islow-style table */
|
||||
break;
|
||||
case ((4 << 8) + 8):
|
||||
method_ptr = jpeg_idct_4x8;
|
||||
method = JDCT_ISLOW; /* jidctint uses islow-style table */
|
||||
break;
|
||||
case ((3 << 8) + 6):
|
||||
method_ptr = jpeg_idct_3x6;
|
||||
method = JDCT_ISLOW; /* jidctint uses islow-style table */
|
||||
break;
|
||||
case ((2 << 8) + 4):
|
||||
method_ptr = jpeg_idct_2x4;
|
||||
method = JDCT_ISLOW; /* jidctint uses islow-style table */
|
||||
break;
|
||||
case ((1 << 8) + 2):
|
||||
method_ptr = jpeg_idct_1x2;
|
||||
method = JDCT_ISLOW; /* jidctint uses islow-style table */
|
||||
break;
|
||||
#endif
|
||||
case DCTSIZE:
|
||||
case ((DCTSIZE << 8) + DCTSIZE):
|
||||
switch (cinfo->dct_method) {
|
||||
#ifdef DCT_ISLOW_SUPPORTED
|
||||
case JDCT_ISLOW:
|
||||
method_ptr = jpeg_idct_islow;
|
||||
method = JDCT_ISLOW;
|
||||
break;
|
||||
method_ptr = jpeg_idct_islow;
|
||||
method = JDCT_ISLOW;
|
||||
break;
|
||||
#endif
|
||||
#ifdef DCT_IFAST_SUPPORTED
|
||||
case JDCT_IFAST:
|
||||
method_ptr = jpeg_idct_ifast;
|
||||
method = JDCT_IFAST;
|
||||
break;
|
||||
method_ptr = jpeg_idct_ifast;
|
||||
method = JDCT_IFAST;
|
||||
break;
|
||||
#endif
|
||||
#ifdef DCT_FLOAT_SUPPORTED
|
||||
case JDCT_FLOAT:
|
||||
method_ptr = jpeg_idct_float;
|
||||
method = JDCT_FLOAT;
|
||||
break;
|
||||
method_ptr = jpeg_idct_float;
|
||||
method = JDCT_FLOAT;
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
ERREXIT(cinfo, JERR_NOT_COMPILED);
|
||||
break;
|
||||
ERREXIT(cinfo, JERR_NOT_COMPILED);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
ERREXIT1(cinfo, JERR_BAD_DCTSIZE, compptr->DCT_scaled_size);
|
||||
ERREXIT2(cinfo, JERR_BAD_DCTSIZE,
|
||||
compptr->DCT_h_scaled_size, compptr->DCT_v_scaled_size);
|
||||
break;
|
||||
}
|
||||
idct->pub.inverse_DCT[ci] = method_ptr;
|
||||
@ -160,74 +274,75 @@ start_pass (j_decompress_ptr cinfo)
|
||||
#ifdef PROVIDE_ISLOW_TABLES
|
||||
case JDCT_ISLOW:
|
||||
{
|
||||
/* For LL&M IDCT method, multipliers are equal to raw quantization
|
||||
* coefficients, but are stored as ints to ensure access efficiency.
|
||||
*/
|
||||
ISLOW_MULT_TYPE * ismtbl = (ISLOW_MULT_TYPE *) compptr->dct_table;
|
||||
for (i = 0; i < DCTSIZE2; i++) {
|
||||
ismtbl[i] = (ISLOW_MULT_TYPE) qtbl->quantval[i];
|
||||
}
|
||||
/* For LL&M IDCT method, multipliers are equal to raw quantization
|
||||
* coefficients, but are stored as ints to ensure access efficiency.
|
||||
*/
|
||||
ISLOW_MULT_TYPE * ismtbl = (ISLOW_MULT_TYPE *) compptr->dct_table;
|
||||
for (i = 0; i < DCTSIZE2; i++) {
|
||||
ismtbl[i] = (ISLOW_MULT_TYPE) qtbl->quantval[i];
|
||||
}
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
#ifdef DCT_IFAST_SUPPORTED
|
||||
case JDCT_IFAST:
|
||||
{
|
||||
/* For AA&N IDCT method, multipliers are equal to quantization
|
||||
* coefficients scaled by scalefactor[row]*scalefactor[col], where
|
||||
* scalefactor[0] = 1
|
||||
* scalefactor[k] = cos(k*PI/16) * sqrt(2) for k=1..7
|
||||
* For integer operation, the multiplier table is to be scaled by
|
||||
* IFAST_SCALE_BITS.
|
||||
*/
|
||||
IFAST_MULT_TYPE * ifmtbl = (IFAST_MULT_TYPE *) compptr->dct_table;
|
||||
/* For AA&N IDCT method, multipliers are equal to quantization
|
||||
* coefficients scaled by scalefactor[row]*scalefactor[col], where
|
||||
* scalefactor[0] = 1
|
||||
* scalefactor[k] = cos(k*PI/16) * sqrt(2) for k=1..7
|
||||
* For integer operation, the multiplier table is to be scaled by
|
||||
* IFAST_SCALE_BITS.
|
||||
*/
|
||||
IFAST_MULT_TYPE * ifmtbl = (IFAST_MULT_TYPE *) compptr->dct_table;
|
||||
#define CONST_BITS 14
|
||||
static const INT16 aanscales[DCTSIZE2] = {
|
||||
/* precomputed values scaled up by 14 bits */
|
||||
16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
|
||||
22725, 31521, 29692, 26722, 22725, 17855, 12299, 6270,
|
||||
21407, 29692, 27969, 25172, 21407, 16819, 11585, 5906,
|
||||
19266, 26722, 25172, 22654, 19266, 15137, 10426, 5315,
|
||||
16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
|
||||
12873, 17855, 16819, 15137, 12873, 10114, 6967, 3552,
|
||||
8867, 12299, 11585, 10426, 8867, 6967, 4799, 2446,
|
||||
4520, 6270, 5906, 5315, 4520, 3552, 2446, 1247
|
||||
};
|
||||
SHIFT_TEMPS
|
||||
static const INT16 aanscales[DCTSIZE2] = {
|
||||
/* precomputed values scaled up by 14 bits */
|
||||
16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
|
||||
22725, 31521, 29692, 26722, 22725, 17855, 12299, 6270,
|
||||
21407, 29692, 27969, 25172, 21407, 16819, 11585, 5906,
|
||||
19266, 26722, 25172, 22654, 19266, 15137, 10426, 5315,
|
||||
16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
|
||||
12873, 17855, 16819, 15137, 12873, 10114, 6967, 3552,
|
||||
8867, 12299, 11585, 10426, 8867, 6967, 4799, 2446,
|
||||
4520, 6270, 5906, 5315, 4520, 3552, 2446, 1247
|
||||
};
|
||||
SHIFT_TEMPS
|
||||
|
||||
for (i = 0; i < DCTSIZE2; i++) {
|
||||
ifmtbl[i] = (IFAST_MULT_TYPE)
|
||||
DESCALE(MULTIPLY16V16((INT32) qtbl->quantval[i],
|
||||
(INT32) aanscales[i]),
|
||||
CONST_BITS-IFAST_SCALE_BITS);
|
||||
}
|
||||
for (i = 0; i < DCTSIZE2; i++) {
|
||||
ifmtbl[i] = (IFAST_MULT_TYPE)
|
||||
DESCALE(MULTIPLY16V16((INT32) qtbl->quantval[i],
|
||||
(INT32) aanscales[i]),
|
||||
CONST_BITS-IFAST_SCALE_BITS);
|
||||
}
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
#ifdef DCT_FLOAT_SUPPORTED
|
||||
case JDCT_FLOAT:
|
||||
{
|
||||
/* For float AA&N IDCT method, multipliers are equal to quantization
|
||||
* coefficients scaled by scalefactor[row]*scalefactor[col], where
|
||||
* scalefactor[0] = 1
|
||||
* scalefactor[k] = cos(k*PI/16) * sqrt(2) for k=1..7
|
||||
*/
|
||||
FLOAT_MULT_TYPE * fmtbl = (FLOAT_MULT_TYPE *) compptr->dct_table;
|
||||
int row, col;
|
||||
static const double aanscalefactor[DCTSIZE] = {
|
||||
1.0, 1.387039845, 1.306562965, 1.175875602,
|
||||
1.0, 0.785694958, 0.541196100, 0.275899379
|
||||
};
|
||||
/* For float AA&N IDCT method, multipliers are equal to quantization
|
||||
* coefficients scaled by scalefactor[row]*scalefactor[col], where
|
||||
* scalefactor[0] = 1
|
||||
* scalefactor[k] = cos(k*PI/16) * sqrt(2) for k=1..7
|
||||
* We apply a further scale factor of 1/8.
|
||||
*/
|
||||
FLOAT_MULT_TYPE * fmtbl = (FLOAT_MULT_TYPE *) compptr->dct_table;
|
||||
int row, col;
|
||||
static const double aanscalefactor[DCTSIZE] = {
|
||||
1.0, 1.387039845, 1.306562965, 1.175875602,
|
||||
1.0, 0.785694958, 0.541196100, 0.275899379
|
||||
};
|
||||
|
||||
i = 0;
|
||||
for (row = 0; row < DCTSIZE; row++) {
|
||||
for (col = 0; col < DCTSIZE; col++) {
|
||||
fmtbl[i] = (FLOAT_MULT_TYPE)
|
||||
((double) qtbl->quantval[i] *
|
||||
aanscalefactor[row] * aanscalefactor[col]);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
i = 0;
|
||||
for (row = 0; row < DCTSIZE; row++) {
|
||||
for (col = 0; col < DCTSIZE; col++) {
|
||||
fmtbl[i] = (FLOAT_MULT_TYPE)
|
||||
((double) qtbl->quantval[i] *
|
||||
aanscalefactor[row] * aanscalefactor[col] * 0.125);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
@ -252,7 +367,7 @@ jinit_inverse_dct (j_decompress_ptr cinfo)
|
||||
|
||||
idct = (my_idct_ptr)
|
||||
(*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;
|
||||
idct->pub.start_pass = start_pass;
|
||||
|
||||
@ -261,7 +376,7 @@ jinit_inverse_dct (j_decompress_ptr cinfo)
|
||||
/* Allocate and pre-zero a multiplier table for each component */
|
||||
compptr->dct_table =
|
||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
||||
SIZEOF(multiplier_table));
|
||||
SIZEOF(multiplier_table));
|
||||
MEMZERO(compptr->dct_table, SIZEOF(multiplier_table));
|
||||
/* Mark multiplier table not yet set up for any method */
|
||||
idct->cur_method[ci] = -1;
|
||||
|
1331
3rdparty/libjpeg/jdhuff.c
vendored
1331
3rdparty/libjpeg/jdhuff.c
vendored
File diff suppressed because it is too large
Load Diff
201
3rdparty/libjpeg/jdhuff.h
vendored
201
3rdparty/libjpeg/jdhuff.h
vendored
@ -1,201 +0,0 @@
|
||||
/*
|
||||
* jdhuff.h
|
||||
*
|
||||
* Copyright (C) 1991-1997, Thomas G. Lane.
|
||||
* This file is part of the Independent JPEG Group's software.
|
||||
* For conditions of distribution and use, see the accompanying README file.
|
||||
*
|
||||
* This file contains declarations for Huffman entropy decoding routines
|
||||
* that are shared between the sequential decoder (jdhuff.c) and the
|
||||
* progressive decoder (jdphuff.c). No other modules need to see these.
|
||||
*/
|
||||
|
||||
/* Short forms of external names for systems with brain-damaged linkers. */
|
||||
|
||||
#ifdef NEED_SHORT_EXTERNAL_NAMES
|
||||
#define jpeg_make_d_derived_tbl jMkDDerived
|
||||
#define jpeg_fill_bit_buffer jFilBitBuf
|
||||
#define jpeg_huff_decode jHufDecode
|
||||
#endif /* NEED_SHORT_EXTERNAL_NAMES */
|
||||
|
||||
|
||||
/* Derived data constructed for each Huffman table */
|
||||
|
||||
#define HUFF_LOOKAHEAD 8 /* # of bits of lookahead */
|
||||
|
||||
typedef struct {
|
||||
/* Basic tables: (element [0] of each array is unused) */
|
||||
INT32 maxcode[18]; /* largest code of length k (-1 if none) */
|
||||
/* (maxcode[17] is a sentinel to ensure jpeg_huff_decode terminates) */
|
||||
INT32 valoffset[17]; /* huffval[] offset for codes of length k */
|
||||
/* valoffset[k] = huffval[] index of 1st symbol of code length k, less
|
||||
* the smallest code of length k; so given a code of length k, the
|
||||
* corresponding symbol is huffval[code + valoffset[k]]
|
||||
*/
|
||||
|
||||
/* Link to public Huffman table (needed only in jpeg_huff_decode) */
|
||||
JHUFF_TBL *pub;
|
||||
|
||||
/* Lookahead tables: indexed by the next HUFF_LOOKAHEAD bits of
|
||||
* the input data stream. If the next Huffman code is no more
|
||||
* than HUFF_LOOKAHEAD bits long, we can obtain its length and
|
||||
* the corresponding symbol directly from these tables.
|
||||
*/
|
||||
int look_nbits[1<<HUFF_LOOKAHEAD]; /* # bits, or 0 if too long */
|
||||
UINT8 look_sym[1<<HUFF_LOOKAHEAD]; /* symbol, or unused */
|
||||
} d_derived_tbl;
|
||||
|
||||
/* Expand a Huffman table definition into the derived format */
|
||||
EXTERN(void) jpeg_make_d_derived_tbl
|
||||
JPP((j_decompress_ptr cinfo, boolean isDC, int tblno,
|
||||
d_derived_tbl ** pdtbl));
|
||||
|
||||
|
||||
/*
|
||||
* Fetching the next N bits from the input stream is a time-critical operation
|
||||
* for the Huffman decoders. We implement it with a combination of inline
|
||||
* macros and out-of-line subroutines. Note that N (the number of bits
|
||||
* demanded at one time) never exceeds 15 for JPEG use.
|
||||
*
|
||||
* We read source bytes into get_buffer and dole out bits as needed.
|
||||
* If get_buffer already contains enough bits, they are fetched in-line
|
||||
* by the macros CHECK_BIT_BUFFER and GET_BITS. When there aren't enough
|
||||
* bits, jpeg_fill_bit_buffer is called; it will attempt to fill get_buffer
|
||||
* as full as possible (not just to the number of bits needed; this
|
||||
* prefetching reduces the overhead cost of calling jpeg_fill_bit_buffer).
|
||||
* Note that jpeg_fill_bit_buffer may return FALSE to indicate suspension.
|
||||
* On TRUE return, jpeg_fill_bit_buffer guarantees that get_buffer contains
|
||||
* at least the requested number of bits --- dummy zeroes are inserted if
|
||||
* necessary.
|
||||
*/
|
||||
|
||||
typedef INT32 bit_buf_type; /* type of bit-extraction buffer */
|
||||
#define BIT_BUF_SIZE 32 /* size of buffer in bits */
|
||||
|
||||
/* If long is > 32 bits on your machine, and shifting/masking longs is
|
||||
* reasonably fast, making bit_buf_type be long and setting BIT_BUF_SIZE
|
||||
* appropriately should be a win. Unfortunately we can't define the size
|
||||
* with something like #define BIT_BUF_SIZE (sizeof(bit_buf_type)*8)
|
||||
* because not all machines measure sizeof in 8-bit bytes.
|
||||
*/
|
||||
|
||||
typedef struct { /* Bitreading state saved across MCUs */
|
||||
bit_buf_type get_buffer; /* current bit-extraction buffer */
|
||||
int bits_left; /* # of unused bits in it */
|
||||
} bitread_perm_state;
|
||||
|
||||
typedef struct { /* Bitreading working state within an MCU */
|
||||
/* Current data source location */
|
||||
/* We need a copy, rather than munging the original, in case of suspension */
|
||||
const JOCTET * next_input_byte; /* => next byte to read from source */
|
||||
size_t bytes_in_buffer; /* # of bytes remaining in source buffer */
|
||||
/* Bit input buffer --- note these values are kept in register variables,
|
||||
* not in this struct, inside the inner loops.
|
||||
*/
|
||||
bit_buf_type get_buffer; /* current bit-extraction buffer */
|
||||
int bits_left; /* # of unused bits in it */
|
||||
/* Pointer needed by jpeg_fill_bit_buffer. */
|
||||
j_decompress_ptr cinfo; /* back link to decompress master record */
|
||||
} bitread_working_state;
|
||||
|
||||
/* Macros to declare and load/save bitread local variables. */
|
||||
#define BITREAD_STATE_VARS \
|
||||
register bit_buf_type get_buffer; \
|
||||
register int bits_left; \
|
||||
bitread_working_state br_state
|
||||
|
||||
#define BITREAD_LOAD_STATE(cinfop,permstate) \
|
||||
br_state.cinfo = cinfop; \
|
||||
br_state.next_input_byte = cinfop->src->next_input_byte; \
|
||||
br_state.bytes_in_buffer = cinfop->src->bytes_in_buffer; \
|
||||
get_buffer = permstate.get_buffer; \
|
||||
bits_left = permstate.bits_left;
|
||||
|
||||
#define BITREAD_SAVE_STATE(cinfop,permstate) \
|
||||
cinfop->src->next_input_byte = br_state.next_input_byte; \
|
||||
cinfop->src->bytes_in_buffer = br_state.bytes_in_buffer; \
|
||||
permstate.get_buffer = get_buffer; \
|
||||
permstate.bits_left = bits_left
|
||||
|
||||
/*
|
||||
* These macros provide the in-line portion of bit fetching.
|
||||
* Use CHECK_BIT_BUFFER to ensure there are N bits in get_buffer
|
||||
* before using GET_BITS, PEEK_BITS, or DROP_BITS.
|
||||
* The variables get_buffer and bits_left are assumed to be locals,
|
||||
* but the state struct might not be (jpeg_huff_decode needs this).
|
||||
* CHECK_BIT_BUFFER(state,n,action);
|
||||
* Ensure there are N bits in get_buffer; if suspend, take action.
|
||||
* val = GET_BITS(n);
|
||||
* Fetch next N bits.
|
||||
* val = PEEK_BITS(n);
|
||||
* Fetch next N bits without removing them from the buffer.
|
||||
* DROP_BITS(n);
|
||||
* Discard next N bits.
|
||||
* The value N should be a simple variable, not an expression, because it
|
||||
* is evaluated multiple times.
|
||||
*/
|
||||
|
||||
#define CHECK_BIT_BUFFER(state,nbits,action) \
|
||||
{ if (bits_left < (nbits)) { \
|
||||
if (! jpeg_fill_bit_buffer(&(state),get_buffer,bits_left,nbits)) \
|
||||
{ action; } \
|
||||
get_buffer = (state).get_buffer; bits_left = (state).bits_left; } }
|
||||
|
||||
#define GET_BITS(nbits) \
|
||||
(((int) (get_buffer >> (bits_left -= (nbits)))) & ((1<<(nbits))-1))
|
||||
|
||||
#define PEEK_BITS(nbits) \
|
||||
(((int) (get_buffer >> (bits_left - (nbits)))) & ((1<<(nbits))-1))
|
||||
|
||||
#define DROP_BITS(nbits) \
|
||||
(bits_left -= (nbits))
|
||||
|
||||
/* Load up the bit buffer to a depth of at least nbits */
|
||||
EXTERN(boolean) jpeg_fill_bit_buffer
|
||||
JPP((bitread_working_state * state, register bit_buf_type get_buffer,
|
||||
register int bits_left, int nbits));
|
||||
|
||||
|
||||
/*
|
||||
* Code for extracting next Huffman-coded symbol from input bit stream.
|
||||
* Again, this is time-critical and we make the main paths be macros.
|
||||
*
|
||||
* We use a lookahead table to process codes of up to HUFF_LOOKAHEAD bits
|
||||
* without looping. Usually, more than 95% of the Huffman codes will be 8
|
||||
* or fewer bits long. The few overlength codes are handled with a loop,
|
||||
* which need not be inline code.
|
||||
*
|
||||
* Notes about the HUFF_DECODE macro:
|
||||
* 1. Near the end of the data segment, we may fail to get enough bits
|
||||
* for a lookahead. In that case, we do it the hard way.
|
||||
* 2. If the lookahead table contains no entry, the next code must be
|
||||
* more than HUFF_LOOKAHEAD bits long.
|
||||
* 3. jpeg_huff_decode returns -1 if forced to suspend.
|
||||
*/
|
||||
|
||||
#define HUFF_DECODE(result,state,htbl,failaction,slowlabel) \
|
||||
{ register int nb, look; \
|
||||
if (bits_left < HUFF_LOOKAHEAD) { \
|
||||
if (! jpeg_fill_bit_buffer(&state,get_buffer,bits_left, 0)) {failaction;} \
|
||||
get_buffer = state.get_buffer; bits_left = state.bits_left; \
|
||||
if (bits_left < HUFF_LOOKAHEAD) { \
|
||||
nb = 1; goto slowlabel; \
|
||||
} \
|
||||
} \
|
||||
look = PEEK_BITS(HUFF_LOOKAHEAD); \
|
||||
if ((nb = htbl->look_nbits[look]) != 0) { \
|
||||
DROP_BITS(nb); \
|
||||
result = htbl->look_sym[look]; \
|
||||
} else { \
|
||||
nb = HUFF_LOOKAHEAD+1; \
|
||||
slowlabel: \
|
||||
if ((result=jpeg_huff_decode(&state,get_buffer,bits_left,htbl,nb)) < 0) \
|
||||
{ failaction; } \
|
||||
get_buffer = state.get_buffer; bits_left = state.bits_left; \
|
||||
} \
|
||||
}
|
||||
|
||||
/* Out-of-line case for Huffman code fetching */
|
||||
EXTERN(int) jpeg_huff_decode
|
||||
JPP((bitread_working_state * state, register bit_buf_type get_buffer,
|
||||
register int bits_left, d_derived_tbl * htbl, int min_bits));
|
400
3rdparty/libjpeg/jdinput.c
vendored
400
3rdparty/libjpeg/jdinput.c
vendored
@ -2,13 +2,14 @@
|
||||
* jdinput.c
|
||||
*
|
||||
* Copyright (C) 1991-1997, Thomas G. Lane.
|
||||
* Modified 2002-2009 by Guido Vollbeding.
|
||||
* This file is part of the Independent JPEG Group's software.
|
||||
* For conditions of distribution and use, see the accompanying README file.
|
||||
*
|
||||
* This file contains input control logic for the JPEG decompressor.
|
||||
* These routines are concerned with controlling the decompressor's input
|
||||
* processing (marker reading and coefficient decoding). The actual input
|
||||
* reading is done in jdmarker.c, jdhuff.c, and jdphuff.c.
|
||||
* reading is done in jdmarker.c, jdhuff.c, and jdarith.c.
|
||||
*/
|
||||
|
||||
#define JPEG_INTERNALS
|
||||
@ -21,7 +22,7 @@
|
||||
typedef struct {
|
||||
struct jpeg_input_controller pub; /* public fields */
|
||||
|
||||
boolean inheaders; /* TRUE until first SOS is reached */
|
||||
int inheaders; /* Nonzero until first SOS is reached */
|
||||
} my_input_controller;
|
||||
|
||||
typedef my_input_controller * my_inputctl_ptr;
|
||||
@ -35,6 +36,174 @@ METHODDEF(int) consume_markers JPP((j_decompress_ptr cinfo));
|
||||
* Routines to calculate various quantities related to the size of the image.
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* Compute output image dimensions and related values.
|
||||
* NOTE: this is exported for possible use by application.
|
||||
* Hence it mustn't do anything that can't be done twice.
|
||||
*/
|
||||
|
||||
GLOBAL(void)
|
||||
jpeg_core_output_dimensions (j_decompress_ptr cinfo)
|
||||
/* Do computations that are needed before master selection phase.
|
||||
* This function is used for transcoding and full decompression.
|
||||
*/
|
||||
{
|
||||
#ifdef IDCT_SCALING_SUPPORTED
|
||||
int ci;
|
||||
jpeg_component_info *compptr;
|
||||
|
||||
/* Compute actual output image dimensions and DCT scaling choices. */
|
||||
if (cinfo->scale_num * cinfo->block_size <= cinfo->scale_denom) {
|
||||
/* Provide 1/block_size scaling */
|
||||
cinfo->output_width = (JDIMENSION)
|
||||
jdiv_round_up((long) cinfo->image_width, (long) cinfo->block_size);
|
||||
cinfo->output_height = (JDIMENSION)
|
||||
jdiv_round_up((long) cinfo->image_height, (long) cinfo->block_size);
|
||||
cinfo->min_DCT_h_scaled_size = 1;
|
||||
cinfo->min_DCT_v_scaled_size = 1;
|
||||
} else if (cinfo->scale_num * cinfo->block_size <= cinfo->scale_denom * 2) {
|
||||
/* Provide 2/block_size scaling */
|
||||
cinfo->output_width = (JDIMENSION)
|
||||
jdiv_round_up((long) cinfo->image_width * 2L, (long) cinfo->block_size);
|
||||
cinfo->output_height = (JDIMENSION)
|
||||
jdiv_round_up((long) cinfo->image_height * 2L, (long) cinfo->block_size);
|
||||
cinfo->min_DCT_h_scaled_size = 2;
|
||||
cinfo->min_DCT_v_scaled_size = 2;
|
||||
} else if (cinfo->scale_num * cinfo->block_size <= cinfo->scale_denom * 3) {
|
||||
/* Provide 3/block_size scaling */
|
||||
cinfo->output_width = (JDIMENSION)
|
||||
jdiv_round_up((long) cinfo->image_width * 3L, (long) cinfo->block_size);
|
||||
cinfo->output_height = (JDIMENSION)
|
||||
jdiv_round_up((long) cinfo->image_height * 3L, (long) cinfo->block_size);
|
||||
cinfo->min_DCT_h_scaled_size = 3;
|
||||
cinfo->min_DCT_v_scaled_size = 3;
|
||||
} else if (cinfo->scale_num * cinfo->block_size <= cinfo->scale_denom * 4) {
|
||||
/* Provide 4/block_size scaling */
|
||||
cinfo->output_width = (JDIMENSION)
|
||||
jdiv_round_up((long) cinfo->image_width * 4L, (long) cinfo->block_size);
|
||||
cinfo->output_height = (JDIMENSION)
|
||||
jdiv_round_up((long) cinfo->image_height * 4L, (long) cinfo->block_size);
|
||||
cinfo->min_DCT_h_scaled_size = 4;
|
||||
cinfo->min_DCT_v_scaled_size = 4;
|
||||
} else if (cinfo->scale_num * cinfo->block_size <= cinfo->scale_denom * 5) {
|
||||
/* Provide 5/block_size scaling */
|
||||
cinfo->output_width = (JDIMENSION)
|
||||
jdiv_round_up((long) cinfo->image_width * 5L, (long) cinfo->block_size);
|
||||
cinfo->output_height = (JDIMENSION)
|
||||
jdiv_round_up((long) cinfo->image_height * 5L, (long) cinfo->block_size);
|
||||
cinfo->min_DCT_h_scaled_size = 5;
|
||||
cinfo->min_DCT_v_scaled_size = 5;
|
||||
} else if (cinfo->scale_num * cinfo->block_size <= cinfo->scale_denom * 6) {
|
||||
/* Provide 6/block_size scaling */
|
||||
cinfo->output_width = (JDIMENSION)
|
||||
jdiv_round_up((long) cinfo->image_width * 6L, (long) cinfo->block_size);
|
||||
cinfo->output_height = (JDIMENSION)
|
||||
jdiv_round_up((long) cinfo->image_height * 6L, (long) cinfo->block_size);
|
||||
cinfo->min_DCT_h_scaled_size = 6;
|
||||
cinfo->min_DCT_v_scaled_size = 6;
|
||||
} else if (cinfo->scale_num * cinfo->block_size <= cinfo->scale_denom * 7) {
|
||||
/* Provide 7/block_size scaling */
|
||||
cinfo->output_width = (JDIMENSION)
|
||||
jdiv_round_up((long) cinfo->image_width * 7L, (long) cinfo->block_size);
|
||||
cinfo->output_height = (JDIMENSION)
|
||||
jdiv_round_up((long) cinfo->image_height * 7L, (long) cinfo->block_size);
|
||||
cinfo->min_DCT_h_scaled_size = 7;
|
||||
cinfo->min_DCT_v_scaled_size = 7;
|
||||
} else if (cinfo->scale_num * cinfo->block_size <= cinfo->scale_denom * 8) {
|
||||
/* Provide 8/block_size scaling */
|
||||
cinfo->output_width = (JDIMENSION)
|
||||
jdiv_round_up((long) cinfo->image_width * 8L, (long) cinfo->block_size);
|
||||
cinfo->output_height = (JDIMENSION)
|
||||
jdiv_round_up((long) cinfo->image_height * 8L, (long) cinfo->block_size);
|
||||
cinfo->min_DCT_h_scaled_size = 8;
|
||||
cinfo->min_DCT_v_scaled_size = 8;
|
||||
} else if (cinfo->scale_num * cinfo->block_size <= cinfo->scale_denom * 9) {
|
||||
/* Provide 9/block_size scaling */
|
||||
cinfo->output_width = (JDIMENSION)
|
||||
jdiv_round_up((long) cinfo->image_width * 9L, (long) cinfo->block_size);
|
||||
cinfo->output_height = (JDIMENSION)
|
||||
jdiv_round_up((long) cinfo->image_height * 9L, (long) cinfo->block_size);
|
||||
cinfo->min_DCT_h_scaled_size = 9;
|
||||
cinfo->min_DCT_v_scaled_size = 9;
|
||||
} else if (cinfo->scale_num * cinfo->block_size <= cinfo->scale_denom * 10) {
|
||||
/* Provide 10/block_size scaling */
|
||||
cinfo->output_width = (JDIMENSION)
|
||||
jdiv_round_up((long) cinfo->image_width * 10L, (long) cinfo->block_size);
|
||||
cinfo->output_height = (JDIMENSION)
|
||||
jdiv_round_up((long) cinfo->image_height * 10L, (long) cinfo->block_size);
|
||||
cinfo->min_DCT_h_scaled_size = 10;
|
||||
cinfo->min_DCT_v_scaled_size = 10;
|
||||
} else if (cinfo->scale_num * cinfo->block_size <= cinfo->scale_denom * 11) {
|
||||
/* Provide 11/block_size scaling */
|
||||
cinfo->output_width = (JDIMENSION)
|
||||
jdiv_round_up((long) cinfo->image_width * 11L, (long) cinfo->block_size);
|
||||
cinfo->output_height = (JDIMENSION)
|
||||
jdiv_round_up((long) cinfo->image_height * 11L, (long) cinfo->block_size);
|
||||
cinfo->min_DCT_h_scaled_size = 11;
|
||||
cinfo->min_DCT_v_scaled_size = 11;
|
||||
} else if (cinfo->scale_num * cinfo->block_size <= cinfo->scale_denom * 12) {
|
||||
/* Provide 12/block_size scaling */
|
||||
cinfo->output_width = (JDIMENSION)
|
||||
jdiv_round_up((long) cinfo->image_width * 12L, (long) cinfo->block_size);
|
||||
cinfo->output_height = (JDIMENSION)
|
||||
jdiv_round_up((long) cinfo->image_height * 12L, (long) cinfo->block_size);
|
||||
cinfo->min_DCT_h_scaled_size = 12;
|
||||
cinfo->min_DCT_v_scaled_size = 12;
|
||||
} else if (cinfo->scale_num * cinfo->block_size <= cinfo->scale_denom * 13) {
|
||||
/* Provide 13/block_size scaling */
|
||||
cinfo->output_width = (JDIMENSION)
|
||||
jdiv_round_up((long) cinfo->image_width * 13L, (long) cinfo->block_size);
|
||||
cinfo->output_height = (JDIMENSION)
|
||||
jdiv_round_up((long) cinfo->image_height * 13L, (long) cinfo->block_size);
|
||||
cinfo->min_DCT_h_scaled_size = 13;
|
||||
cinfo->min_DCT_v_scaled_size = 13;
|
||||
} else if (cinfo->scale_num * cinfo->block_size <= cinfo->scale_denom * 14) {
|
||||
/* Provide 14/block_size scaling */
|
||||
cinfo->output_width = (JDIMENSION)
|
||||
jdiv_round_up((long) cinfo->image_width * 14L, (long) cinfo->block_size);
|
||||
cinfo->output_height = (JDIMENSION)
|
||||
jdiv_round_up((long) cinfo->image_height * 14L, (long) cinfo->block_size);
|
||||
cinfo->min_DCT_h_scaled_size = 14;
|
||||
cinfo->min_DCT_v_scaled_size = 14;
|
||||
} else if (cinfo->scale_num * cinfo->block_size <= cinfo->scale_denom * 15) {
|
||||
/* Provide 15/block_size scaling */
|
||||
cinfo->output_width = (JDIMENSION)
|
||||
jdiv_round_up((long) cinfo->image_width * 15L, (long) cinfo->block_size);
|
||||
cinfo->output_height = (JDIMENSION)
|
||||
jdiv_round_up((long) cinfo->image_height * 15L, (long) cinfo->block_size);
|
||||
cinfo->min_DCT_h_scaled_size = 15;
|
||||
cinfo->min_DCT_v_scaled_size = 15;
|
||||
} else {
|
||||
/* Provide 16/block_size scaling */
|
||||
cinfo->output_width = (JDIMENSION)
|
||||
jdiv_round_up((long) cinfo->image_width * 16L, (long) cinfo->block_size);
|
||||
cinfo->output_height = (JDIMENSION)
|
||||
jdiv_round_up((long) cinfo->image_height * 16L, (long) cinfo->block_size);
|
||||
cinfo->min_DCT_h_scaled_size = 16;
|
||||
cinfo->min_DCT_v_scaled_size = 16;
|
||||
}
|
||||
|
||||
/* Recompute dimensions of components */
|
||||
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
|
||||
ci++, compptr++) {
|
||||
compptr->DCT_h_scaled_size = cinfo->min_DCT_h_scaled_size;
|
||||
compptr->DCT_v_scaled_size = cinfo->min_DCT_v_scaled_size;
|
||||
}
|
||||
|
||||
#else /* !IDCT_SCALING_SUPPORTED */
|
||||
|
||||
/* Hardwire it to "no scaling" */
|
||||
cinfo->output_width = cinfo->image_width;
|
||||
cinfo->output_height = cinfo->image_height;
|
||||
/* jdinput.c has already initialized DCT_scaled_size,
|
||||
* and has computed unscaled downsampled_width and downsampled_height.
|
||||
*/
|
||||
|
||||
#endif /* IDCT_SCALING_SUPPORTED */
|
||||
}
|
||||
|
||||
|
||||
LOCAL(void)
|
||||
initial_setup (j_decompress_ptr cinfo)
|
||||
/* Called once, when first SOS marker is reached */
|
||||
@ -54,7 +223,7 @@ initial_setup (j_decompress_ptr cinfo)
|
||||
/* Check that number of components won't exceed internal array sizes */
|
||||
if (cinfo->num_components > MAX_COMPONENTS)
|
||||
ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
|
||||
MAX_COMPONENTS);
|
||||
MAX_COMPONENTS);
|
||||
|
||||
/* Compute maximum sampling factors; check factor validity */
|
||||
cinfo->max_h_samp_factor = 1;
|
||||
@ -62,31 +231,129 @@ initial_setup (j_decompress_ptr cinfo)
|
||||
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
|
||||
ci++, compptr++) {
|
||||
if (compptr->h_samp_factor<=0 || compptr->h_samp_factor>MAX_SAMP_FACTOR ||
|
||||
compptr->v_samp_factor<=0 || compptr->v_samp_factor>MAX_SAMP_FACTOR)
|
||||
compptr->v_samp_factor<=0 || compptr->v_samp_factor>MAX_SAMP_FACTOR)
|
||||
ERREXIT(cinfo, JERR_BAD_SAMPLING);
|
||||
cinfo->max_h_samp_factor = MAX(cinfo->max_h_samp_factor,
|
||||
compptr->h_samp_factor);
|
||||
compptr->h_samp_factor);
|
||||
cinfo->max_v_samp_factor = MAX(cinfo->max_v_samp_factor,
|
||||
compptr->v_samp_factor);
|
||||
compptr->v_samp_factor);
|
||||
}
|
||||
|
||||
/* We initialize DCT_scaled_size and min_DCT_scaled_size to DCTSIZE.
|
||||
* In the full decompressor, this will be overridden by jdmaster.c;
|
||||
* but in the transcoder, jdmaster.c is not used, so we must do it here.
|
||||
/* Derive block_size, natural_order, and lim_Se */
|
||||
if (cinfo->is_baseline || (cinfo->progressive_mode &&
|
||||
cinfo->comps_in_scan)) { /* no pseudo SOS marker */
|
||||
cinfo->block_size = DCTSIZE;
|
||||
cinfo->natural_order = jpeg_natural_order;
|
||||
cinfo->lim_Se = DCTSIZE2-1;
|
||||
} else
|
||||
switch (cinfo->Se) {
|
||||
case (1*1-1):
|
||||
cinfo->block_size = 1;
|
||||
cinfo->natural_order = jpeg_natural_order; /* not needed */
|
||||
cinfo->lim_Se = cinfo->Se;
|
||||
break;
|
||||
case (2*2-1):
|
||||
cinfo->block_size = 2;
|
||||
cinfo->natural_order = jpeg_natural_order2;
|
||||
cinfo->lim_Se = cinfo->Se;
|
||||
break;
|
||||
case (3*3-1):
|
||||
cinfo->block_size = 3;
|
||||
cinfo->natural_order = jpeg_natural_order3;
|
||||
cinfo->lim_Se = cinfo->Se;
|
||||
break;
|
||||
case (4*4-1):
|
||||
cinfo->block_size = 4;
|
||||
cinfo->natural_order = jpeg_natural_order4;
|
||||
cinfo->lim_Se = cinfo->Se;
|
||||
break;
|
||||
case (5*5-1):
|
||||
cinfo->block_size = 5;
|
||||
cinfo->natural_order = jpeg_natural_order5;
|
||||
cinfo->lim_Se = cinfo->Se;
|
||||
break;
|
||||
case (6*6-1):
|
||||
cinfo->block_size = 6;
|
||||
cinfo->natural_order = jpeg_natural_order6;
|
||||
cinfo->lim_Se = cinfo->Se;
|
||||
break;
|
||||
case (7*7-1):
|
||||
cinfo->block_size = 7;
|
||||
cinfo->natural_order = jpeg_natural_order7;
|
||||
cinfo->lim_Se = cinfo->Se;
|
||||
break;
|
||||
case (8*8-1):
|
||||
cinfo->block_size = 8;
|
||||
cinfo->natural_order = jpeg_natural_order;
|
||||
cinfo->lim_Se = DCTSIZE2-1;
|
||||
break;
|
||||
case (9*9-1):
|
||||
cinfo->block_size = 9;
|
||||
cinfo->natural_order = jpeg_natural_order;
|
||||
cinfo->lim_Se = DCTSIZE2-1;
|
||||
break;
|
||||
case (10*10-1):
|
||||
cinfo->block_size = 10;
|
||||
cinfo->natural_order = jpeg_natural_order;
|
||||
cinfo->lim_Se = DCTSIZE2-1;
|
||||
break;
|
||||
case (11*11-1):
|
||||
cinfo->block_size = 11;
|
||||
cinfo->natural_order = jpeg_natural_order;
|
||||
cinfo->lim_Se = DCTSIZE2-1;
|
||||
break;
|
||||
case (12*12-1):
|
||||
cinfo->block_size = 12;
|
||||
cinfo->natural_order = jpeg_natural_order;
|
||||
cinfo->lim_Se = DCTSIZE2-1;
|
||||
break;
|
||||
case (13*13-1):
|
||||
cinfo->block_size = 13;
|
||||
cinfo->natural_order = jpeg_natural_order;
|
||||
cinfo->lim_Se = DCTSIZE2-1;
|
||||
break;
|
||||
case (14*14-1):
|
||||
cinfo->block_size = 14;
|
||||
cinfo->natural_order = jpeg_natural_order;
|
||||
cinfo->lim_Se = DCTSIZE2-1;
|
||||
break;
|
||||
case (15*15-1):
|
||||
cinfo->block_size = 15;
|
||||
cinfo->natural_order = jpeg_natural_order;
|
||||
cinfo->lim_Se = DCTSIZE2-1;
|
||||
break;
|
||||
case (16*16-1):
|
||||
cinfo->block_size = 16;
|
||||
cinfo->natural_order = jpeg_natural_order;
|
||||
cinfo->lim_Se = DCTSIZE2-1;
|
||||
break;
|
||||
default:
|
||||
ERREXIT4(cinfo, JERR_BAD_PROGRESSION,
|
||||
cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al);
|
||||
break;
|
||||
}
|
||||
|
||||
/* We initialize DCT_scaled_size and min_DCT_scaled_size to block_size.
|
||||
* In the full decompressor,
|
||||
* this will be overridden by jpeg_calc_output_dimensions in jdmaster.c;
|
||||
* but in the transcoder,
|
||||
* jpeg_calc_output_dimensions is not used, so we must do it here.
|
||||
*/
|
||||
cinfo->min_DCT_scaled_size = DCTSIZE;
|
||||
cinfo->min_DCT_h_scaled_size = cinfo->block_size;
|
||||
cinfo->min_DCT_v_scaled_size = cinfo->block_size;
|
||||
|
||||
/* Compute dimensions of components */
|
||||
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
|
||||
ci++, compptr++) {
|
||||
compptr->DCT_scaled_size = DCTSIZE;
|
||||
compptr->DCT_h_scaled_size = cinfo->block_size;
|
||||
compptr->DCT_v_scaled_size = cinfo->block_size;
|
||||
/* Size in DCT blocks */
|
||||
compptr->width_in_blocks = (JDIMENSION)
|
||||
jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor,
|
||||
(long) (cinfo->max_h_samp_factor * DCTSIZE));
|
||||
(long) (cinfo->max_h_samp_factor * cinfo->block_size));
|
||||
compptr->height_in_blocks = (JDIMENSION)
|
||||
jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor,
|
||||
(long) (cinfo->max_v_samp_factor * DCTSIZE));
|
||||
(long) (cinfo->max_v_samp_factor * cinfo->block_size));
|
||||
/* downsampled_width and downsampled_height will also be overridden by
|
||||
* jdmaster.c if we are doing full decompression. The transcoder library
|
||||
* doesn't use these values, but the calling application might.
|
||||
@ -94,10 +361,10 @@ initial_setup (j_decompress_ptr cinfo)
|
||||
/* Size in samples */
|
||||
compptr->downsampled_width = (JDIMENSION)
|
||||
jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor,
|
||||
(long) cinfo->max_h_samp_factor);
|
||||
(long) cinfo->max_h_samp_factor);
|
||||
compptr->downsampled_height = (JDIMENSION)
|
||||
jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor,
|
||||
(long) cinfo->max_v_samp_factor);
|
||||
(long) cinfo->max_v_samp_factor);
|
||||
/* Mark component needed, until color conversion says otherwise */
|
||||
compptr->component_needed = TRUE;
|
||||
/* Mark no quantization table yet saved for component */
|
||||
@ -107,7 +374,7 @@ initial_setup (j_decompress_ptr cinfo)
|
||||
/* Compute number of fully interleaved MCU rows. */
|
||||
cinfo->total_iMCU_rows = (JDIMENSION)
|
||||
jdiv_round_up((long) cinfo->image_height,
|
||||
(long) (cinfo->max_v_samp_factor*DCTSIZE));
|
||||
(long) (cinfo->max_v_samp_factor * cinfo->block_size));
|
||||
|
||||
/* Decide whether file contains multiple scans */
|
||||
if (cinfo->comps_in_scan < cinfo->num_components || cinfo->progressive_mode)
|
||||
@ -138,7 +405,7 @@ per_scan_setup (j_decompress_ptr cinfo)
|
||||
compptr->MCU_width = 1;
|
||||
compptr->MCU_height = 1;
|
||||
compptr->MCU_blocks = 1;
|
||||
compptr->MCU_sample_width = compptr->DCT_scaled_size;
|
||||
compptr->MCU_sample_width = compptr->DCT_h_scaled_size;
|
||||
compptr->last_col_width = 1;
|
||||
/* For noninterleaved scans, it is convenient to define last_row_height
|
||||
* as the number of block rows present in the last iMCU row.
|
||||
@ -156,15 +423,15 @@ per_scan_setup (j_decompress_ptr cinfo)
|
||||
/* Interleaved (multi-component) scan */
|
||||
if (cinfo->comps_in_scan <= 0 || cinfo->comps_in_scan > MAX_COMPS_IN_SCAN)
|
||||
ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->comps_in_scan,
|
||||
MAX_COMPS_IN_SCAN);
|
||||
MAX_COMPS_IN_SCAN);
|
||||
|
||||
/* Overall image size in MCUs */
|
||||
cinfo->MCUs_per_row = (JDIMENSION)
|
||||
jdiv_round_up((long) cinfo->image_width,
|
||||
(long) (cinfo->max_h_samp_factor*DCTSIZE));
|
||||
(long) (cinfo->max_h_samp_factor * cinfo->block_size));
|
||||
cinfo->MCU_rows_in_scan = (JDIMENSION)
|
||||
jdiv_round_up((long) cinfo->image_height,
|
||||
(long) (cinfo->max_v_samp_factor*DCTSIZE));
|
||||
(long) (cinfo->max_v_samp_factor * cinfo->block_size));
|
||||
|
||||
cinfo->blocks_in_MCU = 0;
|
||||
|
||||
@ -174,7 +441,7 @@ per_scan_setup (j_decompress_ptr cinfo)
|
||||
compptr->MCU_width = compptr->h_samp_factor;
|
||||
compptr->MCU_height = compptr->v_samp_factor;
|
||||
compptr->MCU_blocks = compptr->MCU_width * compptr->MCU_height;
|
||||
compptr->MCU_sample_width = compptr->MCU_width * compptr->DCT_scaled_size;
|
||||
compptr->MCU_sample_width = compptr->MCU_width * compptr->DCT_h_scaled_size;
|
||||
/* Figure number of non-dummy blocks in last MCU column & row */
|
||||
tmp = (int) (compptr->width_in_blocks % compptr->MCU_width);
|
||||
if (tmp == 0) tmp = compptr->MCU_width;
|
||||
@ -185,9 +452,9 @@ per_scan_setup (j_decompress_ptr cinfo)
|
||||
/* Prepare array describing MCU composition */
|
||||
mcublks = compptr->MCU_blocks;
|
||||
if (cinfo->blocks_in_MCU + mcublks > D_MAX_BLOCKS_IN_MCU)
|
||||
ERREXIT(cinfo, JERR_BAD_MCU_SIZE);
|
||||
ERREXIT(cinfo, JERR_BAD_MCU_SIZE);
|
||||
while (mcublks-- > 0) {
|
||||
cinfo->MCU_membership[cinfo->blocks_in_MCU++] = ci;
|
||||
cinfo->MCU_membership[cinfo->blocks_in_MCU++] = ci;
|
||||
}
|
||||
}
|
||||
|
||||
@ -231,12 +498,12 @@ latch_quant_tables (j_decompress_ptr cinfo)
|
||||
/* Make sure specified quantization table is present */
|
||||
qtblno = compptr->quant_tbl_no;
|
||||
if (qtblno < 0 || qtblno >= NUM_QUANT_TBLS ||
|
||||
cinfo->quant_tbl_ptrs[qtblno] == NULL)
|
||||
cinfo->quant_tbl_ptrs[qtblno] == NULL)
|
||||
ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, qtblno);
|
||||
/* OK, save away the quantization table */
|
||||
qtbl = (JQUANT_TBL *)
|
||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
||||
SIZEOF(JQUANT_TBL));
|
||||
SIZEOF(JQUANT_TBL));
|
||||
MEMCOPY(qtbl, cinfo->quant_tbl_ptrs[qtblno], SIZEOF(JQUANT_TBL));
|
||||
compptr->quant_table = qtbl;
|
||||
}
|
||||
@ -282,6 +549,10 @@ finish_input_pass (j_decompress_ptr cinfo)
|
||||
* The consume_input method pointer points either here or to the
|
||||
* coefficient controller's consume_data routine, depending on whether
|
||||
* we are reading a compressed data segment or inter-segment markers.
|
||||
*
|
||||
* Note: This function should NOT return a pseudo SOS marker (with zero
|
||||
* component number) to the caller. A pseudo marker received by
|
||||
* read_markers is processed and then skipped for other markers.
|
||||
*/
|
||||
|
||||
METHODDEF(int)
|
||||
@ -293,41 +564,50 @@ consume_markers (j_decompress_ptr cinfo)
|
||||
if (inputctl->pub.eoi_reached) /* After hitting EOI, read no further */
|
||||
return JPEG_REACHED_EOI;
|
||||
|
||||
val = (*cinfo->marker->read_markers) (cinfo);
|
||||
for (;;) { /* Loop to pass pseudo SOS marker */
|
||||
val = (*cinfo->marker->read_markers) (cinfo);
|
||||
|
||||
switch (val) {
|
||||
case JPEG_REACHED_SOS: /* Found SOS */
|
||||
if (inputctl->inheaders) { /* 1st SOS */
|
||||
initial_setup(cinfo);
|
||||
inputctl->inheaders = FALSE;
|
||||
/* Note: start_input_pass must be called by jdmaster.c
|
||||
* before any more input can be consumed. jdapimin.c is
|
||||
* responsible for enforcing this sequencing.
|
||||
*/
|
||||
} else { /* 2nd or later SOS marker */
|
||||
if (! inputctl->pub.has_multiple_scans)
|
||||
ERREXIT(cinfo, JERR_EOI_EXPECTED); /* Oops, I wasn't expecting this! */
|
||||
start_input_pass(cinfo);
|
||||
switch (val) {
|
||||
case JPEG_REACHED_SOS: /* Found SOS */
|
||||
if (inputctl->inheaders) { /* 1st SOS */
|
||||
if (inputctl->inheaders == 1)
|
||||
initial_setup(cinfo);
|
||||
if (cinfo->comps_in_scan == 0) { /* pseudo SOS marker */
|
||||
inputctl->inheaders = 2;
|
||||
break;
|
||||
}
|
||||
inputctl->inheaders = 0;
|
||||
/* Note: start_input_pass must be called by jdmaster.c
|
||||
* before any more input can be consumed. jdapimin.c is
|
||||
* responsible for enforcing this sequencing.
|
||||
*/
|
||||
} else { /* 2nd or later SOS marker */
|
||||
if (! inputctl->pub.has_multiple_scans)
|
||||
ERREXIT(cinfo, JERR_EOI_EXPECTED); /* Oops, I wasn't expecting this! */
|
||||
if (cinfo->comps_in_scan == 0) /* unexpected pseudo SOS marker */
|
||||
break;
|
||||
start_input_pass(cinfo);
|
||||
}
|
||||
return val;
|
||||
case JPEG_REACHED_EOI: /* Found EOI */
|
||||
inputctl->pub.eoi_reached = TRUE;
|
||||
if (inputctl->inheaders) { /* Tables-only datastream, apparently */
|
||||
if (cinfo->marker->saw_SOF)
|
||||
ERREXIT(cinfo, JERR_SOF_NO_SOS);
|
||||
} else {
|
||||
/* Prevent infinite loop in coef ctlr's decompress_data routine
|
||||
* if user set output_scan_number larger than number of scans.
|
||||
*/
|
||||
if (cinfo->output_scan_number > cinfo->input_scan_number)
|
||||
cinfo->output_scan_number = cinfo->input_scan_number;
|
||||
}
|
||||
return val;
|
||||
case JPEG_SUSPENDED:
|
||||
return val;
|
||||
default:
|
||||
return val;
|
||||
}
|
||||
break;
|
||||
case JPEG_REACHED_EOI: /* Found EOI */
|
||||
inputctl->pub.eoi_reached = TRUE;
|
||||
if (inputctl->inheaders) { /* Tables-only datastream, apparently */
|
||||
if (cinfo->marker->saw_SOF)
|
||||
ERREXIT(cinfo, JERR_SOF_NO_SOS);
|
||||
} else {
|
||||
/* Prevent infinite loop in coef ctlr's decompress_data routine
|
||||
* if user set output_scan_number larger than number of scans.
|
||||
*/
|
||||
if (cinfo->output_scan_number > cinfo->input_scan_number)
|
||||
cinfo->output_scan_number = cinfo->input_scan_number;
|
||||
}
|
||||
break;
|
||||
case JPEG_SUSPENDED:
|
||||
break;
|
||||
}
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
|
||||
@ -343,7 +623,7 @@ reset_input_controller (j_decompress_ptr cinfo)
|
||||
inputctl->pub.consume_input = consume_markers;
|
||||
inputctl->pub.has_multiple_scans = FALSE; /* "unknown" would be better */
|
||||
inputctl->pub.eoi_reached = FALSE;
|
||||
inputctl->inheaders = TRUE;
|
||||
inputctl->inheaders = 1;
|
||||
/* Reset other modules */
|
||||
(*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);
|
||||
(*cinfo->marker->reset_marker_reader) (cinfo);
|
||||
@ -365,7 +645,7 @@ jinit_input_controller (j_decompress_ptr cinfo)
|
||||
/* Create subobject in permanent pool */
|
||||
inputctl = (my_inputctl_ptr)
|
||||
(*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;
|
||||
/* Initialize method pointers */
|
||||
inputctl->pub.consume_input = consume_markers;
|
||||
@ -377,5 +657,5 @@ jinit_input_controller (j_decompress_ptr cinfo)
|
||||
*/
|
||||
inputctl->pub.has_multiple_scans = FALSE; /* "unknown" would be better */
|
||||
inputctl->pub.eoi_reached = FALSE;
|
||||
inputctl->inheaders = TRUE;
|
||||
inputctl->inheaders = 1;
|
||||
}
|
||||
|
221
3rdparty/libjpeg/jdmainct.c
vendored
221
3rdparty/libjpeg/jdmainct.c
vendored
@ -2,15 +2,16 @@
|
||||
* jdmainct.c
|
||||
*
|
||||
* Copyright (C) 1994-1996, Thomas G. Lane.
|
||||
* Modified 2002-2012 by Guido Vollbeding.
|
||||
* This file is part of the Independent JPEG Group's software.
|
||||
* For conditions of distribution and use, see the accompanying README file.
|
||||
*
|
||||
* This file contains the main_ptr buffer controller for decompression.
|
||||
* The main_ptr buffer lies between the JPEG decompressor proper and the
|
||||
* This file contains the main buffer controller for decompression.
|
||||
* The main buffer lies between the JPEG decompressor proper and the
|
||||
* post-processor; it holds downsampled data in the JPEG colorspace.
|
||||
*
|
||||
* Note that this code is bypassed in raw-data mode, since the application
|
||||
* supplies the equivalent of the main_ptr buffer in that case.
|
||||
* supplies the equivalent of the main buffer in that case.
|
||||
*/
|
||||
|
||||
#define JPEG_INTERNALS
|
||||
@ -19,9 +20,9 @@
|
||||
|
||||
|
||||
/*
|
||||
* In the current system design, the main_ptr buffer need never be a full-image
|
||||
* In the current system design, the main buffer need never be a full-image
|
||||
* buffer; any full-height buffers will be found inside the coefficient or
|
||||
* postprocessing controllers. Nonetheless, the main_ptr controller is not
|
||||
* postprocessing controllers. Nonetheless, the main controller is not
|
||||
* trivial. Its responsibility is to provide context rows for upsampling/
|
||||
* rescaling, and doing this in an efficient fashion is a bit tricky.
|
||||
*
|
||||
@ -141,15 +142,15 @@ typedef my_main_controller * my_main_ptr;
|
||||
|
||||
/* Forward declarations */
|
||||
METHODDEF(void) process_data_simple_main
|
||||
JPP((j_decompress_ptr cinfo, JSAMPARRAY output_buf,
|
||||
JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail));
|
||||
JPP((j_decompress_ptr cinfo, JSAMPARRAY output_buf,
|
||||
JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail));
|
||||
METHODDEF(void) process_data_context_main
|
||||
JPP((j_decompress_ptr cinfo, JSAMPARRAY output_buf,
|
||||
JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail));
|
||||
JPP((j_decompress_ptr cinfo, JSAMPARRAY output_buf,
|
||||
JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail));
|
||||
#ifdef QUANT_2PASS_SUPPORTED
|
||||
METHODDEF(void) process_data_crank_post
|
||||
JPP((j_decompress_ptr cinfo, JSAMPARRAY output_buf,
|
||||
JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail));
|
||||
JPP((j_decompress_ptr cinfo, JSAMPARRAY output_buf,
|
||||
JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail));
|
||||
#endif
|
||||
|
||||
|
||||
@ -159,34 +160,34 @@ alloc_funny_pointers (j_decompress_ptr cinfo)
|
||||
* This is done only once, not once per pass.
|
||||
*/
|
||||
{
|
||||
my_main_ptr main_ptr = (my_main_ptr) cinfo->main;
|
||||
my_main_ptr mainp = (my_main_ptr) cinfo->main;
|
||||
int ci, rgroup;
|
||||
int M = cinfo->min_DCT_scaled_size;
|
||||
int M = cinfo->min_DCT_v_scaled_size;
|
||||
jpeg_component_info *compptr;
|
||||
JSAMPARRAY xbuf;
|
||||
|
||||
/* Get top-level space for component array pointers.
|
||||
* We alloc both arrays with one call to save a few cycles.
|
||||
*/
|
||||
main_ptr->xbuffer[0] = (JSAMPIMAGE)
|
||||
mainp->xbuffer[0] = (JSAMPIMAGE)
|
||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
||||
cinfo->num_components * 2 * SIZEOF(JSAMPARRAY));
|
||||
main_ptr->xbuffer[1] = main_ptr->xbuffer[0] + cinfo->num_components;
|
||||
cinfo->num_components * 2 * SIZEOF(JSAMPARRAY));
|
||||
mainp->xbuffer[1] = mainp->xbuffer[0] + cinfo->num_components;
|
||||
|
||||
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
|
||||
ci++, compptr++) {
|
||||
rgroup = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
|
||||
cinfo->min_DCT_scaled_size; /* height of a row group of component */
|
||||
rgroup = (compptr->v_samp_factor * compptr->DCT_v_scaled_size) /
|
||||
cinfo->min_DCT_v_scaled_size; /* height of a row group of component */
|
||||
/* Get space for pointer lists --- M+4 row groups in each list.
|
||||
* We alloc both pointer lists with one call to save a few cycles.
|
||||
*/
|
||||
xbuf = (JSAMPARRAY)
|
||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
||||
2 * (rgroup * (M + 4)) * SIZEOF(JSAMPROW));
|
||||
2 * (rgroup * (M + 4)) * SIZEOF(JSAMPROW));
|
||||
xbuf += rgroup; /* want one row group at negative offsets */
|
||||
main_ptr->xbuffer[0][ci] = xbuf;
|
||||
mainp->xbuffer[0][ci] = xbuf;
|
||||
xbuf += rgroup * (M + 4);
|
||||
main_ptr->xbuffer[1][ci] = xbuf;
|
||||
mainp->xbuffer[1][ci] = xbuf;
|
||||
}
|
||||
}
|
||||
|
||||
@ -194,26 +195,26 @@ alloc_funny_pointers (j_decompress_ptr cinfo)
|
||||
LOCAL(void)
|
||||
make_funny_pointers (j_decompress_ptr cinfo)
|
||||
/* Create the funny pointer lists discussed in the comments above.
|
||||
* The actual workspace is already allocated (in main_ptr->buffer),
|
||||
* The actual workspace is already allocated (in main->buffer),
|
||||
* and the space for the pointer lists is allocated too.
|
||||
* This routine just fills in the curiously ordered lists.
|
||||
* This will be repeated at the beginning of each pass.
|
||||
*/
|
||||
{
|
||||
my_main_ptr main_ptr = (my_main_ptr) cinfo->main;
|
||||
my_main_ptr mainp = (my_main_ptr) cinfo->main;
|
||||
int ci, i, rgroup;
|
||||
int M = cinfo->min_DCT_scaled_size;
|
||||
int M = cinfo->min_DCT_v_scaled_size;
|
||||
jpeg_component_info *compptr;
|
||||
JSAMPARRAY buf, xbuf0, xbuf1;
|
||||
|
||||
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
|
||||
ci++, compptr++) {
|
||||
rgroup = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
|
||||
cinfo->min_DCT_scaled_size; /* height of a row group of component */
|
||||
xbuf0 = main_ptr->xbuffer[0][ci];
|
||||
xbuf1 = main_ptr->xbuffer[1][ci];
|
||||
rgroup = (compptr->v_samp_factor * compptr->DCT_v_scaled_size) /
|
||||
cinfo->min_DCT_v_scaled_size; /* height of a row group of component */
|
||||
xbuf0 = mainp->xbuffer[0][ci];
|
||||
xbuf1 = mainp->xbuffer[1][ci];
|
||||
/* First copy the workspace pointers as-is */
|
||||
buf = main_ptr->buffer[ci];
|
||||
buf = mainp->buffer[ci];
|
||||
for (i = 0; i < rgroup * (M + 2); i++) {
|
||||
xbuf0[i] = xbuf1[i] = buf[i];
|
||||
}
|
||||
@ -240,18 +241,18 @@ set_wraparound_pointers (j_decompress_ptr cinfo)
|
||||
* This changes the pointer list state from top-of-image to the normal state.
|
||||
*/
|
||||
{
|
||||
my_main_ptr main_ptr = (my_main_ptr) cinfo->main;
|
||||
my_main_ptr mainp = (my_main_ptr) cinfo->main;
|
||||
int ci, i, rgroup;
|
||||
int M = cinfo->min_DCT_scaled_size;
|
||||
int M = cinfo->min_DCT_v_scaled_size;
|
||||
jpeg_component_info *compptr;
|
||||
JSAMPARRAY xbuf0, xbuf1;
|
||||
|
||||
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
|
||||
ci++, compptr++) {
|
||||
rgroup = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
|
||||
cinfo->min_DCT_scaled_size; /* height of a row group of component */
|
||||
xbuf0 = main_ptr->xbuffer[0][ci];
|
||||
xbuf1 = main_ptr->xbuffer[1][ci];
|
||||
rgroup = (compptr->v_samp_factor * compptr->DCT_v_scaled_size) /
|
||||
cinfo->min_DCT_v_scaled_size; /* height of a row group of component */
|
||||
xbuf0 = mainp->xbuffer[0][ci];
|
||||
xbuf1 = mainp->xbuffer[1][ci];
|
||||
for (i = 0; i < rgroup; i++) {
|
||||
xbuf0[i - rgroup] = xbuf0[rgroup*(M+1) + i];
|
||||
xbuf1[i - rgroup] = xbuf1[rgroup*(M+1) + i];
|
||||
@ -269,7 +270,7 @@ set_bottom_pointers (j_decompress_ptr cinfo)
|
||||
* Also sets rowgroups_avail to indicate number of nondummy row groups in row.
|
||||
*/
|
||||
{
|
||||
my_main_ptr main_ptr = (my_main_ptr) cinfo->main;
|
||||
my_main_ptr mainp = (my_main_ptr) cinfo->main;
|
||||
int ci, i, rgroup, iMCUheight, rows_left;
|
||||
jpeg_component_info *compptr;
|
||||
JSAMPARRAY xbuf;
|
||||
@ -277,8 +278,8 @@ set_bottom_pointers (j_decompress_ptr cinfo)
|
||||
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
|
||||
ci++, compptr++) {
|
||||
/* Count sample rows in one iMCU row and in one row group */
|
||||
iMCUheight = compptr->v_samp_factor * compptr->DCT_scaled_size;
|
||||
rgroup = iMCUheight / cinfo->min_DCT_scaled_size;
|
||||
iMCUheight = compptr->v_samp_factor * compptr->DCT_v_scaled_size;
|
||||
rgroup = iMCUheight / cinfo->min_DCT_v_scaled_size;
|
||||
/* Count nondummy sample rows remaining for this component */
|
||||
rows_left = (int) (compptr->downsampled_height % (JDIMENSION) iMCUheight);
|
||||
if (rows_left == 0) rows_left = iMCUheight;
|
||||
@ -286,12 +287,12 @@ set_bottom_pointers (j_decompress_ptr cinfo)
|
||||
* so we need only do it once.
|
||||
*/
|
||||
if (ci == 0) {
|
||||
main_ptr->rowgroups_avail = (JDIMENSION) ((rows_left-1) / rgroup + 1);
|
||||
mainp->rowgroups_avail = (JDIMENSION) ((rows_left-1) / rgroup + 1);
|
||||
}
|
||||
/* Duplicate the last real sample row rgroup*2 times; this pads out the
|
||||
* last partial rowgroup and ensures at least one full rowgroup of context.
|
||||
*/
|
||||
xbuf = main_ptr->xbuffer[main_ptr->whichptr][ci];
|
||||
xbuf = mainp->xbuffer[mainp->whichptr][ci];
|
||||
for (i = 0; i < rgroup * 2; i++) {
|
||||
xbuf[rows_left + i] = xbuf[rows_left-1];
|
||||
}
|
||||
@ -306,27 +307,27 @@ set_bottom_pointers (j_decompress_ptr cinfo)
|
||||
METHODDEF(void)
|
||||
start_pass_main (j_decompress_ptr cinfo, J_BUF_MODE pass_mode)
|
||||
{
|
||||
my_main_ptr main_ptr = (my_main_ptr) cinfo->main;
|
||||
my_main_ptr mainp = (my_main_ptr) cinfo->main;
|
||||
|
||||
switch (pass_mode) {
|
||||
case JBUF_PASS_THRU:
|
||||
if (cinfo->upsample->need_context_rows) {
|
||||
main_ptr->pub.process_data = process_data_context_main;
|
||||
mainp->pub.process_data = process_data_context_main;
|
||||
make_funny_pointers(cinfo); /* Create the xbuffer[] lists */
|
||||
main_ptr->whichptr = 0; /* Read first iMCU row into xbuffer[0] */
|
||||
main_ptr->context_state = CTX_PREPARE_FOR_IMCU;
|
||||
main_ptr->iMCU_row_ctr = 0;
|
||||
mainp->whichptr = 0; /* Read first iMCU row into xbuffer[0] */
|
||||
mainp->context_state = CTX_PREPARE_FOR_IMCU;
|
||||
mainp->iMCU_row_ctr = 0;
|
||||
} else {
|
||||
/* Simple case with no context needed */
|
||||
main_ptr->pub.process_data = process_data_simple_main;
|
||||
mainp->pub.process_data = process_data_simple_main;
|
||||
}
|
||||
main_ptr->buffer_full = FALSE; /* Mark buffer empty */
|
||||
main_ptr->rowgroup_ctr = 0;
|
||||
mainp->buffer_full = FALSE; /* Mark buffer empty */
|
||||
mainp->rowgroup_ctr = 0;
|
||||
break;
|
||||
#ifdef QUANT_2PASS_SUPPORTED
|
||||
case JBUF_CRANK_DEST:
|
||||
/* For last pass of 2-pass quantization, just crank the postprocessor */
|
||||
main_ptr->pub.process_data = process_data_crank_post;
|
||||
mainp->pub.process_data = process_data_crank_post;
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
@ -343,35 +344,35 @@ start_pass_main (j_decompress_ptr cinfo, J_BUF_MODE pass_mode)
|
||||
|
||||
METHODDEF(void)
|
||||
process_data_simple_main (j_decompress_ptr cinfo,
|
||||
JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
|
||||
JDIMENSION out_rows_avail)
|
||||
JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
|
||||
JDIMENSION out_rows_avail)
|
||||
{
|
||||
my_main_ptr main_ptr = (my_main_ptr) cinfo->main;
|
||||
my_main_ptr mainp = (my_main_ptr) cinfo->main;
|
||||
JDIMENSION rowgroups_avail;
|
||||
|
||||
/* Read input data if we haven't filled the main_ptr buffer yet */
|
||||
if (! main_ptr->buffer_full) {
|
||||
if (! (*cinfo->coef->decompress_data) (cinfo, main_ptr->buffer))
|
||||
/* Read input data if we haven't filled the main buffer yet */
|
||||
if (! mainp->buffer_full) {
|
||||
if (! (*cinfo->coef->decompress_data) (cinfo, mainp->buffer))
|
||||
return; /* suspension forced, can do nothing more */
|
||||
main_ptr->buffer_full = TRUE; /* OK, we have an iMCU row to work with */
|
||||
mainp->buffer_full = TRUE; /* OK, we have an iMCU row to work with */
|
||||
}
|
||||
|
||||
/* There are always min_DCT_scaled_size row groups in an iMCU row. */
|
||||
rowgroups_avail = (JDIMENSION) cinfo->min_DCT_scaled_size;
|
||||
rowgroups_avail = (JDIMENSION) cinfo->min_DCT_v_scaled_size;
|
||||
/* Note: at the bottom of the image, we may pass extra garbage row groups
|
||||
* to the postprocessor. The postprocessor has to check for bottom
|
||||
* of image anyway (at row resolution), so no point in us doing it too.
|
||||
*/
|
||||
|
||||
/* Feed the postprocessor */
|
||||
(*cinfo->post->post_process_data) (cinfo, main_ptr->buffer,
|
||||
&main_ptr->rowgroup_ctr, rowgroups_avail,
|
||||
output_buf, out_row_ctr, out_rows_avail);
|
||||
(*cinfo->post->post_process_data) (cinfo, mainp->buffer,
|
||||
&mainp->rowgroup_ctr, rowgroups_avail,
|
||||
output_buf, out_row_ctr, out_rows_avail);
|
||||
|
||||
/* Has postprocessor consumed all the data yet? If so, mark buffer empty */
|
||||
if (main_ptr->rowgroup_ctr >= rowgroups_avail) {
|
||||
main_ptr->buffer_full = FALSE;
|
||||
main_ptr->rowgroup_ctr = 0;
|
||||
if (mainp->rowgroup_ctr >= rowgroups_avail) {
|
||||
mainp->buffer_full = FALSE;
|
||||
mainp->rowgroup_ctr = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@ -383,18 +384,18 @@ process_data_simple_main (j_decompress_ptr cinfo,
|
||||
|
||||
METHODDEF(void)
|
||||
process_data_context_main (j_decompress_ptr cinfo,
|
||||
JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
|
||||
JDIMENSION out_rows_avail)
|
||||
JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
|
||||
JDIMENSION out_rows_avail)
|
||||
{
|
||||
my_main_ptr main_ptr = (my_main_ptr) cinfo->main;
|
||||
my_main_ptr mainp = (my_main_ptr) cinfo->main;
|
||||
|
||||
/* Read input data if we haven't filled the main_ptr buffer yet */
|
||||
if (! main_ptr->buffer_full) {
|
||||
/* Read input data if we haven't filled the main buffer yet */
|
||||
if (! mainp->buffer_full) {
|
||||
if (! (*cinfo->coef->decompress_data) (cinfo,
|
||||
main_ptr->xbuffer[main_ptr->whichptr]))
|
||||
mainp->xbuffer[mainp->whichptr]))
|
||||
return; /* suspension forced, can do nothing more */
|
||||
main_ptr->buffer_full = TRUE; /* OK, we have an iMCU row to work with */
|
||||
main_ptr->iMCU_row_ctr++; /* count rows received */
|
||||
mainp->buffer_full = TRUE; /* OK, we have an iMCU row to work with */
|
||||
mainp->iMCU_row_ctr++; /* count rows received */
|
||||
}
|
||||
|
||||
/* Postprocessor typically will not swallow all the input data it is handed
|
||||
@ -402,47 +403,47 @@ process_data_context_main (j_decompress_ptr cinfo,
|
||||
* to exit and restart. This switch lets us keep track of how far we got.
|
||||
* Note that each case falls through to the next on successful completion.
|
||||
*/
|
||||
switch (main_ptr->context_state) {
|
||||
switch (mainp->context_state) {
|
||||
case CTX_POSTPONED_ROW:
|
||||
/* Call postprocessor using previously set pointers for postponed row */
|
||||
(*cinfo->post->post_process_data) (cinfo, main_ptr->xbuffer[main_ptr->whichptr],
|
||||
&main_ptr->rowgroup_ctr, main_ptr->rowgroups_avail,
|
||||
output_buf, out_row_ctr, out_rows_avail);
|
||||
if (main_ptr->rowgroup_ctr < main_ptr->rowgroups_avail)
|
||||
(*cinfo->post->post_process_data) (cinfo, mainp->xbuffer[mainp->whichptr],
|
||||
&mainp->rowgroup_ctr, mainp->rowgroups_avail,
|
||||
output_buf, out_row_ctr, out_rows_avail);
|
||||
if (mainp->rowgroup_ctr < mainp->rowgroups_avail)
|
||||
return; /* Need to suspend */
|
||||
main_ptr->context_state = CTX_PREPARE_FOR_IMCU;
|
||||
mainp->context_state = CTX_PREPARE_FOR_IMCU;
|
||||
if (*out_row_ctr >= out_rows_avail)
|
||||
return; /* Postprocessor exactly filled output buf */
|
||||
/*FALLTHROUGH*/
|
||||
case CTX_PREPARE_FOR_IMCU:
|
||||
/* Prepare to process first M-1 row groups of this iMCU row */
|
||||
main_ptr->rowgroup_ctr = 0;
|
||||
main_ptr->rowgroups_avail = (JDIMENSION) (cinfo->min_DCT_scaled_size - 1);
|
||||
mainp->rowgroup_ctr = 0;
|
||||
mainp->rowgroups_avail = (JDIMENSION) (cinfo->min_DCT_v_scaled_size - 1);
|
||||
/* Check for bottom of image: if so, tweak pointers to "duplicate"
|
||||
* the last sample row, and adjust rowgroups_avail to ignore padding rows.
|
||||
*/
|
||||
if (main_ptr->iMCU_row_ctr == cinfo->total_iMCU_rows)
|
||||
if (mainp->iMCU_row_ctr == cinfo->total_iMCU_rows)
|
||||
set_bottom_pointers(cinfo);
|
||||
main_ptr->context_state = CTX_PROCESS_IMCU;
|
||||
mainp->context_state = CTX_PROCESS_IMCU;
|
||||
/*FALLTHROUGH*/
|
||||
case CTX_PROCESS_IMCU:
|
||||
/* Call postprocessor using previously set pointers */
|
||||
(*cinfo->post->post_process_data) (cinfo, main_ptr->xbuffer[main_ptr->whichptr],
|
||||
&main_ptr->rowgroup_ctr, main_ptr->rowgroups_avail,
|
||||
output_buf, out_row_ctr, out_rows_avail);
|
||||
if (main_ptr->rowgroup_ctr < main_ptr->rowgroups_avail)
|
||||
(*cinfo->post->post_process_data) (cinfo, mainp->xbuffer[mainp->whichptr],
|
||||
&mainp->rowgroup_ctr, mainp->rowgroups_avail,
|
||||
output_buf, out_row_ctr, out_rows_avail);
|
||||
if (mainp->rowgroup_ctr < mainp->rowgroups_avail)
|
||||
return; /* Need to suspend */
|
||||
/* After the first iMCU, change wraparound pointers to normal state */
|
||||
if (main_ptr->iMCU_row_ctr == 1)
|
||||
if (mainp->iMCU_row_ctr == 1)
|
||||
set_wraparound_pointers(cinfo);
|
||||
/* Prepare to load new iMCU row using other xbuffer list */
|
||||
main_ptr->whichptr ^= 1; /* 0=>1 or 1=>0 */
|
||||
main_ptr->buffer_full = FALSE;
|
||||
mainp->whichptr ^= 1; /* 0=>1 or 1=>0 */
|
||||
mainp->buffer_full = FALSE;
|
||||
/* Still need to process last row group of this iMCU row, */
|
||||
/* which is saved at index M+1 of the other xbuffer */
|
||||
main_ptr->rowgroup_ctr = (JDIMENSION) (cinfo->min_DCT_scaled_size + 1);
|
||||
main_ptr->rowgroups_avail = (JDIMENSION) (cinfo->min_DCT_scaled_size + 2);
|
||||
main_ptr->context_state = CTX_POSTPONED_ROW;
|
||||
mainp->rowgroup_ctr = (JDIMENSION) (cinfo->min_DCT_v_scaled_size + 1);
|
||||
mainp->rowgroups_avail = (JDIMENSION) (cinfo->min_DCT_v_scaled_size + 2);
|
||||
mainp->context_state = CTX_POSTPONED_ROW;
|
||||
}
|
||||
}
|
||||
|
||||
@ -457,33 +458,33 @@ process_data_context_main (j_decompress_ptr cinfo,
|
||||
|
||||
METHODDEF(void)
|
||||
process_data_crank_post (j_decompress_ptr cinfo,
|
||||
JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
|
||||
JDIMENSION out_rows_avail)
|
||||
JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
|
||||
JDIMENSION out_rows_avail)
|
||||
{
|
||||
(*cinfo->post->post_process_data) (cinfo, (JSAMPIMAGE) NULL,
|
||||
(JDIMENSION *) NULL, (JDIMENSION) 0,
|
||||
output_buf, out_row_ctr, out_rows_avail);
|
||||
(JDIMENSION *) NULL, (JDIMENSION) 0,
|
||||
output_buf, out_row_ctr, out_rows_avail);
|
||||
}
|
||||
|
||||
#endif /* QUANT_2PASS_SUPPORTED */
|
||||
|
||||
|
||||
/*
|
||||
* Initialize main_ptr buffer controller.
|
||||
* Initialize main buffer controller.
|
||||
*/
|
||||
|
||||
GLOBAL(void)
|
||||
jinit_d_main_controller (j_decompress_ptr cinfo, boolean need_full_buffer)
|
||||
{
|
||||
my_main_ptr main_ptr;
|
||||
my_main_ptr mainp;
|
||||
int ci, rgroup, ngroups;
|
||||
jpeg_component_info *compptr;
|
||||
|
||||
main_ptr = (my_main_ptr)
|
||||
mainp = (my_main_ptr)
|
||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
||||
SIZEOF(my_main_controller));
|
||||
cinfo->main = (struct jpeg_d_main_controller *) main_ptr;
|
||||
main_ptr->pub.start_pass = start_pass_main;
|
||||
SIZEOF(my_main_controller));
|
||||
cinfo->main = &mainp->pub;
|
||||
mainp->pub.start_pass = start_pass_main;
|
||||
|
||||
if (need_full_buffer) /* shouldn't happen */
|
||||
ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
|
||||
@ -492,21 +493,21 @@ jinit_d_main_controller (j_decompress_ptr cinfo, boolean need_full_buffer)
|
||||
* ngroups is the number of row groups we need.
|
||||
*/
|
||||
if (cinfo->upsample->need_context_rows) {
|
||||
if (cinfo->min_DCT_scaled_size < 2) /* unsupported, see comments above */
|
||||
if (cinfo->min_DCT_v_scaled_size < 2) /* unsupported, see comments above */
|
||||
ERREXIT(cinfo, JERR_NOTIMPL);
|
||||
alloc_funny_pointers(cinfo); /* Alloc space for xbuffer[] lists */
|
||||
ngroups = cinfo->min_DCT_scaled_size + 2;
|
||||
ngroups = cinfo->min_DCT_v_scaled_size + 2;
|
||||
} else {
|
||||
ngroups = cinfo->min_DCT_scaled_size;
|
||||
ngroups = cinfo->min_DCT_v_scaled_size;
|
||||
}
|
||||
|
||||
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
|
||||
ci++, compptr++) {
|
||||
rgroup = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
|
||||
cinfo->min_DCT_scaled_size; /* height of a row group of component */
|
||||
main_ptr->buffer[ci] = (*cinfo->mem->alloc_sarray)
|
||||
((j_common_ptr) cinfo, JPOOL_IMAGE,
|
||||
compptr->width_in_blocks * compptr->DCT_scaled_size,
|
||||
(JDIMENSION) (rgroup * ngroups));
|
||||
rgroup = (compptr->v_samp_factor * compptr->DCT_v_scaled_size) /
|
||||
cinfo->min_DCT_v_scaled_size; /* height of a row group of component */
|
||||
mainp->buffer[ci] = (*cinfo->mem->alloc_sarray)
|
||||
((j_common_ptr) cinfo, JPOOL_IMAGE,
|
||||
compptr->width_in_blocks * ((JDIMENSION) compptr->DCT_h_scaled_size),
|
||||
(JDIMENSION) (rgroup * ngroups));
|
||||
}
|
||||
}
|
||||
|
369
3rdparty/libjpeg/jdmarker.c
vendored
369
3rdparty/libjpeg/jdmarker.c
vendored
@ -2,6 +2,7 @@
|
||||
* jdmarker.c
|
||||
*
|
||||
* Copyright (C) 1991-1998, Thomas G. Lane.
|
||||
* Modified 2009-2012 by Guido Vollbeding.
|
||||
* This file is part of the Independent JPEG Group's software.
|
||||
* For conditions of distribution and use, see the accompanying README file.
|
||||
*
|
||||
@ -76,6 +77,7 @@ typedef enum { /* JPEG marker codes */
|
||||
M_APP15 = 0xef,
|
||||
|
||||
M_JPG0 = 0xf0,
|
||||
M_JPG8 = 0xf8,
|
||||
M_JPG13 = 0xfd,
|
||||
M_COM = 0xfe,
|
||||
|
||||
@ -117,49 +119,49 @@ typedef my_marker_reader * my_marker_ptr;
|
||||
|
||||
/* Declare and initialize local copies of input pointer/count */
|
||||
#define INPUT_VARS(cinfo) \
|
||||
struct jpeg_source_mgr * datasrc = (cinfo)->src; \
|
||||
const JOCTET * next_input_byte = datasrc->next_input_byte; \
|
||||
size_t bytes_in_buffer = datasrc->bytes_in_buffer
|
||||
struct jpeg_source_mgr * datasrc = (cinfo)->src; \
|
||||
const JOCTET * next_input_byte = datasrc->next_input_byte; \
|
||||
size_t bytes_in_buffer = datasrc->bytes_in_buffer
|
||||
|
||||
/* Unload the local copies --- do this only at a restart boundary */
|
||||
#define INPUT_SYNC(cinfo) \
|
||||
( datasrc->next_input_byte = next_input_byte, \
|
||||
datasrc->bytes_in_buffer = bytes_in_buffer )
|
||||
( datasrc->next_input_byte = next_input_byte, \
|
||||
datasrc->bytes_in_buffer = bytes_in_buffer )
|
||||
|
||||
/* Reload the local copies --- used only in MAKE_BYTE_AVAIL */
|
||||
#define INPUT_RELOAD(cinfo) \
|
||||
( next_input_byte = datasrc->next_input_byte, \
|
||||
bytes_in_buffer = datasrc->bytes_in_buffer )
|
||||
( next_input_byte = datasrc->next_input_byte, \
|
||||
bytes_in_buffer = datasrc->bytes_in_buffer )
|
||||
|
||||
/* Internal macro for INPUT_BYTE and INPUT_2BYTES: make a byte available.
|
||||
* Note we do *not* do INPUT_SYNC before calling fill_input_buffer,
|
||||
* but we must reload the local copies after a successful fill.
|
||||
*/
|
||||
#define MAKE_BYTE_AVAIL(cinfo,action) \
|
||||
if (bytes_in_buffer == 0) { \
|
||||
if (! (*datasrc->fill_input_buffer) (cinfo)) \
|
||||
{ action; } \
|
||||
INPUT_RELOAD(cinfo); \
|
||||
}
|
||||
if (bytes_in_buffer == 0) { \
|
||||
if (! (*datasrc->fill_input_buffer) (cinfo)) \
|
||||
{ action; } \
|
||||
INPUT_RELOAD(cinfo); \
|
||||
}
|
||||
|
||||
/* Read a byte into variable V.
|
||||
* If must suspend, take the specified action (typically "return FALSE").
|
||||
*/
|
||||
#define INPUT_BYTE(cinfo,V,action) \
|
||||
MAKESTMT( MAKE_BYTE_AVAIL(cinfo,action); \
|
||||
bytes_in_buffer--; \
|
||||
V = GETJOCTET(*next_input_byte++); )
|
||||
MAKESTMT( MAKE_BYTE_AVAIL(cinfo,action); \
|
||||
bytes_in_buffer--; \
|
||||
V = GETJOCTET(*next_input_byte++); )
|
||||
|
||||
/* As above, but read two bytes interpreted as an unsigned 16-bit integer.
|
||||
* V should be declared unsigned int or perhaps INT32.
|
||||
*/
|
||||
#define INPUT_2BYTES(cinfo,V,action) \
|
||||
MAKESTMT( MAKE_BYTE_AVAIL(cinfo,action); \
|
||||
bytes_in_buffer--; \
|
||||
V = ((unsigned int) GETJOCTET(*next_input_byte++)) << 8; \
|
||||
MAKE_BYTE_AVAIL(cinfo,action); \
|
||||
bytes_in_buffer--; \
|
||||
V += GETJOCTET(*next_input_byte++); )
|
||||
MAKESTMT( MAKE_BYTE_AVAIL(cinfo,action); \
|
||||
bytes_in_buffer--; \
|
||||
V = ((unsigned int) GETJOCTET(*next_input_byte++)) << 8; \
|
||||
MAKE_BYTE_AVAIL(cinfo,action); \
|
||||
bytes_in_buffer--; \
|
||||
V += GETJOCTET(*next_input_byte++); )
|
||||
|
||||
|
||||
/*
|
||||
@ -216,6 +218,7 @@ get_soi (j_decompress_ptr cinfo)
|
||||
/* Set initial assumptions for colorspace etc */
|
||||
|
||||
cinfo->jpeg_color_space = JCS_UNKNOWN;
|
||||
cinfo->color_transform = JCT_NONE;
|
||||
cinfo->CCIR601_sampling = FALSE; /* Assume non-CCIR sampling??? */
|
||||
|
||||
cinfo->saw_JFIF_marker = FALSE;
|
||||
@ -234,14 +237,16 @@ get_soi (j_decompress_ptr cinfo)
|
||||
|
||||
|
||||
LOCAL(boolean)
|
||||
get_sof (j_decompress_ptr cinfo, boolean is_prog, boolean is_arith)
|
||||
get_sof (j_decompress_ptr cinfo, boolean is_baseline, boolean is_prog,
|
||||
boolean is_arith)
|
||||
/* Process a SOFn marker */
|
||||
{
|
||||
INT32 length;
|
||||
int c, ci;
|
||||
int c, ci, i;
|
||||
jpeg_component_info * compptr;
|
||||
INPUT_VARS(cinfo);
|
||||
|
||||
cinfo->is_baseline = is_baseline;
|
||||
cinfo->progressive_mode = is_prog;
|
||||
cinfo->arith_code = is_arith;
|
||||
|
||||
@ -255,8 +260,8 @@ get_sof (j_decompress_ptr cinfo, boolean is_prog, boolean is_arith)
|
||||
length -= 8;
|
||||
|
||||
TRACEMS4(cinfo, 1, JTRC_SOF, cinfo->unread_marker,
|
||||
(int) cinfo->image_width, (int) cinfo->image_height,
|
||||
cinfo->num_components);
|
||||
(int) cinfo->image_width, (int) cinfo->image_height,
|
||||
cinfo->num_components);
|
||||
|
||||
if (cinfo->marker->saw_SOF)
|
||||
ERREXIT(cinfo, JERR_SOF_DUPLICATE);
|
||||
@ -273,21 +278,37 @@ get_sof (j_decompress_ptr cinfo, boolean is_prog, boolean is_arith)
|
||||
|
||||
if (cinfo->comp_info == NULL) /* do only once, even if suspend */
|
||||
cinfo->comp_info = (jpeg_component_info *) (*cinfo->mem->alloc_small)
|
||||
((j_common_ptr) cinfo, JPOOL_IMAGE,
|
||||
cinfo->num_components * SIZEOF(jpeg_component_info));
|
||||
((j_common_ptr) cinfo, JPOOL_IMAGE,
|
||||
cinfo->num_components * SIZEOF(jpeg_component_info));
|
||||
|
||||
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
|
||||
ci++, compptr++) {
|
||||
for (ci = 0; ci < cinfo->num_components; ci++) {
|
||||
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;
|
||||
INPUT_BYTE(cinfo, compptr->component_id, return FALSE);
|
||||
INPUT_BYTE(cinfo, c, return FALSE);
|
||||
compptr->h_samp_factor = (c >> 4) & 15;
|
||||
compptr->v_samp_factor = (c ) & 15;
|
||||
INPUT_BYTE(cinfo, compptr->quant_tbl_no, return FALSE);
|
||||
|
||||
TRACEMS4(cinfo, 1, JTRC_SOF_COMPONENT,
|
||||
compptr->component_id, compptr->h_samp_factor,
|
||||
compptr->v_samp_factor, compptr->quant_tbl_no);
|
||||
compptr->component_id, compptr->h_samp_factor,
|
||||
compptr->v_samp_factor, compptr->quant_tbl_no);
|
||||
}
|
||||
|
||||
cinfo->marker->saw_SOF = TRUE;
|
||||
@ -302,12 +323,12 @@ get_sos (j_decompress_ptr cinfo)
|
||||
/* Process a SOS marker */
|
||||
{
|
||||
INT32 length;
|
||||
int i, ci, n, c, cc;
|
||||
int c, ci, i, n;
|
||||
jpeg_component_info * compptr;
|
||||
INPUT_VARS(cinfo);
|
||||
|
||||
if (! cinfo->marker->saw_SOF)
|
||||
ERREXIT(cinfo, JERR_SOS_NO_SOF);
|
||||
ERREXITS(cinfo, JERR_SOF_BEFORE, "SOS");
|
||||
|
||||
INPUT_2BYTES(cinfo, length, return FALSE);
|
||||
|
||||
@ -315,7 +336,9 @@ get_sos (j_decompress_ptr cinfo)
|
||||
|
||||
TRACEMS1(cinfo, 1, JTRC_SOS, n);
|
||||
|
||||
if (length != (n * 2 + 6) || n < 1 || n > MAX_COMPS_IN_SCAN)
|
||||
if (length != (n * 2 + 6) || n > MAX_COMPS_IN_SCAN ||
|
||||
(n == 0 && !cinfo->progressive_mode))
|
||||
/* pseudo SOS marker only allowed in progressive mode */
|
||||
ERREXIT(cinfo, JERR_BAD_LENGTH);
|
||||
|
||||
cinfo->comps_in_scan = n;
|
||||
@ -323,25 +346,39 @@ get_sos (j_decompress_ptr cinfo)
|
||||
/* Collect the component-spec parameters */
|
||||
|
||||
for (i = 0; i < n; i++) {
|
||||
INPUT_BYTE(cinfo, cc, return FALSE);
|
||||
INPUT_BYTE(cinfo, c, return FALSE);
|
||||
|
||||
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
|
||||
ci++, compptr++) {
|
||||
if (cc == compptr->component_id)
|
||||
goto id_found;
|
||||
/* 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. */
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
ERREXIT1(cinfo, JERR_BAD_COMPONENT_ID, cc);
|
||||
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
|
||||
ci++, compptr++) {
|
||||
if (c == compptr->component_id)
|
||||
goto id_found;
|
||||
}
|
||||
|
||||
ERREXIT1(cinfo, JERR_BAD_COMPONENT_ID, c);
|
||||
|
||||
id_found:
|
||||
|
||||
cinfo->cur_comp_info[i] = compptr;
|
||||
INPUT_BYTE(cinfo, c, return FALSE);
|
||||
compptr->dc_tbl_no = (c >> 4) & 15;
|
||||
compptr->ac_tbl_no = (c ) & 15;
|
||||
|
||||
TRACEMS3(cinfo, 1, JTRC_SOS_COMPONENT, cc,
|
||||
compptr->dc_tbl_no, compptr->ac_tbl_no);
|
||||
TRACEMS3(cinfo, 1, JTRC_SOS_COMPONENT, compptr->component_id,
|
||||
compptr->dc_tbl_no, compptr->ac_tbl_no);
|
||||
}
|
||||
|
||||
/* Collect the additional scan parameters Ss, Se, Ah/Al. */
|
||||
@ -354,13 +391,13 @@ get_sos (j_decompress_ptr cinfo)
|
||||
cinfo->Al = (c ) & 15;
|
||||
|
||||
TRACEMS4(cinfo, 1, JTRC_SOS_PARAMS, cinfo->Ss, cinfo->Se,
|
||||
cinfo->Ah, cinfo->Al);
|
||||
cinfo->Ah, cinfo->Al);
|
||||
|
||||
/* Prepare to scan data & restart markers */
|
||||
cinfo->marker->next_restart_num = 0;
|
||||
|
||||
/* Count another SOS marker */
|
||||
cinfo->input_scan_number++;
|
||||
/* Count another (non-pseudo) SOS marker */
|
||||
if (n) cinfo->input_scan_number++;
|
||||
|
||||
INPUT_SYNC(cinfo);
|
||||
return TRUE;
|
||||
@ -397,7 +434,7 @@ get_dac (j_decompress_ptr cinfo)
|
||||
cinfo->arith_dc_L[index] = (UINT8) (val & 0x0F);
|
||||
cinfo->arith_dc_U[index] = (UINT8) (val >> 4);
|
||||
if (cinfo->arith_dc_L[index] > cinfo->arith_dc_U[index])
|
||||
ERREXIT1(cinfo, JERR_DAC_VALUE, val);
|
||||
ERREXIT1(cinfo, JERR_DAC_VALUE, val);
|
||||
}
|
||||
}
|
||||
|
||||
@ -444,11 +481,11 @@ get_dht (j_decompress_ptr cinfo)
|
||||
length -= 1 + 16;
|
||||
|
||||
TRACEMS8(cinfo, 2, JTRC_HUFFBITS,
|
||||
bits[1], bits[2], bits[3], bits[4],
|
||||
bits[5], bits[6], bits[7], bits[8]);
|
||||
bits[1], bits[2], bits[3], bits[4],
|
||||
bits[5], bits[6], bits[7], bits[8]);
|
||||
TRACEMS8(cinfo, 2, JTRC_HUFFBITS,
|
||||
bits[9], bits[10], bits[11], bits[12],
|
||||
bits[13], bits[14], bits[15], bits[16]);
|
||||
bits[9], bits[10], bits[11], bits[12],
|
||||
bits[13], bits[14], bits[15], bits[16]);
|
||||
|
||||
/* Here we just do minimal validation of the counts to avoid walking
|
||||
* off the end of our table space. jdhuff.c will check more carefully.
|
||||
@ -490,16 +527,18 @@ LOCAL(boolean)
|
||||
get_dqt (j_decompress_ptr cinfo)
|
||||
/* Process a DQT marker */
|
||||
{
|
||||
INT32 length;
|
||||
int n, i, prec;
|
||||
INT32 length, count, i;
|
||||
int n, prec;
|
||||
unsigned int tmp;
|
||||
JQUANT_TBL *quant_ptr;
|
||||
const int *natural_order;
|
||||
INPUT_VARS(cinfo);
|
||||
|
||||
INPUT_2BYTES(cinfo, length, return FALSE);
|
||||
length -= 2;
|
||||
|
||||
while (length > 0) {
|
||||
length--;
|
||||
INPUT_BYTE(cinfo, n, return FALSE);
|
||||
prec = n >> 4;
|
||||
n &= 0x0F;
|
||||
@ -513,27 +552,57 @@ get_dqt (j_decompress_ptr cinfo)
|
||||
cinfo->quant_tbl_ptrs[n] = jpeg_alloc_quant_table((j_common_ptr) cinfo);
|
||||
quant_ptr = cinfo->quant_tbl_ptrs[n];
|
||||
|
||||
for (i = 0; i < DCTSIZE2; i++) {
|
||||
if (prec) {
|
||||
if (length < DCTSIZE2 * 2) {
|
||||
/* Initialize full table for safety. */
|
||||
for (i = 0; i < DCTSIZE2; i++) {
|
||||
quant_ptr->quantval[i] = 1;
|
||||
}
|
||||
count = length >> 1;
|
||||
} else
|
||||
count = DCTSIZE2;
|
||||
} else {
|
||||
if (length < DCTSIZE2) {
|
||||
/* Initialize full table for safety. */
|
||||
for (i = 0; i < DCTSIZE2; i++) {
|
||||
quant_ptr->quantval[i] = 1;
|
||||
}
|
||||
count = length;
|
||||
} else
|
||||
count = DCTSIZE2;
|
||||
}
|
||||
|
||||
switch (count) {
|
||||
case (2*2): natural_order = jpeg_natural_order2; break;
|
||||
case (3*3): natural_order = jpeg_natural_order3; break;
|
||||
case (4*4): natural_order = jpeg_natural_order4; break;
|
||||
case (5*5): natural_order = jpeg_natural_order5; break;
|
||||
case (6*6): natural_order = jpeg_natural_order6; break;
|
||||
case (7*7): natural_order = jpeg_natural_order7; break;
|
||||
default: natural_order = jpeg_natural_order; break;
|
||||
}
|
||||
|
||||
for (i = 0; i < count; i++) {
|
||||
if (prec)
|
||||
INPUT_2BYTES(cinfo, tmp, return FALSE);
|
||||
INPUT_2BYTES(cinfo, tmp, return FALSE);
|
||||
else
|
||||
INPUT_BYTE(cinfo, tmp, return FALSE);
|
||||
INPUT_BYTE(cinfo, tmp, return FALSE);
|
||||
/* We convert the zigzag-order table to natural array order. */
|
||||
quant_ptr->quantval[jpeg_natural_order[i]] = (UINT16) tmp;
|
||||
quant_ptr->quantval[natural_order[i]] = (UINT16) tmp;
|
||||
}
|
||||
|
||||
if (cinfo->err->trace_level >= 2) {
|
||||
for (i = 0; i < DCTSIZE2; i += 8) {
|
||||
TRACEMS8(cinfo, 2, JTRC_QUANTVALS,
|
||||
quant_ptr->quantval[i], quant_ptr->quantval[i+1],
|
||||
quant_ptr->quantval[i+2], quant_ptr->quantval[i+3],
|
||||
quant_ptr->quantval[i+4], quant_ptr->quantval[i+5],
|
||||
quant_ptr->quantval[i+6], quant_ptr->quantval[i+7]);
|
||||
TRACEMS8(cinfo, 2, JTRC_QUANTVALS,
|
||||
quant_ptr->quantval[i], quant_ptr->quantval[i+1],
|
||||
quant_ptr->quantval[i+2], quant_ptr->quantval[i+3],
|
||||
quant_ptr->quantval[i+4], quant_ptr->quantval[i+5],
|
||||
quant_ptr->quantval[i+6], quant_ptr->quantval[i+7]);
|
||||
}
|
||||
}
|
||||
|
||||
length -= DCTSIZE2+1;
|
||||
if (prec) length -= DCTSIZE2;
|
||||
length -= count;
|
||||
if (prec) length -= count;
|
||||
}
|
||||
|
||||
if (length != 0)
|
||||
@ -568,6 +637,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.
|
||||
* These are either saved in memory or discarded, per application request.
|
||||
@ -582,7 +713,7 @@ get_dri (j_decompress_ptr cinfo)
|
||||
|
||||
LOCAL(void)
|
||||
examine_app0 (j_decompress_ptr cinfo, JOCTET FAR * data,
|
||||
unsigned int datalen, INT32 remaining)
|
||||
unsigned int datalen, INT32 remaining)
|
||||
/* Examine first few bytes from an APP0.
|
||||
* Take appropriate action if it is a JFIF marker.
|
||||
* datalen is # of bytes at data[], remaining is length of rest of marker data.
|
||||
@ -611,18 +742,18 @@ examine_app0 (j_decompress_ptr cinfo, JOCTET FAR * data,
|
||||
*/
|
||||
if (cinfo->JFIF_major_version != 1)
|
||||
WARNMS2(cinfo, JWRN_JFIF_MAJOR,
|
||||
cinfo->JFIF_major_version, cinfo->JFIF_minor_version);
|
||||
cinfo->JFIF_major_version, cinfo->JFIF_minor_version);
|
||||
/* Generate trace messages */
|
||||
TRACEMS5(cinfo, 1, JTRC_JFIF,
|
||||
cinfo->JFIF_major_version, cinfo->JFIF_minor_version,
|
||||
cinfo->X_density, cinfo->Y_density, cinfo->density_unit);
|
||||
cinfo->JFIF_major_version, cinfo->JFIF_minor_version,
|
||||
cinfo->X_density, cinfo->Y_density, cinfo->density_unit);
|
||||
/* Validate thumbnail dimensions and issue appropriate messages */
|
||||
if (GETJOCTET(data[12]) | GETJOCTET(data[13]))
|
||||
TRACEMS2(cinfo, 1, JTRC_JFIF_THUMBNAIL,
|
||||
GETJOCTET(data[12]), GETJOCTET(data[13]));
|
||||
GETJOCTET(data[12]), GETJOCTET(data[13]));
|
||||
totallen -= APP0_DATA_LEN;
|
||||
if (totallen !=
|
||||
((INT32)GETJOCTET(data[12]) * (INT32)GETJOCTET(data[13]) * (INT32) 3))
|
||||
((INT32)GETJOCTET(data[12]) * (INT32)GETJOCTET(data[13]) * (INT32) 3))
|
||||
TRACEMS1(cinfo, 1, JTRC_JFIF_BADTHUMBNAILSIZE, (int) totallen);
|
||||
} else if (datalen >= 6 &&
|
||||
GETJOCTET(data[0]) == 0x4A &&
|
||||
@ -646,7 +777,7 @@ examine_app0 (j_decompress_ptr cinfo, JOCTET FAR * data,
|
||||
break;
|
||||
default:
|
||||
TRACEMS2(cinfo, 1, JTRC_JFIF_EXTENSION,
|
||||
GETJOCTET(data[5]), (int) totallen);
|
||||
GETJOCTET(data[5]), (int) totallen);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
@ -658,7 +789,7 @@ examine_app0 (j_decompress_ptr cinfo, JOCTET FAR * data,
|
||||
|
||||
LOCAL(void)
|
||||
examine_app14 (j_decompress_ptr cinfo, JOCTET FAR * data,
|
||||
unsigned int datalen, INT32 remaining)
|
||||
unsigned int datalen, INT32 remaining)
|
||||
/* Examine first few bytes from an APP14.
|
||||
* Take appropriate action if it is an Adobe marker.
|
||||
* datalen is # of bytes at data[], remaining is length of rest of marker data.
|
||||
@ -754,15 +885,15 @@ save_marker (j_decompress_ptr cinfo)
|
||||
/* figure out how much we want to save */
|
||||
unsigned int limit;
|
||||
if (cinfo->unread_marker == (int) M_COM)
|
||||
limit = marker->length_limit_COM;
|
||||
limit = marker->length_limit_COM;
|
||||
else
|
||||
limit = marker->length_limit_APPn[cinfo->unread_marker - (int) M_APP0];
|
||||
limit = marker->length_limit_APPn[cinfo->unread_marker - (int) M_APP0];
|
||||
if ((unsigned int) length < limit)
|
||||
limit = (unsigned int) length;
|
||||
limit = (unsigned int) length;
|
||||
/* allocate and initialize the marker item */
|
||||
cur_marker = (jpeg_saved_marker_ptr)
|
||||
(*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
||||
SIZEOF(struct jpeg_marker_struct) + limit);
|
||||
(*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
||||
SIZEOF(struct jpeg_marker_struct) + limit);
|
||||
cur_marker->next = NULL;
|
||||
cur_marker->marker = (UINT8) cinfo->unread_marker;
|
||||
cur_marker->original_length = (unsigned int) length;
|
||||
@ -806,7 +937,7 @@ save_marker (j_decompress_ptr cinfo)
|
||||
} else {
|
||||
jpeg_saved_marker_ptr prev = cinfo->marker_list;
|
||||
while (prev->next != NULL)
|
||||
prev = prev->next;
|
||||
prev = prev->next;
|
||||
prev->next = cur_marker;
|
||||
}
|
||||
/* Reset pointer & calc remaining data length */
|
||||
@ -826,7 +957,7 @@ save_marker (j_decompress_ptr cinfo)
|
||||
break;
|
||||
default:
|
||||
TRACEMS2(cinfo, 1, JTRC_MISC_MARKER, cinfo->unread_marker,
|
||||
(int) (data_length + length));
|
||||
(int) (data_length + length));
|
||||
break;
|
||||
}
|
||||
|
||||
@ -946,6 +1077,11 @@ first_marker (j_decompress_ptr cinfo)
|
||||
*
|
||||
* Returns same codes as are defined for jpeg_consume_input:
|
||||
* JPEG_SUSPENDED, JPEG_REACHED_SOS, or JPEG_REACHED_EOI.
|
||||
*
|
||||
* Note: This function may return a pseudo SOS marker (with zero
|
||||
* component number) for treat by input controller's consume_input.
|
||||
* consume_input itself should filter out (skip) the pseudo marker
|
||||
* after processing for the caller.
|
||||
*/
|
||||
|
||||
METHODDEF(int)
|
||||
@ -957,11 +1093,11 @@ read_markers (j_decompress_ptr cinfo)
|
||||
/* NB: first_marker() enforces the requirement that SOI appear first. */
|
||||
if (cinfo->unread_marker == 0) {
|
||||
if (! cinfo->marker->saw_SOI) {
|
||||
if (! first_marker(cinfo))
|
||||
return JPEG_SUSPENDED;
|
||||
if (! first_marker(cinfo))
|
||||
return JPEG_SUSPENDED;
|
||||
} else {
|
||||
if (! next_marker(cinfo))
|
||||
return JPEG_SUSPENDED;
|
||||
if (! next_marker(cinfo))
|
||||
return JPEG_SUSPENDED;
|
||||
}
|
||||
}
|
||||
/* At this point cinfo->unread_marker contains the marker code and the
|
||||
@ -971,28 +1107,32 @@ read_markers (j_decompress_ptr cinfo)
|
||||
switch (cinfo->unread_marker) {
|
||||
case M_SOI:
|
||||
if (! get_soi(cinfo))
|
||||
return JPEG_SUSPENDED;
|
||||
return JPEG_SUSPENDED;
|
||||
break;
|
||||
|
||||
case M_SOF0: /* Baseline */
|
||||
if (! get_sof(cinfo, TRUE, FALSE, FALSE))
|
||||
return JPEG_SUSPENDED;
|
||||
break;
|
||||
|
||||
case M_SOF1: /* Extended sequential, Huffman */
|
||||
if (! get_sof(cinfo, FALSE, FALSE))
|
||||
return JPEG_SUSPENDED;
|
||||
if (! get_sof(cinfo, FALSE, FALSE, FALSE))
|
||||
return JPEG_SUSPENDED;
|
||||
break;
|
||||
|
||||
case M_SOF2: /* Progressive, Huffman */
|
||||
if (! get_sof(cinfo, TRUE, FALSE))
|
||||
return JPEG_SUSPENDED;
|
||||
if (! get_sof(cinfo, FALSE, TRUE, FALSE))
|
||||
return JPEG_SUSPENDED;
|
||||
break;
|
||||
|
||||
case M_SOF9: /* Extended sequential, arithmetic */
|
||||
if (! get_sof(cinfo, FALSE, TRUE))
|
||||
return JPEG_SUSPENDED;
|
||||
if (! get_sof(cinfo, FALSE, FALSE, TRUE))
|
||||
return JPEG_SUSPENDED;
|
||||
break;
|
||||
|
||||
case M_SOF10: /* Progressive, arithmetic */
|
||||
if (! get_sof(cinfo, TRUE, TRUE))
|
||||
return JPEG_SUSPENDED;
|
||||
if (! get_sof(cinfo, FALSE, TRUE, TRUE))
|
||||
return JPEG_SUSPENDED;
|
||||
break;
|
||||
|
||||
/* Currently unsupported SOFn types */
|
||||
@ -1010,7 +1150,7 @@ read_markers (j_decompress_ptr cinfo)
|
||||
|
||||
case M_SOS:
|
||||
if (! get_sos(cinfo))
|
||||
return JPEG_SUSPENDED;
|
||||
return JPEG_SUSPENDED;
|
||||
cinfo->unread_marker = 0; /* processed the marker */
|
||||
return JPEG_REACHED_SOS;
|
||||
|
||||
@ -1021,22 +1161,27 @@ read_markers (j_decompress_ptr cinfo)
|
||||
|
||||
case M_DAC:
|
||||
if (! get_dac(cinfo))
|
||||
return JPEG_SUSPENDED;
|
||||
return JPEG_SUSPENDED;
|
||||
break;
|
||||
|
||||
case M_DHT:
|
||||
if (! get_dht(cinfo))
|
||||
return JPEG_SUSPENDED;
|
||||
return JPEG_SUSPENDED;
|
||||
break;
|
||||
|
||||
case M_DQT:
|
||||
if (! get_dqt(cinfo))
|
||||
return JPEG_SUSPENDED;
|
||||
return JPEG_SUSPENDED;
|
||||
break;
|
||||
|
||||
case M_DRI:
|
||||
if (! get_dri(cinfo))
|
||||
return JPEG_SUSPENDED;
|
||||
return JPEG_SUSPENDED;
|
||||
break;
|
||||
|
||||
case M_JPG8:
|
||||
if (! get_lse(cinfo))
|
||||
return JPEG_SUSPENDED;
|
||||
break;
|
||||
|
||||
case M_APP0:
|
||||
@ -1056,13 +1201,13 @@ read_markers (j_decompress_ptr cinfo)
|
||||
case M_APP14:
|
||||
case M_APP15:
|
||||
if (! (*((my_marker_ptr) cinfo->marker)->process_APPn[
|
||||
cinfo->unread_marker - (int) M_APP0]) (cinfo))
|
||||
return JPEG_SUSPENDED;
|
||||
cinfo->unread_marker - (int) M_APP0]) (cinfo))
|
||||
return JPEG_SUSPENDED;
|
||||
break;
|
||||
|
||||
case M_COM:
|
||||
if (! (*((my_marker_ptr) cinfo->marker)->process_COM) (cinfo))
|
||||
return JPEG_SUSPENDED;
|
||||
return JPEG_SUSPENDED;
|
||||
break;
|
||||
|
||||
case M_RST0: /* these are all parameterless */
|
||||
@ -1079,7 +1224,7 @@ read_markers (j_decompress_ptr cinfo)
|
||||
|
||||
case M_DNL: /* Ignore DNL ... perhaps the wrong thing */
|
||||
if (! skip_variable(cinfo))
|
||||
return JPEG_SUSPENDED;
|
||||
return JPEG_SUSPENDED;
|
||||
break;
|
||||
|
||||
default: /* must be DHP, EXP, JPGn, or RESn */
|
||||
@ -1128,7 +1273,7 @@ read_restart_marker (j_decompress_ptr cinfo)
|
||||
/* Uh-oh, the restart markers have been messed up. */
|
||||
/* Let the data source manager determine how to resync. */
|
||||
if (! (*cinfo->src->resync_to_restart) (cinfo,
|
||||
cinfo->marker->next_restart_num))
|
||||
cinfo->marker->next_restart_num))
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
@ -1205,13 +1350,13 @@ jpeg_resync_to_restart (j_decompress_ptr cinfo, int desired)
|
||||
action = 3; /* valid non-restart marker */
|
||||
else {
|
||||
if (marker == ((int) M_RST0 + ((desired+1) & 7)) ||
|
||||
marker == ((int) M_RST0 + ((desired+2) & 7)))
|
||||
action = 3; /* one of the next two expected restarts */
|
||||
marker == ((int) M_RST0 + ((desired+2) & 7)))
|
||||
action = 3; /* one of the next two expected restarts */
|
||||
else if (marker == ((int) M_RST0 + ((desired-1) & 7)) ||
|
||||
marker == ((int) M_RST0 + ((desired-2) & 7)))
|
||||
action = 2; /* a prior restart, so advance */
|
||||
marker == ((int) M_RST0 + ((desired-2) & 7)))
|
||||
action = 2; /* a prior restart, so advance */
|
||||
else
|
||||
action = 1; /* desired restart or too far away */
|
||||
action = 1; /* desired restart or too far away */
|
||||
}
|
||||
TRACEMS2(cinfo, 4, JTRC_RECOVERY_ACTION, marker, action);
|
||||
switch (action) {
|
||||
@ -1222,7 +1367,7 @@ jpeg_resync_to_restart (j_decompress_ptr cinfo, int desired)
|
||||
case 2:
|
||||
/* Scan to the next marker, and repeat the decision loop. */
|
||||
if (! next_marker(cinfo))
|
||||
return FALSE;
|
||||
return FALSE;
|
||||
marker = cinfo->unread_marker;
|
||||
break;
|
||||
case 3:
|
||||
@ -1267,8 +1412,8 @@ jinit_marker_reader (j_decompress_ptr cinfo)
|
||||
/* Create subobject in permanent pool */
|
||||
marker = (my_marker_ptr)
|
||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
|
||||
SIZEOF(my_marker_reader));
|
||||
cinfo->marker = (struct jpeg_marker_reader *) marker;
|
||||
SIZEOF(my_marker_reader));
|
||||
cinfo->marker = &marker->pub;
|
||||
/* Initialize public method pointers */
|
||||
marker->pub.reset_marker_reader = reset_marker_reader;
|
||||
marker->pub.read_markers = read_markers;
|
||||
@ -1298,7 +1443,7 @@ jinit_marker_reader (j_decompress_ptr cinfo)
|
||||
|
||||
GLOBAL(void)
|
||||
jpeg_save_markers (j_decompress_ptr cinfo, int marker_code,
|
||||
unsigned int length_limit)
|
||||
unsigned int length_limit)
|
||||
{
|
||||
my_marker_ptr marker = (my_marker_ptr) cinfo->marker;
|
||||
long maxlength;
|
||||
@ -1347,7 +1492,7 @@ jpeg_save_markers (j_decompress_ptr cinfo, int marker_code,
|
||||
|
||||
GLOBAL(void)
|
||||
jpeg_set_marker_processor (j_decompress_ptr cinfo, int marker_code,
|
||||
jpeg_marker_parser_method routine)
|
||||
jpeg_marker_parser_method routine)
|
||||
{
|
||||
my_marker_ptr marker = (my_marker_ptr) cinfo->marker;
|
||||
|
||||
|
132
3rdparty/libjpeg/jdmaster.c
vendored
132
3rdparty/libjpeg/jdmaster.c
vendored
@ -2,6 +2,7 @@
|
||||
* jdmaster.c
|
||||
*
|
||||
* Copyright (C) 1991-1997, Thomas G. Lane.
|
||||
* Modified 2002-2011 by Guido Vollbeding.
|
||||
* This file is part of the Independent JPEG Group's software.
|
||||
* For conditions of distribution and use, see the accompanying README file.
|
||||
*
|
||||
@ -61,9 +62,12 @@ use_merged_upsample (j_decompress_ptr cinfo)
|
||||
cinfo->comp_info[2].v_samp_factor != 1)
|
||||
return FALSE;
|
||||
/* furthermore, it doesn't work if we've scaled the IDCTs differently */
|
||||
if (cinfo->comp_info[0].DCT_scaled_size != cinfo->min_DCT_scaled_size ||
|
||||
cinfo->comp_info[1].DCT_scaled_size != cinfo->min_DCT_scaled_size ||
|
||||
cinfo->comp_info[2].DCT_scaled_size != cinfo->min_DCT_scaled_size)
|
||||
if (cinfo->comp_info[0].DCT_h_scaled_size != cinfo->min_DCT_h_scaled_size ||
|
||||
cinfo->comp_info[1].DCT_h_scaled_size != cinfo->min_DCT_h_scaled_size ||
|
||||
cinfo->comp_info[2].DCT_h_scaled_size != cinfo->min_DCT_h_scaled_size ||
|
||||
cinfo->comp_info[0].DCT_v_scaled_size != cinfo->min_DCT_v_scaled_size ||
|
||||
cinfo->comp_info[1].DCT_v_scaled_size != cinfo->min_DCT_v_scaled_size ||
|
||||
cinfo->comp_info[2].DCT_v_scaled_size != cinfo->min_DCT_v_scaled_size)
|
||||
return FALSE;
|
||||
/* ??? also need to test for upsample-time rescaling, when & if supported */
|
||||
return TRUE; /* by golly, it'll work... */
|
||||
@ -82,7 +86,9 @@ use_merged_upsample (j_decompress_ptr cinfo)
|
||||
|
||||
GLOBAL(void)
|
||||
jpeg_calc_output_dimensions (j_decompress_ptr cinfo)
|
||||
/* Do computations that are needed before master selection phase */
|
||||
/* Do computations that are needed before master selection phase.
|
||||
* This function is used for full decompression.
|
||||
*/
|
||||
{
|
||||
#ifdef IDCT_SCALING_SUPPORTED
|
||||
int ci;
|
||||
@ -93,52 +99,38 @@ jpeg_calc_output_dimensions (j_decompress_ptr cinfo)
|
||||
if (cinfo->global_state != DSTATE_READY)
|
||||
ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
|
||||
|
||||
/* Compute core output image dimensions and DCT scaling choices. */
|
||||
jpeg_core_output_dimensions(cinfo);
|
||||
|
||||
#ifdef IDCT_SCALING_SUPPORTED
|
||||
|
||||
/* Compute actual output image dimensions and DCT scaling choices. */
|
||||
if (cinfo->scale_num * 8 <= cinfo->scale_denom) {
|
||||
/* Provide 1/8 scaling */
|
||||
cinfo->output_width = (JDIMENSION)
|
||||
jdiv_round_up((long) cinfo->image_width, 8L);
|
||||
cinfo->output_height = (JDIMENSION)
|
||||
jdiv_round_up((long) cinfo->image_height, 8L);
|
||||
cinfo->min_DCT_scaled_size = 1;
|
||||
} else if (cinfo->scale_num * 4 <= cinfo->scale_denom) {
|
||||
/* Provide 1/4 scaling */
|
||||
cinfo->output_width = (JDIMENSION)
|
||||
jdiv_round_up((long) cinfo->image_width, 4L);
|
||||
cinfo->output_height = (JDIMENSION)
|
||||
jdiv_round_up((long) cinfo->image_height, 4L);
|
||||
cinfo->min_DCT_scaled_size = 2;
|
||||
} else if (cinfo->scale_num * 2 <= cinfo->scale_denom) {
|
||||
/* Provide 1/2 scaling */
|
||||
cinfo->output_width = (JDIMENSION)
|
||||
jdiv_round_up((long) cinfo->image_width, 2L);
|
||||
cinfo->output_height = (JDIMENSION)
|
||||
jdiv_round_up((long) cinfo->image_height, 2L);
|
||||
cinfo->min_DCT_scaled_size = 4;
|
||||
} else {
|
||||
/* Provide 1/1 scaling */
|
||||
cinfo->output_width = cinfo->image_width;
|
||||
cinfo->output_height = cinfo->image_height;
|
||||
cinfo->min_DCT_scaled_size = DCTSIZE;
|
||||
}
|
||||
/* In selecting the actual DCT scaling for each component, we try to
|
||||
* scale up the chroma components via IDCT scaling rather than upsampling.
|
||||
* This saves time if the upsampler gets to use 1:1 scaling.
|
||||
* Note this code assumes that the supported DCT scalings are powers of 2.
|
||||
* Note this code adapts subsampling ratios which are powers of 2.
|
||||
*/
|
||||
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
|
||||
ci++, compptr++) {
|
||||
int ssize = cinfo->min_DCT_scaled_size;
|
||||
while (ssize < DCTSIZE &&
|
||||
(compptr->h_samp_factor * ssize * 2 <=
|
||||
cinfo->max_h_samp_factor * cinfo->min_DCT_scaled_size) &&
|
||||
(compptr->v_samp_factor * ssize * 2 <=
|
||||
cinfo->max_v_samp_factor * cinfo->min_DCT_scaled_size)) {
|
||||
int ssize = 1;
|
||||
while (cinfo->min_DCT_h_scaled_size * ssize <=
|
||||
(cinfo->do_fancy_upsampling ? DCTSIZE : DCTSIZE / 2) &&
|
||||
(cinfo->max_h_samp_factor % (compptr->h_samp_factor * ssize * 2)) == 0) {
|
||||
ssize = ssize * 2;
|
||||
}
|
||||
compptr->DCT_scaled_size = ssize;
|
||||
compptr->DCT_h_scaled_size = cinfo->min_DCT_h_scaled_size * ssize;
|
||||
ssize = 1;
|
||||
while (cinfo->min_DCT_v_scaled_size * ssize <=
|
||||
(cinfo->do_fancy_upsampling ? DCTSIZE : DCTSIZE / 2) &&
|
||||
(cinfo->max_v_samp_factor % (compptr->v_samp_factor * ssize * 2)) == 0) {
|
||||
ssize = ssize * 2;
|
||||
}
|
||||
compptr->DCT_v_scaled_size = cinfo->min_DCT_v_scaled_size * ssize;
|
||||
|
||||
/* We don't support IDCT ratios larger than 2. */
|
||||
if (compptr->DCT_h_scaled_size > compptr->DCT_v_scaled_size * 2)
|
||||
compptr->DCT_h_scaled_size = compptr->DCT_v_scaled_size * 2;
|
||||
else if (compptr->DCT_v_scaled_size > compptr->DCT_h_scaled_size * 2)
|
||||
compptr->DCT_v_scaled_size = compptr->DCT_h_scaled_size * 2;
|
||||
}
|
||||
|
||||
/* Recompute downsampled dimensions of components;
|
||||
@ -149,23 +141,14 @@ jpeg_calc_output_dimensions (j_decompress_ptr cinfo)
|
||||
/* Size in samples, after IDCT scaling */
|
||||
compptr->downsampled_width = (JDIMENSION)
|
||||
jdiv_round_up((long) cinfo->image_width *
|
||||
(long) (compptr->h_samp_factor * compptr->DCT_scaled_size),
|
||||
(long) (cinfo->max_h_samp_factor * DCTSIZE));
|
||||
(long) (compptr->h_samp_factor * compptr->DCT_h_scaled_size),
|
||||
(long) (cinfo->max_h_samp_factor * cinfo->block_size));
|
||||
compptr->downsampled_height = (JDIMENSION)
|
||||
jdiv_round_up((long) cinfo->image_height *
|
||||
(long) (compptr->v_samp_factor * compptr->DCT_scaled_size),
|
||||
(long) (cinfo->max_v_samp_factor * DCTSIZE));
|
||||
(long) (compptr->v_samp_factor * compptr->DCT_v_scaled_size),
|
||||
(long) (cinfo->max_v_samp_factor * cinfo->block_size));
|
||||
}
|
||||
|
||||
#else /* !IDCT_SCALING_SUPPORTED */
|
||||
|
||||
/* Hardwire it to "no scaling" */
|
||||
cinfo->output_width = cinfo->image_width;
|
||||
cinfo->output_height = cinfo->image_height;
|
||||
/* jdinput.c has already initialized DCT_scaled_size to DCTSIZE,
|
||||
* and has computed unscaled downsampled_width and downsampled_height.
|
||||
*/
|
||||
|
||||
#endif /* IDCT_SCALING_SUPPORTED */
|
||||
|
||||
/* Report number of components in selected colorspace. */
|
||||
@ -175,10 +158,8 @@ jpeg_calc_output_dimensions (j_decompress_ptr cinfo)
|
||||
cinfo->out_color_components = 1;
|
||||
break;
|
||||
case JCS_RGB:
|
||||
#if RGB_PIXELSIZE != 3
|
||||
cinfo->out_color_components = RGB_PIXELSIZE;
|
||||
break;
|
||||
#endif /* else share code with YCbCr */
|
||||
case JCS_YCbCr:
|
||||
cinfo->out_color_components = 3;
|
||||
break;
|
||||
@ -191,7 +172,7 @@ jpeg_calc_output_dimensions (j_decompress_ptr cinfo)
|
||||
break;
|
||||
}
|
||||
cinfo->output_components = (cinfo->quantize_colors ? 1 :
|
||||
cinfo->out_color_components);
|
||||
cinfo->out_color_components);
|
||||
|
||||
/* See if upsampler will want to emit more than one row at a time */
|
||||
if (use_merged_upsample(cinfo))
|
||||
@ -253,7 +234,7 @@ prepare_range_limit_table (j_decompress_ptr cinfo)
|
||||
|
||||
table = (JSAMPLE *)
|
||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
||||
(5 * (MAXJSAMPLE+1) + CENTERJSAMPLE) * SIZEOF(JSAMPLE));
|
||||
(5 * (MAXJSAMPLE+1) + CENTERJSAMPLE) * SIZEOF(JSAMPLE));
|
||||
table += (MAXJSAMPLE+1); /* allow negative subscripts of simple table */
|
||||
cinfo->sample_range_limit = table;
|
||||
/* First segment of "simple" table: limit[x] = 0 for x < 0 */
|
||||
@ -267,9 +248,9 @@ prepare_range_limit_table (j_decompress_ptr cinfo)
|
||||
table[i] = MAXJSAMPLE;
|
||||
/* Second half of post-IDCT table */
|
||||
MEMZERO(table + (2 * (MAXJSAMPLE+1)),
|
||||
(2 * (MAXJSAMPLE+1) - CENTERJSAMPLE) * SIZEOF(JSAMPLE));
|
||||
(2 * (MAXJSAMPLE+1) - CENTERJSAMPLE) * SIZEOF(JSAMPLE));
|
||||
MEMCOPY(table + (4 * (MAXJSAMPLE+1) - CENTERJSAMPLE),
|
||||
cinfo->sample_range_limit, CENTERJSAMPLE * SIZEOF(JSAMPLE));
|
||||
cinfo->sample_range_limit, CENTERJSAMPLE * SIZEOF(JSAMPLE));
|
||||
}
|
||||
|
||||
|
||||
@ -372,17 +353,10 @@ master_selection (j_decompress_ptr cinfo)
|
||||
/* Inverse DCT */
|
||||
jinit_inverse_dct(cinfo);
|
||||
/* Entropy decoding: either Huffman or arithmetic coding. */
|
||||
if (cinfo->arith_code) {
|
||||
ERREXIT(cinfo, JERR_ARITH_NOTIMPL);
|
||||
} else {
|
||||
if (cinfo->progressive_mode) {
|
||||
#ifdef D_PROGRESSIVE_SUPPORTED
|
||||
jinit_phuff_decoder(cinfo);
|
||||
#else
|
||||
ERREXIT(cinfo, JERR_NOT_COMPILED);
|
||||
#endif
|
||||
} else
|
||||
jinit_huff_decoder(cinfo);
|
||||
if (cinfo->arith_code)
|
||||
jinit_arith_decoder(cinfo);
|
||||
else {
|
||||
jinit_huff_decoder(cinfo);
|
||||
}
|
||||
|
||||
/* Initialize principal buffer controllers. */
|
||||
@ -453,24 +427,24 @@ prepare_for_output_pass (j_decompress_ptr cinfo)
|
||||
if (cinfo->quantize_colors && cinfo->colormap == NULL) {
|
||||
/* Select new quantization method */
|
||||
if (cinfo->two_pass_quantize && cinfo->enable_2pass_quant) {
|
||||
cinfo->cquantize = master->quantizer_2pass;
|
||||
master->pub.is_dummy_pass = TRUE;
|
||||
cinfo->cquantize = master->quantizer_2pass;
|
||||
master->pub.is_dummy_pass = TRUE;
|
||||
} else if (cinfo->enable_1pass_quant) {
|
||||
cinfo->cquantize = master->quantizer_1pass;
|
||||
cinfo->cquantize = master->quantizer_1pass;
|
||||
} else {
|
||||
ERREXIT(cinfo, JERR_MODE_CHANGE);
|
||||
ERREXIT(cinfo, JERR_MODE_CHANGE);
|
||||
}
|
||||
}
|
||||
(*cinfo->idct->start_pass) (cinfo);
|
||||
(*cinfo->coef->start_output_pass) (cinfo);
|
||||
if (! cinfo->raw_data_out) {
|
||||
if (! master->using_merged_upsample)
|
||||
(*cinfo->cconvert->start_pass) (cinfo);
|
||||
(*cinfo->cconvert->start_pass) (cinfo);
|
||||
(*cinfo->upsample->start_pass) (cinfo);
|
||||
if (cinfo->quantize_colors)
|
||||
(*cinfo->cquantize->start_pass) (cinfo, master->pub.is_dummy_pass);
|
||||
(*cinfo->cquantize->start_pass) (cinfo, master->pub.is_dummy_pass);
|
||||
(*cinfo->post->start_pass) (cinfo,
|
||||
(master->pub.is_dummy_pass ? JBUF_SAVE_AND_PASS : JBUF_PASS_THRU));
|
||||
(master->pub.is_dummy_pass ? JBUF_SAVE_AND_PASS : JBUF_PASS_THRU));
|
||||
(*cinfo->main->start_pass) (cinfo, JBUF_PASS_THRU);
|
||||
}
|
||||
}
|
||||
@ -479,7 +453,7 @@ prepare_for_output_pass (j_decompress_ptr cinfo)
|
||||
if (cinfo->progress != NULL) {
|
||||
cinfo->progress->completed_passes = master->pass_number;
|
||||
cinfo->progress->total_passes = master->pass_number +
|
||||
(master->pub.is_dummy_pass ? 2 : 1);
|
||||
(master->pub.is_dummy_pass ? 2 : 1);
|
||||
/* In buffered-image mode, we assume one more output pass if EOI not
|
||||
* yet reached, but no more passes if EOI has been reached.
|
||||
*/
|
||||
@ -546,7 +520,7 @@ jinit_master_decompress (j_decompress_ptr cinfo)
|
||||
|
||||
master = (my_master_ptr)
|
||||
(*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;
|
||||
master->pub.prepare_for_output_pass = prepare_for_output_pass;
|
||||
master->pub.finish_output_pass = finish_output_pass;
|
||||
|
48
3rdparty/libjpeg/jdmerge.c
vendored
48
3rdparty/libjpeg/jdmerge.c
vendored
@ -46,8 +46,8 @@ typedef struct {
|
||||
|
||||
/* Pointer to routine to do actual upsampling/conversion of one row group */
|
||||
JMETHOD(void, upmethod, (j_decompress_ptr cinfo,
|
||||
JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
|
||||
JSAMPARRAY output_buf));
|
||||
JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
|
||||
JSAMPARRAY output_buf));
|
||||
|
||||
/* Private state for YCC->RGB conversion */
|
||||
int * Cr_r_tab; /* => table for Cr to R conversion */
|
||||
@ -89,26 +89,26 @@ build_ycc_rgb_table (j_decompress_ptr cinfo)
|
||||
|
||||
upsample->Cr_r_tab = (int *)
|
||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
||||
(MAXJSAMPLE+1) * SIZEOF(int));
|
||||
(MAXJSAMPLE+1) * SIZEOF(int));
|
||||
upsample->Cb_b_tab = (int *)
|
||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
||||
(MAXJSAMPLE+1) * SIZEOF(int));
|
||||
(MAXJSAMPLE+1) * SIZEOF(int));
|
||||
upsample->Cr_g_tab = (INT32 *)
|
||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
||||
(MAXJSAMPLE+1) * SIZEOF(INT32));
|
||||
(MAXJSAMPLE+1) * SIZEOF(INT32));
|
||||
upsample->Cb_g_tab = (INT32 *)
|
||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
||||
(MAXJSAMPLE+1) * SIZEOF(INT32));
|
||||
(MAXJSAMPLE+1) * SIZEOF(INT32));
|
||||
|
||||
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 1.40200 * x */
|
||||
upsample->Cr_r_tab[i] = (int)
|
||||
RIGHT_SHIFT(FIX(1.40200) * x + ONE_HALF, SCALEBITS);
|
||||
RIGHT_SHIFT(FIX(1.40200) * x + ONE_HALF, SCALEBITS);
|
||||
/* Cb=>B value is nearest int to 1.77200 * x */
|
||||
upsample->Cb_b_tab[i] = (int)
|
||||
RIGHT_SHIFT(FIX(1.77200) * x + ONE_HALF, SCALEBITS);
|
||||
RIGHT_SHIFT(FIX(1.77200) * x + ONE_HALF, SCALEBITS);
|
||||
/* Cr=>G value is scaled-up -0.71414 * x */
|
||||
upsample->Cr_g_tab[i] = (- FIX(0.71414)) * x;
|
||||
/* Cb=>G value is scaled-up -0.34414 * x */
|
||||
@ -142,10 +142,10 @@ start_pass_merged_upsample (j_decompress_ptr cinfo)
|
||||
|
||||
METHODDEF(void)
|
||||
merged_2v_upsample (j_decompress_ptr cinfo,
|
||||
JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
|
||||
JDIMENSION in_row_groups_avail,
|
||||
JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
|
||||
JDIMENSION out_rows_avail)
|
||||
JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
|
||||
JDIMENSION in_row_groups_avail,
|
||||
JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
|
||||
JDIMENSION out_rows_avail)
|
||||
/* 2:1 vertical sampling case: may need a spare row. */
|
||||
{
|
||||
my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
|
||||
@ -155,7 +155,7 @@ merged_2v_upsample (j_decompress_ptr cinfo,
|
||||
if (upsample->spare_full) {
|
||||
/* If we have a spare row saved from a previous cycle, just return it. */
|
||||
jcopy_sample_rows(& upsample->spare_row, 0, output_buf + *out_row_ctr, 0,
|
||||
1, upsample->out_row_width);
|
||||
1, upsample->out_row_width);
|
||||
num_rows = 1;
|
||||
upsample->spare_full = FALSE;
|
||||
} else {
|
||||
@ -191,17 +191,17 @@ merged_2v_upsample (j_decompress_ptr cinfo,
|
||||
|
||||
METHODDEF(void)
|
||||
merged_1v_upsample (j_decompress_ptr cinfo,
|
||||
JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
|
||||
JDIMENSION in_row_groups_avail,
|
||||
JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
|
||||
JDIMENSION out_rows_avail)
|
||||
JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
|
||||
JDIMENSION in_row_groups_avail,
|
||||
JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
|
||||
JDIMENSION out_rows_avail)
|
||||
/* 1:1 vertical sampling case: much easier, never need a spare row. */
|
||||
{
|
||||
my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
|
||||
|
||||
/* Just do the upsampling. */
|
||||
(*upsample->upmethod) (cinfo, input_buf, *in_row_group_ctr,
|
||||
output_buf + *out_row_ctr);
|
||||
output_buf + *out_row_ctr);
|
||||
/* Adjust counts */
|
||||
(*out_row_ctr)++;
|
||||
(*in_row_group_ctr)++;
|
||||
@ -224,8 +224,8 @@ merged_1v_upsample (j_decompress_ptr cinfo,
|
||||
|
||||
METHODDEF(void)
|
||||
h2v1_merged_upsample (j_decompress_ptr cinfo,
|
||||
JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
|
||||
JSAMPARRAY output_buf)
|
||||
JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
|
||||
JSAMPARRAY output_buf)
|
||||
{
|
||||
my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
|
||||
register int y, cred, cgreen, cblue;
|
||||
@ -286,8 +286,8 @@ h2v1_merged_upsample (j_decompress_ptr cinfo,
|
||||
|
||||
METHODDEF(void)
|
||||
h2v2_merged_upsample (j_decompress_ptr cinfo,
|
||||
JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
|
||||
JSAMPARRAY output_buf)
|
||||
JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
|
||||
JSAMPARRAY output_buf)
|
||||
{
|
||||
my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
|
||||
register int y, cred, cgreen, cblue;
|
||||
@ -373,7 +373,7 @@ jinit_merged_upsampler (j_decompress_ptr cinfo)
|
||||
|
||||
upsample = (my_upsample_ptr)
|
||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
||||
SIZEOF(my_upsampler));
|
||||
SIZEOF(my_upsampler));
|
||||
cinfo->upsample = (struct jpeg_upsampler *) upsample;
|
||||
upsample->pub.start_pass = start_pass_merged_upsample;
|
||||
upsample->pub.need_context_rows = FALSE;
|
||||
@ -386,7 +386,7 @@ jinit_merged_upsampler (j_decompress_ptr cinfo)
|
||||
/* Allocate a spare row buffer */
|
||||
upsample->spare_row = (JSAMPROW)
|
||||
(*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
||||
(size_t) (upsample->out_row_width * SIZEOF(JSAMPLE)));
|
||||
(size_t) (upsample->out_row_width * SIZEOF(JSAMPLE)));
|
||||
} else {
|
||||
upsample->pub.upsample = merged_1v_upsample;
|
||||
upsample->upmethod = h2v1_merged_upsample;
|
||||
|
668
3rdparty/libjpeg/jdphuff.c
vendored
668
3rdparty/libjpeg/jdphuff.c
vendored
@ -1,668 +0,0 @@
|
||||
/*
|
||||
* jdphuff.c
|
||||
*
|
||||
* Copyright (C) 1995-1997, Thomas G. Lane.
|
||||
* This file is part of the Independent JPEG Group's software.
|
||||
* For conditions of distribution and use, see the accompanying README file.
|
||||
*
|
||||
* This file contains Huffman entropy decoding routines for progressive JPEG.
|
||||
*
|
||||
* Much of the complexity here has to do with supporting input suspension.
|
||||
* If the data source module demands suspension, we want to be able to back
|
||||
* up to the start of the current MCU. To do this, we copy state variables
|
||||
* into local working storage, and update them back to the permanent
|
||||
* storage only upon successful completion of an MCU.
|
||||
*/
|
||||
|
||||
#define JPEG_INTERNALS
|
||||
#include "jinclude.h"
|
||||
#include "jpeglib.h"
|
||||
#include "jdhuff.h" /* Declarations shared with jdhuff.c */
|
||||
|
||||
|
||||
#ifdef D_PROGRESSIVE_SUPPORTED
|
||||
|
||||
/*
|
||||
* Expanded entropy decoder object for progressive Huffman decoding.
|
||||
*
|
||||
* The savable_state subrecord contains fields that change within an MCU,
|
||||
* but must not be updated permanently until we complete the MCU.
|
||||
*/
|
||||
|
||||
typedef struct {
|
||||
unsigned int EOBRUN; /* remaining EOBs in EOBRUN */
|
||||
int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
|
||||
} savable_state;
|
||||
|
||||
/* This macro is to work around compilers with missing or broken
|
||||
* structure assignment. You'll need to fix this code if you have
|
||||
* such a compiler and you change MAX_COMPS_IN_SCAN.
|
||||
*/
|
||||
|
||||
#ifndef NO_STRUCT_ASSIGN
|
||||
#define ASSIGN_STATE(dest,src) ((dest) = (src))
|
||||
#else
|
||||
#if MAX_COMPS_IN_SCAN == 4
|
||||
#define ASSIGN_STATE(dest,src) \
|
||||
((dest).EOBRUN = (src).EOBRUN, \
|
||||
(dest).last_dc_val[0] = (src).last_dc_val[0], \
|
||||
(dest).last_dc_val[1] = (src).last_dc_val[1], \
|
||||
(dest).last_dc_val[2] = (src).last_dc_val[2], \
|
||||
(dest).last_dc_val[3] = (src).last_dc_val[3])
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
typedef struct {
|
||||
struct jpeg_entropy_decoder pub; /* public fields */
|
||||
|
||||
/* These fields are loaded into local variables at start of each MCU.
|
||||
* In case of suspension, we exit WITHOUT updating them.
|
||||
*/
|
||||
bitread_perm_state bitstate; /* Bit buffer at start of MCU */
|
||||
savable_state saved; /* Other state at start of MCU */
|
||||
|
||||
/* These fields are NOT loaded into local working state. */
|
||||
unsigned int restarts_to_go; /* MCUs left in this restart interval */
|
||||
|
||||
/* Pointers to derived tables (these workspaces have image lifespan) */
|
||||
d_derived_tbl * derived_tbls[NUM_HUFF_TBLS];
|
||||
|
||||
d_derived_tbl * ac_derived_tbl; /* active table during an AC scan */
|
||||
} phuff_entropy_decoder;
|
||||
|
||||
typedef phuff_entropy_decoder * phuff_entropy_ptr;
|
||||
|
||||
/* Forward declarations */
|
||||
METHODDEF(boolean) decode_mcu_DC_first JPP((j_decompress_ptr cinfo,
|
||||
JBLOCKROW *MCU_data));
|
||||
METHODDEF(boolean) decode_mcu_AC_first JPP((j_decompress_ptr cinfo,
|
||||
JBLOCKROW *MCU_data));
|
||||
METHODDEF(boolean) decode_mcu_DC_refine JPP((j_decompress_ptr cinfo,
|
||||
JBLOCKROW *MCU_data));
|
||||
METHODDEF(boolean) decode_mcu_AC_refine JPP((j_decompress_ptr cinfo,
|
||||
JBLOCKROW *MCU_data));
|
||||
|
||||
|
||||
/*
|
||||
* Initialize for a Huffman-compressed scan.
|
||||
*/
|
||||
|
||||
METHODDEF(void)
|
||||
start_pass_phuff_decoder (j_decompress_ptr cinfo)
|
||||
{
|
||||
phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
|
||||
boolean is_DC_band, bad;
|
||||
int ci, coefi, tbl;
|
||||
int *coef_bit_ptr;
|
||||
jpeg_component_info * compptr;
|
||||
|
||||
is_DC_band = (cinfo->Ss == 0);
|
||||
|
||||
/* Validate scan parameters */
|
||||
bad = FALSE;
|
||||
if (is_DC_band) {
|
||||
if (cinfo->Se != 0)
|
||||
bad = TRUE;
|
||||
} else {
|
||||
/* need not check Ss/Se < 0 since they came from unsigned bytes */
|
||||
if (cinfo->Ss > cinfo->Se || cinfo->Se >= DCTSIZE2)
|
||||
bad = TRUE;
|
||||
/* AC scans may have only one component */
|
||||
if (cinfo->comps_in_scan != 1)
|
||||
bad = TRUE;
|
||||
}
|
||||
if (cinfo->Ah != 0) {
|
||||
/* Successive approximation refinement scan: must have Al = Ah-1. */
|
||||
if (cinfo->Al != cinfo->Ah-1)
|
||||
bad = TRUE;
|
||||
}
|
||||
if (cinfo->Al > 13) /* need not check for < 0 */
|
||||
bad = TRUE;
|
||||
/* Arguably the maximum Al value should be less than 13 for 8-bit precision,
|
||||
* but the spec doesn't say so, and we try to be liberal about what we
|
||||
* accept. Note: large Al values could result in out-of-range DC
|
||||
* coefficients during early scans, leading to bizarre displays due to
|
||||
* overflows in the IDCT math. But we won't crash.
|
||||
*/
|
||||
if (bad)
|
||||
ERREXIT4(cinfo, JERR_BAD_PROGRESSION,
|
||||
cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al);
|
||||
/* Update progression status, and verify that scan order is legal.
|
||||
* Note that inter-scan inconsistencies are treated as warnings
|
||||
* not fatal errors ... not clear if this is right way to behave.
|
||||
*/
|
||||
for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
|
||||
int cindex = cinfo->cur_comp_info[ci]->component_index;
|
||||
coef_bit_ptr = & cinfo->coef_bits[cindex][0];
|
||||
if (!is_DC_band && coef_bit_ptr[0] < 0) /* AC without prior DC scan */
|
||||
WARNMS2(cinfo, JWRN_BOGUS_PROGRESSION, cindex, 0);
|
||||
for (coefi = cinfo->Ss; coefi <= cinfo->Se; coefi++) {
|
||||
int expected = (coef_bit_ptr[coefi] < 0) ? 0 : coef_bit_ptr[coefi];
|
||||
if (cinfo->Ah != expected)
|
||||
WARNMS2(cinfo, JWRN_BOGUS_PROGRESSION, cindex, coefi);
|
||||
coef_bit_ptr[coefi] = cinfo->Al;
|
||||
}
|
||||
}
|
||||
|
||||
/* Select MCU decoding routine */
|
||||
if (cinfo->Ah == 0) {
|
||||
if (is_DC_band)
|
||||
entropy->pub.decode_mcu = decode_mcu_DC_first;
|
||||
else
|
||||
entropy->pub.decode_mcu = decode_mcu_AC_first;
|
||||
} else {
|
||||
if (is_DC_band)
|
||||
entropy->pub.decode_mcu = decode_mcu_DC_refine;
|
||||
else
|
||||
entropy->pub.decode_mcu = decode_mcu_AC_refine;
|
||||
}
|
||||
|
||||
for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
|
||||
compptr = cinfo->cur_comp_info[ci];
|
||||
/* Make sure requested tables are present, and compute derived tables.
|
||||
* We may build same derived table more than once, but it's not expensive.
|
||||
*/
|
||||
if (is_DC_band) {
|
||||
if (cinfo->Ah == 0) { /* DC refinement needs no table */
|
||||
tbl = compptr->dc_tbl_no;
|
||||
jpeg_make_d_derived_tbl(cinfo, TRUE, tbl,
|
||||
& entropy->derived_tbls[tbl]);
|
||||
}
|
||||
} else {
|
||||
tbl = compptr->ac_tbl_no;
|
||||
jpeg_make_d_derived_tbl(cinfo, FALSE, tbl,
|
||||
& entropy->derived_tbls[tbl]);
|
||||
/* remember the single active table */
|
||||
entropy->ac_derived_tbl = entropy->derived_tbls[tbl];
|
||||
}
|
||||
/* Initialize DC predictions to 0 */
|
||||
entropy->saved.last_dc_val[ci] = 0;
|
||||
}
|
||||
|
||||
/* Initialize bitread state variables */
|
||||
entropy->bitstate.bits_left = 0;
|
||||
entropy->bitstate.get_buffer = 0; /* unnecessary, but keeps Purify quiet */
|
||||
entropy->pub.insufficient_data = FALSE;
|
||||
|
||||
/* Initialize private state variables */
|
||||
entropy->saved.EOBRUN = 0;
|
||||
|
||||
/* Initialize restart counter */
|
||||
entropy->restarts_to_go = cinfo->restart_interval;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Figure F.12: extend sign bit.
|
||||
* On some machines, a shift and add will be faster than a table lookup.
|
||||
*/
|
||||
|
||||
#ifdef AVOID_TABLES
|
||||
|
||||
#define HUFF_EXTEND(x,s) ((x) < (1<<((s)-1)) ? (x) + (((-1)<<(s)) + 1) : (x))
|
||||
|
||||
#else
|
||||
|
||||
#define HUFF_EXTEND(x,s) ((x) < extend_test[s] ? (x) + extend_offset[s] : (x))
|
||||
|
||||
static const int extend_test[16] = /* entry n is 2**(n-1) */
|
||||
{ 0, 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080,
|
||||
0x0100, 0x0200, 0x0400, 0x0800, 0x1000, 0x2000, 0x4000 };
|
||||
|
||||
static const int extend_offset[16] = /* entry n is (-1 << n) + 1 */
|
||||
{ 0, ((-1)<<1) + 1, ((-1)<<2) + 1, ((-1)<<3) + 1, ((-1)<<4) + 1,
|
||||
((-1)<<5) + 1, ((-1)<<6) + 1, ((-1)<<7) + 1, ((-1)<<8) + 1,
|
||||
((-1)<<9) + 1, ((-1)<<10) + 1, ((-1)<<11) + 1, ((-1)<<12) + 1,
|
||||
((-1)<<13) + 1, ((-1)<<14) + 1, ((-1)<<15) + 1 };
|
||||
|
||||
#endif /* AVOID_TABLES */
|
||||
|
||||
|
||||
/*
|
||||
* Check for a restart marker & resynchronize decoder.
|
||||
* Returns FALSE if must suspend.
|
||||
*/
|
||||
|
||||
LOCAL(boolean)
|
||||
process_restart (j_decompress_ptr cinfo)
|
||||
{
|
||||
phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
|
||||
int ci;
|
||||
|
||||
/* 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;
|
||||
|
||||
/* Advance past the RSTn marker */
|
||||
if (! (*cinfo->marker->read_restart_marker) (cinfo))
|
||||
return FALSE;
|
||||
|
||||
/* Re-initialize DC predictions to 0 */
|
||||
for (ci = 0; ci < cinfo->comps_in_scan; ci++)
|
||||
entropy->saved.last_dc_val[ci] = 0;
|
||||
/* Re-init EOB run count, too */
|
||||
entropy->saved.EOBRUN = 0;
|
||||
|
||||
/* Reset restart counter */
|
||||
entropy->restarts_to_go = cinfo->restart_interval;
|
||||
|
||||
/* Reset out-of-data flag, unless read_restart_marker left us smack up
|
||||
* against a marker. In that case we will end up treating the next data
|
||||
* segment as empty, and we can avoid producing bogus output pixels by
|
||||
* leaving the flag set.
|
||||
*/
|
||||
if (cinfo->unread_marker == 0)
|
||||
entropy->pub.insufficient_data = FALSE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Huffman MCU decoding.
|
||||
* Each of these routines decodes and returns one MCU's worth of
|
||||
* Huffman-compressed coefficients.
|
||||
* The coefficients are reordered from zigzag order into natural array order,
|
||||
* but are not dequantized.
|
||||
*
|
||||
* The i'th block of the MCU is stored into the block pointed to by
|
||||
* MCU_data[i]. WE ASSUME THIS AREA IS INITIALLY ZEROED BY THE CALLER.
|
||||
*
|
||||
* We return FALSE if data source requested suspension. In that case no
|
||||
* changes have been made to permanent state. (Exception: some output
|
||||
* coefficients may already have been assigned. This is harmless for
|
||||
* spectral selection, since we'll just re-assign them on the next call.
|
||||
* Successive approximation AC refinement has to be more careful, however.)
|
||||
*/
|
||||
|
||||
/*
|
||||
* MCU decoding for DC initial scan (either spectral selection,
|
||||
* or first pass of successive approximation).
|
||||
*/
|
||||
|
||||
METHODDEF(boolean)
|
||||
decode_mcu_DC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
|
||||
{
|
||||
phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
|
||||
int Al = cinfo->Al;
|
||||
register int s, r;
|
||||
int blkn, ci;
|
||||
JBLOCKROW block;
|
||||
BITREAD_STATE_VARS;
|
||||
savable_state state;
|
||||
d_derived_tbl * tbl;
|
||||
jpeg_component_info * compptr;
|
||||
|
||||
/* Process restart marker if needed; may have to suspend */
|
||||
if (cinfo->restart_interval) {
|
||||
if (entropy->restarts_to_go == 0)
|
||||
if (! process_restart(cinfo))
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* If we've run out of data, just leave the MCU set to zeroes.
|
||||
* This way, we return uniform gray for the remainder of the segment.
|
||||
*/
|
||||
if (! entropy->pub.insufficient_data) {
|
||||
|
||||
/* Load up working state */
|
||||
BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
|
||||
ASSIGN_STATE(state, entropy->saved);
|
||||
|
||||
/* Outer loop handles each block in the MCU */
|
||||
|
||||
for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
|
||||
block = MCU_data[blkn];
|
||||
ci = cinfo->MCU_membership[blkn];
|
||||
compptr = cinfo->cur_comp_info[ci];
|
||||
tbl = entropy->derived_tbls[compptr->dc_tbl_no];
|
||||
|
||||
/* Decode a single block's worth of coefficients */
|
||||
|
||||
/* Section F.2.2.1: decode the DC coefficient difference */
|
||||
HUFF_DECODE(s, br_state, tbl, return FALSE, label1);
|
||||
if (s) {
|
||||
CHECK_BIT_BUFFER(br_state, s, return FALSE);
|
||||
r = GET_BITS(s);
|
||||
s = HUFF_EXTEND(r, s);
|
||||
}
|
||||
|
||||
/* Convert DC difference to actual value, update last_dc_val */
|
||||
s += state.last_dc_val[ci];
|
||||
state.last_dc_val[ci] = s;
|
||||
/* Scale and output the coefficient (assumes jpeg_natural_order[0]=0) */
|
||||
(*block)[0] = (JCOEF) (s << Al);
|
||||
}
|
||||
|
||||
/* Completed MCU, so update state */
|
||||
BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
|
||||
ASSIGN_STATE(entropy->saved, state);
|
||||
}
|
||||
|
||||
/* Account for restart interval (no-op if not using restarts) */
|
||||
entropy->restarts_to_go--;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* MCU decoding for AC initial scan (either spectral selection,
|
||||
* or first pass of successive approximation).
|
||||
*/
|
||||
|
||||
METHODDEF(boolean)
|
||||
decode_mcu_AC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
|
||||
{
|
||||
phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
|
||||
int Se = cinfo->Se;
|
||||
int Al = cinfo->Al;
|
||||
register int s, k, r;
|
||||
unsigned int EOBRUN;
|
||||
JBLOCKROW block;
|
||||
BITREAD_STATE_VARS;
|
||||
d_derived_tbl * tbl;
|
||||
|
||||
/* Process restart marker if needed; may have to suspend */
|
||||
if (cinfo->restart_interval) {
|
||||
if (entropy->restarts_to_go == 0)
|
||||
if (! process_restart(cinfo))
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* If we've run out of data, just leave the MCU set to zeroes.
|
||||
* This way, we return uniform gray for the remainder of the segment.
|
||||
*/
|
||||
if (! entropy->pub.insufficient_data) {
|
||||
|
||||
/* Load up working state.
|
||||
* We can avoid loading/saving bitread state if in an EOB run.
|
||||
*/
|
||||
EOBRUN = entropy->saved.EOBRUN; /* only part of saved state we need */
|
||||
|
||||
/* There is always only one block per MCU */
|
||||
|
||||
if (EOBRUN > 0) /* if it's a band of zeroes... */
|
||||
EOBRUN--; /* ...process it now (we do nothing) */
|
||||
else {
|
||||
BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
|
||||
block = MCU_data[0];
|
||||
tbl = entropy->ac_derived_tbl;
|
||||
|
||||
for (k = cinfo->Ss; k <= Se; k++) {
|
||||
HUFF_DECODE(s, br_state, tbl, return FALSE, label2);
|
||||
r = s >> 4;
|
||||
s &= 15;
|
||||
if (s) {
|
||||
k += r;
|
||||
CHECK_BIT_BUFFER(br_state, s, return FALSE);
|
||||
r = GET_BITS(s);
|
||||
s = HUFF_EXTEND(r, s);
|
||||
/* Scale and output coefficient in natural (dezigzagged) order */
|
||||
(*block)[jpeg_natural_order[k]] = (JCOEF) (s << Al);
|
||||
} else {
|
||||
if (r == 15) { /* ZRL */
|
||||
k += 15; /* skip 15 zeroes in band */
|
||||
} else { /* EOBr, run length is 2^r + appended bits */
|
||||
EOBRUN = 1 << r;
|
||||
if (r) { /* EOBr, r > 0 */
|
||||
CHECK_BIT_BUFFER(br_state, r, return FALSE);
|
||||
r = GET_BITS(r);
|
||||
EOBRUN += r;
|
||||
}
|
||||
EOBRUN--; /* this band is processed at this moment */
|
||||
break; /* force end-of-band */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
|
||||
}
|
||||
|
||||
/* Completed MCU, so update state */
|
||||
entropy->saved.EOBRUN = EOBRUN; /* only part of saved state we need */
|
||||
}
|
||||
|
||||
/* Account for restart interval (no-op if not using restarts) */
|
||||
entropy->restarts_to_go--;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 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)
|
||||
decode_mcu_DC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
|
||||
{
|
||||
phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
|
||||
int p1 = 1 << cinfo->Al; /* 1 in the bit position being coded */
|
||||
int blkn;
|
||||
JBLOCKROW block;
|
||||
BITREAD_STATE_VARS;
|
||||
|
||||
/* Process restart marker if needed; may have to suspend */
|
||||
if (cinfo->restart_interval) {
|
||||
if (entropy->restarts_to_go == 0)
|
||||
if (! process_restart(cinfo))
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* Not worth the cycles to check insufficient_data here,
|
||||
* since we will not change the data anyway if we read zeroes.
|
||||
*/
|
||||
|
||||
/* Load up working state */
|
||||
BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
|
||||
|
||||
/* Outer loop handles each block in the MCU */
|
||||
|
||||
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 */
|
||||
CHECK_BIT_BUFFER(br_state, 1, return FALSE);
|
||||
if (GET_BITS(1))
|
||||
(*block)[0] |= p1;
|
||||
/* Note: since we use |=, repeating the assignment later is safe */
|
||||
}
|
||||
|
||||
/* Completed MCU, so update state */
|
||||
BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
|
||||
|
||||
/* Account for restart interval (no-op if not using restarts) */
|
||||
entropy->restarts_to_go--;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* MCU decoding for AC successive approximation refinement scan.
|
||||
*/
|
||||
|
||||
METHODDEF(boolean)
|
||||
decode_mcu_AC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
|
||||
{
|
||||
phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
|
||||
int Se = cinfo->Se;
|
||||
int p1 = 1 << cinfo->Al; /* 1 in the bit position being coded */
|
||||
int m1 = (-1) << cinfo->Al; /* -1 in the bit position being coded */
|
||||
register int s, k, r;
|
||||
unsigned int EOBRUN;
|
||||
JBLOCKROW block;
|
||||
JCOEFPTR thiscoef;
|
||||
BITREAD_STATE_VARS;
|
||||
d_derived_tbl * tbl;
|
||||
int num_newnz;
|
||||
int newnz_pos[DCTSIZE2];
|
||||
|
||||
/* Process restart marker if needed; may have to suspend */
|
||||
if (cinfo->restart_interval) {
|
||||
if (entropy->restarts_to_go == 0)
|
||||
if (! process_restart(cinfo))
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* If we've run out of data, don't modify the MCU.
|
||||
*/
|
||||
if (! entropy->pub.insufficient_data) {
|
||||
|
||||
/* Load up working state */
|
||||
BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
|
||||
EOBRUN = entropy->saved.EOBRUN; /* only part of saved state we need */
|
||||
|
||||
/* There is always only one block per MCU */
|
||||
block = MCU_data[0];
|
||||
tbl = entropy->ac_derived_tbl;
|
||||
|
||||
/* If we are forced to suspend, we must undo the assignments to any newly
|
||||
* nonzero coefficients in the block, because otherwise we'd get confused
|
||||
* next time about which coefficients were already nonzero.
|
||||
* But we need not undo addition of bits to already-nonzero coefficients;
|
||||
* instead, we can test the current bit to see if we already did it.
|
||||
*/
|
||||
num_newnz = 0;
|
||||
|
||||
/* initialize coefficient loop counter to start of band */
|
||||
k = cinfo->Ss;
|
||||
|
||||
if (EOBRUN == 0) {
|
||||
for (; k <= Se; k++) {
|
||||
HUFF_DECODE(s, br_state, tbl, goto undoit, label3);
|
||||
r = s >> 4;
|
||||
s &= 15;
|
||||
if (s) {
|
||||
if (s != 1) /* size of new coef should always be 1 */
|
||||
WARNMS(cinfo, JWRN_HUFF_BAD_CODE);
|
||||
CHECK_BIT_BUFFER(br_state, 1, goto undoit);
|
||||
if (GET_BITS(1))
|
||||
s = p1; /* newly nonzero coef is positive */
|
||||
else
|
||||
s = m1; /* newly nonzero coef is negative */
|
||||
} else {
|
||||
if (r != 15) {
|
||||
EOBRUN = 1 << r; /* EOBr, run length is 2^r + appended bits */
|
||||
if (r) {
|
||||
CHECK_BIT_BUFFER(br_state, r, goto undoit);
|
||||
r = GET_BITS(r);
|
||||
EOBRUN += r;
|
||||
}
|
||||
break; /* rest of block is handled by EOB logic */
|
||||
}
|
||||
/* note s = 0 for processing ZRL */
|
||||
}
|
||||
/* Advance over already-nonzero coefs and r still-zero coefs,
|
||||
* appending correction bits to the nonzeroes. A correction bit is 1
|
||||
* if the absolute value of the coefficient must be increased.
|
||||
*/
|
||||
do {
|
||||
thiscoef = *block + jpeg_natural_order[k];
|
||||
if (*thiscoef != 0) {
|
||||
CHECK_BIT_BUFFER(br_state, 1, goto undoit);
|
||||
if (GET_BITS(1)) {
|
||||
if ((*thiscoef & p1) == 0) { /* do nothing if already set it */
|
||||
if (*thiscoef >= 0)
|
||||
*thiscoef += p1;
|
||||
else
|
||||
*thiscoef += m1;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (--r < 0)
|
||||
break; /* reached target zero coefficient */
|
||||
}
|
||||
k++;
|
||||
} while (k <= Se);
|
||||
if (s) {
|
||||
int pos = jpeg_natural_order[k];
|
||||
/* Output newly nonzero coefficient */
|
||||
(*block)[pos] = (JCOEF) s;
|
||||
/* Remember its position in case we have to suspend */
|
||||
newnz_pos[num_newnz++] = pos;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (EOBRUN > 0) {
|
||||
/* Scan any remaining coefficient positions after the end-of-band
|
||||
* (the last newly nonzero coefficient, if any). Append a correction
|
||||
* bit to each already-nonzero coefficient. A correction bit is 1
|
||||
* if the absolute value of the coefficient must be increased.
|
||||
*/
|
||||
for (; k <= Se; k++) {
|
||||
thiscoef = *block + jpeg_natural_order[k];
|
||||
if (*thiscoef != 0) {
|
||||
CHECK_BIT_BUFFER(br_state, 1, goto undoit);
|
||||
if (GET_BITS(1)) {
|
||||
if ((*thiscoef & p1) == 0) { /* do nothing if already changed it */
|
||||
if (*thiscoef >= 0)
|
||||
*thiscoef += p1;
|
||||
else
|
||||
*thiscoef += m1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/* Count one block completed in EOB run */
|
||||
EOBRUN--;
|
||||
}
|
||||
|
||||
/* Completed MCU, so update state */
|
||||
BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
|
||||
entropy->saved.EOBRUN = EOBRUN; /* only part of saved state we need */
|
||||
}
|
||||
|
||||
/* Account for restart interval (no-op if not using restarts) */
|
||||
entropy->restarts_to_go--;
|
||||
|
||||
return TRUE;
|
||||
|
||||
undoit:
|
||||
/* Re-zero any output coefficients that we made newly nonzero */
|
||||
while (num_newnz > 0)
|
||||
(*block)[newnz_pos[--num_newnz]] = 0;
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Module initialization routine for progressive Huffman entropy decoding.
|
||||
*/
|
||||
|
||||
GLOBAL(void)
|
||||
jinit_phuff_decoder (j_decompress_ptr cinfo)
|
||||
{
|
||||
phuff_entropy_ptr entropy;
|
||||
int *coef_bit_ptr;
|
||||
int ci, i;
|
||||
|
||||
entropy = (phuff_entropy_ptr)
|
||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
||||
SIZEOF(phuff_entropy_decoder));
|
||||
cinfo->entropy = (struct jpeg_entropy_decoder *) entropy;
|
||||
entropy->pub.start_pass = start_pass_phuff_decoder;
|
||||
|
||||
/* Mark derived tables unallocated */
|
||||
for (i = 0; i < NUM_HUFF_TBLS; i++) {
|
||||
entropy->derived_tbls[i] = NULL;
|
||||
}
|
||||
|
||||
/* Create progression status table */
|
||||
cinfo->coef_bits = (int (*)[DCTSIZE2])
|
||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
||||
cinfo->num_components*DCTSIZE2*SIZEOF(int));
|
||||
coef_bit_ptr = & cinfo->coef_bits[0][0];
|
||||
for (ci = 0; ci < cinfo->num_components; ci++)
|
||||
for (i = 0; i < DCTSIZE2; i++)
|
||||
*coef_bit_ptr++ = -1;
|
||||
}
|
||||
|
||||
#endif /* D_PROGRESSIVE_SUPPORTED */
|
102
3rdparty/libjpeg/jdpostct.c
vendored
102
3rdparty/libjpeg/jdpostct.c
vendored
@ -44,24 +44,24 @@ typedef my_post_controller * my_post_ptr;
|
||||
|
||||
/* Forward declarations */
|
||||
METHODDEF(void) post_process_1pass
|
||||
JPP((j_decompress_ptr cinfo,
|
||||
JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
|
||||
JDIMENSION in_row_groups_avail,
|
||||
JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
|
||||
JDIMENSION out_rows_avail));
|
||||
JPP((j_decompress_ptr cinfo,
|
||||
JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
|
||||
JDIMENSION in_row_groups_avail,
|
||||
JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
|
||||
JDIMENSION out_rows_avail));
|
||||
#ifdef QUANT_2PASS_SUPPORTED
|
||||
METHODDEF(void) post_process_prepass
|
||||
JPP((j_decompress_ptr cinfo,
|
||||
JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
|
||||
JDIMENSION in_row_groups_avail,
|
||||
JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
|
||||
JDIMENSION out_rows_avail));
|
||||
JPP((j_decompress_ptr cinfo,
|
||||
JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
|
||||
JDIMENSION in_row_groups_avail,
|
||||
JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
|
||||
JDIMENSION out_rows_avail));
|
||||
METHODDEF(void) post_process_2pass
|
||||
JPP((j_decompress_ptr cinfo,
|
||||
JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
|
||||
JDIMENSION in_row_groups_avail,
|
||||
JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
|
||||
JDIMENSION out_rows_avail));
|
||||
JPP((j_decompress_ptr cinfo,
|
||||
JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
|
||||
JDIMENSION in_row_groups_avail,
|
||||
JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
|
||||
JDIMENSION out_rows_avail));
|
||||
#endif
|
||||
|
||||
|
||||
@ -84,9 +84,9 @@ start_pass_dpost (j_decompress_ptr cinfo, J_BUF_MODE pass_mode)
|
||||
* allocate a strip buffer. Use the virtual-array buffer as workspace.
|
||||
*/
|
||||
if (post->buffer == NULL) {
|
||||
post->buffer = (*cinfo->mem->access_virt_sarray)
|
||||
((j_common_ptr) cinfo, post->whole_image,
|
||||
(JDIMENSION) 0, post->strip_height, TRUE);
|
||||
post->buffer = (*cinfo->mem->access_virt_sarray)
|
||||
((j_common_ptr) cinfo, post->whole_image,
|
||||
(JDIMENSION) 0, post->strip_height, TRUE);
|
||||
}
|
||||
} else {
|
||||
/* For single-pass processing without color quantization,
|
||||
@ -124,10 +124,10 @@ start_pass_dpost (j_decompress_ptr cinfo, J_BUF_MODE pass_mode)
|
||||
|
||||
METHODDEF(void)
|
||||
post_process_1pass (j_decompress_ptr cinfo,
|
||||
JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
|
||||
JDIMENSION in_row_groups_avail,
|
||||
JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
|
||||
JDIMENSION out_rows_avail)
|
||||
JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
|
||||
JDIMENSION in_row_groups_avail,
|
||||
JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
|
||||
JDIMENSION out_rows_avail)
|
||||
{
|
||||
my_post_ptr post = (my_post_ptr) cinfo->post;
|
||||
JDIMENSION num_rows, max_rows;
|
||||
@ -139,11 +139,11 @@ post_process_1pass (j_decompress_ptr cinfo,
|
||||
max_rows = post->strip_height;
|
||||
num_rows = 0;
|
||||
(*cinfo->upsample->upsample) (cinfo,
|
||||
input_buf, in_row_group_ctr, in_row_groups_avail,
|
||||
post->buffer, &num_rows, max_rows);
|
||||
input_buf, in_row_group_ctr, in_row_groups_avail,
|
||||
post->buffer, &num_rows, max_rows);
|
||||
/* Quantize and emit data. */
|
||||
(*cinfo->cquantize->color_quantize) (cinfo,
|
||||
post->buffer, output_buf + *out_row_ctr, (int) num_rows);
|
||||
post->buffer, output_buf + *out_row_ctr, (int) num_rows);
|
||||
*out_row_ctr += num_rows;
|
||||
}
|
||||
|
||||
@ -156,10 +156,10 @@ post_process_1pass (j_decompress_ptr cinfo,
|
||||
|
||||
METHODDEF(void)
|
||||
post_process_prepass (j_decompress_ptr cinfo,
|
||||
JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
|
||||
JDIMENSION in_row_groups_avail,
|
||||
JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
|
||||
JDIMENSION out_rows_avail)
|
||||
JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
|
||||
JDIMENSION in_row_groups_avail,
|
||||
JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
|
||||
JDIMENSION out_rows_avail)
|
||||
{
|
||||
my_post_ptr post = (my_post_ptr) cinfo->post;
|
||||
JDIMENSION old_next_row, num_rows;
|
||||
@ -167,22 +167,22 @@ post_process_prepass (j_decompress_ptr cinfo,
|
||||
/* Reposition virtual buffer if at start of strip. */
|
||||
if (post->next_row == 0) {
|
||||
post->buffer = (*cinfo->mem->access_virt_sarray)
|
||||
((j_common_ptr) cinfo, post->whole_image,
|
||||
post->starting_row, post->strip_height, TRUE);
|
||||
((j_common_ptr) cinfo, post->whole_image,
|
||||
post->starting_row, post->strip_height, TRUE);
|
||||
}
|
||||
|
||||
/* Upsample some data (up to a strip height's worth). */
|
||||
old_next_row = post->next_row;
|
||||
(*cinfo->upsample->upsample) (cinfo,
|
||||
input_buf, in_row_group_ctr, in_row_groups_avail,
|
||||
post->buffer, &post->next_row, post->strip_height);
|
||||
input_buf, in_row_group_ctr, in_row_groups_avail,
|
||||
post->buffer, &post->next_row, post->strip_height);
|
||||
|
||||
/* Allow quantizer to scan new data. No data is emitted, */
|
||||
/* but we advance out_row_ctr so outer loop can tell when we're done. */
|
||||
if (post->next_row > old_next_row) {
|
||||
num_rows = post->next_row - old_next_row;
|
||||
(*cinfo->cquantize->color_quantize) (cinfo, post->buffer + old_next_row,
|
||||
(JSAMPARRAY) NULL, (int) num_rows);
|
||||
(JSAMPARRAY) NULL, (int) num_rows);
|
||||
*out_row_ctr += num_rows;
|
||||
}
|
||||
|
||||
@ -200,10 +200,10 @@ post_process_prepass (j_decompress_ptr cinfo,
|
||||
|
||||
METHODDEF(void)
|
||||
post_process_2pass (j_decompress_ptr cinfo,
|
||||
JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
|
||||
JDIMENSION in_row_groups_avail,
|
||||
JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
|
||||
JDIMENSION out_rows_avail)
|
||||
JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
|
||||
JDIMENSION in_row_groups_avail,
|
||||
JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
|
||||
JDIMENSION out_rows_avail)
|
||||
{
|
||||
my_post_ptr post = (my_post_ptr) cinfo->post;
|
||||
JDIMENSION num_rows, max_rows;
|
||||
@ -211,8 +211,8 @@ post_process_2pass (j_decompress_ptr cinfo,
|
||||
/* Reposition virtual buffer if at start of strip. */
|
||||
if (post->next_row == 0) {
|
||||
post->buffer = (*cinfo->mem->access_virt_sarray)
|
||||
((j_common_ptr) cinfo, post->whole_image,
|
||||
post->starting_row, post->strip_height, FALSE);
|
||||
((j_common_ptr) cinfo, post->whole_image,
|
||||
post->starting_row, post->strip_height, FALSE);
|
||||
}
|
||||
|
||||
/* Determine number of rows to emit. */
|
||||
@ -227,8 +227,8 @@ post_process_2pass (j_decompress_ptr cinfo,
|
||||
|
||||
/* Quantize and emit data. */
|
||||
(*cinfo->cquantize->color_quantize) (cinfo,
|
||||
post->buffer + post->next_row, output_buf + *out_row_ctr,
|
||||
(int) num_rows);
|
||||
post->buffer + post->next_row, output_buf + *out_row_ctr,
|
||||
(int) num_rows);
|
||||
*out_row_ctr += num_rows;
|
||||
|
||||
/* Advance if we filled the strip. */
|
||||
@ -253,7 +253,7 @@ jinit_d_post_controller (j_decompress_ptr cinfo, boolean need_full_buffer)
|
||||
|
||||
post = (my_post_ptr)
|
||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
||||
SIZEOF(my_post_controller));
|
||||
SIZEOF(my_post_controller));
|
||||
cinfo->post = (struct jpeg_d_post_controller *) post;
|
||||
post->pub.start_pass = start_pass_dpost;
|
||||
post->whole_image = NULL; /* flag for no virtual arrays */
|
||||
@ -271,20 +271,20 @@ jinit_d_post_controller (j_decompress_ptr cinfo, boolean need_full_buffer)
|
||||
/* We round up the number of rows to a multiple of the strip height. */
|
||||
#ifdef QUANT_2PASS_SUPPORTED
|
||||
post->whole_image = (*cinfo->mem->request_virt_sarray)
|
||||
((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE,
|
||||
cinfo->output_width * cinfo->out_color_components,
|
||||
(JDIMENSION) jround_up((long) cinfo->output_height,
|
||||
(long) post->strip_height),
|
||||
post->strip_height);
|
||||
((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE,
|
||||
cinfo->output_width * cinfo->out_color_components,
|
||||
(JDIMENSION) jround_up((long) cinfo->output_height,
|
||||
(long) post->strip_height),
|
||||
post->strip_height);
|
||||
#else
|
||||
ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
|
||||
#endif /* QUANT_2PASS_SUPPORTED */
|
||||
} else {
|
||||
/* One-pass color quantization: just make a strip buffer. */
|
||||
post->buffer = (*cinfo->mem->alloc_sarray)
|
||||
((j_common_ptr) cinfo, JPOOL_IMAGE,
|
||||
cinfo->output_width * cinfo->out_color_components,
|
||||
post->strip_height);
|
||||
((j_common_ptr) cinfo, JPOOL_IMAGE,
|
||||
cinfo->output_width * cinfo->out_color_components,
|
||||
post->strip_height);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
203
3rdparty/libjpeg/jdsample.c
vendored
203
3rdparty/libjpeg/jdsample.c
vendored
@ -2,13 +2,14 @@
|
||||
* jdsample.c
|
||||
*
|
||||
* Copyright (C) 1991-1996, Thomas G. Lane.
|
||||
* Modified 2002-2008 by Guido Vollbeding.
|
||||
* This file is part of the Independent JPEG Group's software.
|
||||
* For conditions of distribution and use, see the accompanying README file.
|
||||
*
|
||||
* This file contains upsampling routines.
|
||||
*
|
||||
* Upsampling input data is counted in "row groups". A row group
|
||||
* is defined to be (v_samp_factor * DCT_scaled_size / min_DCT_scaled_size)
|
||||
* is defined to be (v_samp_factor * DCT_v_scaled_size / min_DCT_v_scaled_size)
|
||||
* sample rows of each component. Upsampling will normally produce
|
||||
* max_v_samp_factor pixel rows from each row group (but this could vary
|
||||
* if the upsampler is applying a scale factor of its own).
|
||||
@ -25,8 +26,8 @@
|
||||
|
||||
/* Pointer to routine to upsample a single component */
|
||||
typedef JMETHOD(void, upsample1_ptr,
|
||||
(j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
||||
JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr));
|
||||
(j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
||||
JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr));
|
||||
|
||||
/* Private subobject */
|
||||
|
||||
@ -87,10 +88,10 @@ start_pass_upsample (j_decompress_ptr cinfo)
|
||||
|
||||
METHODDEF(void)
|
||||
sep_upsample (j_decompress_ptr cinfo,
|
||||
JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
|
||||
JDIMENSION in_row_groups_avail,
|
||||
JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
|
||||
JDIMENSION out_rows_avail)
|
||||
JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
|
||||
JDIMENSION in_row_groups_avail,
|
||||
JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
|
||||
JDIMENSION out_rows_avail)
|
||||
{
|
||||
my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
|
||||
int ci;
|
||||
@ -100,13 +101,13 @@ sep_upsample (j_decompress_ptr cinfo,
|
||||
/* Fill the conversion buffer, if it's empty */
|
||||
if (upsample->next_row_out >= cinfo->max_v_samp_factor) {
|
||||
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
|
||||
ci++, compptr++) {
|
||||
ci++, compptr++) {
|
||||
/* Invoke per-component upsample method. Notice we pass a POINTER
|
||||
* to color_buf[ci], so that fullsize_upsample can change it.
|
||||
*/
|
||||
(*upsample->methods[ci]) (cinfo, compptr,
|
||||
input_buf[ci] + (*in_row_group_ctr * upsample->rowgroup_height[ci]),
|
||||
upsample->color_buf + ci);
|
||||
input_buf[ci] + (*in_row_group_ctr * upsample->rowgroup_height[ci]),
|
||||
upsample->color_buf + ci);
|
||||
}
|
||||
upsample->next_row_out = 0;
|
||||
}
|
||||
@ -126,9 +127,9 @@ sep_upsample (j_decompress_ptr cinfo,
|
||||
num_rows = out_rows_avail;
|
||||
|
||||
(*cinfo->cconvert->color_convert) (cinfo, upsample->color_buf,
|
||||
(JDIMENSION) upsample->next_row_out,
|
||||
output_buf + *out_row_ctr,
|
||||
(int) num_rows);
|
||||
(JDIMENSION) upsample->next_row_out,
|
||||
output_buf + *out_row_ctr,
|
||||
(int) num_rows);
|
||||
|
||||
/* Adjust counts */
|
||||
*out_row_ctr += num_rows;
|
||||
@ -155,7 +156,7 @@ sep_upsample (j_decompress_ptr cinfo,
|
||||
|
||||
METHODDEF(void)
|
||||
fullsize_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
||||
JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
|
||||
JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
|
||||
{
|
||||
*output_data_ptr = input_data;
|
||||
}
|
||||
@ -168,7 +169,7 @@ fullsize_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
||||
|
||||
METHODDEF(void)
|
||||
noop_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
||||
JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
|
||||
JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
|
||||
{
|
||||
*output_data_ptr = NULL; /* safety check */
|
||||
}
|
||||
@ -187,7 +188,7 @@ noop_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
||||
|
||||
METHODDEF(void)
|
||||
int_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
||||
JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
|
||||
JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
|
||||
{
|
||||
my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
|
||||
JSAMPARRAY output_data = *output_data_ptr;
|
||||
@ -210,13 +211,13 @@ int_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
||||
while (outptr < outend) {
|
||||
invalue = *inptr++; /* don't need GETJSAMPLE() here */
|
||||
for (h = h_expand; h > 0; h--) {
|
||||
*outptr++ = invalue;
|
||||
*outptr++ = invalue;
|
||||
}
|
||||
}
|
||||
/* Generate any additional output rows by duplicating the first one */
|
||||
if (v_expand > 1) {
|
||||
jcopy_sample_rows(output_data, outrow, output_data, outrow+1,
|
||||
v_expand-1, cinfo->output_width);
|
||||
v_expand-1, cinfo->output_width);
|
||||
}
|
||||
inrow++;
|
||||
outrow += v_expand;
|
||||
@ -231,17 +232,17 @@ int_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
||||
|
||||
METHODDEF(void)
|
||||
h2v1_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
||||
JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
|
||||
JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
|
||||
{
|
||||
JSAMPARRAY output_data = *output_data_ptr;
|
||||
register JSAMPROW inptr, outptr;
|
||||
register JSAMPLE invalue;
|
||||
JSAMPROW outend;
|
||||
int inrow;
|
||||
int outrow;
|
||||
|
||||
for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) {
|
||||
inptr = input_data[inrow];
|
||||
outptr = output_data[inrow];
|
||||
for (outrow = 0; outrow < cinfo->max_v_samp_factor; outrow++) {
|
||||
inptr = input_data[outrow];
|
||||
outptr = output_data[outrow];
|
||||
outend = outptr + cinfo->output_width;
|
||||
while (outptr < outend) {
|
||||
invalue = *inptr++; /* don't need GETJSAMPLE() here */
|
||||
@ -259,7 +260,7 @@ h2v1_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
||||
|
||||
METHODDEF(void)
|
||||
h2v2_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
||||
JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
|
||||
JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
|
||||
{
|
||||
JSAMPARRAY output_data = *output_data_ptr;
|
||||
register JSAMPROW inptr, outptr;
|
||||
@ -278,119 +279,13 @@ h2v2_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
||||
*outptr++ = invalue;
|
||||
}
|
||||
jcopy_sample_rows(output_data, outrow, output_data, outrow+1,
|
||||
1, cinfo->output_width);
|
||||
1, cinfo->output_width);
|
||||
inrow++;
|
||||
outrow += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Fancy processing for the common case of 2:1 horizontal and 1:1 vertical.
|
||||
*
|
||||
* The upsampling algorithm is linear interpolation between pixel centers,
|
||||
* also known as a "triangle filter". This is a good compromise between
|
||||
* speed and visual quality. The centers of the output pixels are 1/4 and 3/4
|
||||
* of the way between input pixel centers.
|
||||
*
|
||||
* A note about the "bias" calculations: when rounding fractional values to
|
||||
* integer, we do not want to always round 0.5 up to the next integer.
|
||||
* If we did that, we'd introduce a noticeable bias towards larger values.
|
||||
* Instead, this code is arranged so that 0.5 will be rounded up or down at
|
||||
* alternate pixel locations (a simple ordered dither pattern).
|
||||
*/
|
||||
|
||||
METHODDEF(void)
|
||||
h2v1_fancy_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
||||
JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
|
||||
{
|
||||
JSAMPARRAY output_data = *output_data_ptr;
|
||||
register JSAMPROW inptr, outptr;
|
||||
register int invalue;
|
||||
register JDIMENSION colctr;
|
||||
int inrow;
|
||||
|
||||
for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) {
|
||||
inptr = input_data[inrow];
|
||||
outptr = output_data[inrow];
|
||||
/* Special case for first column */
|
||||
invalue = GETJSAMPLE(*inptr++);
|
||||
*outptr++ = (JSAMPLE) invalue;
|
||||
*outptr++ = (JSAMPLE) ((invalue * 3 + GETJSAMPLE(*inptr) + 2) >> 2);
|
||||
|
||||
for (colctr = compptr->downsampled_width - 2; colctr > 0; colctr--) {
|
||||
/* General case: 3/4 * nearer pixel + 1/4 * further pixel */
|
||||
invalue = GETJSAMPLE(*inptr++) * 3;
|
||||
*outptr++ = (JSAMPLE) ((invalue + GETJSAMPLE(inptr[-2]) + 1) >> 2);
|
||||
*outptr++ = (JSAMPLE) ((invalue + GETJSAMPLE(*inptr) + 2) >> 2);
|
||||
}
|
||||
|
||||
/* Special case for last column */
|
||||
invalue = GETJSAMPLE(*inptr);
|
||||
*outptr++ = (JSAMPLE) ((invalue * 3 + GETJSAMPLE(inptr[-1]) + 1) >> 2);
|
||||
*outptr++ = (JSAMPLE) invalue;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Fancy processing for the common case of 2:1 horizontal and 2:1 vertical.
|
||||
* Again a triangle filter; see comments for h2v1 case, above.
|
||||
*
|
||||
* It is OK for us to reference the adjacent input rows because we demanded
|
||||
* context from the main buffer controller (see initialization code).
|
||||
*/
|
||||
|
||||
METHODDEF(void)
|
||||
h2v2_fancy_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
||||
JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
|
||||
{
|
||||
JSAMPARRAY output_data = *output_data_ptr;
|
||||
register JSAMPROW inptr0, inptr1, outptr;
|
||||
#if BITS_IN_JSAMPLE == 8
|
||||
register int thiscolsum, lastcolsum, nextcolsum;
|
||||
#else
|
||||
register INT32 thiscolsum, lastcolsum, nextcolsum;
|
||||
#endif
|
||||
register JDIMENSION colctr;
|
||||
int inrow, outrow, v;
|
||||
|
||||
inrow = outrow = 0;
|
||||
while (outrow < cinfo->max_v_samp_factor) {
|
||||
for (v = 0; v < 2; v++) {
|
||||
/* inptr0 points to nearest input row, inptr1 points to next nearest */
|
||||
inptr0 = input_data[inrow];
|
||||
if (v == 0) /* next nearest is row above */
|
||||
inptr1 = input_data[inrow-1];
|
||||
else /* next nearest is row below */
|
||||
inptr1 = input_data[inrow+1];
|
||||
outptr = output_data[outrow++];
|
||||
|
||||
/* Special case for first column */
|
||||
thiscolsum = GETJSAMPLE(*inptr0++) * 3 + GETJSAMPLE(*inptr1++);
|
||||
nextcolsum = GETJSAMPLE(*inptr0++) * 3 + GETJSAMPLE(*inptr1++);
|
||||
*outptr++ = (JSAMPLE) ((thiscolsum * 4 + 8) >> 4);
|
||||
*outptr++ = (JSAMPLE) ((thiscolsum * 3 + nextcolsum + 7) >> 4);
|
||||
lastcolsum = thiscolsum; thiscolsum = nextcolsum;
|
||||
|
||||
for (colctr = compptr->downsampled_width - 2; colctr > 0; colctr--) {
|
||||
/* General case: 3/4 * nearer pixel + 1/4 * further pixel in each */
|
||||
/* dimension, thus 9/16, 3/16, 3/16, 1/16 overall */
|
||||
nextcolsum = GETJSAMPLE(*inptr0++) * 3 + GETJSAMPLE(*inptr1++);
|
||||
*outptr++ = (JSAMPLE) ((thiscolsum * 3 + lastcolsum + 8) >> 4);
|
||||
*outptr++ = (JSAMPLE) ((thiscolsum * 3 + nextcolsum + 7) >> 4);
|
||||
lastcolsum = thiscolsum; thiscolsum = nextcolsum;
|
||||
}
|
||||
|
||||
/* Special case for last column */
|
||||
*outptr++ = (JSAMPLE) ((thiscolsum * 3 + lastcolsum + 8) >> 4);
|
||||
*outptr++ = (JSAMPLE) ((thiscolsum * 4 + 7) >> 4);
|
||||
}
|
||||
inrow++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Module initialization routine for upsampling.
|
||||
*/
|
||||
@ -401,12 +296,12 @@ jinit_upsampler (j_decompress_ptr cinfo)
|
||||
my_upsample_ptr upsample;
|
||||
int ci;
|
||||
jpeg_component_info * compptr;
|
||||
boolean need_buffer, do_fancy;
|
||||
boolean need_buffer;
|
||||
int h_in_group, v_in_group, h_out_group, v_out_group;
|
||||
|
||||
upsample = (my_upsample_ptr)
|
||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
||||
SIZEOF(my_upsampler));
|
||||
SIZEOF(my_upsampler));
|
||||
cinfo->upsample = (struct jpeg_upsampler *) upsample;
|
||||
upsample->pub.start_pass = start_pass_upsample;
|
||||
upsample->pub.upsample = sep_upsample;
|
||||
@ -415,11 +310,6 @@ jinit_upsampler (j_decompress_ptr cinfo)
|
||||
if (cinfo->CCIR601_sampling) /* this isn't supported */
|
||||
ERREXIT(cinfo, JERR_CCIR601_NOTIMPL);
|
||||
|
||||
/* jdmainct.c doesn't support context rows when min_DCT_scaled_size = 1,
|
||||
* so don't ask for it.
|
||||
*/
|
||||
do_fancy = cinfo->do_fancy_upsampling && cinfo->min_DCT_scaled_size > 1;
|
||||
|
||||
/* Verify we can handle the sampling factors, select per-component methods,
|
||||
* and create storage as needed.
|
||||
*/
|
||||
@ -428,10 +318,10 @@ jinit_upsampler (j_decompress_ptr cinfo)
|
||||
/* Compute size of an "input group" after IDCT scaling. This many samples
|
||||
* are to be converted to max_h_samp_factor * max_v_samp_factor pixels.
|
||||
*/
|
||||
h_in_group = (compptr->h_samp_factor * compptr->DCT_scaled_size) /
|
||||
cinfo->min_DCT_scaled_size;
|
||||
v_in_group = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
|
||||
cinfo->min_DCT_scaled_size;
|
||||
h_in_group = (compptr->h_samp_factor * compptr->DCT_h_scaled_size) /
|
||||
cinfo->min_DCT_h_scaled_size;
|
||||
v_in_group = (compptr->v_samp_factor * compptr->DCT_v_scaled_size) /
|
||||
cinfo->min_DCT_v_scaled_size;
|
||||
h_out_group = cinfo->max_h_samp_factor;
|
||||
v_out_group = cinfo->max_v_samp_factor;
|
||||
upsample->rowgroup_height[ci] = v_in_group; /* save for use later */
|
||||
@ -445,22 +335,15 @@ jinit_upsampler (j_decompress_ptr cinfo)
|
||||
upsample->methods[ci] = fullsize_upsample;
|
||||
need_buffer = FALSE;
|
||||
} else if (h_in_group * 2 == h_out_group &&
|
||||
v_in_group == v_out_group) {
|
||||
/* Special cases for 2h1v upsampling */
|
||||
if (do_fancy && compptr->downsampled_width > 2)
|
||||
upsample->methods[ci] = h2v1_fancy_upsample;
|
||||
else
|
||||
upsample->methods[ci] = h2v1_upsample;
|
||||
v_in_group == v_out_group) {
|
||||
/* Special case for 2h1v upsampling */
|
||||
upsample->methods[ci] = h2v1_upsample;
|
||||
} else if (h_in_group * 2 == h_out_group &&
|
||||
v_in_group * 2 == v_out_group) {
|
||||
/* Special cases for 2h2v upsampling */
|
||||
if (do_fancy && compptr->downsampled_width > 2) {
|
||||
upsample->methods[ci] = h2v2_fancy_upsample;
|
||||
upsample->pub.need_context_rows = TRUE;
|
||||
} else
|
||||
upsample->methods[ci] = h2v2_upsample;
|
||||
v_in_group * 2 == v_out_group) {
|
||||
/* Special case for 2h2v upsampling */
|
||||
upsample->methods[ci] = h2v2_upsample;
|
||||
} else if ((h_out_group % h_in_group) == 0 &&
|
||||
(v_out_group % v_in_group) == 0) {
|
||||
(v_out_group % v_in_group) == 0) {
|
||||
/* Generic integral-factors upsampling method */
|
||||
upsample->methods[ci] = int_upsample;
|
||||
upsample->h_expand[ci] = (UINT8) (h_out_group / h_in_group);
|
||||
@ -469,10 +352,10 @@ jinit_upsampler (j_decompress_ptr cinfo)
|
||||
ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL);
|
||||
if (need_buffer) {
|
||||
upsample->color_buf[ci] = (*cinfo->mem->alloc_sarray)
|
||||
((j_common_ptr) cinfo, JPOOL_IMAGE,
|
||||
(JDIMENSION) jround_up((long) cinfo->output_width,
|
||||
(long) cinfo->max_h_samp_factor),
|
||||
(JDIMENSION) cinfo->max_v_samp_factor);
|
||||
((j_common_ptr) cinfo, JPOOL_IMAGE,
|
||||
(JDIMENSION) jround_up((long) cinfo->output_width,
|
||||
(long) cinfo->max_h_samp_factor),
|
||||
(JDIMENSION) cinfo->max_v_samp_factor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
35
3rdparty/libjpeg/jdtrans.c
vendored
35
3rdparty/libjpeg/jdtrans.c
vendored
@ -2,6 +2,7 @@
|
||||
* jdtrans.c
|
||||
*
|
||||
* Copyright (C) 1995-1997, Thomas G. Lane.
|
||||
* Modified 2000-2009 by Guido Vollbeding.
|
||||
* This file is part of the Independent JPEG Group's software.
|
||||
* For conditions of distribution and use, see the accompanying README file.
|
||||
*
|
||||
@ -55,20 +56,20 @@ jpeg_read_coefficients (j_decompress_ptr cinfo)
|
||||
int retcode;
|
||||
/* Call progress monitor hook if present */
|
||||
if (cinfo->progress != NULL)
|
||||
(*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
|
||||
(*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
|
||||
/* Absorb some more input */
|
||||
retcode = (*cinfo->inputctl->consume_input) (cinfo);
|
||||
if (retcode == JPEG_SUSPENDED)
|
||||
return NULL;
|
||||
return NULL;
|
||||
if (retcode == JPEG_REACHED_EOI)
|
||||
break;
|
||||
break;
|
||||
/* Advance progress counter if appropriate */
|
||||
if (cinfo->progress != NULL &&
|
||||
(retcode == JPEG_ROW_COMPLETED || retcode == JPEG_REACHED_SOS)) {
|
||||
if (++cinfo->progress->pass_counter >= cinfo->progress->pass_limit) {
|
||||
/* startup underestimated number of scans; ratchet up one scan */
|
||||
cinfo->progress->pass_limit += (long) cinfo->total_iMCU_rows;
|
||||
}
|
||||
(retcode == JPEG_ROW_COMPLETED || retcode == JPEG_REACHED_SOS)) {
|
||||
if (++cinfo->progress->pass_counter >= cinfo->progress->pass_limit) {
|
||||
/* startup underestimated number of scans; ratchet up one scan */
|
||||
cinfo->progress->pass_limit += (long) cinfo->total_iMCU_rows;
|
||||
}
|
||||
}
|
||||
}
|
||||
/* Set state so that jpeg_finish_decompress does the right thing */
|
||||
@ -99,18 +100,14 @@ transdecode_master_selection (j_decompress_ptr cinfo)
|
||||
/* This is effectively a buffered-image operation. */
|
||||
cinfo->buffered_image = TRUE;
|
||||
|
||||
/* Compute output image dimensions and related values. */
|
||||
jpeg_core_output_dimensions(cinfo);
|
||||
|
||||
/* Entropy decoding: either Huffman or arithmetic coding. */
|
||||
if (cinfo->arith_code) {
|
||||
ERREXIT(cinfo, JERR_ARITH_NOTIMPL);
|
||||
} else {
|
||||
if (cinfo->progressive_mode) {
|
||||
#ifdef D_PROGRESSIVE_SUPPORTED
|
||||
jinit_phuff_decoder(cinfo);
|
||||
#else
|
||||
ERREXIT(cinfo, JERR_NOT_COMPILED);
|
||||
#endif
|
||||
} else
|
||||
jinit_huff_decoder(cinfo);
|
||||
if (cinfo->arith_code)
|
||||
jinit_arith_decoder(cinfo);
|
||||
else {
|
||||
jinit_huff_decoder(cinfo);
|
||||
}
|
||||
|
||||
/* Always get a full-image coefficient buffer. */
|
||||
|
18
3rdparty/libjpeg/jerror.c
vendored
18
3rdparty/libjpeg/jerror.c
vendored
@ -2,6 +2,7 @@
|
||||
* jerror.c
|
||||
*
|
||||
* Copyright (C) 1991-1998, Thomas G. Lane.
|
||||
* Modified 2012 by Guido Vollbeding.
|
||||
* This file is part of the Independent JPEG Group's software.
|
||||
* For conditions of distribution and use, see the accompanying README file.
|
||||
*
|
||||
@ -23,7 +24,6 @@
|
||||
#include "jpeglib.h"
|
||||
#include "jversion.h"
|
||||
#include "jerror.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef USE_WINDOWS_MESSAGEBOX
|
||||
#include <windows.h>
|
||||
@ -67,7 +67,7 @@ const char * const jpeg_std_message_table[] = {
|
||||
* or jpeg_destroy) at some point.
|
||||
*/
|
||||
|
||||
METHODDEF(void)
|
||||
METHODDEF(noreturn_t)
|
||||
error_exit (j_common_ptr cinfo)
|
||||
{
|
||||
/* Always display the message */
|
||||
@ -106,7 +106,7 @@ output_message (j_common_ptr cinfo)
|
||||
#ifdef USE_WINDOWS_MESSAGEBOX
|
||||
/* Display it in a message dialog box */
|
||||
MessageBox(GetActiveWindow(), buffer, "JPEG Library Error",
|
||||
MB_OK | MB_ICONERROR);
|
||||
MB_OK | MB_ICONERROR);
|
||||
#else
|
||||
/* Send it to stderr, adding a newline */
|
||||
fprintf(stderr, "%s\n", buffer);
|
||||
@ -168,8 +168,8 @@ format_message (j_common_ptr cinfo, char * buffer)
|
||||
if (msg_code > 0 && msg_code <= err->last_jpeg_message) {
|
||||
msgtext = err->jpeg_message_table[msg_code];
|
||||
} else if (err->addon_message_table != NULL &&
|
||||
msg_code >= err->first_addon_message &&
|
||||
msg_code <= err->last_addon_message) {
|
||||
msg_code >= err->first_addon_message &&
|
||||
msg_code <= err->last_addon_message) {
|
||||
msgtext = err->addon_message_table[msg_code - err->first_addon_message];
|
||||
}
|
||||
|
||||
@ -194,10 +194,10 @@ format_message (j_common_ptr cinfo, char * buffer)
|
||||
sprintf(buffer, msgtext, err->msg_parm.s);
|
||||
else
|
||||
sprintf(buffer, msgtext,
|
||||
err->msg_parm.i[0], err->msg_parm.i[1],
|
||||
err->msg_parm.i[2], err->msg_parm.i[3],
|
||||
err->msg_parm.i[4], err->msg_parm.i[5],
|
||||
err->msg_parm.i[6], err->msg_parm.i[7]);
|
||||
err->msg_parm.i[0], err->msg_parm.i[1],
|
||||
err->msg_parm.i[2], err->msg_parm.i[3],
|
||||
err->msg_parm.i[4], err->msg_parm.i[5],
|
||||
err->msg_parm.i[6], err->msg_parm.i[7]);
|
||||
}
|
||||
|
||||
|
||||
|
86
3rdparty/libjpeg/jerror.h
vendored
86
3rdparty/libjpeg/jerror.h
vendored
@ -2,6 +2,7 @@
|
||||
* jerror.h
|
||||
*
|
||||
* Copyright (C) 1994-1997, Thomas G. Lane.
|
||||
* Modified 1997-2012 by Guido Vollbeding.
|
||||
* This file is part of the Independent JPEG Group's software.
|
||||
* For conditions of distribution and use, see the accompanying README file.
|
||||
*
|
||||
@ -39,33 +40,33 @@ typedef enum {
|
||||
JMESSAGE(JMSG_NOMESSAGE, "Bogus message code %d") /* Must be first entry! */
|
||||
|
||||
/* For maintenance convenience, list is alphabetical by message code name */
|
||||
JMESSAGE(JERR_ARITH_NOTIMPL,
|
||||
"Sorry, there are legal restrictions on arithmetic coding")
|
||||
JMESSAGE(JERR_BAD_ALIGN_TYPE, "ALIGN_TYPE is wrong, please fix")
|
||||
JMESSAGE(JERR_BAD_ALLOC_CHUNK, "MAX_ALLOC_CHUNK is wrong, please fix")
|
||||
JMESSAGE(JERR_BAD_BUFFER_MODE, "Bogus buffer control mode")
|
||||
JMESSAGE(JERR_BAD_COMPONENT_ID, "Invalid component ID %d in SOS")
|
||||
JMESSAGE(JERR_BAD_CROP_SPEC, "Invalid crop request")
|
||||
JMESSAGE(JERR_BAD_DCT_COEF, "DCT coefficient out of range")
|
||||
JMESSAGE(JERR_BAD_DCTSIZE, "IDCT output block size %d not supported")
|
||||
JMESSAGE(JERR_BAD_DCTSIZE, "DCT scaled block size %dx%d not supported")
|
||||
JMESSAGE(JERR_BAD_DROP_SAMPLING,
|
||||
"Component index %d: mismatching sampling ratio %d:%d, %d:%d, %c")
|
||||
JMESSAGE(JERR_BAD_HUFF_TABLE, "Bogus Huffman table definition")
|
||||
JMESSAGE(JERR_BAD_IN_COLORSPACE, "Bogus input colorspace")
|
||||
JMESSAGE(JERR_BAD_J_COLORSPACE, "Bogus JPEG colorspace")
|
||||
JMESSAGE(JERR_BAD_LENGTH, "Bogus marker length")
|
||||
JMESSAGE(JERR_BAD_LIB_VERSION,
|
||||
"Wrong JPEG library version: library is %d, caller expects %d")
|
||||
"Wrong JPEG library version: library is %d, caller expects %d")
|
||||
JMESSAGE(JERR_BAD_MCU_SIZE, "Sampling factors too large for interleaved scan")
|
||||
JMESSAGE(JERR_BAD_POOL_ID, "Invalid memory pool code %d")
|
||||
JMESSAGE(JERR_BAD_PRECISION, "Unsupported JPEG data precision %d")
|
||||
JMESSAGE(JERR_BAD_PROGRESSION,
|
||||
"Invalid progressive parameters Ss=%d Se=%d Ah=%d Al=%d")
|
||||
"Invalid progressive parameters Ss=%d Se=%d Ah=%d Al=%d")
|
||||
JMESSAGE(JERR_BAD_PROG_SCRIPT,
|
||||
"Invalid progressive parameters at scan script entry %d")
|
||||
"Invalid progressive parameters at scan script entry %d")
|
||||
JMESSAGE(JERR_BAD_SAMPLING, "Bogus sampling factors")
|
||||
JMESSAGE(JERR_BAD_SCAN_SCRIPT, "Invalid scan script at entry %d")
|
||||
JMESSAGE(JERR_BAD_STATE, "Improper call to JPEG library in state %d")
|
||||
JMESSAGE(JERR_BAD_STRUCT_SIZE,
|
||||
"JPEG parameter struct mismatch: library thinks size is %u, caller expects %u")
|
||||
"JPEG parameter struct mismatch: library thinks size is %u, caller expects %u")
|
||||
JMESSAGE(JERR_BAD_VIRTUAL_ACCESS, "Bogus virtual array access")
|
||||
JMESSAGE(JERR_BUFFER_SIZE, "Buffer passed to JPEG library is too small")
|
||||
JMESSAGE(JERR_CANT_SUSPEND, "Suspension not allowed here")
|
||||
@ -89,11 +90,12 @@ JMESSAGE(JERR_IMAGE_TOO_BIG, "Maximum supported image dimension is %u pixels")
|
||||
JMESSAGE(JERR_INPUT_EMPTY, "Empty input file")
|
||||
JMESSAGE(JERR_INPUT_EOF, "Premature end of input file")
|
||||
JMESSAGE(JERR_MISMATCHED_QUANT_TABLE,
|
||||
"Cannot transcode due to multiple use of quantization table %d")
|
||||
"Cannot transcode due to multiple use of quantization table %d")
|
||||
JMESSAGE(JERR_MISSING_DATA, "Scan script does not transmit all data")
|
||||
JMESSAGE(JERR_MODE_CHANGE, "Invalid color quantization mode change")
|
||||
JMESSAGE(JERR_NOTIMPL, "Not implemented yet")
|
||||
JMESSAGE(JERR_NOT_COMPILED, "Requested feature was omitted at compile time")
|
||||
JMESSAGE(JERR_NO_ARITH_TABLE, "Arithmetic table 0x%02x was not defined")
|
||||
JMESSAGE(JERR_NO_BACKING_STORE, "Backing store not supported")
|
||||
JMESSAGE(JERR_NO_HUFF_TABLE, "Huffman table 0x%02x was not defined")
|
||||
JMESSAGE(JERR_NO_IMAGE, "JPEG datastream contains no image")
|
||||
@ -101,19 +103,19 @@ JMESSAGE(JERR_NO_QUANT_TABLE, "Quantization table 0x%02x was not defined")
|
||||
JMESSAGE(JERR_NO_SOI, "Not a JPEG file: starts with 0x%02x 0x%02x")
|
||||
JMESSAGE(JERR_OUT_OF_MEMORY, "Insufficient memory (case %d)")
|
||||
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_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_NO_SOS, "Invalid JPEG file structure: missing SOS marker")
|
||||
JMESSAGE(JERR_SOF_UNSUPPORTED, "Unsupported JPEG process: SOF type 0x%02x")
|
||||
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_READ, "Read failed on temporary file")
|
||||
JMESSAGE(JERR_TFILE_SEEK, "Seek failed on temporary file")
|
||||
JMESSAGE(JERR_TFILE_WRITE,
|
||||
"Write failed on temporary file --- out of disk space?")
|
||||
"Write failed on temporary file --- out of disk space?")
|
||||
JMESSAGE(JERR_TOO_LITTLE_DATA, "Application transferred too few scanlines")
|
||||
JMESSAGE(JERR_UNKNOWN_MARKER, "Unsupported marker type 0x%02x")
|
||||
JMESSAGE(JERR_VIRTUAL_BUG, "Virtual array controller messed up")
|
||||
@ -123,9 +125,9 @@ JMESSAGE(JERR_XMS_WRITE, "Write to XMS failed")
|
||||
JMESSAGE(JMSG_COPYRIGHT, JCOPYRIGHT)
|
||||
JMESSAGE(JMSG_VERSION, JVERSION)
|
||||
JMESSAGE(JTRC_16BIT_TABLES,
|
||||
"Caution: quantization tables are too coarse for baseline JPEG")
|
||||
"Caution: quantization tables are too coarse for baseline JPEG")
|
||||
JMESSAGE(JTRC_ADOBE,
|
||||
"Adobe APP14 marker: version %d, flags 0x%04x 0x%04x, transform %d")
|
||||
"Adobe APP14 marker: version %d, flags 0x%04x 0x%04x, transform %d")
|
||||
JMESSAGE(JTRC_APP0, "Unknown APP0 marker (not JFIF), length %u")
|
||||
JMESSAGE(JTRC_APP14, "Unknown APP14 marker (not Adobe), length %u")
|
||||
JMESSAGE(JTRC_DAC, "Define Arithmetic Table 0x%02x: 0x%02x")
|
||||
@ -138,9 +140,9 @@ JMESSAGE(JTRC_EOI, "End Of Image")
|
||||
JMESSAGE(JTRC_HUFFBITS, " %3d %3d %3d %3d %3d %3d %3d %3d")
|
||||
JMESSAGE(JTRC_JFIF, "JFIF APP0 marker: version %d.%02d, density %dx%d %d")
|
||||
JMESSAGE(JTRC_JFIF_BADTHUMBNAILSIZE,
|
||||
"Warning: thumbnail image size does not match data length %u")
|
||||
"Warning: thumbnail image size does not match data length %u")
|
||||
JMESSAGE(JTRC_JFIF_EXTENSION,
|
||||
"JFIF extension marker: type 0x%02x, length %u")
|
||||
"JFIF extension marker: type 0x%02x, length %u")
|
||||
JMESSAGE(JTRC_JFIF_THUMBNAIL, " with %d x %d thumbnail image")
|
||||
JMESSAGE(JTRC_MISC_MARKER, "Miscellaneous marker 0x%02x, length %u")
|
||||
JMESSAGE(JTRC_PARMLESS_MARKER, "Unexpected marker 0x%02x")
|
||||
@ -151,7 +153,7 @@ JMESSAGE(JTRC_QUANT_SELECTED, "Selected %d colors for quantization")
|
||||
JMESSAGE(JTRC_RECOVERY_ACTION, "At marker 0x%02x, recovery action %d")
|
||||
JMESSAGE(JTRC_RST, "RST%d")
|
||||
JMESSAGE(JTRC_SMOOTH_NOTIMPL,
|
||||
"Smoothing not supported with nonstandard sampling ratios")
|
||||
"Smoothing not supported with nonstandard sampling ratios")
|
||||
JMESSAGE(JTRC_SOF, "Start Of Frame 0x%02x: width=%u, height=%u, components=%d")
|
||||
JMESSAGE(JTRC_SOF_COMPONENT, " Component %d: %dhx%dv q=%d")
|
||||
JMESSAGE(JTRC_SOI, "Start of Image")
|
||||
@ -161,26 +163,27 @@ JMESSAGE(JTRC_SOS_PARAMS, " Ss=%d, Se=%d, Ah=%d, Al=%d")
|
||||
JMESSAGE(JTRC_TFILE_CLOSE, "Closed temporary file %s")
|
||||
JMESSAGE(JTRC_TFILE_OPEN, "Opened temporary file %s")
|
||||
JMESSAGE(JTRC_THUMB_JPEG,
|
||||
"JFIF extension marker: JPEG-compressed thumbnail image, length %u")
|
||||
"JFIF extension marker: JPEG-compressed thumbnail image, length %u")
|
||||
JMESSAGE(JTRC_THUMB_PALETTE,
|
||||
"JFIF extension marker: palette thumbnail image, length %u")
|
||||
"JFIF extension marker: palette thumbnail image, length %u")
|
||||
JMESSAGE(JTRC_THUMB_RGB,
|
||||
"JFIF extension marker: RGB thumbnail image, length %u")
|
||||
"JFIF extension marker: RGB thumbnail image, length %u")
|
||||
JMESSAGE(JTRC_UNKNOWN_IDS,
|
||||
"Unrecognized component IDs %d %d %d, assuming YCbCr")
|
||||
"Unrecognized component IDs %d %d %d, assuming YCbCr")
|
||||
JMESSAGE(JTRC_XMS_CLOSE, "Freed XMS handle %u")
|
||||
JMESSAGE(JTRC_XMS_OPEN, "Obtained XMS handle %u")
|
||||
JMESSAGE(JWRN_ADOBE_XFORM, "Unknown Adobe color transform code %d")
|
||||
JMESSAGE(JWRN_ARITH_BAD_CODE, "Corrupt JPEG data: bad arithmetic code")
|
||||
JMESSAGE(JWRN_BOGUS_PROGRESSION,
|
||||
"Inconsistent progression sequence for component %d coefficient %d")
|
||||
"Inconsistent progression sequence for component %d coefficient %d")
|
||||
JMESSAGE(JWRN_EXTRANEOUS_DATA,
|
||||
"Corrupt JPEG data: %u extraneous bytes before marker 0x%02x")
|
||||
"Corrupt JPEG data: %u extraneous bytes before marker 0x%02x")
|
||||
JMESSAGE(JWRN_HIT_MARKER, "Corrupt JPEG data: premature end of data segment")
|
||||
JMESSAGE(JWRN_HUFF_BAD_CODE, "Corrupt JPEG data: bad Huffman code")
|
||||
JMESSAGE(JWRN_JFIF_MAJOR, "Warning: unknown JFIF revision number %d.%02d")
|
||||
JMESSAGE(JWRN_JPEG_EOF, "Premature end of JPEG file")
|
||||
JMESSAGE(JWRN_MUST_RESYNC,
|
||||
"Corrupt JPEG data: found marker 0x%02x instead of RST%d")
|
||||
"Corrupt JPEG data: found marker 0x%02x instead of RST%d")
|
||||
JMESSAGE(JWRN_NOT_SEQUENTIAL, "Invalid SOS parameters for sequential JPEG")
|
||||
JMESSAGE(JWRN_TOO_MUCH_DATA, "Application transferred too many scanlines")
|
||||
|
||||
@ -228,6 +231,15 @@ JMESSAGE(JWRN_TOO_MUCH_DATA, "Application transferred too many scanlines")
|
||||
(cinfo)->err->msg_parm.i[2] = (p3), \
|
||||
(cinfo)->err->msg_parm.i[3] = (p4), \
|
||||
(*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
|
||||
#define ERREXIT6(cinfo,code,p1,p2,p3,p4,p5,p6) \
|
||||
((cinfo)->err->msg_code = (code), \
|
||||
(cinfo)->err->msg_parm.i[0] = (p1), \
|
||||
(cinfo)->err->msg_parm.i[1] = (p2), \
|
||||
(cinfo)->err->msg_parm.i[2] = (p3), \
|
||||
(cinfo)->err->msg_parm.i[3] = (p4), \
|
||||
(cinfo)->err->msg_parm.i[4] = (p5), \
|
||||
(cinfo)->err->msg_parm.i[5] = (p6), \
|
||||
(*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
|
||||
#define ERREXITS(cinfo,code,str) \
|
||||
((cinfo)->err->msg_code = (code), \
|
||||
strncpy((cinfo)->err->msg_parm.s, (str), JMSG_STR_PARM_MAX), \
|
||||
@ -264,26 +276,26 @@ JMESSAGE(JWRN_TOO_MUCH_DATA, "Application transferred too many scanlines")
|
||||
(*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
|
||||
#define TRACEMS3(cinfo,lvl,code,p1,p2,p3) \
|
||||
MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
|
||||
_mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); \
|
||||
(cinfo)->err->msg_code = (code); \
|
||||
(*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
|
||||
_mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); \
|
||||
(cinfo)->err->msg_code = (code); \
|
||||
(*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
|
||||
#define TRACEMS4(cinfo,lvl,code,p1,p2,p3,p4) \
|
||||
MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
|
||||
_mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
|
||||
(cinfo)->err->msg_code = (code); \
|
||||
(*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
|
||||
_mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
|
||||
(cinfo)->err->msg_code = (code); \
|
||||
(*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
|
||||
#define TRACEMS5(cinfo,lvl,code,p1,p2,p3,p4,p5) \
|
||||
MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
|
||||
_mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
|
||||
_mp[4] = (p5); \
|
||||
(cinfo)->err->msg_code = (code); \
|
||||
(*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
|
||||
_mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
|
||||
_mp[4] = (p5); \
|
||||
(cinfo)->err->msg_code = (code); \
|
||||
(*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
|
||||
#define TRACEMS8(cinfo,lvl,code,p1,p2,p3,p4,p5,p6,p7,p8) \
|
||||
MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
|
||||
_mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
|
||||
_mp[4] = (p5); _mp[5] = (p6); _mp[6] = (p7); _mp[7] = (p8); \
|
||||
(cinfo)->err->msg_code = (code); \
|
||||
(*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
|
||||
_mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
|
||||
_mp[4] = (p5); _mp[5] = (p6); _mp[6] = (p7); _mp[7] = (p8); \
|
||||
(cinfo)->err->msg_code = (code); \
|
||||
(*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
|
||||
#define TRACEMSS(cinfo,lvl,code,str) \
|
||||
((cinfo)->err->msg_code = (code), \
|
||||
strncpy((cinfo)->err->msg_parm.s, (str), JMSG_STR_PARM_MAX), \
|
||||
|
28
3rdparty/libjpeg/jfdctflt.c
vendored
28
3rdparty/libjpeg/jfdctflt.c
vendored
@ -2,6 +2,7 @@
|
||||
* jfdctflt.c
|
||||
*
|
||||
* Copyright (C) 1994-1996, Thomas G. Lane.
|
||||
* Modified 2003-2009 by Guido Vollbeding.
|
||||
* This file is part of the Independent JPEG Group's software.
|
||||
* For conditions of distribution and use, see the accompanying README file.
|
||||
*
|
||||
@ -56,26 +57,30 @@
|
||||
*/
|
||||
|
||||
GLOBAL(void)
|
||||
jpeg_fdct_float (FAST_FLOAT * data)
|
||||
jpeg_fdct_float (FAST_FLOAT * data, JSAMPARRAY sample_data, JDIMENSION start_col)
|
||||
{
|
||||
FAST_FLOAT tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
|
||||
FAST_FLOAT tmp10, tmp11, tmp12, tmp13;
|
||||
FAST_FLOAT z1, z2, z3, z4, z5, z11, z13;
|
||||
FAST_FLOAT *dataptr;
|
||||
JSAMPROW elemptr;
|
||||
int ctr;
|
||||
|
||||
/* Pass 1: process rows. */
|
||||
|
||||
dataptr = data;
|
||||
for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
|
||||
tmp0 = dataptr[0] + dataptr[7];
|
||||
tmp7 = dataptr[0] - dataptr[7];
|
||||
tmp1 = dataptr[1] + dataptr[6];
|
||||
tmp6 = dataptr[1] - dataptr[6];
|
||||
tmp2 = dataptr[2] + dataptr[5];
|
||||
tmp5 = dataptr[2] - dataptr[5];
|
||||
tmp3 = dataptr[3] + dataptr[4];
|
||||
tmp4 = dataptr[3] - dataptr[4];
|
||||
for (ctr = 0; ctr < DCTSIZE; ctr++) {
|
||||
elemptr = sample_data[ctr] + start_col;
|
||||
|
||||
/* Load data into workspace */
|
||||
tmp0 = (FAST_FLOAT) (GETJSAMPLE(elemptr[0]) + GETJSAMPLE(elemptr[7]));
|
||||
tmp7 = (FAST_FLOAT) (GETJSAMPLE(elemptr[0]) - GETJSAMPLE(elemptr[7]));
|
||||
tmp1 = (FAST_FLOAT) (GETJSAMPLE(elemptr[1]) + GETJSAMPLE(elemptr[6]));
|
||||
tmp6 = (FAST_FLOAT) (GETJSAMPLE(elemptr[1]) - GETJSAMPLE(elemptr[6]));
|
||||
tmp2 = (FAST_FLOAT) (GETJSAMPLE(elemptr[2]) + GETJSAMPLE(elemptr[5]));
|
||||
tmp5 = (FAST_FLOAT) (GETJSAMPLE(elemptr[2]) - GETJSAMPLE(elemptr[5]));
|
||||
tmp3 = (FAST_FLOAT) (GETJSAMPLE(elemptr[3]) + GETJSAMPLE(elemptr[4]));
|
||||
tmp4 = (FAST_FLOAT) (GETJSAMPLE(elemptr[3]) - GETJSAMPLE(elemptr[4]));
|
||||
|
||||
/* Even part */
|
||||
|
||||
@ -84,7 +89,8 @@ jpeg_fdct_float (FAST_FLOAT * data)
|
||||
tmp11 = tmp1 + tmp2;
|
||||
tmp12 = tmp1 - tmp2;
|
||||
|
||||
dataptr[0] = tmp10 + tmp11; /* phase 3 */
|
||||
/* Apply unsigned->signed conversion */
|
||||
dataptr[0] = tmp10 + tmp11 - 8 * CENTERJSAMPLE; /* phase 3 */
|
||||
dataptr[4] = tmp10 - tmp11;
|
||||
|
||||
z1 = (tmp12 + tmp13) * ((FAST_FLOAT) 0.707106781); /* c4 */
|
||||
|
28
3rdparty/libjpeg/jfdctfst.c
vendored
28
3rdparty/libjpeg/jfdctfst.c
vendored
@ -2,6 +2,7 @@
|
||||
* jfdctfst.c
|
||||
*
|
||||
* Copyright (C) 1994-1996, Thomas G. Lane.
|
||||
* Modified 2003-2009 by Guido Vollbeding.
|
||||
* This file is part of the Independent JPEG Group's software.
|
||||
* For conditions of distribution and use, see the accompanying README file.
|
||||
*
|
||||
@ -111,27 +112,31 @@
|
||||
*/
|
||||
|
||||
GLOBAL(void)
|
||||
jpeg_fdct_ifast (DCTELEM * data)
|
||||
jpeg_fdct_ifast (DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col)
|
||||
{
|
||||
DCTELEM tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
|
||||
DCTELEM tmp10, tmp11, tmp12, tmp13;
|
||||
DCTELEM z1, z2, z3, z4, z5, z11, z13;
|
||||
DCTELEM *dataptr;
|
||||
JSAMPROW elemptr;
|
||||
int ctr;
|
||||
SHIFT_TEMPS
|
||||
|
||||
/* Pass 1: process rows. */
|
||||
|
||||
dataptr = data;
|
||||
for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
|
||||
tmp0 = dataptr[0] + dataptr[7];
|
||||
tmp7 = dataptr[0] - dataptr[7];
|
||||
tmp1 = dataptr[1] + dataptr[6];
|
||||
tmp6 = dataptr[1] - dataptr[6];
|
||||
tmp2 = dataptr[2] + dataptr[5];
|
||||
tmp5 = dataptr[2] - dataptr[5];
|
||||
tmp3 = dataptr[3] + dataptr[4];
|
||||
tmp4 = dataptr[3] - dataptr[4];
|
||||
for (ctr = 0; ctr < DCTSIZE; ctr++) {
|
||||
elemptr = sample_data[ctr] + start_col;
|
||||
|
||||
/* Load data into workspace */
|
||||
tmp0 = GETJSAMPLE(elemptr[0]) + GETJSAMPLE(elemptr[7]);
|
||||
tmp7 = GETJSAMPLE(elemptr[0]) - GETJSAMPLE(elemptr[7]);
|
||||
tmp1 = GETJSAMPLE(elemptr[1]) + GETJSAMPLE(elemptr[6]);
|
||||
tmp6 = GETJSAMPLE(elemptr[1]) - GETJSAMPLE(elemptr[6]);
|
||||
tmp2 = GETJSAMPLE(elemptr[2]) + GETJSAMPLE(elemptr[5]);
|
||||
tmp5 = GETJSAMPLE(elemptr[2]) - GETJSAMPLE(elemptr[5]);
|
||||
tmp3 = GETJSAMPLE(elemptr[3]) + GETJSAMPLE(elemptr[4]);
|
||||
tmp4 = GETJSAMPLE(elemptr[3]) - GETJSAMPLE(elemptr[4]);
|
||||
|
||||
/* Even part */
|
||||
|
||||
@ -140,7 +145,8 @@ jpeg_fdct_ifast (DCTELEM * data)
|
||||
tmp11 = tmp1 + tmp2;
|
||||
tmp12 = tmp1 - tmp2;
|
||||
|
||||
dataptr[0] = tmp10 + tmp11; /* phase 3 */
|
||||
/* Apply unsigned->signed conversion */
|
||||
dataptr[0] = tmp10 + tmp11 - 8 * CENTERJSAMPLE; /* phase 3 */
|
||||
dataptr[4] = tmp10 - tmp11;
|
||||
|
||||
z1 = MULTIPLY(tmp12 + tmp13, FIX_0_707106781); /* c4 */
|
||||
|
4239
3rdparty/libjpeg/jfdctint.c
vendored
4239
3rdparty/libjpeg/jfdctint.c
vendored
File diff suppressed because it is too large
Load Diff
63
3rdparty/libjpeg/jidctflt.c
vendored
63
3rdparty/libjpeg/jidctflt.c
vendored
@ -2,6 +2,7 @@
|
||||
* jidctflt.c
|
||||
*
|
||||
* Copyright (C) 1994-1998, Thomas G. Lane.
|
||||
* Modified 2010 by Guido Vollbeding.
|
||||
* This file is part of the Independent JPEG Group's software.
|
||||
* For conditions of distribution and use, see the accompanying README file.
|
||||
*
|
||||
@ -66,8 +67,8 @@
|
||||
|
||||
GLOBAL(void)
|
||||
jpeg_idct_float (j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
||||
JCOEFPTR coef_block,
|
||||
JSAMPARRAY output_buf, JDIMENSION output_col)
|
||||
JCOEFPTR coef_block,
|
||||
JSAMPARRAY output_buf, JDIMENSION output_col)
|
||||
{
|
||||
FAST_FLOAT tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
|
||||
FAST_FLOAT tmp10, tmp11, tmp12, tmp13;
|
||||
@ -76,10 +77,9 @@ jpeg_idct_float (j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
||||
FLOAT_MULT_TYPE * quantptr;
|
||||
FAST_FLOAT * wsptr;
|
||||
JSAMPROW outptr;
|
||||
JSAMPLE *range_limit = IDCT_range_limit(cinfo);
|
||||
JSAMPLE *range_limit = cinfo->sample_range_limit;
|
||||
int ctr;
|
||||
FAST_FLOAT workspace[DCTSIZE2]; /* buffers data between passes */
|
||||
SHIFT_TEMPS
|
||||
|
||||
/* Pass 1: process columns from input, store into work array. */
|
||||
|
||||
@ -97,9 +97,9 @@ jpeg_idct_float (j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
||||
*/
|
||||
|
||||
if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 &&
|
||||
inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*4] == 0 &&
|
||||
inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*6] == 0 &&
|
||||
inptr[DCTSIZE*7] == 0) {
|
||||
inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*4] == 0 &&
|
||||
inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*6] == 0 &&
|
||||
inptr[DCTSIZE*7] == 0) {
|
||||
/* AC terms all zero */
|
||||
FAST_FLOAT dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
|
||||
|
||||
@ -152,12 +152,12 @@ jpeg_idct_float (j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
||||
tmp11 = (z11 - z13) * ((FAST_FLOAT) 1.414213562); /* 2*c4 */
|
||||
|
||||
z5 = (z10 + z12) * ((FAST_FLOAT) 1.847759065); /* 2*c2 */
|
||||
tmp10 = ((FAST_FLOAT) 1.082392200) * z12 - z5; /* 2*(c2-c6) */
|
||||
tmp12 = ((FAST_FLOAT) -2.613125930) * z10 + z5; /* -2*(c2+c6) */
|
||||
tmp10 = z5 - z12 * ((FAST_FLOAT) 1.082392200); /* 2*(c2-c6) */
|
||||
tmp12 = z5 - z10 * ((FAST_FLOAT) 2.613125930); /* 2*(c2+c6) */
|
||||
|
||||
tmp6 = tmp12 - tmp7; /* phase 2 */
|
||||
tmp5 = tmp11 - tmp6;
|
||||
tmp4 = tmp10 + tmp5;
|
||||
tmp4 = tmp10 - tmp5;
|
||||
|
||||
wsptr[DCTSIZE*0] = tmp0 + tmp7;
|
||||
wsptr[DCTSIZE*7] = tmp0 - tmp7;
|
||||
@ -165,8 +165,8 @@ jpeg_idct_float (j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
||||
wsptr[DCTSIZE*6] = tmp1 - tmp6;
|
||||
wsptr[DCTSIZE*2] = tmp2 + tmp5;
|
||||
wsptr[DCTSIZE*5] = tmp2 - tmp5;
|
||||
wsptr[DCTSIZE*4] = tmp3 + tmp4;
|
||||
wsptr[DCTSIZE*3] = tmp3 - tmp4;
|
||||
wsptr[DCTSIZE*3] = tmp3 + tmp4;
|
||||
wsptr[DCTSIZE*4] = tmp3 - tmp4;
|
||||
|
||||
inptr++; /* advance pointers to next column */
|
||||
quantptr++;
|
||||
@ -174,7 +174,6 @@ jpeg_idct_float (j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
||||
}
|
||||
|
||||
/* 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. */
|
||||
|
||||
wsptr = workspace;
|
||||
for (ctr = 0; ctr < DCTSIZE; ctr++) {
|
||||
@ -187,8 +186,10 @@ jpeg_idct_float (j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
||||
|
||||
/* Even part */
|
||||
|
||||
tmp10 = wsptr[0] + wsptr[4];
|
||||
tmp11 = wsptr[0] - wsptr[4];
|
||||
/* Apply signed->unsigned and prepare float->int conversion */
|
||||
z5 = wsptr[0] + ((FAST_FLOAT) CENTERJSAMPLE + (FAST_FLOAT) 0.5);
|
||||
tmp10 = z5 + wsptr[4];
|
||||
tmp11 = z5 - wsptr[4];
|
||||
|
||||
tmp13 = wsptr[2] + wsptr[6];
|
||||
tmp12 = (wsptr[2] - wsptr[6]) * ((FAST_FLOAT) 1.414213562) - tmp13;
|
||||
@ -209,31 +210,23 @@ jpeg_idct_float (j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
||||
tmp11 = (z11 - z13) * ((FAST_FLOAT) 1.414213562);
|
||||
|
||||
z5 = (z10 + z12) * ((FAST_FLOAT) 1.847759065); /* 2*c2 */
|
||||
tmp10 = ((FAST_FLOAT) 1.082392200) * z12 - z5; /* 2*(c2-c6) */
|
||||
tmp12 = ((FAST_FLOAT) -2.613125930) * z10 + z5; /* -2*(c2+c6) */
|
||||
tmp10 = z5 - z12 * ((FAST_FLOAT) 1.082392200); /* 2*(c2-c6) */
|
||||
tmp12 = z5 - z10 * ((FAST_FLOAT) 2.613125930); /* 2*(c2+c6) */
|
||||
|
||||
tmp6 = tmp12 - tmp7;
|
||||
tmp5 = tmp11 - tmp6;
|
||||
tmp4 = tmp10 + tmp5;
|
||||
tmp4 = tmp10 - tmp5;
|
||||
|
||||
/* Final output stage: scale down by a factor of 8 and range-limit */
|
||||
/* Final output stage: float->int conversion and range-limit */
|
||||
|
||||
outptr[0] = range_limit[(int) DESCALE((INT32) (tmp0 + tmp7), 3)
|
||||
& RANGE_MASK];
|
||||
outptr[7] = range_limit[(int) DESCALE((INT32) (tmp0 - tmp7), 3)
|
||||
& RANGE_MASK];
|
||||
outptr[1] = range_limit[(int) DESCALE((INT32) (tmp1 + tmp6), 3)
|
||||
& RANGE_MASK];
|
||||
outptr[6] = range_limit[(int) DESCALE((INT32) (tmp1 - tmp6), 3)
|
||||
& RANGE_MASK];
|
||||
outptr[2] = range_limit[(int) DESCALE((INT32) (tmp2 + tmp5), 3)
|
||||
& RANGE_MASK];
|
||||
outptr[5] = range_limit[(int) DESCALE((INT32) (tmp2 - tmp5), 3)
|
||||
& RANGE_MASK];
|
||||
outptr[4] = range_limit[(int) DESCALE((INT32) (tmp3 + tmp4), 3)
|
||||
& RANGE_MASK];
|
||||
outptr[3] = range_limit[(int) DESCALE((INT32) (tmp3 - tmp4), 3)
|
||||
& RANGE_MASK];
|
||||
outptr[0] = range_limit[((int) (tmp0 + tmp7)) & RANGE_MASK];
|
||||
outptr[7] = range_limit[((int) (tmp0 - tmp7)) & RANGE_MASK];
|
||||
outptr[1] = range_limit[((int) (tmp1 + tmp6)) & RANGE_MASK];
|
||||
outptr[6] = range_limit[((int) (tmp1 - tmp6)) & RANGE_MASK];
|
||||
outptr[2] = range_limit[((int) (tmp2 + tmp5)) & RANGE_MASK];
|
||||
outptr[5] = range_limit[((int) (tmp2 - tmp5)) & RANGE_MASK];
|
||||
outptr[3] = range_limit[((int) (tmp3 + tmp4)) & RANGE_MASK];
|
||||
outptr[4] = range_limit[((int) (tmp3 - tmp4)) & RANGE_MASK];
|
||||
|
||||
wsptr += DCTSIZE; /* advance pointer to next row */
|
||||
}
|
||||
|
34
3rdparty/libjpeg/jidctfst.c
vendored
34
3rdparty/libjpeg/jidctfst.c
vendored
@ -129,7 +129,7 @@
|
||||
#define DEQUANTIZE(coef,quantval) (((IFAST_MULT_TYPE) (coef)) * (quantval))
|
||||
#else
|
||||
#define DEQUANTIZE(coef,quantval) \
|
||||
DESCALE((coef)*(quantval), IFAST_SCALE_BITS-PASS1_BITS)
|
||||
DESCALE((coef)*(quantval), IFAST_SCALE_BITS-PASS1_BITS)
|
||||
#endif
|
||||
|
||||
|
||||
@ -166,8 +166,8 @@
|
||||
|
||||
GLOBAL(void)
|
||||
jpeg_idct_ifast (j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
||||
JCOEFPTR coef_block,
|
||||
JSAMPARRAY output_buf, JDIMENSION output_col)
|
||||
JCOEFPTR coef_block,
|
||||
JSAMPARRAY output_buf, JDIMENSION output_col)
|
||||
{
|
||||
DCTELEM tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
|
||||
DCTELEM tmp10, tmp11, tmp12, tmp13;
|
||||
@ -198,9 +198,9 @@ jpeg_idct_ifast (j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
||||
*/
|
||||
|
||||
if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 &&
|
||||
inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*4] == 0 &&
|
||||
inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*6] == 0 &&
|
||||
inptr[DCTSIZE*7] == 0) {
|
||||
inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*4] == 0 &&
|
||||
inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*6] == 0 &&
|
||||
inptr[DCTSIZE*7] == 0) {
|
||||
/* AC terms all zero */
|
||||
int dcval = (int) DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
|
||||
|
||||
@ -291,10 +291,10 @@ jpeg_idct_ifast (j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
||||
|
||||
#ifndef NO_ZERO_ROW_TEST
|
||||
if (wsptr[1] == 0 && wsptr[2] == 0 && wsptr[3] == 0 && wsptr[4] == 0 &&
|
||||
wsptr[5] == 0 && wsptr[6] == 0 && wsptr[7] == 0) {
|
||||
wsptr[5] == 0 && wsptr[6] == 0 && wsptr[7] == 0) {
|
||||
/* AC terms all zero */
|
||||
JSAMPLE dcval = range_limit[IDESCALE(wsptr[0], PASS1_BITS+3)
|
||||
& RANGE_MASK];
|
||||
& RANGE_MASK];
|
||||
|
||||
outptr[0] = dcval;
|
||||
outptr[1] = dcval;
|
||||
@ -317,7 +317,7 @@ jpeg_idct_ifast (j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
||||
|
||||
tmp13 = ((DCTELEM) wsptr[2] + (DCTELEM) wsptr[6]);
|
||||
tmp12 = MULTIPLY((DCTELEM) wsptr[2] - (DCTELEM) wsptr[6], FIX_1_414213562)
|
||||
- tmp13;
|
||||
- tmp13;
|
||||
|
||||
tmp0 = tmp10 + tmp13;
|
||||
tmp3 = tmp10 - tmp13;
|
||||
@ -345,21 +345,21 @@ jpeg_idct_ifast (j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
||||
/* Final output stage: scale down by a factor of 8 and range-limit */
|
||||
|
||||
outptr[0] = range_limit[IDESCALE(tmp0 + tmp7, PASS1_BITS+3)
|
||||
& RANGE_MASK];
|
||||
& RANGE_MASK];
|
||||
outptr[7] = range_limit[IDESCALE(tmp0 - tmp7, PASS1_BITS+3)
|
||||
& RANGE_MASK];
|
||||
& RANGE_MASK];
|
||||
outptr[1] = range_limit[IDESCALE(tmp1 + tmp6, PASS1_BITS+3)
|
||||
& RANGE_MASK];
|
||||
& RANGE_MASK];
|
||||
outptr[6] = range_limit[IDESCALE(tmp1 - tmp6, PASS1_BITS+3)
|
||||
& RANGE_MASK];
|
||||
& RANGE_MASK];
|
||||
outptr[2] = range_limit[IDESCALE(tmp2 + tmp5, PASS1_BITS+3)
|
||||
& RANGE_MASK];
|
||||
& RANGE_MASK];
|
||||
outptr[5] = range_limit[IDESCALE(tmp2 - tmp5, PASS1_BITS+3)
|
||||
& RANGE_MASK];
|
||||
& RANGE_MASK];
|
||||
outptr[4] = range_limit[IDESCALE(tmp3 + tmp4, PASS1_BITS+3)
|
||||
& RANGE_MASK];
|
||||
& RANGE_MASK];
|
||||
outptr[3] = range_limit[IDESCALE(tmp3 - tmp4, PASS1_BITS+3)
|
||||
& RANGE_MASK];
|
||||
& RANGE_MASK];
|
||||
|
||||
wsptr += DCTSIZE; /* advance pointer to next row */
|
||||
}
|
||||
|
4934
3rdparty/libjpeg/jidctint.c
vendored
4934
3rdparty/libjpeg/jidctint.c
vendored
File diff suppressed because it is too large
Load Diff
398
3rdparty/libjpeg/jidctred.c
vendored
398
3rdparty/libjpeg/jidctred.c
vendored
@ -1,398 +0,0 @@
|
||||
/*
|
||||
* jidctred.c
|
||||
*
|
||||
* Copyright (C) 1994-1998, Thomas G. Lane.
|
||||
* This file is part of the Independent JPEG Group's software.
|
||||
* For conditions of distribution and use, see the accompanying README file.
|
||||
*
|
||||
* This file contains inverse-DCT routines that produce reduced-size output:
|
||||
* either 4x4, 2x2, or 1x1 pixels from an 8x8 DCT block.
|
||||
*
|
||||
* The implementation is based on the Loeffler, Ligtenberg and Moschytz (LL&M)
|
||||
* algorithm used in jidctint.c. We simply replace each 8-to-8 1-D IDCT step
|
||||
* with an 8-to-4 step that produces the four averages of two adjacent outputs
|
||||
* (or an 8-to-2 step producing two averages of four outputs, for 2x2 output).
|
||||
* These steps were derived by computing the corresponding values at the end
|
||||
* of the normal LL&M code, then simplifying as much as possible.
|
||||
*
|
||||
* 1x1 is trivial: just take the DC coefficient divided by 8.
|
||||
*
|
||||
* See jidctint.c for additional comments.
|
||||
*/
|
||||
|
||||
#define JPEG_INTERNALS
|
||||
#include "jinclude.h"
|
||||
#include "jpeglib.h"
|
||||
#include "jdct.h" /* Private declarations for DCT subsystem */
|
||||
|
||||
#ifdef IDCT_SCALING_SUPPORTED
|
||||
|
||||
|
||||
/*
|
||||
* This module is specialized to the case DCTSIZE = 8.
|
||||
*/
|
||||
|
||||
#if DCTSIZE != 8
|
||||
Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
|
||||
#endif
|
||||
|
||||
|
||||
/* Scaling is the same as in jidctint.c. */
|
||||
|
||||
#if BITS_IN_JSAMPLE == 8
|
||||
#define CONST_BITS 13
|
||||
#define PASS1_BITS 2
|
||||
#else
|
||||
#define CONST_BITS 13
|
||||
#define PASS1_BITS 1 /* lose a little precision to avoid overflow */
|
||||
#endif
|
||||
|
||||
/* Some C compilers fail to reduce "FIX(constant)" at compile time, thus
|
||||
* causing a lot of useless floating-point operations at run time.
|
||||
* To get around this we use the following pre-calculated constants.
|
||||
* If you change CONST_BITS you may want to add appropriate values.
|
||||
* (With a reasonable C compiler, you can just rely on the FIX() macro...)
|
||||
*/
|
||||
|
||||
#if CONST_BITS == 13
|
||||
#define FIX_0_211164243 ((INT32) 1730) /* FIX(0.211164243) */
|
||||
#define FIX_0_509795579 ((INT32) 4176) /* FIX(0.509795579) */
|
||||
#define FIX_0_601344887 ((INT32) 4926) /* FIX(0.601344887) */
|
||||
#define FIX_0_720959822 ((INT32) 5906) /* FIX(0.720959822) */
|
||||
#define FIX_0_765366865 ((INT32) 6270) /* FIX(0.765366865) */
|
||||
#define FIX_0_850430095 ((INT32) 6967) /* FIX(0.850430095) */
|
||||
#define FIX_0_899976223 ((INT32) 7373) /* FIX(0.899976223) */
|
||||
#define FIX_1_061594337 ((INT32) 8697) /* FIX(1.061594337) */
|
||||
#define FIX_1_272758580 ((INT32) 10426) /* FIX(1.272758580) */
|
||||
#define FIX_1_451774981 ((INT32) 11893) /* FIX(1.451774981) */
|
||||
#define FIX_1_847759065 ((INT32) 15137) /* FIX(1.847759065) */
|
||||
#define FIX_2_172734803 ((INT32) 17799) /* FIX(2.172734803) */
|
||||
#define FIX_2_562915447 ((INT32) 20995) /* FIX(2.562915447) */
|
||||
#define FIX_3_624509785 ((INT32) 29692) /* FIX(3.624509785) */
|
||||
#else
|
||||
#define FIX_0_211164243 FIX(0.211164243)
|
||||
#define FIX_0_509795579 FIX(0.509795579)
|
||||
#define FIX_0_601344887 FIX(0.601344887)
|
||||
#define FIX_0_720959822 FIX(0.720959822)
|
||||
#define FIX_0_765366865 FIX(0.765366865)
|
||||
#define FIX_0_850430095 FIX(0.850430095)
|
||||
#define FIX_0_899976223 FIX(0.899976223)
|
||||
#define FIX_1_061594337 FIX(1.061594337)
|
||||
#define FIX_1_272758580 FIX(1.272758580)
|
||||
#define FIX_1_451774981 FIX(1.451774981)
|
||||
#define FIX_1_847759065 FIX(1.847759065)
|
||||
#define FIX_2_172734803 FIX(2.172734803)
|
||||
#define FIX_2_562915447 FIX(2.562915447)
|
||||
#define FIX_3_624509785 FIX(3.624509785)
|
||||
#endif
|
||||
|
||||
|
||||
/* Multiply an INT32 variable by an INT32 constant to yield an INT32 result.
|
||||
* For 8-bit samples with the recommended scaling, all the variable
|
||||
* and constant values involved are no more than 16 bits wide, so a
|
||||
* 16x16->32 bit multiply can be used instead of a full 32x32 multiply.
|
||||
* For 12-bit samples, a full 32-bit multiplication will be needed.
|
||||
*/
|
||||
|
||||
#if BITS_IN_JSAMPLE == 8
|
||||
#define MULTIPLY(var,const) MULTIPLY16C16(var,const)
|
||||
#else
|
||||
#define MULTIPLY(var,const) ((var) * (const))
|
||||
#endif
|
||||
|
||||
|
||||
/* Dequantize a coefficient by multiplying it by the multiplier-table
|
||||
* entry; produce an int result. In this module, both inputs and result
|
||||
* are 16 bits or less, so either int or short multiply will work.
|
||||
*/
|
||||
|
||||
#define DEQUANTIZE(coef,quantval) (((ISLOW_MULT_TYPE) (coef)) * (quantval))
|
||||
|
||||
|
||||
/*
|
||||
* Perform dequantization and inverse DCT on one block of coefficients,
|
||||
* producing a reduced-size 4x4 output block.
|
||||
*/
|
||||
|
||||
GLOBAL(void)
|
||||
jpeg_idct_4x4 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
||||
JCOEFPTR coef_block,
|
||||
JSAMPARRAY output_buf, JDIMENSION output_col)
|
||||
{
|
||||
INT32 tmp0, tmp2, tmp10, tmp12;
|
||||
INT32 z1, z2, z3, z4;
|
||||
JCOEFPTR inptr;
|
||||
ISLOW_MULT_TYPE * quantptr;
|
||||
int * wsptr;
|
||||
JSAMPROW outptr;
|
||||
JSAMPLE *range_limit = IDCT_range_limit(cinfo);
|
||||
int ctr;
|
||||
int workspace[DCTSIZE*4]; /* buffers data between passes */
|
||||
SHIFT_TEMPS
|
||||
|
||||
/* Pass 1: process columns from input, store into work array. */
|
||||
|
||||
inptr = coef_block;
|
||||
quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
|
||||
wsptr = workspace;
|
||||
for (ctr = DCTSIZE; ctr > 0; inptr++, quantptr++, wsptr++, ctr--) {
|
||||
/* Don't bother to process column 4, because second pass won't use it */
|
||||
if (ctr == DCTSIZE-4)
|
||||
continue;
|
||||
if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 &&
|
||||
inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*5] == 0 &&
|
||||
inptr[DCTSIZE*6] == 0 && inptr[DCTSIZE*7] == 0) {
|
||||
/* AC terms all zero; we need not examine term 4 for 4x4 output */
|
||||
int dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]) << PASS1_BITS;
|
||||
|
||||
wsptr[DCTSIZE*0] = dcval;
|
||||
wsptr[DCTSIZE*1] = dcval;
|
||||
wsptr[DCTSIZE*2] = dcval;
|
||||
wsptr[DCTSIZE*3] = dcval;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Even part */
|
||||
|
||||
tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
|
||||
tmp0 <<= (CONST_BITS+1);
|
||||
|
||||
z2 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
|
||||
z3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
|
||||
|
||||
tmp2 = MULTIPLY(z2, FIX_1_847759065) + MULTIPLY(z3, - FIX_0_765366865);
|
||||
|
||||
tmp10 = tmp0 + tmp2;
|
||||
tmp12 = tmp0 - tmp2;
|
||||
|
||||
/* Odd part */
|
||||
|
||||
z1 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
|
||||
z2 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
|
||||
z3 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
|
||||
z4 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
|
||||
|
||||
tmp0 = MULTIPLY(z1, - FIX_0_211164243) /* sqrt(2) * (c3-c1) */
|
||||
+ MULTIPLY(z2, FIX_1_451774981) /* sqrt(2) * (c3+c7) */
|
||||
+ MULTIPLY(z3, - FIX_2_172734803) /* sqrt(2) * (-c1-c5) */
|
||||
+ MULTIPLY(z4, FIX_1_061594337); /* sqrt(2) * (c5+c7) */
|
||||
|
||||
tmp2 = MULTIPLY(z1, - FIX_0_509795579) /* sqrt(2) * (c7-c5) */
|
||||
+ MULTIPLY(z2, - FIX_0_601344887) /* sqrt(2) * (c5-c1) */
|
||||
+ MULTIPLY(z3, FIX_0_899976223) /* sqrt(2) * (c3-c7) */
|
||||
+ MULTIPLY(z4, FIX_2_562915447); /* sqrt(2) * (c1+c3) */
|
||||
|
||||
/* Final output stage */
|
||||
|
||||
wsptr[DCTSIZE*0] = (int) DESCALE(tmp10 + tmp2, CONST_BITS-PASS1_BITS+1);
|
||||
wsptr[DCTSIZE*3] = (int) DESCALE(tmp10 - tmp2, CONST_BITS-PASS1_BITS+1);
|
||||
wsptr[DCTSIZE*1] = (int) DESCALE(tmp12 + tmp0, CONST_BITS-PASS1_BITS+1);
|
||||
wsptr[DCTSIZE*2] = (int) DESCALE(tmp12 - tmp0, CONST_BITS-PASS1_BITS+1);
|
||||
}
|
||||
|
||||
/* Pass 2: process 4 rows from work array, store into output array. */
|
||||
|
||||
wsptr = workspace;
|
||||
for (ctr = 0; ctr < 4; ctr++) {
|
||||
outptr = output_buf[ctr] + output_col;
|
||||
/* It's not clear whether a zero row test is worthwhile here ... */
|
||||
|
||||
#ifndef NO_ZERO_ROW_TEST
|
||||
if (wsptr[1] == 0 && wsptr[2] == 0 && wsptr[3] == 0 &&
|
||||
wsptr[5] == 0 && wsptr[6] == 0 && wsptr[7] == 0) {
|
||||
/* AC terms all zero */
|
||||
JSAMPLE dcval = range_limit[(int) DESCALE((INT32) wsptr[0], PASS1_BITS+3)
|
||||
& RANGE_MASK];
|
||||
|
||||
outptr[0] = dcval;
|
||||
outptr[1] = dcval;
|
||||
outptr[2] = dcval;
|
||||
outptr[3] = dcval;
|
||||
|
||||
wsptr += DCTSIZE; /* advance pointer to next row */
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Even part */
|
||||
|
||||
tmp0 = ((INT32) wsptr[0]) << (CONST_BITS+1);
|
||||
|
||||
tmp2 = MULTIPLY((INT32) wsptr[2], FIX_1_847759065)
|
||||
+ MULTIPLY((INT32) wsptr[6], - FIX_0_765366865);
|
||||
|
||||
tmp10 = tmp0 + tmp2;
|
||||
tmp12 = tmp0 - tmp2;
|
||||
|
||||
/* Odd part */
|
||||
|
||||
z1 = (INT32) wsptr[7];
|
||||
z2 = (INT32) wsptr[5];
|
||||
z3 = (INT32) wsptr[3];
|
||||
z4 = (INT32) wsptr[1];
|
||||
|
||||
tmp0 = MULTIPLY(z1, - FIX_0_211164243) /* sqrt(2) * (c3-c1) */
|
||||
+ MULTIPLY(z2, FIX_1_451774981) /* sqrt(2) * (c3+c7) */
|
||||
+ MULTIPLY(z3, - FIX_2_172734803) /* sqrt(2) * (-c1-c5) */
|
||||
+ MULTIPLY(z4, FIX_1_061594337); /* sqrt(2) * (c5+c7) */
|
||||
|
||||
tmp2 = MULTIPLY(z1, - FIX_0_509795579) /* sqrt(2) * (c7-c5) */
|
||||
+ MULTIPLY(z2, - FIX_0_601344887) /* sqrt(2) * (c5-c1) */
|
||||
+ MULTIPLY(z3, FIX_0_899976223) /* sqrt(2) * (c3-c7) */
|
||||
+ MULTIPLY(z4, FIX_2_562915447); /* sqrt(2) * (c1+c3) */
|
||||
|
||||
/* Final output stage */
|
||||
|
||||
outptr[0] = range_limit[(int) DESCALE(tmp10 + tmp2,
|
||||
CONST_BITS+PASS1_BITS+3+1)
|
||||
& RANGE_MASK];
|
||||
outptr[3] = range_limit[(int) DESCALE(tmp10 - tmp2,
|
||||
CONST_BITS+PASS1_BITS+3+1)
|
||||
& RANGE_MASK];
|
||||
outptr[1] = range_limit[(int) DESCALE(tmp12 + tmp0,
|
||||
CONST_BITS+PASS1_BITS+3+1)
|
||||
& RANGE_MASK];
|
||||
outptr[2] = range_limit[(int) DESCALE(tmp12 - tmp0,
|
||||
CONST_BITS+PASS1_BITS+3+1)
|
||||
& RANGE_MASK];
|
||||
|
||||
wsptr += DCTSIZE; /* advance pointer to next row */
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Perform dequantization and inverse DCT on one block of coefficients,
|
||||
* producing a reduced-size 2x2 output block.
|
||||
*/
|
||||
|
||||
GLOBAL(void)
|
||||
jpeg_idct_2x2 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
||||
JCOEFPTR coef_block,
|
||||
JSAMPARRAY output_buf, JDIMENSION output_col)
|
||||
{
|
||||
INT32 tmp0, tmp10, z1;
|
||||
JCOEFPTR inptr;
|
||||
ISLOW_MULT_TYPE * quantptr;
|
||||
int * wsptr;
|
||||
JSAMPROW outptr;
|
||||
JSAMPLE *range_limit = IDCT_range_limit(cinfo);
|
||||
int ctr;
|
||||
int workspace[DCTSIZE*2]; /* buffers data between passes */
|
||||
SHIFT_TEMPS
|
||||
|
||||
/* Pass 1: process columns from input, store into work array. */
|
||||
|
||||
inptr = coef_block;
|
||||
quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
|
||||
wsptr = workspace;
|
||||
for (ctr = DCTSIZE; ctr > 0; inptr++, quantptr++, wsptr++, ctr--) {
|
||||
/* Don't bother to process columns 2,4,6 */
|
||||
if (ctr == DCTSIZE-2 || ctr == DCTSIZE-4 || ctr == DCTSIZE-6)
|
||||
continue;
|
||||
if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*3] == 0 &&
|
||||
inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*7] == 0) {
|
||||
/* AC terms all zero; we need not examine terms 2,4,6 for 2x2 output */
|
||||
int dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]) << PASS1_BITS;
|
||||
|
||||
wsptr[DCTSIZE*0] = dcval;
|
||||
wsptr[DCTSIZE*1] = dcval;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Even part */
|
||||
|
||||
z1 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
|
||||
tmp10 = z1 << (CONST_BITS+2);
|
||||
|
||||
/* Odd part */
|
||||
|
||||
z1 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
|
||||
tmp0 = MULTIPLY(z1, - FIX_0_720959822); /* sqrt(2) * (c7-c5+c3-c1) */
|
||||
z1 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
|
||||
tmp0 += MULTIPLY(z1, FIX_0_850430095); /* sqrt(2) * (-c1+c3+c5+c7) */
|
||||
z1 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
|
||||
tmp0 += MULTIPLY(z1, - FIX_1_272758580); /* sqrt(2) * (-c1+c3-c5-c7) */
|
||||
z1 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
|
||||
tmp0 += MULTIPLY(z1, FIX_3_624509785); /* sqrt(2) * (c1+c3+c5+c7) */
|
||||
|
||||
/* Final output stage */
|
||||
|
||||
wsptr[DCTSIZE*0] = (int) DESCALE(tmp10 + tmp0, CONST_BITS-PASS1_BITS+2);
|
||||
wsptr[DCTSIZE*1] = (int) DESCALE(tmp10 - tmp0, CONST_BITS-PASS1_BITS+2);
|
||||
}
|
||||
|
||||
/* Pass 2: process 2 rows from work array, store into output array. */
|
||||
|
||||
wsptr = workspace;
|
||||
for (ctr = 0; ctr < 2; ctr++) {
|
||||
outptr = output_buf[ctr] + output_col;
|
||||
/* It's not clear whether a zero row test is worthwhile here ... */
|
||||
|
||||
#ifndef NO_ZERO_ROW_TEST
|
||||
if (wsptr[1] == 0 && wsptr[3] == 0 && wsptr[5] == 0 && wsptr[7] == 0) {
|
||||
/* AC terms all zero */
|
||||
JSAMPLE dcval = range_limit[(int) DESCALE((INT32) wsptr[0], PASS1_BITS+3)
|
||||
& RANGE_MASK];
|
||||
|
||||
outptr[0] = dcval;
|
||||
outptr[1] = dcval;
|
||||
|
||||
wsptr += DCTSIZE; /* advance pointer to next row */
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Even part */
|
||||
|
||||
tmp10 = ((INT32) wsptr[0]) << (CONST_BITS+2);
|
||||
|
||||
/* Odd part */
|
||||
|
||||
tmp0 = MULTIPLY((INT32) wsptr[7], - FIX_0_720959822) /* sqrt(2) * (c7-c5+c3-c1) */
|
||||
+ MULTIPLY((INT32) wsptr[5], FIX_0_850430095) /* sqrt(2) * (-c1+c3+c5+c7) */
|
||||
+ MULTIPLY((INT32) wsptr[3], - FIX_1_272758580) /* sqrt(2) * (-c1+c3-c5-c7) */
|
||||
+ MULTIPLY((INT32) wsptr[1], FIX_3_624509785); /* sqrt(2) * (c1+c3+c5+c7) */
|
||||
|
||||
/* Final output stage */
|
||||
|
||||
outptr[0] = range_limit[(int) DESCALE(tmp10 + tmp0,
|
||||
CONST_BITS+PASS1_BITS+3+2)
|
||||
& RANGE_MASK];
|
||||
outptr[1] = range_limit[(int) DESCALE(tmp10 - tmp0,
|
||||
CONST_BITS+PASS1_BITS+3+2)
|
||||
& RANGE_MASK];
|
||||
|
||||
wsptr += DCTSIZE; /* advance pointer to next row */
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Perform dequantization and inverse DCT on one block of coefficients,
|
||||
* producing a reduced-size 1x1 output block.
|
||||
*/
|
||||
|
||||
GLOBAL(void)
|
||||
jpeg_idct_1x1 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
||||
JCOEFPTR coef_block,
|
||||
JSAMPARRAY output_buf, JDIMENSION output_col)
|
||||
{
|
||||
int dcval;
|
||||
ISLOW_MULT_TYPE * quantptr;
|
||||
JSAMPLE *range_limit = IDCT_range_limit(cinfo);
|
||||
SHIFT_TEMPS
|
||||
|
||||
/* We hardly need an inverse DCT routine for this: just take the
|
||||
* average pixel value, which is one-eighth of the DC coefficient.
|
||||
*/
|
||||
quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
|
||||
dcval = DEQUANTIZE(coef_block[0], quantptr[0]);
|
||||
dcval = (int) DESCALE((INT32) dcval, 3);
|
||||
|
||||
output_buf[0][output_col] = range_limit[dcval & RANGE_MASK];
|
||||
}
|
||||
|
||||
#endif /* IDCT_SCALING_SUPPORTED */
|
12
3rdparty/libjpeg/jmemansi.c
vendored
12
3rdparty/libjpeg/jmemansi.c
vendored
@ -79,7 +79,7 @@ jpeg_free_large (j_common_ptr cinfo, void FAR * object, size_t sizeofobject)
|
||||
|
||||
GLOBAL(long)
|
||||
jpeg_mem_available (j_common_ptr cinfo, long min_bytes_needed,
|
||||
long max_bytes_needed, long already_allocated)
|
||||
long max_bytes_needed, long already_allocated)
|
||||
{
|
||||
return cinfo->mem->max_memory_to_use - already_allocated;
|
||||
}
|
||||
@ -95,8 +95,8 @@ jpeg_mem_available (j_common_ptr cinfo, long min_bytes_needed,
|
||||
|
||||
METHODDEF(void)
|
||||
read_backing_store (j_common_ptr cinfo, backing_store_ptr info,
|
||||
void FAR * buffer_address,
|
||||
long file_offset, long byte_count)
|
||||
void FAR * buffer_address,
|
||||
long file_offset, long byte_count)
|
||||
{
|
||||
if (fseek(info->temp_file, file_offset, SEEK_SET))
|
||||
ERREXIT(cinfo, JERR_TFILE_SEEK);
|
||||
@ -108,8 +108,8 @@ read_backing_store (j_common_ptr cinfo, backing_store_ptr info,
|
||||
|
||||
METHODDEF(void)
|
||||
write_backing_store (j_common_ptr cinfo, backing_store_ptr info,
|
||||
void FAR * buffer_address,
|
||||
long file_offset, long byte_count)
|
||||
void FAR * buffer_address,
|
||||
long file_offset, long byte_count)
|
||||
{
|
||||
if (fseek(info->temp_file, file_offset, SEEK_SET))
|
||||
ERREXIT(cinfo, JERR_TFILE_SEEK);
|
||||
@ -139,7 +139,7 @@ close_backing_store (j_common_ptr cinfo, backing_store_ptr info)
|
||||
|
||||
GLOBAL(void)
|
||||
jpeg_open_backing_store (j_common_ptr cinfo, backing_store_ptr info,
|
||||
long total_bytes_needed)
|
||||
long total_bytes_needed)
|
||||
{
|
||||
if ((info->temp_file = tmpfile()) == NULL)
|
||||
ERREXITS(cinfo, JERR_TFILE_CREATE, "");
|
||||
|
176
3rdparty/libjpeg/jmemmgr.c
vendored
176
3rdparty/libjpeg/jmemmgr.c
vendored
@ -2,6 +2,7 @@
|
||||
* jmemmgr.c
|
||||
*
|
||||
* Copyright (C) 1991-1997, Thomas G. Lane.
|
||||
* Modified 2011-2012 by Guido Vollbeding.
|
||||
* This file is part of the Independent JPEG Group's software.
|
||||
* For conditions of distribution and use, see the accompanying README file.
|
||||
*
|
||||
@ -36,9 +37,6 @@ extern char * getenv JPP((const char * name));
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined _MSC_VER && _MSC_VER >= 1400
|
||||
#pragma warning(disable: 4267)
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Some important notes:
|
||||
@ -197,26 +195,26 @@ print_mem_stats (j_common_ptr cinfo, int pool_id)
|
||||
* This is helpful because message parm array can't handle longs.
|
||||
*/
|
||||
fprintf(stderr, "Freeing pool %d, total space = %ld\n",
|
||||
pool_id, mem->total_space_allocated);
|
||||
pool_id, mem->total_space_allocated);
|
||||
|
||||
for (lhdr_ptr = mem->large_list[pool_id]; lhdr_ptr != NULL;
|
||||
lhdr_ptr = lhdr_ptr->hdr.next) {
|
||||
fprintf(stderr, " Large chunk used %ld\n",
|
||||
(long) lhdr_ptr->hdr.bytes_used);
|
||||
(long) lhdr_ptr->hdr.bytes_used);
|
||||
}
|
||||
|
||||
for (shdr_ptr = mem->small_list[pool_id]; shdr_ptr != NULL;
|
||||
shdr_ptr = shdr_ptr->hdr.next) {
|
||||
fprintf(stderr, " Small chunk used %ld free %ld\n",
|
||||
(long) shdr_ptr->hdr.bytes_used,
|
||||
(long) shdr_ptr->hdr.bytes_left);
|
||||
(long) shdr_ptr->hdr.bytes_used,
|
||||
(long) shdr_ptr->hdr.bytes_left);
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* MEM_STATS */
|
||||
|
||||
|
||||
LOCAL(void)
|
||||
LOCAL(noreturn_t)
|
||||
out_of_memory (j_common_ptr cinfo, int which)
|
||||
/* Report an out-of-memory error and stop execution */
|
||||
/* If we compiled MEM_STATS support, report alloc requests before dying */
|
||||
@ -243,14 +241,14 @@ out_of_memory (j_common_ptr cinfo, int which)
|
||||
|
||||
static const size_t first_pool_slop[JPOOL_NUMPOOLS] =
|
||||
{
|
||||
1600, /* first PERMANENT pool */
|
||||
16000 /* first IMAGE pool */
|
||||
1600, /* first PERMANENT pool */
|
||||
16000 /* first IMAGE pool */
|
||||
};
|
||||
|
||||
static const size_t extra_pool_slop[JPOOL_NUMPOOLS] =
|
||||
{
|
||||
0, /* additional PERMANENT pools */
|
||||
5000 /* additional IMAGE pools */
|
||||
0, /* additional PERMANENT pools */
|
||||
5000 /* additional IMAGE pools */
|
||||
};
|
||||
|
||||
#define MIN_SLOP 50 /* greater than 0 to avoid futile looping */
|
||||
@ -301,10 +299,10 @@ alloc_small (j_common_ptr cinfo, int pool_id, size_t sizeofobject)
|
||||
for (;;) {
|
||||
hdr_ptr = (small_pool_ptr) jpeg_get_small(cinfo, min_request + slop);
|
||||
if (hdr_ptr != NULL)
|
||||
break;
|
||||
break;
|
||||
slop /= 2;
|
||||
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 += min_request + slop;
|
||||
/* Success, initialize the new pool header and add to end of list */
|
||||
@ -363,7 +361,7 @@ alloc_large (j_common_ptr cinfo, int pool_id, size_t sizeofobject)
|
||||
ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
|
||||
|
||||
hdr_ptr = (large_pool_ptr) jpeg_get_large(cinfo, sizeofobject +
|
||||
SIZEOF(large_pool_hdr));
|
||||
SIZEOF(large_pool_hdr));
|
||||
if (hdr_ptr == NULL)
|
||||
out_of_memory(cinfo, 4); /* jpeg_get_large failed */
|
||||
mem->total_space_allocated += sizeofobject + SIZEOF(large_pool_hdr);
|
||||
@ -396,7 +394,7 @@ alloc_large (j_common_ptr cinfo, int pool_id, size_t sizeofobject)
|
||||
|
||||
METHODDEF(JSAMPARRAY)
|
||||
alloc_sarray (j_common_ptr cinfo, int pool_id,
|
||||
JDIMENSION samplesperrow, JDIMENSION numrows)
|
||||
JDIMENSION samplesperrow, JDIMENSION numrows)
|
||||
/* Allocate a 2-D sample array */
|
||||
{
|
||||
my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
|
||||
@ -407,7 +405,7 @@ alloc_sarray (j_common_ptr cinfo, int pool_id,
|
||||
|
||||
/* Calculate max # of rows allowed in one allocation chunk */
|
||||
ltemp = (MAX_ALLOC_CHUNK-SIZEOF(large_pool_hdr)) /
|
||||
((long) samplesperrow * SIZEOF(JSAMPLE));
|
||||
((long) samplesperrow * SIZEOF(JSAMPLE));
|
||||
if (ltemp <= 0)
|
||||
ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
|
||||
if (ltemp < (long) numrows)
|
||||
@ -418,15 +416,15 @@ alloc_sarray (j_common_ptr cinfo, int pool_id,
|
||||
|
||||
/* Get space for row pointers (small object) */
|
||||
result = (JSAMPARRAY) alloc_small(cinfo, pool_id,
|
||||
(size_t) (numrows * SIZEOF(JSAMPROW)));
|
||||
(size_t) (numrows * SIZEOF(JSAMPROW)));
|
||||
|
||||
/* Get the rows themselves (large objects) */
|
||||
currow = 0;
|
||||
while (currow < numrows) {
|
||||
rowsperchunk = MIN(rowsperchunk, numrows - currow);
|
||||
workspace = (JSAMPROW) alloc_large(cinfo, pool_id,
|
||||
(size_t) ((size_t) rowsperchunk * (size_t) samplesperrow
|
||||
* SIZEOF(JSAMPLE)));
|
||||
(size_t) ((size_t) rowsperchunk * (size_t) samplesperrow
|
||||
* SIZEOF(JSAMPLE)));
|
||||
for (i = rowsperchunk; i > 0; i--) {
|
||||
result[currow++] = workspace;
|
||||
workspace += samplesperrow;
|
||||
@ -444,7 +442,7 @@ alloc_sarray (j_common_ptr cinfo, int pool_id,
|
||||
|
||||
METHODDEF(JBLOCKARRAY)
|
||||
alloc_barray (j_common_ptr cinfo, int pool_id,
|
||||
JDIMENSION blocksperrow, JDIMENSION numrows)
|
||||
JDIMENSION blocksperrow, JDIMENSION numrows)
|
||||
/* Allocate a 2-D coefficient-block array */
|
||||
{
|
||||
my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
|
||||
@ -455,7 +453,7 @@ alloc_barray (j_common_ptr cinfo, int pool_id,
|
||||
|
||||
/* Calculate max # of rows allowed in one allocation chunk */
|
||||
ltemp = (MAX_ALLOC_CHUNK-SIZEOF(large_pool_hdr)) /
|
||||
((long) blocksperrow * SIZEOF(JBLOCK));
|
||||
((long) blocksperrow * SIZEOF(JBLOCK));
|
||||
if (ltemp <= 0)
|
||||
ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
|
||||
if (ltemp < (long) numrows)
|
||||
@ -466,15 +464,15 @@ alloc_barray (j_common_ptr cinfo, int pool_id,
|
||||
|
||||
/* Get space for row pointers (small object) */
|
||||
result = (JBLOCKARRAY) alloc_small(cinfo, pool_id,
|
||||
(size_t) (numrows * SIZEOF(JBLOCKROW)));
|
||||
(size_t) (numrows * SIZEOF(JBLOCKROW)));
|
||||
|
||||
/* Get the rows themselves (large objects) */
|
||||
currow = 0;
|
||||
while (currow < numrows) {
|
||||
rowsperchunk = MIN(rowsperchunk, numrows - currow);
|
||||
workspace = (JBLOCKROW) alloc_large(cinfo, pool_id,
|
||||
(size_t) ((size_t) rowsperchunk * (size_t) blocksperrow
|
||||
* SIZEOF(JBLOCK)));
|
||||
(size_t) ((size_t) rowsperchunk * (size_t) blocksperrow
|
||||
* SIZEOF(JBLOCK)));
|
||||
for (i = rowsperchunk; i > 0; i--) {
|
||||
result[currow++] = workspace;
|
||||
workspace += blocksperrow;
|
||||
@ -524,8 +522,8 @@ alloc_barray (j_common_ptr cinfo, int pool_id,
|
||||
|
||||
METHODDEF(jvirt_sarray_ptr)
|
||||
request_virt_sarray (j_common_ptr cinfo, int pool_id, boolean pre_zero,
|
||||
JDIMENSION samplesperrow, JDIMENSION numrows,
|
||||
JDIMENSION maxaccess)
|
||||
JDIMENSION samplesperrow, JDIMENSION numrows,
|
||||
JDIMENSION maxaccess)
|
||||
/* Request a virtual 2-D sample array */
|
||||
{
|
||||
my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
|
||||
@ -537,7 +535,7 @@ request_virt_sarray (j_common_ptr cinfo, int pool_id, boolean pre_zero,
|
||||
|
||||
/* get control block */
|
||||
result = (jvirt_sarray_ptr) alloc_small(cinfo, pool_id,
|
||||
SIZEOF(struct jvirt_sarray_control));
|
||||
SIZEOF(struct jvirt_sarray_control));
|
||||
|
||||
result->mem_buffer = NULL; /* marks array not yet realized */
|
||||
result->rows_in_array = numrows;
|
||||
@ -554,8 +552,8 @@ request_virt_sarray (j_common_ptr cinfo, int pool_id, boolean pre_zero,
|
||||
|
||||
METHODDEF(jvirt_barray_ptr)
|
||||
request_virt_barray (j_common_ptr cinfo, int pool_id, boolean pre_zero,
|
||||
JDIMENSION blocksperrow, JDIMENSION numrows,
|
||||
JDIMENSION maxaccess)
|
||||
JDIMENSION blocksperrow, JDIMENSION numrows,
|
||||
JDIMENSION maxaccess)
|
||||
/* Request a virtual 2-D coefficient-block array */
|
||||
{
|
||||
my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
|
||||
@ -567,7 +565,7 @@ request_virt_barray (j_common_ptr cinfo, int pool_id, boolean pre_zero,
|
||||
|
||||
/* get control block */
|
||||
result = (jvirt_barray_ptr) alloc_small(cinfo, pool_id,
|
||||
SIZEOF(struct jvirt_barray_control));
|
||||
SIZEOF(struct jvirt_barray_control));
|
||||
|
||||
result->mem_buffer = NULL; /* marks array not yet realized */
|
||||
result->rows_in_array = numrows;
|
||||
@ -601,17 +599,17 @@ realize_virt_arrays (j_common_ptr cinfo)
|
||||
for (sptr = mem->virt_sarray_list; sptr != NULL; sptr = sptr->next) {
|
||||
if (sptr->mem_buffer == NULL) { /* if not realized yet */
|
||||
space_per_minheight += (long) sptr->maxaccess *
|
||||
(long) sptr->samplesperrow * SIZEOF(JSAMPLE);
|
||||
(long) sptr->samplesperrow * SIZEOF(JSAMPLE);
|
||||
maximum_space += (long) sptr->rows_in_array *
|
||||
(long) sptr->samplesperrow * SIZEOF(JSAMPLE);
|
||||
(long) sptr->samplesperrow * SIZEOF(JSAMPLE);
|
||||
}
|
||||
}
|
||||
for (bptr = mem->virt_barray_list; bptr != NULL; bptr = bptr->next) {
|
||||
if (bptr->mem_buffer == NULL) { /* if not realized yet */
|
||||
space_per_minheight += (long) bptr->maxaccess *
|
||||
(long) bptr->blocksperrow * SIZEOF(JBLOCK);
|
||||
(long) bptr->blocksperrow * SIZEOF(JBLOCK);
|
||||
maximum_space += (long) bptr->rows_in_array *
|
||||
(long) bptr->blocksperrow * SIZEOF(JBLOCK);
|
||||
(long) bptr->blocksperrow * SIZEOF(JBLOCK);
|
||||
}
|
||||
}
|
||||
|
||||
@ -620,7 +618,7 @@ realize_virt_arrays (j_common_ptr cinfo)
|
||||
|
||||
/* Determine amount of memory to actually use; this is system-dependent. */
|
||||
avail_mem = jpeg_mem_available(cinfo, space_per_minheight, maximum_space,
|
||||
mem->total_space_allocated);
|
||||
mem->total_space_allocated);
|
||||
|
||||
/* If the maximum space needed is available, make all the buffers full
|
||||
* height; otherwise parcel it out with the same number of minheights
|
||||
@ -643,19 +641,19 @@ realize_virt_arrays (j_common_ptr cinfo)
|
||||
if (sptr->mem_buffer == NULL) { /* if not realized yet */
|
||||
minheights = ((long) sptr->rows_in_array - 1L) / sptr->maxaccess + 1L;
|
||||
if (minheights <= max_minheights) {
|
||||
/* This buffer fits in memory */
|
||||
sptr->rows_in_mem = sptr->rows_in_array;
|
||||
/* This buffer fits in memory */
|
||||
sptr->rows_in_mem = sptr->rows_in_array;
|
||||
} else {
|
||||
/* It doesn't fit in memory, create backing store. */
|
||||
sptr->rows_in_mem = (JDIMENSION) (max_minheights * sptr->maxaccess);
|
||||
jpeg_open_backing_store(cinfo, & sptr->b_s_info,
|
||||
(long) sptr->rows_in_array *
|
||||
(long) sptr->samplesperrow *
|
||||
(long) SIZEOF(JSAMPLE));
|
||||
sptr->b_s_open = TRUE;
|
||||
/* It doesn't fit in memory, create backing store. */
|
||||
sptr->rows_in_mem = (JDIMENSION) (max_minheights * sptr->maxaccess);
|
||||
jpeg_open_backing_store(cinfo, & sptr->b_s_info,
|
||||
(long) sptr->rows_in_array *
|
||||
(long) sptr->samplesperrow *
|
||||
(long) SIZEOF(JSAMPLE));
|
||||
sptr->b_s_open = TRUE;
|
||||
}
|
||||
sptr->mem_buffer = alloc_sarray(cinfo, JPOOL_IMAGE,
|
||||
sptr->samplesperrow, sptr->rows_in_mem);
|
||||
sptr->samplesperrow, sptr->rows_in_mem);
|
||||
sptr->rowsperchunk = mem->last_rowsperchunk;
|
||||
sptr->cur_start_row = 0;
|
||||
sptr->first_undef_row = 0;
|
||||
@ -667,19 +665,19 @@ realize_virt_arrays (j_common_ptr cinfo)
|
||||
if (bptr->mem_buffer == NULL) { /* if not realized yet */
|
||||
minheights = ((long) bptr->rows_in_array - 1L) / bptr->maxaccess + 1L;
|
||||
if (minheights <= max_minheights) {
|
||||
/* This buffer fits in memory */
|
||||
bptr->rows_in_mem = bptr->rows_in_array;
|
||||
/* This buffer fits in memory */
|
||||
bptr->rows_in_mem = bptr->rows_in_array;
|
||||
} else {
|
||||
/* It doesn't fit in memory, create backing store. */
|
||||
bptr->rows_in_mem = (JDIMENSION) (max_minheights * bptr->maxaccess);
|
||||
jpeg_open_backing_store(cinfo, & bptr->b_s_info,
|
||||
(long) bptr->rows_in_array *
|
||||
(long) bptr->blocksperrow *
|
||||
(long) SIZEOF(JBLOCK));
|
||||
bptr->b_s_open = TRUE;
|
||||
/* It doesn't fit in memory, create backing store. */
|
||||
bptr->rows_in_mem = (JDIMENSION) (max_minheights * bptr->maxaccess);
|
||||
jpeg_open_backing_store(cinfo, & bptr->b_s_info,
|
||||
(long) bptr->rows_in_array *
|
||||
(long) bptr->blocksperrow *
|
||||
(long) SIZEOF(JBLOCK));
|
||||
bptr->b_s_open = TRUE;
|
||||
}
|
||||
bptr->mem_buffer = alloc_barray(cinfo, JPOOL_IMAGE,
|
||||
bptr->blocksperrow, bptr->rows_in_mem);
|
||||
bptr->blocksperrow, bptr->rows_in_mem);
|
||||
bptr->rowsperchunk = mem->last_rowsperchunk;
|
||||
bptr->cur_start_row = 0;
|
||||
bptr->first_undef_row = 0;
|
||||
@ -711,12 +709,12 @@ do_sarray_io (j_common_ptr cinfo, jvirt_sarray_ptr ptr, boolean writing)
|
||||
byte_count = rows * bytesperrow;
|
||||
if (writing)
|
||||
(*ptr->b_s_info.write_backing_store) (cinfo, & ptr->b_s_info,
|
||||
(void FAR *) ptr->mem_buffer[i],
|
||||
file_offset, byte_count);
|
||||
(void FAR *) ptr->mem_buffer[i],
|
||||
file_offset, byte_count);
|
||||
else
|
||||
(*ptr->b_s_info.read_backing_store) (cinfo, & ptr->b_s_info,
|
||||
(void FAR *) ptr->mem_buffer[i],
|
||||
file_offset, byte_count);
|
||||
(void FAR *) ptr->mem_buffer[i],
|
||||
file_offset, byte_count);
|
||||
file_offset += byte_count;
|
||||
}
|
||||
}
|
||||
@ -744,12 +742,12 @@ do_barray_io (j_common_ptr cinfo, jvirt_barray_ptr ptr, boolean writing)
|
||||
byte_count = rows * bytesperrow;
|
||||
if (writing)
|
||||
(*ptr->b_s_info.write_backing_store) (cinfo, & ptr->b_s_info,
|
||||
(void FAR *) ptr->mem_buffer[i],
|
||||
file_offset, byte_count);
|
||||
(void FAR *) ptr->mem_buffer[i],
|
||||
file_offset, byte_count);
|
||||
else
|
||||
(*ptr->b_s_info.read_backing_store) (cinfo, & ptr->b_s_info,
|
||||
(void FAR *) ptr->mem_buffer[i],
|
||||
file_offset, byte_count);
|
||||
(void FAR *) ptr->mem_buffer[i],
|
||||
file_offset, byte_count);
|
||||
file_offset += byte_count;
|
||||
}
|
||||
}
|
||||
@ -757,8 +755,8 @@ do_barray_io (j_common_ptr cinfo, jvirt_barray_ptr ptr, boolean writing)
|
||||
|
||||
METHODDEF(JSAMPARRAY)
|
||||
access_virt_sarray (j_common_ptr cinfo, jvirt_sarray_ptr ptr,
|
||||
JDIMENSION start_row, JDIMENSION num_rows,
|
||||
boolean writable)
|
||||
JDIMENSION start_row, JDIMENSION num_rows,
|
||||
boolean writable)
|
||||
/* Access the part of a virtual sample array starting at start_row */
|
||||
/* and extending for num_rows rows. writable is true if */
|
||||
/* caller intends to modify the accessed area. */
|
||||
@ -796,7 +794,7 @@ access_virt_sarray (j_common_ptr cinfo, jvirt_sarray_ptr ptr,
|
||||
|
||||
ltemp = (long) end_row - (long) ptr->rows_in_mem;
|
||||
if (ltemp < 0)
|
||||
ltemp = 0; /* don't fall off front end of file */
|
||||
ltemp = 0; /* don't fall off front end of file */
|
||||
ptr->cur_start_row = (JDIMENSION) ltemp;
|
||||
}
|
||||
/* Read in the selected part of the array.
|
||||
@ -812,7 +810,7 @@ access_virt_sarray (j_common_ptr cinfo, jvirt_sarray_ptr ptr,
|
||||
if (ptr->first_undef_row < end_row) {
|
||||
if (ptr->first_undef_row < start_row) {
|
||||
if (writable) /* writer skipped over a section of array */
|
||||
ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
|
||||
ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
|
||||
undef_row = start_row; /* but reader is allowed to read ahead */
|
||||
} else {
|
||||
undef_row = ptr->first_undef_row;
|
||||
@ -824,12 +822,12 @@ access_virt_sarray (j_common_ptr cinfo, jvirt_sarray_ptr ptr,
|
||||
undef_row -= ptr->cur_start_row; /* make indexes relative to buffer */
|
||||
end_row -= ptr->cur_start_row;
|
||||
while (undef_row < end_row) {
|
||||
jzero_far((void FAR *) ptr->mem_buffer[undef_row], bytesperrow);
|
||||
undef_row++;
|
||||
FMEMZERO((void FAR *) ptr->mem_buffer[undef_row], bytesperrow);
|
||||
undef_row++;
|
||||
}
|
||||
} else {
|
||||
if (! writable) /* reader looking at undefined data */
|
||||
ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
|
||||
ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
|
||||
}
|
||||
}
|
||||
/* Flag the buffer dirty if caller will write in it */
|
||||
@ -842,8 +840,8 @@ access_virt_sarray (j_common_ptr cinfo, jvirt_sarray_ptr ptr,
|
||||
|
||||
METHODDEF(JBLOCKARRAY)
|
||||
access_virt_barray (j_common_ptr cinfo, jvirt_barray_ptr ptr,
|
||||
JDIMENSION start_row, JDIMENSION num_rows,
|
||||
boolean writable)
|
||||
JDIMENSION start_row, JDIMENSION num_rows,
|
||||
boolean writable)
|
||||
/* Access the part of a virtual block array starting at start_row */
|
||||
/* and extending for num_rows rows. writable is true if */
|
||||
/* caller intends to modify the accessed area. */
|
||||
@ -881,7 +879,7 @@ access_virt_barray (j_common_ptr cinfo, jvirt_barray_ptr ptr,
|
||||
|
||||
ltemp = (long) end_row - (long) ptr->rows_in_mem;
|
||||
if (ltemp < 0)
|
||||
ltemp = 0; /* don't fall off front end of file */
|
||||
ltemp = 0; /* don't fall off front end of file */
|
||||
ptr->cur_start_row = (JDIMENSION) ltemp;
|
||||
}
|
||||
/* Read in the selected part of the array.
|
||||
@ -897,7 +895,7 @@ access_virt_barray (j_common_ptr cinfo, jvirt_barray_ptr ptr,
|
||||
if (ptr->first_undef_row < end_row) {
|
||||
if (ptr->first_undef_row < start_row) {
|
||||
if (writable) /* writer skipped over a section of array */
|
||||
ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
|
||||
ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
|
||||
undef_row = start_row; /* but reader is allowed to read ahead */
|
||||
} else {
|
||||
undef_row = ptr->first_undef_row;
|
||||
@ -909,12 +907,12 @@ access_virt_barray (j_common_ptr cinfo, jvirt_barray_ptr ptr,
|
||||
undef_row -= ptr->cur_start_row; /* make indexes relative to buffer */
|
||||
end_row -= ptr->cur_start_row;
|
||||
while (undef_row < end_row) {
|
||||
jzero_far((void FAR *) ptr->mem_buffer[undef_row], bytesperrow);
|
||||
undef_row++;
|
||||
FMEMZERO((void FAR *) ptr->mem_buffer[undef_row], bytesperrow);
|
||||
undef_row++;
|
||||
}
|
||||
} else {
|
||||
if (! writable) /* reader looking at undefined data */
|
||||
ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
|
||||
ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
|
||||
}
|
||||
}
|
||||
/* Flag the buffer dirty if caller will write in it */
|
||||
@ -952,15 +950,15 @@ free_pool (j_common_ptr cinfo, int pool_id)
|
||||
|
||||
for (sptr = mem->virt_sarray_list; sptr != NULL; sptr = sptr->next) {
|
||||
if (sptr->b_s_open) { /* there may be no backing store */
|
||||
sptr->b_s_open = FALSE; /* prevent recursive close if error */
|
||||
(*sptr->b_s_info.close_backing_store) (cinfo, & sptr->b_s_info);
|
||||
sptr->b_s_open = FALSE; /* prevent recursive close if error */
|
||||
(*sptr->b_s_info.close_backing_store) (cinfo, & sptr->b_s_info);
|
||||
}
|
||||
}
|
||||
mem->virt_sarray_list = NULL;
|
||||
for (bptr = mem->virt_barray_list; bptr != NULL; bptr = bptr->next) {
|
||||
if (bptr->b_s_open) { /* there may be no backing store */
|
||||
bptr->b_s_open = FALSE; /* prevent recursive close if error */
|
||||
(*bptr->b_s_info.close_backing_store) (cinfo, & bptr->b_s_info);
|
||||
bptr->b_s_open = FALSE; /* prevent recursive close if error */
|
||||
(*bptr->b_s_info.close_backing_store) (cinfo, & bptr->b_s_info);
|
||||
}
|
||||
}
|
||||
mem->virt_barray_list = NULL;
|
||||
@ -973,8 +971,8 @@ free_pool (j_common_ptr cinfo, int pool_id)
|
||||
while (lhdr_ptr != NULL) {
|
||||
large_pool_ptr next_lhdr_ptr = lhdr_ptr->hdr.next;
|
||||
space_freed = lhdr_ptr->hdr.bytes_used +
|
||||
lhdr_ptr->hdr.bytes_left +
|
||||
SIZEOF(large_pool_hdr);
|
||||
lhdr_ptr->hdr.bytes_left +
|
||||
SIZEOF(large_pool_hdr);
|
||||
jpeg_free_large(cinfo, (void FAR *) lhdr_ptr, space_freed);
|
||||
mem->total_space_allocated -= space_freed;
|
||||
lhdr_ptr = next_lhdr_ptr;
|
||||
@ -987,8 +985,8 @@ free_pool (j_common_ptr cinfo, int pool_id)
|
||||
while (shdr_ptr != NULL) {
|
||||
small_pool_ptr next_shdr_ptr = shdr_ptr->hdr.next;
|
||||
space_freed = shdr_ptr->hdr.bytes_used +
|
||||
shdr_ptr->hdr.bytes_left +
|
||||
SIZEOF(small_pool_hdr);
|
||||
shdr_ptr->hdr.bytes_left +
|
||||
SIZEOF(small_pool_hdr);
|
||||
jpeg_free_small(cinfo, (void *) shdr_ptr, space_freed);
|
||||
mem->total_space_allocated -= space_freed;
|
||||
shdr_ptr = next_shdr_ptr;
|
||||
@ -1110,9 +1108,9 @@ jinit_memory_mgr (j_common_ptr cinfo)
|
||||
char ch = 'x';
|
||||
|
||||
if (sscanf(memenv, "%ld%c", &max_to_use, &ch) > 0) {
|
||||
if (ch == 'm' || ch == 'M')
|
||||
max_to_use *= 1000L;
|
||||
mem->pub.max_memory_to_use = max_to_use * 1000L;
|
||||
if (ch == 'm' || ch == 'M')
|
||||
max_to_use *= 1000L;
|
||||
mem->pub.max_memory_to_use = max_to_use * 1000L;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
109
3rdparty/libjpeg/jmemnobs.c
vendored
Normal file
109
3rdparty/libjpeg/jmemnobs.c
vendored
Normal file
@ -0,0 +1,109 @@
|
||||
/*
|
||||
* jmemnobs.c
|
||||
*
|
||||
* Copyright (C) 1992-1996, Thomas G. Lane.
|
||||
* This file is part of the Independent JPEG Group's software.
|
||||
* For conditions of distribution and use, see the accompanying README file.
|
||||
*
|
||||
* This file provides a really simple implementation of the system-
|
||||
* dependent portion of the JPEG memory manager. This implementation
|
||||
* assumes that no backing-store files are needed: all required space
|
||||
* can be obtained from malloc().
|
||||
* This is very portable in the sense that it'll compile on almost anything,
|
||||
* but you'd better have lots of main memory (or virtual memory) if you want
|
||||
* to process big images.
|
||||
* Note that the max_memory_to_use option is ignored by this implementation.
|
||||
*/
|
||||
|
||||
#define JPEG_INTERNALS
|
||||
#include "jinclude.h"
|
||||
#include "jpeglib.h"
|
||||
#include "jmemsys.h" /* import the system-dependent declarations */
|
||||
|
||||
#ifndef HAVE_STDLIB_H /* <stdlib.h> should declare malloc(),free() */
|
||||
extern void * malloc JPP((size_t size));
|
||||
extern void free JPP((void *ptr));
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* Memory allocation and freeing are controlled by the regular library
|
||||
* routines malloc() and free().
|
||||
*/
|
||||
|
||||
GLOBAL(void *)
|
||||
jpeg_get_small (j_common_ptr cinfo, size_t sizeofobject)
|
||||
{
|
||||
return (void *) malloc(sizeofobject);
|
||||
}
|
||||
|
||||
GLOBAL(void)
|
||||
jpeg_free_small (j_common_ptr cinfo, void * object, size_t sizeofobject)
|
||||
{
|
||||
free(object);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* "Large" objects are treated the same as "small" ones.
|
||||
* NB: although we include FAR keywords in the routine declarations,
|
||||
* this file won't actually work in 80x86 small/medium model; at least,
|
||||
* you probably won't be able to process useful-size images in only 64KB.
|
||||
*/
|
||||
|
||||
GLOBAL(void FAR *)
|
||||
jpeg_get_large (j_common_ptr cinfo, size_t sizeofobject)
|
||||
{
|
||||
return (void FAR *) malloc(sizeofobject);
|
||||
}
|
||||
|
||||
GLOBAL(void)
|
||||
jpeg_free_large (j_common_ptr cinfo, void FAR * object, size_t sizeofobject)
|
||||
{
|
||||
free(object);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* This routine computes the total memory space available for allocation.
|
||||
* Here we always say, "we got all you want bud!"
|
||||
*/
|
||||
|
||||
GLOBAL(long)
|
||||
jpeg_mem_available (j_common_ptr cinfo, long min_bytes_needed,
|
||||
long max_bytes_needed, long already_allocated)
|
||||
{
|
||||
return max_bytes_needed;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Backing store (temporary file) management.
|
||||
* Since jpeg_mem_available always promised the moon,
|
||||
* this should never be called and we can just error out.
|
||||
*/
|
||||
|
||||
GLOBAL(void)
|
||||
jpeg_open_backing_store (j_common_ptr cinfo, backing_store_ptr info,
|
||||
long total_bytes_needed)
|
||||
{
|
||||
ERREXIT(cinfo, JERR_NO_BACKING_STORE);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* These routines take care of any system-dependent initialization and
|
||||
* cleanup required. Here, there isn't any.
|
||||
*/
|
||||
|
||||
GLOBAL(long)
|
||||
jpeg_mem_init (j_common_ptr cinfo)
|
||||
{
|
||||
return 0; /* just set max_memory_to_use to 0 */
|
||||
}
|
||||
|
||||
GLOBAL(void)
|
||||
jpeg_mem_term (j_common_ptr cinfo)
|
||||
{
|
||||
/* no work */
|
||||
}
|
30
3rdparty/libjpeg/jmemsys.h
vendored
30
3rdparty/libjpeg/jmemsys.h
vendored
@ -46,7 +46,7 @@
|
||||
|
||||
EXTERN(void *) jpeg_get_small JPP((j_common_ptr cinfo, size_t sizeofobject));
|
||||
EXTERN(void) jpeg_free_small JPP((j_common_ptr cinfo, void * object,
|
||||
size_t sizeofobject));
|
||||
size_t sizeofobject));
|
||||
|
||||
/*
|
||||
* These two functions are used to allocate and release large chunks of
|
||||
@ -58,9 +58,9 @@ EXTERN(void) jpeg_free_small JPP((j_common_ptr cinfo, void * object,
|
||||
*/
|
||||
|
||||
EXTERN(void FAR *) jpeg_get_large JPP((j_common_ptr cinfo,
|
||||
size_t sizeofobject));
|
||||
size_t sizeofobject));
|
||||
EXTERN(void) jpeg_free_large JPP((j_common_ptr cinfo, void FAR * object,
|
||||
size_t sizeofobject));
|
||||
size_t sizeofobject));
|
||||
|
||||
/*
|
||||
* The macro MAX_ALLOC_CHUNK designates the maximum number of bytes that may
|
||||
@ -101,9 +101,9 @@ EXTERN(void) jpeg_free_large JPP((j_common_ptr cinfo, void FAR * object,
|
||||
*/
|
||||
|
||||
EXTERN(long) jpeg_mem_available JPP((j_common_ptr cinfo,
|
||||
long min_bytes_needed,
|
||||
long max_bytes_needed,
|
||||
long already_allocated));
|
||||
long min_bytes_needed,
|
||||
long max_bytes_needed,
|
||||
long already_allocated));
|
||||
|
||||
|
||||
/*
|
||||
@ -139,15 +139,15 @@ typedef struct backing_store_struct * backing_store_ptr;
|
||||
typedef struct backing_store_struct {
|
||||
/* Methods for reading/writing/closing this backing-store object */
|
||||
JMETHOD(void, read_backing_store, (j_common_ptr cinfo,
|
||||
backing_store_ptr info,
|
||||
void FAR * buffer_address,
|
||||
long file_offset, long byte_count));
|
||||
backing_store_ptr info,
|
||||
void FAR * buffer_address,
|
||||
long file_offset, long byte_count));
|
||||
JMETHOD(void, write_backing_store, (j_common_ptr cinfo,
|
||||
backing_store_ptr info,
|
||||
void FAR * buffer_address,
|
||||
long file_offset, long byte_count));
|
||||
backing_store_ptr info,
|
||||
void FAR * buffer_address,
|
||||
long file_offset, long byte_count));
|
||||
JMETHOD(void, close_backing_store, (j_common_ptr cinfo,
|
||||
backing_store_ptr info));
|
||||
backing_store_ptr info));
|
||||
|
||||
/* Private fields for system-dependent backing-store management */
|
||||
#ifdef USE_MSDOS_MEMMGR
|
||||
@ -178,8 +178,8 @@ typedef struct backing_store_struct {
|
||||
*/
|
||||
|
||||
EXTERN(void) jpeg_open_backing_store JPP((j_common_ptr cinfo,
|
||||
backing_store_ptr info,
|
||||
long total_bytes_needed));
|
||||
backing_store_ptr info,
|
||||
long total_bytes_needed));
|
||||
|
||||
|
||||
/*
|
||||
|
49
3rdparty/libjpeg/jmorecfg.h
vendored
49
3rdparty/libjpeg/jmorecfg.h
vendored
@ -2,6 +2,7 @@
|
||||
* jmorecfg.h
|
||||
*
|
||||
* Copyright (C) 1991-1997, Thomas G. Lane.
|
||||
* Modified 1997-2012 by Guido Vollbeding.
|
||||
* This file is part of the Independent JPEG Group's software.
|
||||
* For conditions of distribution and use, see the accompanying README file.
|
||||
*
|
||||
@ -158,8 +159,14 @@ typedef short INT16;
|
||||
/* INT32 must hold at least signed 32-bit values. */
|
||||
|
||||
#ifndef XMD_H /* X11/xmd.h correctly defines INT32 */
|
||||
#ifndef _BASETSD_H_ /* Microsoft defines it in basetsd.h */
|
||||
#ifndef _BASETSD_H /* MinGW is slightly different */
|
||||
#ifndef QGLOBAL_H /* Qt defines it in qglobal.h */
|
||||
typedef long INT32;
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* Datatype used for image dimensions. The JPEG standard only supports
|
||||
* images up to 64K*64K due to 16-bit fields in SOF markers. Therefore
|
||||
@ -203,17 +210,39 @@ typedef unsigned int JDIMENSION;
|
||||
#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"
|
||||
* 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
|
||||
* explicit coding is needed; see uses of the NEED_FAR_POINTERS symbol.
|
||||
*/
|
||||
|
||||
#ifndef FAR
|
||||
#ifdef NEED_FAR_POINTERS
|
||||
#define FAR far
|
||||
#else
|
||||
#define FAR
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
@ -223,15 +252,16 @@ typedef unsigned int JDIMENSION;
|
||||
* Defining HAVE_BOOLEAN before including jpeglib.h should make it work.
|
||||
*/
|
||||
|
||||
#ifndef HAVE_BOOLEAN
|
||||
typedef int boolean;
|
||||
#endif
|
||||
#ifdef HAVE_BOOLEAN
|
||||
#ifndef FALSE /* in case these macros already exist */
|
||||
#define FALSE 0 /* values of boolean */
|
||||
#endif
|
||||
#ifndef TRUE
|
||||
#define TRUE 1
|
||||
#endif
|
||||
#else
|
||||
typedef enum { FALSE = 0, TRUE = 1 } boolean;
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
@ -256,8 +286,6 @@ typedef int boolean;
|
||||
* (You may HAVE to do that if your compiler doesn't like null source files.)
|
||||
*/
|
||||
|
||||
/* Arithmetic coding is unsupported for legal reasons. Complaints to IBM. */
|
||||
|
||||
/* Capability options common to encoder and decoder: */
|
||||
|
||||
#define DCT_ISLOW_SUPPORTED /* slow but accurate integer algorithm */
|
||||
@ -266,9 +294,10 @@ typedef int boolean;
|
||||
|
||||
/* Encoder capability options: */
|
||||
|
||||
#undef C_ARITH_CODING_SUPPORTED /* Arithmetic coding back end? */
|
||||
#define C_ARITH_CODING_SUPPORTED /* Arithmetic coding back end? */
|
||||
#define C_MULTISCAN_FILES_SUPPORTED /* Multiple-scan JPEG files? */
|
||||
#define C_PROGRESSIVE_SUPPORTED /* Progressive JPEG? (Requires MULTISCAN)*/
|
||||
#define DCT_SCALING_SUPPORTED /* Input rescaling via DCT? (Requires DCT_ISLOW)*/
|
||||
#define ENTROPY_OPT_SUPPORTED /* Optimization of entropy coding parms? */
|
||||
/* Note: if you selected 12-bit data precision, it is dangerous to turn off
|
||||
* ENTROPY_OPT_SUPPORTED. The standard Huffman tables are only good for 8-bit
|
||||
@ -282,12 +311,12 @@ typedef int boolean;
|
||||
|
||||
/* Decoder capability options: */
|
||||
|
||||
#undef 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_PROGRESSIVE_SUPPORTED /* Progressive JPEG? (Requires MULTISCAN)*/
|
||||
#define IDCT_SCALING_SUPPORTED /* Output rescaling via IDCT? */
|
||||
#define SAVE_MARKERS_SUPPORTED /* jpeg_save_markers() needed? */
|
||||
#define BLOCK_SMOOTHING_SUPPORTED /* Block smoothing? (Progressive only) */
|
||||
#define IDCT_SCALING_SUPPORTED /* Output rescaling via IDCT? */
|
||||
#undef UPSAMPLE_SCALING_SUPPORTED /* Output rescaling at upsample stage? */
|
||||
#define UPSAMPLE_MERGING_SUPPORTED /* Fast path for sloppy upsampling? */
|
||||
#define QUANT_1PASS_SUPPORTED /* 1-pass color quantization? */
|
||||
@ -304,9 +333,7 @@ typedef int boolean;
|
||||
* the offsets will also change the order in which colormap data is organized.
|
||||
* RESTRICTIONS:
|
||||
* 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
|
||||
* 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
|
||||
* 2. The color quantizer modules will not behave desirably if RGB_PIXELSIZE
|
||||
* is not 3 (they don't understand about dummy color components!). So you
|
||||
* can't use color quantization if you change that value.
|
||||
*/
|
||||
|
178
3rdparty/libjpeg/jpegint.h
vendored
178
3rdparty/libjpeg/jpegint.h
vendored
@ -2,6 +2,7 @@
|
||||
* jpegint.h
|
||||
*
|
||||
* Copyright (C) 1991-1997, Thomas G. Lane.
|
||||
* Modified 1997-2011 by Guido Vollbeding.
|
||||
* This file is part of the Independent JPEG Group's software.
|
||||
* For conditions of distribution and use, see the accompanying README file.
|
||||
*
|
||||
@ -14,11 +15,11 @@
|
||||
/* Declarations for both compression & decompression */
|
||||
|
||||
typedef enum { /* Operating modes for buffer controllers */
|
||||
JBUF_PASS_THRU, /* Plain stripwise operation */
|
||||
/* Remaining modes require a full-image buffer to have been created */
|
||||
JBUF_SAVE_SOURCE, /* Run source subobject only, save output */
|
||||
JBUF_CRANK_DEST, /* Run dest subobject only, using saved data */
|
||||
JBUF_SAVE_AND_PASS /* Run both subobjects, save output */
|
||||
JBUF_PASS_THRU, /* Plain stripwise operation */
|
||||
/* Remaining modes require a full-image buffer to have been created */
|
||||
JBUF_SAVE_SOURCE, /* Run source subobject only, save output */
|
||||
JBUF_CRANK_DEST, /* Run dest subobject only, using saved data */
|
||||
JBUF_SAVE_AND_PASS /* Run both subobjects, save output */
|
||||
} J_BUF_MODE;
|
||||
|
||||
/* Values of global_state field (jdapi.c has some dependencies on ordering!) */
|
||||
@ -56,57 +57,59 @@ struct jpeg_comp_master {
|
||||
struct jpeg_c_main_controller {
|
||||
JMETHOD(void, start_pass, (j_compress_ptr cinfo, J_BUF_MODE pass_mode));
|
||||
JMETHOD(void, process_data, (j_compress_ptr cinfo,
|
||||
JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
|
||||
JDIMENSION in_rows_avail));
|
||||
JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
|
||||
JDIMENSION in_rows_avail));
|
||||
};
|
||||
|
||||
/* Compression preprocessing (downsampling input buffer control) */
|
||||
struct jpeg_c_prep_controller {
|
||||
JMETHOD(void, start_pass, (j_compress_ptr cinfo, J_BUF_MODE pass_mode));
|
||||
JMETHOD(void, pre_process_data, (j_compress_ptr cinfo,
|
||||
JSAMPARRAY input_buf,
|
||||
JDIMENSION *in_row_ctr,
|
||||
JDIMENSION in_rows_avail,
|
||||
JSAMPIMAGE output_buf,
|
||||
JDIMENSION *out_row_group_ctr,
|
||||
JDIMENSION out_row_groups_avail));
|
||||
JSAMPARRAY input_buf,
|
||||
JDIMENSION *in_row_ctr,
|
||||
JDIMENSION in_rows_avail,
|
||||
JSAMPIMAGE output_buf,
|
||||
JDIMENSION *out_row_group_ctr,
|
||||
JDIMENSION out_row_groups_avail));
|
||||
};
|
||||
|
||||
/* Coefficient buffer control */
|
||||
struct jpeg_c_coef_controller {
|
||||
JMETHOD(void, start_pass, (j_compress_ptr cinfo, J_BUF_MODE pass_mode));
|
||||
JMETHOD(boolean, compress_data, (j_compress_ptr cinfo,
|
||||
JSAMPIMAGE input_buf));
|
||||
JSAMPIMAGE input_buf));
|
||||
};
|
||||
|
||||
/* Colorspace conversion */
|
||||
struct jpeg_color_converter {
|
||||
JMETHOD(void, start_pass, (j_compress_ptr cinfo));
|
||||
JMETHOD(void, color_convert, (j_compress_ptr cinfo,
|
||||
JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
|
||||
JDIMENSION output_row, int num_rows));
|
||||
JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
|
||||
JDIMENSION output_row, int num_rows));
|
||||
};
|
||||
|
||||
/* Downsampling */
|
||||
struct jpeg_downsampler {
|
||||
JMETHOD(void, start_pass, (j_compress_ptr cinfo));
|
||||
JMETHOD(void, downsample, (j_compress_ptr cinfo,
|
||||
JSAMPIMAGE input_buf, JDIMENSION in_row_index,
|
||||
JSAMPIMAGE output_buf,
|
||||
JDIMENSION out_row_group_index));
|
||||
JSAMPIMAGE input_buf, JDIMENSION in_row_index,
|
||||
JSAMPIMAGE output_buf,
|
||||
JDIMENSION out_row_group_index));
|
||||
|
||||
boolean need_context_rows; /* TRUE if need rows above & below */
|
||||
};
|
||||
|
||||
/* Forward DCT (also controls coefficient quantization) */
|
||||
typedef JMETHOD(void, forward_DCT_ptr,
|
||||
(j_compress_ptr cinfo, jpeg_component_info * compptr,
|
||||
JSAMPARRAY sample_data, JBLOCKROW coef_blocks,
|
||||
JDIMENSION start_row, JDIMENSION start_col,
|
||||
JDIMENSION num_blocks));
|
||||
|
||||
struct jpeg_forward_dct {
|
||||
JMETHOD(void, start_pass, (j_compress_ptr cinfo));
|
||||
/* perhaps this should be an array??? */
|
||||
JMETHOD(void, forward_DCT, (j_compress_ptr cinfo,
|
||||
jpeg_component_info * compptr,
|
||||
JSAMPARRAY sample_data, JBLOCKROW coef_blocks,
|
||||
JDIMENSION start_row, JDIMENSION start_col,
|
||||
JDIMENSION num_blocks));
|
||||
/* It is useful to allow each component to have a separate FDCT method. */
|
||||
forward_DCT_ptr forward_DCT[MAX_COMPONENTS];
|
||||
};
|
||||
|
||||
/* Entropy encoding */
|
||||
@ -126,7 +129,7 @@ struct jpeg_marker_writer {
|
||||
/* These routines are exported to allow insertion of extra markers */
|
||||
/* Probably only COM and APPn markers should be written this way */
|
||||
JMETHOD(void, write_marker_header, (j_compress_ptr cinfo, int marker,
|
||||
unsigned int datalen));
|
||||
unsigned int datalen));
|
||||
JMETHOD(void, write_marker_byte, (j_compress_ptr cinfo, int val));
|
||||
};
|
||||
|
||||
@ -158,8 +161,8 @@ struct jpeg_input_controller {
|
||||
struct jpeg_d_main_controller {
|
||||
JMETHOD(void, start_pass, (j_decompress_ptr cinfo, J_BUF_MODE pass_mode));
|
||||
JMETHOD(void, process_data, (j_decompress_ptr cinfo,
|
||||
JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
|
||||
JDIMENSION out_rows_avail));
|
||||
JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
|
||||
JDIMENSION out_rows_avail));
|
||||
};
|
||||
|
||||
/* Coefficient buffer control */
|
||||
@ -168,7 +171,7 @@ struct jpeg_d_coef_controller {
|
||||
JMETHOD(int, consume_data, (j_decompress_ptr cinfo));
|
||||
JMETHOD(void, start_output_pass, (j_decompress_ptr cinfo));
|
||||
JMETHOD(int, decompress_data, (j_decompress_ptr cinfo,
|
||||
JSAMPIMAGE output_buf));
|
||||
JSAMPIMAGE output_buf));
|
||||
/* Pointer to array of coefficient virtual arrays, or NULL if none */
|
||||
jvirt_barray_ptr *coef_arrays;
|
||||
};
|
||||
@ -177,12 +180,12 @@ struct jpeg_d_coef_controller {
|
||||
struct jpeg_d_post_controller {
|
||||
JMETHOD(void, start_pass, (j_decompress_ptr cinfo, J_BUF_MODE pass_mode));
|
||||
JMETHOD(void, post_process_data, (j_decompress_ptr cinfo,
|
||||
JSAMPIMAGE input_buf,
|
||||
JDIMENSION *in_row_group_ctr,
|
||||
JDIMENSION in_row_groups_avail,
|
||||
JSAMPARRAY output_buf,
|
||||
JDIMENSION *out_row_ctr,
|
||||
JDIMENSION out_rows_avail));
|
||||
JSAMPIMAGE input_buf,
|
||||
JDIMENSION *in_row_group_ctr,
|
||||
JDIMENSION in_row_groups_avail,
|
||||
JSAMPARRAY output_buf,
|
||||
JDIMENSION *out_row_ctr,
|
||||
JDIMENSION out_rows_avail));
|
||||
};
|
||||
|
||||
/* Marker reading & parsing */
|
||||
@ -209,18 +212,14 @@ struct jpeg_marker_reader {
|
||||
struct jpeg_entropy_decoder {
|
||||
JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
|
||||
JMETHOD(boolean, decode_mcu, (j_decompress_ptr cinfo,
|
||||
JBLOCKROW *MCU_data));
|
||||
|
||||
/* This is here to share code between baseline and progressive decoders; */
|
||||
/* other modules probably should not use it */
|
||||
boolean insufficient_data; /* set TRUE after emitting warning */
|
||||
JBLOCKROW *MCU_data));
|
||||
};
|
||||
|
||||
/* Inverse DCT (also performs dequantization) */
|
||||
typedef JMETHOD(void, inverse_DCT_method_ptr,
|
||||
(j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
||||
JCOEFPTR coef_block,
|
||||
JSAMPARRAY output_buf, JDIMENSION output_col));
|
||||
(j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
||||
JCOEFPTR coef_block,
|
||||
JSAMPARRAY output_buf, JDIMENSION output_col));
|
||||
|
||||
struct jpeg_inverse_dct {
|
||||
JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
|
||||
@ -232,12 +231,12 @@ struct jpeg_inverse_dct {
|
||||
struct jpeg_upsampler {
|
||||
JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
|
||||
JMETHOD(void, upsample, (j_decompress_ptr cinfo,
|
||||
JSAMPIMAGE input_buf,
|
||||
JDIMENSION *in_row_group_ctr,
|
||||
JDIMENSION in_row_groups_avail,
|
||||
JSAMPARRAY output_buf,
|
||||
JDIMENSION *out_row_ctr,
|
||||
JDIMENSION out_rows_avail));
|
||||
JSAMPIMAGE input_buf,
|
||||
JDIMENSION *in_row_group_ctr,
|
||||
JDIMENSION in_row_groups_avail,
|
||||
JSAMPARRAY output_buf,
|
||||
JDIMENSION *out_row_ctr,
|
||||
JDIMENSION out_rows_avail));
|
||||
|
||||
boolean need_context_rows; /* TRUE if need rows above & below */
|
||||
};
|
||||
@ -246,16 +245,16 @@ struct jpeg_upsampler {
|
||||
struct jpeg_color_deconverter {
|
||||
JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
|
||||
JMETHOD(void, color_convert, (j_decompress_ptr cinfo,
|
||||
JSAMPIMAGE input_buf, JDIMENSION input_row,
|
||||
JSAMPARRAY output_buf, int num_rows));
|
||||
JSAMPIMAGE input_buf, JDIMENSION input_row,
|
||||
JSAMPARRAY output_buf, int num_rows));
|
||||
};
|
||||
|
||||
/* Color quantization or color precision reduction */
|
||||
struct jpeg_color_quantizer {
|
||||
JMETHOD(void, start_pass, (j_decompress_ptr cinfo, boolean is_pre_scan));
|
||||
JMETHOD(void, color_quantize, (j_decompress_ptr cinfo,
|
||||
JSAMPARRAY input_buf, JSAMPARRAY output_buf,
|
||||
int num_rows));
|
||||
JSAMPARRAY input_buf, JSAMPARRAY output_buf,
|
||||
int num_rows));
|
||||
JMETHOD(void, finish_pass, (j_decompress_ptr cinfo));
|
||||
JMETHOD(void, new_color_map, (j_decompress_ptr cinfo));
|
||||
};
|
||||
@ -282,9 +281,9 @@ struct jpeg_color_quantizer {
|
||||
#ifdef RIGHT_SHIFT_IS_UNSIGNED
|
||||
#define SHIFT_TEMPS INT32 shift_temp;
|
||||
#define RIGHT_SHIFT(x,shft) \
|
||||
((shift_temp = (x)) < 0 ? \
|
||||
(shift_temp >> (shft)) | ((~((INT32) 0)) << (32-(shft))) : \
|
||||
(shift_temp >> (shft)))
|
||||
((shift_temp = (x)) < 0 ? \
|
||||
(shift_temp >> (shft)) | ((~((INT32) 0)) << (32-(shft))) : \
|
||||
(shift_temp >> (shft)))
|
||||
#else
|
||||
#define SHIFT_TEMPS
|
||||
#define RIGHT_SHIFT(x,shft) ((x) >> (shft))
|
||||
@ -303,7 +302,7 @@ struct jpeg_color_quantizer {
|
||||
#define jinit_downsampler jIDownsampler
|
||||
#define jinit_forward_dct jIFDCT
|
||||
#define jinit_huff_encoder jIHEncoder
|
||||
#define jinit_phuff_encoder jIPHEncoder
|
||||
#define jinit_arith_encoder jIAEncoder
|
||||
#define jinit_marker_writer jIMWriter
|
||||
#define jinit_master_decompress jIDMaster
|
||||
#define jinit_d_main_controller jIDMainC
|
||||
@ -312,7 +311,7 @@ struct jpeg_color_quantizer {
|
||||
#define jinit_input_controller jIInCtlr
|
||||
#define jinit_marker_reader jIMReader
|
||||
#define jinit_huff_decoder jIHDecoder
|
||||
#define jinit_phuff_decoder jIPHDecoder
|
||||
#define jinit_arith_decoder jIADecoder
|
||||
#define jinit_inverse_dct jIIDCT
|
||||
#define jinit_upsampler jIUpsampler
|
||||
#define jinit_color_deconverter jIDColor
|
||||
@ -322,42 +321,69 @@ struct jpeg_color_quantizer {
|
||||
#define jinit_memory_mgr jIMemMgr
|
||||
#define jdiv_round_up jDivRound
|
||||
#define jround_up jRound
|
||||
#define jzero_far jZeroFar
|
||||
#define jcopy_sample_rows jCopySamples
|
||||
#define jcopy_block_row jCopyBlocks
|
||||
#define jzero_far jZeroFar
|
||||
#define jpeg_zigzag_order jZIGTable
|
||||
#define jpeg_natural_order jZAGTable
|
||||
#define jpeg_natural_order7 jZAG7Table
|
||||
#define jpeg_natural_order6 jZAG6Table
|
||||
#define jpeg_natural_order5 jZAG5Table
|
||||
#define jpeg_natural_order4 jZAG4Table
|
||||
#define jpeg_natural_order3 jZAG3Table
|
||||
#define jpeg_natural_order2 jZAG2Table
|
||||
#define jpeg_aritab jAriTab
|
||||
#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 */
|
||||
EXTERN(void) jinit_compress_master JPP((j_compress_ptr cinfo));
|
||||
EXTERN(void) jinit_c_master_control JPP((j_compress_ptr cinfo,
|
||||
boolean transcode_only));
|
||||
boolean transcode_only));
|
||||
EXTERN(void) jinit_c_main_controller JPP((j_compress_ptr cinfo,
|
||||
boolean need_full_buffer));
|
||||
boolean need_full_buffer));
|
||||
EXTERN(void) jinit_c_prep_controller JPP((j_compress_ptr cinfo,
|
||||
boolean need_full_buffer));
|
||||
boolean need_full_buffer));
|
||||
EXTERN(void) jinit_c_coef_controller JPP((j_compress_ptr cinfo,
|
||||
boolean need_full_buffer));
|
||||
boolean need_full_buffer));
|
||||
EXTERN(void) jinit_color_converter JPP((j_compress_ptr cinfo));
|
||||
EXTERN(void) jinit_downsampler JPP((j_compress_ptr cinfo));
|
||||
EXTERN(void) jinit_forward_dct JPP((j_compress_ptr cinfo));
|
||||
EXTERN(void) jinit_huff_encoder JPP((j_compress_ptr cinfo));
|
||||
EXTERN(void) jinit_phuff_encoder JPP((j_compress_ptr cinfo));
|
||||
EXTERN(void) jinit_arith_encoder JPP((j_compress_ptr cinfo));
|
||||
EXTERN(void) jinit_marker_writer JPP((j_compress_ptr cinfo));
|
||||
/* Decompression module initialization routines */
|
||||
EXTERN(void) jinit_master_decompress JPP((j_decompress_ptr cinfo));
|
||||
EXTERN(void) jinit_d_main_controller JPP((j_decompress_ptr cinfo,
|
||||
boolean need_full_buffer));
|
||||
boolean need_full_buffer));
|
||||
EXTERN(void) jinit_d_coef_controller JPP((j_decompress_ptr cinfo,
|
||||
boolean need_full_buffer));
|
||||
boolean need_full_buffer));
|
||||
EXTERN(void) jinit_d_post_controller JPP((j_decompress_ptr cinfo,
|
||||
boolean need_full_buffer));
|
||||
boolean need_full_buffer));
|
||||
EXTERN(void) jinit_input_controller JPP((j_decompress_ptr cinfo));
|
||||
EXTERN(void) jinit_marker_reader JPP((j_decompress_ptr cinfo));
|
||||
EXTERN(void) jinit_huff_decoder JPP((j_decompress_ptr cinfo));
|
||||
EXTERN(void) jinit_phuff_decoder JPP((j_decompress_ptr cinfo));
|
||||
EXTERN(void) jinit_arith_decoder JPP((j_decompress_ptr cinfo));
|
||||
EXTERN(void) jinit_inverse_dct JPP((j_decompress_ptr cinfo));
|
||||
EXTERN(void) jinit_upsampler JPP((j_decompress_ptr cinfo));
|
||||
EXTERN(void) jinit_color_deconverter JPP((j_decompress_ptr cinfo));
|
||||
@ -371,16 +397,24 @@ EXTERN(void) jinit_memory_mgr JPP((j_common_ptr cinfo));
|
||||
EXTERN(long) jdiv_round_up JPP((long a, long b));
|
||||
EXTERN(long) jround_up JPP((long a, long b));
|
||||
EXTERN(void) jcopy_sample_rows JPP((JSAMPARRAY input_array, int source_row,
|
||||
JSAMPARRAY output_array, int dest_row,
|
||||
int num_rows, JDIMENSION num_cols));
|
||||
JSAMPARRAY output_array, int dest_row,
|
||||
int num_rows, JDIMENSION num_cols));
|
||||
EXTERN(void) jcopy_block_row JPP((JBLOCKROW input_row, JBLOCKROW output_row,
|
||||
JDIMENSION num_blocks));
|
||||
EXTERN(void) jzero_far JPP((void FAR * target, size_t bytestozero));
|
||||
JDIMENSION num_blocks));
|
||||
/* Constant tables in jutils.c */
|
||||
#if 0 /* This table is not actually needed in v6a */
|
||||
extern const int jpeg_zigzag_order[]; /* natural coef order to zigzag order */
|
||||
#endif
|
||||
extern const int jpeg_natural_order[]; /* zigzag coef order to natural order */
|
||||
extern const int jpeg_natural_order7[]; /* zz to natural order for 7x7 block */
|
||||
extern const int jpeg_natural_order6[]; /* zz to natural order for 6x6 block */
|
||||
extern const int jpeg_natural_order5[]; /* zz to natural order for 5x5 block */
|
||||
extern const int jpeg_natural_order4[]; /* zz to natural order for 4x4 block */
|
||||
extern const int jpeg_natural_order3[]; /* zz to natural order for 3x3 block */
|
||||
extern const int jpeg_natural_order2[]; /* zz to natural order for 2x2 block */
|
||||
|
||||
/* Arithmetic coding probability estimation tables in jaricom.c */
|
||||
extern const INT32 jpeg_aritab[];
|
||||
|
||||
/* Suppress undefined-structure complaints if necessary. */
|
||||
|
||||
|
273
3rdparty/libjpeg/jpeglib.h
vendored
273
3rdparty/libjpeg/jpeglib.h
vendored
@ -2,6 +2,7 @@
|
||||
* jpeglib.h
|
||||
*
|
||||
* Copyright (C) 1991-1998, Thomas G. Lane.
|
||||
* Modified 2002-2012 by Guido Vollbeding.
|
||||
* This file is part of the Independent JPEG Group's software.
|
||||
* For conditions of distribution and use, see the accompanying README file.
|
||||
*
|
||||
@ -13,17 +14,6 @@
|
||||
#ifndef JPEGLIB_H
|
||||
#define JPEGLIB_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* HJH modification: protect compiler options for structure alignment and enum
|
||||
* size if the compiler is Borland C++ */
|
||||
#ifdef __BORLANDC__
|
||||
#pragma option push -b
|
||||
#pragma option push -a4
|
||||
#endif
|
||||
|
||||
/*
|
||||
* First we include the configuration files that record how this
|
||||
* installation of the JPEG library is set up. jconfig.h can be
|
||||
@ -37,11 +27,19 @@ extern "C" {
|
||||
#include "jmorecfg.h" /* seldom changed options */
|
||||
|
||||
|
||||
/* Version ID for the JPEG library.
|
||||
* Might be useful for tests like "#if JPEG_LIB_VERSION >= 60".
|
||||
#ifdef __cplusplus
|
||||
#ifndef DONT_USE_EXTERN_C
|
||||
extern "C" {
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* Version IDs for the JPEG library.
|
||||
* Might be useful for tests like "#if JPEG_LIB_VERSION >= 90".
|
||||
*/
|
||||
|
||||
#define JPEG_LIB_VERSION 62 /* Version 6b */
|
||||
#define JPEG_LIB_VERSION 90 /* Compatibility version 9.0 */
|
||||
#define JPEG_LIB_VERSION_MAJOR 9
|
||||
#define JPEG_LIB_VERSION_MINOR 0
|
||||
|
||||
|
||||
/* Various constants determining the sizes of things.
|
||||
@ -49,7 +47,7 @@ extern "C" {
|
||||
* 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 NUM_QUANT_TBLS 4 /* Quantization tables are numbered 0..3 */
|
||||
#define NUM_HUFF_TBLS 4 /* Huffman tables are numbered 0..3 */
|
||||
@ -111,7 +109,7 @@ typedef struct {
|
||||
typedef struct {
|
||||
/* These two fields directly represent the contents of a JPEG DHT marker */
|
||||
UINT8 bits[17]; /* bits[k] = # of symbols with codes of */
|
||||
/* length k bits; bits[0] is unused */
|
||||
/* length k bits; bits[0] is unused */
|
||||
UINT8 huffval[256]; /* The symbols, in order of incr code length */
|
||||
/* This field is used only during compression. It's initialized FALSE when
|
||||
* the table is created, and set TRUE when it's been output to the file.
|
||||
@ -149,18 +147,18 @@ typedef struct {
|
||||
*/
|
||||
JDIMENSION width_in_blocks;
|
||||
JDIMENSION height_in_blocks;
|
||||
/* Size of a DCT block in samples. Always DCTSIZE for compression.
|
||||
* For decompression this is the size of the output from one DCT block,
|
||||
* reflecting any scaling we choose to apply during the IDCT step.
|
||||
* Values of 1,2,4,8 are likely to be supported. Note that different
|
||||
* components may receive different IDCT scalings.
|
||||
/* Size of a DCT block in samples,
|
||||
* reflecting any scaling we choose to apply during the DCT step.
|
||||
* Values from 1 to 16 are supported.
|
||||
* Note that different components may receive different DCT scalings.
|
||||
*/
|
||||
int DCT_scaled_size;
|
||||
int DCT_h_scaled_size;
|
||||
int DCT_v_scaled_size;
|
||||
/* The downsampled dimensions are the component's actual, unpadded number
|
||||
* of samples at the main buffer (preprocessing/compression interface), thus
|
||||
* downsampled_width = ceil(image_width * Hi/Hmax)
|
||||
* and similarly for height. For decompression, IDCT scaling is included, so
|
||||
* downsampled_width = ceil(image_width * Hi/Hmax * DCT_scaled_size/DCTSIZE)
|
||||
* of samples at the main buffer (preprocessing/compression interface);
|
||||
* DCT scaling is included, so
|
||||
* downsampled_width = ceil(image_width * Hi/Hmax * DCT_h_scaled_size/DCTSIZE)
|
||||
* and similarly for height.
|
||||
*/
|
||||
JDIMENSION downsampled_width; /* actual width in samples */
|
||||
JDIMENSION downsampled_height; /* actual height in samples */
|
||||
@ -175,7 +173,7 @@ typedef struct {
|
||||
int MCU_width; /* number of blocks per MCU, horizontally */
|
||||
int MCU_height; /* number of blocks per MCU, vertically */
|
||||
int MCU_blocks; /* MCU_width * MCU_height */
|
||||
int MCU_sample_width; /* MCU width in samples, MCU_width*DCT_scaled_size */
|
||||
int MCU_sample_width; /* MCU width in samples: MCU_width * DCT_h_scaled_size */
|
||||
int last_col_width; /* # of non-dummy blocks across in last MCU */
|
||||
int last_row_height; /* # of non-dummy blocks down in last MCU */
|
||||
|
||||
@ -215,20 +213,27 @@ struct jpeg_marker_struct {
|
||||
/* Known color spaces. */
|
||||
|
||||
typedef enum {
|
||||
JCS_UNKNOWN, /* error/unspecified */
|
||||
JCS_GRAYSCALE, /* monochrome */
|
||||
JCS_RGB, /* red/green/blue */
|
||||
JCS_YCbCr, /* Y/Cb/Cr (also known as YUV) */
|
||||
JCS_CMYK, /* C/M/Y/K */
|
||||
JCS_YCCK /* Y/Cb/Cr/K */
|
||||
JCS_UNKNOWN, /* error/unspecified */
|
||||
JCS_GRAYSCALE, /* monochrome */
|
||||
JCS_RGB, /* red/green/blue */
|
||||
JCS_YCbCr, /* Y/Cb/Cr (also known as YUV) */
|
||||
JCS_CMYK, /* C/M/Y/K */
|
||||
JCS_YCCK /* Y/Cb/Cr/K */
|
||||
} J_COLOR_SPACE;
|
||||
|
||||
/* Supported color transforms. */
|
||||
|
||||
typedef enum {
|
||||
JCT_NONE = 0,
|
||||
JCT_SUBTRACT_GREEN = 1
|
||||
} J_COLOR_TRANSFORM;
|
||||
|
||||
/* DCT/IDCT algorithm options. */
|
||||
|
||||
typedef enum {
|
||||
JDCT_ISLOW, /* slow but accurate integer algorithm */
|
||||
JDCT_IFAST, /* faster, less accurate integer method */
|
||||
JDCT_FLOAT /* floating-point: accurate, fast on fast HW */
|
||||
JDCT_ISLOW, /* slow but accurate integer algorithm */
|
||||
JDCT_IFAST, /* faster, less accurate integer method */
|
||||
JDCT_FLOAT /* floating-point: accurate, fast on fast HW */
|
||||
} J_DCT_METHOD;
|
||||
|
||||
#ifndef JDCT_DEFAULT /* may be overridden in jconfig.h */
|
||||
@ -241,9 +246,9 @@ typedef enum {
|
||||
/* Dithering options for decompression. */
|
||||
|
||||
typedef enum {
|
||||
JDITHER_NONE, /* no dithering */
|
||||
JDITHER_ORDERED, /* simple ordered dither */
|
||||
JDITHER_FS /* Floyd-Steinberg error diffusion dither */
|
||||
JDITHER_NONE, /* no dithering */
|
||||
JDITHER_ORDERED, /* simple ordered dither */
|
||||
JDITHER_FS /* Floyd-Steinberg error diffusion dither */
|
||||
} J_DITHER_MODE;
|
||||
|
||||
|
||||
@ -302,6 +307,17 @@ struct jpeg_compress_struct {
|
||||
* helper routines to simplify changing parameters.
|
||||
*/
|
||||
|
||||
unsigned int scale_num, scale_denom; /* fraction by which to scale image */
|
||||
|
||||
JDIMENSION jpeg_width; /* scaled JPEG image width */
|
||||
JDIMENSION jpeg_height; /* scaled JPEG image height */
|
||||
/* Dimensions of actual JPEG image that will be written to file,
|
||||
* derived from input dimensions by scaling factors above.
|
||||
* These fields are computed by jpeg_start_compress().
|
||||
* You can also use jpeg_calc_jpeg_dimensions() to determine these values
|
||||
* in advance of calling jpeg_start_compress().
|
||||
*/
|
||||
|
||||
int data_precision; /* bits of precision in image data */
|
||||
|
||||
int num_components; /* # of color components in JPEG image */
|
||||
@ -311,7 +327,10 @@ struct jpeg_compress_struct {
|
||||
/* comp_info[i] describes component that appears i'th in SOF */
|
||||
|
||||
JQUANT_TBL * quant_tbl_ptrs[NUM_QUANT_TBLS];
|
||||
/* ptrs to coefficient quantization tables, or NULL if not defined */
|
||||
int q_scale_factor[NUM_QUANT_TBLS];
|
||||
/* ptrs to coefficient quantization tables, or NULL if not defined,
|
||||
* and corresponding scale factors (percentage, initialized 100).
|
||||
*/
|
||||
|
||||
JHUFF_TBL * dc_huff_tbl_ptrs[NUM_HUFF_TBLS];
|
||||
JHUFF_TBL * ac_huff_tbl_ptrs[NUM_HUFF_TBLS];
|
||||
@ -332,6 +351,7 @@ struct jpeg_compress_struct {
|
||||
boolean arith_code; /* TRUE=arithmetic coding, FALSE=Huffman */
|
||||
boolean optimize_coding; /* TRUE=optimize entropy encoding parms */
|
||||
boolean CCIR601_sampling; /* TRUE=first samples are cosited */
|
||||
boolean do_fancy_downsampling; /* TRUE=apply fancy downsampling */
|
||||
int smoothing_factor; /* 1..100, or 0 for no input smoothing */
|
||||
J_DCT_METHOD dct_method; /* DCT algorithm selector */
|
||||
|
||||
@ -357,6 +377,9 @@ struct jpeg_compress_struct {
|
||||
UINT16 Y_density; /* Vertical pixel density */
|
||||
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
|
||||
* jpeg_write_scanlines(). Application may use this to control its
|
||||
* processing loop, e.g., "while (next_scanline < image_height)".
|
||||
@ -375,6 +398,9 @@ struct jpeg_compress_struct {
|
||||
int max_h_samp_factor; /* largest h_samp_factor */
|
||||
int max_v_samp_factor; /* largest v_samp_factor */
|
||||
|
||||
int min_DCT_h_scaled_size; /* smallest DCT_h_scaled_size of any component */
|
||||
int min_DCT_v_scaled_size; /* smallest DCT_v_scaled_size of any component */
|
||||
|
||||
JDIMENSION total_iMCU_rows; /* # of iMCU rows to be input to coef ctlr */
|
||||
/* The coefficient controller receives data in units of MCU rows as defined
|
||||
* for fully interleaved scans (whether the JPEG file is interleaved or not).
|
||||
@ -400,6 +426,10 @@ struct jpeg_compress_struct {
|
||||
|
||||
int Ss, Se, Ah, Al; /* progressive JPEG parameters for scan */
|
||||
|
||||
int block_size; /* the basic DCT block size: 1..16 */
|
||||
const int * natural_order; /* natural-order position array */
|
||||
int lim_Se; /* min( Se, DCTSIZE2-1 ) */
|
||||
|
||||
/*
|
||||
* Links to compression subobjects (methods and private variables of modules)
|
||||
*/
|
||||
@ -546,6 +576,7 @@ struct jpeg_decompress_struct {
|
||||
jpeg_component_info * comp_info;
|
||||
/* comp_info[i] describes component that appears i'th in SOF */
|
||||
|
||||
boolean is_baseline; /* TRUE if Baseline SOF0 encountered */
|
||||
boolean progressive_mode; /* TRUE if SOFn specifies progressive mode */
|
||||
boolean arith_code; /* TRUE=arithmetic coding, FALSE=Huffman */
|
||||
|
||||
@ -568,6 +599,9 @@ struct jpeg_decompress_struct {
|
||||
boolean saw_Adobe_marker; /* TRUE iff an Adobe APP14 marker was found */
|
||||
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 */
|
||||
|
||||
/* Aside from the specific data retained from APPn markers known to the
|
||||
@ -586,7 +620,8 @@ struct jpeg_decompress_struct {
|
||||
int max_h_samp_factor; /* largest h_samp_factor */
|
||||
int max_v_samp_factor; /* largest v_samp_factor */
|
||||
|
||||
int min_DCT_scaled_size; /* smallest DCT_scaled_size of any component */
|
||||
int min_DCT_h_scaled_size; /* smallest DCT_h_scaled_size of any component */
|
||||
int min_DCT_v_scaled_size; /* smallest DCT_v_scaled_size of any component */
|
||||
|
||||
JDIMENSION total_iMCU_rows; /* # of iMCU rows in image */
|
||||
/* The coefficient controller's input and output progress is measured in
|
||||
@ -594,7 +629,7 @@ struct jpeg_decompress_struct {
|
||||
* in fully interleaved JPEG scans, but are used whether the scan is
|
||||
* interleaved or not. We define an iMCU row as v_samp_factor DCT block
|
||||
* rows of each component. Therefore, the IDCT output contains
|
||||
* v_samp_factor*DCT_scaled_size sample rows of a component per iMCU row.
|
||||
* v_samp_factor*DCT_v_scaled_size sample rows of a component per iMCU row.
|
||||
*/
|
||||
|
||||
JSAMPLE * sample_range_limit; /* table for fast range-limiting */
|
||||
@ -618,6 +653,12 @@ struct jpeg_decompress_struct {
|
||||
|
||||
int Ss, Se, Ah, Al; /* progressive JPEG parameters for scan */
|
||||
|
||||
/* These fields are derived from Se of first SOS marker.
|
||||
*/
|
||||
int block_size; /* the basic DCT block size: 1..16 */
|
||||
const int * natural_order; /* natural-order position array for entropy decode */
|
||||
int lim_Se; /* min( Se, DCTSIZE2-1 ) for entropy decode */
|
||||
|
||||
/* This field is shared between entropy decoder and marker parser.
|
||||
* It is either zero or the code of a JPEG marker that has been
|
||||
* read from the data source, but has not yet been processed.
|
||||
@ -653,7 +694,7 @@ struct jpeg_decompress_struct {
|
||||
|
||||
struct jpeg_error_mgr {
|
||||
/* 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 */
|
||||
JMETHOD(void, emit_message, (j_common_ptr cinfo, int msg_level));
|
||||
/* Routine that actually outputs a trace or error message */
|
||||
@ -767,38 +808,38 @@ typedef struct jvirt_barray_control * jvirt_barray_ptr;
|
||||
struct jpeg_memory_mgr {
|
||||
/* Method pointers */
|
||||
JMETHOD(void *, alloc_small, (j_common_ptr cinfo, int pool_id,
|
||||
size_t sizeofobject));
|
||||
size_t sizeofobject));
|
||||
JMETHOD(void FAR *, alloc_large, (j_common_ptr cinfo, int pool_id,
|
||||
size_t sizeofobject));
|
||||
size_t sizeofobject));
|
||||
JMETHOD(JSAMPARRAY, alloc_sarray, (j_common_ptr cinfo, int pool_id,
|
||||
JDIMENSION samplesperrow,
|
||||
JDIMENSION numrows));
|
||||
JDIMENSION samplesperrow,
|
||||
JDIMENSION numrows));
|
||||
JMETHOD(JBLOCKARRAY, alloc_barray, (j_common_ptr cinfo, int pool_id,
|
||||
JDIMENSION blocksperrow,
|
||||
JDIMENSION numrows));
|
||||
JDIMENSION blocksperrow,
|
||||
JDIMENSION numrows));
|
||||
JMETHOD(jvirt_sarray_ptr, request_virt_sarray, (j_common_ptr cinfo,
|
||||
int pool_id,
|
||||
boolean pre_zero,
|
||||
JDIMENSION samplesperrow,
|
||||
JDIMENSION numrows,
|
||||
JDIMENSION maxaccess));
|
||||
int pool_id,
|
||||
boolean pre_zero,
|
||||
JDIMENSION samplesperrow,
|
||||
JDIMENSION numrows,
|
||||
JDIMENSION maxaccess));
|
||||
JMETHOD(jvirt_barray_ptr, request_virt_barray, (j_common_ptr cinfo,
|
||||
int pool_id,
|
||||
boolean pre_zero,
|
||||
JDIMENSION blocksperrow,
|
||||
JDIMENSION numrows,
|
||||
JDIMENSION maxaccess));
|
||||
int pool_id,
|
||||
boolean pre_zero,
|
||||
JDIMENSION blocksperrow,
|
||||
JDIMENSION numrows,
|
||||
JDIMENSION maxaccess));
|
||||
JMETHOD(void, realize_virt_arrays, (j_common_ptr cinfo));
|
||||
JMETHOD(JSAMPARRAY, access_virt_sarray, (j_common_ptr cinfo,
|
||||
jvirt_sarray_ptr ptr,
|
||||
JDIMENSION start_row,
|
||||
JDIMENSION num_rows,
|
||||
boolean writable));
|
||||
jvirt_sarray_ptr ptr,
|
||||
JDIMENSION start_row,
|
||||
JDIMENSION num_rows,
|
||||
boolean writable));
|
||||
JMETHOD(JBLOCKARRAY, access_virt_barray, (j_common_ptr cinfo,
|
||||
jvirt_barray_ptr ptr,
|
||||
JDIMENSION start_row,
|
||||
JDIMENSION num_rows,
|
||||
boolean writable));
|
||||
jvirt_barray_ptr ptr,
|
||||
JDIMENSION start_row,
|
||||
JDIMENSION num_rows,
|
||||
boolean writable));
|
||||
JMETHOD(void, free_pool, (j_common_ptr cinfo, int pool_id));
|
||||
JMETHOD(void, self_destruct, (j_common_ptr cinfo));
|
||||
|
||||
@ -847,11 +888,14 @@ typedef JMETHOD(boolean, jpeg_marker_parser_method, (j_decompress_ptr cinfo));
|
||||
#define jpeg_destroy_decompress jDestDecompress
|
||||
#define jpeg_stdio_dest jStdDest
|
||||
#define jpeg_stdio_src jStdSrc
|
||||
#define jpeg_mem_dest jMemDest
|
||||
#define jpeg_mem_src jMemSrc
|
||||
#define jpeg_set_defaults jSetDefaults
|
||||
#define jpeg_set_colorspace jSetColorspace
|
||||
#define jpeg_default_colorspace jDefColorspace
|
||||
#define jpeg_set_quality jSetQuality
|
||||
#define jpeg_set_linear_quality jSetLQuality
|
||||
#define jpeg_default_qtables jDefQTables
|
||||
#define jpeg_add_quant_table jAddQuantTable
|
||||
#define jpeg_quality_scaling jQualityScaling
|
||||
#define jpeg_simple_progression jSimProgress
|
||||
@ -861,6 +905,7 @@ typedef JMETHOD(boolean, jpeg_marker_parser_method, (j_decompress_ptr cinfo));
|
||||
#define jpeg_start_compress jStrtCompress
|
||||
#define jpeg_write_scanlines jWrtScanlines
|
||||
#define jpeg_finish_compress jFinCompress
|
||||
#define jpeg_calc_jpeg_dimensions jCjpegDimensions
|
||||
#define jpeg_write_raw_data jWrtRawData
|
||||
#define jpeg_write_marker jWrtMarker
|
||||
#define jpeg_write_m_header jWrtMHeader
|
||||
@ -877,6 +922,7 @@ typedef JMETHOD(boolean, jpeg_marker_parser_method, (j_decompress_ptr cinfo));
|
||||
#define jpeg_input_complete jInComplete
|
||||
#define jpeg_new_colormap jNewCMap
|
||||
#define jpeg_consume_input jConsumeInput
|
||||
#define jpeg_core_output_dimensions jCoreDimensions
|
||||
#define jpeg_calc_output_dimensions jCalcDimensions
|
||||
#define jpeg_save_markers jSaveMarkers
|
||||
#define jpeg_set_marker_processor jSetMarker
|
||||
@ -893,7 +939,7 @@ typedef JMETHOD(boolean, jpeg_marker_parser_method, (j_decompress_ptr cinfo));
|
||||
|
||||
/* Default error-management setup */
|
||||
EXTERN(struct jpeg_error_mgr *) jpeg_std_error
|
||||
JPP((struct jpeg_error_mgr * err));
|
||||
JPP((struct jpeg_error_mgr * err));
|
||||
|
||||
/* Initialization of JPEG compression objects.
|
||||
* jpeg_create_compress() and jpeg_create_decompress() are the exported
|
||||
@ -904,14 +950,14 @@ EXTERN(struct jpeg_error_mgr *) jpeg_std_error
|
||||
*/
|
||||
#define jpeg_create_compress(cinfo) \
|
||||
jpeg_CreateCompress((cinfo), JPEG_LIB_VERSION, \
|
||||
(size_t) sizeof(struct jpeg_compress_struct))
|
||||
(size_t) sizeof(struct jpeg_compress_struct))
|
||||
#define jpeg_create_decompress(cinfo) \
|
||||
jpeg_CreateDecompress((cinfo), JPEG_LIB_VERSION, \
|
||||
(size_t) sizeof(struct jpeg_decompress_struct))
|
||||
(size_t) sizeof(struct jpeg_decompress_struct))
|
||||
EXTERN(void) jpeg_CreateCompress JPP((j_compress_ptr cinfo,
|
||||
int version, size_t structsize));
|
||||
int version, size_t structsize));
|
||||
EXTERN(void) jpeg_CreateDecompress JPP((j_decompress_ptr cinfo,
|
||||
int version, size_t structsize));
|
||||
int version, size_t structsize));
|
||||
/* Destruction of JPEG compression objects */
|
||||
EXTERN(void) jpeg_destroy_compress JPP((j_compress_ptr cinfo));
|
||||
EXTERN(void) jpeg_destroy_decompress JPP((j_decompress_ptr cinfo));
|
||||
@ -921,57 +967,70 @@ EXTERN(void) jpeg_destroy_decompress JPP((j_decompress_ptr cinfo));
|
||||
EXTERN(void) jpeg_stdio_dest JPP((j_compress_ptr cinfo, FILE * outfile));
|
||||
EXTERN(void) jpeg_stdio_src JPP((j_decompress_ptr cinfo, FILE * infile));
|
||||
|
||||
/* Data source and destination managers: memory buffers. */
|
||||
EXTERN(void) jpeg_mem_dest JPP((j_compress_ptr cinfo,
|
||||
unsigned char ** outbuffer,
|
||||
unsigned long * outsize));
|
||||
EXTERN(void) jpeg_mem_src JPP((j_decompress_ptr cinfo,
|
||||
unsigned char * inbuffer,
|
||||
unsigned long insize));
|
||||
|
||||
/* Default parameter setup for compression */
|
||||
EXTERN(void) jpeg_set_defaults JPP((j_compress_ptr cinfo));
|
||||
/* Compression parameter setup aids */
|
||||
EXTERN(void) jpeg_set_colorspace JPP((j_compress_ptr cinfo,
|
||||
J_COLOR_SPACE colorspace));
|
||||
J_COLOR_SPACE colorspace));
|
||||
EXTERN(void) jpeg_default_colorspace JPP((j_compress_ptr cinfo));
|
||||
EXTERN(void) jpeg_set_quality JPP((j_compress_ptr cinfo, int quality,
|
||||
boolean force_baseline));
|
||||
boolean force_baseline));
|
||||
EXTERN(void) jpeg_set_linear_quality JPP((j_compress_ptr cinfo,
|
||||
int scale_factor,
|
||||
boolean force_baseline));
|
||||
int scale_factor,
|
||||
boolean force_baseline));
|
||||
EXTERN(void) jpeg_default_qtables JPP((j_compress_ptr cinfo,
|
||||
boolean force_baseline));
|
||||
EXTERN(void) jpeg_add_quant_table JPP((j_compress_ptr cinfo, int which_tbl,
|
||||
const unsigned int *basic_table,
|
||||
int scale_factor,
|
||||
boolean force_baseline));
|
||||
const unsigned int *basic_table,
|
||||
int scale_factor,
|
||||
boolean force_baseline));
|
||||
EXTERN(int) jpeg_quality_scaling JPP((int quality));
|
||||
EXTERN(void) jpeg_simple_progression JPP((j_compress_ptr cinfo));
|
||||
EXTERN(void) jpeg_suppress_tables JPP((j_compress_ptr cinfo,
|
||||
boolean suppress));
|
||||
boolean suppress));
|
||||
EXTERN(JQUANT_TBL *) jpeg_alloc_quant_table JPP((j_common_ptr cinfo));
|
||||
EXTERN(JHUFF_TBL *) jpeg_alloc_huff_table JPP((j_common_ptr cinfo));
|
||||
|
||||
/* Main entry points for compression */
|
||||
EXTERN(void) jpeg_start_compress JPP((j_compress_ptr cinfo,
|
||||
boolean write_all_tables));
|
||||
boolean write_all_tables));
|
||||
EXTERN(JDIMENSION) jpeg_write_scanlines JPP((j_compress_ptr cinfo,
|
||||
JSAMPARRAY scanlines,
|
||||
JDIMENSION num_lines));
|
||||
JSAMPARRAY scanlines,
|
||||
JDIMENSION num_lines));
|
||||
EXTERN(void) jpeg_finish_compress JPP((j_compress_ptr cinfo));
|
||||
|
||||
/* Precalculate JPEG dimensions for current compression parameters. */
|
||||
EXTERN(void) jpeg_calc_jpeg_dimensions JPP((j_compress_ptr cinfo));
|
||||
|
||||
/* Replaces jpeg_write_scanlines when writing raw downsampled data. */
|
||||
EXTERN(JDIMENSION) jpeg_write_raw_data JPP((j_compress_ptr cinfo,
|
||||
JSAMPIMAGE data,
|
||||
JDIMENSION num_lines));
|
||||
JSAMPIMAGE data,
|
||||
JDIMENSION num_lines));
|
||||
|
||||
/* Write a special marker. See libjpeg.doc concerning safe usage. */
|
||||
/* Write a special marker. See libjpeg.txt concerning safe usage. */
|
||||
EXTERN(void) jpeg_write_marker
|
||||
JPP((j_compress_ptr cinfo, int marker,
|
||||
const JOCTET * dataptr, unsigned int datalen));
|
||||
JPP((j_compress_ptr cinfo, int marker,
|
||||
const JOCTET * dataptr, unsigned int datalen));
|
||||
/* Same, but piecemeal. */
|
||||
EXTERN(void) jpeg_write_m_header
|
||||
JPP((j_compress_ptr cinfo, int marker, unsigned int datalen));
|
||||
JPP((j_compress_ptr cinfo, int marker, unsigned int datalen));
|
||||
EXTERN(void) jpeg_write_m_byte
|
||||
JPP((j_compress_ptr cinfo, int val));
|
||||
JPP((j_compress_ptr cinfo, int val));
|
||||
|
||||
/* Alternate compression function: just write an abbreviated table file */
|
||||
EXTERN(void) jpeg_write_tables JPP((j_compress_ptr cinfo));
|
||||
|
||||
/* Decompression startup: read start of JPEG datastream to see what's there */
|
||||
EXTERN(int) jpeg_read_header JPP((j_decompress_ptr cinfo,
|
||||
boolean require_image));
|
||||
boolean require_image));
|
||||
/* Return value is one of: */
|
||||
#define JPEG_SUSPENDED 0 /* Suspended due to lack of input data */
|
||||
#define JPEG_HEADER_OK 1 /* Found valid image datastream */
|
||||
@ -985,19 +1044,19 @@ EXTERN(int) jpeg_read_header JPP((j_decompress_ptr cinfo,
|
||||
/* Main entry points for decompression */
|
||||
EXTERN(boolean) jpeg_start_decompress JPP((j_decompress_ptr cinfo));
|
||||
EXTERN(JDIMENSION) jpeg_read_scanlines JPP((j_decompress_ptr cinfo,
|
||||
JSAMPARRAY scanlines,
|
||||
JDIMENSION max_lines));
|
||||
JSAMPARRAY scanlines,
|
||||
JDIMENSION max_lines));
|
||||
EXTERN(boolean) jpeg_finish_decompress JPP((j_decompress_ptr cinfo));
|
||||
|
||||
/* Replaces jpeg_read_scanlines when reading raw downsampled data. */
|
||||
EXTERN(JDIMENSION) jpeg_read_raw_data JPP((j_decompress_ptr cinfo,
|
||||
JSAMPIMAGE data,
|
||||
JDIMENSION max_lines));
|
||||
JSAMPIMAGE data,
|
||||
JDIMENSION max_lines));
|
||||
|
||||
/* Additional entry points for buffered-image mode. */
|
||||
EXTERN(boolean) jpeg_has_multiple_scans JPP((j_decompress_ptr cinfo));
|
||||
EXTERN(boolean) jpeg_start_output JPP((j_decompress_ptr cinfo,
|
||||
int scan_number));
|
||||
int scan_number));
|
||||
EXTERN(boolean) jpeg_finish_output JPP((j_decompress_ptr cinfo));
|
||||
EXTERN(boolean) jpeg_input_complete JPP((j_decompress_ptr cinfo));
|
||||
EXTERN(void) jpeg_new_colormap JPP((j_decompress_ptr cinfo));
|
||||
@ -1010,24 +1069,25 @@ EXTERN(int) jpeg_consume_input JPP((j_decompress_ptr cinfo));
|
||||
#define JPEG_SCAN_COMPLETED 4 /* Completed last iMCU row of a scan */
|
||||
|
||||
/* Precalculate output dimensions for current decompression parameters. */
|
||||
EXTERN(void) jpeg_core_output_dimensions JPP((j_decompress_ptr cinfo));
|
||||
EXTERN(void) jpeg_calc_output_dimensions JPP((j_decompress_ptr cinfo));
|
||||
|
||||
/* Control saving of COM and APPn markers into marker_list. */
|
||||
EXTERN(void) jpeg_save_markers
|
||||
JPP((j_decompress_ptr cinfo, int marker_code,
|
||||
unsigned int length_limit));
|
||||
JPP((j_decompress_ptr cinfo, int marker_code,
|
||||
unsigned int length_limit));
|
||||
|
||||
/* Install a special processing method for COM or APPn markers. */
|
||||
EXTERN(void) jpeg_set_marker_processor
|
||||
JPP((j_decompress_ptr cinfo, int marker_code,
|
||||
jpeg_marker_parser_method routine));
|
||||
JPP((j_decompress_ptr cinfo, int marker_code,
|
||||
jpeg_marker_parser_method routine));
|
||||
|
||||
/* Read or write raw DCT coefficients --- useful for lossless transcoding. */
|
||||
EXTERN(jvirt_barray_ptr *) jpeg_read_coefficients JPP((j_decompress_ptr cinfo));
|
||||
EXTERN(void) jpeg_write_coefficients JPP((j_compress_ptr cinfo,
|
||||
jvirt_barray_ptr * coef_arrays));
|
||||
jvirt_barray_ptr * coef_arrays));
|
||||
EXTERN(void) jpeg_copy_critical_parameters JPP((j_decompress_ptr srcinfo,
|
||||
j_compress_ptr dstinfo));
|
||||
j_compress_ptr dstinfo));
|
||||
|
||||
/* If you choose to abort compression or decompression before completing
|
||||
* jpeg_finish_(de)compress, then you need to clean up to release memory,
|
||||
@ -1046,7 +1106,7 @@ EXTERN(void) jpeg_destroy JPP((j_common_ptr cinfo));
|
||||
|
||||
/* Default restart-marker-resync procedure for use by data source modules */
|
||||
EXTERN(boolean) jpeg_resync_to_restart JPP((j_decompress_ptr cinfo,
|
||||
int desired));
|
||||
int desired));
|
||||
|
||||
|
||||
/* These marker codes are exported since applications and data source modules
|
||||
@ -1104,13 +1164,10 @@ struct jpeg_color_quantizer { long dummy; };
|
||||
#include "jerror.h" /* fetch error codes too */
|
||||
#endif
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma option pop /* pop -a switch */
|
||||
#pragma option pop /* pop -b */
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
#ifndef DONT_USE_EXTERN_C
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif /* JPEGLIB_H */
|
||||
|
181
3rdparty/libjpeg/jquant1.c
vendored
181
3rdparty/libjpeg/jquant1.c
vendored
@ -2,6 +2,7 @@
|
||||
* jquant1.c
|
||||
*
|
||||
* Copyright (C) 1991-1996, Thomas G. Lane.
|
||||
* Modified 2011 by Guido Vollbeding.
|
||||
* This file is part of the Independent JPEG Group's software.
|
||||
* For conditions of distribution and use, see the accompanying README file.
|
||||
*
|
||||
@ -230,7 +231,7 @@ select_ncolors (j_decompress_ptr cinfo, int Ncolors[])
|
||||
temp = total_colors / Ncolors[j];
|
||||
temp *= Ncolors[j]+1; /* done in long arith to avoid oflo */
|
||||
if (temp > (long) max_colors)
|
||||
break; /* won't fit, done with this pass */
|
||||
break; /* won't fit, done with this pass */
|
||||
Ncolors[j]++; /* OK, apply the increment */
|
||||
total_colors = (int) temp;
|
||||
changed = TRUE;
|
||||
@ -283,8 +284,8 @@ create_colormap (j_decompress_ptr cinfo)
|
||||
/* Report selected color counts */
|
||||
if (cinfo->out_color_components == 3)
|
||||
TRACEMS4(cinfo, 1, JTRC_QUANT_3_NCOLORS,
|
||||
total_colors, cquantize->Ncolors[0],
|
||||
cquantize->Ncolors[1], cquantize->Ncolors[2]);
|
||||
total_colors, cquantize->Ncolors[0],
|
||||
cquantize->Ncolors[1], cquantize->Ncolors[2]);
|
||||
else
|
||||
TRACEMS1(cinfo, 1, JTRC_QUANT_NCOLORS, total_colors);
|
||||
|
||||
@ -309,9 +310,9 @@ create_colormap (j_decompress_ptr cinfo)
|
||||
val = output_value(cinfo, i, j, nci-1);
|
||||
/* Fill in all colormap entries that have this value of this component */
|
||||
for (ptr = j * blksize; ptr < total_colors; ptr += blkdist) {
|
||||
/* fill in blksize entries beginning at ptr */
|
||||
for (k = 0; k < blksize; k++)
|
||||
colormap[i][ptr+k] = (JSAMPLE) val;
|
||||
/* fill in blksize entries beginning at ptr */
|
||||
for (k = 0; k < blksize; k++)
|
||||
colormap[i][ptr+k] = (JSAMPLE) val;
|
||||
}
|
||||
}
|
||||
blkdist = blksize; /* blksize of this color is blkdist of next */
|
||||
@ -373,15 +374,15 @@ create_colorindex (j_decompress_ptr cinfo)
|
||||
k = largest_input_value(cinfo, i, 0, nci-1);
|
||||
for (j = 0; j <= MAXJSAMPLE; j++) {
|
||||
while (j > k) /* advance val if past boundary */
|
||||
k = largest_input_value(cinfo, i, ++val, nci-1);
|
||||
k = largest_input_value(cinfo, i, ++val, nci-1);
|
||||
/* premultiply so that no multiplication needed in main processing */
|
||||
indexptr[j] = (JSAMPLE) (val * blksize);
|
||||
}
|
||||
/* Pad at both ends if necessary */
|
||||
if (pad)
|
||||
for (j = 1; j <= MAXJSAMPLE; j++) {
|
||||
indexptr[-j] = indexptr[0];
|
||||
indexptr[MAXJSAMPLE+j] = indexptr[MAXJSAMPLE];
|
||||
indexptr[-j] = indexptr[0];
|
||||
indexptr[MAXJSAMPLE+j] = indexptr[MAXJSAMPLE];
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -401,7 +402,7 @@ make_odither_array (j_decompress_ptr cinfo, int ncolors)
|
||||
|
||||
odither = (ODITHER_MATRIX_PTR)
|
||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
||||
SIZEOF(ODITHER_MATRIX));
|
||||
SIZEOF(ODITHER_MATRIX));
|
||||
/* The inter-value distance for this color is MAXJSAMPLE/(ncolors-1).
|
||||
* Hence the dither value for the matrix cell with fill order f
|
||||
* (f=0..N-1) should be (N-1-2*f)/(2*N) * MAXJSAMPLE/(ncolors-1).
|
||||
@ -411,7 +412,7 @@ make_odither_array (j_decompress_ptr cinfo, int ncolors)
|
||||
for (j = 0; j < ODITHER_SIZE; j++) {
|
||||
for (k = 0; k < ODITHER_SIZE; k++) {
|
||||
num = ((INT32) (ODITHER_CELLS-1 - 2*((int)base_dither_matrix[j][k])))
|
||||
* MAXJSAMPLE;
|
||||
* MAXJSAMPLE;
|
||||
/* Ensure round towards zero despite C's lack of consistency
|
||||
* about rounding negative values in integer division...
|
||||
*/
|
||||
@ -440,8 +441,8 @@ create_odither_tables (j_decompress_ptr cinfo)
|
||||
odither = NULL; /* search for matching prior component */
|
||||
for (j = 0; j < i; j++) {
|
||||
if (nci == cquantize->Ncolors[j]) {
|
||||
odither = cquantize->odither[j];
|
||||
break;
|
||||
odither = cquantize->odither[j];
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (odither == NULL) /* need a new table? */
|
||||
@ -457,7 +458,7 @@ create_odither_tables (j_decompress_ptr cinfo)
|
||||
|
||||
METHODDEF(void)
|
||||
color_quantize (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
|
||||
JSAMPARRAY output_buf, int num_rows)
|
||||
JSAMPARRAY output_buf, int num_rows)
|
||||
/* General case, no dithering */
|
||||
{
|
||||
my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
|
||||
@ -475,7 +476,7 @@ color_quantize (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
|
||||
for (col = width; col > 0; col--) {
|
||||
pixcode = 0;
|
||||
for (ci = 0; ci < nc; ci++) {
|
||||
pixcode += GETJSAMPLE(colorindex[ci][GETJSAMPLE(*ptrin++)]);
|
||||
pixcode += GETJSAMPLE(colorindex[ci][GETJSAMPLE(*ptrin++)]);
|
||||
}
|
||||
*ptrout++ = (JSAMPLE) pixcode;
|
||||
}
|
||||
@ -485,7 +486,7 @@ color_quantize (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
|
||||
|
||||
METHODDEF(void)
|
||||
color_quantize3 (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
|
||||
JSAMPARRAY output_buf, int num_rows)
|
||||
JSAMPARRAY output_buf, int num_rows)
|
||||
/* Fast path for out_color_components==3, no dithering */
|
||||
{
|
||||
my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
|
||||
@ -513,7 +514,7 @@ color_quantize3 (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
|
||||
|
||||
METHODDEF(void)
|
||||
quantize_ord_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
|
||||
JSAMPARRAY output_buf, int num_rows)
|
||||
JSAMPARRAY output_buf, int num_rows)
|
||||
/* General case, with ordered dithering */
|
||||
{
|
||||
my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
|
||||
@ -530,8 +531,8 @@ quantize_ord_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
|
||||
|
||||
for (row = 0; row < num_rows; row++) {
|
||||
/* Initialize output values to 0 so can process components separately */
|
||||
jzero_far((void FAR *) output_buf[row],
|
||||
(size_t) (width * SIZEOF(JSAMPLE)));
|
||||
FMEMZERO((void FAR *) output_buf[row],
|
||||
(size_t) (width * SIZEOF(JSAMPLE)));
|
||||
row_index = cquantize->row_index;
|
||||
for (ci = 0; ci < nc; ci++) {
|
||||
input_ptr = input_buf[row] + ci;
|
||||
@ -541,17 +542,17 @@ quantize_ord_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
|
||||
col_index = 0;
|
||||
|
||||
for (col = width; col > 0; col--) {
|
||||
/* Form pixel value + dither, range-limit to 0..MAXJSAMPLE,
|
||||
* select output value, accumulate into output code for this pixel.
|
||||
* Range-limiting need not be done explicitly, as we have extended
|
||||
* the colorindex table to produce the right answers for out-of-range
|
||||
* inputs. The maximum dither is +- MAXJSAMPLE; this sets the
|
||||
* required amount of padding.
|
||||
*/
|
||||
*output_ptr += colorindex_ci[GETJSAMPLE(*input_ptr)+dither[col_index]];
|
||||
input_ptr += nc;
|
||||
output_ptr++;
|
||||
col_index = (col_index + 1) & ODITHER_MASK;
|
||||
/* Form pixel value + dither, range-limit to 0..MAXJSAMPLE,
|
||||
* select output value, accumulate into output code for this pixel.
|
||||
* Range-limiting need not be done explicitly, as we have extended
|
||||
* the colorindex table to produce the right answers for out-of-range
|
||||
* inputs. The maximum dither is +- MAXJSAMPLE; this sets the
|
||||
* required amount of padding.
|
||||
*/
|
||||
*output_ptr += colorindex_ci[GETJSAMPLE(*input_ptr)+dither[col_index]];
|
||||
input_ptr += nc;
|
||||
output_ptr++;
|
||||
col_index = (col_index + 1) & ODITHER_MASK;
|
||||
}
|
||||
}
|
||||
/* Advance row index for next row */
|
||||
@ -563,7 +564,7 @@ quantize_ord_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
|
||||
|
||||
METHODDEF(void)
|
||||
quantize3_ord_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
|
||||
JSAMPARRAY output_buf, int num_rows)
|
||||
JSAMPARRAY output_buf, int num_rows)
|
||||
/* Fast path for out_color_components==3, with ordered dithering */
|
||||
{
|
||||
my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
|
||||
@ -592,11 +593,11 @@ quantize3_ord_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
|
||||
|
||||
for (col = width; col > 0; col--) {
|
||||
pixcode = GETJSAMPLE(colorindex0[GETJSAMPLE(*input_ptr++) +
|
||||
dither0[col_index]]);
|
||||
dither0[col_index]]);
|
||||
pixcode += GETJSAMPLE(colorindex1[GETJSAMPLE(*input_ptr++) +
|
||||
dither1[col_index]]);
|
||||
dither1[col_index]]);
|
||||
pixcode += GETJSAMPLE(colorindex2[GETJSAMPLE(*input_ptr++) +
|
||||
dither2[col_index]]);
|
||||
dither2[col_index]]);
|
||||
*output_ptr++ = (JSAMPLE) pixcode;
|
||||
col_index = (col_index + 1) & ODITHER_MASK;
|
||||
}
|
||||
@ -608,7 +609,7 @@ quantize3_ord_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
|
||||
|
||||
METHODDEF(void)
|
||||
quantize_fs_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
|
||||
JSAMPARRAY output_buf, int num_rows)
|
||||
JSAMPARRAY output_buf, int num_rows)
|
||||
/* General case, with Floyd-Steinberg dithering */
|
||||
{
|
||||
my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
|
||||
@ -635,23 +636,23 @@ quantize_fs_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
|
||||
|
||||
for (row = 0; row < num_rows; row++) {
|
||||
/* Initialize output values to 0 so can process components separately */
|
||||
jzero_far((void FAR *) output_buf[row],
|
||||
(size_t) (width * SIZEOF(JSAMPLE)));
|
||||
FMEMZERO((void FAR *) output_buf[row],
|
||||
(size_t) (width * SIZEOF(JSAMPLE)));
|
||||
for (ci = 0; ci < nc; ci++) {
|
||||
input_ptr = input_buf[row] + ci;
|
||||
output_ptr = output_buf[row];
|
||||
if (cquantize->on_odd_row) {
|
||||
/* work right to left in this row */
|
||||
input_ptr += (width-1) * nc; /* so point to rightmost pixel */
|
||||
output_ptr += width-1;
|
||||
dir = -1;
|
||||
dirnc = -nc;
|
||||
errorptr = cquantize->fserrors[ci] + (width+1); /* => entry after last column */
|
||||
/* work right to left in this row */
|
||||
input_ptr += (width-1) * nc; /* so point to rightmost pixel */
|
||||
output_ptr += width-1;
|
||||
dir = -1;
|
||||
dirnc = -nc;
|
||||
errorptr = cquantize->fserrors[ci] + (width+1); /* => entry after last column */
|
||||
} else {
|
||||
/* work left to right in this row */
|
||||
dir = 1;
|
||||
dirnc = nc;
|
||||
errorptr = cquantize->fserrors[ci]; /* => entry before first column */
|
||||
/* work left to right in this row */
|
||||
dir = 1;
|
||||
dirnc = nc;
|
||||
errorptr = cquantize->fserrors[ci]; /* => entry before first column */
|
||||
}
|
||||
colorindex_ci = cquantize->colorindex[ci];
|
||||
colormap_ci = cquantize->sv_colormap[ci];
|
||||
@ -661,47 +662,47 @@ quantize_fs_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
|
||||
belowerr = bpreverr = 0;
|
||||
|
||||
for (col = width; col > 0; col--) {
|
||||
/* cur holds the error propagated from the previous pixel on the
|
||||
* current line. Add the error propagated from the previous line
|
||||
* to form the complete error correction term for this pixel, and
|
||||
* round the error term (which is expressed * 16) to an integer.
|
||||
* RIGHT_SHIFT rounds towards minus infinity, so adding 8 is correct
|
||||
* for either sign of the error value.
|
||||
* Note: errorptr points to *previous* column's array entry.
|
||||
*/
|
||||
cur = RIGHT_SHIFT(cur + errorptr[dir] + 8, 4);
|
||||
/* Form pixel value + error, and range-limit to 0..MAXJSAMPLE.
|
||||
* The maximum error is +- MAXJSAMPLE; this sets the required size
|
||||
* of the range_limit array.
|
||||
*/
|
||||
cur += GETJSAMPLE(*input_ptr);
|
||||
cur = GETJSAMPLE(range_limit[cur]);
|
||||
/* Select output value, accumulate into output code for this pixel */
|
||||
pixcode = GETJSAMPLE(colorindex_ci[cur]);
|
||||
*output_ptr += (JSAMPLE) pixcode;
|
||||
/* Compute actual representation error at this pixel */
|
||||
/* Note: we can do this even though we don't have the final */
|
||||
/* pixel code, because the colormap is orthogonal. */
|
||||
cur -= GETJSAMPLE(colormap_ci[pixcode]);
|
||||
/* Compute error fractions to be propagated to adjacent pixels.
|
||||
* Add these into the running sums, and simultaneously shift the
|
||||
* next-line error sums left by 1 column.
|
||||
*/
|
||||
bnexterr = cur;
|
||||
delta = cur * 2;
|
||||
cur += delta; /* form error * 3 */
|
||||
errorptr[0] = (FSERROR) (bpreverr + cur);
|
||||
cur += delta; /* form error * 5 */
|
||||
bpreverr = belowerr + cur;
|
||||
belowerr = bnexterr;
|
||||
cur += delta; /* form error * 7 */
|
||||
/* At this point cur contains the 7/16 error value to be propagated
|
||||
* to the next pixel on the current line, and all the errors for the
|
||||
* next line have been shifted over. We are therefore ready to move on.
|
||||
*/
|
||||
input_ptr += dirnc; /* advance input ptr to next column */
|
||||
output_ptr += dir; /* advance output ptr to next column */
|
||||
errorptr += dir; /* advance errorptr to current column */
|
||||
/* cur holds the error propagated from the previous pixel on the
|
||||
* current line. Add the error propagated from the previous line
|
||||
* to form the complete error correction term for this pixel, and
|
||||
* round the error term (which is expressed * 16) to an integer.
|
||||
* RIGHT_SHIFT rounds towards minus infinity, so adding 8 is correct
|
||||
* for either sign of the error value.
|
||||
* Note: errorptr points to *previous* column's array entry.
|
||||
*/
|
||||
cur = RIGHT_SHIFT(cur + errorptr[dir] + 8, 4);
|
||||
/* Form pixel value + error, and range-limit to 0..MAXJSAMPLE.
|
||||
* The maximum error is +- MAXJSAMPLE; this sets the required size
|
||||
* of the range_limit array.
|
||||
*/
|
||||
cur += GETJSAMPLE(*input_ptr);
|
||||
cur = GETJSAMPLE(range_limit[cur]);
|
||||
/* Select output value, accumulate into output code for this pixel */
|
||||
pixcode = GETJSAMPLE(colorindex_ci[cur]);
|
||||
*output_ptr += (JSAMPLE) pixcode;
|
||||
/* Compute actual representation error at this pixel */
|
||||
/* Note: we can do this even though we don't have the final */
|
||||
/* pixel code, because the colormap is orthogonal. */
|
||||
cur -= GETJSAMPLE(colormap_ci[pixcode]);
|
||||
/* Compute error fractions to be propagated to adjacent pixels.
|
||||
* Add these into the running sums, and simultaneously shift the
|
||||
* next-line error sums left by 1 column.
|
||||
*/
|
||||
bnexterr = cur;
|
||||
delta = cur * 2;
|
||||
cur += delta; /* form error * 3 */
|
||||
errorptr[0] = (FSERROR) (bpreverr + cur);
|
||||
cur += delta; /* form error * 5 */
|
||||
bpreverr = belowerr + cur;
|
||||
belowerr = bnexterr;
|
||||
cur += delta; /* form error * 7 */
|
||||
/* At this point cur contains the 7/16 error value to be propagated
|
||||
* to the next pixel on the current line, and all the errors for the
|
||||
* next line have been shifted over. We are therefore ready to move on.
|
||||
*/
|
||||
input_ptr += dirnc; /* advance input ptr to next column */
|
||||
output_ptr += dir; /* advance output ptr to next column */
|
||||
errorptr += dir; /* advance errorptr to current column */
|
||||
}
|
||||
/* Post-loop cleanup: we must unload the final error value into the
|
||||
* final fserrors[] entry. Note we need not unload belowerr because
|
||||
@ -781,7 +782,7 @@ start_pass_1_quant (j_decompress_ptr cinfo, boolean is_pre_scan)
|
||||
/* Initialize the propagated errors to zero. */
|
||||
arraysize = (size_t) ((cinfo->output_width + 2) * SIZEOF(FSERROR));
|
||||
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;
|
||||
default:
|
||||
ERREXIT(cinfo, JERR_NOT_COMPILED);
|
||||
@ -824,7 +825,7 @@ jinit_1pass_quantizer (j_decompress_ptr cinfo)
|
||||
|
||||
cquantize = (my_cquantize_ptr)
|
||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
||||
SIZEOF(my_cquantizer));
|
||||
SIZEOF(my_cquantizer));
|
||||
cinfo->cquantize = (struct jpeg_color_quantizer *) cquantize;
|
||||
cquantize->pub.start_pass = start_pass_1_quant;
|
||||
cquantize->pub.finish_pass = finish_pass_1_quant;
|
||||
|
243
3rdparty/libjpeg/jquant2.c
vendored
243
3rdparty/libjpeg/jquant2.c
vendored
@ -2,6 +2,7 @@
|
||||
* jquant2.c
|
||||
*
|
||||
* Copyright (C) 1991-1996, Thomas G. Lane.
|
||||
* Modified 2011 by Guido Vollbeding.
|
||||
* This file is part of the Independent JPEG Group's software.
|
||||
* For conditions of distribution and use, see the accompanying README file.
|
||||
*
|
||||
@ -222,7 +223,7 @@ typedef my_cquantizer * my_cquantize_ptr;
|
||||
|
||||
METHODDEF(void)
|
||||
prescan_quantize (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
|
||||
JSAMPARRAY output_buf, int num_rows)
|
||||
JSAMPARRAY output_buf, int num_rows)
|
||||
{
|
||||
my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
|
||||
register JSAMPROW ptr;
|
||||
@ -237,11 +238,11 @@ prescan_quantize (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
|
||||
for (col = width; col > 0; col--) {
|
||||
/* get pixel value and index into the histogram */
|
||||
histp = & histogram[GETJSAMPLE(ptr[0]) >> C0_SHIFT]
|
||||
[GETJSAMPLE(ptr[1]) >> C1_SHIFT]
|
||||
[GETJSAMPLE(ptr[2]) >> C2_SHIFT];
|
||||
[GETJSAMPLE(ptr[1]) >> C1_SHIFT]
|
||||
[GETJSAMPLE(ptr[2]) >> C2_SHIFT];
|
||||
/* increment, check for overflow and undo increment if so. */
|
||||
if (++(*histp) <= 0)
|
||||
(*histp)--;
|
||||
(*histp)--;
|
||||
ptr += 3;
|
||||
}
|
||||
}
|
||||
@ -329,67 +330,67 @@ update_box (j_decompress_ptr cinfo, boxptr boxp)
|
||||
if (c0max > c0min)
|
||||
for (c0 = c0min; c0 <= c0max; c0++)
|
||||
for (c1 = c1min; c1 <= c1max; c1++) {
|
||||
histp = & histogram[c0][c1][c2min];
|
||||
for (c2 = c2min; c2 <= c2max; c2++)
|
||||
if (*histp++ != 0) {
|
||||
boxp->c0min = c0min = c0;
|
||||
goto have_c0min;
|
||||
}
|
||||
histp = & histogram[c0][c1][c2min];
|
||||
for (c2 = c2min; c2 <= c2max; c2++)
|
||||
if (*histp++ != 0) {
|
||||
boxp->c0min = c0min = c0;
|
||||
goto have_c0min;
|
||||
}
|
||||
}
|
||||
have_c0min:
|
||||
if (c0max > c0min)
|
||||
for (c0 = c0max; c0 >= c0min; c0--)
|
||||
for (c1 = c1min; c1 <= c1max; c1++) {
|
||||
histp = & histogram[c0][c1][c2min];
|
||||
for (c2 = c2min; c2 <= c2max; c2++)
|
||||
if (*histp++ != 0) {
|
||||
boxp->c0max = c0max = c0;
|
||||
goto have_c0max;
|
||||
}
|
||||
histp = & histogram[c0][c1][c2min];
|
||||
for (c2 = c2min; c2 <= c2max; c2++)
|
||||
if (*histp++ != 0) {
|
||||
boxp->c0max = c0max = c0;
|
||||
goto have_c0max;
|
||||
}
|
||||
}
|
||||
have_c0max:
|
||||
if (c1max > c1min)
|
||||
for (c1 = c1min; c1 <= c1max; c1++)
|
||||
for (c0 = c0min; c0 <= c0max; c0++) {
|
||||
histp = & histogram[c0][c1][c2min];
|
||||
for (c2 = c2min; c2 <= c2max; c2++)
|
||||
if (*histp++ != 0) {
|
||||
boxp->c1min = c1min = c1;
|
||||
goto have_c1min;
|
||||
}
|
||||
histp = & histogram[c0][c1][c2min];
|
||||
for (c2 = c2min; c2 <= c2max; c2++)
|
||||
if (*histp++ != 0) {
|
||||
boxp->c1min = c1min = c1;
|
||||
goto have_c1min;
|
||||
}
|
||||
}
|
||||
have_c1min:
|
||||
if (c1max > c1min)
|
||||
for (c1 = c1max; c1 >= c1min; c1--)
|
||||
for (c0 = c0min; c0 <= c0max; c0++) {
|
||||
histp = & histogram[c0][c1][c2min];
|
||||
for (c2 = c2min; c2 <= c2max; c2++)
|
||||
if (*histp++ != 0) {
|
||||
boxp->c1max = c1max = c1;
|
||||
goto have_c1max;
|
||||
}
|
||||
histp = & histogram[c0][c1][c2min];
|
||||
for (c2 = c2min; c2 <= c2max; c2++)
|
||||
if (*histp++ != 0) {
|
||||
boxp->c1max = c1max = c1;
|
||||
goto have_c1max;
|
||||
}
|
||||
}
|
||||
have_c1max:
|
||||
if (c2max > c2min)
|
||||
for (c2 = c2min; c2 <= c2max; c2++)
|
||||
for (c0 = c0min; c0 <= c0max; c0++) {
|
||||
histp = & histogram[c0][c1min][c2];
|
||||
for (c1 = c1min; c1 <= c1max; c1++, histp += HIST_C2_ELEMS)
|
||||
if (*histp != 0) {
|
||||
boxp->c2min = c2min = c2;
|
||||
goto have_c2min;
|
||||
}
|
||||
histp = & histogram[c0][c1min][c2];
|
||||
for (c1 = c1min; c1 <= c1max; c1++, histp += HIST_C2_ELEMS)
|
||||
if (*histp != 0) {
|
||||
boxp->c2min = c2min = c2;
|
||||
goto have_c2min;
|
||||
}
|
||||
}
|
||||
have_c2min:
|
||||
if (c2max > c2min)
|
||||
for (c2 = c2max; c2 >= c2min; c2--)
|
||||
for (c0 = c0min; c0 <= c0max; c0++) {
|
||||
histp = & histogram[c0][c1min][c2];
|
||||
for (c1 = c1min; c1 <= c1max; c1++, histp += HIST_C2_ELEMS)
|
||||
if (*histp != 0) {
|
||||
boxp->c2max = c2max = c2;
|
||||
goto have_c2max;
|
||||
}
|
||||
histp = & histogram[c0][c1min][c2];
|
||||
for (c1 = c1min; c1 <= c1max; c1++, histp += HIST_C2_ELEMS)
|
||||
if (*histp != 0) {
|
||||
boxp->c2max = c2max = c2;
|
||||
goto have_c2max;
|
||||
}
|
||||
}
|
||||
have_c2max:
|
||||
|
||||
@ -412,9 +413,9 @@ update_box (j_decompress_ptr cinfo, boxptr boxp)
|
||||
for (c1 = c1min; c1 <= c1max; c1++) {
|
||||
histp = & histogram[c0][c1][c2min];
|
||||
for (c2 = c2min; c2 <= c2max; c2++, histp++)
|
||||
if (*histp != 0) {
|
||||
ccount++;
|
||||
}
|
||||
if (*histp != 0) {
|
||||
ccount++;
|
||||
}
|
||||
}
|
||||
boxp->colorcount = ccount;
|
||||
}
|
||||
@ -422,7 +423,7 @@ update_box (j_decompress_ptr cinfo, boxptr boxp)
|
||||
|
||||
LOCAL(int)
|
||||
median_cut (j_decompress_ptr cinfo, boxptr boxlist, int numboxes,
|
||||
int desired_colors)
|
||||
int desired_colors)
|
||||
/* Repeatedly select and split the largest box until we have enough boxes */
|
||||
{
|
||||
int n,lb;
|
||||
@ -520,12 +521,12 @@ compute_color (j_decompress_ptr cinfo, boxptr boxp, int icolor)
|
||||
for (c1 = c1min; c1 <= c1max; c1++) {
|
||||
histp = & histogram[c0][c1][c2min];
|
||||
for (c2 = c2min; c2 <= c2max; c2++) {
|
||||
if ((count = *histp++) != 0) {
|
||||
total += count;
|
||||
c0total += ((c0 << C0_SHIFT) + ((1<<C0_SHIFT)>>1)) * count;
|
||||
c1total += ((c1 << C1_SHIFT) + ((1<<C1_SHIFT)>>1)) * count;
|
||||
c2total += ((c2 << C2_SHIFT) + ((1<<C2_SHIFT)>>1)) * count;
|
||||
}
|
||||
if ((count = *histp++) != 0) {
|
||||
total += count;
|
||||
c0total += ((c0 << C0_SHIFT) + ((1<<C0_SHIFT)>>1)) * count;
|
||||
c1total += ((c1 << C1_SHIFT) + ((1<<C1_SHIFT)>>1)) * count;
|
||||
c2total += ((c2 << C2_SHIFT) + ((1<<C2_SHIFT)>>1)) * count;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -644,7 +645,7 @@ select_colors (j_decompress_ptr cinfo, int desired_colors)
|
||||
|
||||
LOCAL(int)
|
||||
find_nearby_colors (j_decompress_ptr cinfo, int minc0, int minc1, int minc2,
|
||||
JSAMPLE colorlist[])
|
||||
JSAMPLE colorlist[])
|
||||
/* Locate the colormap entries close enough to an update box to be candidates
|
||||
* for the nearest entry to some cell(s) in the update box. The update box
|
||||
* is specified by the center coordinates of its first cell. The number of
|
||||
@ -701,11 +702,11 @@ find_nearby_colors (j_decompress_ptr cinfo, int minc0, int minc1, int minc2,
|
||||
/* within cell range so no contribution to min_dist */
|
||||
min_dist = 0;
|
||||
if (x <= centerc0) {
|
||||
tdist = (x - maxc0) * C0_SCALE;
|
||||
max_dist = tdist*tdist;
|
||||
tdist = (x - maxc0) * C0_SCALE;
|
||||
max_dist = tdist*tdist;
|
||||
} else {
|
||||
tdist = (x - minc0) * C0_SCALE;
|
||||
max_dist = tdist*tdist;
|
||||
tdist = (x - minc0) * C0_SCALE;
|
||||
max_dist = tdist*tdist;
|
||||
}
|
||||
}
|
||||
|
||||
@ -723,11 +724,11 @@ find_nearby_colors (j_decompress_ptr cinfo, int minc0, int minc1, int minc2,
|
||||
} else {
|
||||
/* within cell range so no contribution to min_dist */
|
||||
if (x <= centerc1) {
|
||||
tdist = (x - maxc1) * C1_SCALE;
|
||||
max_dist += tdist*tdist;
|
||||
tdist = (x - maxc1) * C1_SCALE;
|
||||
max_dist += tdist*tdist;
|
||||
} else {
|
||||
tdist = (x - minc1) * C1_SCALE;
|
||||
max_dist += tdist*tdist;
|
||||
tdist = (x - minc1) * C1_SCALE;
|
||||
max_dist += tdist*tdist;
|
||||
}
|
||||
}
|
||||
|
||||
@ -745,11 +746,11 @@ find_nearby_colors (j_decompress_ptr cinfo, int minc0, int minc1, int minc2,
|
||||
} else {
|
||||
/* within cell range so no contribution to min_dist */
|
||||
if (x <= centerc2) {
|
||||
tdist = (x - maxc2) * C2_SCALE;
|
||||
max_dist += tdist*tdist;
|
||||
tdist = (x - maxc2) * C2_SCALE;
|
||||
max_dist += tdist*tdist;
|
||||
} else {
|
||||
tdist = (x - minc2) * C2_SCALE;
|
||||
max_dist += tdist*tdist;
|
||||
tdist = (x - minc2) * C2_SCALE;
|
||||
max_dist += tdist*tdist;
|
||||
}
|
||||
}
|
||||
|
||||
@ -773,7 +774,7 @@ find_nearby_colors (j_decompress_ptr cinfo, int minc0, int minc1, int minc2,
|
||||
|
||||
LOCAL(void)
|
||||
find_best_colors (j_decompress_ptr cinfo, int minc0, int minc1, int minc2,
|
||||
int numcolors, JSAMPLE colorlist[], JSAMPLE bestcolor[])
|
||||
int numcolors, JSAMPLE colorlist[], JSAMPLE bestcolor[])
|
||||
/* Find the closest colormap entry for each cell in the update box,
|
||||
* given the list of candidate colors prepared by find_nearby_colors.
|
||||
* Return the indexes of the closest entries in the bestcolor[] array.
|
||||
@ -829,20 +830,20 @@ find_best_colors (j_decompress_ptr cinfo, int minc0, int minc1, int minc2,
|
||||
dist1 = dist0;
|
||||
xx1 = inc1;
|
||||
for (ic1 = BOX_C1_ELEMS-1; ic1 >= 0; ic1--) {
|
||||
dist2 = dist1;
|
||||
xx2 = inc2;
|
||||
for (ic2 = BOX_C2_ELEMS-1; ic2 >= 0; ic2--) {
|
||||
if (dist2 < *bptr) {
|
||||
*bptr = dist2;
|
||||
*cptr = (JSAMPLE) icolor;
|
||||
}
|
||||
dist2 += xx2;
|
||||
xx2 += 2 * STEP_C2 * STEP_C2;
|
||||
bptr++;
|
||||
cptr++;
|
||||
}
|
||||
dist1 += xx1;
|
||||
xx1 += 2 * STEP_C1 * STEP_C1;
|
||||
dist2 = dist1;
|
||||
xx2 = inc2;
|
||||
for (ic2 = BOX_C2_ELEMS-1; ic2 >= 0; ic2--) {
|
||||
if (dist2 < *bptr) {
|
||||
*bptr = dist2;
|
||||
*cptr = (JSAMPLE) icolor;
|
||||
}
|
||||
dist2 += xx2;
|
||||
xx2 += 2 * STEP_C2 * STEP_C2;
|
||||
bptr++;
|
||||
cptr++;
|
||||
}
|
||||
dist1 += xx1;
|
||||
xx1 += 2 * STEP_C1 * STEP_C1;
|
||||
}
|
||||
dist0 += xx0;
|
||||
xx0 += 2 * STEP_C0 * STEP_C0;
|
||||
@ -889,7 +890,7 @@ fill_inverse_cmap (j_decompress_ptr cinfo, int c0, int c1, int c2)
|
||||
|
||||
/* Determine the actually nearest colors. */
|
||||
find_best_colors(cinfo, minc0, minc1, minc2, numcolors, colorlist,
|
||||
bestcolor);
|
||||
bestcolor);
|
||||
|
||||
/* Save the best color numbers (plus 1) in the main cache array */
|
||||
c0 <<= BOX_C0_LOG; /* convert ID back to base cell indexes */
|
||||
@ -900,7 +901,7 @@ fill_inverse_cmap (j_decompress_ptr cinfo, int c0, int c1, int c2)
|
||||
for (ic1 = 0; ic1 < BOX_C1_ELEMS; ic1++) {
|
||||
cachep = & histogram[c0+ic0][c1+ic1][c2];
|
||||
for (ic2 = 0; ic2 < BOX_C2_ELEMS; ic2++) {
|
||||
*cachep++ = (histcell) (GETJSAMPLE(*cptr++) + 1);
|
||||
*cachep++ = (histcell) (GETJSAMPLE(*cptr++) + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -913,7 +914,7 @@ fill_inverse_cmap (j_decompress_ptr cinfo, int c0, int c1, int c2)
|
||||
|
||||
METHODDEF(void)
|
||||
pass2_no_dither (j_decompress_ptr cinfo,
|
||||
JSAMPARRAY input_buf, JSAMPARRAY output_buf, int num_rows)
|
||||
JSAMPARRAY input_buf, JSAMPARRAY output_buf, int num_rows)
|
||||
/* This version performs no dithering */
|
||||
{
|
||||
my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
|
||||
@ -937,7 +938,7 @@ pass2_no_dither (j_decompress_ptr cinfo,
|
||||
/* If we have not seen this color before, find nearest colormap entry */
|
||||
/* and update the cache */
|
||||
if (*cachep == 0)
|
||||
fill_inverse_cmap(cinfo, c0,c1,c2);
|
||||
fill_inverse_cmap(cinfo, c0,c1,c2);
|
||||
/* Now emit the colormap index for this cell */
|
||||
*outptr++ = (JSAMPLE) (*cachep - 1);
|
||||
}
|
||||
@ -947,7 +948,7 @@ pass2_no_dither (j_decompress_ptr cinfo,
|
||||
|
||||
METHODDEF(void)
|
||||
pass2_fs_dither (j_decompress_ptr cinfo,
|
||||
JSAMPARRAY input_buf, JSAMPARRAY output_buf, int num_rows)
|
||||
JSAMPARRAY input_buf, JSAMPARRAY output_buf, int num_rows)
|
||||
/* This version performs Floyd-Steinberg dithering */
|
||||
{
|
||||
my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
|
||||
@ -1028,14 +1029,14 @@ pass2_fs_dither (j_decompress_ptr cinfo,
|
||||
/* If we have not seen this color before, find nearest colormap */
|
||||
/* entry and update the cache */
|
||||
if (*cachep == 0)
|
||||
fill_inverse_cmap(cinfo, cur0>>C0_SHIFT,cur1>>C1_SHIFT,cur2>>C2_SHIFT);
|
||||
fill_inverse_cmap(cinfo, cur0>>C0_SHIFT,cur1>>C1_SHIFT,cur2>>C2_SHIFT);
|
||||
/* Now emit the colormap index for this cell */
|
||||
{ register int pixcode = *cachep - 1;
|
||||
*outptr = (JSAMPLE) pixcode;
|
||||
/* Compute representation error for this pixel */
|
||||
cur0 -= GETJSAMPLE(colormap0[pixcode]);
|
||||
cur1 -= GETJSAMPLE(colormap1[pixcode]);
|
||||
cur2 -= GETJSAMPLE(colormap2[pixcode]);
|
||||
*outptr = (JSAMPLE) pixcode;
|
||||
/* Compute representation error for this pixel */
|
||||
cur0 -= GETJSAMPLE(colormap0[pixcode]);
|
||||
cur1 -= GETJSAMPLE(colormap1[pixcode]);
|
||||
cur2 -= GETJSAMPLE(colormap2[pixcode]);
|
||||
}
|
||||
/* Compute error fractions to be propagated to adjacent pixels.
|
||||
* Add these into the running sums, and simultaneously shift the
|
||||
@ -1043,30 +1044,30 @@ pass2_fs_dither (j_decompress_ptr cinfo,
|
||||
*/
|
||||
{ register LOCFSERROR bnexterr, delta;
|
||||
|
||||
bnexterr = cur0; /* Process component 0 */
|
||||
delta = cur0 * 2;
|
||||
cur0 += delta; /* form error * 3 */
|
||||
errorptr[0] = (FSERROR) (bpreverr0 + cur0);
|
||||
cur0 += delta; /* form error * 5 */
|
||||
bpreverr0 = belowerr0 + cur0;
|
||||
belowerr0 = bnexterr;
|
||||
cur0 += delta; /* form error * 7 */
|
||||
bnexterr = cur1; /* Process component 1 */
|
||||
delta = cur1 * 2;
|
||||
cur1 += delta; /* form error * 3 */
|
||||
errorptr[1] = (FSERROR) (bpreverr1 + cur1);
|
||||
cur1 += delta; /* form error * 5 */
|
||||
bpreverr1 = belowerr1 + cur1;
|
||||
belowerr1 = bnexterr;
|
||||
cur1 += delta; /* form error * 7 */
|
||||
bnexterr = cur2; /* Process component 2 */
|
||||
delta = cur2 * 2;
|
||||
cur2 += delta; /* form error * 3 */
|
||||
errorptr[2] = (FSERROR) (bpreverr2 + cur2);
|
||||
cur2 += delta; /* form error * 5 */
|
||||
bpreverr2 = belowerr2 + cur2;
|
||||
belowerr2 = bnexterr;
|
||||
cur2 += delta; /* form error * 7 */
|
||||
bnexterr = cur0; /* Process component 0 */
|
||||
delta = cur0 * 2;
|
||||
cur0 += delta; /* form error * 3 */
|
||||
errorptr[0] = (FSERROR) (bpreverr0 + cur0);
|
||||
cur0 += delta; /* form error * 5 */
|
||||
bpreverr0 = belowerr0 + cur0;
|
||||
belowerr0 = bnexterr;
|
||||
cur0 += delta; /* form error * 7 */
|
||||
bnexterr = cur1; /* Process component 1 */
|
||||
delta = cur1 * 2;
|
||||
cur1 += delta; /* form error * 3 */
|
||||
errorptr[1] = (FSERROR) (bpreverr1 + cur1);
|
||||
cur1 += delta; /* form error * 5 */
|
||||
bpreverr1 = belowerr1 + cur1;
|
||||
belowerr1 = bnexterr;
|
||||
cur1 += delta; /* form error * 7 */
|
||||
bnexterr = cur2; /* Process component 2 */
|
||||
delta = cur2 * 2;
|
||||
cur2 += delta; /* form error * 3 */
|
||||
errorptr[2] = (FSERROR) (bpreverr2 + cur2);
|
||||
cur2 += delta; /* form error * 5 */
|
||||
bpreverr2 = belowerr2 + cur2;
|
||||
belowerr2 = bnexterr;
|
||||
cur2 += delta; /* form error * 7 */
|
||||
}
|
||||
/* At this point curN contains the 7/16 error value to be propagated
|
||||
* to the next pixel on the current line, and all the errors for the
|
||||
@ -1197,16 +1198,16 @@ start_pass_2_quant (j_decompress_ptr cinfo, boolean is_pre_scan)
|
||||
|
||||
if (cinfo->dither_mode == JDITHER_FS) {
|
||||
size_t arraysize = (size_t) ((cinfo->output_width + 2) *
|
||||
(3 * SIZEOF(FSERROR)));
|
||||
(3 * SIZEOF(FSERROR)));
|
||||
/* Allocate Floyd-Steinberg workspace if we didn't already. */
|
||||
if (cquantize->fserrors == NULL)
|
||||
cquantize->fserrors = (FSERRPTR) (*cinfo->mem->alloc_large)
|
||||
((j_common_ptr) cinfo, JPOOL_IMAGE, arraysize);
|
||||
cquantize->fserrors = (FSERRPTR) (*cinfo->mem->alloc_large)
|
||||
((j_common_ptr) cinfo, JPOOL_IMAGE, arraysize);
|
||||
/* 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. */
|
||||
if (cquantize->error_limiter == NULL)
|
||||
init_error_limit(cinfo);
|
||||
init_error_limit(cinfo);
|
||||
cquantize->on_odd_row = FALSE;
|
||||
}
|
||||
|
||||
@ -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 */
|
||||
if (cquantize->needs_zeroed) {
|
||||
for (i = 0; i < HIST_C0_ELEMS; i++) {
|
||||
jzero_far((void FAR *) histogram[i],
|
||||
HIST_C1_ELEMS*HIST_C2_ELEMS * SIZEOF(histcell));
|
||||
FMEMZERO((void FAR *) histogram[i],
|
||||
HIST_C1_ELEMS*HIST_C2_ELEMS * SIZEOF(histcell));
|
||||
}
|
||||
cquantize->needs_zeroed = FALSE;
|
||||
}
|
||||
@ -1248,7 +1249,7 @@ jinit_2pass_quantizer (j_decompress_ptr cinfo)
|
||||
|
||||
cquantize = (my_cquantize_ptr)
|
||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
||||
SIZEOF(my_cquantizer));
|
||||
SIZEOF(my_cquantizer));
|
||||
cinfo->cquantize = (struct jpeg_color_quantizer *) cquantize;
|
||||
cquantize->pub.start_pass = start_pass_2_quant;
|
||||
cquantize->pub.new_color_map = new_color_map_2_quant;
|
||||
|
96
3rdparty/libjpeg/jutils.c
vendored
96
3rdparty/libjpeg/jutils.c
vendored
@ -2,6 +2,7 @@
|
||||
* jutils.c
|
||||
*
|
||||
* Copyright (C) 1991-1996, Thomas G. Lane.
|
||||
* Modified 2009-2011 by Guido Vollbeding.
|
||||
* This file is part of the Independent JPEG Group's software.
|
||||
* For conditions of distribution and use, see the accompanying README file.
|
||||
*
|
||||
@ -63,6 +64,57 @@ const int jpeg_natural_order[DCTSIZE2+16] = {
|
||||
63, 63, 63, 63, 63, 63, 63, 63
|
||||
};
|
||||
|
||||
const int jpeg_natural_order7[7*7+16] = {
|
||||
0, 1, 8, 16, 9, 2, 3, 10,
|
||||
17, 24, 32, 25, 18, 11, 4, 5,
|
||||
12, 19, 26, 33, 40, 48, 41, 34,
|
||||
27, 20, 13, 6, 14, 21, 28, 35,
|
||||
42, 49, 50, 43, 36, 29, 22, 30,
|
||||
37, 44, 51, 52, 45, 38, 46, 53,
|
||||
54,
|
||||
63, 63, 63, 63, 63, 63, 63, 63, /* extra entries for safety in decoder */
|
||||
63, 63, 63, 63, 63, 63, 63, 63
|
||||
};
|
||||
|
||||
const int jpeg_natural_order6[6*6+16] = {
|
||||
0, 1, 8, 16, 9, 2, 3, 10,
|
||||
17, 24, 32, 25, 18, 11, 4, 5,
|
||||
12, 19, 26, 33, 40, 41, 34, 27,
|
||||
20, 13, 21, 28, 35, 42, 43, 36,
|
||||
29, 37, 44, 45,
|
||||
63, 63, 63, 63, 63, 63, 63, 63, /* extra entries for safety in decoder */
|
||||
63, 63, 63, 63, 63, 63, 63, 63
|
||||
};
|
||||
|
||||
const int jpeg_natural_order5[5*5+16] = {
|
||||
0, 1, 8, 16, 9, 2, 3, 10,
|
||||
17, 24, 32, 25, 18, 11, 4, 12,
|
||||
19, 26, 33, 34, 27, 20, 28, 35,
|
||||
36,
|
||||
63, 63, 63, 63, 63, 63, 63, 63, /* extra entries for safety in decoder */
|
||||
63, 63, 63, 63, 63, 63, 63, 63
|
||||
};
|
||||
|
||||
const int jpeg_natural_order4[4*4+16] = {
|
||||
0, 1, 8, 16, 9, 2, 3, 10,
|
||||
17, 24, 25, 18, 11, 19, 26, 27,
|
||||
63, 63, 63, 63, 63, 63, 63, 63, /* extra entries for safety in decoder */
|
||||
63, 63, 63, 63, 63, 63, 63, 63
|
||||
};
|
||||
|
||||
const int jpeg_natural_order3[3*3+16] = {
|
||||
0, 1, 8, 16, 9, 2, 10, 17,
|
||||
18,
|
||||
63, 63, 63, 63, 63, 63, 63, 63, /* extra entries for safety in decoder */
|
||||
63, 63, 63, 63, 63, 63, 63, 63
|
||||
};
|
||||
|
||||
const int jpeg_natural_order2[2*2+16] = {
|
||||
0, 1, 8, 9,
|
||||
63, 63, 63, 63, 63, 63, 63, 63, /* extra entries for safety in decoder */
|
||||
63, 63, 63, 63, 63, 63, 63, 63
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* Arithmetic utilities
|
||||
@ -96,21 +148,35 @@ jround_up (long a, long b)
|
||||
* 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 FMEMZERO(target,size) MEMZERO(target,size)
|
||||
#else /* 80x86 case, define if we can */
|
||||
#ifdef USE_FMEM
|
||||
#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
|
||||
|
||||
|
||||
GLOBAL(void)
|
||||
jcopy_sample_rows (JSAMPARRAY input_array, int source_row,
|
||||
JSAMPARRAY output_array, int dest_row,
|
||||
int num_rows, JDIMENSION num_cols)
|
||||
JSAMPARRAY output_array, int dest_row,
|
||||
int num_rows, JDIMENSION num_cols)
|
||||
/* Copy some rows of samples from one place to another.
|
||||
* num_rows rows are copied from input_array[source_row++]
|
||||
* to output_array[dest_row++]; these areas may overlap for duplication.
|
||||
@ -143,7 +209,7 @@ jcopy_sample_rows (JSAMPARRAY input_array, int source_row,
|
||||
|
||||
GLOBAL(void)
|
||||
jcopy_block_row (JBLOCKROW input_row, JBLOCKROW output_row,
|
||||
JDIMENSION num_blocks)
|
||||
JDIMENSION num_blocks)
|
||||
/* Copy a row of coefficient blocks from one place to another. */
|
||||
{
|
||||
#ifdef FMEMCOPY
|
||||
@ -159,21 +225,3 @@ jcopy_block_row (JBLOCKROW input_row, JBLOCKROW output_row,
|
||||
}
|
||||
#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
|
||||
}
|
||||
|
6
3rdparty/libjpeg/jversion.h
vendored
6
3rdparty/libjpeg/jversion.h
vendored
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* jversion.h
|
||||
*
|
||||
* Copyright (C) 1991-1998, Thomas G. Lane.
|
||||
* Copyright (C) 1991-2013, Thomas G. Lane, Guido Vollbeding.
|
||||
* This file is part of the Independent JPEG Group's software.
|
||||
* For conditions of distribution and use, see the accompanying README file.
|
||||
*
|
||||
@ -9,6 +9,6 @@
|
||||
*/
|
||||
|
||||
|
||||
#define JVERSION "6b 27-Mar-1998"
|
||||
#define JVERSION "9 13-Jan-2013"
|
||||
|
||||
#define JCOPYRIGHT "Copyright (C) 1998, Thomas G. Lane"
|
||||
#define JCOPYRIGHT "Copyright (C) 2013, Thomas G. Lane, Guido Vollbeding"
|
||||
|
1533
3rdparty/libjpeg/transupp.c
vendored
1533
3rdparty/libjpeg/transupp.c
vendored
File diff suppressed because it is too large
Load Diff
205
3rdparty/libjpeg/transupp.h
vendored
205
3rdparty/libjpeg/transupp.h
vendored
@ -1,205 +0,0 @@
|
||||
/*
|
||||
* transupp.h
|
||||
*
|
||||
* Copyright (C) 1997-2001, Thomas G. Lane.
|
||||
* This file is part of the Independent JPEG Group's software.
|
||||
* For conditions of distribution and use, see the accompanying README file.
|
||||
*
|
||||
* This file contains declarations for image transformation routines and
|
||||
* other utility code used by the jpegtran sample application. These are
|
||||
* NOT part of the core JPEG library. But we keep these routines separate
|
||||
* from jpegtran.c to ease the task of maintaining jpegtran-like programs
|
||||
* that have other user interfaces.
|
||||
*
|
||||
* NOTE: all the routines declared here have very specific requirements
|
||||
* about when they are to be executed during the reading and writing of the
|
||||
* source and destination files. See the comments in transupp.c, or see
|
||||
* jpegtran.c for an example of correct usage.
|
||||
*/
|
||||
|
||||
/* If you happen not to want the image transform support, disable it here */
|
||||
#ifndef TRANSFORMS_SUPPORTED
|
||||
#define TRANSFORMS_SUPPORTED 1 /* 0 disables transform code */
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Although rotating and flipping data expressed as DCT coefficients is not
|
||||
* hard, there is an asymmetry in the JPEG format specification for images
|
||||
* whose dimensions aren't multiples of the iMCU size. The right and bottom
|
||||
* image edges are padded out to the next iMCU boundary with junk data; but
|
||||
* no padding is possible at the top and left edges. If we were to flip
|
||||
* the whole image including the pad data, then pad garbage would become
|
||||
* visible at the top and/or left, and real pixels would disappear into the
|
||||
* pad margins --- perhaps permanently, since encoders & decoders may not
|
||||
* bother to preserve DCT blocks that appear to be completely outside the
|
||||
* nominal image area. So, we have to exclude any partial iMCUs from the
|
||||
* basic transformation.
|
||||
*
|
||||
* Transpose is the only transformation that can handle partial iMCUs at the
|
||||
* right and bottom edges completely cleanly. flip_h can flip partial iMCUs
|
||||
* at the bottom, but leaves any partial iMCUs at the right edge untouched.
|
||||
* Similarly flip_v leaves any partial iMCUs at the bottom edge untouched.
|
||||
* The other transforms are defined as combinations of these basic transforms
|
||||
* and process edge blocks in a way that preserves the equivalence.
|
||||
*
|
||||
* The "trim" option causes untransformable partial iMCUs to be dropped;
|
||||
* this is not strictly lossless, but it usually gives the best-looking
|
||||
* result for odd-size images. Note that when this option is active,
|
||||
* the expected mathematical equivalences between the transforms may not hold.
|
||||
* (For example, -rot 270 -trim trims only the bottom edge, but -rot 90 -trim
|
||||
* followed by -rot 180 -trim trims both edges.)
|
||||
*
|
||||
* We also offer a lossless-crop option, which discards data outside a given
|
||||
* image region but losslessly preserves what is inside. Like the rotate and
|
||||
* flip transforms, lossless crop is restricted by the JPEG format: the upper
|
||||
* left corner of the selected region must fall on an iMCU boundary. If this
|
||||
* does not hold for the given crop parameters, we silently move the upper left
|
||||
* corner up and/or left to make it so, simultaneously increasing the region
|
||||
* dimensions to keep the lower right crop corner unchanged. (Thus, the
|
||||
* output image covers at least the requested region, but may cover more.)
|
||||
*
|
||||
* If both crop and a rotate/flip transform are requested, the crop is applied
|
||||
* last --- that is, the crop region is specified in terms of the destination
|
||||
* image.
|
||||
*
|
||||
* We also offer a "force to grayscale" option, which simply discards the
|
||||
* chrominance channels of a YCbCr image. This is lossless in the sense that
|
||||
* the luminance channel is preserved exactly. It's not the same kind of
|
||||
* thing as the rotate/flip transformations, but it's convenient to handle it
|
||||
* as part of this package, mainly because the transformation routines have to
|
||||
* be aware of the option to know how many components to work on.
|
||||
*/
|
||||
|
||||
|
||||
/* Short forms of external names for systems with brain-damaged linkers. */
|
||||
|
||||
#ifdef NEED_SHORT_EXTERNAL_NAMES
|
||||
#define jtransform_parse_crop_spec jTrParCrop
|
||||
#define jtransform_request_workspace jTrRequest
|
||||
#define jtransform_adjust_parameters jTrAdjust
|
||||
#define jtransform_execute_transform jTrExec
|
||||
#define jtransform_perfect_transform jTrPerfect
|
||||
#define jcopy_markers_setup jCMrkSetup
|
||||
#define jcopy_markers_execute jCMrkExec
|
||||
#endif /* NEED_SHORT_EXTERNAL_NAMES */
|
||||
|
||||
|
||||
/*
|
||||
* Codes for supported types of image transformations.
|
||||
*/
|
||||
|
||||
typedef enum {
|
||||
JXFORM_NONE, /* no transformation */
|
||||
JXFORM_FLIP_H, /* horizontal flip */
|
||||
JXFORM_FLIP_V, /* vertical flip */
|
||||
JXFORM_TRANSPOSE, /* transpose across UL-to-LR axis */
|
||||
JXFORM_TRANSVERSE, /* transpose across UR-to-LL axis */
|
||||
JXFORM_ROT_90, /* 90-degree clockwise rotation */
|
||||
JXFORM_ROT_180, /* 180-degree rotation */
|
||||
JXFORM_ROT_270 /* 270-degree clockwise (or 90 ccw) */
|
||||
} JXFORM_CODE;
|
||||
|
||||
/*
|
||||
* Codes for crop parameters, which can individually be unspecified,
|
||||
* positive, or negative. (Negative width or height makes no sense, though.)
|
||||
*/
|
||||
|
||||
typedef enum {
|
||||
JCROP_UNSET,
|
||||
JCROP_POS,
|
||||
JCROP_NEG
|
||||
} JCROP_CODE;
|
||||
|
||||
/*
|
||||
* Transform parameters struct.
|
||||
* NB: application must not change any elements of this struct after
|
||||
* calling jtransform_request_workspace.
|
||||
*/
|
||||
|
||||
typedef struct {
|
||||
/* Options: set by caller */
|
||||
JXFORM_CODE transform; /* image transform operator */
|
||||
boolean perfect; /* if TRUE, fail if partial MCUs are requested */
|
||||
boolean trim; /* if TRUE, trim partial MCUs as needed */
|
||||
boolean force_grayscale; /* if TRUE, convert color image to grayscale */
|
||||
boolean crop; /* if TRUE, crop source image */
|
||||
|
||||
/* Crop parameters: application need not set these unless crop is TRUE.
|
||||
* These can be filled in by jtransform_parse_crop_spec().
|
||||
*/
|
||||
JDIMENSION crop_width; /* Width of selected region */
|
||||
JCROP_CODE crop_width_set;
|
||||
JDIMENSION crop_height; /* Height of selected region */
|
||||
JCROP_CODE crop_height_set;
|
||||
JDIMENSION crop_xoffset; /* X offset of selected region */
|
||||
JCROP_CODE crop_xoffset_set; /* (negative measures from right edge) */
|
||||
JDIMENSION crop_yoffset; /* Y offset of selected region */
|
||||
JCROP_CODE crop_yoffset_set; /* (negative measures from bottom edge) */
|
||||
|
||||
/* Internal workspace: caller should not touch these */
|
||||
int num_components; /* # of components in workspace */
|
||||
jvirt_barray_ptr * workspace_coef_arrays; /* workspace for transformations */
|
||||
JDIMENSION output_width; /* cropped destination dimensions */
|
||||
JDIMENSION output_height;
|
||||
JDIMENSION x_crop_offset; /* destination crop offsets measured in iMCUs */
|
||||
JDIMENSION y_crop_offset;
|
||||
int max_h_samp_factor; /* destination iMCU size */
|
||||
int max_v_samp_factor;
|
||||
} jpeg_transform_info;
|
||||
|
||||
|
||||
#if TRANSFORMS_SUPPORTED
|
||||
|
||||
/* Parse a crop specification (written in X11 geometry style) */
|
||||
EXTERN(boolean) jtransform_parse_crop_spec
|
||||
JPP((jpeg_transform_info *info, const char *spec));
|
||||
/* Request any required workspace */
|
||||
EXTERN(void) jtransform_request_workspace
|
||||
JPP((j_decompress_ptr srcinfo, jpeg_transform_info *info));
|
||||
/* Adjust output image parameters */
|
||||
EXTERN(jvirt_barray_ptr *) jtransform_adjust_parameters
|
||||
JPP((j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
|
||||
jvirt_barray_ptr *src_coef_arrays,
|
||||
jpeg_transform_info *info));
|
||||
/* Execute the actual transformation, if any */
|
||||
EXTERN(void) jtransform_execute_transform
|
||||
JPP((j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
|
||||
jvirt_barray_ptr *src_coef_arrays,
|
||||
jpeg_transform_info *info));
|
||||
/* Determine whether lossless transformation is perfectly
|
||||
* possible for a specified image and transformation.
|
||||
*/
|
||||
EXTERN(boolean) jtransform_perfect_transform
|
||||
JPP((JDIMENSION image_width, JDIMENSION image_height,
|
||||
int MCU_width, int MCU_height,
|
||||
JXFORM_CODE transform));
|
||||
|
||||
/* jtransform_execute_transform used to be called
|
||||
* jtransform_execute_transformation, but some compilers complain about
|
||||
* routine names that long. This macro is here to avoid breaking any
|
||||
* old source code that uses the original name...
|
||||
*/
|
||||
#define jtransform_execute_transformation jtransform_execute_transform
|
||||
|
||||
#endif /* TRANSFORMS_SUPPORTED */
|
||||
|
||||
|
||||
/*
|
||||
* Support for copying optional markers from source to destination file.
|
||||
*/
|
||||
|
||||
typedef enum {
|
||||
JCOPYOPT_NONE, /* copy no optional markers */
|
||||
JCOPYOPT_COMMENTS, /* copy only comment (COM) markers */
|
||||
JCOPYOPT_ALL /* copy all optional markers */
|
||||
} JCOPY_OPTION;
|
||||
|
||||
#define JCOPYOPT_DEFAULT JCOPYOPT_COMMENTS /* recommended default */
|
||||
|
||||
/* Setup decompression object to save desired markers in memory */
|
||||
EXTERN(void) jcopy_markers_setup
|
||||
JPP((j_decompress_ptr srcinfo, JCOPY_OPTION option));
|
||||
/* Copy markers saved in the given source object to the destination object */
|
||||
EXTERN(void) jcopy_markers_execute
|
||||
JPP((j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
|
||||
JCOPY_OPTION option));
|
Loading…
Reference in New Issue
Block a user