mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-08 10:44:56 +00:00
Landing JPEG_BRANCH.
This commit is contained in:
parent
25e26733c3
commit
9eeabf7820
168
jpeg/README
168
jpeg/README
@ -1,8 +1,8 @@
|
||||
The Independent JPEG Group's JPEG software
|
||||
==========================================
|
||||
|
||||
README for release 6 of 2-Aug-95
|
||||
================================
|
||||
README for release 6b of 27-Mar-1998
|
||||
====================================
|
||||
|
||||
This distribution contains the sixth public release of the Independent JPEG
|
||||
Group's free JPEG software. You are welcome to redistribute this software and
|
||||
@ -13,9 +13,10 @@ larger programs) should contact IJG at jpeg-info@uunet.uu.net to be added to
|
||||
our electronic mailing list. Mailing list members are notified of updates
|
||||
and have a chance to participate in technical discussions, etc.
|
||||
|
||||
This software is the work of Tom Lane, Philip Gladstone, Luis Ortiz, Jim
|
||||
Boucher, Lee Crocker, Julian Minguillon, 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.
|
||||
|
||||
@ -126,7 +127,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, 1992, 1993, 1994, 1995, Thomas G. Lane.
|
||||
This software is copyright (C) 1991-1998, Thomas G. Lane.
|
||||
All Rights Reserved except as specified below.
|
||||
|
||||
Permission is hereby granted to use, copy, modify, and distribute this
|
||||
@ -166,8 +167,11 @@ 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 configuration script "configure" was produced with GNU Autoconf. It
|
||||
is copyright by the Free Software Foundation but is freely distributable.
|
||||
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
|
||||
@ -178,13 +182,12 @@ 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.
|
||||
|
||||
WARNING: Unisys has begun to enforce their patent on LZW compression against
|
||||
GIF encoders and decoders. You will need a license from Unisys to use the
|
||||
included rdgif.c or wrgif.c files in a commercial or shareware application.
|
||||
At this time, Unisys is not enforcing their patent against freeware, so
|
||||
distribution of this package remains legal. However, we intend to remove
|
||||
GIF support from the IJG package as soon as a suitable replacement format
|
||||
becomes reasonably popular.
|
||||
The IJG distribution formerly included code to read and write GIF files.
|
||||
To avoid entanglement with the Unisys LZW patent, GIF reading support has
|
||||
been removed altogether, and the GIF writer has been simplified to produce
|
||||
"uncompressed GIFs". This technique does not use the LZW algorithm; the
|
||||
resulting GIF files are larger than usual, but are readable by all standard
|
||||
GIF decoders.
|
||||
|
||||
We are required to state that
|
||||
"The Graphics Interchange Format(c) is the Copyright property of
|
||||
@ -203,21 +206,21 @@ The best short technical introduction to the JPEG compression algorithm is
|
||||
Communications of the ACM, April 1991 (vol. 34 no. 4), pp. 30-44.
|
||||
(Adjacent articles in that issue discuss MPEG motion picture compression,
|
||||
applications of JPEG, and related topics.) If you don't have the CACM issue
|
||||
handy, a PostScript file containing a revised version of Wallace's article
|
||||
is available at ftp.uu.net, graphics/jpeg/wallace.ps.gz. The file (actually
|
||||
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
|
||||
a preprint for an article that appeared in IEEE Trans. Consumer Electronics)
|
||||
omits the sample images that appeared in CACM, but it includes corrections
|
||||
and some added material. Note: the Wallace article is copyright ACM and
|
||||
IEEE, and it may not be used for commercial purposes.
|
||||
and some added material. Note: the Wallace article is copyright ACM and IEEE,
|
||||
and it may not be used for commercial purposes.
|
||||
|
||||
A somewhat less technical, more leisurely introduction to JPEG can be found in
|
||||
"The Data Compression Book" by Mark Nelson, published by M&T Books (Redwood
|
||||
City, CA), 1991, ISBN 1-55851-216-0. This book provides good explanations and
|
||||
example C code for a multitude of compression methods including JPEG. It is
|
||||
an excellent source if you are comfortable reading C code but don't know much
|
||||
about data compression in general. The book's JPEG sample code is far from
|
||||
industrial-strength, but when you are ready to look at a full implementation,
|
||||
you've got one here...
|
||||
"The Data Compression Book" by Mark Nelson and Jean-loup Gailly, published by
|
||||
M&T Books (New York), 2nd ed. 1996, ISBN 1-55851-434-1. This book provides
|
||||
good explanations and example C code for a multitude of compression methods
|
||||
including JPEG. It is an excellent source if you are comfortable reading C
|
||||
code but don't know much about data compression in general. The book's JPEG
|
||||
sample code is far from industrial-strength, but when you are ready to look
|
||||
at a full implementation, you've got one here...
|
||||
|
||||
The best full description of JPEG is the textbook "JPEG Still Image Data
|
||||
Compression Standard" by William B. Pennebaker and Joan L. Mitchell, published
|
||||
@ -227,23 +230,24 @@ and draft DIS 10918-2). This is by far the most complete exposition of JPEG
|
||||
in existence, and we highly recommend it.
|
||||
|
||||
The JPEG standard itself is not available electronically; you must order a
|
||||
paper copy through ISO. (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 US,
|
||||
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, Part 1: Requirements
|
||||
and guidelines" and has document number ISO/IEC IS 10918-1. Part 2 is titled
|
||||
"Digital Compression and Coding of Continuous-tone Still Images, Part 2:
|
||||
Compliance testing" and has document number ISO/IEC IS 10918-2.
|
||||
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,
|
||||
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.
|
||||
|
||||
Extensions to the original JPEG standard are defined in Part 3, a new ISO
|
||||
document. Part 3 is undergoing ISO balloting and is expected to be approved
|
||||
by the end of 1995. IJG currently does not support any Part 3 extensions.
|
||||
Some extensions to the original JPEG standard are defined in JPEG Part 3,
|
||||
a newer ISO standard numbered ISO/IEC IS 10918-3 and ITU-T T.84. IJG
|
||||
currently does not support any Part 3 extensions.
|
||||
|
||||
The JPEG standard does not specify all details of an interchangeable file
|
||||
format. For the omitted details we follow the "JFIF" conventions, revision
|
||||
@ -253,24 +257,22 @@ format. For the omitted details we follow the "JFIF" conventions, revision
|
||||
1778 McCarthy Blvd.
|
||||
Milpitas, CA 95035
|
||||
phone (408) 944-6300, fax (408) 944-6314
|
||||
A PostScript version of this document is available at ftp.uu.net, file
|
||||
graphics/jpeg/jfif.ps.gz. It can also be obtained by e-mail from the C-Cube
|
||||
mail server, netlib@c3.pla.ca.us. Send the message "send jfif_ps from jpeg"
|
||||
to the server to obtain the JFIF document; send the message "help" if you have
|
||||
trouble.
|
||||
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.
|
||||
|
||||
The TIFF 6.0 file format specification can be obtained by FTP from sgi.com
|
||||
(192.48.153.1), file graphics/tiff/TIFF6.ps.Z; or you can order a printed
|
||||
copy from Aldus Corp. at (206) 628-6593. The JPEG incorporation scheme
|
||||
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 sgi.com or
|
||||
from ftp.uu.net:/graphics/jpeg/. It is expected that the next revision of
|
||||
the TIFF spec will replace the 6.0 JPEG design with the Note's design.
|
||||
(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
|
||||
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 sgi.com:/graphics/tiff/.
|
||||
from ftp://ftp.sgi.com/graphics/tiff/.
|
||||
|
||||
|
||||
ARCHIVE LOCATIONS
|
||||
@ -279,28 +281,27 @@ 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 graphics/jpeg/jpegsrc.v6.tar.gz. If you are on the Internet, you
|
||||
can retrieve files from ftp.uu.net by standard anonymous FTP. If you don't
|
||||
have FTP access, UUNET's archives are also available via UUCP; contact
|
||||
as ftp://ftp.uu.net/graphics/jpeg/jpegsrc.v6b.tar.gz. If you don't have
|
||||
direct Internet access, UUNET's archives are also available via UUCP; contact
|
||||
help@uunet.uu.net for information on retrieving files that way.
|
||||
|
||||
Numerous Internet sites maintain copies of the UUNET files; in particular,
|
||||
you can probably find a copy at any site that archives comp.sources.misc
|
||||
submissions. However, only ftp.uu.net is guaranteed to have the latest
|
||||
official version.
|
||||
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.coast.net:/SimTel/msdos/graphics/), or on CompuServe
|
||||
in the GRAPHSUPPORT forum (GO GRAPHSUP), library 12 "JPEG Tools". Again,
|
||||
these versions may sometimes lag behind the ftp.uu.net release.
|
||||
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, news.answers, and other groups. You can
|
||||
always obtain the latest version from the news.answers archive at
|
||||
rtfm.mit.edu. By FTP, fetch /pub/usenet/news.answers/jpeg-faq/part1 and
|
||||
.../part2. If you don't have FTP, send e-mail to mail-server@rtfm.mit.edu
|
||||
Usenet newsgroups comp.graphics.misc, news.answers, and other groups.
|
||||
It is available on the World Wide Web at http://www.faqs.org/faqs/jpeg-faq/
|
||||
and other news.answers archive sites, including the official news.answers
|
||||
archive at rtfm.mit.edu: ftp://rtfm.mit.edu/pub/usenet/news.answers/jpeg-faq/.
|
||||
If you don't have Web or FTP access, send e-mail to mail-server@rtfm.mit.edu
|
||||
with body
|
||||
send usenet/news.answers/jpeg-faq/part1
|
||||
send usenet/news.answers/jpeg-faq/part2
|
||||
@ -315,21 +316,20 @@ some of the more popular free and shareware viewers, and tells where to
|
||||
obtain them on Internet.
|
||||
|
||||
If you are on a Unix machine, we highly recommend Jef Poskanzer's free
|
||||
PBMPLUS image 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. You can obtain this package by FTP from ftp.x.org
|
||||
(contrib/pbmplus*.tar.Z) or ftp.ee.lbl.gov (pbmplus*.tar.Z). There is also
|
||||
a newer update of this package called NETPBM, available from
|
||||
wuarchive.wustl.edu under directory /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.
|
||||
PBMPLUS software, which provides many useful operations on PPM-format image
|
||||
files. In particular, it can convert PPM images to and from a wide range of
|
||||
other formats, thus making cjpeg/djpeg considerably more useful. The latest
|
||||
version is distributed by the NetPBM group, and is available from numerous
|
||||
sites, notably ftp://wuarchive.wustl.edu/graphics/graphics/packages/NetPBM/.
|
||||
Unfortunately PBMPLUS/NETPBM is not nearly as portable as the IJG software is;
|
||||
you are likely to have difficulty making it work on any non-Unix machine.
|
||||
|
||||
A different free JPEG implementation, written by the PVRG group at Stanford,
|
||||
is available from havefun.stanford.edu in directory pub/jpeg. This program
|
||||
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.
|
||||
which we do not. (On the other hand, it doesn't do progressive JPEG.)
|
||||
|
||||
|
||||
FILE FORMAT WARS
|
||||
@ -370,14 +370,16 @@ use a proprietary file format!
|
||||
TO DO
|
||||
=====
|
||||
|
||||
The major thrust for v7 will probably be improvement of visual quality.
|
||||
The current method for scaling the quantization tables is known not to be
|
||||
very good at low Q values. We also intend to investigate block boundary
|
||||
smoothing, "poor man's variable quantization", and other means of improving
|
||||
quality-vs-file-size performance without sacrificing compatibility.
|
||||
|
||||
In future versions, we are considering supporting some of the upcoming JPEG
|
||||
Part 3 extensions --- principally, variable quantization and the SPIFF file
|
||||
format.
|
||||
|
||||
Tuning the software for better behavior at low quality/high compression
|
||||
settings is also of interest. The current method for scaling the
|
||||
quantization tables is known not to be very good at low Q values.
|
||||
|
||||
As always, speeding things up is high on our priority list.
|
||||
As always, speeding things up is of great interest.
|
||||
|
||||
Please send bug reports, offers of help, etc. to jpeg-info@uunet.uu.net.
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* cderror.h
|
||||
*
|
||||
* Copyright (C) 1994, Thomas G. Lane.
|
||||
* Copyright (C) 1994-1997, Thomas G. Lane.
|
||||
* This file is part of the Independent JPEG Group's software.
|
||||
* For conditions of distribution and use, see the accompanying README file.
|
||||
*
|
||||
@ -72,7 +72,7 @@ JMESSAGE(JWRN_GIF_NOMOREDATA, "Ran out of GIF bits")
|
||||
#ifdef PPM_SUPPORTED
|
||||
JMESSAGE(JERR_PPM_COLORSPACE, "PPM output must be grayscale or RGB")
|
||||
JMESSAGE(JERR_PPM_NONNUMERIC, "Nonnumeric data in PPM file")
|
||||
JMESSAGE(JERR_PPM_NOT, "Not a PPM file")
|
||||
JMESSAGE(JERR_PPM_NOT, "Not a PPM/PGM file")
|
||||
JMESSAGE(JTRC_PGM, "%ux%u PGM image")
|
||||
JMESSAGE(JTRC_PGM_TEXT, "%ux%u text PGM image")
|
||||
JMESSAGE(JTRC_PPM, "%ux%u PPM image")
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* cdjpeg.c
|
||||
*
|
||||
* Copyright (C) 1991-1995, Thomas G. Lane.
|
||||
* 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.
|
||||
*
|
||||
@ -31,7 +31,7 @@
|
||||
|
||||
static j_common_ptr sig_cinfo;
|
||||
|
||||
GLOBAL void /* must be global for Manx C */
|
||||
void /* must be global for Manx C */
|
||||
signal_catcher (int signum)
|
||||
{
|
||||
if (sig_cinfo != NULL) {
|
||||
@ -43,11 +43,13 @@ signal_catcher (int signum)
|
||||
}
|
||||
|
||||
|
||||
GLOBAL void
|
||||
GLOBAL(void)
|
||||
enable_signal_catcher (j_common_ptr cinfo)
|
||||
{
|
||||
sig_cinfo = cinfo;
|
||||
#ifdef SIGINT /* not all systems have SIGINT */
|
||||
signal(SIGINT, signal_catcher);
|
||||
#endif
|
||||
#ifdef SIGTERM /* not all systems have SIGTERM */
|
||||
signal(SIGTERM, signal_catcher);
|
||||
#endif
|
||||
@ -62,7 +64,7 @@ enable_signal_catcher (j_common_ptr cinfo)
|
||||
|
||||
#ifdef PROGRESS_REPORT
|
||||
|
||||
METHODDEF void
|
||||
METHODDEF(void)
|
||||
progress_monitor (j_common_ptr cinfo)
|
||||
{
|
||||
cd_progress_ptr prog = (cd_progress_ptr) cinfo->progress;
|
||||
@ -83,7 +85,7 @@ progress_monitor (j_common_ptr cinfo)
|
||||
}
|
||||
|
||||
|
||||
GLOBAL void
|
||||
GLOBAL(void)
|
||||
start_progress_monitor (j_common_ptr cinfo, cd_progress_ptr progress)
|
||||
{
|
||||
/* Enable progress display, unless trace output is on */
|
||||
@ -97,7 +99,7 @@ start_progress_monitor (j_common_ptr cinfo, cd_progress_ptr progress)
|
||||
}
|
||||
|
||||
|
||||
GLOBAL void
|
||||
GLOBAL(void)
|
||||
end_progress_monitor (j_common_ptr cinfo)
|
||||
{
|
||||
/* Clear away progress display */
|
||||
@ -116,7 +118,7 @@ end_progress_monitor (j_common_ptr cinfo)
|
||||
* minchars is length of minimum legal abbreviation.
|
||||
*/
|
||||
|
||||
GLOBAL boolean
|
||||
GLOBAL(boolean)
|
||||
keymatch (char * arg, const char * keyword, int minchars)
|
||||
{
|
||||
register int ca, ck;
|
||||
@ -143,7 +145,7 @@ keymatch (char * arg, const char * keyword, int minchars)
|
||||
* Non-Unix systems often require some hacking to get out of text mode.
|
||||
*/
|
||||
|
||||
GLOBAL FILE *
|
||||
GLOBAL(FILE *)
|
||||
read_stdin (void)
|
||||
{
|
||||
FILE * input_file = stdin;
|
||||
@ -161,7 +163,7 @@ read_stdin (void)
|
||||
}
|
||||
|
||||
|
||||
GLOBAL FILE *
|
||||
GLOBAL(FILE *)
|
||||
write_stdout (void)
|
||||
{
|
||||
FILE * output_file = stdout;
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* cdjpeg.h
|
||||
*
|
||||
* Copyright (C) 1994-1995, Thomas G. Lane.
|
||||
* Copyright (C) 1994-1997, Thomas G. Lane.
|
||||
* This file is part of the Independent JPEG Group's software.
|
||||
* For conditions of distribution and use, see the accompanying README file.
|
||||
*
|
||||
@ -116,39 +116,39 @@ typedef struct cdjpeg_progress_mgr * cd_progress_ptr;
|
||||
|
||||
/* Module selection routines for I/O modules. */
|
||||
|
||||
EXTERN cjpeg_source_ptr jinit_read_bmp JPP((j_compress_ptr cinfo));
|
||||
EXTERN djpeg_dest_ptr jinit_write_bmp JPP((j_decompress_ptr cinfo,
|
||||
boolean is_os2));
|
||||
EXTERN cjpeg_source_ptr jinit_read_gif JPP((j_compress_ptr cinfo));
|
||||
EXTERN djpeg_dest_ptr jinit_write_gif JPP((j_decompress_ptr cinfo));
|
||||
EXTERN cjpeg_source_ptr jinit_read_ppm JPP((j_compress_ptr cinfo));
|
||||
EXTERN djpeg_dest_ptr jinit_write_ppm JPP((j_decompress_ptr cinfo));
|
||||
EXTERN cjpeg_source_ptr jinit_read_rle JPP((j_compress_ptr cinfo));
|
||||
EXTERN djpeg_dest_ptr jinit_write_rle JPP((j_decompress_ptr cinfo));
|
||||
EXTERN cjpeg_source_ptr jinit_read_targa JPP((j_compress_ptr cinfo));
|
||||
EXTERN djpeg_dest_ptr jinit_write_targa JPP((j_decompress_ptr cinfo));
|
||||
EXTERN(cjpeg_source_ptr) jinit_read_bmp JPP((j_compress_ptr cinfo));
|
||||
EXTERN(djpeg_dest_ptr) jinit_write_bmp JPP((j_decompress_ptr cinfo,
|
||||
boolean is_os2));
|
||||
EXTERN(cjpeg_source_ptr) jinit_read_gif JPP((j_compress_ptr cinfo));
|
||||
EXTERN(djpeg_dest_ptr) jinit_write_gif JPP((j_decompress_ptr cinfo));
|
||||
EXTERN(cjpeg_source_ptr) jinit_read_ppm JPP((j_compress_ptr cinfo));
|
||||
EXTERN(djpeg_dest_ptr) jinit_write_ppm JPP((j_decompress_ptr cinfo));
|
||||
EXTERN(cjpeg_source_ptr) jinit_read_rle JPP((j_compress_ptr cinfo));
|
||||
EXTERN(djpeg_dest_ptr) jinit_write_rle JPP((j_decompress_ptr cinfo));
|
||||
EXTERN(cjpeg_source_ptr) jinit_read_targa JPP((j_compress_ptr cinfo));
|
||||
EXTERN(djpeg_dest_ptr) jinit_write_targa JPP((j_decompress_ptr cinfo));
|
||||
|
||||
/* cjpeg support routines (in rdswitch.c) */
|
||||
|
||||
EXTERN boolean read_quant_tables JPP((j_compress_ptr cinfo, char * filename,
|
||||
int scale_factor, boolean force_baseline));
|
||||
EXTERN boolean read_scan_script JPP((j_compress_ptr cinfo, char * filename));
|
||||
EXTERN boolean set_quant_slots JPP((j_compress_ptr cinfo, char *arg));
|
||||
EXTERN boolean set_sample_factors JPP((j_compress_ptr cinfo, char *arg));
|
||||
EXTERN(boolean) read_quant_tables JPP((j_compress_ptr cinfo, char * filename,
|
||||
int scale_factor, boolean force_baseline));
|
||||
EXTERN(boolean) read_scan_script JPP((j_compress_ptr cinfo, char * filename));
|
||||
EXTERN(boolean) set_quant_slots JPP((j_compress_ptr cinfo, char *arg));
|
||||
EXTERN(boolean) set_sample_factors JPP((j_compress_ptr cinfo, char *arg));
|
||||
|
||||
/* djpeg support routines (in rdcolmap.c) */
|
||||
|
||||
EXTERN void read_color_map JPP((j_decompress_ptr cinfo, FILE * infile));
|
||||
EXTERN(void) read_color_map JPP((j_decompress_ptr cinfo, FILE * infile));
|
||||
|
||||
/* common support routines (in cdjpeg.c) */
|
||||
|
||||
EXTERN void enable_signal_catcher JPP((j_common_ptr cinfo));
|
||||
EXTERN void start_progress_monitor JPP((j_common_ptr cinfo,
|
||||
cd_progress_ptr progress));
|
||||
EXTERN void end_progress_monitor JPP((j_common_ptr cinfo));
|
||||
EXTERN boolean keymatch JPP((char * arg, const char * keyword, int minchars));
|
||||
EXTERN FILE * read_stdin JPP((void));
|
||||
EXTERN FILE * write_stdout JPP((void));
|
||||
EXTERN(void) enable_signal_catcher JPP((j_common_ptr cinfo));
|
||||
EXTERN(void) start_progress_monitor JPP((j_common_ptr cinfo,
|
||||
cd_progress_ptr progress));
|
||||
EXTERN(void) end_progress_monitor JPP((j_common_ptr cinfo));
|
||||
EXTERN(boolean) keymatch JPP((char * arg, const char * keyword, int minchars));
|
||||
EXTERN(FILE *) read_stdin JPP((void));
|
||||
EXTERN(FILE *) write_stdout JPP((void));
|
||||
|
||||
/* miscellaneous useful macros */
|
||||
|
||||
@ -156,9 +156,14 @@ EXTERN FILE * write_stdout JPP((void));
|
||||
#define READ_BINARY "r"
|
||||
#define WRITE_BINARY "w"
|
||||
#else
|
||||
#ifdef VMS /* VMS is very nonstandard */
|
||||
#define READ_BINARY "rb", "ctx=stm"
|
||||
#define WRITE_BINARY "wb", "ctx=stm"
|
||||
#else /* standard ANSI-compliant case */
|
||||
#define READ_BINARY "rb"
|
||||
#define WRITE_BINARY "wb"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef EXIT_FAILURE /* define exit() codes if not provided */
|
||||
#define EXIT_FAILURE 1
|
||||
|
105
jpeg/change.log
105
jpeg/change.log
@ -1,6 +1,111 @@
|
||||
CHANGE LOG for Independent JPEG Group's JPEG software
|
||||
|
||||
|
||||
Version 6b 27-Mar-1998
|
||||
-----------------------
|
||||
|
||||
jpegtran has new features for lossless image transformations (rotation
|
||||
and flipping) as well as "lossless" reduction to grayscale.
|
||||
|
||||
jpegtran now copies comments by default; it has a -copy switch to enable
|
||||
copying all APPn blocks as well, or to suppress comments. (Formerly it
|
||||
always suppressed comments and APPn blocks.) jpegtran now also preserves
|
||||
JFIF version and resolution information.
|
||||
|
||||
New decompressor library feature: COM and APPn markers found in the input
|
||||
file can be saved in memory for later use by the application. (Before,
|
||||
you had to code this up yourself with a custom marker processor.)
|
||||
|
||||
There is an unused field "void * client_data" now in compress and decompress
|
||||
parameter structs; this may be useful in some applications.
|
||||
|
||||
JFIF version number information is now saved by the decoder and accepted by
|
||||
the encoder. jpegtran uses this to copy the source file's version number,
|
||||
to ensure "jpegtran -copy all" won't create bogus files that contain JFXX
|
||||
extensions but claim to be version 1.01. Applications that generate their
|
||||
own JFXX extension markers also (finally) have a supported way to cause the
|
||||
encoder to emit JFIF version number 1.02.
|
||||
|
||||
djpeg's trace mode reports JFIF 1.02 thumbnail images as such, rather
|
||||
than as unknown APP0 markers.
|
||||
|
||||
In -verbose mode, djpeg and rdjpgcom will try to print the contents of
|
||||
APP12 markers as text. Some digital cameras store useful text information
|
||||
in APP12 markers.
|
||||
|
||||
Handling of truncated data streams is more robust: blocks beyond the one in
|
||||
which the error occurs will be output as uniform gray, or left unchanged
|
||||
if decoding a progressive JPEG. The appearance no longer depends on the
|
||||
Huffman tables being used.
|
||||
|
||||
Huffman tables are checked for validity much more carefully than before.
|
||||
|
||||
To avoid the Unisys LZW patent, djpeg's GIF output capability has been
|
||||
changed to produce "uncompressed GIFs", and cjpeg's GIF input capability
|
||||
has been removed altogether. We're not happy about it either, but there
|
||||
seems to be no good alternative.
|
||||
|
||||
The configure script now supports building libjpeg as a shared library
|
||||
on many flavors of Unix (all the ones that GNU libtool knows how to
|
||||
build shared libraries for). Use "./configure --enable-shared" to
|
||||
try this out.
|
||||
|
||||
New jconfig file and makefiles for Microsoft Visual C++ and Developer Studio.
|
||||
Also, a jconfig file and a build script for Metrowerks CodeWarrior
|
||||
on Apple Macintosh. makefile.dj has been updated for DJGPP v2, and there
|
||||
are miscellaneous other minor improvements in the makefiles.
|
||||
|
||||
jmemmac.c now knows how to create temporary files following Mac System 7
|
||||
conventions.
|
||||
|
||||
djpeg's -map switch is now able to read raw-format PPM files reliably.
|
||||
|
||||
cjpeg -progressive -restart no longer generates any unnecessary DRI markers.
|
||||
|
||||
Multiple calls to jpeg_simple_progression for a single JPEG object
|
||||
no longer leak memory.
|
||||
|
||||
|
||||
Version 6a 7-Feb-96
|
||||
--------------------
|
||||
|
||||
Library initialization sequence modified to detect version mismatches
|
||||
and struct field packing mismatches between library and calling application.
|
||||
This change requires applications to be recompiled, but does not require
|
||||
any application source code change.
|
||||
|
||||
All routine declarations changed to the style "GLOBAL(type) name ...",
|
||||
that is, GLOBAL, LOCAL, METHODDEF, EXTERN are now macros taking the
|
||||
routine's return type as an argument. This makes it possible to add
|
||||
Microsoft-style linkage keywords to all the routines by changing just
|
||||
these macros. Note that any application code that was using these macros
|
||||
will have to be changed.
|
||||
|
||||
DCT coefficient quantization tables are now stored in normal array order
|
||||
rather than zigzag order. Application code that calls jpeg_add_quant_table,
|
||||
or otherwise manipulates quantization tables directly, will need to be
|
||||
changed. If you need to make such code work with either older or newer
|
||||
versions of the library, a test like "#if JPEG_LIB_VERSION >= 61" is
|
||||
recommended.
|
||||
|
||||
djpeg's trace capability now dumps DQT tables in natural order, not zigzag
|
||||
order. This allows the trace output to be made into a "-qtables" file
|
||||
more easily.
|
||||
|
||||
New system-dependent memory manager module for use on Apple Macintosh.
|
||||
|
||||
Fix bug in cjpeg's -smooth option: last one or two scanlines would be
|
||||
duplicates of the prior line unless the image height mod 16 was 1 or 2.
|
||||
|
||||
Repair minor problems in VMS, BCC, MC6 makefiles.
|
||||
|
||||
New configure script based on latest GNU Autoconf.
|
||||
|
||||
Correct the list of include files needed by MetroWerks C for ccommand().
|
||||
|
||||
Numerous small documentation updates.
|
||||
|
||||
|
||||
Version 6 2-Aug-95
|
||||
-------------------
|
||||
|
||||
|
17
jpeg/cjpeg.c
17
jpeg/cjpeg.c
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* cjpeg.c
|
||||
*
|
||||
* Copyright (C) 1991-1995, Thomas G. Lane.
|
||||
* Copyright (C) 1991-1998, Thomas G. Lane.
|
||||
* This file is part of the Independent JPEG Group's software.
|
||||
* For conditions of distribution and use, see the accompanying README file.
|
||||
*
|
||||
@ -28,7 +28,8 @@
|
||||
|
||||
#ifdef USE_CCOMMAND /* command-line reader for Macintosh */
|
||||
#ifdef __MWERKS__
|
||||
#include <SIOUX.h> /* Metrowerks declares it here */
|
||||
#include <SIOUX.h> /* Metrowerks needs this */
|
||||
#include <console.h> /* ... and this */
|
||||
#endif
|
||||
#ifdef THINK_C
|
||||
#include <console.h> /* Think declares it here */
|
||||
@ -75,7 +76,7 @@ static const char * const cdjpeg_message_table[] = {
|
||||
static boolean is_targa; /* records user -targa switch */
|
||||
|
||||
|
||||
LOCAL cjpeg_source_ptr
|
||||
LOCAL(cjpeg_source_ptr)
|
||||
select_file_type (j_compress_ptr cinfo, FILE * infile)
|
||||
{
|
||||
int c;
|
||||
@ -136,7 +137,7 @@ static const char * progname; /* program name for error messages */
|
||||
static char * outfilename; /* for -outfile switch */
|
||||
|
||||
|
||||
LOCAL void
|
||||
LOCAL(void)
|
||||
usage (void)
|
||||
/* complain about bad command line */
|
||||
{
|
||||
@ -183,7 +184,7 @@ usage (void)
|
||||
#ifdef C_ARITH_CODING_SUPPORTED
|
||||
fprintf(stderr, " -arithmetic Use arithmetic coding\n");
|
||||
#endif
|
||||
fprintf(stderr, " -baseline Force baseline output\n");
|
||||
fprintf(stderr, " -baseline Force baseline quantization tables\n");
|
||||
fprintf(stderr, " -qtables file Use quantization tables given in file\n");
|
||||
fprintf(stderr, " -qslots N[,...] Set component quantization tables\n");
|
||||
fprintf(stderr, " -sample HxV[,...] Set component sampling factors\n");
|
||||
@ -194,7 +195,7 @@ usage (void)
|
||||
}
|
||||
|
||||
|
||||
LOCAL int
|
||||
LOCAL(int)
|
||||
parse_switches (j_compress_ptr cinfo, int argc, char **argv,
|
||||
int last_file_arg_seen, boolean for_real)
|
||||
/* Parse optional switches.
|
||||
@ -254,7 +255,7 @@ parse_switches (j_compress_ptr cinfo, int argc, char **argv,
|
||||
#endif
|
||||
|
||||
} else if (keymatch(arg, "baseline", 1)) {
|
||||
/* Force baseline output (8-bit quantizer values). */
|
||||
/* Force baseline-compatible output (8-bit quantizer values). */
|
||||
force_baseline = TRUE;
|
||||
|
||||
} else if (keymatch(arg, "dct", 2)) {
|
||||
@ -456,7 +457,7 @@ parse_switches (j_compress_ptr cinfo, int argc, char **argv,
|
||||
* The main program.
|
||||
*/
|
||||
|
||||
GLOBAL int
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
{
|
||||
struct jpeg_compress_struct cinfo;
|
||||
|
@ -1,6 +1,6 @@
|
||||
IJG JPEG LIBRARY: CODING RULES
|
||||
|
||||
Copyright (C) 1991-1994, Thomas G. Lane.
|
||||
Copyright (C) 1991-1996, Thomas G. Lane.
|
||||
This file is part of the Independent JPEG Group's software.
|
||||
For conditions of distribution and use, see the accompanying README file.
|
||||
|
||||
@ -43,17 +43,17 @@ ansi2knr is not very bright, so it imposes a format requirement on function
|
||||
declarations: the function name MUST BEGIN IN COLUMN 1. Thus all functions
|
||||
should be written in the following style:
|
||||
|
||||
LOCAL int *
|
||||
LOCAL(int *)
|
||||
function_name (int a, char *b)
|
||||
{
|
||||
code...
|
||||
}
|
||||
|
||||
Note that each function definition is prefixed with GLOBAL, LOCAL, or
|
||||
METHODDEF. These macros expand to "static" or nothing as appropriate.
|
||||
They provide a readable indication of the routine's usage and can readily be
|
||||
changed for special needs. (For instance, all routines can be made global for
|
||||
use with debuggers or code profilers that require it.)
|
||||
Note that each function definition must begin with GLOBAL(type), LOCAL(type),
|
||||
or METHODDEF(type). These macros expand to "static type" or just "type" as
|
||||
appropriate. They provide a readable indication of the routine's usage and
|
||||
can readily be changed for special needs. (For instance, special linkage
|
||||
keywords can be inserted for use in Windows DLLs.)
|
||||
|
||||
ansi2knr does not transform method declarations (function pointers in
|
||||
structs). We handle these with a macro JMETHOD, defined as
|
||||
@ -69,8 +69,8 @@ which is used like this:
|
||||
};
|
||||
Note the set of parentheses surrounding the parameter list.
|
||||
|
||||
A similar solution is used for external function declarations (see the JPP
|
||||
macro).
|
||||
A similar solution is used for forward and external function declarations
|
||||
(see the EXTERN and JPP macros).
|
||||
|
||||
If the code is to work on non-ANSI compilers, we cannot rely on a prototype
|
||||
declaration to coerce actual parameters into the right types. Therefore, use
|
||||
|
41
jpeg/djpeg.c
41
jpeg/djpeg.c
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* djpeg.c
|
||||
*
|
||||
* Copyright (C) 1991-1995, Thomas G. Lane.
|
||||
* 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.
|
||||
*
|
||||
@ -30,7 +30,8 @@
|
||||
|
||||
#ifdef USE_CCOMMAND /* command-line reader for Macintosh */
|
||||
#ifdef __MWERKS__
|
||||
#include <SIOUX.h> /* Metrowerks declares it here */
|
||||
#include <SIOUX.h> /* Metrowerks needs this */
|
||||
#include <console.h> /* ... and this */
|
||||
#endif
|
||||
#ifdef THINK_C
|
||||
#include <console.h> /* Think declares it here */
|
||||
@ -85,7 +86,7 @@ static const char * progname; /* program name for error messages */
|
||||
static char * outfilename; /* for -outfile switch */
|
||||
|
||||
|
||||
LOCAL void
|
||||
LOCAL(void)
|
||||
usage (void)
|
||||
/* complain about bad command line */
|
||||
{
|
||||
@ -157,7 +158,7 @@ usage (void)
|
||||
}
|
||||
|
||||
|
||||
LOCAL int
|
||||
LOCAL(int)
|
||||
parse_switches (j_decompress_ptr cinfo, int argc, char **argv,
|
||||
int last_file_arg_seen, boolean for_real)
|
||||
/* Parse optional switches.
|
||||
@ -343,13 +344,13 @@ parse_switches (j_decompress_ptr cinfo, int argc, char **argv,
|
||||
|
||||
|
||||
/*
|
||||
* Marker processor for COM markers.
|
||||
* Marker processor for COM and interesting APPn markers.
|
||||
* This replaces the library's built-in processor, which just skips the marker.
|
||||
* We want to print out the marker as text, if possible.
|
||||
* We want to print out the marker as text, to the extent possible.
|
||||
* Note this code relies on a non-suspending data source.
|
||||
*/
|
||||
|
||||
LOCAL unsigned int
|
||||
LOCAL(unsigned int)
|
||||
jpeg_getc (j_decompress_ptr cinfo)
|
||||
/* Read next byte */
|
||||
{
|
||||
@ -364,8 +365,8 @@ jpeg_getc (j_decompress_ptr cinfo)
|
||||
}
|
||||
|
||||
|
||||
METHODDEF boolean
|
||||
COM_handler (j_decompress_ptr cinfo)
|
||||
METHODDEF(boolean)
|
||||
print_text_marker (j_decompress_ptr cinfo)
|
||||
{
|
||||
boolean traceit = (cinfo->err->trace_level >= 1);
|
||||
INT32 length;
|
||||
@ -376,8 +377,13 @@ COM_handler (j_decompress_ptr cinfo)
|
||||
length += jpeg_getc(cinfo);
|
||||
length -= 2; /* discount the length word itself */
|
||||
|
||||
if (traceit)
|
||||
fprintf(stderr, "Comment, length %ld:\n", (long) length);
|
||||
if (traceit) {
|
||||
if (cinfo->unread_marker == JPEG_COM)
|
||||
fprintf(stderr, "Comment, length %ld:\n", (long) length);
|
||||
else /* assume it is an APPn otherwise */
|
||||
fprintf(stderr, "APP%d, length %ld:\n",
|
||||
cinfo->unread_marker - JPEG_APP0, (long) length);
|
||||
}
|
||||
|
||||
while (--length >= 0) {
|
||||
ch = jpeg_getc(cinfo);
|
||||
@ -414,7 +420,7 @@ COM_handler (j_decompress_ptr cinfo)
|
||||
* The main program.
|
||||
*/
|
||||
|
||||
GLOBAL int
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
{
|
||||
struct jpeg_decompress_struct cinfo;
|
||||
@ -444,8 +450,15 @@ main (int argc, char **argv)
|
||||
jerr.addon_message_table = cdjpeg_message_table;
|
||||
jerr.first_addon_message = JMSG_FIRSTADDONCODE;
|
||||
jerr.last_addon_message = JMSG_LASTADDONCODE;
|
||||
/* Insert custom COM marker processor. */
|
||||
jpeg_set_marker_processor(&cinfo, JPEG_COM, COM_handler);
|
||||
|
||||
/* Insert custom marker processor for COM and APP12.
|
||||
* APP12 is used by some digital camera makers for textual info,
|
||||
* so we provide the ability to display it as text.
|
||||
* If you like, additional APPn marker types can be selected for display,
|
||||
* but don't try to override APP0 or APP14 this way (see libjpeg.doc).
|
||||
*/
|
||||
jpeg_set_marker_processor(&cinfo, JPEG_COM, print_text_marker);
|
||||
jpeg_set_marker_processor(&cinfo, JPEG_APP0+12, print_text_marker);
|
||||
|
||||
/* Now safe to enable signal catcher. */
|
||||
#ifdef NEED_SIGNAL_CATCHER
|
||||
|
@ -68,7 +68,7 @@ extern int image_width; /* Number of columns in image */
|
||||
* and a compression quality factor are passed in.
|
||||
*/
|
||||
|
||||
GLOBAL void
|
||||
GLOBAL(void)
|
||||
write_JPEG_file (char * filename, int quality)
|
||||
{
|
||||
/* This struct contains the JPEG compression parameters and pointers to
|
||||
@ -259,7 +259,7 @@ typedef struct my_error_mgr * my_error_ptr;
|
||||
* Here's the routine that will replace the standard error_exit method:
|
||||
*/
|
||||
|
||||
METHODDEF void
|
||||
METHODDEF(void)
|
||||
my_error_exit (j_common_ptr cinfo)
|
||||
{
|
||||
/* cinfo->err really points to a my_error_mgr struct, so coerce pointer */
|
||||
@ -280,7 +280,7 @@ my_error_exit (j_common_ptr cinfo)
|
||||
*/
|
||||
|
||||
|
||||
GLOBAL int
|
||||
GLOBAL(int)
|
||||
read_JPEG_file (char * filename)
|
||||
{
|
||||
/* This struct contains the JPEG decompression parameters and pointers to
|
||||
|
@ -1,6 +1,6 @@
|
||||
IJG JPEG LIBRARY: FILE LIST
|
||||
|
||||
Copyright (C) 1994-1995, Thomas G. Lane.
|
||||
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.
|
||||
|
||||
@ -113,8 +113,9 @@ module:
|
||||
jmemnobs.c "No backing store": assumes adequate virtual memory exists.
|
||||
jmemansi.c Makes temporary files with ANSI-standard routine tmpfile().
|
||||
jmemname.c Makes temporary files with program-generated file names.
|
||||
jmemdos.c Custom implementation for MS-DOS: knows about extended and
|
||||
expanded memory as well as temporary files.
|
||||
jmemdos.c Custom implementation for MS-DOS (16-bit environment only):
|
||||
can use extended and expanded memory as well as temp files.
|
||||
jmemmac.c Custom implementation for Apple Macintosh.
|
||||
|
||||
Exactly one of the system-dependent modules should be configured into an
|
||||
installed JPEG library (see install.doc for hints about which one to use).
|
||||
@ -133,8 +134,9 @@ CJPEG/DJPEG/JPEGTRAN
|
||||
|
||||
Include files:
|
||||
|
||||
cdjpeg.h Declarations shared by cjpeg/djpeg modules.
|
||||
cderror.h Additional error and trace message codes for cjpeg/djpeg.
|
||||
cdjpeg.h Declarations shared by cjpeg/djpeg/jpegtran modules.
|
||||
cderror.h Additional error and trace message codes for cjpeg et al.
|
||||
transupp.h Declarations for jpegtran support routines in transupp.c.
|
||||
|
||||
C source code files:
|
||||
|
||||
@ -145,11 +147,12 @@ cdjpeg.c Utility routines used by all three programs.
|
||||
rdcolmap.c Code to read a colormap file for djpeg's "-map" switch.
|
||||
rdswitch.c Code to process some of cjpeg's more complex switches.
|
||||
Also used by jpegtran.
|
||||
transupp.c Support code for jpegtran: lossless image manipulations.
|
||||
|
||||
Image file reader modules for cjpeg:
|
||||
|
||||
rdbmp.c BMP file input.
|
||||
rdgif.c GIF file input.
|
||||
rdgif.c GIF file input (now just a stub).
|
||||
rdppm.c PPM/PGM file input.
|
||||
rdrle.c Utah RLE file input.
|
||||
rdtarga.c Targa file input.
|
||||
@ -157,7 +160,7 @@ rdtarga.c Targa file input.
|
||||
Image file writer modules for djpeg:
|
||||
|
||||
wrbmp.c BMP file output.
|
||||
wrgif.c GIF file output.
|
||||
wrgif.c GIF file output (a mere shadow of its former self).
|
||||
wrppm.c PPM/PGM file output.
|
||||
wrrle.c Utah RLE file output.
|
||||
wrtarga.c Targa file output.
|
||||
@ -189,6 +192,11 @@ example.c Sample code for calling JPEG library.
|
||||
Configuration/installation files and programs (see install.doc for more info):
|
||||
|
||||
configure Unix shell script to perform automatic configuration.
|
||||
ltconfig Support scripts for configure (from GNU libtool).
|
||||
ltmain.sh
|
||||
config.guess
|
||||
config.sub
|
||||
install-sh Install shell script for those Unix systems lacking one.
|
||||
ckconfig.c Program to generate jconfig.h on non-Unix systems.
|
||||
jconfig.doc Template for making jconfig.h by hand.
|
||||
makefile.* Sample makefiles for particular systems.
|
||||
|
348
jpeg/install.doc
348
jpeg/install.doc
@ -1,6 +1,6 @@
|
||||
INSTALLATION INSTRUCTIONS for the Independent JPEG Group's JPEG software
|
||||
|
||||
Copyright (C) 1991-1995, Thomas G. Lane.
|
||||
Copyright (C) 1991-1998, Thomas G. Lane.
|
||||
This file is part of the Independent JPEG Group's software.
|
||||
For conditions of distribution and use, see the accompanying README file.
|
||||
|
||||
@ -94,6 +94,19 @@ Configure was created with GNU Autoconf and it follows the usual conventions
|
||||
for GNU configure scripts. It makes a few assumptions that you may want to
|
||||
override. You can do this by providing optional switches to configure:
|
||||
|
||||
* If you want to build libjpeg as a shared library, say
|
||||
./configure --enable-shared
|
||||
To get both shared and static libraries, say
|
||||
./configure --enable-shared --enable-static
|
||||
Note that these switches invoke GNU libtool to take care of system-dependent
|
||||
shared library building methods. If things don't work this way, please try
|
||||
running configure without either switch; that should build a static library
|
||||
without using libtool. If that works, your problem is probably with libtool
|
||||
not with the IJG code. libtool is fairly new and doesn't support all flavors
|
||||
of Unix yet. (You might be able to find a newer version of libtool than the
|
||||
one included with libjpeg; see ftp.gnu.org. Report libtool problems to
|
||||
bug-libtool@gnu.org.)
|
||||
|
||||
* Configure will use gcc (GNU C compiler) if it's available, otherwise cc.
|
||||
To force a particular compiler to be selected, use the CC option, for example
|
||||
./configure CC='cc'
|
||||
@ -102,8 +115,10 @@ For example, on HP-UX you probably want to say
|
||||
./configure CC='cc -Aa'
|
||||
to get HP's compiler to run in ANSI mode.
|
||||
|
||||
* The default CFLAGS setting is "-O". You can override this by saying,
|
||||
for example, ./configure CFLAGS='-O2'.
|
||||
* The default CFLAGS setting is "-O" for non-gcc compilers, "-O2" for gcc.
|
||||
You can override this by saying, for example,
|
||||
./configure CFLAGS='-g'
|
||||
if you want to compile with debugging support.
|
||||
|
||||
* Configure will set up the makefile so that "make install" will install files
|
||||
into /usr/local/bin, /usr/local/man, etc. You can specify an installation
|
||||
@ -131,17 +146,20 @@ Makefile jconfig file System and/or compiler
|
||||
|
||||
makefile.manx jconfig.manx Amiga, Manx Aztec C
|
||||
makefile.sas jconfig.sas Amiga, SAS C
|
||||
makeproj.mac jconfig.mac Apple Macintosh, Metrowerks CodeWarrior
|
||||
mak*jpeg.st jconfig.st Atari ST/STE/TT, Pure C or Turbo C
|
||||
makefile.bcc jconfig.bcc MS-DOS or OS/2, Borland C
|
||||
makefile.dj jconfig.dj MS-DOS, DJGPP (Delorie's port of GNU C)
|
||||
makefile.mc6 jconfig.mc6 MS-DOS, Microsoft C version 6.x and up
|
||||
makefile.mc6 jconfig.mc6 MS-DOS, Microsoft C (16-bit only)
|
||||
makefile.wat jconfig.wat MS-DOS, OS/2, or Windows NT, Watcom C
|
||||
makefile.vc jconfig.vc Windows NT/95, MS Visual C++
|
||||
make*.ds jconfig.vc Windows NT/95, MS Developer Studio
|
||||
makefile.mms jconfig.vms Digital VMS, with MMS software
|
||||
makefile.vms jconfig.vms Digital VMS, without MMS software
|
||||
|
||||
Copy the proper jconfig file to jconfig.h and the makefile to Makefile
|
||||
(or whatever your system uses as the standard makefile name). For the
|
||||
Atari, we provide four project files; see the Atari hints below.
|
||||
Copy the proper jconfig file to jconfig.h and the makefile to Makefile (or
|
||||
whatever your system uses as the standard makefile name). For more info see
|
||||
the appropriate system-specific hints section near the end of this file.
|
||||
|
||||
|
||||
Configuring the software by hand
|
||||
@ -216,7 +234,7 @@ Selecting a memory manager
|
||||
|
||||
The IJG code is capable of working on images that are too big to fit in main
|
||||
memory; data is swapped out to temporary files as necessary. However, the
|
||||
code to do this is rather system-dependent. We provide four different
|
||||
code to do this is rather system-dependent. We provide five different
|
||||
memory managers:
|
||||
|
||||
* jmemansi.c This version uses the ANSI-standard library routine tmpfile(),
|
||||
@ -240,7 +258,10 @@ memory managers:
|
||||
IMPORTANT: if you use this, define USE_MSDOS_MEMMGR in
|
||||
jconfig.h, and include the assembly file jmemdosa.asm in the
|
||||
programs. The supplied makefiles and jconfig files for
|
||||
MS-DOS compilers already do both.
|
||||
16-bit MS-DOS compilers already do both.
|
||||
|
||||
* jmemmac.c Custom version for Apple Macintosh; see the system-specific
|
||||
notes for Macintosh for more info.
|
||||
|
||||
To use a particular memory manager, change the SYSDEPMEM variable in your
|
||||
makefile to equal the corresponding object file name (for example, jmemansi.o
|
||||
@ -253,8 +274,8 @@ If yours doesn't, try jmemansi.c first. If that doesn't compile, you'll have
|
||||
to use jmemname.c; be sure to adjust select_file_name() for local conditions.
|
||||
You may also need to change unlink() to remove() in close_backing_store().
|
||||
|
||||
Except with jmemnobs.c, you need to adjust the DEFAULT_MAX_MEM setting to a
|
||||
reasonable value for your system (either by adding a #define for
|
||||
Except with jmemnobs.c or jmemmac.c, you need to adjust the DEFAULT_MAX_MEM
|
||||
setting to a reasonable value for your system (either by adding a #define for
|
||||
DEFAULT_MAX_MEM to jconfig.h, or by adding a -D switch to the Makefile).
|
||||
This value limits the amount of data space the program will attempt to
|
||||
allocate. Code and static data space isn't counted, so the actual memory
|
||||
@ -300,7 +321,7 @@ As a quick test of functionality we've included a small sample image in
|
||||
several forms:
|
||||
testorig.jpg Starting point for the djpeg tests.
|
||||
testimg.ppm The output of djpeg testorig.jpg
|
||||
testimg.gif The output of djpeg -gif testorig.jpg
|
||||
testimg.bmp The output of djpeg -bmp -colors 256 testorig.jpg
|
||||
testimg.jpg The output of cjpeg testimg.ppm
|
||||
testprog.jpg Progressive-mode equivalent of testorig.jpg.
|
||||
testimgp.jpg The output of cjpeg -progressive -optimize testimg.ppm
|
||||
@ -336,10 +357,10 @@ check fails, try recompiling with USE_SETMODE or USE_FDOPEN defined.
|
||||
If it still doesn't work, better use two-file style.
|
||||
|
||||
If you chose a memory manager other than jmemnobs.c, you should test that
|
||||
temporary-file usage works. Try "djpeg -gif -max 0 testorig.jpg" and make
|
||||
sure its output matches testimg.gif. If you have any really large images
|
||||
handy, try compressing them with -optimize and/or decompressing with -gif to
|
||||
make sure your DEFAULT_MAX_MEM setting is not too large.
|
||||
temporary-file usage works. Try "djpeg -bmp -colors 256 -max 0 testorig.jpg"
|
||||
and make sure its output matches testimg.bmp. If you have any really large
|
||||
images handy, try compressing them with -optimize and/or decompressing with
|
||||
-colors 256 to make sure your DEFAULT_MAX_MEM setting is not too large.
|
||||
|
||||
NOTE: this is far from an exhaustive test of the JPEG software; some modules,
|
||||
such as 1-pass color quantization, are not exercised at all. It's just a
|
||||
@ -354,7 +375,7 @@ Once you're done with the above steps, you can install the software by
|
||||
copying the executable files (cjpeg, djpeg, jpegtran, rdjpgcom, and wrjpgcom)
|
||||
to wherever you normally install programs. On Unix systems, you'll also want
|
||||
to put the man pages (cjpeg.1, djpeg.1, jpegtran.1, rdjpgcom.1, wrjpgcom.1)
|
||||
in the man-page directory. The canned makefiles don't support this step
|
||||
in the man-page directory. The pre-fab makefiles don't support this step
|
||||
since there's such a wide variety of installation procedures on different
|
||||
systems.
|
||||
|
||||
@ -367,8 +388,13 @@ to see where configure thought the files should go. You may need to edit
|
||||
the Makefile, particularly if your system's conventions for man page
|
||||
filenames don't match what configure expects.
|
||||
|
||||
If you want to install the library file libjpeg.a and the include files j*.h
|
||||
(for use in compiling other programs besides the IJG ones), then say
|
||||
If you want to install the IJG library itself, for use in compiling other
|
||||
programs besides ours, then you need to put the four include files
|
||||
jpeglib.h jerror.h jconfig.h jmorecfg.h
|
||||
into your include-file directory, and put the library file libjpeg.a
|
||||
(extension may vary depending on system) wherever library files go.
|
||||
If you generated a Makefile with "configure", it will do what it thinks
|
||||
is the right thing if you say
|
||||
make install-lib
|
||||
|
||||
|
||||
@ -423,8 +449,8 @@ The PPM reader (rdppm.c) can read 12-bit data from either text-format or
|
||||
binary-format PPM and PGM files. Binary-format PPM/PGM files which have a
|
||||
maxval greater than 255 are assumed to use 2 bytes per sample, LSB first
|
||||
(little-endian order). As of early 1995, 2-byte binary format is not
|
||||
officially supported by the PBMPLUS library, but it is expected that the
|
||||
next release of PBMPLUS will support it. Note that the PPM reader will
|
||||
officially supported by the PBMPLUS library, but it is expected that a
|
||||
future release of PBMPLUS will support it. Note that the PPM reader will
|
||||
read files of any maxval regardless of the BITS_IN_JSAMPLE setting; incoming
|
||||
data is automatically rescaled to either maxval=255 or maxval=4095 as
|
||||
appropriate for the cjpeg bit depth.
|
||||
@ -565,19 +591,19 @@ Atari ST/STE/TT:
|
||||
Copy the project files makcjpeg.st, makdjpeg.st, maktjpeg.st, and makljpeg.st
|
||||
to cjpeg.prj, djpeg.prj, jpegtran.prj, and libjpeg.prj respectively. The
|
||||
project files should work as-is with Pure C. For Turbo C, change library
|
||||
filenames "PC..." to "TC..." in each project file. Note that libjpeg.prj
|
||||
filenames "pc..." to "tc..." in each project file. Note that libjpeg.prj
|
||||
selects jmemansi.c as the recommended memory manager. You'll probably want to
|
||||
adjust the DEFAULT_MAX_MEM setting --- you want it to be a couple hundred K
|
||||
less than your normal free memory. Put "#define DEFAULT_MAX_MEM nnnn" into
|
||||
jconfig.h to do this.
|
||||
|
||||
To use the 68881/68882 coprocessor for the floating point DCT, add the
|
||||
compiler option "-8" to the project files and replace PCFLTLIB.LIB with
|
||||
PC881LIB.LIB in cjpeg.prj and djpeg.prj. Or if you don't have a
|
||||
compiler option "-8" to the project files and replace pcfltlib.lib with
|
||||
pc881lib.lib in cjpeg.prj and djpeg.prj. Or if you don't have a
|
||||
coprocessor, you may prefer to remove the float DCT code by undefining
|
||||
DCT_FLOAT_SUPPORTED in jmorecfg.h (since without a coprocessor, the float
|
||||
code will be too slow to be useful). In that case, you can delete
|
||||
PCFLTLIB.LIB from the project files.
|
||||
pcfltlib.lib from the project files.
|
||||
|
||||
Note that you must make libjpeg.lib before making cjpeg.ttp, djpeg.ttp,
|
||||
or jpegtran.ttp. You'll have to perform the self-test by hand.
|
||||
@ -627,38 +653,69 @@ to A.08.07. If you get complaints about "not a typedef name", you'll have to
|
||||
use makefile.unix, or run configure without the CC option.
|
||||
|
||||
|
||||
Macintosh, MPW:
|
||||
Macintosh, generic comments:
|
||||
|
||||
We don't directly support MPW in the current release, but Larry Rosenstein
|
||||
ported an earlier version of the IJG code without very much trouble. There's
|
||||
useful notes and conversion scripts in his kit for porting PBMPLUS to MPW.
|
||||
You can obtain the kit by FTP to ftp.apple.com, files /pub/lsr/pbmplus-port*.
|
||||
The supplied user-interface files (cjpeg.c, djpeg.c, etc) are set up to
|
||||
provide a Unix-style command line interface. You can use this interface on
|
||||
the Mac by means of the ccommand() library routine provided by Metrowerks
|
||||
CodeWarrior or Think C. This is only appropriate for testing the library,
|
||||
however; to make a user-friendly equivalent of cjpeg/djpeg you'd really want
|
||||
to develop a Mac-style user interface. There isn't a complete example
|
||||
available at the moment, but there are some helpful starting points:
|
||||
1. Sam Bushell's free "To JPEG" applet provides drag-and-drop conversion to
|
||||
JPEG under System 7 and later. This only illustrates how to use the
|
||||
compression half of the library, but it does a very nice job of that part.
|
||||
The CodeWarrior source code is available from http://www.pobox.com/~jsam.
|
||||
2. Jim Brunner prepared a Mac-style user interface for both compression and
|
||||
decompression. Unfortunately, it hasn't been updated since IJG v4, and
|
||||
the library's API has changed considerably since then. Still it may be of
|
||||
some help, particularly as a guide to compiling the IJG code under Think C.
|
||||
Jim's code is available from the Info-Mac archives, at sumex-aim.stanford.edu
|
||||
or mirrors thereof; see file /info-mac/dev/src/jpeg-convert-c.hqx.
|
||||
|
||||
jmemmac.c is the recommended memory manager back end for Macintosh. It uses
|
||||
NewPtr/DisposePtr instead of malloc/free, and has a Mac-specific
|
||||
implementation of jpeg_mem_available(). It also creates temporary files that
|
||||
follow Mac conventions. (That part of the code relies on System-7-or-later OS
|
||||
functions. See the comments in jmemmac.c if you need to run it on System 6.)
|
||||
NOTE that USE_MAC_MEMMGR must be defined in jconfig.h to use jmemmac.c.
|
||||
|
||||
You can also use jmemnobs.c, if you don't care about handling images larger
|
||||
than available memory. If you use any memory manager back end other than
|
||||
jmemmac.c, we recommend replacing "malloc" and "free" by "NewPtr" and
|
||||
"DisposePtr", because Mac C libraries often have peculiar implementations of
|
||||
malloc/free. (For instance, free() may not return the freed space to the
|
||||
Mac Memory Manager. This is undesirable for the IJG code because jmemmgr.c
|
||||
already clumps space requests.)
|
||||
|
||||
|
||||
Macintosh, Metrowerks CodeWarrior:
|
||||
|
||||
Metrowerks release DR2 has problems with the IJG code; don't use it. Release
|
||||
DR3.5 or later should be OK.
|
||||
|
||||
The command-line-style interface can be used by defining USE_CCOMMAND and
|
||||
TWO_FILE_COMMANDLINE (see next entry for more details).
|
||||
The Unix-command-line-style interface can be used by defining USE_CCOMMAND.
|
||||
You'll also need to define TWO_FILE_COMMANDLINE to avoid stdin/stdout.
|
||||
This means that when using the cjpeg/djpeg programs, you'll have to type the
|
||||
input and output file names in the "Arguments" text-edit box, rather than
|
||||
using the file radio buttons. (Perhaps USE_FDOPEN or USE_SETMODE would
|
||||
eliminate the problem, but I haven't heard from anyone who's tried it.)
|
||||
|
||||
On 680x0 Macs, Metrowerks defines type "double" as a 10-byte IEEE extended
|
||||
float. jmemmgr.c won't like this: it wants sizeof(ALIGN_TYPE) to be a power
|
||||
of 2. Add "#define ALIGN_TYPE long" to jconfig.h to eliminate the complaint.
|
||||
|
||||
The supplied configuration file jconfig.mac can be used for your jconfig.h;
|
||||
it includes all the recommended symbol definitions. If you have AppleScript
|
||||
installed, you can run the supplied script makeproj.mac to create CodeWarrior
|
||||
project files for the library and the testbed applications, then build the
|
||||
library and applications. (Thanks to Dan Sears and Don Agro for this nifty
|
||||
hack, which saves us from trying to maintain CodeWarrior project files as part
|
||||
of the IJG distribution...)
|
||||
|
||||
|
||||
Macintosh, Think C:
|
||||
|
||||
The supplied user-interface files (cjpeg.c and djpeg.c) are set up to provide
|
||||
a Unix-style command line interface. You can use this interface on the Mac
|
||||
by means of Think's ccommand() library routine. However, a much better
|
||||
Mac-style user interface has been prepared by Jim Brunner. You can obtain
|
||||
the additional source code needed for that user interface by FTP to
|
||||
sumex-aim.stanford.edu, file /info-mac/dev/src/jpeg-convert-c.hqx. Jim's
|
||||
documentation also includes more detailed build instructions for Think C.
|
||||
(Jim is working on updating this code to work with v5 of the IJG library,
|
||||
but it wasn't ready as of v5 release time. Should be out before too long.)
|
||||
The documentation in Jim Brunner's "JPEG Convert" source code (see above)
|
||||
includes detailed build instructions for Think C; it's probably somewhat
|
||||
out of date for the current release, but may be helpful.
|
||||
|
||||
If you want to build the minimal command line version, proceed as follows.
|
||||
You'll have to prepare project files for the programs; we don't include any
|
||||
@ -674,6 +731,9 @@ On 680x0 Macs, Think C defines type "double" as a 12-byte IEEE extended float.
|
||||
jmemmgr.c won't like this: it wants sizeof(ALIGN_TYPE) to be a power of 2.
|
||||
Add "#define ALIGN_TYPE long" to jconfig.h to eliminate the complaint.
|
||||
|
||||
jconfig.mac should work as a jconfig.h configuration file for Think C,
|
||||
but the makeproj.mac AppleScript script is specific to CodeWarrior. Sorry.
|
||||
|
||||
|
||||
MIPS R3000:
|
||||
|
||||
@ -684,7 +744,7 @@ Note that the R3000 chip is found in workstations from DEC and others.
|
||||
|
||||
MS-DOS, generic comments for 16-bit compilers:
|
||||
|
||||
The IJG code is designed to be compiled in 80x86 "small" or "medium" memory
|
||||
The IJG code is designed to work well in 80x86 "small" or "medium" memory
|
||||
models (i.e., data pointers are 16 bits unless explicitly declared "far";
|
||||
code pointers can be either size). You may be able to use small model to
|
||||
compile cjpeg or djpeg by itself, but you will probably have to use medium
|
||||
@ -700,7 +760,7 @@ The DOS-specific memory manager, jmemdos.c, should be used if possible.
|
||||
It needs some assembly-code routines which are in jmemdosa.asm; make sure
|
||||
your makefile assembles that file and includes it in the library. If you
|
||||
don't have a suitable assembler, you can get pre-assembled object files for
|
||||
jmemdosa by FTP from ftp.uu.net: graphics/jpeg/jdosaobj.zip. (DOS-oriented
|
||||
jmemdosa by FTP from ftp.uu.net:/graphics/jpeg/jdosaobj.zip. (DOS-oriented
|
||||
distributions of the IJG source code often include these object files.)
|
||||
|
||||
When using jmemdos.c, jconfig.h must define USE_MSDOS_MEMMGR and must set
|
||||
@ -757,23 +817,22 @@ jconfig.bcc already includes #define USE_SETMODE to make this work.
|
||||
(fdopen does not work correctly.)
|
||||
|
||||
|
||||
MS-DOS, DJGPP:
|
||||
|
||||
Use a recent version of DJGPP (1.11 or better). If you prefer two-file
|
||||
command line style, change the supplied jconfig.dj to define
|
||||
TWO_FILE_COMMANDLINE. makefile.dj is set up to generate only COFF files
|
||||
(cjpeg, djpeg, etc) when you say make. After testing, say "make exe" to
|
||||
make executables with stub.exe, or "make standalone" if you want executables
|
||||
that include go32. You will probably need to tweak the makefile's pointer to
|
||||
go32.exe to do "make standalone".
|
||||
|
||||
|
||||
MS-DOS, Microsoft C:
|
||||
|
||||
makefile.mc6 works with Microsoft C, DOS Visual C++, etc. It should only
|
||||
be used if you want to build a 16-bit (small or medium memory model) program.
|
||||
|
||||
If you want one-file command line style, just undefine TWO_FILE_COMMANDLINE.
|
||||
jconfig.mc6 already includes #define USE_SETMODE to make this work.
|
||||
(fdopen does not work correctly.)
|
||||
|
||||
Note that this makefile assumes that the working copy of itself is called
|
||||
"makefile". If you want to call it something else, say "makefile.mak",
|
||||
be sure to adjust the dependency line that reads "$(RFILE) : makefile".
|
||||
Otherwise the make will fail because it doesn't know how to create "makefile".
|
||||
Worse, some releases of Microsoft's make utilities give an incorrect error
|
||||
message in this situation.
|
||||
|
||||
Old versions of MS C fail with an "out of macro expansion space" error
|
||||
because they can't cope with the macro TRACEMS8 (defined in jerror.h).
|
||||
If this happens to you, the easiest solution is to change TRACEMS8 to
|
||||
@ -784,11 +843,12 @@ Original MS C 6.0 is very buggy; it compiles incorrect code unless you turn
|
||||
off optimization entirely (remove -O from CFLAGS). 6.00A is better, but it
|
||||
still generates bad code if you enable loop optimizations (-Ol or -Ox).
|
||||
|
||||
MS C 8.0 reportedly fails to compile jquant1.c if optimization is turned off
|
||||
(yes, off).
|
||||
MS C 8.0 crashes when compiling jquant1.c with optimization switch /Oo ...
|
||||
which is on by default. To work around this bug, compile that one file
|
||||
with /Oo-.
|
||||
|
||||
|
||||
Microsoft Windows (all versions):
|
||||
Microsoft Windows (all versions), generic comments:
|
||||
|
||||
Some Windows system include files define typedef boolean as "unsigned char".
|
||||
The IJG code also defines typedef boolean, but we make it "int" by default.
|
||||
@ -796,24 +856,104 @@ This doesn't affect the IJG programs because we don't import those Windows
|
||||
include files. But if you use the JPEG library in your own program, and some
|
||||
of your program's files import one definition of boolean while some import the
|
||||
other, you can get all sorts of mysterious problems. A good preventive step
|
||||
is to change jmorecfg.h to define boolean as unsigned char. We recommend
|
||||
making that part of jmorecfg.h read like this:
|
||||
is to make the IJG library use "unsigned char" for boolean. To do that,
|
||||
add something like this to your jconfig.h file:
|
||||
/* Define "boolean" as unsigned char, not int, per Windows custom */
|
||||
#ifndef __RPCNDR_H__ /* don't conflict if rpcndr.h already read */
|
||||
typedef unsigned char boolean;
|
||||
#endif
|
||||
#define HAVE_BOOLEAN /* prevent jmorecfg.h from redefining it */
|
||||
(This is already in jconfig.vc, by the way.)
|
||||
|
||||
windef.h contains the declarations
|
||||
#define far
|
||||
#define FAR far
|
||||
Since jmorecfg.h tries to define FAR as empty, you may get a compiler
|
||||
warning if you include both jpeglib.h and windef.h (which windows.h
|
||||
includes). To suppress the warning, you can put "#ifndef FAR"/"#endif"
|
||||
around the line "#define FAR" in jmorecfg.h.
|
||||
|
||||
When using the library in a Windows application, you will almost certainly
|
||||
want to modify or replace the error handler module jerror.c, since our
|
||||
default error handler does a couple of inappropriate things:
|
||||
1. it tries to write error and warning messages on stderr;
|
||||
2. in event of a fatal error, it exits by calling exit().
|
||||
|
||||
A simple stopgap solution for problem 1 is to replace the line
|
||||
fprintf(stderr, "%s\n", buffer);
|
||||
(in output_message in jerror.c) with
|
||||
MessageBox(GetActiveWindow(),buffer,"JPEG Error",MB_OK|MB_ICONERROR);
|
||||
It's highly recommended that you at least do that much, since otherwise
|
||||
error messages will disappear into nowhere. (Beginning with IJG v6b, this
|
||||
code is already present in jerror.c; just define USE_WINDOWS_MESSAGEBOX in
|
||||
jconfig.h to enable it.)
|
||||
|
||||
The proper solution for problem 2 is to return control to your calling
|
||||
application after a library error. This can be done with the setjmp/longjmp
|
||||
technique discussed in libjpeg.doc and illustrated in example.c. (NOTE:
|
||||
some older Windows C compilers provide versions of setjmp/longjmp that
|
||||
don't actually work under Windows. You may need to use the Windows system
|
||||
functions Catch and Throw instead.)
|
||||
|
||||
The recommended memory manager under Windows is jmemnobs.c; in other words,
|
||||
let Windows do any virtual memory management needed. You should NOT use
|
||||
jmemdos.c nor jmemdosa.asm under Windows.
|
||||
|
||||
For Windows 3.1, we recommend compiling in medium or large memory model;
|
||||
for newer Windows versions, use a 32-bit flat memory model. (See the MS-DOS
|
||||
sections above for more info about memory models.) In the 16-bit memory
|
||||
models only, you'll need to put
|
||||
#define MAX_ALLOC_CHUNK 65520L /* Maximum request to malloc() */
|
||||
into jconfig.h to limit allocation chunks to 64Kb. (Without that, you'd
|
||||
have to use huge memory model, which slows things down unnecessarily.)
|
||||
jmemnobs.c works without modification in large or flat memory models, but to
|
||||
use medium model, you need to modify its jpeg_get_large and jpeg_free_large
|
||||
routines to allocate far memory. In any case, you might like to replace
|
||||
its calls to malloc and free with direct calls on Windows memory allocation
|
||||
functions.
|
||||
|
||||
You may also want to modify jdatasrc.c and jdatadst.c to use Windows file
|
||||
operations rather than fread/fwrite. This is only necessary if your C
|
||||
compiler doesn't provide a competent implementation of C stdio functions.
|
||||
|
||||
You might want to tweak the RGB_xxx macros in jmorecfg.h so that the library
|
||||
will accept or deliver color pixels in BGR sample order, not RGB; BGR order
|
||||
is usually more convenient under Windows. Note that this change will break
|
||||
the sample applications cjpeg/djpeg, but the library itself works fine.
|
||||
|
||||
|
||||
Many people want to convert the IJG library into a DLL. This is reasonably
|
||||
straightforward, but watch out for the following:
|
||||
|
||||
1. Don't try to compile as a DLL in small or medium memory model; use
|
||||
large model, or even better, 32-bit flat model. Many places in the IJG code
|
||||
assume the address of a local variable is an ordinary (not FAR) pointer;
|
||||
that isn't true in a medium-model DLL.
|
||||
|
||||
2. Microsoft C cannot pass file pointers between applications and DLLs.
|
||||
(See Microsoft Knowledge Base, PSS ID Number Q50336.) So jdatasrc.c and
|
||||
jdatadst.c don't work if you open a file in your application and then pass
|
||||
the pointer to the DLL. One workaround is to make jdatasrc.c/jdatadst.c
|
||||
part of your main application rather than part of the DLL.
|
||||
|
||||
3. You'll probably need to modify the macros GLOBAL() and EXTERN() to
|
||||
attach suitable linkage keywords to the exported routine names. Similarly,
|
||||
you'll want to modify METHODDEF() and JMETHOD() to ensure function pointers
|
||||
are declared in a way that lets application routines be called back through
|
||||
the function pointers. These macros are in jmorecfg.h. Typical definitions
|
||||
for a 16-bit DLL are:
|
||||
#define GLOBAL(type) type _far _pascal _loadds _export
|
||||
#define EXTERN(type) extern type _far _pascal _loadds
|
||||
#define METHODDEF(type) static type _far _pascal
|
||||
#define JMETHOD(type,methodname,arglist) \
|
||||
type (_far _pascal *methodname) arglist
|
||||
For a 32-bit DLL you may want something like
|
||||
#define GLOBAL(type) __declspec(dllexport) type
|
||||
#define EXTERN(type) extern __declspec(dllexport) type
|
||||
Although not all the GLOBAL routines are actually intended to be called by
|
||||
the application, the performance cost of making them all DLL entry points is
|
||||
negligible.
|
||||
|
||||
The unmodified IJG library presents a very C-specific application interface,
|
||||
so the resulting DLL is only usable from C or C++ applications. There has
|
||||
been some talk of writing wrapper code that would present a simpler interface
|
||||
@ -823,23 +963,85 @@ but hasn't been very high priority --- any volunteers out there?
|
||||
|
||||
Microsoft Windows, Borland C:
|
||||
|
||||
The provided jconfig.bcc should work OK in a 32-bit Windows environment,
|
||||
but you'll need to tweak it in a 16-bit environment (you'd need to define
|
||||
NEED_FAR_POINTERS and MAX_ALLOC_CHUNK). Beware that makefile.bcc will need
|
||||
alteration if you want to use it for Windows --- in particular, you should
|
||||
use jmemnobs.c not jmemdos.c under Windows.
|
||||
|
||||
Borland C++ 4.5 fails with an internal compiler error when trying to compile
|
||||
jdmerge.c. If enough people complain, perhaps Borland will fix it.
|
||||
In the meantime, you can work around the problem by undefining
|
||||
UPSAMPLE_MERGING_SUPPORTED in jmorecfg.h, at the price of losing most of the
|
||||
speedup from the "-nosmooth" decompression option. Alternatively, I'm told
|
||||
that replacing three or more uses of h2v1_merged_upsample()'s variable
|
||||
"range_limit" with direct references to "cinfo->sample_range_limit" makes
|
||||
the problem go away, though the routine is then a little slower than it
|
||||
should be. Pretty bizarre, especially since the very similar routine
|
||||
h2v2_merged_upsample doesn't trigger the bug.
|
||||
jdmerge.c in 32-bit mode. If enough people complain, perhaps Borland will fix
|
||||
it. In the meantime, the simplest known workaround is to add a redundant
|
||||
definition of the variable range_limit in h2v1_merged_upsample(), at the head
|
||||
of the block that handles odd image width (about line 268 in v6 jdmerge.c):
|
||||
/* If image width is odd, do the last output column separately */
|
||||
if (cinfo->output_width & 1) {
|
||||
register JSAMPLE * range_limit = cinfo->sample_range_limit; /* ADD THIS */
|
||||
cb = GETJSAMPLE(*inptr1);
|
||||
Pretty bizarre, especially since the very similar routine h2v2_merged_upsample
|
||||
doesn't trigger the bug.
|
||||
Recent reports suggest that this bug does not occur with "bcc32a" (the
|
||||
Pentium-optimized version of the compiler).
|
||||
|
||||
Another report from a user of Borland C 4.5 was that incorrect code (leading
|
||||
to a color shift in processed images) was produced if any of the following
|
||||
optimization switch combinations were used:
|
||||
-Ot -Og
|
||||
-Ot -Op
|
||||
-Ot -Om
|
||||
So try backing off on optimization if you see such a problem. (Are there
|
||||
several different releases all numbered "4.5"??)
|
||||
|
||||
|
||||
Microsoft Windows, Microsoft Visual C++:
|
||||
|
||||
jconfig.vc should work OK with any Microsoft compiler for a 32-bit memory
|
||||
model. makefile.vc is intended for command-line use. (If you are using
|
||||
the Developer Studio environment, you may prefer the DevStudio project
|
||||
files; see below.)
|
||||
|
||||
Some users feel that it's easier to call the library from C++ code if you
|
||||
force VC++ to treat the library as C++ code, which you can do by renaming
|
||||
all the *.c files to *.cpp (and adjusting the makefile to match). This
|
||||
avoids the need to put extern "C" { ... } around #include "jpeglib.h" in
|
||||
your C++ application.
|
||||
|
||||
|
||||
Microsoft Windows, Microsoft Developer Studio:
|
||||
|
||||
We include makefiles that should work as project files in DevStudio 4.2 or
|
||||
later. There is a library makefile that builds the IJG library as a static
|
||||
Win32 library, and an application makefile that builds the sample applications
|
||||
as Win32 console applications. (Even if you only want the library, we
|
||||
recommend building the applications so that you can run the self-test.)
|
||||
|
||||
To use:
|
||||
1. Copy jconfig.vc to jconfig.h, makelib.ds to jpeg.mak, and
|
||||
makeapps.ds to apps.mak. (Note that the renaming is critical!)
|
||||
2. Click on the .mak files to construct project workspaces.
|
||||
(If you are using DevStudio more recent than 4.2, you'll probably
|
||||
get a message saying that the makefiles are being updated.)
|
||||
3. Build the library project, then the applications project.
|
||||
4. Move the application .exe files from `app`\Release to an
|
||||
appropriate location on your path.
|
||||
5. To perform the self-test, execute the command line
|
||||
NMAKE /f makefile.vc test
|
||||
|
||||
|
||||
OS/2, Borland C++:
|
||||
|
||||
Watch out for optimization bugs in older Borland compilers; you may need
|
||||
to back off the optimization switch settings. See the comments in
|
||||
makefile.bcc.
|
||||
|
||||
|
||||
SGI:
|
||||
|
||||
Set "AR2= ar -ts" rather than "AR2= ranlib" in the Makefile. If you are
|
||||
using configure, you should say
|
||||
On some SGI systems, you may need to set "AR2= ar -ts" in the Makefile.
|
||||
If you are using configure, you can do this by saying
|
||||
./configure RANLIB='ar -ts'
|
||||
This change is not needed on all SGIs. Use it only if the make fails at the
|
||||
stage of linking the completed programs.
|
||||
|
||||
On the MIPS R4000 architecture (Indy, etc.), the compiler option "-mips2"
|
||||
reportedly speeds up the float DCT method substantially, enough to make it
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* jcapimin.c
|
||||
*
|
||||
* Copyright (C) 1994-1995, Thomas G. Lane.
|
||||
* 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.
|
||||
*
|
||||
@ -17,7 +17,6 @@
|
||||
*/
|
||||
|
||||
#define JPEG_INTERNALS
|
||||
#include "xp_core.h"/*defines of int32 ect*/
|
||||
#include "jinclude.h"
|
||||
#include "jpeglib.h"
|
||||
|
||||
@ -27,18 +26,31 @@
|
||||
* The error manager must already be set up (in case memory manager fails).
|
||||
*/
|
||||
|
||||
GLOBAL JRI_PUBLIC_API(void)
|
||||
jpeg_create_compress (j_compress_ptr cinfo)
|
||||
GLOBAL(void)
|
||||
jpeg_CreateCompress (j_compress_ptr cinfo, int version, size_t structsize)
|
||||
{
|
||||
int16 i;
|
||||
int i;
|
||||
|
||||
/* For debugging purposes, zero the whole master structure.
|
||||
* But error manager pointer is already there, so save and restore it.
|
||||
/* Guard against version mismatches between library and caller. */
|
||||
cinfo->mem = NULL; /* so jpeg_destroy knows mem mgr not called */
|
||||
if (version != JPEG_LIB_VERSION)
|
||||
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);
|
||||
|
||||
/* For debugging purposes, we zero the whole master structure.
|
||||
* But the application has already set the err pointer, and may have set
|
||||
* client_data, so we have to save and restore those fields.
|
||||
* Note: if application hasn't set client_data, tools like Purify may
|
||||
* complain here.
|
||||
*/
|
||||
{
|
||||
struct jpeg_error_mgr * err = cinfo->err;
|
||||
void * client_data = cinfo->client_data; /* ignore Purify complaint here */
|
||||
MEMZERO(cinfo, SIZEOF(struct jpeg_compress_struct));
|
||||
cinfo->err = err;
|
||||
cinfo->client_data = client_data;
|
||||
}
|
||||
cinfo->is_decompressor = FALSE;
|
||||
|
||||
@ -59,6 +71,8 @@ jpeg_create_compress (j_compress_ptr cinfo)
|
||||
cinfo->ac_huff_tbl_ptrs[i] = NULL;
|
||||
}
|
||||
|
||||
cinfo->script_space = NULL;
|
||||
|
||||
cinfo->input_gamma = 1.0; /* in case application forgets */
|
||||
|
||||
/* OK, I'm ready */
|
||||
@ -70,7 +84,7 @@ jpeg_create_compress (j_compress_ptr cinfo)
|
||||
* Destruction of a JPEG compression object
|
||||
*/
|
||||
|
||||
GLOBAL JRI_PUBLIC_API(void)
|
||||
GLOBAL(void)
|
||||
jpeg_destroy_compress (j_compress_ptr cinfo)
|
||||
{
|
||||
jpeg_destroy((j_common_ptr) cinfo); /* use common routine */
|
||||
@ -82,7 +96,7 @@ jpeg_destroy_compress (j_compress_ptr cinfo)
|
||||
* but don't destroy the object itself.
|
||||
*/
|
||||
|
||||
GLOBAL void
|
||||
GLOBAL(void)
|
||||
jpeg_abort_compress (j_compress_ptr cinfo)
|
||||
{
|
||||
jpeg_abort((j_common_ptr) cinfo); /* use common routine */
|
||||
@ -101,10 +115,10 @@ jpeg_abort_compress (j_compress_ptr cinfo)
|
||||
* jcparam.o would be linked whether the application used it or not.
|
||||
*/
|
||||
|
||||
GLOBAL void
|
||||
GLOBAL(void)
|
||||
jpeg_suppress_tables (j_compress_ptr cinfo, boolean suppress)
|
||||
{
|
||||
int16 i;
|
||||
int i;
|
||||
JQUANT_TBL * qtbl;
|
||||
JHUFF_TBL * htbl;
|
||||
|
||||
@ -129,7 +143,7 @@ jpeg_suppress_tables (j_compress_ptr cinfo, boolean suppress)
|
||||
* work including most of the actual output.
|
||||
*/
|
||||
|
||||
GLOBAL JRI_PUBLIC_API(void)
|
||||
GLOBAL(void)
|
||||
jpeg_finish_compress (j_compress_ptr cinfo)
|
||||
{
|
||||
JDIMENSION iMCU_row;
|
||||
@ -147,8 +161,8 @@ 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 = (int32) iMCU_row;
|
||||
cinfo->progress->pass_limit = (int32) cinfo->total_iMCU_rows;
|
||||
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;
|
||||
@ -174,9 +188,30 @@ jpeg_finish_compress (j_compress_ptr cinfo)
|
||||
* first call to jpeg_write_scanlines() or jpeg_write_raw_data().
|
||||
*/
|
||||
|
||||
GLOBAL void
|
||||
GLOBAL(void)
|
||||
jpeg_write_marker (j_compress_ptr cinfo, int marker,
|
||||
const JOCTET *dataptr, unsigned int datalen)
|
||||
{
|
||||
JMETHOD(void, write_marker_byte, (j_compress_ptr info, int val));
|
||||
|
||||
if (cinfo->next_scanline != 0 ||
|
||||
(cinfo->global_state != CSTATE_SCANNING &&
|
||||
cinfo->global_state != CSTATE_RAW_OK &&
|
||||
cinfo->global_state != CSTATE_WRCOEFS))
|
||||
ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
|
||||
|
||||
(*cinfo->marker->write_marker_header) (cinfo, marker, datalen);
|
||||
write_marker_byte = cinfo->marker->write_marker_byte; /* copy for speed */
|
||||
while (datalen--) {
|
||||
(*write_marker_byte) (cinfo, *dataptr);
|
||||
dataptr++;
|
||||
}
|
||||
}
|
||||
|
||||
/* Same, but piecemeal. */
|
||||
|
||||
GLOBAL(void)
|
||||
jpeg_write_m_header (j_compress_ptr cinfo, int marker, unsigned int datalen)
|
||||
{
|
||||
if (cinfo->next_scanline != 0 ||
|
||||
(cinfo->global_state != CSTATE_SCANNING &&
|
||||
@ -184,7 +219,13 @@ jpeg_write_marker (j_compress_ptr cinfo, int marker,
|
||||
cinfo->global_state != CSTATE_WRCOEFS))
|
||||
ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
|
||||
|
||||
(*cinfo->marker->write_any_marker) (cinfo, marker, dataptr, datalen);
|
||||
(*cinfo->marker->write_marker_header) (cinfo, marker, datalen);
|
||||
}
|
||||
|
||||
GLOBAL(void)
|
||||
jpeg_write_m_byte (j_compress_ptr cinfo, int val)
|
||||
{
|
||||
(*cinfo->marker->write_marker_byte) (cinfo, val);
|
||||
}
|
||||
|
||||
|
||||
@ -209,7 +250,7 @@ jpeg_write_marker (j_compress_ptr cinfo, int marker,
|
||||
* will not re-emit the tables unless it is passed write_all_tables=TRUE.
|
||||
*/
|
||||
|
||||
GLOBAL void
|
||||
GLOBAL(void)
|
||||
jpeg_write_tables (j_compress_ptr cinfo)
|
||||
{
|
||||
if (cinfo->global_state != CSTATE_START)
|
||||
@ -224,6 +265,16 @@ jpeg_write_tables (j_compress_ptr cinfo)
|
||||
(*cinfo->marker->write_tables_only) (cinfo);
|
||||
/* And clean up. */
|
||||
(*cinfo->dest->term_destination) (cinfo);
|
||||
/* We can use jpeg_abort to release memory. */
|
||||
jpeg_abort((j_common_ptr) cinfo);
|
||||
/*
|
||||
* In library releases up through v6a, we called jpeg_abort() here to free
|
||||
* any working memory allocated by the destination manager and marker
|
||||
* writer. Some applications had a problem with that: they allocated space
|
||||
* of their own from the library memory manager, and didn't want it to go
|
||||
* away during write_tables. So now we do nothing. This will cause a
|
||||
* memory leak if an app calls write_tables repeatedly without doing a full
|
||||
* compression cycle or otherwise resetting the JPEG object. However, that
|
||||
* seems less bad than unexpectedly freeing memory in the normal case.
|
||||
* An app that prefers the old behavior can call jpeg_abort for itself after
|
||||
* each call to jpeg_write_tables().
|
||||
*/
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* jcapistd.c
|
||||
*
|
||||
* Copyright (C) 1994-1995, Thomas G. Lane.
|
||||
* Copyright (C) 1994-1996, Thomas G. Lane.
|
||||
* This file is part of the Independent JPEG Group's software.
|
||||
* For conditions of distribution and use, see the accompanying README file.
|
||||
*
|
||||
@ -15,7 +15,6 @@
|
||||
*/
|
||||
|
||||
#define JPEG_INTERNALS
|
||||
#include "xp_core.h"/*defines of int32 ect*/
|
||||
#include "jinclude.h"
|
||||
#include "jpeglib.h"
|
||||
|
||||
@ -35,7 +34,7 @@
|
||||
* wrong thing.
|
||||
*/
|
||||
|
||||
GLOBAL JRI_PUBLIC_API(void)
|
||||
GLOBAL(void)
|
||||
jpeg_start_compress (j_compress_ptr cinfo, boolean write_all_tables)
|
||||
{
|
||||
if (cinfo->global_state != CSTATE_START)
|
||||
@ -74,7 +73,7 @@ jpeg_start_compress (j_compress_ptr cinfo, boolean write_all_tables)
|
||||
* when using a multiple-scanline buffer.
|
||||
*/
|
||||
|
||||
GLOBAL JRI_PUBLIC_API(JDIMENSION)
|
||||
GLOBAL(JDIMENSION)
|
||||
jpeg_write_scanlines (j_compress_ptr cinfo, JSAMPARRAY scanlines,
|
||||
JDIMENSION num_lines)
|
||||
{
|
||||
@ -87,8 +86,8 @@ jpeg_write_scanlines (j_compress_ptr cinfo, JSAMPARRAY scanlines,
|
||||
|
||||
/* Call progress monitor hook if present */
|
||||
if (cinfo->progress != NULL) {
|
||||
cinfo->progress->pass_counter = (int32) cinfo->next_scanline;
|
||||
cinfo->progress->pass_limit = (int32) cinfo->image_height;
|
||||
cinfo->progress->pass_counter = (long) cinfo->next_scanline;
|
||||
cinfo->progress->pass_limit = (long) cinfo->image_height;
|
||||
(*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
|
||||
}
|
||||
|
||||
@ -117,7 +116,7 @@ jpeg_write_scanlines (j_compress_ptr cinfo, JSAMPARRAY scanlines,
|
||||
* Processes exactly one iMCU row per call, unless suspended.
|
||||
*/
|
||||
|
||||
GLOBAL JDIMENSION
|
||||
GLOBAL(JDIMENSION)
|
||||
jpeg_write_raw_data (j_compress_ptr cinfo, JSAMPIMAGE data,
|
||||
JDIMENSION num_lines)
|
||||
{
|
||||
@ -132,8 +131,8 @@ jpeg_write_raw_data (j_compress_ptr cinfo, JSAMPIMAGE data,
|
||||
|
||||
/* Call progress monitor hook if present */
|
||||
if (cinfo->progress != NULL) {
|
||||
cinfo->progress->pass_counter = (int32) cinfo->next_scanline;
|
||||
cinfo->progress->pass_limit = (int32) cinfo->image_height;
|
||||
cinfo->progress->pass_counter = (long) cinfo->next_scanline;
|
||||
cinfo->progress->pass_limit = (long) cinfo->image_height;
|
||||
(*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* jccoefct.c
|
||||
*
|
||||
* Copyright (C) 1994-1995, Thomas G. Lane.
|
||||
* Copyright (C) 1994-1997, Thomas G. Lane.
|
||||
* This file is part of the Independent JPEG Group's software.
|
||||
* For conditions of distribution and use, see the accompanying README file.
|
||||
*
|
||||
@ -11,7 +11,6 @@
|
||||
*/
|
||||
|
||||
#define JPEG_INTERNALS
|
||||
#include "xp_core.h"/*defines of int32 ect*/
|
||||
#include "jinclude.h"
|
||||
#include "jpeglib.h"
|
||||
|
||||
@ -37,8 +36,8 @@ typedef struct {
|
||||
|
||||
JDIMENSION iMCU_row_num; /* iMCU row # within image */
|
||||
JDIMENSION mcu_ctr; /* counts MCUs processed in current row */
|
||||
int16 MCU_vert_offset; /* counts MCU rows within iMCU row */
|
||||
int16 MCU_rows_per_iMCU_row; /* number of such rows needed */
|
||||
int MCU_vert_offset; /* counts MCU rows within iMCU row */
|
||||
int MCU_rows_per_iMCU_row; /* number of such rows needed */
|
||||
|
||||
/* For single-pass compression, it's sufficient to buffer just one MCU
|
||||
* (although this may prove a bit slow in practice). We allocate a
|
||||
@ -59,17 +58,17 @@ typedef my_coef_controller * my_coef_ptr;
|
||||
|
||||
|
||||
/* Forward declarations */
|
||||
METHODDEF boolean compress_data
|
||||
METHODDEF(boolean) compress_data
|
||||
JPP((j_compress_ptr cinfo, JSAMPIMAGE input_buf));
|
||||
#ifdef FULL_COEF_BUFFER_SUPPORTED
|
||||
METHODDEF boolean compress_first_pass
|
||||
METHODDEF(boolean) compress_first_pass
|
||||
JPP((j_compress_ptr cinfo, JSAMPIMAGE input_buf));
|
||||
METHODDEF boolean compress_output
|
||||
METHODDEF(boolean) compress_output
|
||||
JPP((j_compress_ptr cinfo, JSAMPIMAGE input_buf));
|
||||
#endif
|
||||
|
||||
|
||||
LOCAL void
|
||||
LOCAL(void)
|
||||
start_iMCU_row (j_compress_ptr cinfo)
|
||||
/* Reset within-iMCU-row counters for a new row */
|
||||
{
|
||||
@ -97,7 +96,7 @@ start_iMCU_row (j_compress_ptr cinfo)
|
||||
* Initialize for a processing pass.
|
||||
*/
|
||||
|
||||
METHODDEF void
|
||||
METHODDEF(void)
|
||||
start_pass_coef (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
|
||||
{
|
||||
my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
|
||||
@ -136,18 +135,18 @@ start_pass_coef (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
|
||||
* per call, ie, v_samp_factor block rows for each component in the image.
|
||||
* Returns TRUE if the iMCU row is completed, FALSE if suspended.
|
||||
*
|
||||
* NB: input_buf contains a plane for each component in image.
|
||||
* For single pass, this is the same as the components in the scan.
|
||||
* NB: input_buf contains a plane for each component in image,
|
||||
* which we index according to the component's SOF position.
|
||||
*/
|
||||
|
||||
METHODDEF boolean
|
||||
METHODDEF(boolean)
|
||||
compress_data (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
|
||||
{
|
||||
my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
|
||||
JDIMENSION MCU_col_num; /* index of current MCU within row */
|
||||
JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
|
||||
JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
|
||||
int16 blkn, bi, ci, yindex, yoffset, blockcnt;
|
||||
int blkn, bi, ci, yindex, yoffset, blockcnt;
|
||||
JDIMENSION ypos, xpos;
|
||||
jpeg_component_info *compptr;
|
||||
|
||||
@ -176,7 +175,8 @@ compress_data (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
|
||||
if (coef->iMCU_row_num < last_iMCU_row ||
|
||||
yoffset+yindex < compptr->last_row_height) {
|
||||
(*cinfo->fdct->forward_DCT) (cinfo, compptr,
|
||||
input_buf[ci], coef->MCU_buffer[blkn],
|
||||
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. */
|
||||
@ -241,13 +241,13 @@ compress_data (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
|
||||
* at the scan-dependent variables (MCU dimensions, etc).
|
||||
*/
|
||||
|
||||
METHODDEF boolean
|
||||
METHODDEF(boolean)
|
||||
compress_first_pass (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
|
||||
{
|
||||
my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
|
||||
JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
|
||||
JDIMENSION blocks_across, MCUs_across, MCUindex;
|
||||
int16 bi, ci, h_samp_factor, block_row, block_rows, ndummy;
|
||||
int bi, ci, h_samp_factor, block_row, block_rows, ndummy;
|
||||
JCOEF lastDC;
|
||||
jpeg_component_info *compptr;
|
||||
JBLOCKARRAY buffer;
|
||||
@ -265,13 +265,13 @@ compress_first_pass (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
|
||||
block_rows = compptr->v_samp_factor;
|
||||
else {
|
||||
/* NB: can't use last_row_height here, since may not be set! */
|
||||
block_rows = (int16) (compptr->height_in_blocks % compptr->v_samp_factor);
|
||||
block_rows = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
|
||||
if (block_rows == 0) block_rows = compptr->v_samp_factor;
|
||||
}
|
||||
blocks_across = compptr->width_in_blocks;
|
||||
h_samp_factor = compptr->h_samp_factor;
|
||||
/* Count number of dummy blocks to be added at the right margin. */
|
||||
ndummy = (int16) (blocks_across % h_samp_factor);
|
||||
ndummy = (int) (blocks_across % h_samp_factor);
|
||||
if (ndummy > 0)
|
||||
ndummy = h_samp_factor - ndummy;
|
||||
/* Perform DCT for all non-dummy blocks in this iMCU row. Each call
|
||||
@ -337,12 +337,12 @@ compress_first_pass (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
|
||||
* NB: input_buf is ignored; it is likely to be a NULL pointer.
|
||||
*/
|
||||
|
||||
METHODDEF boolean
|
||||
METHODDEF(boolean)
|
||||
compress_output (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
|
||||
{
|
||||
my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
|
||||
JDIMENSION MCU_col_num; /* index of current MCU within row */
|
||||
int16 blkn, ci, xindex, yindex, yoffset;
|
||||
int blkn, ci, xindex, yindex, yoffset;
|
||||
JDIMENSION start_col;
|
||||
JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
|
||||
JBLOCKROW buffer_ptr;
|
||||
@ -401,7 +401,7 @@ compress_output (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
|
||||
* Initialize coefficient buffer controller.
|
||||
*/
|
||||
|
||||
GLOBAL void
|
||||
GLOBAL(void)
|
||||
jinit_c_coef_controller (j_compress_ptr cinfo, boolean need_full_buffer)
|
||||
{
|
||||
my_coef_ptr coef;
|
||||
@ -417,17 +417,17 @@ jinit_c_coef_controller (j_compress_ptr cinfo, boolean need_full_buffer)
|
||||
#ifdef FULL_COEF_BUFFER_SUPPORTED
|
||||
/* Allocate a full-image virtual array for each component, */
|
||||
/* padded to a multiple of samp_factor DCT blocks in each direction. */
|
||||
int16 ci;
|
||||
int ci;
|
||||
jpeg_component_info *compptr;
|
||||
|
||||
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
|
||||
ci++, compptr++) {
|
||||
coef->whole_image[ci] = (*cinfo->mem->request_virt_barray)
|
||||
((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE,
|
||||
(JDIMENSION) jround_up((int32) compptr->width_in_blocks,
|
||||
(int32) compptr->h_samp_factor),
|
||||
(JDIMENSION) jround_up((int32) compptr->height_in_blocks,
|
||||
(int32) compptr->v_samp_factor),
|
||||
(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
|
||||
@ -436,7 +436,7 @@ jinit_c_coef_controller (j_compress_ptr cinfo, boolean need_full_buffer)
|
||||
} else {
|
||||
/* We only need a single-MCU buffer. */
|
||||
JBLOCKROW buffer;
|
||||
int16 i;
|
||||
int i;
|
||||
|
||||
buffer = (JBLOCKROW)
|
||||
(*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* jccolor.c
|
||||
*
|
||||
* Copyright (C) 1991-1994, Thomas G. Lane.
|
||||
* Copyright (C) 1991-1996, Thomas G. Lane.
|
||||
* This file is part of the Independent JPEG Group's software.
|
||||
* For conditions of distribution and use, see the accompanying README file.
|
||||
*
|
||||
@ -9,7 +9,6 @@
|
||||
*/
|
||||
|
||||
#define JPEG_INTERNALS
|
||||
#include "xp_core.h"/*defines of int32 ect*/
|
||||
#include "jinclude.h"
|
||||
#include "jpeglib.h"
|
||||
|
||||
@ -20,7 +19,7 @@ typedef struct {
|
||||
struct jpeg_color_converter pub; /* public fields */
|
||||
|
||||
/* Private state for RGB->YCC conversion */
|
||||
int32 * rgb_ycc_tab; /* => table for RGB to YCbCr conversion */
|
||||
INT32 * rgb_ycc_tab; /* => table for RGB to YCbCr conversion */
|
||||
} my_color_converter;
|
||||
|
||||
typedef my_color_converter * my_cconvert_ptr;
|
||||
@ -57,9 +56,9 @@ typedef my_color_converter * my_cconvert_ptr;
|
||||
*/
|
||||
|
||||
#define SCALEBITS 16 /* speediest right-shift on some machines */
|
||||
#define CBCR_OFFSET ((int32) CENTERJSAMPLE << SCALEBITS)
|
||||
#define ONE_HALF ((int32) 1 << (SCALEBITS-1))
|
||||
#define FIX(x) ((int32) ((x) * (1L<<SCALEBITS) + 0.5))
|
||||
#define CBCR_OFFSET ((INT32) CENTERJSAMPLE << SCALEBITS)
|
||||
#define ONE_HALF ((INT32) 1 << (SCALEBITS-1))
|
||||
#define FIX(x) ((INT32) ((x) * (1L<<SCALEBITS) + 0.5))
|
||||
|
||||
/* We allocate one big table and divide it up into eight parts, instead of
|
||||
* doing eight alloc_small requests. This lets us use a single table base
|
||||
@ -83,17 +82,17 @@ typedef my_color_converter * my_cconvert_ptr;
|
||||
* Initialize for RGB->YCC colorspace conversion.
|
||||
*/
|
||||
|
||||
METHODDEF void
|
||||
METHODDEF(void)
|
||||
rgb_ycc_start (j_compress_ptr cinfo)
|
||||
{
|
||||
my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
|
||||
int32 * rgb_ycc_tab;
|
||||
int32 i;
|
||||
INT32 * rgb_ycc_tab;
|
||||
INT32 i;
|
||||
|
||||
/* Allocate and fill in the conversion tables. */
|
||||
cconvert->rgb_ycc_tab = rgb_ycc_tab = (int32 *)
|
||||
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;
|
||||
@ -127,14 +126,14 @@ rgb_ycc_start (j_compress_ptr cinfo)
|
||||
* offset required on that side.
|
||||
*/
|
||||
|
||||
METHODDEF void
|
||||
METHODDEF(void)
|
||||
rgb_ycc_convert (j_compress_ptr cinfo,
|
||||
JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
|
||||
JDIMENSION output_row, int num_rows)
|
||||
{
|
||||
my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
|
||||
register int16 r, g, b;
|
||||
register int32 * ctab = cconvert->rgb_ycc_tab;
|
||||
register int r, g, b;
|
||||
register INT32 * ctab = cconvert->rgb_ycc_tab;
|
||||
register JSAMPROW inptr;
|
||||
register JSAMPROW outptr0, outptr1, outptr2;
|
||||
register JDIMENSION col;
|
||||
@ -183,14 +182,14 @@ rgb_ycc_convert (j_compress_ptr cinfo,
|
||||
* We assume rgb_ycc_start has been called (we only use the Y tables).
|
||||
*/
|
||||
|
||||
METHODDEF void
|
||||
METHODDEF(void)
|
||||
rgb_gray_convert (j_compress_ptr cinfo,
|
||||
JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
|
||||
JDIMENSION output_row, int num_rows)
|
||||
{
|
||||
my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
|
||||
register int16 r, g, b;
|
||||
register int32 * ctab = cconvert->rgb_ycc_tab;
|
||||
register int r, g, b;
|
||||
register INT32 * ctab = cconvert->rgb_ycc_tab;
|
||||
register JSAMPROW inptr;
|
||||
register JSAMPROW outptr;
|
||||
register JDIMENSION col;
|
||||
@ -222,14 +221,14 @@ rgb_gray_convert (j_compress_ptr cinfo,
|
||||
* We assume rgb_ycc_start has been called.
|
||||
*/
|
||||
|
||||
METHODDEF void
|
||||
METHODDEF(void)
|
||||
cmyk_ycck_convert (j_compress_ptr cinfo,
|
||||
JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
|
||||
JDIMENSION output_row, int num_rows)
|
||||
{
|
||||
my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
|
||||
register int16 r, g, b;
|
||||
register int32 * ctab = cconvert->rgb_ycc_tab;
|
||||
register int r, g, b;
|
||||
register INT32 * ctab = cconvert->rgb_ycc_tab;
|
||||
register JSAMPROW inptr;
|
||||
register JSAMPROW outptr0, outptr1, outptr2, outptr3;
|
||||
register JDIMENSION col;
|
||||
@ -277,7 +276,7 @@ cmyk_ycck_convert (j_compress_ptr cinfo,
|
||||
* The source can be either plain grayscale or YCbCr (since Y == gray).
|
||||
*/
|
||||
|
||||
METHODDEF void
|
||||
METHODDEF(void)
|
||||
grayscale_convert (j_compress_ptr cinfo,
|
||||
JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
|
||||
JDIMENSION output_row, int num_rows)
|
||||
@ -286,7 +285,7 @@ grayscale_convert (j_compress_ptr cinfo,
|
||||
register JSAMPROW outptr;
|
||||
register JDIMENSION col;
|
||||
JDIMENSION num_cols = cinfo->image_width;
|
||||
int16 instride = cinfo->input_components;
|
||||
int instride = cinfo->input_components;
|
||||
|
||||
while (--num_rows >= 0) {
|
||||
inptr = *input_buf++;
|
||||
@ -306,7 +305,7 @@ grayscale_convert (j_compress_ptr cinfo,
|
||||
* We assume input_components == num_components.
|
||||
*/
|
||||
|
||||
METHODDEF void
|
||||
METHODDEF(void)
|
||||
null_convert (j_compress_ptr cinfo,
|
||||
JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
|
||||
JDIMENSION output_row, int num_rows)
|
||||
@ -314,8 +313,8 @@ null_convert (j_compress_ptr cinfo,
|
||||
register JSAMPROW inptr;
|
||||
register JSAMPROW outptr;
|
||||
register JDIMENSION col;
|
||||
register int16 ci;
|
||||
int16 nc = cinfo->num_components;
|
||||
register int ci;
|
||||
int nc = cinfo->num_components;
|
||||
JDIMENSION num_cols = cinfo->image_width;
|
||||
|
||||
while (--num_rows >= 0) {
|
||||
@ -338,7 +337,7 @@ null_convert (j_compress_ptr cinfo,
|
||||
* Empty method for start_pass.
|
||||
*/
|
||||
|
||||
METHODDEF void
|
||||
METHODDEF(void)
|
||||
null_method (j_compress_ptr cinfo)
|
||||
{
|
||||
/* no work needed */
|
||||
@ -349,7 +348,7 @@ null_method (j_compress_ptr cinfo)
|
||||
* Module initialization routine for input colorspace conversion.
|
||||
*/
|
||||
|
||||
GLOBAL void
|
||||
GLOBAL(void)
|
||||
jinit_color_converter (j_compress_ptr cinfo)
|
||||
{
|
||||
my_cconvert_ptr cconvert;
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* jcdctmgr.c
|
||||
*
|
||||
* Copyright (C) 1994-1995, Thomas G. Lane.
|
||||
* Copyright (C) 1994-1996, Thomas G. Lane.
|
||||
* This file is part of the Independent JPEG Group's software.
|
||||
* For conditions of distribution and use, see the accompanying README file.
|
||||
*
|
||||
@ -12,7 +12,6 @@
|
||||
*/
|
||||
|
||||
#define JPEG_INTERNALS
|
||||
#include "xp_core.h"/*defines of int32 ect*/
|
||||
#include "jinclude.h"
|
||||
#include "jpeglib.h"
|
||||
#include "jdct.h" /* Private declarations for DCT subsystem */
|
||||
@ -28,8 +27,7 @@ typedef struct {
|
||||
|
||||
/* The actual post-DCT divisors --- not identical to the quant table
|
||||
* entries, because of scaling (especially for an unnormalized DCT).
|
||||
* Each table is given in normal array order; note that this must
|
||||
* be converted from the zigzag order of the quantization tables.
|
||||
* Each table is given in normal array order.
|
||||
*/
|
||||
DCTELEM * divisors[NUM_QUANT_TBLS];
|
||||
|
||||
@ -52,11 +50,11 @@ typedef my_fdct_controller * my_fdct_ptr;
|
||||
* first scan. Hence all components should be examined here.
|
||||
*/
|
||||
|
||||
METHODDEF void
|
||||
METHODDEF(void)
|
||||
start_pass_fdctmgr (j_compress_ptr cinfo)
|
||||
{
|
||||
my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct;
|
||||
int16 ci, qtblno, i;
|
||||
int ci, qtblno, i;
|
||||
jpeg_component_info *compptr;
|
||||
JQUANT_TBL * qtbl;
|
||||
DCTELEM * dtbl;
|
||||
@ -84,7 +82,7 @@ start_pass_fdctmgr (j_compress_ptr cinfo)
|
||||
}
|
||||
dtbl = fdct->divisors[qtblno];
|
||||
for (i = 0; i < DCTSIZE2; i++) {
|
||||
dtbl[i] = ((DCTELEM) qtbl->quantval[jpeg_zigzag_order[i]]) << 3;
|
||||
dtbl[i] = ((DCTELEM) qtbl->quantval[i]) << 3;
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
@ -99,7 +97,7 @@ start_pass_fdctmgr (j_compress_ptr cinfo)
|
||||
*/
|
||||
#define CONST_BITS 14
|
||||
static const INT16 aanscales[DCTSIZE2] = {
|
||||
/* precomputed values scaled up by 14 bits: in natural order */
|
||||
/* 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,
|
||||
@ -119,7 +117,7 @@ start_pass_fdctmgr (j_compress_ptr cinfo)
|
||||
dtbl = fdct->divisors[qtblno];
|
||||
for (i = 0; i < DCTSIZE2; i++) {
|
||||
dtbl[i] = (DCTELEM)
|
||||
DESCALE(MULTIPLY16V16((INT32) qtbl->quantval[jpeg_zigzag_order[i]],
|
||||
DESCALE(MULTIPLY16V16((INT32) qtbl->quantval[i],
|
||||
(INT32) aanscales[i]),
|
||||
CONST_BITS-3);
|
||||
}
|
||||
@ -138,7 +136,7 @@ start_pass_fdctmgr (j_compress_ptr cinfo)
|
||||
* use a multiplication rather than a division.
|
||||
*/
|
||||
FAST_FLOAT * fdtbl;
|
||||
int16 row, col;
|
||||
int row, col;
|
||||
static const double aanscalefactor[DCTSIZE] = {
|
||||
1.0, 1.387039845, 1.306562965, 1.175875602,
|
||||
1.0, 0.785694958, 0.541196100, 0.275899379
|
||||
@ -154,7 +152,7 @@ start_pass_fdctmgr (j_compress_ptr cinfo)
|
||||
for (row = 0; row < DCTSIZE; row++) {
|
||||
for (col = 0; col < DCTSIZE; col++) {
|
||||
fdtbl[i] = (FAST_FLOAT)
|
||||
(1.0 / (((double) qtbl->quantval[jpeg_zigzag_order[i]] *
|
||||
(1.0 / (((double) qtbl->quantval[i] *
|
||||
aanscalefactor[row] * aanscalefactor[col] * 8.0)));
|
||||
i++;
|
||||
}
|
||||
@ -178,7 +176,7 @@ start_pass_fdctmgr (j_compress_ptr cinfo)
|
||||
* blocks. The quantized coefficients are returned in coef_blocks[].
|
||||
*/
|
||||
|
||||
METHODDEF void
|
||||
METHODDEF(void)
|
||||
forward_DCT (j_compress_ptr cinfo, jpeg_component_info * compptr,
|
||||
JSAMPARRAY sample_data, JBLOCKROW coef_blocks,
|
||||
JDIMENSION start_row, JDIMENSION start_col,
|
||||
@ -198,7 +196,7 @@ forward_DCT (j_compress_ptr cinfo, jpeg_component_info * compptr,
|
||||
/* Load data into workspace, applying unsigned->signed conversion */
|
||||
{ register DCTELEM *workspaceptr;
|
||||
register JSAMPROW elemptr;
|
||||
register int16 elemr;
|
||||
register int elemr;
|
||||
|
||||
workspaceptr = workspace;
|
||||
for (elemr = 0; elemr < DCTSIZE; elemr++) {
|
||||
@ -213,7 +211,7 @@ forward_DCT (j_compress_ptr cinfo, jpeg_component_info * compptr,
|
||||
*workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
|
||||
*workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
|
||||
#else
|
||||
{ register int16 elemc;
|
||||
{ register int elemc;
|
||||
for (elemc = DCTSIZE; elemc > 0; elemc--) {
|
||||
*workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
|
||||
}
|
||||
@ -227,7 +225,7 @@ forward_DCT (j_compress_ptr cinfo, jpeg_component_info * compptr,
|
||||
|
||||
/* Quantize/descale the coefficients, and store into coef_blocks[] */
|
||||
{ register DCTELEM temp, qval;
|
||||
register int16 i;
|
||||
register int i;
|
||||
register JCOEFPTR output_ptr = coef_blocks[bi];
|
||||
|
||||
for (i = 0; i < DCTSIZE2; i++) {
|
||||
@ -268,7 +266,7 @@ forward_DCT (j_compress_ptr cinfo, jpeg_component_info * compptr,
|
||||
|
||||
#ifdef DCT_FLOAT_SUPPORTED
|
||||
|
||||
METHODDEF void
|
||||
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,
|
||||
@ -288,7 +286,7 @@ forward_DCT_float (j_compress_ptr cinfo, jpeg_component_info * compptr,
|
||||
/* Load data into workspace, applying unsigned->signed conversion */
|
||||
{ register FAST_FLOAT *workspaceptr;
|
||||
register JSAMPROW elemptr;
|
||||
register int16 elemr;
|
||||
register int elemr;
|
||||
|
||||
workspaceptr = workspace;
|
||||
for (elemr = 0; elemr < DCTSIZE; elemr++) {
|
||||
@ -303,7 +301,7 @@ forward_DCT_float (j_compress_ptr cinfo, jpeg_component_info * compptr,
|
||||
*workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
|
||||
*workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
|
||||
#else
|
||||
{ register int16 elemc;
|
||||
{ register int elemc;
|
||||
for (elemc = DCTSIZE; elemc > 0; elemc--) {
|
||||
*workspaceptr++ = (FAST_FLOAT)
|
||||
(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
|
||||
@ -318,7 +316,7 @@ forward_DCT_float (j_compress_ptr cinfo, jpeg_component_info * compptr,
|
||||
|
||||
/* Quantize/descale the coefficients, and store into coef_blocks[] */
|
||||
{ register FAST_FLOAT temp;
|
||||
register int16 i;
|
||||
register int i;
|
||||
register JCOEFPTR output_ptr = coef_blocks[bi];
|
||||
|
||||
for (i = 0; i < DCTSIZE2; i++) {
|
||||
@ -330,7 +328,7 @@ forward_DCT_float (j_compress_ptr cinfo, jpeg_component_info * compptr,
|
||||
* 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) ((int16) (temp + (FAST_FLOAT) 16384.5) - 16384);
|
||||
output_ptr[i] = (JCOEF) ((int) (temp + (FAST_FLOAT) 16384.5) - 16384);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -343,11 +341,11 @@ forward_DCT_float (j_compress_ptr cinfo, jpeg_component_info * compptr,
|
||||
* Initialize FDCT manager.
|
||||
*/
|
||||
|
||||
GLOBAL void
|
||||
GLOBAL(void)
|
||||
jinit_forward_dct (j_compress_ptr cinfo)
|
||||
{
|
||||
my_fdct_ptr fdct;
|
||||
int16 i;
|
||||
int i;
|
||||
|
||||
fdct = (my_fdct_ptr)
|
||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
||||
|
270
jpeg/jchuff.c
270
jpeg/jchuff.c
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* jchuff.c
|
||||
*
|
||||
* Copyright (C) 1991-1995, Thomas G. Lane.
|
||||
* 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.
|
||||
*
|
||||
@ -15,7 +15,6 @@
|
||||
*/
|
||||
|
||||
#define JPEG_INTERNALS
|
||||
#include "xp_core.h"/*defines of int32 ect*/
|
||||
#include "jinclude.h"
|
||||
#include "jpeglib.h"
|
||||
#include "jchuff.h" /* Declarations shared with jcphuff.c */
|
||||
@ -28,9 +27,9 @@
|
||||
*/
|
||||
|
||||
typedef struct {
|
||||
int32 put_buffer; /* current bit-accumulation buffer */
|
||||
int16 put_bits; /* # of bits now in it */
|
||||
int16 last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
|
||||
INT32 put_buffer; /* current bit-accumulation buffer */
|
||||
int put_bits; /* # of bits now in it */
|
||||
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
|
||||
@ -59,16 +58,16 @@ typedef struct {
|
||||
savable_state saved; /* Bit buffer & DC state at start of MCU */
|
||||
|
||||
/* These fields are NOT loaded into local working state. */
|
||||
uint16 restarts_to_go; /* MCUs left in this restart interval */
|
||||
int16 next_restart_num; /* next restart number to write (0-7) */
|
||||
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) */
|
||||
c_derived_tbl * dc_derived_tbls[NUM_HUFF_TBLS];
|
||||
c_derived_tbl * ac_derived_tbls[NUM_HUFF_TBLS];
|
||||
|
||||
#ifdef ENTROPY_OPT_SUPPORTED /* Statistics tables for optimization */
|
||||
int32 * dc_count_ptrs[NUM_HUFF_TBLS];
|
||||
int32 * ac_count_ptrs[NUM_HUFF_TBLS];
|
||||
long * dc_count_ptrs[NUM_HUFF_TBLS];
|
||||
long * ac_count_ptrs[NUM_HUFF_TBLS];
|
||||
#endif
|
||||
} huff_entropy_encoder;
|
||||
|
||||
@ -87,13 +86,13 @@ typedef struct {
|
||||
|
||||
|
||||
/* Forward declarations */
|
||||
METHODDEF boolean encode_mcu_huff JPP((j_compress_ptr cinfo,
|
||||
JBLOCKROW *MCU_data));
|
||||
METHODDEF void finish_pass_huff JPP((j_compress_ptr cinfo));
|
||||
METHODDEF(boolean) encode_mcu_huff JPP((j_compress_ptr cinfo,
|
||||
JBLOCKROW *MCU_data));
|
||||
METHODDEF(void) finish_pass_huff JPP((j_compress_ptr cinfo));
|
||||
#ifdef ENTROPY_OPT_SUPPORTED
|
||||
METHODDEF boolean encode_mcu_gather JPP((j_compress_ptr cinfo,
|
||||
JBLOCKROW *MCU_data));
|
||||
METHODDEF void finish_pass_gather JPP((j_compress_ptr cinfo));
|
||||
METHODDEF(boolean) encode_mcu_gather JPP((j_compress_ptr cinfo,
|
||||
JBLOCKROW *MCU_data));
|
||||
METHODDEF(void) finish_pass_gather JPP((j_compress_ptr cinfo));
|
||||
#endif
|
||||
|
||||
|
||||
@ -103,11 +102,11 @@ METHODDEF void finish_pass_gather JPP((j_compress_ptr cinfo));
|
||||
* just count the Huffman symbols used and generate Huffman code tables.
|
||||
*/
|
||||
|
||||
METHODDEF void
|
||||
METHODDEF(void)
|
||||
start_pass_huff (j_compress_ptr cinfo, boolean gather_statistics)
|
||||
{
|
||||
huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
|
||||
int16 ci, dctbl, actbl;
|
||||
int ci, dctbl, actbl;
|
||||
jpeg_component_info * compptr;
|
||||
|
||||
if (gather_statistics) {
|
||||
@ -126,35 +125,33 @@ start_pass_huff (j_compress_ptr cinfo, boolean gather_statistics)
|
||||
compptr = cinfo->cur_comp_info[ci];
|
||||
dctbl = compptr->dc_tbl_no;
|
||||
actbl = compptr->ac_tbl_no;
|
||||
/* Make sure requested tables are present */
|
||||
/* (In gather mode, tables need not be allocated yet) */
|
||||
if (dctbl < 0 || dctbl >= NUM_HUFF_TBLS ||
|
||||
(cinfo->dc_huff_tbl_ptrs[dctbl] == NULL && !gather_statistics))
|
||||
ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, dctbl);
|
||||
if (actbl < 0 || actbl >= NUM_HUFF_TBLS ||
|
||||
(cinfo->ac_huff_tbl_ptrs[actbl] == NULL && !gather_statistics))
|
||||
ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, actbl);
|
||||
if (gather_statistics) {
|
||||
#ifdef ENTROPY_OPT_SUPPORTED
|
||||
/* Check for invalid table indexes */
|
||||
/* (make_c_derived_tbl does this in the other path) */
|
||||
if (dctbl < 0 || dctbl >= NUM_HUFF_TBLS)
|
||||
ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, dctbl);
|
||||
if (actbl < 0 || actbl >= NUM_HUFF_TBLS)
|
||||
ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, actbl);
|
||||
/* Allocate and zero the statistics tables */
|
||||
/* Note that jpeg_gen_optimal_table expects 257 entries in each table! */
|
||||
if (entropy->dc_count_ptrs[dctbl] == NULL)
|
||||
entropy->dc_count_ptrs[dctbl] = (int32 *)
|
||||
entropy->dc_count_ptrs[dctbl] = (long *)
|
||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
||||
257 * SIZEOF(int32));
|
||||
MEMZERO(entropy->dc_count_ptrs[dctbl], 257 * SIZEOF(int32));
|
||||
257 * SIZEOF(long));
|
||||
MEMZERO(entropy->dc_count_ptrs[dctbl], 257 * SIZEOF(long));
|
||||
if (entropy->ac_count_ptrs[actbl] == NULL)
|
||||
entropy->ac_count_ptrs[actbl] = (int32 *)
|
||||
entropy->ac_count_ptrs[actbl] = (long *)
|
||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
||||
257 * SIZEOF(int32));
|
||||
MEMZERO(entropy->ac_count_ptrs[actbl], 257 * SIZEOF(int32));
|
||||
257 * SIZEOF(long));
|
||||
MEMZERO(entropy->ac_count_ptrs[actbl], 257 * SIZEOF(long));
|
||||
#endif
|
||||
} else {
|
||||
/* Compute derived values for Huffman tables */
|
||||
/* We may do this more than once for a table, but it's not expensive */
|
||||
jpeg_make_c_derived_tbl(cinfo, cinfo->dc_huff_tbl_ptrs[dctbl],
|
||||
jpeg_make_c_derived_tbl(cinfo, TRUE, dctbl,
|
||||
& entropy->dc_derived_tbls[dctbl]);
|
||||
jpeg_make_c_derived_tbl(cinfo, cinfo->ac_huff_tbl_ptrs[actbl],
|
||||
jpeg_make_c_derived_tbl(cinfo, FALSE, actbl,
|
||||
& entropy->ac_derived_tbls[actbl]);
|
||||
}
|
||||
/* Initialize DC predictions to 0 */
|
||||
@ -173,18 +170,33 @@ start_pass_huff (j_compress_ptr cinfo, boolean gather_statistics)
|
||||
|
||||
/*
|
||||
* Compute the derived values for a Huffman table.
|
||||
* This routine also performs some validation checks on the table.
|
||||
*
|
||||
* Note this is also used by jcphuff.c.
|
||||
*/
|
||||
|
||||
GLOBAL void
|
||||
jpeg_make_c_derived_tbl (j_compress_ptr cinfo, JHUFF_TBL * htbl,
|
||||
GLOBAL(void)
|
||||
jpeg_make_c_derived_tbl (j_compress_ptr cinfo, boolean isDC, int tblno,
|
||||
c_derived_tbl ** pdtbl)
|
||||
{
|
||||
JHUFF_TBL *htbl;
|
||||
c_derived_tbl *dtbl;
|
||||
int16 p, i, l, lastp, si;
|
||||
int p, i, l, lastp, si, maxsymbol;
|
||||
char huffsize[257];
|
||||
uint16 huffcode[257];
|
||||
uint16 code;
|
||||
unsigned int huffcode[257];
|
||||
unsigned int code;
|
||||
|
||||
/* Note that huffsize[] and huffcode[] are filled in code-length order,
|
||||
* paralleling the order of the symbols themselves in htbl->huffval[].
|
||||
*/
|
||||
|
||||
/* Find the input Huffman table */
|
||||
if (tblno < 0 || tblno >= NUM_HUFF_TBLS)
|
||||
ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno);
|
||||
htbl =
|
||||
isDC ? cinfo->dc_huff_tbl_ptrs[tblno] : cinfo->ac_huff_tbl_ptrs[tblno];
|
||||
if (htbl == NULL)
|
||||
ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno);
|
||||
|
||||
/* Allocate a workspace if we haven't already done so. */
|
||||
if (*pdtbl == NULL)
|
||||
@ -194,27 +206,34 @@ jpeg_make_c_derived_tbl (j_compress_ptr cinfo, JHUFF_TBL * htbl,
|
||||
dtbl = *pdtbl;
|
||||
|
||||
/* Figure C.1: make table of Huffman code length for each symbol */
|
||||
/* Note that this is in code-length order. */
|
||||
|
||||
p = 0;
|
||||
for (l = 1; l <= 16; l++) {
|
||||
for (i = 1; i <= (int16) htbl->bits[l]; i++)
|
||||
i = (int) htbl->bits[l];
|
||||
if (i < 0 || p + i > 256) /* protect against table overrun */
|
||||
ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
|
||||
while (i--)
|
||||
huffsize[p++] = (char) l;
|
||||
}
|
||||
huffsize[p] = 0;
|
||||
lastp = p;
|
||||
|
||||
/* Figure C.2: generate the codes themselves */
|
||||
/* Note that this is in code-length order. */
|
||||
|
||||
/* We also validate that the counts represent a legal Huffman code tree. */
|
||||
|
||||
code = 0;
|
||||
si = huffsize[0];
|
||||
p = 0;
|
||||
while (huffsize[p]) {
|
||||
while (((int16) huffsize[p]) == si) {
|
||||
while (((int) huffsize[p]) == si) {
|
||||
huffcode[p++] = code;
|
||||
code++;
|
||||
}
|
||||
/* code is now 1 more than the last code used for codelength si; but
|
||||
* it must still fit in si bits, since no code is allowed to be all ones.
|
||||
*/
|
||||
if (((INT32) code) >= (((INT32) 1) << si))
|
||||
ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
|
||||
code <<= 1;
|
||||
si++;
|
||||
}
|
||||
@ -222,14 +241,25 @@ jpeg_make_c_derived_tbl (j_compress_ptr cinfo, JHUFF_TBL * htbl,
|
||||
/* Figure C.3: generate encoding tables */
|
||||
/* These are code and size indexed by symbol value */
|
||||
|
||||
/* Set any codeless symbols to have code length 0;
|
||||
* this allows emit_bits to detect any attempt to emit such symbols.
|
||||
/* Set all codeless symbols to have code length 0;
|
||||
* this lets us detect duplicate VAL entries here, and later
|
||||
* allows emit_bits to detect any attempt to emit such symbols.
|
||||
*/
|
||||
MEMZERO(dtbl->ehufsi, SIZEOF(dtbl->ehufsi));
|
||||
|
||||
/* This is also a convenient place to check for out-of-range
|
||||
* and duplicated VAL entries. We allow 0..255 for AC symbols
|
||||
* but only 0..15 for DC. (We could constrain them further
|
||||
* based on data depth and mode, but this seems enough.)
|
||||
*/
|
||||
maxsymbol = isDC ? 15 : 255;
|
||||
|
||||
for (p = 0; p < lastp; p++) {
|
||||
dtbl->ehufco[htbl->huffval[p]] = huffcode[p];
|
||||
dtbl->ehufsi[htbl->huffval[p]] = huffsize[p];
|
||||
i = htbl->huffval[p];
|
||||
if (i < 0 || i > maxsymbol || dtbl->ehufsi[i])
|
||||
ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
|
||||
dtbl->ehufco[i] = huffcode[p];
|
||||
dtbl->ehufsi[i] = huffsize[p];
|
||||
}
|
||||
}
|
||||
|
||||
@ -244,7 +274,7 @@ jpeg_make_c_derived_tbl (j_compress_ptr cinfo, JHUFF_TBL * htbl,
|
||||
{ action; } }
|
||||
|
||||
|
||||
LOCAL boolean
|
||||
LOCAL(boolean)
|
||||
dump_buffer (working_state * state)
|
||||
/* Empty the output buffer; return TRUE if successful, FALSE if must suspend */
|
||||
{
|
||||
@ -268,19 +298,19 @@ dump_buffer (working_state * state)
|
||||
*/
|
||||
|
||||
INLINE
|
||||
LOCAL boolean
|
||||
emit_bits (working_state * state, uint16 code, int16 size)
|
||||
LOCAL(boolean)
|
||||
emit_bits (working_state * state, unsigned int code, int size)
|
||||
/* Emit some bits; return TRUE if successful, FALSE if must suspend */
|
||||
{
|
||||
/* This routine is heavily used, so it's worth coding tightly. */
|
||||
register int32 put_buffer = (int32) code;
|
||||
register int16 put_bits = state->cur.put_bits;
|
||||
register INT32 put_buffer = (INT32) code;
|
||||
register int put_bits = state->cur.put_bits;
|
||||
|
||||
/* if size is 0, caller used an invalid Huffman table entry */
|
||||
if (size == 0)
|
||||
ERREXIT(state->cinfo, JERR_HUFF_MISSING_CODE);
|
||||
|
||||
put_buffer &= (((int32) 1)<<size) - 1; /* mask off any extra bits in code */
|
||||
put_buffer &= (((INT32) 1)<<size) - 1; /* mask off any extra bits in code */
|
||||
|
||||
put_bits += size; /* new number of bits in buffer */
|
||||
|
||||
@ -289,7 +319,7 @@ emit_bits (working_state * state, uint16 code, int16 size)
|
||||
put_buffer |= state->cur.put_buffer; /* and merge with old buffer contents */
|
||||
|
||||
while (put_bits >= 8) {
|
||||
int16 c = (int16) ((put_buffer >> 16) & 0xFF);
|
||||
int c = (int) ((put_buffer >> 16) & 0xFF);
|
||||
|
||||
emit_byte(state, c, return FALSE);
|
||||
if (c == 0xFF) { /* need to stuff a zero byte? */
|
||||
@ -306,7 +336,7 @@ emit_bits (working_state * state, uint16 code, int16 size)
|
||||
}
|
||||
|
||||
|
||||
LOCAL boolean
|
||||
LOCAL(boolean)
|
||||
flush_bits (working_state * state)
|
||||
{
|
||||
if (! emit_bits(state, 0x7F, 7)) /* fill any partial byte with ones */
|
||||
@ -319,13 +349,13 @@ flush_bits (working_state * state)
|
||||
|
||||
/* Encode a single block's worth of coefficients */
|
||||
|
||||
LOCAL boolean
|
||||
encode_one_block (working_state * state, JCOEFPTR block, int16 last_dc_val,
|
||||
LOCAL(boolean)
|
||||
encode_one_block (working_state * state, JCOEFPTR block, int last_dc_val,
|
||||
c_derived_tbl *dctbl, c_derived_tbl *actbl)
|
||||
{
|
||||
register int16 temp, temp2;
|
||||
register int16 nbits;
|
||||
register int16 k, r, i;
|
||||
register int temp, temp2;
|
||||
register int nbits;
|
||||
register int k, r, i;
|
||||
|
||||
/* Encode the DC coefficient difference per section F.1.2.1 */
|
||||
|
||||
@ -344,6 +374,11 @@ encode_one_block (working_state * state, JCOEFPTR block, int16 last_dc_val,
|
||||
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(state->cinfo, JERR_BAD_DCT_COEF);
|
||||
|
||||
/* Emit the Huffman-coded symbol for the number of bits */
|
||||
if (! emit_bits(state, dctbl->ehufco[nbits], dctbl->ehufsi[nbits]))
|
||||
@ -352,7 +387,7 @@ encode_one_block (working_state * state, JCOEFPTR block, int16 last_dc_val,
|
||||
/* 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 */
|
||||
if (! emit_bits(state, (uint16) temp2, nbits))
|
||||
if (! emit_bits(state, (unsigned int) temp2, nbits))
|
||||
return FALSE;
|
||||
|
||||
/* Encode the AC coefficients per section F.1.2.2 */
|
||||
@ -381,6 +416,9 @@ encode_one_block (working_state * state, JCOEFPTR block, int16 last_dc_val,
|
||||
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(state->cinfo, JERR_BAD_DCT_COEF);
|
||||
|
||||
/* Emit Huffman symbol for run length / number of bits */
|
||||
i = (r << 4) + nbits;
|
||||
@ -389,7 +427,7 @@ encode_one_block (working_state * state, JCOEFPTR block, int16 last_dc_val,
|
||||
|
||||
/* Emit that number of bits of the value, if positive, */
|
||||
/* or the complement of its magnitude, if negative. */
|
||||
if (! emit_bits(state, (uint16) temp2, nbits))
|
||||
if (! emit_bits(state, (unsigned int) temp2, nbits))
|
||||
return FALSE;
|
||||
|
||||
r = 0;
|
||||
@ -409,10 +447,10 @@ encode_one_block (working_state * state, JCOEFPTR block, int16 last_dc_val,
|
||||
* Emit a restart marker & resynchronize predictions.
|
||||
*/
|
||||
|
||||
LOCAL boolean
|
||||
emit_restart (working_state * state, int16 restart_num)
|
||||
LOCAL(boolean)
|
||||
emit_restart (working_state * state, int restart_num)
|
||||
{
|
||||
int16 ci;
|
||||
int ci;
|
||||
|
||||
if (! flush_bits(state))
|
||||
return FALSE;
|
||||
@ -434,12 +472,12 @@ emit_restart (working_state * state, int16 restart_num)
|
||||
* Encode and output one MCU's worth of Huffman-compressed coefficients.
|
||||
*/
|
||||
|
||||
METHODDEF boolean
|
||||
METHODDEF(boolean)
|
||||
encode_mcu_huff (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
|
||||
{
|
||||
huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
|
||||
working_state state;
|
||||
int16 blkn, ci;
|
||||
int blkn, ci;
|
||||
jpeg_component_info * compptr;
|
||||
|
||||
/* Load up working state */
|
||||
@ -491,7 +529,7 @@ encode_mcu_huff (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
|
||||
* Finish up at the end of a Huffman-compressed scan.
|
||||
*/
|
||||
|
||||
METHODDEF void
|
||||
METHODDEF(void)
|
||||
finish_pass_huff (j_compress_ptr cinfo)
|
||||
{
|
||||
huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
|
||||
@ -517,19 +555,12 @@ finish_pass_huff (j_compress_ptr cinfo)
|
||||
/*
|
||||
* Huffman coding optimization.
|
||||
*
|
||||
* This actually is optimization, in the sense that we find the best possible
|
||||
* Huffman table(s) for the given data. We first scan the supplied data and
|
||||
* count the number of uses of each symbol that is to be Huffman-coded.
|
||||
* (This process must agree with the code above.) Then we build an
|
||||
* optimal Huffman coding tree for the observed counts.
|
||||
*
|
||||
* The JPEG standard requires Huffman codes to be no more than 16 bits long.
|
||||
* If some symbols have a very small but nonzero probability, the Huffman tree
|
||||
* must be adjusted to meet the code length restriction. We currently use
|
||||
* the adjustment method suggested in the JPEG spec. This method is *not*
|
||||
* optimal; it may not choose the best possible limited-length code. But
|
||||
* since the symbols involved are infrequently used, it's not clear that
|
||||
* going to extra trouble is worthwhile.
|
||||
* We first scan the supplied data and count the number of uses of each symbol
|
||||
* that is to be Huffman-coded. (This process MUST agree with the code above.)
|
||||
* Then we build a Huffman coding tree for the observed counts.
|
||||
* Symbols which are not needed at all for the particular image are not
|
||||
* assigned any code, which saves space in the DHT marker as well as in
|
||||
* the compressed data.
|
||||
*/
|
||||
|
||||
#ifdef ENTROPY_OPT_SUPPORTED
|
||||
@ -537,13 +568,13 @@ finish_pass_huff (j_compress_ptr cinfo)
|
||||
|
||||
/* Process a single block's worth of coefficients */
|
||||
|
||||
LOCAL void
|
||||
htest_one_block (JCOEFPTR block, int16 last_dc_val,
|
||||
int32 dc_counts[], int32 ac_counts[])
|
||||
LOCAL(void)
|
||||
htest_one_block (j_compress_ptr cinfo, JCOEFPTR block, int last_dc_val,
|
||||
long dc_counts[], long ac_counts[])
|
||||
{
|
||||
register int16 temp;
|
||||
register int16 nbits;
|
||||
register int16 k, r;
|
||||
register int temp;
|
||||
register int nbits;
|
||||
register int k, r;
|
||||
|
||||
/* Encode the DC coefficient difference per section F.1.2.1 */
|
||||
|
||||
@ -557,6 +588,11 @@ htest_one_block (JCOEFPTR block, int16 last_dc_val,
|
||||
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 the Huffman symbol for the number of bits */
|
||||
dc_counts[nbits]++;
|
||||
@ -583,6 +619,9 @@ htest_one_block (JCOEFPTR block, int16 last_dc_val,
|
||||
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 Huffman symbol for run length / number of bits */
|
||||
ac_counts[(r << 4) + nbits]++;
|
||||
@ -602,11 +641,11 @@ htest_one_block (JCOEFPTR block, int16 last_dc_val,
|
||||
* No data is actually output, so no suspension return is possible.
|
||||
*/
|
||||
|
||||
METHODDEF boolean
|
||||
METHODDEF(boolean)
|
||||
encode_mcu_gather (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
|
||||
{
|
||||
huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
|
||||
int16 blkn, ci;
|
||||
int blkn, ci;
|
||||
jpeg_component_info * compptr;
|
||||
|
||||
/* Take care of restart intervals if needed */
|
||||
@ -624,7 +663,7 @@ encode_mcu_gather (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
|
||||
for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
|
||||
ci = cinfo->MCU_membership[blkn];
|
||||
compptr = cinfo->cur_comp_info[ci];
|
||||
htest_one_block(MCU_data[blkn][0], entropy->saved.last_dc_val[ci],
|
||||
htest_one_block(cinfo, MCU_data[blkn][0], entropy->saved.last_dc_val[ci],
|
||||
entropy->dc_count_ptrs[compptr->dc_tbl_no],
|
||||
entropy->ac_count_ptrs[compptr->ac_tbl_no]);
|
||||
entropy->saved.last_dc_val[ci] = MCU_data[blkn][0][0];
|
||||
@ -635,20 +674,43 @@ encode_mcu_gather (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
|
||||
|
||||
|
||||
/*
|
||||
* Generate the optimal coding for the given counts, fill htbl.
|
||||
* Generate the best Huffman code table for the given counts, fill htbl.
|
||||
* Note this is also used by jcphuff.c.
|
||||
*
|
||||
* The JPEG standard requires that no symbol be assigned a codeword of all
|
||||
* one bits (so that padding bits added at the end of a compressed segment
|
||||
* can't look like a valid code). Because of the canonical ordering of
|
||||
* codewords, this just means that there must be an unused slot in the
|
||||
* longest codeword length category. Section K.2 of the JPEG spec suggests
|
||||
* reserving such a slot by pretending that symbol 256 is a valid symbol
|
||||
* with count 1. In theory that's not optimal; giving it count zero but
|
||||
* including it in the symbol set anyway should give a better Huffman code.
|
||||
* But the theoretically better code actually seems to come out worse in
|
||||
* practice, because it produces more all-ones bytes (which incur stuffed
|
||||
* zero bytes in the final file). In any case the difference is tiny.
|
||||
*
|
||||
* The JPEG standard requires Huffman codes to be no more than 16 bits long.
|
||||
* If some symbols have a very small but nonzero probability, the Huffman tree
|
||||
* must be adjusted to meet the code length restriction. We currently use
|
||||
* the adjustment method suggested in JPEG section K.2. This method is *not*
|
||||
* optimal; it may not choose the best possible limited-length code. But
|
||||
* typically only very-low-frequency symbols will be given less-than-optimal
|
||||
* lengths, so the code is almost optimal. Experimental comparisons against
|
||||
* an optimal limited-length-code algorithm indicate that the difference is
|
||||
* microscopic --- usually less than a hundredth of a percent of total size.
|
||||
* So the extra complexity of an optimal algorithm doesn't seem worthwhile.
|
||||
*/
|
||||
|
||||
GLOBAL void
|
||||
jpeg_gen_optimal_table (j_compress_ptr cinfo, JHUFF_TBL * htbl, int32 freq[])
|
||||
GLOBAL(void)
|
||||
jpeg_gen_optimal_table (j_compress_ptr cinfo, JHUFF_TBL * htbl, long freq[])
|
||||
{
|
||||
#define MAX_CLEN 32 /* assumed maximum initial code length */
|
||||
UINT8 bits[MAX_CLEN+1]; /* bits[k] = # of symbols with code length k */
|
||||
int16 codesize[257]; /* codesize[k] = code length of symbol k */
|
||||
int16 others[257]; /* next symbol in current branch of tree */
|
||||
int16 c1, c2;
|
||||
int16 p, i, j;
|
||||
int32 v;
|
||||
int codesize[257]; /* codesize[k] = code length of symbol k */
|
||||
int others[257]; /* next symbol in current branch of tree */
|
||||
int c1, c2;
|
||||
int p, i, j;
|
||||
long v;
|
||||
|
||||
/* This algorithm is explained in section K.2 of the JPEG standard */
|
||||
|
||||
@ -657,10 +719,10 @@ jpeg_gen_optimal_table (j_compress_ptr cinfo, JHUFF_TBL * htbl, int32 freq[])
|
||||
for (i = 0; i < 257; i++)
|
||||
others[i] = -1; /* init links to empty */
|
||||
|
||||
freq[256] = 1; /* make sure there is a nonzero count */
|
||||
freq[256] = 1; /* make sure 256 has a nonzero count */
|
||||
/* Including the pseudo-symbol 256 in the Huffman procedure guarantees
|
||||
* that no real symbol is given code-value of all ones, because 256
|
||||
* will be placed in the largest codeword category.
|
||||
* will be placed last in the largest codeword category.
|
||||
*/
|
||||
|
||||
/* Huffman's basic algorithm to assign optimal code lengths to symbols */
|
||||
@ -780,11 +842,11 @@ jpeg_gen_optimal_table (j_compress_ptr cinfo, JHUFF_TBL * htbl, int32 freq[])
|
||||
* Finish up a statistics-gathering pass and create the new Huffman tables.
|
||||
*/
|
||||
|
||||
METHODDEF void
|
||||
METHODDEF(void)
|
||||
finish_pass_gather (j_compress_ptr cinfo)
|
||||
{
|
||||
huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
|
||||
int16 ci, dctbl, actbl;
|
||||
int ci, dctbl, actbl;
|
||||
jpeg_component_info * compptr;
|
||||
JHUFF_TBL **htblptr;
|
||||
boolean did_dc[NUM_HUFF_TBLS];
|
||||
@ -825,11 +887,11 @@ finish_pass_gather (j_compress_ptr cinfo)
|
||||
* Module initialization routine for Huffman entropy encoding.
|
||||
*/
|
||||
|
||||
GLOBAL void
|
||||
GLOBAL(void)
|
||||
jinit_huff_encoder (j_compress_ptr cinfo)
|
||||
{
|
||||
huff_entropy_ptr entropy;
|
||||
int16 i;
|
||||
int i;
|
||||
|
||||
entropy = (huff_entropy_ptr)
|
||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* jchuff.h
|
||||
*
|
||||
* Copyright (C) 1991-1995, Thomas G. Lane.
|
||||
* 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.
|
||||
*
|
||||
@ -10,10 +10,22 @@
|
||||
* 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 {
|
||||
uint16 ehufco[256]; /* code for each symbol */
|
||||
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;
|
||||
@ -26,9 +38,10 @@ typedef struct {
|
||||
#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,
|
||||
JHUFF_TBL * htbl, c_derived_tbl ** pdtbl));
|
||||
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, int32 freq[]));
|
||||
EXTERN(void) jpeg_gen_optimal_table
|
||||
JPP((j_compress_ptr cinfo, JHUFF_TBL * htbl, long freq[]));
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* jcinit.c
|
||||
*
|
||||
* Copyright (C) 1991-1995, Thomas G. Lane.
|
||||
* 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.
|
||||
*
|
||||
@ -16,7 +16,6 @@
|
||||
*/
|
||||
|
||||
#define JPEG_INTERNALS
|
||||
#include "xp_core.h"/*defines of int32 ect*/
|
||||
#include "jinclude.h"
|
||||
#include "jpeglib.h"
|
||||
|
||||
@ -27,7 +26,7 @@
|
||||
* which modules will be used and give them appropriate initialization calls.
|
||||
*/
|
||||
|
||||
GLOBAL void
|
||||
GLOBAL(void)
|
||||
jinit_compress_master (j_compress_ptr cinfo)
|
||||
{
|
||||
/* Initialize master control (includes parameter checking/processing) */
|
||||
@ -57,7 +56,7 @@ jinit_compress_master (j_compress_ptr 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);
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* jcmainct.c
|
||||
*
|
||||
* Copyright (C) 1994-1995, Thomas G. Lane.
|
||||
* Copyright (C) 1994-1996, Thomas G. Lane.
|
||||
* This file is part of the Independent JPEG Group's software.
|
||||
* For conditions of distribution and use, see the accompanying README file.
|
||||
*
|
||||
@ -11,7 +11,6 @@
|
||||
*/
|
||||
|
||||
#define JPEG_INTERNALS
|
||||
#include "xp_core.h"/*defines of int32 ect*/
|
||||
#include "jinclude.h"
|
||||
#include "jpeglib.h"
|
||||
|
||||
@ -52,11 +51,11 @@ typedef my_main_controller * my_main_ptr;
|
||||
|
||||
|
||||
/* Forward declarations */
|
||||
METHODDEF void process_data_simple_main
|
||||
METHODDEF(void) process_data_simple_main
|
||||
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
|
||||
METHODDEF(void) process_data_buffer_main
|
||||
JPP((j_compress_ptr cinfo, JSAMPARRAY input_buf,
|
||||
JDIMENSION *in_row_ctr, JDIMENSION in_rows_avail));
|
||||
#endif
|
||||
@ -66,7 +65,7 @@ METHODDEF void process_data_buffer_main
|
||||
* Initialize for a processing pass.
|
||||
*/
|
||||
|
||||
METHODDEF void
|
||||
METHODDEF(void)
|
||||
start_pass_main (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
|
||||
{
|
||||
my_main_ptr main = (my_main_ptr) cinfo->main;
|
||||
@ -110,7 +109,7 @@ start_pass_main (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
|
||||
* where we have only a strip buffer.
|
||||
*/
|
||||
|
||||
METHODDEF void
|
||||
METHODDEF(void)
|
||||
process_data_simple_main (j_compress_ptr cinfo,
|
||||
JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
|
||||
JDIMENSION in_rows_avail)
|
||||
@ -166,13 +165,13 @@ process_data_simple_main (j_compress_ptr cinfo,
|
||||
* This routine handles all of the modes that use a full-size buffer.
|
||||
*/
|
||||
|
||||
METHODDEF void
|
||||
METHODDEF(void)
|
||||
process_data_buffer_main (j_compress_ptr cinfo,
|
||||
JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
|
||||
JDIMENSION in_rows_avail)
|
||||
{
|
||||
my_main_ptr main = (my_main_ptr) cinfo->main;
|
||||
int16 ci;
|
||||
int ci;
|
||||
jpeg_component_info *compptr;
|
||||
boolean writing = (main->pass_mode != JBUF_CRANK_DEST);
|
||||
|
||||
@ -242,11 +241,11 @@ process_data_buffer_main (j_compress_ptr cinfo,
|
||||
* Initialize main buffer controller.
|
||||
*/
|
||||
|
||||
GLOBAL void
|
||||
GLOBAL(void)
|
||||
jinit_c_main_controller (j_compress_ptr cinfo, boolean need_full_buffer)
|
||||
{
|
||||
my_main_ptr main;
|
||||
int16 ci;
|
||||
int ci;
|
||||
jpeg_component_info *compptr;
|
||||
|
||||
main = (my_main_ptr)
|
||||
@ -271,8 +270,8 @@ jinit_c_main_controller (j_compress_ptr cinfo, boolean need_full_buffer)
|
||||
main->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
|
||||
((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE,
|
||||
compptr->width_in_blocks * DCTSIZE,
|
||||
(JDIMENSION) jround_up((int32) compptr->height_in_blocks,
|
||||
(int32) compptr->v_samp_factor) * DCTSIZE,
|
||||
(JDIMENSION) jround_up((long) compptr->height_in_blocks,
|
||||
(long) compptr->v_samp_factor) * DCTSIZE,
|
||||
(JDIMENSION) (compptr->v_samp_factor * DCTSIZE));
|
||||
}
|
||||
#else
|
||||
|
196
jpeg/jcmarker.c
196
jpeg/jcmarker.c
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* jcmarker.c
|
||||
*
|
||||
* Copyright (C) 1991-1995, Thomas G. Lane.
|
||||
* Copyright (C) 1991-1998, Thomas G. Lane.
|
||||
* This file is part of the Independent JPEG Group's software.
|
||||
* For conditions of distribution and use, see the accompanying README file.
|
||||
*
|
||||
@ -10,6 +10,8 @@
|
||||
|
||||
#define JPEG_INTERNALS
|
||||
#include "jinclude.h"
|
||||
#include "jpeglib.h"
|
||||
|
||||
|
||||
typedef enum { /* JPEG marker codes */
|
||||
M_SOF0 = 0xc0,
|
||||
@ -73,16 +75,20 @@ typedef enum { /* JPEG marker codes */
|
||||
M_JPG13 = 0xfd,
|
||||
M_COM = 0xfe,
|
||||
|
||||
M_TEM = 0x01,
|
||||
|
||||
M_ERROR = 0x100
|
||||
M_TEM = 0x01
|
||||
} JPEG_MARKER;
|
||||
|
||||
#include "xp_core.h" /* defines of int32 ect */
|
||||
#include "jpeglib.h" /* Move these after JPEG_MARKER to avoid name
|
||||
* clash with Sun header, /usr/include/sys/stream.h,
|
||||
* which defines M_ERROR.
|
||||
*/
|
||||
|
||||
/* Private state */
|
||||
|
||||
typedef struct {
|
||||
struct jpeg_marker_writer pub; /* public fields */
|
||||
|
||||
unsigned int last_restart_interval; /* last DRI value emitted; 0 after SOI */
|
||||
} my_marker_writer;
|
||||
|
||||
typedef my_marker_writer * my_marker_ptr;
|
||||
|
||||
|
||||
/*
|
||||
* Basic output routines.
|
||||
@ -96,7 +102,7 @@ typedef enum { /* JPEG marker codes */
|
||||
* points where markers will be written.
|
||||
*/
|
||||
|
||||
LOCAL void
|
||||
LOCAL(void)
|
||||
emit_byte (j_compress_ptr cinfo, int16 val)
|
||||
/* Emit a byte */
|
||||
{
|
||||
@ -110,7 +116,7 @@ emit_byte (j_compress_ptr cinfo, int16 val)
|
||||
}
|
||||
|
||||
|
||||
LOCAL void
|
||||
LOCAL(void)
|
||||
emit_marker (j_compress_ptr cinfo, JPEG_MARKER mark)
|
||||
/* Emit a marker code */
|
||||
{
|
||||
@ -119,12 +125,12 @@ emit_marker (j_compress_ptr cinfo, JPEG_MARKER mark)
|
||||
}
|
||||
|
||||
|
||||
LOCAL void
|
||||
LOCAL(void)
|
||||
emit_2bytes (j_compress_ptr cinfo, int16 value)
|
||||
/* Emit a 2-byte integer; these are always MSB first in JPEG files */
|
||||
{
|
||||
emit_byte(cinfo, (int16)((value >> 8) & 0xFF));
|
||||
emit_byte(cinfo, (int16)(value & 0xFF));
|
||||
emit_byte(cinfo, (value >> 8) & 0xFF);
|
||||
emit_byte(cinfo, value & 0xFF);
|
||||
}
|
||||
|
||||
|
||||
@ -132,7 +138,7 @@ emit_2bytes (j_compress_ptr cinfo, int16 value)
|
||||
* Routines to write specific marker types.
|
||||
*/
|
||||
|
||||
LOCAL int16
|
||||
LOCAL(int16)
|
||||
emit_dqt (j_compress_ptr cinfo, int16 index)
|
||||
/* Emit a DQT marker */
|
||||
/* Returns the precision used (0 = 8bits, 1 = 16bits) for baseline checking */
|
||||
@ -153,14 +159,16 @@ emit_dqt (j_compress_ptr cinfo, int16 index)
|
||||
if (! qtbl->sent_table) {
|
||||
emit_marker(cinfo, M_DQT);
|
||||
|
||||
emit_2bytes(cinfo, (int16)(prec ? DCTSIZE2*2 + 1 + 2 : DCTSIZE2 + 1 + 2));
|
||||
emit_2bytes(cinfo, prec ? DCTSIZE2*2 + 1 + 2 : DCTSIZE2 + 1 + 2);
|
||||
|
||||
emit_byte(cinfo, (int16)(index + (prec<<4)));
|
||||
emit_byte(cinfo, index + (prec<<4));
|
||||
|
||||
for (i = 0; i < DCTSIZE2; i++) {
|
||||
/* The table entries must be emitted in zigzag order. */
|
||||
unsigned int qval = qtbl->quantval[jpeg_natural_order[i]];
|
||||
if (prec)
|
||||
emit_byte(cinfo, (int16)(qtbl->quantval[i] >> 8));
|
||||
emit_byte(cinfo, (int16)(qtbl->quantval[i] & 0xFF));
|
||||
emit_byte(cinfo, (int16) (qval >> 8));
|
||||
emit_byte(cinfo, (int16) (qval & 0xFF));
|
||||
}
|
||||
|
||||
qtbl->sent_table = TRUE;
|
||||
@ -170,7 +178,7 @@ emit_dqt (j_compress_ptr cinfo, int16 index)
|
||||
}
|
||||
|
||||
|
||||
LOCAL void
|
||||
LOCAL(void)
|
||||
emit_dht (j_compress_ptr cinfo, int16 index, boolean is_ac)
|
||||
/* Emit a DHT marker */
|
||||
{
|
||||
@ -194,7 +202,7 @@ emit_dht (j_compress_ptr cinfo, int16 index, boolean is_ac)
|
||||
for (i = 1; i <= 16; i++)
|
||||
length += htbl->bits[i];
|
||||
|
||||
emit_2bytes(cinfo, (int16)(length + 2 + 1 + 16));
|
||||
emit_2bytes(cinfo, length + 2 + 1 + 16);
|
||||
emit_byte(cinfo, index);
|
||||
|
||||
for (i = 1; i <= 16; i++)
|
||||
@ -208,7 +216,7 @@ emit_dht (j_compress_ptr cinfo, int16 index, boolean is_ac)
|
||||
}
|
||||
|
||||
|
||||
LOCAL void
|
||||
LOCAL(void)
|
||||
emit_dac (j_compress_ptr cinfo)
|
||||
/* Emit a DAC marker */
|
||||
/* Since the useful info is so small, we want to emit all the tables in */
|
||||
@ -251,7 +259,7 @@ emit_dac (j_compress_ptr cinfo)
|
||||
}
|
||||
|
||||
|
||||
LOCAL void
|
||||
LOCAL(void)
|
||||
emit_dri (j_compress_ptr cinfo)
|
||||
/* Emit a DRI marker */
|
||||
{
|
||||
@ -263,7 +271,7 @@ emit_dri (j_compress_ptr cinfo)
|
||||
}
|
||||
|
||||
|
||||
LOCAL void
|
||||
LOCAL(void)
|
||||
emit_sof (j_compress_ptr cinfo, JPEG_MARKER code)
|
||||
/* Emit a SOF marker */
|
||||
{
|
||||
@ -272,29 +280,29 @@ emit_sof (j_compress_ptr cinfo, JPEG_MARKER code)
|
||||
|
||||
emit_marker(cinfo, code);
|
||||
|
||||
emit_2bytes(cinfo, (int16)(3 * cinfo->num_components + 2 + 5 + 1)); /* length */
|
||||
emit_2bytes(cinfo, 3 * cinfo->num_components + 2 + 5 + 1); /* length */
|
||||
|
||||
/* Make sure image isn't bigger than SOF field can handle */
|
||||
if ((int32) cinfo->image_height > 65535L ||
|
||||
(int32) cinfo->image_width > 65535L)
|
||||
ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (uint16) 65535);
|
||||
if ((long) cinfo->image_height > 65535L ||
|
||||
(long) cinfo->image_width > 65535L)
|
||||
ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) 65535);
|
||||
|
||||
emit_byte(cinfo, (int16)(cinfo->data_precision));
|
||||
emit_byte(cinfo, cinfo->data_precision);
|
||||
emit_2bytes(cinfo, (int16) cinfo->image_height);
|
||||
emit_2bytes(cinfo, (int16) cinfo->image_width);
|
||||
|
||||
emit_byte(cinfo, (int16)(cinfo->num_components));
|
||||
emit_byte(cinfo, cinfo->num_components);
|
||||
|
||||
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
|
||||
ci++, compptr++) {
|
||||
emit_byte(cinfo, (int16)(compptr->component_id));
|
||||
emit_byte(cinfo, (int16)((compptr->h_samp_factor << 4) + compptr->v_samp_factor));
|
||||
emit_byte(cinfo, (int16)(compptr->quant_tbl_no));
|
||||
emit_byte(cinfo, compptr->component_id);
|
||||
emit_byte(cinfo, (compptr->h_samp_factor << 4) + compptr->v_samp_factor);
|
||||
emit_byte(cinfo, compptr->quant_tbl_no);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
LOCAL void
|
||||
LOCAL(void)
|
||||
emit_sos (j_compress_ptr cinfo)
|
||||
/* Emit a SOS marker */
|
||||
{
|
||||
@ -303,13 +311,13 @@ emit_sos (j_compress_ptr cinfo)
|
||||
|
||||
emit_marker(cinfo, M_SOS);
|
||||
|
||||
emit_2bytes(cinfo, (int16)(2 * cinfo->comps_in_scan + 2 + 1 + 3)); /* length */
|
||||
emit_2bytes(cinfo, 2 * cinfo->comps_in_scan + 2 + 1 + 3); /* length */
|
||||
|
||||
emit_byte(cinfo, (int16)(cinfo->comps_in_scan));
|
||||
emit_byte(cinfo, cinfo->comps_in_scan);
|
||||
|
||||
for (i = 0; i < cinfo->comps_in_scan; i++) {
|
||||
compptr = cinfo->cur_comp_info[i];
|
||||
emit_byte(cinfo, (int16)(compptr->component_id));
|
||||
emit_byte(cinfo, compptr->component_id);
|
||||
td = compptr->dc_tbl_no;
|
||||
ta = compptr->ac_tbl_no;
|
||||
if (cinfo->progressive_mode) {
|
||||
@ -326,16 +334,16 @@ emit_sos (j_compress_ptr cinfo)
|
||||
td = 0; /* AC scan */
|
||||
}
|
||||
}
|
||||
emit_byte(cinfo, (int16)((td << 4) + ta));
|
||||
emit_byte(cinfo, (td << 4) + ta);
|
||||
}
|
||||
|
||||
emit_byte(cinfo, (int16)(cinfo->Ss));
|
||||
emit_byte(cinfo, (int16)(cinfo->Se));
|
||||
emit_byte(cinfo, (int16)((cinfo->Ah << 4) + cinfo->Al));
|
||||
emit_byte(cinfo, cinfo->Ss);
|
||||
emit_byte(cinfo, cinfo->Se);
|
||||
emit_byte(cinfo, (cinfo->Ah << 4) + cinfo->Al);
|
||||
}
|
||||
|
||||
|
||||
LOCAL void
|
||||
LOCAL(void)
|
||||
emit_jfif_app0 (j_compress_ptr cinfo)
|
||||
/* Emit a JFIF-compliant APP0 marker */
|
||||
{
|
||||
@ -343,7 +351,7 @@ emit_jfif_app0 (j_compress_ptr cinfo)
|
||||
* Length of APP0 block (2 bytes)
|
||||
* Block ID (4 bytes - ASCII "JFIF")
|
||||
* Zero byte (1 byte to terminate the ID string)
|
||||
* Version Major, Minor (2 bytes - 0x01, 0x01)
|
||||
* Version Major, Minor (2 bytes - major first)
|
||||
* Units (1 byte - 0x00 = none, 0x01 = inch, 0x02 = cm)
|
||||
* Xdpu (2 bytes - dots per unit horizontal)
|
||||
* Ydpu (2 bytes - dots per unit vertical)
|
||||
@ -360,11 +368,8 @@ emit_jfif_app0 (j_compress_ptr cinfo)
|
||||
emit_byte(cinfo, 0x49);
|
||||
emit_byte(cinfo, 0x46);
|
||||
emit_byte(cinfo, 0);
|
||||
/* We currently emit version code 1.01 since we use no 1.02 features.
|
||||
* This may avoid complaints from some older decoders.
|
||||
*/
|
||||
emit_byte(cinfo, 1); /* Major version */
|
||||
emit_byte(cinfo, 1); /* Minor version */
|
||||
emit_byte(cinfo, cinfo->JFIF_major_version); /* Version fields */
|
||||
emit_byte(cinfo, cinfo->JFIF_minor_version);
|
||||
emit_byte(cinfo, cinfo->density_unit); /* Pixel size information */
|
||||
emit_2bytes(cinfo, (int16) cinfo->X_density);
|
||||
emit_2bytes(cinfo, (int16) cinfo->Y_density);
|
||||
@ -373,7 +378,7 @@ emit_jfif_app0 (j_compress_ptr cinfo)
|
||||
}
|
||||
|
||||
|
||||
LOCAL void
|
||||
LOCAL(void)
|
||||
emit_adobe_app14 (j_compress_ptr cinfo)
|
||||
/* Emit an Adobe APP14 marker */
|
||||
{
|
||||
@ -420,28 +425,30 @@ emit_adobe_app14 (j_compress_ptr cinfo)
|
||||
|
||||
|
||||
/*
|
||||
* This routine is exported for possible use by applications.
|
||||
* The intended use is to emit COM or APPn markers after calling
|
||||
* jpeg_start_compress() and before the first jpeg_write_scanlines() call
|
||||
* (hence, after write_file_header but before write_frame_header).
|
||||
* These routines allow writing an arbitrary marker with parameters.
|
||||
* The only intended use is to emit COM or APPn markers after calling
|
||||
* write_file_header and before calling write_frame_header.
|
||||
* Other uses are not guaranteed to produce desirable results.
|
||||
* Counting the parameter bytes properly is the caller's responsibility.
|
||||
*/
|
||||
|
||||
METHODDEF void
|
||||
write_any_marker (j_compress_ptr cinfo, int marker,
|
||||
const JOCTET *dataptr, unsigned int datalen)
|
||||
/* Emit an arbitrary marker with parameters */
|
||||
METHODDEF(void)
|
||||
write_marker_header (j_compress_ptr cinfo, int16 marker, unsigned int datalen)
|
||||
/* Emit an arbitrary marker header */
|
||||
{
|
||||
if (datalen <= (uint16) 65533) { /* safety check */
|
||||
emit_marker(cinfo, (JPEG_MARKER) marker);
|
||||
|
||||
emit_2bytes(cinfo, (int16) (datalen + 2)); /* total length */
|
||||
if (datalen > (unsigned int) 65533) /* safety check */
|
||||
ERREXIT(cinfo, JERR_BAD_LENGTH);
|
||||
|
||||
while (datalen--) {
|
||||
emit_byte(cinfo, *dataptr);
|
||||
dataptr++;
|
||||
}
|
||||
}
|
||||
emit_marker(cinfo, (JPEG_MARKER) marker);
|
||||
|
||||
emit_2bytes(cinfo, (int16) (datalen + 2)); /* total length */
|
||||
}
|
||||
|
||||
METHODDEF(void)
|
||||
write_marker_byte (j_compress_ptr cinfo, int16 val)
|
||||
/* Emit one byte of marker parameters following write_marker_header */
|
||||
{
|
||||
emit_byte(cinfo, val);
|
||||
}
|
||||
|
||||
|
||||
@ -456,11 +463,16 @@ write_any_marker (j_compress_ptr cinfo, int marker,
|
||||
* jpeg_start_compress returns.
|
||||
*/
|
||||
|
||||
METHODDEF void
|
||||
METHODDEF(void)
|
||||
write_file_header (j_compress_ptr cinfo)
|
||||
{
|
||||
my_marker_ptr marker = (my_marker_ptr) cinfo->marker;
|
||||
|
||||
emit_marker(cinfo, M_SOI); /* first the SOI */
|
||||
|
||||
/* SOI is defined to reset restart interval to 0 */
|
||||
marker->last_restart_interval = 0;
|
||||
|
||||
if (cinfo->write_JFIF_header) /* next an optional JFIF APP0 */
|
||||
emit_jfif_app0(cinfo);
|
||||
if (cinfo->write_Adobe_marker) /* next an optional Adobe APP14 */
|
||||
@ -476,7 +488,7 @@ write_file_header (j_compress_ptr cinfo)
|
||||
* try to error-check the quant table numbers as soon as they see the SOF.
|
||||
*/
|
||||
|
||||
METHODDEF void
|
||||
METHODDEF(void)
|
||||
write_frame_header (j_compress_ptr cinfo)
|
||||
{
|
||||
int16 ci, prec;
|
||||
@ -489,7 +501,7 @@ write_frame_header (j_compress_ptr cinfo)
|
||||
prec = 0;
|
||||
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
|
||||
ci++, compptr++) {
|
||||
prec += emit_dqt(cinfo, (int16)(compptr->quant_tbl_no));
|
||||
prec += emit_dqt(cinfo, compptr->quant_tbl_no);
|
||||
}
|
||||
/* now prec is nonzero iff there are any 16-bit quant tables. */
|
||||
|
||||
@ -533,9 +545,10 @@ write_frame_header (j_compress_ptr cinfo)
|
||||
* Compressed data will be written following the SOS.
|
||||
*/
|
||||
|
||||
METHODDEF void
|
||||
METHODDEF(void)
|
||||
write_scan_header (j_compress_ptr cinfo)
|
||||
{
|
||||
my_marker_ptr marker = (my_marker_ptr) cinfo->marker;
|
||||
int16 i;
|
||||
jpeg_component_info *compptr;
|
||||
|
||||
@ -555,24 +568,25 @@ write_scan_header (j_compress_ptr cinfo)
|
||||
/* 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 */
|
||||
emit_dht(cinfo, (int16)(compptr->dc_tbl_no), FALSE);
|
||||
emit_dht(cinfo, compptr->dc_tbl_no, FALSE);
|
||||
} else {
|
||||
emit_dht(cinfo, (int16)(compptr->ac_tbl_no), TRUE);
|
||||
emit_dht(cinfo, compptr->ac_tbl_no, TRUE);
|
||||
}
|
||||
} else {
|
||||
/* Sequential mode: need both DC and AC tables */
|
||||
emit_dht(cinfo, (int16)(compptr->dc_tbl_no), FALSE);
|
||||
emit_dht(cinfo, (int16)(compptr->ac_tbl_no), TRUE);
|
||||
emit_dht(cinfo, compptr->dc_tbl_no, FALSE);
|
||||
emit_dht(cinfo, compptr->ac_tbl_no, TRUE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Emit DRI if required --- note that DRI value could change for each scan.
|
||||
* If it doesn't, a tiny amount of space is wasted in multiple-scan files.
|
||||
* We assume DRI will never be nonzero for one scan and zero for a later one.
|
||||
* We avoid wasting space with unnecessary DRIs, however.
|
||||
*/
|
||||
if (cinfo->restart_interval)
|
||||
if (cinfo->restart_interval != marker->last_restart_interval) {
|
||||
emit_dri(cinfo);
|
||||
marker->last_restart_interval = cinfo->restart_interval;
|
||||
}
|
||||
|
||||
emit_sos(cinfo);
|
||||
}
|
||||
@ -582,7 +596,7 @@ write_scan_header (j_compress_ptr cinfo)
|
||||
* Write datastream trailer.
|
||||
*/
|
||||
|
||||
METHODDEF void
|
||||
METHODDEF(void)
|
||||
write_file_trailer (j_compress_ptr cinfo)
|
||||
{
|
||||
emit_marker(cinfo, M_EOI);
|
||||
@ -596,7 +610,7 @@ write_file_trailer (j_compress_ptr cinfo)
|
||||
* emitted. Note that all tables will be marked sent_table = TRUE at exit.
|
||||
*/
|
||||
|
||||
METHODDEF void
|
||||
METHODDEF(void)
|
||||
write_tables_only (j_compress_ptr cinfo)
|
||||
{
|
||||
int16 i;
|
||||
@ -625,18 +639,24 @@ write_tables_only (j_compress_ptr cinfo)
|
||||
* Initialize the marker writer module.
|
||||
*/
|
||||
|
||||
GLOBAL void
|
||||
GLOBAL(void)
|
||||
jinit_marker_writer (j_compress_ptr cinfo)
|
||||
{
|
||||
my_marker_ptr marker;
|
||||
|
||||
/* Create the subobject */
|
||||
cinfo->marker = (struct jpeg_marker_writer *)
|
||||
marker = (my_marker_ptr)
|
||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
||||
SIZEOF(struct jpeg_marker_writer));
|
||||
SIZEOF(my_marker_writer));
|
||||
cinfo->marker = (struct jpeg_marker_writer *) marker;
|
||||
/* Initialize method pointers */
|
||||
cinfo->marker->write_any_marker = write_any_marker;
|
||||
cinfo->marker->write_file_header = write_file_header;
|
||||
cinfo->marker->write_frame_header = write_frame_header;
|
||||
cinfo->marker->write_scan_header = write_scan_header;
|
||||
cinfo->marker->write_file_trailer = write_file_trailer;
|
||||
cinfo->marker->write_tables_only = write_tables_only;
|
||||
marker->pub.write_file_header = write_file_header;
|
||||
marker->pub.write_frame_header = write_frame_header;
|
||||
marker->pub.write_scan_header = write_scan_header;
|
||||
marker->pub.write_file_trailer = write_file_trailer;
|
||||
marker->pub.write_tables_only = write_tables_only;
|
||||
marker->pub.write_marker_header = write_marker_header;
|
||||
marker->pub.write_marker_byte = write_marker_byte;
|
||||
/* Initialize private state */
|
||||
marker->last_restart_interval = 0;
|
||||
}
|
||||
|
103
jpeg/jcmaster.c
103
jpeg/jcmaster.c
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* jcmaster.c
|
||||
*
|
||||
* Copyright (C) 1991-1995, Thomas G. Lane.
|
||||
* 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.
|
||||
*
|
||||
@ -12,7 +12,6 @@
|
||||
*/
|
||||
|
||||
#define JPEG_INTERNALS
|
||||
#include "xp_core.h"/*defines of int32 ect*/
|
||||
#include "jinclude.h"
|
||||
#include "jpeglib.h"
|
||||
|
||||
@ -30,10 +29,10 @@ typedef struct {
|
||||
|
||||
c_pass_type pass_type; /* the type of the current pass */
|
||||
|
||||
int16 pass_number; /* # of passes completed */
|
||||
int16 total_passes; /* total # of passes needed */
|
||||
int pass_number; /* # of passes completed */
|
||||
int total_passes; /* total # of passes needed */
|
||||
|
||||
int16 scan_number; /* current index in scan_info[] */
|
||||
int scan_number; /* current index in scan_info[] */
|
||||
} my_comp_master;
|
||||
|
||||
typedef my_comp_master * my_master_ptr;
|
||||
@ -43,13 +42,13 @@ typedef my_comp_master * my_master_ptr;
|
||||
* Support routines that do various essential calculations.
|
||||
*/
|
||||
|
||||
LOCAL void
|
||||
LOCAL(void)
|
||||
initial_setup (j_compress_ptr cinfo)
|
||||
/* Do computations that are needed before master selection phase */
|
||||
{
|
||||
int16 ci;
|
||||
int ci;
|
||||
jpeg_component_info *compptr;
|
||||
int32 samplesperrow;
|
||||
long samplesperrow;
|
||||
JDIMENSION jd_samplesperrow;
|
||||
|
||||
/* Sanity check on image dimensions */
|
||||
@ -58,14 +57,14 @@ initial_setup (j_compress_ptr cinfo)
|
||||
ERREXIT(cinfo, JERR_EMPTY_IMAGE);
|
||||
|
||||
/* Make sure image isn't bigger than I can handle */
|
||||
if ((int32) cinfo->image_height > (int32) JPEG_MAX_DIMENSION ||
|
||||
(int32) cinfo->image_width > (int32) JPEG_MAX_DIMENSION)
|
||||
ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (uint16) JPEG_MAX_DIMENSION);
|
||||
if ((long) cinfo->image_height > (long) JPEG_MAX_DIMENSION ||
|
||||
(long) cinfo->image_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. */
|
||||
samplesperrow = (int32) cinfo->image_width * (int32) cinfo->input_components;
|
||||
samplesperrow = (long) cinfo->image_width * (long) cinfo->input_components;
|
||||
jd_samplesperrow = (JDIMENSION) samplesperrow;
|
||||
if ((int32) jd_samplesperrow != samplesperrow)
|
||||
if ((long) jd_samplesperrow != samplesperrow)
|
||||
ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
|
||||
|
||||
/* For now, precision must match compiled-in value... */
|
||||
@ -100,18 +99,18 @@ initial_setup (j_compress_ptr cinfo)
|
||||
compptr->DCT_scaled_size = DCTSIZE;
|
||||
/* Size in DCT blocks */
|
||||
compptr->width_in_blocks = (JDIMENSION)
|
||||
jdiv_round_up((int32) cinfo->image_width * (int32) compptr->h_samp_factor,
|
||||
(int32) (cinfo->max_h_samp_factor * DCTSIZE));
|
||||
jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor,
|
||||
(long) (cinfo->max_h_samp_factor * DCTSIZE));
|
||||
compptr->height_in_blocks = (JDIMENSION)
|
||||
jdiv_round_up((int32) cinfo->image_height * (int32) compptr->v_samp_factor,
|
||||
(int32) (cinfo->max_v_samp_factor * DCTSIZE));
|
||||
jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor,
|
||||
(long) (cinfo->max_v_samp_factor * DCTSIZE));
|
||||
/* Size in samples */
|
||||
compptr->downsampled_width = (JDIMENSION)
|
||||
jdiv_round_up((int32) cinfo->image_width * (int32) compptr->h_samp_factor,
|
||||
(int32) cinfo->max_h_samp_factor);
|
||||
jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor,
|
||||
(long) cinfo->max_h_samp_factor);
|
||||
compptr->downsampled_height = (JDIMENSION)
|
||||
jdiv_round_up((int32) cinfo->image_height * (int32) compptr->v_samp_factor,
|
||||
(int32) cinfo->max_v_samp_factor);
|
||||
jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor,
|
||||
(long) cinfo->max_v_samp_factor);
|
||||
/* Mark component needed (this flag isn't actually used for compression) */
|
||||
compptr->component_needed = TRUE;
|
||||
}
|
||||
@ -120,26 +119,26 @@ initial_setup (j_compress_ptr cinfo)
|
||||
* main controller will call coefficient controller).
|
||||
*/
|
||||
cinfo->total_iMCU_rows = (JDIMENSION)
|
||||
jdiv_round_up((int32) cinfo->image_height,
|
||||
(int32) (cinfo->max_v_samp_factor*DCTSIZE));
|
||||
jdiv_round_up((long) cinfo->image_height,
|
||||
(long) (cinfo->max_v_samp_factor*DCTSIZE));
|
||||
}
|
||||
|
||||
|
||||
#ifdef C_MULTISCAN_FILES_SUPPORTED
|
||||
|
||||
LOCAL void
|
||||
LOCAL(void)
|
||||
validate_script (j_compress_ptr cinfo)
|
||||
/* Verify that the scan script in cinfo->scan_info[] is valid; also
|
||||
* determine whether it uses progressive JPEG, and set cinfo->progressive_mode.
|
||||
*/
|
||||
{
|
||||
const jpeg_scan_info * scanptr;
|
||||
int16 scanno, ncomps, ci, coefi, thisi;
|
||||
int16 Ss, Se, Ah, Al;
|
||||
int scanno, ncomps, ci, coefi, thisi;
|
||||
int Ss, Se, Ah, Al;
|
||||
boolean component_sent[MAX_COMPONENTS];
|
||||
#ifdef C_PROGRESSIVE_SUPPORTED
|
||||
int16 * last_bitpos_ptr;
|
||||
int16 last_bitpos[MAX_COMPONENTS][DCTSIZE2];
|
||||
int * last_bitpos_ptr;
|
||||
int last_bitpos[MAX_COMPONENTS][DCTSIZE2];
|
||||
/* -1 until that coefficient has been seen; then last Al for it */
|
||||
#endif
|
||||
|
||||
@ -186,8 +185,20 @@ validate_script (j_compress_ptr cinfo)
|
||||
Al = scanptr->Al;
|
||||
if (cinfo->progressive_mode) {
|
||||
#ifdef C_PROGRESSIVE_SUPPORTED
|
||||
/* The JPEG spec simply gives the ranges 0..13 for Ah and Al, but that
|
||||
* seems wrong: the upper bound ought to depend on data precision.
|
||||
* Perhaps they really meant 0..N+1 for N-bit precision.
|
||||
* Here we allow 0..10 for 8-bit data; Al larger than 10 results in
|
||||
* out-of-range reconstructed DC values during the first DC scan,
|
||||
* which might cause problems for some decoders.
|
||||
*/
|
||||
#if BITS_IN_JSAMPLE == 8
|
||||
#define MAX_AH_AL 10
|
||||
#else
|
||||
#define MAX_AH_AL 13
|
||||
#endif
|
||||
if (Ss < 0 || Ss >= DCTSIZE2 || Se < Ss || Se >= DCTSIZE2 ||
|
||||
Ah < 0 || Ah > 13 || Al < 0 || Al > 13)
|
||||
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 */
|
||||
@ -252,11 +263,11 @@ validate_script (j_compress_ptr cinfo)
|
||||
#endif /* C_MULTISCAN_FILES_SUPPORTED */
|
||||
|
||||
|
||||
LOCAL void
|
||||
LOCAL(void)
|
||||
select_scan_parameters (j_compress_ptr cinfo)
|
||||
/* Set up the scan parameters for the current scan */
|
||||
{
|
||||
int16 ci;
|
||||
int ci;
|
||||
|
||||
#ifdef C_MULTISCAN_FILES_SUPPORTED
|
||||
if (cinfo->scan_info != NULL) {
|
||||
@ -293,12 +304,12 @@ select_scan_parameters (j_compress_ptr cinfo)
|
||||
}
|
||||
|
||||
|
||||
LOCAL void
|
||||
LOCAL(void)
|
||||
per_scan_setup (j_compress_ptr cinfo)
|
||||
/* Do computations that are needed before processing a JPEG scan */
|
||||
/* cinfo->comps_in_scan and cinfo->cur_comp_info[] are already set */
|
||||
{
|
||||
int16 ci, mcublks, tmp;
|
||||
int ci, mcublks, tmp;
|
||||
jpeg_component_info *compptr;
|
||||
|
||||
if (cinfo->comps_in_scan == 1) {
|
||||
@ -319,7 +330,7 @@ per_scan_setup (j_compress_ptr cinfo)
|
||||
/* For noninterleaved scans, it is convenient to define last_row_height
|
||||
* as the number of block rows present in the last iMCU row.
|
||||
*/
|
||||
tmp = (int16) (compptr->height_in_blocks % compptr->v_samp_factor);
|
||||
tmp = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
|
||||
if (tmp == 0) tmp = compptr->v_samp_factor;
|
||||
compptr->last_row_height = tmp;
|
||||
|
||||
@ -336,11 +347,11 @@ per_scan_setup (j_compress_ptr cinfo)
|
||||
|
||||
/* Overall image size in MCUs */
|
||||
cinfo->MCUs_per_row = (JDIMENSION)
|
||||
jdiv_round_up((int32) cinfo->image_width,
|
||||
(int32) (cinfo->max_h_samp_factor*DCTSIZE));
|
||||
jdiv_round_up((long) cinfo->image_width,
|
||||
(long) (cinfo->max_h_samp_factor*DCTSIZE));
|
||||
cinfo->MCU_rows_in_scan = (JDIMENSION)
|
||||
jdiv_round_up((int32) cinfo->image_height,
|
||||
(int32) (cinfo->max_v_samp_factor*DCTSIZE));
|
||||
jdiv_round_up((long) cinfo->image_height,
|
||||
(long) (cinfo->max_v_samp_factor*DCTSIZE));
|
||||
|
||||
cinfo->blocks_in_MCU = 0;
|
||||
|
||||
@ -352,10 +363,10 @@ per_scan_setup (j_compress_ptr cinfo)
|
||||
compptr->MCU_blocks = compptr->MCU_width * compptr->MCU_height;
|
||||
compptr->MCU_sample_width = compptr->MCU_width * DCTSIZE;
|
||||
/* Figure number of non-dummy blocks in last MCU column & row */
|
||||
tmp = (int16) (compptr->width_in_blocks % compptr->MCU_width);
|
||||
tmp = (int) (compptr->width_in_blocks % compptr->MCU_width);
|
||||
if (tmp == 0) tmp = compptr->MCU_width;
|
||||
compptr->last_col_width = tmp;
|
||||
tmp = (int16) (compptr->height_in_blocks % compptr->MCU_height);
|
||||
tmp = (int) (compptr->height_in_blocks % compptr->MCU_height);
|
||||
if (tmp == 0) tmp = compptr->MCU_height;
|
||||
compptr->last_row_height = tmp;
|
||||
/* Prepare array describing MCU composition */
|
||||
@ -372,8 +383,8 @@ per_scan_setup (j_compress_ptr cinfo)
|
||||
/* Convert restart specified in rows to actual MCU count. */
|
||||
/* Note that count must fit in 16 bits, so we provide limiting. */
|
||||
if (cinfo->restart_in_rows > 0) {
|
||||
int32 nominal = (int32) cinfo->restart_in_rows * (int32) cinfo->MCUs_per_row;
|
||||
cinfo->restart_interval = (uint16) MIN(nominal, 65535L);
|
||||
long nominal = (long) cinfo->restart_in_rows * (long) cinfo->MCUs_per_row;
|
||||
cinfo->restart_interval = (unsigned int) MIN(nominal, 65535L);
|
||||
}
|
||||
}
|
||||
|
||||
@ -386,7 +397,7 @@ per_scan_setup (j_compress_ptr cinfo)
|
||||
* required.
|
||||
*/
|
||||
|
||||
METHODDEF void
|
||||
METHODDEF(void)
|
||||
prepare_for_pass (j_compress_ptr cinfo)
|
||||
{
|
||||
my_master_ptr master = (my_master_ptr) cinfo->master;
|
||||
@ -474,7 +485,7 @@ prepare_for_pass (j_compress_ptr cinfo)
|
||||
* In multi-pass processing, this routine is not used.
|
||||
*/
|
||||
|
||||
METHODDEF void
|
||||
METHODDEF(void)
|
||||
pass_startup (j_compress_ptr cinfo)
|
||||
{
|
||||
cinfo->master->call_pass_startup = FALSE; /* reset flag so call only once */
|
||||
@ -488,7 +499,7 @@ pass_startup (j_compress_ptr cinfo)
|
||||
* Finish up at end of pass.
|
||||
*/
|
||||
|
||||
METHODDEF void
|
||||
METHODDEF(void)
|
||||
finish_pass_master (j_compress_ptr cinfo)
|
||||
{
|
||||
my_master_ptr master = (my_master_ptr) cinfo->master;
|
||||
@ -528,7 +539,7 @@ finish_pass_master (j_compress_ptr cinfo)
|
||||
* Initialize master compression control.
|
||||
*/
|
||||
|
||||
GLOBAL void
|
||||
GLOBAL(void)
|
||||
jinit_c_master_control (j_compress_ptr cinfo, boolean transcode_only)
|
||||
{
|
||||
my_master_ptr master;
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* jcomapi.c
|
||||
*
|
||||
* Copyright (C) 1994, Thomas G. Lane.
|
||||
* Copyright (C) 1994-1997, Thomas G. Lane.
|
||||
* This file is part of the Independent JPEG Group's software.
|
||||
* For conditions of distribution and use, see the accompanying README file.
|
||||
*
|
||||
@ -25,11 +25,15 @@
|
||||
* responsibility.
|
||||
*/
|
||||
|
||||
GLOBAL void
|
||||
GLOBAL(void)
|
||||
jpeg_abort (j_common_ptr cinfo)
|
||||
{
|
||||
int pool;
|
||||
|
||||
/* Do nothing if called on a not-initialized or destroyed JPEG object. */
|
||||
if (cinfo->mem == NULL)
|
||||
return;
|
||||
|
||||
/* Releasing pools in reverse order might help avoid fragmentation
|
||||
* with some (brain-damaged) malloc libraries.
|
||||
*/
|
||||
@ -38,7 +42,15 @@ jpeg_abort (j_common_ptr cinfo)
|
||||
}
|
||||
|
||||
/* Reset overall state for possible reuse of object */
|
||||
cinfo->global_state = (cinfo->is_decompressor ? DSTATE_START : CSTATE_START);
|
||||
if (cinfo->is_decompressor) {
|
||||
cinfo->global_state = DSTATE_START;
|
||||
/* Try to keep application from accessing now-deleted marker list.
|
||||
* A bit kludgy to do it here, but this is the most central place.
|
||||
*/
|
||||
((j_decompress_ptr) cinfo)->marker_list = NULL;
|
||||
} else {
|
||||
cinfo->global_state = CSTATE_START;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -53,7 +65,7 @@ jpeg_abort (j_common_ptr cinfo)
|
||||
* responsibility.
|
||||
*/
|
||||
|
||||
GLOBAL void
|
||||
GLOBAL(void)
|
||||
jpeg_destroy (j_common_ptr cinfo)
|
||||
{
|
||||
/* We need only tell the memory manager to release everything. */
|
||||
@ -70,7 +82,7 @@ jpeg_destroy (j_common_ptr cinfo)
|
||||
* (Would jutils.c be a more reasonable place to put these?)
|
||||
*/
|
||||
|
||||
GLOBAL JQUANT_TBL *
|
||||
GLOBAL(JQUANT_TBL *)
|
||||
jpeg_alloc_quant_table (j_common_ptr cinfo)
|
||||
{
|
||||
JQUANT_TBL *tbl;
|
||||
@ -82,7 +94,7 @@ jpeg_alloc_quant_table (j_common_ptr cinfo)
|
||||
}
|
||||
|
||||
|
||||
GLOBAL JHUFF_TBL *
|
||||
GLOBAL(JHUFF_TBL *)
|
||||
jpeg_alloc_huff_table (j_common_ptr cinfo)
|
||||
{
|
||||
JHUFF_TBL *tbl;
|
||||
|
@ -1,25 +1,36 @@
|
||||
/* jconfig.h. Generated automatically by configure. */
|
||||
/* jconfig.auto --- source file edited by configure script */
|
||||
/* see jconfig.doc for explanations */
|
||||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifdef __MWERKS__ /* macintosh */
|
||||
#error should be including jconfig-mac-cw.h!
|
||||
#endif
|
||||
/*
|
||||
* jconfig.h to configure the IJG JPEG library for the Mozilla/Netscape
|
||||
* environment. Note that there are also Mozilla mods in jmorecfg.h.
|
||||
*/
|
||||
|
||||
#ifdef _WINDOWS /* windows */
|
||||
#error should be including jwinfig.h!
|
||||
#endif
|
||||
#include "xp_core.h" /* get XP_ symbols */
|
||||
#include "jri.h" /* get JRI_PUBLIC_API macro */
|
||||
|
||||
#ifdef XP_OS2 /* os2 */
|
||||
#error should be including jos2fig.h!
|
||||
#endif
|
||||
|
||||
/* We assume an ANSI C or C++ compilation environment */
|
||||
#define HAVE_PROTOTYPES
|
||||
#define HAVE_UNSIGNED_CHAR
|
||||
#define HAVE_UNSIGNED_SHORT
|
||||
#undef void
|
||||
#undef const
|
||||
#define CHAR_IS_UNSIGNED
|
||||
/* #define void char */
|
||||
/* #define const */
|
||||
#define HAVE_STDDEF_H
|
||||
#define HAVE_STDLIB_H
|
||||
#undef NEED_BSD_STRINGS
|
||||
@ -29,17 +40,41 @@
|
||||
/* Define this if you get warnings about undefined structures. */
|
||||
#undef INCOMPLETE_TYPES_BROKEN
|
||||
|
||||
/* With this setting, the IJG code will work regardless of whether
|
||||
* type "char" is signed or unsigned.
|
||||
*/
|
||||
#undef CHAR_IS_UNSIGNED
|
||||
|
||||
|
||||
/* defines that need not be visible to callers of the IJG library */
|
||||
|
||||
#ifdef JPEG_INTERNALS
|
||||
|
||||
/* If right shift of "long" quantities is unsigned on your machine,
|
||||
* you'll have to define this. Fortunately few people should need it.
|
||||
*/
|
||||
#undef RIGHT_SHIFT_IS_UNSIGNED
|
||||
|
||||
#define INLINE __inline
|
||||
/* These are for configuring the JPEG memory manager. */
|
||||
#undef DEFAULT_MAX_MEM
|
||||
#undef NO_MKTEMP
|
||||
#ifdef XP_WIN /* MS Windows */
|
||||
|
||||
/* In case we are using a compiler that only has 16-bit size_t: */
|
||||
#define MAX_ALLOC_CHUNK 65520L /* Maximum request to malloc() */
|
||||
|
||||
#endif /* XP_WIN */
|
||||
|
||||
#ifdef XP_MAC /* Macintosh */
|
||||
|
||||
#define ALIGN_TYPE long /* for sane memory alignment */
|
||||
#define NO_GETENV /* we do have the function, but it's dead */
|
||||
|
||||
#endif /* XP_MAC */
|
||||
|
||||
#endif /* JPEG_INTERNALS */
|
||||
|
||||
|
||||
/* these defines are not interesting for building just the IJG library,
|
||||
* but we leave 'em here anyway.
|
||||
*/
|
||||
#ifdef JPEG_CJPEG_DJPEG
|
||||
|
||||
#define BMP_SUPPORTED /* BMP image file format */
|
||||
@ -51,8 +86,6 @@
|
||||
#undef TWO_FILE_COMMANDLINE
|
||||
#undef NEED_SIGNAL_CATCHER
|
||||
#undef DONT_USE_B_MODE
|
||||
|
||||
/* Define this if you want percent-done progress reports from cjpeg/djpeg. */
|
||||
#undef PROGRESS_REPORT
|
||||
|
||||
#endif /* JPEG_CJPEG_DJPEG */
|
||||
|
144
jpeg/jcparam.c
144
jpeg/jcparam.c
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* jcparam.c
|
||||
*
|
||||
* Copyright (C) 1991-1995, Thomas G. Lane.
|
||||
* Copyright (C) 1991-1998, Thomas G. Lane.
|
||||
* This file is part of the Independent JPEG Group's software.
|
||||
* For conditions of distribution and use, see the accompanying README file.
|
||||
*
|
||||
@ -11,7 +11,6 @@
|
||||
*/
|
||||
|
||||
#define JPEG_INTERNALS
|
||||
#include "xp_core.h"/*defines of int32 ect*/
|
||||
#include "jinclude.h"
|
||||
#include "jpeglib.h"
|
||||
|
||||
@ -20,7 +19,7 @@
|
||||
* Quantization table setup routines
|
||||
*/
|
||||
|
||||
GLOBAL void
|
||||
GLOBAL(void)
|
||||
jpeg_add_quant_table (j_compress_ptr cinfo, int which_tbl,
|
||||
const unsigned int *basic_table,
|
||||
int scale_factor, boolean force_baseline)
|
||||
@ -30,7 +29,7 @@ jpeg_add_quant_table (j_compress_ptr cinfo, int which_tbl,
|
||||
* are limited to 1..255 for JPEG baseline compatibility.
|
||||
*/
|
||||
{
|
||||
JQUANT_TBL ** qtblptr = & cinfo->quant_tbl_ptrs[which_tbl];
|
||||
JQUANT_TBL ** qtblptr;
|
||||
int i;
|
||||
long temp;
|
||||
|
||||
@ -38,11 +37,16 @@ jpeg_add_quant_table (j_compress_ptr cinfo, int which_tbl,
|
||||
if (cinfo->global_state != CSTATE_START)
|
||||
ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
|
||||
|
||||
if (which_tbl < 0 || which_tbl >= NUM_QUANT_TBLS)
|
||||
ERREXIT1(cinfo, JERR_DQT_INDEX, which_tbl);
|
||||
|
||||
qtblptr = & cinfo->quant_tbl_ptrs[which_tbl];
|
||||
|
||||
if (*qtblptr == NULL)
|
||||
*qtblptr = jpeg_alloc_quant_table((j_common_ptr) cinfo);
|
||||
|
||||
for (i = 0; i < DCTSIZE2; i++) {
|
||||
temp = ((int32) basic_table[i] * scale_factor + 50L) / 100L;
|
||||
temp = ((long) basic_table[i] * scale_factor + 50L) / 100L;
|
||||
/* limit the values to the valid range */
|
||||
if (temp <= 0L) temp = 1L;
|
||||
if (temp > 32767L) temp = 32767L; /* max quantizer needed for 12 bits */
|
||||
@ -56,7 +60,7 @@ jpeg_add_quant_table (j_compress_ptr cinfo, int which_tbl,
|
||||
}
|
||||
|
||||
|
||||
GLOBAL void
|
||||
GLOBAL(void)
|
||||
jpeg_set_linear_quality (j_compress_ptr cinfo, int scale_factor,
|
||||
boolean force_baseline)
|
||||
/* Set or change the 'quality' (quantization) setting, using default tables
|
||||
@ -65,31 +69,30 @@ jpeg_set_linear_quality (j_compress_ptr cinfo, int scale_factor,
|
||||
* applications that insist on a linear percentage scaling.
|
||||
*/
|
||||
{
|
||||
/* This is the sample quantization table given in the JPEG spec section K.1,
|
||||
* but expressed in zigzag order (as are all of our quant. tables).
|
||||
/* 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 uint32 std_luminance_quant_tbl[DCTSIZE2] = {
|
||||
16, 11, 12, 14, 12, 10, 16, 14,
|
||||
13, 14, 18, 17, 16, 19, 24, 40,
|
||||
26, 24, 22, 22, 24, 49, 35, 37,
|
||||
29, 40, 58, 51, 61, 60, 57, 51,
|
||||
56, 55, 64, 72, 92, 78, 64, 68,
|
||||
87, 69, 55, 56, 80, 109, 81, 87,
|
||||
95, 98, 103, 104, 103, 62, 77, 113,
|
||||
121, 112, 100, 120, 92, 101, 103, 99
|
||||
};
|
||||
static const uint32 std_chrominance_quant_tbl[DCTSIZE2] = {
|
||||
17, 18, 18, 24, 21, 24, 47, 26,
|
||||
26, 47, 99, 66, 56, 66, 99, 99,
|
||||
99, 99, 99, 99, 99, 99, 99, 99,
|
||||
99, 99, 99, 99, 99, 99, 99, 99,
|
||||
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,
|
||||
@ -99,7 +102,7 @@ jpeg_set_linear_quality (j_compress_ptr cinfo, int scale_factor,
|
||||
}
|
||||
|
||||
|
||||
GLOBAL int
|
||||
GLOBAL(int)
|
||||
jpeg_quality_scaling (int quality)
|
||||
/* Convert a user-specified quality rating to a percentage scaling factor
|
||||
* for an underlying quantization table, using our recommended scaling curve.
|
||||
@ -112,8 +115,8 @@ jpeg_quality_scaling (int quality)
|
||||
|
||||
/* The basic table is used as-is (scaling 100) for a quality of 50.
|
||||
* Qualities 50..100 are converted to scaling percentage 200 - 2*Q;
|
||||
* note that at Q=100 the scaling is 0, which will cause j_add_quant_table
|
||||
* to make all the table entries 1 (hence, no quantization loss).
|
||||
* note that at Q=100 the scaling is 0, which will cause jpeg_add_quant_table
|
||||
* to make all the table entries 1 (hence, minimum quantization loss).
|
||||
* Qualities 1..50 are converted to scaling percentage 5000/Q.
|
||||
*/
|
||||
if (quality < 50)
|
||||
@ -125,7 +128,7 @@ jpeg_quality_scaling (int quality)
|
||||
}
|
||||
|
||||
|
||||
GLOBAL JRI_PUBLIC_API(void)
|
||||
GLOBAL(void)
|
||||
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
|
||||
@ -145,23 +148,37 @@ jpeg_set_quality (j_compress_ptr cinfo, int quality, boolean force_baseline)
|
||||
* Huffman table setup routines
|
||||
*/
|
||||
|
||||
LOCAL void
|
||||
LOCAL(void)
|
||||
add_huff_table (j_compress_ptr cinfo,
|
||||
JHUFF_TBL **htblptr, const UINT8 *bits, const UINT8 *val)
|
||||
/* Define a Huffman table */
|
||||
{
|
||||
int nsymbols, len;
|
||||
|
||||
if (*htblptr == NULL)
|
||||
*htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
|
||||
|
||||
|
||||
/* Copy the number-of-symbols-of-each-code-length counts */
|
||||
MEMCOPY((*htblptr)->bits, bits, SIZEOF((*htblptr)->bits));
|
||||
MEMCOPY((*htblptr)->huffval, val, SIZEOF((*htblptr)->huffval));
|
||||
|
||||
/* Validate the counts. We do this here mainly so we can copy the right
|
||||
* number of symbols from the val[] array, without risking marching off
|
||||
* the end of memory. jchuff.c will do a more thorough test later.
|
||||
*/
|
||||
nsymbols = 0;
|
||||
for (len = 1; len <= 16; len++)
|
||||
nsymbols += bits[len];
|
||||
if (nsymbols < 1 || nsymbols > 256)
|
||||
ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
|
||||
|
||||
MEMCOPY((*htblptr)->huffval, val, nsymbols * SIZEOF(UINT8));
|
||||
|
||||
/* Initialize sent_table FALSE so table will be written to JPEG file. */
|
||||
(*htblptr)->sent_table = FALSE;
|
||||
}
|
||||
|
||||
|
||||
LOCAL void
|
||||
LOCAL(void)
|
||||
std_huff_tables (j_compress_ptr cinfo)
|
||||
/* Set up the standard Huffman tables (cf. JPEG standard section K.3) */
|
||||
/* IMPORTANT: these are only valid for 8-bit data precision! */
|
||||
@ -247,10 +264,10 @@ std_huff_tables (j_compress_ptr cinfo)
|
||||
* your code will still work (they'll be set to reasonable defaults).
|
||||
*/
|
||||
|
||||
GLOBAL JRI_PUBLIC_API(void)
|
||||
GLOBAL(void)
|
||||
jpeg_set_defaults (j_compress_ptr cinfo)
|
||||
{
|
||||
int16 i;
|
||||
int i;
|
||||
|
||||
/* Safety check to ensure start_compress not called yet. */
|
||||
if (cinfo->global_state != CSTATE_START)
|
||||
@ -315,7 +332,15 @@ jpeg_set_defaults (j_compress_ptr cinfo)
|
||||
|
||||
/* Fill in default JFIF marker parameters. Note that whether the marker
|
||||
* will actually be written is determined by jpeg_set_colorspace.
|
||||
*
|
||||
* By default, the library emits JFIF version code 1.01.
|
||||
* An application that wants to emit JFIF 1.02 extension markers should set
|
||||
* JFIF_minor_version to 2. We could probably get away with just defaulting
|
||||
* to 1.02, but there may still be some decoders in use that will complain
|
||||
* about that; saying 1.01 should minimize compatibility problems.
|
||||
*/
|
||||
cinfo->JFIF_major_version = 1; /* Default JFIF version = 1.01 */
|
||||
cinfo->JFIF_minor_version = 1;
|
||||
cinfo->density_unit = 0; /* Pixel size is unknown by default */
|
||||
cinfo->X_density = 1; /* Pixel aspect ratio is square by default */
|
||||
cinfo->Y_density = 1;
|
||||
@ -330,7 +355,7 @@ jpeg_set_defaults (j_compress_ptr cinfo)
|
||||
* Select an appropriate JPEG colorspace for in_color_space.
|
||||
*/
|
||||
|
||||
GLOBAL void
|
||||
GLOBAL(void)
|
||||
jpeg_default_colorspace (j_compress_ptr cinfo)
|
||||
{
|
||||
switch (cinfo->in_color_space) {
|
||||
@ -362,11 +387,11 @@ jpeg_default_colorspace (j_compress_ptr cinfo)
|
||||
* Set the JPEG colorspace, and choose colorspace-dependent default values.
|
||||
*/
|
||||
|
||||
GLOBAL void
|
||||
GLOBAL(void)
|
||||
jpeg_set_colorspace (j_compress_ptr cinfo, J_COLOR_SPACE colorspace)
|
||||
{
|
||||
jpeg_component_info * compptr;
|
||||
int16 ci;
|
||||
int ci;
|
||||
|
||||
#define SET_COMP(index,id,hsamp,vsamp,quant,dctbl,actbl) \
|
||||
(compptr = &cinfo->comp_info[index], \
|
||||
@ -446,9 +471,9 @@ jpeg_set_colorspace (j_compress_ptr cinfo, J_COLOR_SPACE colorspace)
|
||||
|
||||
#ifdef C_PROGRESSIVE_SUPPORTED
|
||||
|
||||
LOCAL jpeg_scan_info *
|
||||
fill_a_scan (jpeg_scan_info * scanptr, int16 ci,
|
||||
int16 Ss, int16 Se, int16 Ah, int16 Al)
|
||||
LOCAL(jpeg_scan_info *)
|
||||
fill_a_scan (jpeg_scan_info * scanptr, int ci,
|
||||
int Ss, int Se, int Ah, int Al)
|
||||
/* Support routine: generate one scan for specified component */
|
||||
{
|
||||
scanptr->comps_in_scan = 1;
|
||||
@ -461,12 +486,12 @@ fill_a_scan (jpeg_scan_info * scanptr, int16 ci,
|
||||
return scanptr;
|
||||
}
|
||||
|
||||
LOCAL jpeg_scan_info *
|
||||
fill_scans (jpeg_scan_info * scanptr, int16 ncomps,
|
||||
int16 Ss, int16 Se, int16 Ah, int16 Al)
|
||||
LOCAL(jpeg_scan_info *)
|
||||
fill_scans (jpeg_scan_info * scanptr, int ncomps,
|
||||
int Ss, int Se, int Ah, int Al)
|
||||
/* Support routine: generate one scan for each component */
|
||||
{
|
||||
int16 ci;
|
||||
int ci;
|
||||
|
||||
for (ci = 0; ci < ncomps; ci++) {
|
||||
scanptr->comps_in_scan = 1;
|
||||
@ -480,11 +505,11 @@ fill_scans (jpeg_scan_info * scanptr, int16 ncomps,
|
||||
return scanptr;
|
||||
}
|
||||
|
||||
LOCAL jpeg_scan_info *
|
||||
fill_dc_scans (jpeg_scan_info * scanptr, int16 ncomps, int16 Ah, int16 Al)
|
||||
LOCAL(jpeg_scan_info *)
|
||||
fill_dc_scans (jpeg_scan_info * scanptr, int ncomps, int Ah, int Al)
|
||||
/* Support routine: generate interleaved DC scan if possible, else N scans */
|
||||
{
|
||||
int16 ci;
|
||||
int ci;
|
||||
|
||||
if (ncomps <= MAX_COMPS_IN_SCAN) {
|
||||
/* Single interleaved DC scan */
|
||||
@ -508,11 +533,11 @@ fill_dc_scans (jpeg_scan_info * scanptr, int16 ncomps, int16 Ah, int16 Al)
|
||||
* cinfo->num_components and cinfo->jpeg_color_space must be correct.
|
||||
*/
|
||||
|
||||
GLOBAL void
|
||||
GLOBAL(void)
|
||||
jpeg_simple_progression (j_compress_ptr cinfo)
|
||||
{
|
||||
int16 ncomps = cinfo->num_components;
|
||||
int16 nscans;
|
||||
int ncomps = cinfo->num_components;
|
||||
int nscans;
|
||||
jpeg_scan_info * scanptr;
|
||||
|
||||
/* Safety check to ensure start_compress not called yet. */
|
||||
@ -531,11 +556,20 @@ jpeg_simple_progression (j_compress_ptr cinfo)
|
||||
nscans = 2 + 4 * ncomps; /* 2 DC scans; 4 AC scans per component */
|
||||
}
|
||||
|
||||
/* Allocate space for script. */
|
||||
/* We use permanent pool just in case application re-uses script. */
|
||||
scanptr = (jpeg_scan_info *)
|
||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
|
||||
nscans * SIZEOF(jpeg_scan_info));
|
||||
/* Allocate space for script.
|
||||
* We need to put it in the permanent pool in case the application performs
|
||||
* multiple compressions without changing the settings. To avoid a memory
|
||||
* leak if jpeg_simple_progression is called repeatedly for the same JPEG
|
||||
* object, we try to re-use previously allocated space, and we allocate
|
||||
* enough space to handle YCbCr even if initially asked for grayscale.
|
||||
*/
|
||||
if (cinfo->script_space == NULL || cinfo->script_space_size < nscans) {
|
||||
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));
|
||||
}
|
||||
scanptr = cinfo->script_space;
|
||||
cinfo->scan_info = scanptr;
|
||||
cinfo->num_scans = nscans;
|
||||
|
||||
|
197
jpeg/jcphuff.c
197
jpeg/jcphuff.c
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* jcphuff.c
|
||||
*
|
||||
* Copyright (C) 1995, Thomas G. Lane.
|
||||
* 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.
|
||||
*
|
||||
@ -13,7 +13,6 @@
|
||||
*/
|
||||
|
||||
#define JPEG_INTERNALS
|
||||
#include "xp_core.h"/*defines of int32 ect*/
|
||||
#include "jinclude.h"
|
||||
#include "jpeglib.h"
|
||||
#include "jchuff.h" /* Declarations shared with jchuff.c */
|
||||
@ -33,22 +32,22 @@ typedef struct {
|
||||
*/
|
||||
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 */
|
||||
int16 put_bits; /* # of bits now in it */
|
||||
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 */
|
||||
int16 last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
|
||||
int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
|
||||
|
||||
/* Coding status for AC components */
|
||||
int16 ac_tbl_no; /* the table number of the single component */
|
||||
uint16 EOBRUN; /* run length of EOBs */
|
||||
uint16 BE; /* # of buffered correction bits before MCU */
|
||||
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... */
|
||||
|
||||
uint16 restarts_to_go; /* MCUs left in this restart interval */
|
||||
int16 next_restart_num; /* next restart number to write (0-7) */
|
||||
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
|
||||
@ -57,7 +56,7 @@ typedef struct {
|
||||
c_derived_tbl * derived_tbls[NUM_HUFF_TBLS];
|
||||
|
||||
/* Statistics tables for optimization; again, one set is enough */
|
||||
int32 * count_ptrs[NUM_HUFF_TBLS];
|
||||
long * count_ptrs[NUM_HUFF_TBLS];
|
||||
} phuff_entropy_encoder;
|
||||
|
||||
typedef phuff_entropy_encoder * phuff_entropy_ptr;
|
||||
@ -70,13 +69,13 @@ typedef phuff_entropy_encoder * phuff_entropy_ptr;
|
||||
|
||||
#define MAX_CORR_BITS 1000 /* Max # of correction bits I can buffer */
|
||||
|
||||
/* IRIGHT_SHIFT is like RIGHT_SHIFT, but works on int16 rather than int32.
|
||||
* We assume that int16 right shift is unsigned if int32 right shift is,
|
||||
/* 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 int16 ishift_temp;
|
||||
#define ISHIFT_TEMPS int ishift_temp;
|
||||
#define IRIGHT_SHIFT(x,shft) \
|
||||
((ishift_temp = (x)) < 0 ? \
|
||||
(ishift_temp >> (shft)) | ((~0) << (16-(shft))) : \
|
||||
@ -87,28 +86,28 @@ typedef phuff_entropy_encoder * phuff_entropy_ptr;
|
||||
#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,
|
||||
METHODDEF(boolean) encode_mcu_DC_first JPP((j_compress_ptr cinfo,
|
||||
JBLOCKROW *MCU_data));
|
||||
METHODDEF boolean encode_mcu_AC_refine JPP((j_compress_ptr cinfo,
|
||||
METHODDEF(boolean) encode_mcu_AC_first 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));
|
||||
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
|
||||
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;
|
||||
int16 ci, tbl;
|
||||
int ci, tbl;
|
||||
jpeg_component_info * compptr;
|
||||
|
||||
entropy->cinfo = cinfo;
|
||||
@ -148,38 +147,31 @@ start_pass_phuff (j_compress_ptr cinfo, boolean gather_statistics)
|
||||
compptr = cinfo->cur_comp_info[ci];
|
||||
/* Initialize DC predictions to 0 */
|
||||
entropy->last_dc_val[ci] = 0;
|
||||
/* Make sure requested tables are present */
|
||||
/* (In gather mode, tables need not be allocated yet) */
|
||||
/* Get table index */
|
||||
if (is_DC_band) {
|
||||
if (cinfo->Ah != 0) /* DC refinement needs no table */
|
||||
continue;
|
||||
tbl = compptr->dc_tbl_no;
|
||||
if (tbl < 0 || tbl >= NUM_HUFF_TBLS ||
|
||||
(cinfo->dc_huff_tbl_ptrs[tbl] == NULL && !gather_statistics))
|
||||
ERREXIT1(cinfo,JERR_NO_HUFF_TABLE, tbl);
|
||||
} else {
|
||||
entropy->ac_tbl_no = tbl = compptr->ac_tbl_no;
|
||||
if (tbl < 0 || tbl >= NUM_HUFF_TBLS ||
|
||||
(cinfo->ac_huff_tbl_ptrs[tbl] == NULL && !gather_statistics))
|
||||
ERREXIT1(cinfo,JERR_NO_HUFF_TABLE, tbl);
|
||||
}
|
||||
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] = (int32 *)
|
||||
entropy->count_ptrs[tbl] = (long *)
|
||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
||||
257 * SIZEOF(int32));
|
||||
MEMZERO(entropy->count_ptrs[tbl], 257 * SIZEOF(int32));
|
||||
257 * SIZEOF(long));
|
||||
MEMZERO(entropy->count_ptrs[tbl], 257 * SIZEOF(long));
|
||||
} else {
|
||||
/* Compute derived values for Huffman tables */
|
||||
/* Compute derived values for Huffman table */
|
||||
/* We may do this more than once for a table, but it's not expensive */
|
||||
if (is_DC_band)
|
||||
jpeg_make_c_derived_tbl(cinfo, cinfo->dc_huff_tbl_ptrs[tbl],
|
||||
& entropy->derived_tbls[tbl]);
|
||||
else
|
||||
jpeg_make_c_derived_tbl(cinfo, cinfo->ac_huff_tbl_ptrs[tbl],
|
||||
& entropy->derived_tbls[tbl]);
|
||||
jpeg_make_c_derived_tbl(cinfo, is_DC_band, tbl,
|
||||
& entropy->derived_tbls[tbl]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -209,7 +201,7 @@ start_pass_phuff (j_compress_ptr cinfo, boolean gather_statistics)
|
||||
dump_buffer(entropy); }
|
||||
|
||||
|
||||
LOCAL void
|
||||
LOCAL(void)
|
||||
dump_buffer (phuff_entropy_ptr entropy)
|
||||
/* Empty the output buffer; we do not support suspension in this module. */
|
||||
{
|
||||
@ -232,13 +224,13 @@ dump_buffer (phuff_entropy_ptr entropy)
|
||||
*/
|
||||
|
||||
INLINE
|
||||
LOCAL void
|
||||
emit_bits (phuff_entropy_ptr entropy, uint16 code, int16 size)
|
||||
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 int16 put_bits = entropy->put_bits;
|
||||
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)
|
||||
@ -247,7 +239,7 @@ emit_bits (phuff_entropy_ptr entropy, uint16 code, int16 size)
|
||||
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_buffer &= (((INT32) 1)<<size) - 1; /* mask off any extra bits in code */
|
||||
|
||||
put_bits += size; /* new number of bits in buffer */
|
||||
|
||||
@ -256,7 +248,7 @@ emit_bits (phuff_entropy_ptr entropy, uint16 code, int16 size)
|
||||
put_buffer |= entropy->put_buffer; /* and merge with old buffer contents */
|
||||
|
||||
while (put_bits >= 8) {
|
||||
int16 c = (int16) ((put_buffer >> 16) & 0xFF);
|
||||
int c = (int) ((put_buffer >> 16) & 0xFF);
|
||||
|
||||
emit_byte(entropy, c);
|
||||
if (c == 0xFF) { /* need to stuff a zero byte? */
|
||||
@ -271,7 +263,7 @@ emit_bits (phuff_entropy_ptr entropy, uint16 code, int16 size)
|
||||
}
|
||||
|
||||
|
||||
LOCAL void
|
||||
LOCAL(void)
|
||||
flush_bits (phuff_entropy_ptr entropy)
|
||||
{
|
||||
emit_bits(entropy, 0x7F, 7); /* fill any partial byte with ones */
|
||||
@ -285,8 +277,8 @@ flush_bits (phuff_entropy_ptr entropy)
|
||||
*/
|
||||
|
||||
INLINE
|
||||
LOCAL void
|
||||
emit_symbol (phuff_entropy_ptr entropy, int16 tbl_no, int16 symbol)
|
||||
LOCAL(void)
|
||||
emit_symbol (phuff_entropy_ptr entropy, int tbl_no, int symbol)
|
||||
{
|
||||
if (entropy->gather_statistics)
|
||||
entropy->count_ptrs[tbl_no][symbol]++;
|
||||
@ -301,15 +293,15 @@ emit_symbol (phuff_entropy_ptr entropy, int16 tbl_no, int16 symbol)
|
||||
* Emit bits from a correction bit buffer.
|
||||
*/
|
||||
|
||||
LOCAL void
|
||||
LOCAL(void)
|
||||
emit_buffered_bits (phuff_entropy_ptr entropy, char * bufstart,
|
||||
uint16 nbits)
|
||||
unsigned int nbits)
|
||||
{
|
||||
if (entropy->gather_statistics)
|
||||
return; /* no real work */
|
||||
|
||||
while (nbits > 0) {
|
||||
emit_bits(entropy, (uint16) (*bufstart), 1);
|
||||
emit_bits(entropy, (unsigned int) (*bufstart), 1);
|
||||
bufstart++;
|
||||
nbits--;
|
||||
}
|
||||
@ -320,18 +312,21 @@ emit_buffered_bits (phuff_entropy_ptr entropy, char * bufstart,
|
||||
* Emit any pending EOBRUN symbol.
|
||||
*/
|
||||
|
||||
LOCAL void
|
||||
LOCAL(void)
|
||||
emit_eobrun (phuff_entropy_ptr entropy)
|
||||
{
|
||||
register int16 temp, nbits;
|
||||
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, (int16)entropy->ac_tbl_no, (int16)(nbits << 4));
|
||||
emit_symbol(entropy, entropy->ac_tbl_no, nbits << 4);
|
||||
if (nbits)
|
||||
emit_bits(entropy, entropy->EOBRUN, nbits);
|
||||
|
||||
@ -348,10 +343,10 @@ emit_eobrun (phuff_entropy_ptr entropy)
|
||||
* Emit a restart marker & resynchronize predictions.
|
||||
*/
|
||||
|
||||
LOCAL void
|
||||
emit_restart (phuff_entropy_ptr entropy, int16 restart_num)
|
||||
LOCAL(void)
|
||||
emit_restart (phuff_entropy_ptr entropy, int restart_num)
|
||||
{
|
||||
int16 ci;
|
||||
int ci;
|
||||
|
||||
emit_eobrun(entropy);
|
||||
|
||||
@ -378,14 +373,14 @@ emit_restart (phuff_entropy_ptr entropy, int16 restart_num)
|
||||
* or first pass of successive approximation).
|
||||
*/
|
||||
|
||||
METHODDEF boolean
|
||||
METHODDEF(boolean)
|
||||
encode_mcu_DC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
|
||||
{
|
||||
phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
|
||||
register int16 temp, temp2;
|
||||
register int16 nbits;
|
||||
int16 blkn, ci;
|
||||
int16 Al = cinfo->Al;
|
||||
register int temp, temp2;
|
||||
register int nbits;
|
||||
int blkn, ci;
|
||||
int Al = cinfo->Al;
|
||||
JBLOCKROW block;
|
||||
jpeg_component_info * compptr;
|
||||
ISHIFT_TEMPS
|
||||
@ -407,7 +402,7 @@ encode_mcu_DC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
|
||||
/* Compute the DC value after the required point transform by Al.
|
||||
* This is simply an arithmetic right shift.
|
||||
*/
|
||||
temp2 = IRIGHT_SHIFT((int16) ((*block)[0]), Al);
|
||||
temp2 = IRIGHT_SHIFT((int) ((*block)[0]), Al);
|
||||
|
||||
/* DC differences are figured on the point-transformed values. */
|
||||
temp = temp2 - entropy->last_dc_val[ci];
|
||||
@ -428,14 +423,19 @@ encode_mcu_DC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
|
||||
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, (int16)compptr->dc_tbl_no, (int16)nbits);
|
||||
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, (uint16) temp2, nbits);
|
||||
emit_bits(entropy, (unsigned int) temp2, nbits);
|
||||
}
|
||||
|
||||
cinfo->dest->next_output_byte = entropy->next_output_byte;
|
||||
@ -460,15 +460,15 @@ encode_mcu_DC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
|
||||
* or first pass of successive approximation).
|
||||
*/
|
||||
|
||||
METHODDEF boolean
|
||||
METHODDEF(boolean)
|
||||
encode_mcu_AC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
|
||||
{
|
||||
phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
|
||||
register int16 temp, temp2;
|
||||
register int16 nbits;
|
||||
register int16 r, k;
|
||||
int16 Se = cinfo->Se;
|
||||
int16 Al = cinfo->Al;
|
||||
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;
|
||||
@ -524,13 +524,16 @@ encode_mcu_AC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
|
||||
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, (int16)entropy->ac_tbl_no, (int16)((r << 4) + nbits));
|
||||
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, (uint16) temp2, nbits);
|
||||
emit_bits(entropy, (unsigned int) temp2, nbits);
|
||||
|
||||
r = 0; /* reset zero run length */
|
||||
}
|
||||
@ -564,13 +567,13 @@ encode_mcu_AC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
|
||||
* is not very clear on the point.
|
||||
*/
|
||||
|
||||
METHODDEF boolean
|
||||
METHODDEF(boolean)
|
||||
encode_mcu_DC_refine (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
|
||||
{
|
||||
phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
|
||||
register int16 temp;
|
||||
int16 blkn;
|
||||
int16 Al = cinfo->Al;
|
||||
register int temp;
|
||||
int blkn;
|
||||
int Al = cinfo->Al;
|
||||
JBLOCKROW block;
|
||||
|
||||
entropy->next_output_byte = cinfo->dest->next_output_byte;
|
||||
@ -587,7 +590,7 @@ encode_mcu_DC_refine (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
|
||||
|
||||
/* We simply emit the Al'th bit of the DC coefficient value. */
|
||||
temp = (*block)[0];
|
||||
emit_bits(entropy, (uint16) (temp >> Al), 1);
|
||||
emit_bits(entropy, (unsigned int) (temp >> Al), 1);
|
||||
}
|
||||
|
||||
cinfo->dest->next_output_byte = entropy->next_output_byte;
|
||||
@ -611,19 +614,19 @@ encode_mcu_DC_refine (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
|
||||
* MCU encoding for AC successive approximation refinement scan.
|
||||
*/
|
||||
|
||||
METHODDEF boolean
|
||||
METHODDEF(boolean)
|
||||
encode_mcu_AC_refine (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
|
||||
{
|
||||
phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
|
||||
register int16 temp;
|
||||
register int16 r, k;
|
||||
int16 EOB;
|
||||
register int temp;
|
||||
register int r, k;
|
||||
int EOB;
|
||||
char *BR_buffer;
|
||||
uint16 BR;
|
||||
int16 Se = cinfo->Se;
|
||||
int16 Al = cinfo->Al;
|
||||
unsigned int BR;
|
||||
int Se = cinfo->Se;
|
||||
int Al = cinfo->Al;
|
||||
JBLOCKROW block;
|
||||
int16 absvalues[DCTSIZE2];
|
||||
int absvalues[DCTSIZE2];
|
||||
|
||||
entropy->next_output_byte = cinfo->dest->next_output_byte;
|
||||
entropy->free_in_buffer = cinfo->dest->free_in_buffer;
|
||||
@ -694,11 +697,11 @@ encode_mcu_AC_refine (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
|
||||
emit_eobrun(entropy);
|
||||
|
||||
/* Count/emit Huffman symbol for run length / number of bits */
|
||||
emit_symbol(entropy, (int16)entropy->ac_tbl_no, (int16)((r << 4) + 1));
|
||||
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, (uint16) temp, 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);
|
||||
@ -739,7 +742,7 @@ encode_mcu_AC_refine (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
|
||||
* Finish up at the end of a Huffman-compressed progressive scan.
|
||||
*/
|
||||
|
||||
METHODDEF void
|
||||
METHODDEF(void)
|
||||
finish_pass_phuff (j_compress_ptr cinfo)
|
||||
{
|
||||
phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
|
||||
@ -760,12 +763,12 @@ finish_pass_phuff (j_compress_ptr cinfo)
|
||||
* Finish up a statistics-gathering pass and create the new Huffman tables.
|
||||
*/
|
||||
|
||||
METHODDEF void
|
||||
METHODDEF(void)
|
||||
finish_pass_gather_phuff (j_compress_ptr cinfo)
|
||||
{
|
||||
phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
|
||||
boolean is_DC_band;
|
||||
int16 ci, tbl;
|
||||
int ci, tbl;
|
||||
jpeg_component_info * compptr;
|
||||
JHUFF_TBL **htblptr;
|
||||
boolean did[NUM_HUFF_TBLS];
|
||||
@ -807,11 +810,11 @@ finish_pass_gather_phuff (j_compress_ptr cinfo)
|
||||
* Module initialization routine for progressive Huffman entropy encoding.
|
||||
*/
|
||||
|
||||
GLOBAL void
|
||||
GLOBAL(void)
|
||||
jinit_phuff_encoder (j_compress_ptr cinfo)
|
||||
{
|
||||
phuff_entropy_ptr entropy;
|
||||
int16 i;
|
||||
int i;
|
||||
|
||||
entropy = (phuff_entropy_ptr)
|
||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* jcprepct.c
|
||||
*
|
||||
* Copyright (C) 1994, Thomas G. Lane.
|
||||
* Copyright (C) 1994-1996, Thomas G. Lane.
|
||||
* This file is part of the Independent JPEG Group's software.
|
||||
* For conditions of distribution and use, see the accompanying README file.
|
||||
*
|
||||
@ -15,7 +15,6 @@
|
||||
*/
|
||||
|
||||
#define JPEG_INTERNALS
|
||||
#include "xp_core.h"/*defines of int32 ect*/
|
||||
#include "jinclude.h"
|
||||
#include "jpeglib.h"
|
||||
|
||||
@ -60,11 +59,11 @@ typedef struct {
|
||||
JSAMPARRAY color_buf[MAX_COMPONENTS];
|
||||
|
||||
JDIMENSION rows_to_go; /* counts rows remaining in source image */
|
||||
int16 next_buf_row; /* index of next row to store in color_buf */
|
||||
int next_buf_row; /* index of next row to store in color_buf */
|
||||
|
||||
#ifdef CONTEXT_ROWS_SUPPORTED /* only needed for context case */
|
||||
int16 this_row_group; /* starting row index of group to process */
|
||||
int16 next_buf_stop; /* downsample when we reach this index */
|
||||
int this_row_group; /* starting row index of group to process */
|
||||
int next_buf_stop; /* downsample when we reach this index */
|
||||
#endif
|
||||
} my_prep_controller;
|
||||
|
||||
@ -75,7 +74,7 @@ typedef my_prep_controller * my_prep_ptr;
|
||||
* Initialize for a processing pass.
|
||||
*/
|
||||
|
||||
METHODDEF void
|
||||
METHODDEF(void)
|
||||
start_pass_prep (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
|
||||
{
|
||||
my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
|
||||
@ -103,11 +102,11 @@ start_pass_prep (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
|
||||
* by duplicating the bottom row.
|
||||
*/
|
||||
|
||||
LOCAL void
|
||||
LOCAL(void)
|
||||
expand_bottom_edge (JSAMPARRAY image_data, JDIMENSION num_cols,
|
||||
int16 input_rows, int16 output_rows)
|
||||
int input_rows, int output_rows)
|
||||
{
|
||||
register int16 row;
|
||||
register int row;
|
||||
|
||||
for (row = input_rows; row < output_rows; row++) {
|
||||
jcopy_sample_rows(image_data, input_rows-1, image_data, row,
|
||||
@ -125,7 +124,7 @@ expand_bottom_edge (JSAMPARRAY image_data, JDIMENSION num_cols,
|
||||
* input rows.
|
||||
*/
|
||||
|
||||
METHODDEF void
|
||||
METHODDEF(void)
|
||||
pre_process_data (j_compress_ptr cinfo,
|
||||
JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
|
||||
JDIMENSION in_rows_avail,
|
||||
@ -133,7 +132,7 @@ pre_process_data (j_compress_ptr cinfo,
|
||||
JDIMENSION out_row_groups_avail)
|
||||
{
|
||||
my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
|
||||
int16 numrows, ci;
|
||||
int numrows, ci;
|
||||
JDIMENSION inrows;
|
||||
jpeg_component_info * compptr;
|
||||
|
||||
@ -142,7 +141,7 @@ pre_process_data (j_compress_ptr cinfo,
|
||||
/* 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 = (int16) MIN((JDIMENSION) numrows, inrows);
|
||||
numrows = (int) MIN((JDIMENSION) numrows, inrows);
|
||||
(*cinfo->cconvert->color_convert) (cinfo, input_buf + *in_row_ctr,
|
||||
prep->color_buf,
|
||||
(JDIMENSION) prep->next_buf_row,
|
||||
@ -155,7 +154,7 @@ pre_process_data (j_compress_ptr cinfo,
|
||||
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,
|
||||
(int16)prep->next_buf_row, (int16)cinfo->max_v_samp_factor);
|
||||
prep->next_buf_row, cinfo->max_v_samp_factor);
|
||||
}
|
||||
prep->next_buf_row = cinfo->max_v_samp_factor;
|
||||
}
|
||||
@ -176,8 +175,8 @@ pre_process_data (j_compress_ptr cinfo,
|
||||
ci++, compptr++) {
|
||||
expand_bottom_edge(output_buf[ci],
|
||||
compptr->width_in_blocks * DCTSIZE,
|
||||
(int16) (*out_row_group_ctr * compptr->v_samp_factor),
|
||||
(int16) (out_row_groups_avail * compptr->v_samp_factor));
|
||||
(int) (*out_row_group_ctr * compptr->v_samp_factor),
|
||||
(int) (out_row_groups_avail * compptr->v_samp_factor));
|
||||
}
|
||||
*out_row_group_ctr = out_row_groups_avail;
|
||||
break; /* can exit outer loop without test */
|
||||
@ -192,7 +191,7 @@ pre_process_data (j_compress_ptr cinfo,
|
||||
* Process some data in the context case.
|
||||
*/
|
||||
|
||||
METHODDEF void
|
||||
METHODDEF(void)
|
||||
pre_process_context (j_compress_ptr cinfo,
|
||||
JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
|
||||
JDIMENSION in_rows_avail,
|
||||
@ -200,17 +199,16 @@ pre_process_context (j_compress_ptr cinfo,
|
||||
JDIMENSION out_row_groups_avail)
|
||||
{
|
||||
my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
|
||||
int16 numrows, ci;
|
||||
int16 buf_height = cinfo->max_v_samp_factor * 3;
|
||||
int numrows, ci;
|
||||
int buf_height = cinfo->max_v_samp_factor * 3;
|
||||
JDIMENSION inrows;
|
||||
jpeg_component_info * compptr;
|
||||
|
||||
while (*out_row_group_ctr < out_row_groups_avail) {
|
||||
if (*in_row_ctr < in_rows_avail) {
|
||||
/* Do color conversion to fill the conversion buffer. */
|
||||
inrows = in_rows_avail - *in_row_ctr;
|
||||
numrows = prep->next_buf_stop - prep->next_buf_row;
|
||||
numrows = (int16) MIN((JDIMENSION) numrows, inrows);
|
||||
numrows = (int) MIN((JDIMENSION) numrows, inrows);
|
||||
(*cinfo->cconvert->color_convert) (cinfo, input_buf + *in_row_ctr,
|
||||
prep->color_buf,
|
||||
(JDIMENSION) prep->next_buf_row,
|
||||
@ -218,7 +216,7 @@ pre_process_context (j_compress_ptr cinfo,
|
||||
/* 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++) {
|
||||
int16 row;
|
||||
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,
|
||||
@ -233,15 +231,14 @@ pre_process_context (j_compress_ptr cinfo,
|
||||
/* Return for more data, unless we are at the bottom of the image. */
|
||||
if (prep->rows_to_go != 0)
|
||||
break;
|
||||
}
|
||||
/* If at bottom of image, pad to fill the conversion buffer. */
|
||||
if (prep->rows_to_go == 0 &&
|
||||
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);
|
||||
/* 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;
|
||||
}
|
||||
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) {
|
||||
@ -258,21 +255,6 @@ pre_process_context (j_compress_ptr cinfo,
|
||||
prep->next_buf_row = 0;
|
||||
prep->next_buf_stop = prep->next_buf_row + cinfo->max_v_samp_factor;
|
||||
}
|
||||
/* If at bottom of image, pad the output to a full iMCU height.
|
||||
* 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) {
|
||||
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
|
||||
ci++, compptr++) {
|
||||
expand_bottom_edge(output_buf[ci],
|
||||
compptr->width_in_blocks * DCTSIZE,
|
||||
(int16) (*out_row_group_ctr * compptr->v_samp_factor),
|
||||
(int16) (out_row_groups_avail * compptr->v_samp_factor));
|
||||
}
|
||||
*out_row_group_ctr = out_row_groups_avail;
|
||||
break; /* can exit outer loop without test */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -281,12 +263,12 @@ pre_process_context (j_compress_ptr cinfo,
|
||||
* Create the wrapped-around downsampling input buffer needed for context mode.
|
||||
*/
|
||||
|
||||
LOCAL void
|
||||
LOCAL(void)
|
||||
create_context_buffer (j_compress_ptr cinfo)
|
||||
{
|
||||
my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
|
||||
int16 rgroup_height = cinfo->max_v_samp_factor;
|
||||
int16 ci, i;
|
||||
int rgroup_height = cinfo->max_v_samp_factor;
|
||||
int ci, i;
|
||||
jpeg_component_info * compptr;
|
||||
JSAMPARRAY true_buffer, fake_buffer;
|
||||
|
||||
@ -306,7 +288,7 @@ create_context_buffer (j_compress_ptr cinfo)
|
||||
*/
|
||||
true_buffer = (*cinfo->mem->alloc_sarray)
|
||||
((j_common_ptr) cinfo, JPOOL_IMAGE,
|
||||
(JDIMENSION) (((int32) compptr->width_in_blocks * DCTSIZE *
|
||||
(JDIMENSION) (((long) compptr->width_in_blocks * DCTSIZE *
|
||||
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 */
|
||||
@ -329,11 +311,11 @@ create_context_buffer (j_compress_ptr cinfo)
|
||||
* Initialize preprocessing controller.
|
||||
*/
|
||||
|
||||
GLOBAL void
|
||||
GLOBAL(void)
|
||||
jinit_c_prep_controller (j_compress_ptr cinfo, boolean need_full_buffer)
|
||||
{
|
||||
my_prep_ptr prep;
|
||||
int16 ci;
|
||||
int ci;
|
||||
jpeg_component_info * compptr;
|
||||
|
||||
if (need_full_buffer) /* safety check */
|
||||
@ -364,7 +346,7 @@ jinit_c_prep_controller (j_compress_ptr cinfo, boolean need_full_buffer)
|
||||
ci++, compptr++) {
|
||||
prep->color_buf[ci] = (*cinfo->mem->alloc_sarray)
|
||||
((j_common_ptr) cinfo, JPOOL_IMAGE,
|
||||
(JDIMENSION) (((int32) compptr->width_in_blocks * DCTSIZE *
|
||||
(JDIMENSION) (((long) compptr->width_in_blocks * DCTSIZE *
|
||||
cinfo->max_h_samp_factor) / compptr->h_samp_factor),
|
||||
(JDIMENSION) cinfo->max_v_samp_factor);
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* jcsample.c
|
||||
*
|
||||
* Copyright (C) 1991-1994, Thomas G. Lane.
|
||||
* Copyright (C) 1991-1996, Thomas G. Lane.
|
||||
* This file is part of the Independent JPEG Group's software.
|
||||
* For conditions of distribution and use, see the accompanying README file.
|
||||
*
|
||||
@ -46,7 +46,6 @@
|
||||
*/
|
||||
|
||||
#define JPEG_INTERNALS
|
||||
#include "xp_core.h"/*defines of int32 ect*/
|
||||
#include "jinclude.h"
|
||||
#include "jpeglib.h"
|
||||
|
||||
@ -72,7 +71,7 @@ typedef my_downsampler * my_downsample_ptr;
|
||||
* Initialize for a downsampling pass.
|
||||
*/
|
||||
|
||||
METHODDEF void
|
||||
METHODDEF(void)
|
||||
start_pass_downsample (j_compress_ptr cinfo)
|
||||
{
|
||||
/* no work for now */
|
||||
@ -84,15 +83,15 @@ start_pass_downsample (j_compress_ptr cinfo)
|
||||
* by duplicating the rightmost samples.
|
||||
*/
|
||||
|
||||
LOCAL void
|
||||
expand_right_edge (JSAMPARRAY image_data, int16 num_rows,
|
||||
LOCAL(void)
|
||||
expand_right_edge (JSAMPARRAY image_data, int num_rows,
|
||||
JDIMENSION input_cols, JDIMENSION output_cols)
|
||||
{
|
||||
register JSAMPROW ptr;
|
||||
register JSAMPLE pixval;
|
||||
register int16 count;
|
||||
int16 row;
|
||||
int16 numcols = (int16) (output_cols - input_cols);
|
||||
register int count;
|
||||
int row;
|
||||
int numcols = (int) (output_cols - input_cols);
|
||||
|
||||
if (numcols > 0) {
|
||||
for (row = 0; row < num_rows; row++) {
|
||||
@ -111,13 +110,13 @@ expand_right_edge (JSAMPARRAY image_data, int16 num_rows,
|
||||
* In this version we simply downsample each component independently.
|
||||
*/
|
||||
|
||||
METHODDEF void
|
||||
METHODDEF(void)
|
||||
sep_downsample (j_compress_ptr cinfo,
|
||||
JSAMPIMAGE input_buf, JDIMENSION in_row_index,
|
||||
JSAMPIMAGE output_buf, JDIMENSION out_row_group_index)
|
||||
{
|
||||
my_downsample_ptr downsample = (my_downsample_ptr) cinfo->downsample;
|
||||
int16 ci;
|
||||
int ci;
|
||||
jpeg_component_info * compptr;
|
||||
JSAMPARRAY in_ptr, out_ptr;
|
||||
|
||||
@ -137,15 +136,15 @@ sep_downsample (j_compress_ptr cinfo,
|
||||
* Note that this version is not actually used for customary sampling ratios.
|
||||
*/
|
||||
|
||||
METHODDEF void
|
||||
METHODDEF(void)
|
||||
int_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
|
||||
JSAMPARRAY input_data, JSAMPARRAY output_data)
|
||||
{
|
||||
int16 inrow, outrow, h_expand, v_expand, numpix, numpix2, h, v;
|
||||
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;
|
||||
JSAMPROW inptr, outptr;
|
||||
int32 outvalue;
|
||||
INT32 outvalue;
|
||||
|
||||
h_expand = cinfo->max_h_samp_factor / compptr->h_samp_factor;
|
||||
v_expand = cinfo->max_v_samp_factor / compptr->v_samp_factor;
|
||||
@ -156,7 +155,7 @@ int_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
|
||||
* by the standard loop. Special-casing padded output would be more
|
||||
* efficient.
|
||||
*/
|
||||
expand_right_edge(input_data, (int16)cinfo->max_v_samp_factor,
|
||||
expand_right_edge(input_data, cinfo->max_v_samp_factor,
|
||||
cinfo->image_width, output_cols * h_expand);
|
||||
|
||||
inrow = 0;
|
||||
@ -168,7 +167,7 @@ int_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
|
||||
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++);
|
||||
outvalue += (INT32) GETJSAMPLE(*inptr++);
|
||||
}
|
||||
}
|
||||
*outptr++ = (JSAMPLE) ((outvalue + numpix2) / numpix);
|
||||
@ -184,7 +183,7 @@ int_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
|
||||
* without smoothing.
|
||||
*/
|
||||
|
||||
METHODDEF void
|
||||
METHODDEF(void)
|
||||
fullsize_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
|
||||
JSAMPARRAY input_data, JSAMPARRAY output_data)
|
||||
{
|
||||
@ -192,7 +191,7 @@ fullsize_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
|
||||
jcopy_sample_rows(input_data, 0, output_data, 0,
|
||||
cinfo->max_v_samp_factor, cinfo->image_width);
|
||||
/* Edge-expand */
|
||||
expand_right_edge(output_data, (int16)cinfo->max_v_samp_factor,
|
||||
expand_right_edge(output_data, cinfo->max_v_samp_factor,
|
||||
cinfo->image_width, compptr->width_in_blocks * DCTSIZE);
|
||||
}
|
||||
|
||||
@ -209,21 +208,21 @@ fullsize_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
|
||||
* alternate pixel locations (a simple ordered dither pattern).
|
||||
*/
|
||||
|
||||
METHODDEF void
|
||||
METHODDEF(void)
|
||||
h2v1_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
|
||||
JSAMPARRAY input_data, JSAMPARRAY output_data)
|
||||
{
|
||||
int16 outrow;
|
||||
int outrow;
|
||||
JDIMENSION outcol;
|
||||
JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
|
||||
register JSAMPROW inptr, outptr;
|
||||
register int16 bias;
|
||||
register int bias;
|
||||
|
||||
/* Expand input data enough to let all the output samples be generated
|
||||
* by the standard loop. Special-casing padded output would be more
|
||||
* efficient.
|
||||
*/
|
||||
expand_right_edge(input_data, (int16)cinfo->max_v_samp_factor,
|
||||
expand_right_edge(input_data, cinfo->max_v_samp_factor,
|
||||
cinfo->image_width, output_cols * 2);
|
||||
|
||||
for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
|
||||
@ -246,21 +245,21 @@ h2v1_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
|
||||
* without smoothing.
|
||||
*/
|
||||
|
||||
METHODDEF void
|
||||
METHODDEF(void)
|
||||
h2v2_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
|
||||
JSAMPARRAY input_data, JSAMPARRAY output_data)
|
||||
{
|
||||
int16 inrow, outrow;
|
||||
int inrow, outrow;
|
||||
JDIMENSION outcol;
|
||||
JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
|
||||
register JSAMPROW inptr0, inptr1, outptr;
|
||||
register int16 bias;
|
||||
register int bias;
|
||||
|
||||
/* Expand input data enough to let all the output samples be generated
|
||||
* by the standard loop. Special-casing padded output would be more
|
||||
* efficient.
|
||||
*/
|
||||
expand_right_edge(input_data, (int16)cinfo->max_v_samp_factor,
|
||||
expand_right_edge(input_data, cinfo->max_v_samp_factor,
|
||||
cinfo->image_width, output_cols * 2);
|
||||
|
||||
inrow = 0;
|
||||
@ -289,21 +288,21 @@ h2v2_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
|
||||
* with smoothing. One row of context is required.
|
||||
*/
|
||||
|
||||
METHODDEF void
|
||||
METHODDEF(void)
|
||||
h2v2_smooth_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
|
||||
JSAMPARRAY input_data, JSAMPARRAY output_data)
|
||||
{
|
||||
int16 inrow, outrow;
|
||||
int inrow, outrow;
|
||||
JDIMENSION colctr;
|
||||
JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
|
||||
register JSAMPROW inptr0, inptr1, above_ptr, below_ptr, outptr;
|
||||
int32 membersum, neighsum, memberscale, neighscale;
|
||||
INT32 membersum, neighsum, memberscale, neighscale;
|
||||
|
||||
/* Expand input data enough to let all the output samples be generated
|
||||
* by the standard loop. Special-casing padded output would be more
|
||||
* efficient.
|
||||
*/
|
||||
expand_right_edge(input_data - 1, (int16)(cinfo->max_v_samp_factor + 2),
|
||||
expand_right_edge(input_data - 1, cinfo->max_v_samp_factor + 2,
|
||||
cinfo->image_width, output_cols * 2);
|
||||
|
||||
/* We don't bother to form the individual "smoothed" input pixel values;
|
||||
@ -389,22 +388,22 @@ h2v2_smooth_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
|
||||
* with smoothing. One row of context is required.
|
||||
*/
|
||||
|
||||
METHODDEF void
|
||||
METHODDEF(void)
|
||||
fullsize_smooth_downsample (j_compress_ptr cinfo, jpeg_component_info *compptr,
|
||||
JSAMPARRAY input_data, JSAMPARRAY output_data)
|
||||
{
|
||||
int16 outrow;
|
||||
int outrow;
|
||||
JDIMENSION colctr;
|
||||
JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
|
||||
register JSAMPROW inptr, above_ptr, below_ptr, outptr;
|
||||
int32 membersum, neighsum, memberscale, neighscale;
|
||||
int16 colsum, lastcolsum, nextcolsum;
|
||||
INT32 membersum, neighsum, memberscale, neighscale;
|
||||
int colsum, lastcolsum, nextcolsum;
|
||||
|
||||
/* Expand input data enough to let all the output samples be generated
|
||||
* by the standard loop. Special-casing padded output would be more
|
||||
* efficient.
|
||||
*/
|
||||
expand_right_edge(input_data - 1, (int16)(cinfo->max_v_samp_factor + 2),
|
||||
expand_right_edge(input_data - 1, cinfo->max_v_samp_factor + 2,
|
||||
cinfo->image_width, output_cols);
|
||||
|
||||
/* Each of the eight neighbor pixels contributes a fraction SF to the
|
||||
@ -461,11 +460,11 @@ fullsize_smooth_downsample (j_compress_ptr cinfo, jpeg_component_info *compptr,
|
||||
* Note that we must select a routine for each component.
|
||||
*/
|
||||
|
||||
GLOBAL void
|
||||
GLOBAL(void)
|
||||
jinit_downsampler (j_compress_ptr cinfo)
|
||||
{
|
||||
my_downsample_ptr downsample;
|
||||
int16 ci;
|
||||
int ci;
|
||||
jpeg_component_info * compptr;
|
||||
boolean smoothok = TRUE;
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* jdapimin.c
|
||||
*
|
||||
* Copyright (C) 1994-1995, Thomas G. Lane.
|
||||
* 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.
|
||||
*
|
||||
@ -19,6 +19,7 @@
|
||||
#define JPEG_INTERNALS
|
||||
#include "jinclude.h"
|
||||
#include "jpeglib.h"
|
||||
|
||||
#include "xp_core.h"
|
||||
|
||||
#ifdef XP_WIN32
|
||||
@ -31,8 +32,8 @@ int mmxsupport();
|
||||
* The error manager must already be set up (in case memory manager fails).
|
||||
*/
|
||||
|
||||
GLOBAL JRI_PUBLIC_API(void)
|
||||
jpeg_create_decompress (j_decompress_ptr cinfo)
|
||||
GLOBAL(void)
|
||||
jpeg_CreateDecompress (j_decompress_ptr cinfo, int version, size_t structsize)
|
||||
{
|
||||
int i;
|
||||
|
||||
@ -49,10 +50,27 @@ jpeg_create_decompress (j_decompress_ptr cinfo)
|
||||
/* For debugging purposes, zero the whole master structure.
|
||||
* But error manager pointer is already there, so save and restore it.
|
||||
*/
|
||||
|
||||
/* Guard against version mismatches between library and caller. */
|
||||
cinfo->mem = NULL; /* so jpeg_destroy knows mem mgr not called */
|
||||
if (version != JPEG_LIB_VERSION)
|
||||
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);
|
||||
|
||||
/* For debugging purposes, we zero the whole master structure.
|
||||
* But the application has already set the err pointer, and may have set
|
||||
* client_data, so we have to save and restore those fields.
|
||||
* Note: if application hasn't set client_data, tools like Purify may
|
||||
* complain here.
|
||||
*/
|
||||
{
|
||||
struct jpeg_error_mgr * err = cinfo->err;
|
||||
void * client_data = cinfo->client_data; /* ignore Purify complaint here */
|
||||
MEMZERO(cinfo, SIZEOF(struct jpeg_decompress_struct));
|
||||
cinfo->err = err;
|
||||
cinfo->client_data = client_data;
|
||||
}
|
||||
cinfo->is_decompressor = TRUE;
|
||||
|
||||
@ -74,6 +92,7 @@ jpeg_create_decompress (j_decompress_ptr cinfo)
|
||||
/* Initialize marker processor so application can override methods
|
||||
* for COM, APPn markers before calling jpeg_read_header.
|
||||
*/
|
||||
cinfo->marker_list = NULL;
|
||||
jinit_marker_reader(cinfo);
|
||||
|
||||
/* And initialize the overall input controller. */
|
||||
@ -88,7 +107,7 @@ jpeg_create_decompress (j_decompress_ptr cinfo)
|
||||
* Destruction of a JPEG decompression object
|
||||
*/
|
||||
|
||||
GLOBAL JRI_PUBLIC_API(void)
|
||||
GLOBAL(void)
|
||||
jpeg_destroy_decompress (j_decompress_ptr cinfo)
|
||||
{
|
||||
jpeg_destroy((j_common_ptr) cinfo); /* use common routine */
|
||||
@ -100,35 +119,17 @@ jpeg_destroy_decompress (j_decompress_ptr cinfo)
|
||||
* but don't destroy the object itself.
|
||||
*/
|
||||
|
||||
GLOBAL void
|
||||
GLOBAL(void)
|
||||
jpeg_abort_decompress (j_decompress_ptr cinfo)
|
||||
{
|
||||
jpeg_abort((j_common_ptr) cinfo); /* use common routine */
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Install a special processing method for COM or APPn markers.
|
||||
*/
|
||||
|
||||
GLOBAL JRI_PUBLIC_API(void)
|
||||
jpeg_set_marker_processor (j_decompress_ptr cinfo, int marker_code,
|
||||
jpeg_marker_parser_method routine)
|
||||
{
|
||||
if (marker_code == JPEG_COM)
|
||||
cinfo->marker->process_COM = routine;
|
||||
else if (marker_code >= JPEG_APP0 && marker_code <= JPEG_APP0+15)
|
||||
cinfo->marker->process_APPn[marker_code-JPEG_APP0] = routine;
|
||||
else
|
||||
ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, marker_code);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Set default decompression parameters.
|
||||
*/
|
||||
|
||||
LOCAL void
|
||||
LOCAL(void)
|
||||
default_decompress_parms (j_decompress_ptr cinfo)
|
||||
{
|
||||
/* Guess the input colorspace, and set output colorspace accordingly. */
|
||||
@ -255,7 +256,7 @@ default_decompress_parms (j_decompress_ptr cinfo)
|
||||
* extra error checking.
|
||||
*/
|
||||
|
||||
GLOBAL JRI_PUBLIC_API(int)
|
||||
GLOBAL(int)
|
||||
jpeg_read_header (j_decompress_ptr cinfo, boolean require_image)
|
||||
{
|
||||
int retcode;
|
||||
@ -301,7 +302,7 @@ jpeg_read_header (j_decompress_ptr cinfo, boolean require_image)
|
||||
* method.
|
||||
*/
|
||||
|
||||
GLOBAL JRI_PUBLIC_API(int)
|
||||
GLOBAL(int)
|
||||
jpeg_consume_input (j_decompress_ptr cinfo)
|
||||
{
|
||||
int retcode = JPEG_SUSPENDED;
|
||||
@ -348,7 +349,7 @@ jpeg_consume_input (j_decompress_ptr cinfo)
|
||||
* Have we finished reading the input file?
|
||||
*/
|
||||
|
||||
GLOBAL boolean
|
||||
GLOBAL(boolean)
|
||||
jpeg_input_complete (j_decompress_ptr cinfo)
|
||||
{
|
||||
/* Check for valid jpeg object */
|
||||
@ -363,7 +364,7 @@ jpeg_input_complete (j_decompress_ptr cinfo)
|
||||
* Is there more than one scan?
|
||||
*/
|
||||
|
||||
GLOBAL JRI_PUBLIC_API(boolean)
|
||||
GLOBAL(boolean)
|
||||
jpeg_has_multiple_scans (j_decompress_ptr cinfo)
|
||||
{
|
||||
/* Only valid after jpeg_read_header completes */
|
||||
@ -383,7 +384,7 @@ jpeg_has_multiple_scans (j_decompress_ptr cinfo)
|
||||
* a suspending data source is used.
|
||||
*/
|
||||
|
||||
GLOBAL JRI_PUBLIC_API(boolean)
|
||||
GLOBAL(boolean)
|
||||
jpeg_finish_decompress (j_decompress_ptr cinfo)
|
||||
{
|
||||
if ((cinfo->global_state == DSTATE_SCANNING ||
|
||||
@ -412,6 +413,7 @@ jpeg_finish_decompress (j_decompress_ptr cinfo)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
#ifdef XP_WIN32
|
||||
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* jdapistd.c
|
||||
*
|
||||
* Copyright (C) 1994-1995, Thomas G. Lane.
|
||||
* Copyright (C) 1994-1996, Thomas G. Lane.
|
||||
* This file is part of the Independent JPEG Group's software.
|
||||
* For conditions of distribution and use, see the accompanying README file.
|
||||
*
|
||||
@ -20,7 +20,7 @@
|
||||
|
||||
|
||||
/* Forward declarations */
|
||||
LOCAL boolean output_pass_setup JPP((j_decompress_ptr cinfo));
|
||||
LOCAL(boolean) output_pass_setup JPP((j_decompress_ptr cinfo));
|
||||
|
||||
|
||||
/*
|
||||
@ -34,7 +34,7 @@ LOCAL boolean output_pass_setup JPP((j_decompress_ptr cinfo));
|
||||
* a suspending data source is used.
|
||||
*/
|
||||
|
||||
GLOBAL JRI_PUBLIC_API(boolean)
|
||||
GLOBAL(boolean)
|
||||
jpeg_start_decompress (j_decompress_ptr cinfo)
|
||||
{
|
||||
if (cinfo->global_state == DSTATE_READY) {
|
||||
@ -91,7 +91,7 @@ jpeg_start_decompress (j_decompress_ptr cinfo)
|
||||
* If suspended, returns FALSE and sets global_state = DSTATE_PRESCAN.
|
||||
*/
|
||||
|
||||
LOCAL boolean
|
||||
LOCAL(boolean)
|
||||
output_pass_setup (j_decompress_ptr cinfo)
|
||||
{
|
||||
if (cinfo->global_state != DSTATE_PRESCAN) {
|
||||
@ -148,7 +148,7 @@ output_pass_setup (j_decompress_ptr cinfo)
|
||||
* an oversize buffer (max_lines > scanlines remaining) is not an error.
|
||||
*/
|
||||
|
||||
GLOBAL JRI_PUBLIC_API(JDIMENSION)
|
||||
GLOBAL(JDIMENSION)
|
||||
jpeg_read_scanlines (j_decompress_ptr cinfo, JSAMPARRAY scanlines,
|
||||
JDIMENSION max_lines)
|
||||
{
|
||||
@ -181,7 +181,7 @@ jpeg_read_scanlines (j_decompress_ptr cinfo, JSAMPARRAY scanlines,
|
||||
* Processes exactly one iMCU row per call, unless suspended.
|
||||
*/
|
||||
|
||||
GLOBAL JDIMENSION
|
||||
GLOBAL(JDIMENSION)
|
||||
jpeg_read_raw_data (j_decompress_ptr cinfo, JSAMPIMAGE data,
|
||||
JDIMENSION max_lines)
|
||||
{
|
||||
@ -224,7 +224,7 @@ jpeg_read_raw_data (j_decompress_ptr cinfo, JSAMPIMAGE data,
|
||||
* Initialize for an output pass in buffered-image mode.
|
||||
*/
|
||||
|
||||
GLOBAL JRI_PUBLIC_API(boolean)
|
||||
GLOBAL(boolean)
|
||||
jpeg_start_output (j_decompress_ptr cinfo, int scan_number)
|
||||
{
|
||||
if (cinfo->global_state != DSTATE_BUFIMAGE &&
|
||||
@ -249,7 +249,7 @@ jpeg_start_output (j_decompress_ptr cinfo, int scan_number)
|
||||
* a suspending data source is used.
|
||||
*/
|
||||
|
||||
GLOBAL JRI_PUBLIC_API(boolean)
|
||||
GLOBAL(boolean)
|
||||
jpeg_finish_output (j_decompress_ptr cinfo)
|
||||
{
|
||||
if ((cinfo->global_state == DSTATE_SCANNING ||
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* jdatadst.c
|
||||
*
|
||||
* Copyright (C) 1994, Thomas G. Lane.
|
||||
* Copyright (C) 1994-1996, Thomas G. Lane.
|
||||
* This file is part of the Independent JPEG Group's software.
|
||||
* For conditions of distribution and use, see the accompanying README file.
|
||||
*
|
||||
@ -39,7 +39,7 @@ typedef my_destination_mgr * my_dest_ptr;
|
||||
* before any data is actually written.
|
||||
*/
|
||||
|
||||
METHODDEF void
|
||||
METHODDEF(void)
|
||||
init_destination (j_compress_ptr cinfo)
|
||||
{
|
||||
my_dest_ptr dest = (my_dest_ptr) cinfo->dest;
|
||||
@ -77,7 +77,7 @@ init_destination (j_compress_ptr cinfo)
|
||||
* write it out when emptying the buffer externally.
|
||||
*/
|
||||
|
||||
METHODDEF boolean
|
||||
METHODDEF(boolean)
|
||||
empty_output_buffer (j_compress_ptr cinfo)
|
||||
{
|
||||
my_dest_ptr dest = (my_dest_ptr) cinfo->dest;
|
||||
@ -102,7 +102,7 @@ empty_output_buffer (j_compress_ptr cinfo)
|
||||
* for error exit.
|
||||
*/
|
||||
|
||||
METHODDEF void
|
||||
METHODDEF(void)
|
||||
term_destination (j_compress_ptr cinfo)
|
||||
{
|
||||
my_dest_ptr dest = (my_dest_ptr) cinfo->dest;
|
||||
@ -126,7 +126,7 @@ term_destination (j_compress_ptr cinfo)
|
||||
* for closing it after finishing compression.
|
||||
*/
|
||||
|
||||
GLOBAL JRI_PUBLIC_API(void)
|
||||
GLOBAL(void)
|
||||
jpeg_stdio_dest (j_compress_ptr cinfo, FILE * outfile)
|
||||
{
|
||||
my_dest_ptr dest;
|
||||
@ -150,9 +150,6 @@ jpeg_stdio_dest (j_compress_ptr cinfo, FILE * outfile)
|
||||
dest->outfile = outfile;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* term_destination_file_close --- called by jpeg_finish_compress
|
||||
* after all data has been written. Usually needs to flush buffer.
|
||||
@ -162,7 +159,7 @@ jpeg_stdio_dest (j_compress_ptr cinfo, FILE * outfile)
|
||||
* for error exit.
|
||||
*/
|
||||
|
||||
METHODDEF void
|
||||
METHODDEF(void)
|
||||
term_destination_file_close(j_compress_ptr cinfo)
|
||||
{
|
||||
my_dest_ptr dest = (my_dest_ptr) cinfo->dest;
|
||||
@ -192,7 +189,7 @@ term_destination_file_close(j_compress_ptr cinfo)
|
||||
* for closing it after finishing compression.
|
||||
*/
|
||||
|
||||
GLOBAL JRI_PUBLIC_API(void)
|
||||
GLOBAL(void)
|
||||
jpeg_file_dest (j_compress_ptr cinfo, char * outfile)
|
||||
{
|
||||
my_dest_ptr dest;
|
||||
@ -222,7 +219,7 @@ jpeg_file_dest (j_compress_ptr cinfo, char * outfile)
|
||||
API to close file in case of error. needed for win16. DLL that opens file must also close it.
|
||||
*/
|
||||
|
||||
GLOBAL JRI_PUBLIC_API(void)
|
||||
GLOBAL(void)
|
||||
jpeg_close_file(j_compress_ptr cinfo)
|
||||
{
|
||||
my_dest_ptr dest = (my_dest_ptr) cinfo->dest;
|
||||
@ -231,5 +228,3 @@ jpeg_close_file(j_compress_ptr cinfo)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* jdatasrc.c
|
||||
*
|
||||
* Copyright (C) 1994, Thomas G. Lane.
|
||||
* Copyright (C) 1994-1996, Thomas G. Lane.
|
||||
* This file is part of the Independent JPEG Group's software.
|
||||
* For conditions of distribution and use, see the accompanying README file.
|
||||
*
|
||||
@ -40,7 +40,7 @@ typedef my_source_mgr * my_src_ptr;
|
||||
* before any data is actually read.
|
||||
*/
|
||||
|
||||
METHODDEF void
|
||||
METHODDEF(void)
|
||||
init_source (j_decompress_ptr cinfo)
|
||||
{
|
||||
my_src_ptr src = (my_src_ptr) cinfo->src;
|
||||
@ -86,7 +86,7 @@ init_source (j_decompress_ptr cinfo)
|
||||
* the front of the buffer rather than discarding it.
|
||||
*/
|
||||
|
||||
METHODDEF boolean
|
||||
METHODDEF(boolean)
|
||||
fill_input_buffer (j_decompress_ptr cinfo)
|
||||
{
|
||||
my_src_ptr src = (my_src_ptr) cinfo->src;
|
||||
@ -124,7 +124,7 @@ fill_input_buffer (j_decompress_ptr cinfo)
|
||||
* buffer is the application writer's problem.
|
||||
*/
|
||||
|
||||
METHODDEF void
|
||||
METHODDEF(void)
|
||||
skip_input_data (j_decompress_ptr cinfo, long num_bytes)
|
||||
{
|
||||
my_src_ptr src = (my_src_ptr) cinfo->src;
|
||||
@ -165,7 +165,7 @@ skip_input_data (j_decompress_ptr cinfo, long num_bytes)
|
||||
* for error exit.
|
||||
*/
|
||||
|
||||
METHODDEF void
|
||||
METHODDEF(void)
|
||||
term_source (j_decompress_ptr cinfo)
|
||||
{
|
||||
/* no work necessary here */
|
||||
@ -178,7 +178,7 @@ term_source (j_decompress_ptr cinfo)
|
||||
* for closing it after finishing decompression.
|
||||
*/
|
||||
|
||||
GLOBAL void
|
||||
GLOBAL(void)
|
||||
jpeg_stdio_src (j_decompress_ptr cinfo, FILE * infile)
|
||||
{
|
||||
my_src_ptr src;
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* jdcoefct.c
|
||||
*
|
||||
* Copyright (C) 1994-1995, Thomas G. Lane.
|
||||
* Copyright (C) 1994-1997, Thomas G. Lane.
|
||||
* This file is part of the Independent JPEG Group's software.
|
||||
* For conditions of distribution and use, see the accompanying README file.
|
||||
*
|
||||
@ -62,20 +62,20 @@ typedef struct {
|
||||
typedef my_coef_controller * my_coef_ptr;
|
||||
|
||||
/* Forward declarations */
|
||||
METHODDEF int decompress_onepass
|
||||
METHODDEF(int) decompress_onepass
|
||||
JPP((j_decompress_ptr cinfo, JSAMPIMAGE output_buf));
|
||||
#ifdef D_MULTISCAN_FILES_SUPPORTED
|
||||
METHODDEF int decompress_data
|
||||
METHODDEF(int) decompress_data
|
||||
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
|
||||
LOCAL(boolean) smoothing_ok JPP((j_decompress_ptr cinfo));
|
||||
METHODDEF(int) decompress_smooth_data
|
||||
JPP((j_decompress_ptr cinfo, JSAMPIMAGE output_buf));
|
||||
#endif
|
||||
|
||||
|
||||
LOCAL void
|
||||
LOCAL(void)
|
||||
start_iMCU_row (j_decompress_ptr cinfo)
|
||||
/* Reset within-iMCU-row counters for a new row (input side) */
|
||||
{
|
||||
@ -103,7 +103,7 @@ start_iMCU_row (j_decompress_ptr cinfo)
|
||||
* Initialize for an input processing pass.
|
||||
*/
|
||||
|
||||
METHODDEF void
|
||||
METHODDEF(void)
|
||||
start_input_pass (j_decompress_ptr cinfo)
|
||||
{
|
||||
cinfo->input_iMCU_row = 0;
|
||||
@ -115,7 +115,7 @@ start_input_pass (j_decompress_ptr cinfo)
|
||||
* Initialize for an output processing pass.
|
||||
*/
|
||||
|
||||
METHODDEF void
|
||||
METHODDEF(void)
|
||||
start_output_pass (j_decompress_ptr cinfo)
|
||||
{
|
||||
#ifdef BLOCK_SMOOTHING_SUPPORTED
|
||||
@ -139,11 +139,11 @@ start_output_pass (j_decompress_ptr cinfo)
|
||||
* Input and output must run in lockstep since we have only a one-MCU buffer.
|
||||
* Return value is JPEG_ROW_COMPLETED, JPEG_SCAN_COMPLETED, or JPEG_SUSPENDED.
|
||||
*
|
||||
* NB: output_buf contains a plane for each component in image.
|
||||
* For single pass, this is the same as the components in the scan.
|
||||
* NB: output_buf contains a plane for each component in image,
|
||||
* which we index according to the component's SOF position.
|
||||
*/
|
||||
|
||||
METHODDEF int
|
||||
METHODDEF(int)
|
||||
decompress_onepass (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
|
||||
{
|
||||
my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
|
||||
@ -186,7 +186,8 @@ decompress_onepass (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
|
||||
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[ci] + yoffset * compptr->DCT_scaled_size;
|
||||
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 ||
|
||||
@ -223,7 +224,7 @@ decompress_onepass (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
|
||||
* Dummy consume-input routine for single-pass operation.
|
||||
*/
|
||||
|
||||
METHODDEF int
|
||||
METHODDEF(int)
|
||||
dummy_consume_data (j_decompress_ptr cinfo)
|
||||
{
|
||||
return JPEG_SUSPENDED; /* Always indicate nothing was done */
|
||||
@ -239,7 +240,7 @@ dummy_consume_data (j_decompress_ptr cinfo)
|
||||
* Return value is JPEG_ROW_COMPLETED, JPEG_SCAN_COMPLETED, or JPEG_SUSPENDED.
|
||||
*/
|
||||
|
||||
METHODDEF int
|
||||
METHODDEF(int)
|
||||
consume_data (j_decompress_ptr cinfo)
|
||||
{
|
||||
my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
|
||||
@ -310,7 +311,7 @@ consume_data (j_decompress_ptr cinfo)
|
||||
* NB: output_buf contains a plane for each component in image.
|
||||
*/
|
||||
|
||||
METHODDEF int
|
||||
METHODDEF(int)
|
||||
decompress_data (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
|
||||
{
|
||||
my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
|
||||
@ -385,6 +386,13 @@ decompress_data (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
|
||||
* the coefficients it can estimate are not yet known to full precision.
|
||||
*/
|
||||
|
||||
/* Natural-order array positions of the first 5 zigzag-order coefficients */
|
||||
#define Q01_POS 1
|
||||
#define Q10_POS 8
|
||||
#define Q20_POS 16
|
||||
#define Q11_POS 9
|
||||
#define Q02_POS 2
|
||||
|
||||
/*
|
||||
* Determine whether block smoothing is applicable and safe.
|
||||
* We also latch the current states of the coef_bits[] entries for the
|
||||
@ -393,7 +401,7 @@ decompress_data (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
|
||||
* more accurately than they really are.
|
||||
*/
|
||||
|
||||
LOCAL boolean
|
||||
LOCAL(boolean)
|
||||
smoothing_ok (j_decompress_ptr cinfo)
|
||||
{
|
||||
my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
|
||||
@ -421,10 +429,13 @@ smoothing_ok (j_decompress_ptr cinfo)
|
||||
if ((qtable = compptr->quant_table) == NULL)
|
||||
return FALSE;
|
||||
/* Verify DC & first 5 AC quantizers are nonzero to avoid zero-divide. */
|
||||
for (coefi = 0; coefi <= 5; coefi++) {
|
||||
if (qtable->quantval[coefi] == 0)
|
||||
return FALSE;
|
||||
}
|
||||
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)
|
||||
return FALSE;
|
||||
/* DC values must be at least partly known for all components. */
|
||||
coef_bits = cinfo->coef_bits[ci];
|
||||
if (coef_bits[0] < 0)
|
||||
@ -446,7 +457,7 @@ smoothing_ok (j_decompress_ptr cinfo)
|
||||
* Variant of decompress_data for use when doing block smoothing.
|
||||
*/
|
||||
|
||||
METHODDEF int
|
||||
METHODDEF(int)
|
||||
decompress_smooth_data (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
|
||||
{
|
||||
my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
|
||||
@ -521,11 +532,11 @@ decompress_smooth_data (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
|
||||
coef_bits = coef->coef_bits_latch + (ci * SAVED_COEFS);
|
||||
quanttbl = compptr->quant_table;
|
||||
Q00 = quanttbl->quantval[0];
|
||||
Q01 = quanttbl->quantval[1];
|
||||
Q10 = quanttbl->quantval[2];
|
||||
Q20 = quanttbl->quantval[3];
|
||||
Q11 = quanttbl->quantval[4];
|
||||
Q02 = quanttbl->quantval[5];
|
||||
Q01 = quanttbl->quantval[Q01_POS];
|
||||
Q10 = quanttbl->quantval[Q10_POS];
|
||||
Q20 = quanttbl->quantval[Q20_POS];
|
||||
Q11 = quanttbl->quantval[Q11_POS];
|
||||
Q02 = quanttbl->quantval[Q02_POS];
|
||||
inverse_DCT = cinfo->idct->inverse_DCT[ci];
|
||||
output_ptr = output_buf[ci];
|
||||
/* Loop over all DCT blocks to be processed. */
|
||||
@ -661,7 +672,7 @@ decompress_smooth_data (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
|
||||
* Initialize coefficient buffer controller.
|
||||
*/
|
||||
|
||||
GLOBAL void
|
||||
GLOBAL(void)
|
||||
jinit_d_coef_controller (j_decompress_ptr cinfo, boolean need_full_buffer)
|
||||
{
|
||||
my_coef_ptr coef;
|
||||
|
315
jpeg/jdcolor.c
315
jpeg/jdcolor.c
@ -1,21 +1,17 @@
|
||||
/*
|
||||
* jdcolor.c
|
||||
*
|
||||
* This file contains an Optimized Routine for YCbCr->RGB Color Space Conversion
|
||||
*
|
||||
* Copyright (C) 1991-1996, Thomas G. Lane.
|
||||
* 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 output colorspace conversion routines.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#define JPEG_INTERNALS
|
||||
#include "jinclude.h"
|
||||
#include "jpeglib.h"
|
||||
#include "xp_core.h"
|
||||
|
||||
|
||||
/* Private subobject */
|
||||
|
||||
@ -32,39 +28,6 @@ typedef struct {
|
||||
typedef my_color_deconverter * my_cconvert_ptr;
|
||||
|
||||
|
||||
#ifdef XP_WIN32
|
||||
/* Info Added for MMX(TM) Technology Optimization */
|
||||
extern void MMXYCbCr2RGB(
|
||||
int columns,
|
||||
unsigned char *inY,
|
||||
unsigned char *inU,
|
||||
unsigned char *inV,
|
||||
unsigned char *outRGB);
|
||||
/*
|
||||
These constants correspond to CCIR 601-1
|
||||
R = [256*Y + 359*(Cr-128)] / 256
|
||||
G = [256*Y - 88*(Cb-128) - 183*(Cr-128)] / 256
|
||||
B = [256*Y + 454*(Cb-128)] / 256
|
||||
Conventional floating point equations:
|
||||
R = Y + 1.40200 * Cr
|
||||
G = Y - 0.34414 * Cb - 0.71414 * Cr
|
||||
B = Y + 1.77200 * Cb
|
||||
*/
|
||||
/*Ry=0100 Ru=0000 Rv=0167*/
|
||||
/*Gy=0100 Gu=FFA8 Gv=FF49*/
|
||||
/*By=0100 Bu=01C6 Bv=0000*/
|
||||
/* constants for YCbCr->RGB and YCbCrA->RGBA*/
|
||||
static __int64 const_0 = 0x0000000000000000;
|
||||
static __int64 const_sub128 = 0x0080008000800080;
|
||||
static __int64 const_VUmul = 0xFF49FFA8FF49FFA8;
|
||||
static __int64 const_YVmul = 0x0100016701000167;
|
||||
static __int64 const_YUmul = 0x010001C6010001C6;
|
||||
static __int64 mask_highd = 0xFFFFFFFF00000000;
|
||||
static __int64 const_invert = 0x00FFFFFF00FFFFFF;
|
||||
|
||||
/* End of added info */
|
||||
#endif
|
||||
|
||||
/**************** YCbCr -> RGB conversion: most common case **************/
|
||||
|
||||
/*
|
||||
@ -103,7 +66,7 @@ static __int64 const_invert = 0x00FFFFFF00FFFFFF;
|
||||
* Initialize tables for YCC->RGB colorspace conversion.
|
||||
*/
|
||||
|
||||
LOCAL void
|
||||
LOCAL(void)
|
||||
build_ycc_rgb_table (j_decompress_ptr cinfo)
|
||||
{
|
||||
my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
|
||||
@ -153,7 +116,7 @@ build_ycc_rgb_table (j_decompress_ptr cinfo)
|
||||
* offset required on that side.
|
||||
*/
|
||||
|
||||
METHODDEF void
|
||||
METHODDEF(void)
|
||||
ycc_rgb_convert (j_decompress_ptr cinfo,
|
||||
JSAMPIMAGE input_buf, JDIMENSION input_row,
|
||||
JSAMPARRAY output_buf, int num_rows)
|
||||
@ -164,13 +127,6 @@ ycc_rgb_convert (j_decompress_ptr cinfo,
|
||||
register JSAMPROW inptr0, inptr1, inptr2;
|
||||
register JDIMENSION col;
|
||||
JDIMENSION num_cols = cinfo->output_width;
|
||||
#ifdef XP_WIN32
|
||||
/* Alignment variables - CRK */
|
||||
/* JDIMENSION tail_cols = num_cols&7; */
|
||||
|
||||
JDIMENSION mmx_cols=num_cols&~7;
|
||||
#endif
|
||||
|
||||
/* copy these pointers into registers if possible */
|
||||
register JSAMPLE * range_limit = cinfo->sample_range_limit;
|
||||
register int * Crrtab = cconvert->Cr_r_tab;
|
||||
@ -179,63 +135,28 @@ ycc_rgb_convert (j_decompress_ptr cinfo,
|
||||
register INT32 * Cbgtab = cconvert->Cb_g_tab;
|
||||
SHIFT_TEMPS
|
||||
|
||||
#ifdef XP_WIN32
|
||||
if(MMXAvailable) { //MMX Code - CRK
|
||||
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++;
|
||||
MMXYCbCr2RGB(mmx_cols, inptr0, inptr1, inptr2, outptr);
|
||||
|
||||
outptr += 3*mmx_cols;
|
||||
for (col = mmx_cols; col < num_cols; col++) {
|
||||
y = GETJSAMPLE(inptr0[col]);
|
||||
cb = GETJSAMPLE(inptr1[col]);
|
||||
cr = GETJSAMPLE(inptr2[col]);
|
||||
/* 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))];
|
||||
outptr[RGB_BLUE] = range_limit[y + Cbbtab[cb]];
|
||||
outptr += RGB_PIXELSIZE;
|
||||
}
|
||||
}
|
||||
__asm emms
|
||||
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++) {
|
||||
y = GETJSAMPLE(inptr0[col]);
|
||||
cb = GETJSAMPLE(inptr1[col]);
|
||||
cr = GETJSAMPLE(inptr2[col]);
|
||||
/* 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))];
|
||||
outptr[RGB_BLUE] = range_limit[y + Cbbtab[cb]];
|
||||
outptr += RGB_PIXELSIZE;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
#endif
|
||||
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++) {
|
||||
y = GETJSAMPLE(inptr0[col]);
|
||||
cb = GETJSAMPLE(inptr1[col]);
|
||||
cr = GETJSAMPLE(inptr2[col]);
|
||||
/* 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))];
|
||||
outptr[RGB_BLUE] = range_limit[y + Cbbtab[cb]];
|
||||
outptr += RGB_PIXELSIZE;
|
||||
}
|
||||
}
|
||||
#ifdef XP_WIN32
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**************** Cases other than YCbCr -> RGB **************/
|
||||
|
||||
|
||||
@ -244,7 +165,7 @@ ycc_rgb_convert (j_decompress_ptr cinfo,
|
||||
* converting from separate-planes to interleaved representation.
|
||||
*/
|
||||
|
||||
METHODDEF void
|
||||
METHODDEF(void)
|
||||
null_convert (j_decompress_ptr cinfo,
|
||||
JSAMPIMAGE input_buf, JDIMENSION input_row,
|
||||
JSAMPARRAY output_buf, int num_rows)
|
||||
@ -270,14 +191,13 @@ null_convert (j_decompress_ptr cinfo,
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Color conversion for grayscale: just copy the data.
|
||||
* This also works for YCbCr -> grayscale conversion, in which
|
||||
* we just copy the Y (luminance) component and ignore chrominance.
|
||||
*/
|
||||
|
||||
METHODDEF void
|
||||
METHODDEF(void)
|
||||
grayscale_convert (j_decompress_ptr cinfo,
|
||||
JSAMPIMAGE input_buf, JDIMENSION input_row,
|
||||
JSAMPARRAY output_buf, int num_rows)
|
||||
@ -287,6 +207,33 @@ grayscale_convert (j_decompress_ptr cinfo,
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Convert grayscale to RGB: just duplicate the graylevel three times.
|
||||
* This is provided to support applications that don't want to cope
|
||||
* with grayscale as a separate case.
|
||||
*/
|
||||
|
||||
METHODDEF(void)
|
||||
gray_rgb_convert (j_decompress_ptr cinfo,
|
||||
JSAMPIMAGE input_buf, JDIMENSION input_row,
|
||||
JSAMPARRAY output_buf, int num_rows)
|
||||
{
|
||||
register JSAMPROW inptr, outptr;
|
||||
register JDIMENSION col;
|
||||
JDIMENSION num_cols = cinfo->output_width;
|
||||
|
||||
while (--num_rows >= 0) {
|
||||
inptr = input_buf[0][input_row++];
|
||||
outptr = *output_buf++;
|
||||
for (col = 0; col < num_cols; col++) {
|
||||
/* We can dispense with GETJSAMPLE() here */
|
||||
outptr[RGB_RED] = outptr[RGB_GREEN] = outptr[RGB_BLUE] = inptr[col];
|
||||
outptr += RGB_PIXELSIZE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Adobe-style YCCK->CMYK conversion.
|
||||
* We convert YCbCr to R=1-C, G=1-M, and B=1-Y using the same
|
||||
@ -294,7 +241,7 @@ grayscale_convert (j_decompress_ptr cinfo,
|
||||
* We assume build_ycc_rgb_table has been called.
|
||||
*/
|
||||
|
||||
METHODDEF void
|
||||
METHODDEF(void)
|
||||
ycck_cmyk_convert (j_decompress_ptr cinfo,
|
||||
JSAMPIMAGE input_buf, JDIMENSION input_row,
|
||||
JSAMPARRAY output_buf, int num_rows)
|
||||
@ -342,7 +289,7 @@ ycck_cmyk_convert (j_decompress_ptr cinfo,
|
||||
* Empty method for start_pass.
|
||||
*/
|
||||
|
||||
METHODDEF void
|
||||
METHODDEF(void)
|
||||
start_pass_dcolor (j_decompress_ptr cinfo)
|
||||
{
|
||||
/* no work needed */
|
||||
@ -353,7 +300,7 @@ start_pass_dcolor (j_decompress_ptr cinfo)
|
||||
* Module initialization routine for output colorspace conversion.
|
||||
*/
|
||||
|
||||
GLOBAL void
|
||||
GLOBAL(void)
|
||||
jinit_color_deconverter (j_decompress_ptr cinfo)
|
||||
{
|
||||
my_cconvert_ptr cconvert;
|
||||
@ -413,6 +360,8 @@ jinit_color_deconverter (j_decompress_ptr cinfo)
|
||||
if (cinfo->jpeg_color_space == JCS_YCbCr) {
|
||||
cconvert->pub.color_convert = ycc_rgb_convert;
|
||||
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
|
||||
@ -445,155 +394,3 @@ jinit_color_deconverter (j_decompress_ptr cinfo)
|
||||
else
|
||||
cinfo->output_components = cinfo->out_color_components;
|
||||
}
|
||||
|
||||
|
||||
#ifdef XP_WIN32
|
||||
// MMX(tm) technology assembly code additions begin here
|
||||
void MMXYCbCr2RGB(
|
||||
int columns,
|
||||
unsigned char *inY,
|
||||
unsigned char *inU,
|
||||
unsigned char *inV,
|
||||
unsigned char *outRGB)
|
||||
{
|
||||
|
||||
//; This program will compile with Microsoft Visual C++ 4.1 or greater.
|
||||
//; Use the /GM compile switch to allow the compilation of MMX(tm) Technology
|
||||
//; instructions as inline assembly
|
||||
|
||||
__asm {
|
||||
// Initialize all the pointers, loop variables
|
||||
mov eax, inY
|
||||
mov ecx, inV
|
||||
|
||||
mov edi, columns
|
||||
mov ebx, inU
|
||||
|
||||
shr edi, 2 ; number of loops = cols/4
|
||||
mov edx, outRGB
|
||||
|
||||
// Main Loop to process 12 bytes
|
||||
YUVtoRGB:
|
||||
movd mm0, [eax] ; 0/0/0/0/Y3/Y2/Y1/Y0
|
||||
pxor mm7, mm7 ; use mm7 as const_0 to achieve better pairing at start
|
||||
|
||||
movd mm2, [ebx] ; 0/0/0/0/U3/U2/U1/U0
|
||||
punpcklbw mm0, mm7 ; Y3/Y2/Y1/Y0
|
||||
|
||||
movd mm3, [ecx] ; 0/0/0/0/V3/V2/V1/V0
|
||||
punpcklbw mm2, mm7 ; U3/U2/U1/U0
|
||||
|
||||
psubsw mm2, const_sub128 ; U3'/U2'/U1'/U0'
|
||||
punpcklbw mm3, mm7 ; V3/V2/V1/V0
|
||||
|
||||
psubsw mm3, const_sub128 ; V3'/V2'/V1'/V0'
|
||||
movq mm4, mm2
|
||||
|
||||
punpcklwd mm2, mm3 ; V1'/U1'/V0'/U0'
|
||||
movq mm1, mm0
|
||||
|
||||
pmaddwd mm2, const_VUmul ; gvV1'+guU1'/gvV0'+guU0'
|
||||
psllw mm1, 8 ; Y3*256/Y2*256/Y1*256/Y0*256
|
||||
|
||||
movq mm6, mm1
|
||||
punpcklwd mm1, mm7 ; Y1*256/Y0*256
|
||||
|
||||
punpckhwd mm6, mm7 ; Y3*256/Y2*256
|
||||
movq mm5, mm4
|
||||
|
||||
punpckhwd mm5, mm3 ; V3'/U3'/V2'/U2'
|
||||
paddd mm2, mm1 ; G1*256/G0*256 (mm1 free)
|
||||
|
||||
pmaddwd mm5, const_VUmul ; gvV3'+guU3'/gvV2'+guU2'
|
||||
movq mm1, mm3 ; (using mm1)
|
||||
|
||||
punpcklwd mm3, mm0 ; Y1/V1'/Y0/V0'
|
||||
movq mm7, mm4 ; This wipes out the zero constant
|
||||
|
||||
pmaddwd mm3, const_YVmul ; ryY1+rvV1'/ryY0+rvV0'
|
||||
psrad mm2, 8 ; G1/G0
|
||||
|
||||
paddd mm5, mm6 ; G3*256/G2*256 (mm6 free)
|
||||
punpcklwd mm4, mm0 ; Y1/U1'/Y0/U0'
|
||||
|
||||
pmaddwd mm4, const_YUmul ; // "byY1+buU1'/byY0'+buU0'"
|
||||
psrad mm5, 8 ; G3/G2
|
||||
|
||||
psrad mm3, 8 ; R1/R0
|
||||
|
||||
punpckhwd mm7 , mm0 ; Y3/U3'/Y2/U2'
|
||||
|
||||
psrad mm4, 8 ; B1/B0
|
||||
movq mm6, mm3
|
||||
|
||||
pmaddwd mm7, const_YUmul ; // "byY3+buU3'/byY2'+buU2'"
|
||||
punpckhwd mm1, mm0 ; Y3/V3'/Y2/V2'
|
||||
|
||||
pmaddwd mm1, const_YVmul ; ryY3+rvV3'/ryY2+rvV2'
|
||||
punpckldq mm3, mm2 ; G0/R0
|
||||
|
||||
punpckhdq mm6, mm2 ; G1/R1 (mm2 free)
|
||||
movq mm0, mm4
|
||||
|
||||
psrad mm7, 8 ; B3/B2
|
||||
|
||||
punpckldq mm4, const_0 ; 0/B0
|
||||
|
||||
punpckhdq mm0, const_0 ; 0/B1
|
||||
|
||||
psrad mm1, 8 ; R3/R2
|
||||
|
||||
packssdw mm3, mm4 ; 0/B0/G0/R0 (mm4 free)
|
||||
movq mm2, mm1
|
||||
|
||||
packssdw mm6, mm0 ; 0/B1/G1/R1 (mm0 free)
|
||||
|
||||
packuswb mm3, mm6 ; 0/B1/G1/R1/0/B0/G0/R0 (mm6 free)
|
||||
|
||||
punpckldq mm2, mm5 ; G2/R2
|
||||
movq mm4, mm7
|
||||
|
||||
punpckhdq mm1, mm5 ; G3/R3 (mm5 done)
|
||||
|
||||
punpckldq mm7, const_0 ; 0/B2 (change this line for alpha code)
|
||||
|
||||
punpckhdq mm4, const_0 ; 0/B3 (change this line for alpha code)
|
||||
|
||||
movq mm0, mm3
|
||||
packssdw mm2, mm7 ; 0/B2/G2/R2
|
||||
|
||||
pand mm3, mask_highd ; 0/B1/G1/R1/0/0/0/0
|
||||
packssdw mm1, mm4 ; 0/B3/G3/R3
|
||||
|
||||
psrlq mm3, 8 ; 0/0/B1/G1/R1/0/0/0
|
||||
add edx, 12
|
||||
|
||||
por mm0, mm3 ; 0/0/?/?/R1/B0/G0/R0
|
||||
packuswb mm2, mm1 ; 0/B3/G3/R3/0/B2/G2/R2
|
||||
|
||||
psrlq mm3, 32 ; 0/0/0/0/0/0/B1/G1
|
||||
add eax, 4
|
||||
|
||||
movd [edx][-12], mm0 ; correct for add
|
||||
punpcklwd mm3, mm2 ; 0/B2/0/0/G2/R2/B1/G1
|
||||
|
||||
psrlq mm2, 24 ; 0/0/0/0/B3/G3/R3/0
|
||||
add ecx, 4
|
||||
|
||||
movd [edx][-8], mm3 ; correct for previous add
|
||||
psrlq mm3, 48 ; 0/0/0/0/0/0/0/B2
|
||||
|
||||
por mm2, mm3 ; 0/0/0/0/B3/G3/R3/0
|
||||
add ebx, 4
|
||||
|
||||
movd [edx][-4], mm2 ; correct for previous add
|
||||
|
||||
dec edi
|
||||
jnz YUVtoRGB ; Do 12 more bytes if not zero
|
||||
|
||||
//emms // "commented out since it is done at the end of the caller's loop"
|
||||
} // end of __asm
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
20
jpeg/jdct.h
20
jpeg/jdct.h
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* jdct.h
|
||||
*
|
||||
* Copyright (C) 1994, Thomas G. Lane.
|
||||
* Copyright (C) 1994-1996, Thomas G. Lane.
|
||||
* This file is part of the Independent JPEG Group's software.
|
||||
* For conditions of distribution and use, see the accompanying README file.
|
||||
*
|
||||
@ -94,26 +94,26 @@ typedef FAST_FLOAT FLOAT_MULT_TYPE; /* preferred floating type */
|
||||
|
||||
/* 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));
|
||||
EXTERN(void) jpeg_fdct_ifast JPP((DCTELEM * data));
|
||||
EXTERN(void) jpeg_fdct_float JPP((FAST_FLOAT * data));
|
||||
|
||||
EXTERN void jpeg_idct_islow
|
||||
EXTERN(void) jpeg_idct_islow
|
||||
JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
||||
JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
|
||||
EXTERN void jpeg_idct_ifast
|
||||
EXTERN(void) jpeg_idct_ifast
|
||||
JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
||||
JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
|
||||
EXTERN void jpeg_idct_float
|
||||
EXTERN(void) jpeg_idct_float
|
||||
JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
||||
JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
|
||||
EXTERN void jpeg_idct_4x4
|
||||
EXTERN(void) jpeg_idct_4x4
|
||||
JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
||||
JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
|
||||
EXTERN void jpeg_idct_2x2
|
||||
EXTERN(void) jpeg_idct_2x2
|
||||
JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
||||
JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
|
||||
EXTERN void jpeg_idct_1x1
|
||||
EXTERN(void) jpeg_idct_1x1
|
||||
JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
||||
JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* jddctmgr.c
|
||||
*
|
||||
* Copyright (C) 1994-1995, Thomas G. Lane.
|
||||
* Copyright (C) 1994-1996, Thomas G. Lane.
|
||||
* This file is part of the Independent JPEG Group's software.
|
||||
* For conditions of distribution and use, see the accompanying README file.
|
||||
*
|
||||
@ -85,7 +85,7 @@ typedef union {
|
||||
* a matching multiplier table.
|
||||
*/
|
||||
|
||||
METHODDEF void
|
||||
METHODDEF(void)
|
||||
start_pass (j_decompress_ptr cinfo)
|
||||
{
|
||||
my_idct_ptr idct = (my_idct_ptr) cinfo->idct;
|
||||
@ -161,11 +161,11 @@ start_pass (j_decompress_ptr cinfo)
|
||||
case JDCT_ISLOW:
|
||||
{
|
||||
/* For LL&M IDCT method, multipliers are equal to raw quantization
|
||||
* coefficients, but are stored in natural order as ints.
|
||||
* 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[jpeg_zigzag_order[i]];
|
||||
ismtbl[i] = (ISLOW_MULT_TYPE) qtbl->quantval[i];
|
||||
}
|
||||
}
|
||||
break;
|
||||
@ -178,7 +178,7 @@ start_pass (j_decompress_ptr cinfo)
|
||||
* 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. The multipliers are stored in natural order.
|
||||
* IFAST_SCALE_BITS.
|
||||
*/
|
||||
IFAST_MULT_TYPE * ifmtbl = (IFAST_MULT_TYPE *) compptr->dct_table;
|
||||
#define CONST_BITS 14
|
||||
@ -197,7 +197,7 @@ start_pass (j_decompress_ptr cinfo)
|
||||
|
||||
for (i = 0; i < DCTSIZE2; i++) {
|
||||
ifmtbl[i] = (IFAST_MULT_TYPE)
|
||||
DESCALE(MULTIPLY16V16((INT32) qtbl->quantval[jpeg_zigzag_order[i]],
|
||||
DESCALE(MULTIPLY16V16((INT32) qtbl->quantval[i],
|
||||
(INT32) aanscales[i]),
|
||||
CONST_BITS-IFAST_SCALE_BITS);
|
||||
}
|
||||
@ -211,7 +211,6 @@ start_pass (j_decompress_ptr cinfo)
|
||||
* coefficients scaled by scalefactor[row]*scalefactor[col], where
|
||||
* scalefactor[0] = 1
|
||||
* scalefactor[k] = cos(k*PI/16) * sqrt(2) for k=1..7
|
||||
* The multipliers are stored in natural order.
|
||||
*/
|
||||
FLOAT_MULT_TYPE * fmtbl = (FLOAT_MULT_TYPE *) compptr->dct_table;
|
||||
int row, col;
|
||||
@ -224,7 +223,7 @@ start_pass (j_decompress_ptr cinfo)
|
||||
for (row = 0; row < DCTSIZE; row++) {
|
||||
for (col = 0; col < DCTSIZE; col++) {
|
||||
fmtbl[i] = (FLOAT_MULT_TYPE)
|
||||
((double) qtbl->quantval[jpeg_zigzag_order[i]] *
|
||||
((double) qtbl->quantval[i] *
|
||||
aanscalefactor[row] * aanscalefactor[col]);
|
||||
i++;
|
||||
}
|
||||
@ -244,7 +243,7 @@ start_pass (j_decompress_ptr cinfo)
|
||||
* Initialize IDCT manager.
|
||||
*/
|
||||
|
||||
GLOBAL void
|
||||
GLOBAL(void)
|
||||
jinit_inverse_dct (j_decompress_ptr cinfo)
|
||||
{
|
||||
my_idct_ptr idct;
|
||||
|
420
jpeg/jdhuff.c
420
jpeg/jdhuff.c
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* jdhuff.c
|
||||
*
|
||||
* Copyright (C) 1991-1995, Thomas G. Lane.
|
||||
* 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.
|
||||
*
|
||||
@ -64,6 +64,15 @@ typedef struct {
|
||||
/* Pointers to derived tables (these workspaces have image lifespan) */
|
||||
d_derived_tbl * dc_derived_tbls[NUM_HUFF_TBLS];
|
||||
d_derived_tbl * ac_derived_tbls[NUM_HUFF_TBLS];
|
||||
|
||||
/* Precalculated info set up by start_pass for use in decode_mcu: */
|
||||
|
||||
/* Pointers to derived tables to be used for each block within an MCU */
|
||||
d_derived_tbl * dc_cur_tbls[D_MAX_BLOCKS_IN_MCU];
|
||||
d_derived_tbl * ac_cur_tbls[D_MAX_BLOCKS_IN_MCU];
|
||||
/* Whether we care about the DC and AC coefficient values for each block */
|
||||
boolean dc_needed[D_MAX_BLOCKS_IN_MCU];
|
||||
boolean ac_needed[D_MAX_BLOCKS_IN_MCU];
|
||||
} huff_entropy_decoder;
|
||||
|
||||
typedef huff_entropy_decoder * huff_entropy_ptr;
|
||||
@ -73,11 +82,11 @@ typedef huff_entropy_decoder * huff_entropy_ptr;
|
||||
* Initialize for a Huffman-compressed scan.
|
||||
*/
|
||||
|
||||
METHODDEF void
|
||||
METHODDEF(void)
|
||||
start_pass_huff_decoder (j_decompress_ptr cinfo)
|
||||
{
|
||||
huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
|
||||
int ci, dctbl, actbl;
|
||||
int ci, blkn, dctbl, actbl;
|
||||
jpeg_component_info * compptr;
|
||||
|
||||
/* Check that the scan parameters Ss, Se, Ah/Al are OK for sequential JPEG.
|
||||
@ -92,27 +101,37 @@ start_pass_huff_decoder (j_decompress_ptr cinfo)
|
||||
compptr = cinfo->cur_comp_info[ci];
|
||||
dctbl = compptr->dc_tbl_no;
|
||||
actbl = compptr->ac_tbl_no;
|
||||
/* Make sure requested tables are present */
|
||||
if (dctbl < 0 || dctbl >= NUM_HUFF_TBLS ||
|
||||
cinfo->dc_huff_tbl_ptrs[dctbl] == NULL)
|
||||
ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, dctbl);
|
||||
if (actbl < 0 || actbl >= NUM_HUFF_TBLS ||
|
||||
cinfo->ac_huff_tbl_ptrs[actbl] == NULL)
|
||||
ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, actbl);
|
||||
/* Compute derived values for Huffman tables */
|
||||
/* We may do this more than once for a table, but it's not expensive */
|
||||
jpeg_make_d_derived_tbl(cinfo, cinfo->dc_huff_tbl_ptrs[dctbl],
|
||||
jpeg_make_d_derived_tbl(cinfo, TRUE, dctbl,
|
||||
& entropy->dc_derived_tbls[dctbl]);
|
||||
jpeg_make_d_derived_tbl(cinfo, cinfo->ac_huff_tbl_ptrs[actbl],
|
||||
jpeg_make_d_derived_tbl(cinfo, FALSE, actbl,
|
||||
& entropy->ac_derived_tbls[actbl]);
|
||||
/* Initialize DC predictions to 0 */
|
||||
entropy->saved.last_dc_val[ci] = 0;
|
||||
}
|
||||
|
||||
/* Precalculate decoding info for each block in an MCU of this scan */
|
||||
for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
|
||||
ci = cinfo->MCU_membership[blkn];
|
||||
compptr = cinfo->cur_comp_info[ci];
|
||||
/* Precalculate which table to use for each block */
|
||||
entropy->dc_cur_tbls[blkn] = entropy->dc_derived_tbls[compptr->dc_tbl_no];
|
||||
entropy->ac_cur_tbls[blkn] = entropy->ac_derived_tbls[compptr->ac_tbl_no];
|
||||
/* Decide whether we really care about the coefficient values */
|
||||
if (compptr->component_needed) {
|
||||
entropy->dc_needed[blkn] = TRUE;
|
||||
/* we don't need the ACs if producing a 1/8th-size image */
|
||||
entropy->ac_needed[blkn] = (compptr->DCT_scaled_size > 1);
|
||||
} else {
|
||||
entropy->dc_needed[blkn] = entropy->ac_needed[blkn] = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
/* Initialize bitread state variables */
|
||||
entropy->bitstate.bits_left = 0;
|
||||
entropy->bitstate.get_buffer = 0; /* unnecessary, but keeps Purify quiet */
|
||||
entropy->bitstate.printed_eod = FALSE;
|
||||
entropy->pub.insufficient_data = FALSE;
|
||||
|
||||
/* Initialize restart counter */
|
||||
entropy->restarts_to_go = cinfo->restart_interval;
|
||||
@ -121,20 +140,35 @@ start_pass_huff_decoder (j_decompress_ptr cinfo)
|
||||
|
||||
/*
|
||||
* Compute the derived values for a Huffman table.
|
||||
* This routine also performs some validation checks on the table.
|
||||
*
|
||||
* Note this is also used by jdphuff.c.
|
||||
*/
|
||||
|
||||
GLOBAL void
|
||||
jpeg_make_d_derived_tbl (j_decompress_ptr cinfo, JHUFF_TBL * htbl,
|
||||
GLOBAL(void)
|
||||
jpeg_make_d_derived_tbl (j_decompress_ptr cinfo, boolean isDC, int tblno,
|
||||
d_derived_tbl ** pdtbl)
|
||||
{
|
||||
JHUFF_TBL *htbl;
|
||||
d_derived_tbl *dtbl;
|
||||
int p, i, l, si;
|
||||
int p, i, l, si, numsymbols;
|
||||
int lookbits, ctr;
|
||||
char huffsize[257];
|
||||
unsigned int huffcode[257];
|
||||
unsigned int code;
|
||||
|
||||
/* Note that huffsize[] and huffcode[] are filled in code-length order,
|
||||
* paralleling the order of the symbols themselves in htbl->huffval[].
|
||||
*/
|
||||
|
||||
/* Find the input Huffman table */
|
||||
if (tblno < 0 || tblno >= NUM_HUFF_TBLS)
|
||||
ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno);
|
||||
htbl =
|
||||
isDC ? cinfo->dc_huff_tbl_ptrs[tblno] : cinfo->ac_huff_tbl_ptrs[tblno];
|
||||
if (htbl == NULL)
|
||||
ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno);
|
||||
|
||||
/* Allocate a workspace if we haven't already done so. */
|
||||
if (*pdtbl == NULL)
|
||||
*pdtbl = (d_derived_tbl *)
|
||||
@ -144,17 +178,20 @@ jpeg_make_d_derived_tbl (j_decompress_ptr cinfo, JHUFF_TBL * htbl,
|
||||
dtbl->pub = htbl; /* fill in back link */
|
||||
|
||||
/* Figure C.1: make table of Huffman code length for each symbol */
|
||||
/* Note that this is in code-length order. */
|
||||
|
||||
p = 0;
|
||||
for (l = 1; l <= 16; l++) {
|
||||
for (i = 1; i <= (int) htbl->bits[l]; i++)
|
||||
i = (int) htbl->bits[l];
|
||||
if (i < 0 || p + i > 256) /* protect against table overrun */
|
||||
ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
|
||||
while (i--)
|
||||
huffsize[p++] = (char) l;
|
||||
}
|
||||
huffsize[p] = 0;
|
||||
numsymbols = p;
|
||||
|
||||
/* Figure C.2: generate the codes themselves */
|
||||
/* Note that this is in code-length order. */
|
||||
/* We also validate that the counts represent a legal Huffman code tree. */
|
||||
|
||||
code = 0;
|
||||
si = huffsize[0];
|
||||
@ -164,6 +201,11 @@ jpeg_make_d_derived_tbl (j_decompress_ptr cinfo, JHUFF_TBL * htbl,
|
||||
huffcode[p++] = code;
|
||||
code++;
|
||||
}
|
||||
/* code is now 1 more than the last code used for codelength si; but
|
||||
* it must still fit in si bits, since no code is allowed to be all ones.
|
||||
*/
|
||||
if (((INT32) code) >= (((INT32) 1) << si))
|
||||
ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
|
||||
code <<= 1;
|
||||
si++;
|
||||
}
|
||||
@ -173,8 +215,10 @@ jpeg_make_d_derived_tbl (j_decompress_ptr cinfo, JHUFF_TBL * htbl,
|
||||
p = 0;
|
||||
for (l = 1; l <= 16; l++) {
|
||||
if (htbl->bits[l]) {
|
||||
dtbl->valptr[l] = p; /* huffval[] index of 1st symbol of code length l */
|
||||
dtbl->mincode[l] = huffcode[p]; /* minimum code of length l */
|
||||
/* valoffset[l] = huffval[] index of 1st symbol of code length l,
|
||||
* minus the minimum code of length l
|
||||
*/
|
||||
dtbl->valoffset[l] = (INT32) p - (INT32) huffcode[p];
|
||||
p += htbl->bits[l];
|
||||
dtbl->maxcode[l] = huffcode[p-1]; /* maximum code of length l */
|
||||
} else {
|
||||
@ -205,6 +249,20 @@ jpeg_make_d_derived_tbl (j_decompress_ptr cinfo, JHUFF_TBL * htbl,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Validate symbols as being reasonable.
|
||||
* For AC tables, we make no check, but accept all byte values 0..255.
|
||||
* For DC tables, we require the symbols to be in range 0..15.
|
||||
* (Tighter bounds could be applied depending on the data depth and mode,
|
||||
* but this is sufficient to ensure safe decoding.)
|
||||
*/
|
||||
if (isDC) {
|
||||
for (i = 0; i < numsymbols; i++) {
|
||||
int sym = htbl->huffval[i];
|
||||
if (sym < 0 || sym > 15)
|
||||
ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -230,7 +288,7 @@ jpeg_make_d_derived_tbl (j_decompress_ptr cinfo, JHUFF_TBL * htbl,
|
||||
#endif
|
||||
|
||||
|
||||
GLOBAL boolean
|
||||
GLOBAL(boolean)
|
||||
jpeg_fill_bit_buffer (bitread_working_state * state,
|
||||
register bit_buf_type get_buffer, register int bits_left,
|
||||
int nbits)
|
||||
@ -239,68 +297,86 @@ jpeg_fill_bit_buffer (bitread_working_state * state,
|
||||
/* Copy heavily used state fields into locals (hopefully registers) */
|
||||
register const JOCTET * next_input_byte = state->next_input_byte;
|
||||
register size_t bytes_in_buffer = state->bytes_in_buffer;
|
||||
register int c;
|
||||
j_decompress_ptr cinfo = state->cinfo;
|
||||
|
||||
/* Attempt to load at least MIN_GET_BITS bits into get_buffer. */
|
||||
/* (It is assumed that no request will be for more than that many bits.) */
|
||||
/* We fail to do so only if we hit a marker or are forced to suspend. */
|
||||
|
||||
while (bits_left < MIN_GET_BITS) {
|
||||
/* Attempt to read a byte */
|
||||
if (state->unread_marker != 0)
|
||||
goto no_more_data; /* can't advance past a marker */
|
||||
if (cinfo->unread_marker == 0) { /* cannot advance past a marker */
|
||||
while (bits_left < MIN_GET_BITS) {
|
||||
register int c;
|
||||
|
||||
if (bytes_in_buffer == 0) {
|
||||
if (! (*state->cinfo->src->fill_input_buffer) (state->cinfo))
|
||||
return FALSE;
|
||||
next_input_byte = state->cinfo->src->next_input_byte;
|
||||
bytes_in_buffer = state->cinfo->src->bytes_in_buffer;
|
||||
}
|
||||
bytes_in_buffer--;
|
||||
c = GETJOCTET(*next_input_byte++);
|
||||
|
||||
/* If it's 0xFF, check and discard stuffed zero byte */
|
||||
if (c == 0xFF) {
|
||||
do {
|
||||
if (bytes_in_buffer == 0) {
|
||||
if (! (*state->cinfo->src->fill_input_buffer) (state->cinfo))
|
||||
return FALSE;
|
||||
next_input_byte = state->cinfo->src->next_input_byte;
|
||||
bytes_in_buffer = state->cinfo->src->bytes_in_buffer;
|
||||
}
|
||||
bytes_in_buffer--;
|
||||
c = GETJOCTET(*next_input_byte++);
|
||||
} while (c == 0xFF);
|
||||
|
||||
if (c == 0) {
|
||||
/* Found FF/00, which represents an FF data byte */
|
||||
c = 0xFF;
|
||||
} else {
|
||||
/* Oops, it's actually a marker indicating end of compressed data. */
|
||||
/* Better put it back for use later */
|
||||
state->unread_marker = c;
|
||||
|
||||
no_more_data:
|
||||
/* There should be enough bits still left in the data segment; */
|
||||
/* if so, just break out of the outer while loop. */
|
||||
if (bits_left >= nbits)
|
||||
break;
|
||||
/* Uh-oh. Report corrupted data to user and stuff zeroes into
|
||||
* the data stream, so that we can produce some kind of image.
|
||||
* Note that this code will be repeated for each byte demanded
|
||||
* for the rest of the segment. We use a nonvolatile flag to ensure
|
||||
* that only one warning message appears.
|
||||
*/
|
||||
if (! *(state->printed_eod_ptr)) {
|
||||
WARNMS(state->cinfo, JWRN_HIT_MARKER);
|
||||
*(state->printed_eod_ptr) = TRUE;
|
||||
}
|
||||
c = 0; /* insert a zero byte into bit buffer */
|
||||
/* Attempt to read a byte */
|
||||
if (bytes_in_buffer == 0) {
|
||||
if (! (*cinfo->src->fill_input_buffer) (cinfo))
|
||||
return FALSE;
|
||||
next_input_byte = cinfo->src->next_input_byte;
|
||||
bytes_in_buffer = cinfo->src->bytes_in_buffer;
|
||||
}
|
||||
}
|
||||
bytes_in_buffer--;
|
||||
c = GETJOCTET(*next_input_byte++);
|
||||
|
||||
/* OK, load c into get_buffer */
|
||||
get_buffer = (get_buffer << 8) | c;
|
||||
bits_left += 8;
|
||||
/* If it's 0xFF, check and discard stuffed zero byte */
|
||||
if (c == 0xFF) {
|
||||
/* Loop here to discard any padding FF's on terminating marker,
|
||||
* so that we can save a valid unread_marker value. NOTE: we will
|
||||
* accept multiple FF's followed by a 0 as meaning a single FF data
|
||||
* byte. This data pattern is not valid according to the standard.
|
||||
*/
|
||||
do {
|
||||
if (bytes_in_buffer == 0) {
|
||||
if (! (*cinfo->src->fill_input_buffer) (cinfo))
|
||||
return FALSE;
|
||||
next_input_byte = cinfo->src->next_input_byte;
|
||||
bytes_in_buffer = cinfo->src->bytes_in_buffer;
|
||||
}
|
||||
bytes_in_buffer--;
|
||||
c = GETJOCTET(*next_input_byte++);
|
||||
} while (c == 0xFF);
|
||||
|
||||
if (c == 0) {
|
||||
/* Found FF/00, which represents an FF data byte */
|
||||
c = 0xFF;
|
||||
} else {
|
||||
/* Oops, it's actually a marker indicating end of compressed data.
|
||||
* Save the marker code for later use.
|
||||
* Fine point: it might appear that we should save the marker into
|
||||
* bitread working state, not straight into permanent state. But
|
||||
* once we have hit a marker, we cannot need to suspend within the
|
||||
* current MCU, because we will read no more bytes from the data
|
||||
* source. So it is OK to update permanent state right away.
|
||||
*/
|
||||
cinfo->unread_marker = c;
|
||||
/* See if we need to insert some fake zero bits. */
|
||||
goto no_more_bytes;
|
||||
}
|
||||
}
|
||||
|
||||
/* OK, load c into get_buffer */
|
||||
get_buffer = (get_buffer << 8) | c;
|
||||
bits_left += 8;
|
||||
} /* end while */
|
||||
} else {
|
||||
no_more_bytes:
|
||||
/* We get here if we've read the marker that terminates the compressed
|
||||
* data segment. There should be enough bits in the buffer register
|
||||
* to satisfy the request; if so, no problem.
|
||||
*/
|
||||
if (nbits > bits_left) {
|
||||
/* Uh-oh. Report corrupted data to user and stuff zeroes into
|
||||
* the data stream, so that we can produce some kind of image.
|
||||
* We use a nonvolatile flag to ensure that only one warning message
|
||||
* appears per data segment.
|
||||
*/
|
||||
if (! cinfo->entropy->insufficient_data) {
|
||||
WARNMS(cinfo, JWRN_HIT_MARKER);
|
||||
cinfo->entropy->insufficient_data = TRUE;
|
||||
}
|
||||
/* Fill the buffer with zero bits */
|
||||
get_buffer <<= MIN_GET_BITS - bits_left;
|
||||
bits_left = MIN_GET_BITS;
|
||||
}
|
||||
}
|
||||
|
||||
/* Unload the local registers */
|
||||
@ -318,7 +394,7 @@ jpeg_fill_bit_buffer (bitread_working_state * state,
|
||||
* See jdhuff.h for info about usage.
|
||||
*/
|
||||
|
||||
GLOBAL int
|
||||
GLOBAL(int)
|
||||
jpeg_huff_decode (bitread_working_state * state,
|
||||
register bit_buf_type get_buffer, register int bits_left,
|
||||
d_derived_tbl * htbl, int min_bits)
|
||||
@ -353,8 +429,7 @@ jpeg_huff_decode (bitread_working_state * state,
|
||||
return 0; /* fake a zero as the safest result */
|
||||
}
|
||||
|
||||
return htbl->pub->huffval[ htbl->valptr[l] +
|
||||
((int) (code - htbl->mincode[l])) ];
|
||||
return htbl->pub->huffval[ (int) (code + htbl->valoffset[l]) ];
|
||||
}
|
||||
|
||||
|
||||
@ -389,7 +464,7 @@ static const int extend_offset[16] = /* entry n is (-1 << n) + 1 */
|
||||
* Returns FALSE if must suspend.
|
||||
*/
|
||||
|
||||
LOCAL boolean
|
||||
LOCAL(boolean)
|
||||
process_restart (j_decompress_ptr cinfo)
|
||||
{
|
||||
huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
|
||||
@ -411,8 +486,13 @@ process_restart (j_decompress_ptr cinfo)
|
||||
/* Reset restart counter */
|
||||
entropy->restarts_to_go = cinfo->restart_interval;
|
||||
|
||||
/* Next segment can get another out-of-data warning */
|
||||
entropy->bitstate.printed_eod = FALSE;
|
||||
/* 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;
|
||||
}
|
||||
@ -433,18 +513,13 @@ process_restart (j_decompress_ptr cinfo)
|
||||
* this module, since we'll just re-assign them on the next call.)
|
||||
*/
|
||||
|
||||
METHODDEF boolean
|
||||
METHODDEF(boolean)
|
||||
decode_mcu (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
|
||||
{
|
||||
huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
|
||||
register int s, k, r;
|
||||
int blkn, ci;
|
||||
JBLOCKROW block;
|
||||
int blkn;
|
||||
BITREAD_STATE_VARS;
|
||||
savable_state state;
|
||||
d_derived_tbl * dctbl;
|
||||
d_derived_tbl * actbl;
|
||||
jpeg_component_info * compptr;
|
||||
|
||||
/* Process restart marker if needed; may have to suspend */
|
||||
if (cinfo->restart_interval) {
|
||||
@ -453,96 +528,98 @@ decode_mcu (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* Load up working state */
|
||||
BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
|
||||
ASSIGN_STATE(state, entropy->saved);
|
||||
/* 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) {
|
||||
|
||||
/* Outer loop handles each block in the MCU */
|
||||
/* Load up working state */
|
||||
BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
|
||||
ASSIGN_STATE(state, entropy->saved);
|
||||
|
||||
for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
|
||||
block = MCU_data[blkn];
|
||||
ci = cinfo->MCU_membership[blkn];
|
||||
compptr = cinfo->cur_comp_info[ci];
|
||||
dctbl = entropy->dc_derived_tbls[compptr->dc_tbl_no];
|
||||
actbl = entropy->ac_derived_tbls[compptr->ac_tbl_no];
|
||||
/* Outer loop handles each block in the MCU */
|
||||
|
||||
/* Decode a single block's worth of coefficients */
|
||||
for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
|
||||
JBLOCKROW block = MCU_data[blkn];
|
||||
d_derived_tbl * dctbl = entropy->dc_cur_tbls[blkn];
|
||||
d_derived_tbl * actbl = entropy->ac_cur_tbls[blkn];
|
||||
register int s, k, r;
|
||||
|
||||
/* Section F.2.2.1: decode the DC coefficient difference */
|
||||
HUFF_DECODE(s, br_state, dctbl, return FALSE, label1);
|
||||
if (s) {
|
||||
CHECK_BIT_BUFFER(br_state, s, return FALSE);
|
||||
r = GET_BITS(s);
|
||||
s = HUFF_EXTEND(r, s);
|
||||
}
|
||||
/* Decode a single block's worth of coefficients */
|
||||
|
||||
/* Shortcut if component's values are not interesting */
|
||||
if (! compptr->component_needed)
|
||||
goto skip_ACs;
|
||||
|
||||
/* Convert DC difference to actual value, update last_dc_val */
|
||||
s += state.last_dc_val[ci];
|
||||
state.last_dc_val[ci] = s;
|
||||
/* Output the DC coefficient (assumes jpeg_natural_order[0] = 0) */
|
||||
(*block)[0] = (JCOEF) s;
|
||||
|
||||
/* Do we need to decode the AC coefficients for this component? */
|
||||
if (compptr->DCT_scaled_size > 1) {
|
||||
|
||||
/* Section F.2.2.2: decode the AC coefficients */
|
||||
/* Since zeroes are skipped, output area must be cleared beforehand */
|
||||
for (k = 1; k < DCTSIZE2; k++) {
|
||||
HUFF_DECODE(s, br_state, actbl, 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);
|
||||
/* Output coefficient in natural (dezigzagged) order.
|
||||
* Note: the extra entries in jpeg_natural_order[] will save us
|
||||
* if k >= DCTSIZE2, which could happen if the data is corrupted.
|
||||
*/
|
||||
(*block)[jpeg_natural_order[k]] = (JCOEF) s;
|
||||
} else {
|
||||
if (r != 15)
|
||||
break;
|
||||
k += 15;
|
||||
}
|
||||
/* Section F.2.2.1: decode the DC coefficient difference */
|
||||
HUFF_DECODE(s, br_state, dctbl, return FALSE, label1);
|
||||
if (s) {
|
||||
CHECK_BIT_BUFFER(br_state, s, return FALSE);
|
||||
r = GET_BITS(s);
|
||||
s = HUFF_EXTEND(r, s);
|
||||
}
|
||||
|
||||
} else {
|
||||
skip_ACs:
|
||||
|
||||
/* Section F.2.2.2: decode the AC coefficients */
|
||||
/* In this path we just discard the values */
|
||||
for (k = 1; k < DCTSIZE2; k++) {
|
||||
HUFF_DECODE(s, br_state, actbl, return FALSE, label3);
|
||||
|
||||
r = s >> 4;
|
||||
s &= 15;
|
||||
|
||||
if (s) {
|
||||
k += r;
|
||||
CHECK_BIT_BUFFER(br_state, s, return FALSE);
|
||||
DROP_BITS(s);
|
||||
} else {
|
||||
if (r != 15)
|
||||
break;
|
||||
k += 15;
|
||||
}
|
||||
if (entropy->dc_needed[blkn]) {
|
||||
/* Convert DC difference to actual value, update last_dc_val */
|
||||
int ci = cinfo->MCU_membership[blkn];
|
||||
s += state.last_dc_val[ci];
|
||||
state.last_dc_val[ci] = s;
|
||||
/* Output the DC coefficient (assumes jpeg_natural_order[0] = 0) */
|
||||
(*block)[0] = (JCOEF) s;
|
||||
}
|
||||
|
||||
if (entropy->ac_needed[blkn]) {
|
||||
|
||||
/* Section F.2.2.2: decode the AC coefficients */
|
||||
/* Since zeroes are skipped, output area must be cleared beforehand */
|
||||
for (k = 1; k < DCTSIZE2; k++) {
|
||||
HUFF_DECODE(s, br_state, actbl, 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);
|
||||
/* Output coefficient in natural (dezigzagged) order.
|
||||
* Note: the extra entries in jpeg_natural_order[] will save us
|
||||
* if k >= DCTSIZE2, which could happen if the data is corrupted.
|
||||
*/
|
||||
(*block)[jpeg_natural_order[k]] = (JCOEF) s;
|
||||
} else {
|
||||
if (r != 15)
|
||||
break;
|
||||
k += 15;
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
/* Section F.2.2.2: decode the AC coefficients */
|
||||
/* In this path we just discard the values */
|
||||
for (k = 1; k < DCTSIZE2; k++) {
|
||||
HUFF_DECODE(s, br_state, actbl, return FALSE, label3);
|
||||
|
||||
r = s >> 4;
|
||||
s &= 15;
|
||||
|
||||
if (s) {
|
||||
k += r;
|
||||
CHECK_BIT_BUFFER(br_state, s, return FALSE);
|
||||
DROP_BITS(s);
|
||||
} else {
|
||||
if (r != 15)
|
||||
break;
|
||||
k += 15;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/* Completed MCU, so update state */
|
||||
BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
|
||||
ASSIGN_STATE(entropy->saved, state);
|
||||
}
|
||||
|
||||
/* 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--;
|
||||
|
||||
@ -554,7 +631,7 @@ skip_ACs:
|
||||
* Module initialization routine for Huffman entropy decoding.
|
||||
*/
|
||||
|
||||
GLOBAL void
|
||||
GLOBAL(void)
|
||||
jinit_huff_decoder (j_decompress_ptr cinfo)
|
||||
{
|
||||
huff_entropy_ptr entropy;
|
||||
@ -571,9 +648,4 @@ jinit_huff_decoder (j_decompress_ptr cinfo)
|
||||
for (i = 0; i < NUM_HUFF_TBLS; i++) {
|
||||
entropy->dc_derived_tbls[i] = entropy->ac_derived_tbls[i] = NULL;
|
||||
}
|
||||
|
||||
/* Initialize DC predictions to 0 */
|
||||
for (i = 0; i < MAX_COMPS_IN_SCAN; i++) {
|
||||
entropy->saved.last_dc_val[i] = 0;
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* jdhuff.h
|
||||
*
|
||||
* Copyright (C) 1991-1995, Thomas G. Lane.
|
||||
* 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.
|
||||
*
|
||||
@ -25,10 +25,13 @@
|
||||
|
||||
typedef struct {
|
||||
/* Basic tables: (element [0] of each array is unused) */
|
||||
INT32 mincode[17]; /* smallest code of length k */
|
||||
INT32 maxcode[18]; /* largest code of length k (-1 if none) */
|
||||
/* (maxcode[17] is a sentinel to ensure jpeg_huff_decode terminates) */
|
||||
int valptr[17]; /* huffval[] index of 1st symbol of length k */
|
||||
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;
|
||||
@ -43,8 +46,9 @@ typedef struct {
|
||||
} d_derived_tbl;
|
||||
|
||||
/* Expand a Huffman table definition into the derived format */
|
||||
EXTERN void jpeg_make_d_derived_tbl JPP((j_decompress_ptr cinfo,
|
||||
JHUFF_TBL * htbl, d_derived_tbl ** pdtbl));
|
||||
EXTERN(void) jpeg_make_d_derived_tbl
|
||||
JPP((j_decompress_ptr cinfo, boolean isDC, int tblno,
|
||||
d_derived_tbl ** pdtbl));
|
||||
|
||||
|
||||
/*
|
||||
@ -70,30 +74,28 @@ typedef INT32 bit_buf_type; /* type of bit-extraction buffer */
|
||||
|
||||
/* 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 do this with
|
||||
* something like #define BIT_BUF_SIZE (sizeof(bit_buf_type)*8)
|
||||
* 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 */
|
||||
boolean printed_eod; /* flag to suppress multiple warning msgs */
|
||||
} bitread_perm_state;
|
||||
|
||||
typedef struct { /* Bitreading working state within an MCU */
|
||||
/* current data source state */
|
||||
/* 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 */
|
||||
int unread_marker; /* nonzero if we have hit a marker */
|
||||
/* bit input buffer --- note these values are kept in register variables,
|
||||
/* 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 */
|
||||
/* pointers needed by jpeg_fill_bit_buffer */
|
||||
/* Pointer needed by jpeg_fill_bit_buffer. */
|
||||
j_decompress_ptr cinfo; /* back link to decompress master record */
|
||||
boolean * printed_eod_ptr; /* => flag in permanent state */
|
||||
} bitread_working_state;
|
||||
|
||||
/* Macros to declare and load/save bitread local variables. */
|
||||
@ -106,15 +108,12 @@ typedef struct { /* Bitreading working state within an MCU */
|
||||
br_state.cinfo = cinfop; \
|
||||
br_state.next_input_byte = cinfop->src->next_input_byte; \
|
||||
br_state.bytes_in_buffer = cinfop->src->bytes_in_buffer; \
|
||||
br_state.unread_marker = cinfop->unread_marker; \
|
||||
get_buffer = permstate.get_buffer; \
|
||||
bits_left = permstate.bits_left; \
|
||||
br_state.printed_eod_ptr = & permstate.printed_eod
|
||||
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; \
|
||||
cinfop->unread_marker = br_state.unread_marker; \
|
||||
permstate.get_buffer = get_buffer; \
|
||||
permstate.bits_left = bits_left
|
||||
|
||||
@ -152,9 +151,9 @@ typedef struct { /* Bitreading working state within an MCU */
|
||||
(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));
|
||||
EXTERN(boolean) jpeg_fill_bit_buffer
|
||||
JPP((bitread_working_state * state, register bit_buf_type get_buffer,
|
||||
register int bits_left, int nbits));
|
||||
|
||||
|
||||
/*
|
||||
@ -197,6 +196,6 @@ slowlabel: \
|
||||
}
|
||||
|
||||
/* 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));
|
||||
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));
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* jdinput.c
|
||||
*
|
||||
* Copyright (C) 1991-1995, Thomas G. Lane.
|
||||
* 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.
|
||||
*
|
||||
@ -28,14 +28,14 @@ typedef my_input_controller * my_inputctl_ptr;
|
||||
|
||||
|
||||
/* Forward declarations */
|
||||
METHODDEF int consume_markers JPP((j_decompress_ptr cinfo));
|
||||
METHODDEF(int) consume_markers JPP((j_decompress_ptr cinfo));
|
||||
|
||||
|
||||
/*
|
||||
* Routines to calculate various quantities related to the size of the image.
|
||||
*/
|
||||
|
||||
LOCAL void
|
||||
LOCAL(void)
|
||||
initial_setup (j_decompress_ptr cinfo)
|
||||
/* Called once, when first SOS marker is reached */
|
||||
{
|
||||
@ -117,7 +117,7 @@ initial_setup (j_decompress_ptr cinfo)
|
||||
}
|
||||
|
||||
|
||||
LOCAL void
|
||||
LOCAL(void)
|
||||
per_scan_setup (j_decompress_ptr cinfo)
|
||||
/* Do computations that are needed before processing a JPEG scan */
|
||||
/* cinfo->comps_in_scan and cinfo->cur_comp_info[] were set from SOS marker */
|
||||
@ -216,7 +216,7 @@ per_scan_setup (j_decompress_ptr cinfo)
|
||||
* not at the current Q-table slots.
|
||||
*/
|
||||
|
||||
LOCAL void
|
||||
LOCAL(void)
|
||||
latch_quant_tables (j_decompress_ptr cinfo)
|
||||
{
|
||||
int ci, qtblno;
|
||||
@ -250,7 +250,7 @@ latch_quant_tables (j_decompress_ptr cinfo)
|
||||
* Subsequent calls come from consume_markers, below.
|
||||
*/
|
||||
|
||||
METHODDEF void
|
||||
METHODDEF(void)
|
||||
start_input_pass (j_decompress_ptr cinfo)
|
||||
{
|
||||
per_scan_setup(cinfo);
|
||||
@ -267,7 +267,7 @@ start_input_pass (j_decompress_ptr cinfo)
|
||||
* the expected data of the scan.
|
||||
*/
|
||||
|
||||
METHODDEF void
|
||||
METHODDEF(void)
|
||||
finish_input_pass (j_decompress_ptr cinfo)
|
||||
{
|
||||
cinfo->inputctl->consume_input = consume_markers;
|
||||
@ -284,7 +284,7 @@ finish_input_pass (j_decompress_ptr cinfo)
|
||||
* we are reading a compressed data segment or inter-segment markers.
|
||||
*/
|
||||
|
||||
METHODDEF int
|
||||
METHODDEF(int)
|
||||
consume_markers (j_decompress_ptr cinfo)
|
||||
{
|
||||
my_inputctl_ptr inputctl = (my_inputctl_ptr) cinfo->inputctl;
|
||||
@ -301,7 +301,7 @@ consume_markers (j_decompress_ptr cinfo)
|
||||
initial_setup(cinfo);
|
||||
inputctl->inheaders = FALSE;
|
||||
/* Note: start_input_pass must be called by jdmaster.c
|
||||
* before any more input can be consumed. jdapi.c is
|
||||
* before any more input can be consumed. jdapimin.c is
|
||||
* responsible for enforcing this sequencing.
|
||||
*/
|
||||
} else { /* 2nd or later SOS marker */
|
||||
@ -335,7 +335,7 @@ consume_markers (j_decompress_ptr cinfo)
|
||||
* Reset state to begin a fresh datastream.
|
||||
*/
|
||||
|
||||
METHODDEF void
|
||||
METHODDEF(void)
|
||||
reset_input_controller (j_decompress_ptr cinfo)
|
||||
{
|
||||
my_inputctl_ptr inputctl = (my_inputctl_ptr) cinfo->inputctl;
|
||||
@ -357,7 +357,7 @@ reset_input_controller (j_decompress_ptr cinfo)
|
||||
* This is called only once, when the decompression object is created.
|
||||
*/
|
||||
|
||||
GLOBAL void
|
||||
GLOBAL(void)
|
||||
jinit_input_controller (j_decompress_ptr cinfo)
|
||||
{
|
||||
my_inputctl_ptr inputctl;
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* jdmainct.c
|
||||
*
|
||||
* Copyright (C) 1994-1995, Thomas G. Lane.
|
||||
* Copyright (C) 1994-1996, Thomas G. Lane.
|
||||
* This file is part of the Independent JPEG Group's software.
|
||||
* For conditions of distribution and use, see the accompanying README file.
|
||||
*
|
||||
@ -140,20 +140,20 @@ typedef my_main_controller * my_main_ptr;
|
||||
|
||||
|
||||
/* Forward declarations */
|
||||
METHODDEF void process_data_simple_main
|
||||
METHODDEF(void) process_data_simple_main
|
||||
JPP((j_decompress_ptr cinfo, JSAMPARRAY output_buf,
|
||||
JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail));
|
||||
METHODDEF void process_data_context_main
|
||||
METHODDEF(void) process_data_context_main
|
||||
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
|
||||
METHODDEF(void) process_data_crank_post
|
||||
JPP((j_decompress_ptr cinfo, JSAMPARRAY output_buf,
|
||||
JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail));
|
||||
#endif
|
||||
|
||||
|
||||
LOCAL void
|
||||
LOCAL(void)
|
||||
alloc_funny_pointers (j_decompress_ptr cinfo)
|
||||
/* Allocate space for the funny pointer lists.
|
||||
* This is done only once, not once per pass.
|
||||
@ -191,7 +191,7 @@ alloc_funny_pointers (j_decompress_ptr cinfo)
|
||||
}
|
||||
|
||||
|
||||
LOCAL void
|
||||
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->buffer),
|
||||
@ -234,7 +234,7 @@ make_funny_pointers (j_decompress_ptr cinfo)
|
||||
}
|
||||
|
||||
|
||||
LOCAL void
|
||||
LOCAL(void)
|
||||
set_wraparound_pointers (j_decompress_ptr cinfo)
|
||||
/* Set up the "wraparound" pointers at top and bottom of the pointer lists.
|
||||
* This changes the pointer list state from top-of-image to the normal state.
|
||||
@ -262,7 +262,7 @@ set_wraparound_pointers (j_decompress_ptr cinfo)
|
||||
}
|
||||
|
||||
|
||||
LOCAL void
|
||||
LOCAL(void)
|
||||
set_bottom_pointers (j_decompress_ptr cinfo)
|
||||
/* Change the pointer lists to duplicate the last sample row at the bottom
|
||||
* of the image. whichptr indicates which xbuffer holds the final iMCU row.
|
||||
@ -303,7 +303,7 @@ set_bottom_pointers (j_decompress_ptr cinfo)
|
||||
* Initialize for a processing pass.
|
||||
*/
|
||||
|
||||
METHODDEF void
|
||||
METHODDEF(void)
|
||||
start_pass_main (j_decompress_ptr cinfo, J_BUF_MODE pass_mode)
|
||||
{
|
||||
my_main_ptr main = (my_main_ptr) cinfo->main;
|
||||
@ -341,7 +341,7 @@ start_pass_main (j_decompress_ptr cinfo, J_BUF_MODE pass_mode)
|
||||
* This handles the simple case where no context is required.
|
||||
*/
|
||||
|
||||
METHODDEF void
|
||||
METHODDEF(void)
|
||||
process_data_simple_main (j_decompress_ptr cinfo,
|
||||
JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
|
||||
JDIMENSION out_rows_avail)
|
||||
@ -381,7 +381,7 @@ process_data_simple_main (j_decompress_ptr cinfo,
|
||||
* This handles the case where context rows must be provided.
|
||||
*/
|
||||
|
||||
METHODDEF void
|
||||
METHODDEF(void)
|
||||
process_data_context_main (j_decompress_ptr cinfo,
|
||||
JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
|
||||
JDIMENSION out_rows_avail)
|
||||
@ -455,7 +455,7 @@ process_data_context_main (j_decompress_ptr cinfo,
|
||||
|
||||
#ifdef QUANT_2PASS_SUPPORTED
|
||||
|
||||
METHODDEF void
|
||||
METHODDEF(void)
|
||||
process_data_crank_post (j_decompress_ptr cinfo,
|
||||
JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
|
||||
JDIMENSION out_rows_avail)
|
||||
@ -472,7 +472,7 @@ process_data_crank_post (j_decompress_ptr cinfo,
|
||||
* Initialize main buffer controller.
|
||||
*/
|
||||
|
||||
GLOBAL void
|
||||
GLOBAL(void)
|
||||
jinit_d_main_controller (j_decompress_ptr cinfo, boolean need_full_buffer)
|
||||
{
|
||||
my_main_ptr main;
|
||||
|
636
jpeg/jdmarker.c
636
jpeg/jdmarker.c
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* jdmarker.c
|
||||
*
|
||||
* Copyright (C) 1991-1995, Thomas G. Lane.
|
||||
* Copyright (C) 1991-1998, Thomas G. Lane.
|
||||
* This file is part of the Independent JPEG Group's software.
|
||||
* For conditions of distribution and use, see the accompanying README file.
|
||||
*
|
||||
@ -14,6 +14,8 @@
|
||||
|
||||
#define JPEG_INTERNALS
|
||||
#include "jinclude.h"
|
||||
#include "jpeglib.h"
|
||||
|
||||
|
||||
typedef enum { /* JPEG marker codes */
|
||||
M_SOF0 = 0xc0,
|
||||
@ -77,15 +79,31 @@ typedef enum { /* JPEG marker codes */
|
||||
M_JPG13 = 0xfd,
|
||||
M_COM = 0xfe,
|
||||
|
||||
M_TEM = 0x01,
|
||||
|
||||
M_ERROR = 0x100
|
||||
M_TEM = 0x01
|
||||
} JPEG_MARKER;
|
||||
|
||||
#include "jpeglib.h" /* Move this after JPEG_MARKER to avoid name
|
||||
* clash with Sun header, /usr/include/sys/stream.h,
|
||||
* which defines M_ERROR.
|
||||
*/
|
||||
|
||||
/* Private state */
|
||||
|
||||
typedef struct {
|
||||
struct jpeg_marker_reader pub; /* public fields */
|
||||
|
||||
/* Application-overridable marker processing methods */
|
||||
jpeg_marker_parser_method process_COM;
|
||||
jpeg_marker_parser_method process_APPn[16];
|
||||
|
||||
/* Limit on marker data length to save for each marker type */
|
||||
unsigned int length_limit_COM;
|
||||
unsigned int length_limit_APPn[16];
|
||||
|
||||
/* Status of COM/APPn marker saving */
|
||||
jpeg_saved_marker_ptr cur_marker; /* NULL if not processing a marker */
|
||||
unsigned int bytes_read; /* data bytes read so far in marker */
|
||||
/* Note: cur_marker is not linked into marker_list until it's all read. */
|
||||
} my_marker_reader;
|
||||
|
||||
typedef my_marker_reader * my_marker_ptr;
|
||||
|
||||
|
||||
/*
|
||||
* Macros for fetching data from the data source module.
|
||||
@ -106,7 +124,7 @@ typedef enum { /* JPEG marker codes */
|
||||
( datasrc->next_input_byte = next_input_byte, \
|
||||
datasrc->bytes_in_buffer = bytes_in_buffer )
|
||||
|
||||
/* Reload the local copies --- seldom used except in MAKE_BYTE_AVAIL */
|
||||
/* 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 )
|
||||
@ -120,14 +138,14 @@ typedef enum { /* JPEG marker codes */
|
||||
if (! (*datasrc->fill_input_buffer) (cinfo)) \
|
||||
{ action; } \
|
||||
INPUT_RELOAD(cinfo); \
|
||||
} \
|
||||
bytes_in_buffer--
|
||||
}
|
||||
|
||||
/* 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++); )
|
||||
|
||||
/* As above, but read two bytes interpreted as an unsigned 16-bit integer.
|
||||
@ -135,8 +153,10 @@ typedef enum { /* JPEG marker codes */
|
||||
*/
|
||||
#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++); )
|
||||
|
||||
|
||||
@ -152,11 +172,18 @@ typedef enum { /* JPEG marker codes */
|
||||
* marker parameters; restart point has not been moved. Same routine
|
||||
* will be called again after application supplies more input data.
|
||||
*
|
||||
* This approach to suspension assumes that all of a marker's parameters can
|
||||
* fit into a single input bufferload. This should hold for "normal"
|
||||
* markers. Some COM/APPn markers might have large parameter segments,
|
||||
* but we use skip_input_data to get past those, and thereby put the problem
|
||||
* on the source manager's shoulders.
|
||||
* This approach to suspension assumes that all of a marker's parameters
|
||||
* can fit into a single input bufferload. This should hold for "normal"
|
||||
* markers. Some COM/APPn markers might have large parameter segments
|
||||
* that might not fit. If we are simply dropping such a marker, we use
|
||||
* skip_input_data to get past it, and thereby put the problem on the
|
||||
* source manager's shoulders. If we are saving the marker's contents
|
||||
* into memory, we use a slightly different convention: when forced to
|
||||
* suspend, the marker processor updates the restart point to the end of
|
||||
* what it's consumed (ie, the end of the buffer) before returning FALSE.
|
||||
* On resumption, cinfo->unread_marker still contains the marker code,
|
||||
* but the data source will point to the next chunk of marker data.
|
||||
* The marker processor must retain internal state to deal with this.
|
||||
*
|
||||
* Note that we don't bother to avoid duplicate trace messages if a
|
||||
* suspension occurs within marker parameters. Other side effects
|
||||
@ -164,7 +191,7 @@ typedef enum { /* JPEG marker codes */
|
||||
*/
|
||||
|
||||
|
||||
LOCAL boolean
|
||||
LOCAL(boolean)
|
||||
get_soi (j_decompress_ptr cinfo)
|
||||
/* Process an SOI marker */
|
||||
{
|
||||
@ -190,7 +217,9 @@ get_soi (j_decompress_ptr cinfo)
|
||||
cinfo->CCIR601_sampling = FALSE; /* Assume non-CCIR sampling??? */
|
||||
|
||||
cinfo->saw_JFIF_marker = FALSE;
|
||||
cinfo->density_unit = 0; /* set default JFIF APP0 values */
|
||||
cinfo->JFIF_major_version = 1; /* set default JFIF APP0 values */
|
||||
cinfo->JFIF_minor_version = 1;
|
||||
cinfo->density_unit = 0;
|
||||
cinfo->X_density = 1;
|
||||
cinfo->Y_density = 1;
|
||||
cinfo->saw_Adobe_marker = FALSE;
|
||||
@ -202,7 +231,7 @@ get_soi (j_decompress_ptr cinfo)
|
||||
}
|
||||
|
||||
|
||||
LOCAL boolean
|
||||
LOCAL(boolean)
|
||||
get_sof (j_decompress_ptr cinfo, boolean is_prog, boolean is_arith)
|
||||
/* Process a SOFn marker */
|
||||
{
|
||||
@ -266,7 +295,7 @@ get_sof (j_decompress_ptr cinfo, boolean is_prog, boolean is_arith)
|
||||
}
|
||||
|
||||
|
||||
LOCAL boolean
|
||||
LOCAL(boolean)
|
||||
get_sos (j_decompress_ptr cinfo)
|
||||
/* Process a SOS marker */
|
||||
{
|
||||
@ -282,11 +311,11 @@ get_sos (j_decompress_ptr cinfo)
|
||||
|
||||
INPUT_BYTE(cinfo, n, return FALSE); /* Number of components */
|
||||
|
||||
TRACEMS1(cinfo, 1, JTRC_SOS, n);
|
||||
|
||||
if (length != (n * 2 + 6) || n < 1 || n > MAX_COMPS_IN_SCAN)
|
||||
ERREXIT(cinfo, JERR_BAD_LENGTH);
|
||||
|
||||
TRACEMS1(cinfo, 1, JTRC_SOS, n);
|
||||
|
||||
cinfo->comps_in_scan = n;
|
||||
|
||||
/* Collect the component-spec parameters */
|
||||
@ -336,113 +365,9 @@ get_sos (j_decompress_ptr cinfo)
|
||||
}
|
||||
|
||||
|
||||
METHODDEF boolean
|
||||
get_app0 (j_decompress_ptr cinfo)
|
||||
/* Process an APP0 marker */
|
||||
{
|
||||
#define JFIF_LEN 14
|
||||
INT32 length;
|
||||
UINT8 b[JFIF_LEN];
|
||||
int buffp;
|
||||
INPUT_VARS(cinfo);
|
||||
#ifdef D_ARITH_CODING_SUPPORTED
|
||||
|
||||
INPUT_2BYTES(cinfo, length, return FALSE);
|
||||
length -= 2;
|
||||
|
||||
/* See if a JFIF APP0 marker is present */
|
||||
|
||||
if (length >= JFIF_LEN) {
|
||||
for (buffp = 0; buffp < JFIF_LEN; buffp++)
|
||||
INPUT_BYTE(cinfo, b[buffp], return FALSE);
|
||||
length -= JFIF_LEN;
|
||||
|
||||
if (b[0]==0x4A && b[1]==0x46 && b[2]==0x49 && b[3]==0x46 && b[4]==0) {
|
||||
/* Found JFIF APP0 marker: check version */
|
||||
/* Major version must be 1, anything else signals an incompatible change.
|
||||
* We used to treat this as an error, but now it's a nonfatal warning,
|
||||
* because some bozo at Hijaak couldn't read the spec.
|
||||
* Minor version should be 0..2, but process anyway if newer.
|
||||
*/
|
||||
if (b[5] != 1)
|
||||
WARNMS2(cinfo, JWRN_JFIF_MAJOR, b[5], b[6]);
|
||||
else if (b[6] > 2)
|
||||
TRACEMS2(cinfo, 1, JTRC_JFIF_MINOR, b[5], b[6]);
|
||||
/* Save info */
|
||||
cinfo->saw_JFIF_marker = TRUE;
|
||||
cinfo->density_unit = b[7];
|
||||
cinfo->X_density = (b[8] << 8) + b[9];
|
||||
cinfo->Y_density = (b[10] << 8) + b[11];
|
||||
TRACEMS3(cinfo, 1, JTRC_JFIF,
|
||||
cinfo->X_density, cinfo->Y_density, cinfo->density_unit);
|
||||
if (b[12] | b[13])
|
||||
TRACEMS2(cinfo, 1, JTRC_JFIF_THUMBNAIL, b[12], b[13]);
|
||||
if (length != ((INT32) b[12] * (INT32) b[13] * (INT32) 3))
|
||||
TRACEMS1(cinfo, 1, JTRC_JFIF_BADTHUMBNAILSIZE, (int) length);
|
||||
} else {
|
||||
/* Start of APP0 does not match "JFIF" */
|
||||
TRACEMS1(cinfo, 1, JTRC_APP0, (int) length + JFIF_LEN);
|
||||
}
|
||||
} else {
|
||||
/* Too short to be JFIF marker */
|
||||
TRACEMS1(cinfo, 1, JTRC_APP0, (int) length);
|
||||
}
|
||||
|
||||
INPUT_SYNC(cinfo);
|
||||
if (length > 0) /* skip any remaining data -- could be lots */
|
||||
(*cinfo->src->skip_input_data) (cinfo, (long) length);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
METHODDEF boolean
|
||||
get_app14 (j_decompress_ptr cinfo)
|
||||
/* Process an APP14 marker */
|
||||
{
|
||||
#define ADOBE_LEN 12
|
||||
INT32 length;
|
||||
UINT8 b[ADOBE_LEN];
|
||||
int buffp;
|
||||
unsigned int version, flags0, flags1, transform;
|
||||
INPUT_VARS(cinfo);
|
||||
|
||||
INPUT_2BYTES(cinfo, length, return FALSE);
|
||||
length -= 2;
|
||||
|
||||
/* See if an Adobe APP14 marker is present */
|
||||
|
||||
if (length >= ADOBE_LEN) {
|
||||
for (buffp = 0; buffp < ADOBE_LEN; buffp++)
|
||||
INPUT_BYTE(cinfo, b[buffp], return FALSE);
|
||||
length -= ADOBE_LEN;
|
||||
|
||||
if (b[0]==0x41 && b[1]==0x64 && b[2]==0x6F && b[3]==0x62 && b[4]==0x65) {
|
||||
/* Found Adobe APP14 marker */
|
||||
version = (b[5] << 8) + b[6];
|
||||
flags0 = (b[7] << 8) + b[8];
|
||||
flags1 = (b[9] << 8) + b[10];
|
||||
transform = b[11];
|
||||
TRACEMS4(cinfo, 1, JTRC_ADOBE, version, flags0, flags1, transform);
|
||||
cinfo->saw_Adobe_marker = TRUE;
|
||||
cinfo->Adobe_transform = (UINT8) transform;
|
||||
} else {
|
||||
/* Start of APP14 does not match "Adobe" */
|
||||
TRACEMS1(cinfo, 1, JTRC_APP14, (int) length + ADOBE_LEN);
|
||||
}
|
||||
} else {
|
||||
/* Too short to be Adobe marker */
|
||||
TRACEMS1(cinfo, 1, JTRC_APP14, (int) length);
|
||||
}
|
||||
|
||||
INPUT_SYNC(cinfo);
|
||||
if (length > 0) /* skip any remaining data -- could be lots */
|
||||
(*cinfo->src->skip_input_data) (cinfo, (long) length);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
LOCAL boolean
|
||||
LOCAL(boolean)
|
||||
get_dac (j_decompress_ptr cinfo)
|
||||
/* Process a DAC marker */
|
||||
{
|
||||
@ -474,12 +399,21 @@ get_dac (j_decompress_ptr cinfo)
|
||||
}
|
||||
}
|
||||
|
||||
if (length != 0)
|
||||
ERREXIT(cinfo, JERR_BAD_LENGTH);
|
||||
|
||||
INPUT_SYNC(cinfo);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
#else /* ! D_ARITH_CODING_SUPPORTED */
|
||||
|
||||
LOCAL boolean
|
||||
#define get_dac(cinfo) skip_variable(cinfo)
|
||||
|
||||
#endif /* D_ARITH_CODING_SUPPORTED */
|
||||
|
||||
|
||||
LOCAL(boolean)
|
||||
get_dht (j_decompress_ptr cinfo)
|
||||
/* Process a DHT marker */
|
||||
{
|
||||
@ -493,7 +427,7 @@ get_dht (j_decompress_ptr cinfo)
|
||||
INPUT_2BYTES(cinfo, length, return FALSE);
|
||||
length -= 2;
|
||||
|
||||
while (length > 0) {
|
||||
while (length > 16) {
|
||||
INPUT_BYTE(cinfo, index, return FALSE);
|
||||
|
||||
TRACEMS1(cinfo, 1, JTRC_DHT, index);
|
||||
@ -514,8 +448,11 @@ get_dht (j_decompress_ptr cinfo)
|
||||
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.
|
||||
*/
|
||||
if (count > 256 || ((INT32) count) > length)
|
||||
ERREXIT(cinfo, JERR_DHT_COUNTS);
|
||||
ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
|
||||
|
||||
for (i = 0; i < count; i++)
|
||||
INPUT_BYTE(cinfo, huffval[i], return FALSE);
|
||||
@ -539,12 +476,15 @@ get_dht (j_decompress_ptr cinfo)
|
||||
MEMCOPY((*htblptr)->huffval, huffval, SIZEOF((*htblptr)->huffval));
|
||||
}
|
||||
|
||||
if (length != 0)
|
||||
ERREXIT(cinfo, JERR_BAD_LENGTH);
|
||||
|
||||
INPUT_SYNC(cinfo);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
LOCAL boolean
|
||||
LOCAL(boolean)
|
||||
get_dqt (j_decompress_ptr cinfo)
|
||||
/* Process a DQT marker */
|
||||
{
|
||||
@ -576,27 +516,33 @@ get_dqt (j_decompress_ptr cinfo)
|
||||
INPUT_2BYTES(cinfo, tmp, return FALSE);
|
||||
else
|
||||
INPUT_BYTE(cinfo, tmp, return FALSE);
|
||||
quant_ptr->quantval[i] = (UINT16) tmp;
|
||||
/* We convert the zigzag-order table to natural array order. */
|
||||
quant_ptr->quantval[jpeg_natural_order[i]] = (UINT16) tmp;
|
||||
}
|
||||
|
||||
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]);
|
||||
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]);
|
||||
}
|
||||
}
|
||||
|
||||
length -= DCTSIZE2+1;
|
||||
if (prec) length -= DCTSIZE2;
|
||||
}
|
||||
|
||||
if (length != 0)
|
||||
ERREXIT(cinfo, JERR_BAD_LENGTH);
|
||||
|
||||
INPUT_SYNC(cinfo);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
LOCAL boolean
|
||||
LOCAL(boolean)
|
||||
get_dri (j_decompress_ptr cinfo)
|
||||
/* Process a DRI marker */
|
||||
{
|
||||
@ -620,7 +566,280 @@ get_dri (j_decompress_ptr cinfo)
|
||||
}
|
||||
|
||||
|
||||
METHODDEF boolean
|
||||
/*
|
||||
* Routines for processing APPn and COM markers.
|
||||
* These are either saved in memory or discarded, per application request.
|
||||
* APP0 and APP14 are specially checked to see if they are
|
||||
* JFIF and Adobe markers, respectively.
|
||||
*/
|
||||
|
||||
#define APP0_DATA_LEN 14 /* Length of interesting data in APP0 */
|
||||
#define APP14_DATA_LEN 12 /* Length of interesting data in APP14 */
|
||||
#define APPN_DATA_LEN 14 /* Must be the largest of the above!! */
|
||||
|
||||
|
||||
LOCAL(void)
|
||||
examine_app0 (j_decompress_ptr cinfo, JOCTET FAR * data,
|
||||
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.
|
||||
*/
|
||||
{
|
||||
INT32 totallen = (INT32) datalen + remaining;
|
||||
|
||||
if (datalen >= APP0_DATA_LEN &&
|
||||
GETJOCTET(data[0]) == 0x4A &&
|
||||
GETJOCTET(data[1]) == 0x46 &&
|
||||
GETJOCTET(data[2]) == 0x49 &&
|
||||
GETJOCTET(data[3]) == 0x46 &&
|
||||
GETJOCTET(data[4]) == 0) {
|
||||
/* Found JFIF APP0 marker: save info */
|
||||
cinfo->saw_JFIF_marker = TRUE;
|
||||
cinfo->JFIF_major_version = GETJOCTET(data[5]);
|
||||
cinfo->JFIF_minor_version = GETJOCTET(data[6]);
|
||||
cinfo->density_unit = GETJOCTET(data[7]);
|
||||
cinfo->X_density = (GETJOCTET(data[8]) << 8) + GETJOCTET(data[9]);
|
||||
cinfo->Y_density = (GETJOCTET(data[10]) << 8) + GETJOCTET(data[11]);
|
||||
/* Check version.
|
||||
* Major version must be 1, anything else signals an incompatible change.
|
||||
* (We used to treat this as an error, but now it's a nonfatal warning,
|
||||
* because some bozo at Hijaak couldn't read the spec.)
|
||||
* Minor version should be 0..2, but process anyway if newer.
|
||||
*/
|
||||
if (cinfo->JFIF_major_version != 1)
|
||||
WARNMS2(cinfo, JWRN_JFIF_MAJOR,
|
||||
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);
|
||||
/* 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]));
|
||||
totallen -= APP0_DATA_LEN;
|
||||
if (totallen !=
|
||||
((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 &&
|
||||
GETJOCTET(data[1]) == 0x46 &&
|
||||
GETJOCTET(data[2]) == 0x58 &&
|
||||
GETJOCTET(data[3]) == 0x58 &&
|
||||
GETJOCTET(data[4]) == 0) {
|
||||
/* Found JFIF "JFXX" extension APP0 marker */
|
||||
/* The library doesn't actually do anything with these,
|
||||
* but we try to produce a helpful trace message.
|
||||
*/
|
||||
switch (GETJOCTET(data[5])) {
|
||||
case 0x10:
|
||||
TRACEMS1(cinfo, 1, JTRC_THUMB_JPEG, (int) totallen);
|
||||
break;
|
||||
case 0x11:
|
||||
TRACEMS1(cinfo, 1, JTRC_THUMB_PALETTE, (int) totallen);
|
||||
break;
|
||||
case 0x13:
|
||||
TRACEMS1(cinfo, 1, JTRC_THUMB_RGB, (int) totallen);
|
||||
break;
|
||||
default:
|
||||
TRACEMS2(cinfo, 1, JTRC_JFIF_EXTENSION,
|
||||
GETJOCTET(data[5]), (int) totallen);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
/* Start of APP0 does not match "JFIF" or "JFXX", or too short */
|
||||
TRACEMS1(cinfo, 1, JTRC_APP0, (int) totallen);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
LOCAL(void)
|
||||
examine_app14 (j_decompress_ptr cinfo, JOCTET FAR * data,
|
||||
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.
|
||||
*/
|
||||
{
|
||||
unsigned int version, flags0, flags1, transform;
|
||||
|
||||
if (datalen >= APP14_DATA_LEN &&
|
||||
GETJOCTET(data[0]) == 0x41 &&
|
||||
GETJOCTET(data[1]) == 0x64 &&
|
||||
GETJOCTET(data[2]) == 0x6F &&
|
||||
GETJOCTET(data[3]) == 0x62 &&
|
||||
GETJOCTET(data[4]) == 0x65) {
|
||||
/* Found Adobe APP14 marker */
|
||||
version = (GETJOCTET(data[5]) << 8) + GETJOCTET(data[6]);
|
||||
flags0 = (GETJOCTET(data[7]) << 8) + GETJOCTET(data[8]);
|
||||
flags1 = (GETJOCTET(data[9]) << 8) + GETJOCTET(data[10]);
|
||||
transform = GETJOCTET(data[11]);
|
||||
TRACEMS4(cinfo, 1, JTRC_ADOBE, version, flags0, flags1, transform);
|
||||
cinfo->saw_Adobe_marker = TRUE;
|
||||
cinfo->Adobe_transform = (UINT8) transform;
|
||||
} else {
|
||||
/* Start of APP14 does not match "Adobe", or too short */
|
||||
TRACEMS1(cinfo, 1, JTRC_APP14, (int) (datalen + remaining));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
METHODDEF(boolean)
|
||||
get_interesting_appn (j_decompress_ptr cinfo)
|
||||
/* Process an APP0 or APP14 marker without saving it */
|
||||
{
|
||||
INT32 length;
|
||||
JOCTET b[APPN_DATA_LEN];
|
||||
unsigned int i, numtoread;
|
||||
INPUT_VARS(cinfo);
|
||||
|
||||
INPUT_2BYTES(cinfo, length, return FALSE);
|
||||
length -= 2;
|
||||
|
||||
/* get the interesting part of the marker data */
|
||||
if (length >= APPN_DATA_LEN)
|
||||
numtoread = APPN_DATA_LEN;
|
||||
else if (length > 0)
|
||||
numtoread = (unsigned int) length;
|
||||
else
|
||||
numtoread = 0;
|
||||
for (i = 0; i < numtoread; i++)
|
||||
INPUT_BYTE(cinfo, b[i], return FALSE);
|
||||
length -= numtoread;
|
||||
|
||||
/* process it */
|
||||
switch (cinfo->unread_marker) {
|
||||
case M_APP0:
|
||||
examine_app0(cinfo, (JOCTET FAR *) b, numtoread, length);
|
||||
break;
|
||||
case M_APP14:
|
||||
examine_app14(cinfo, (JOCTET FAR *) b, numtoread, length);
|
||||
break;
|
||||
default:
|
||||
/* can't get here unless jpeg_save_markers chooses wrong processor */
|
||||
ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, cinfo->unread_marker);
|
||||
break;
|
||||
}
|
||||
|
||||
/* skip any remaining data -- could be lots */
|
||||
INPUT_SYNC(cinfo);
|
||||
if (length > 0)
|
||||
(*cinfo->src->skip_input_data) (cinfo, (long) length);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
#ifdef SAVE_MARKERS_SUPPORTED
|
||||
|
||||
METHODDEF(boolean)
|
||||
save_marker (j_decompress_ptr cinfo)
|
||||
/* Save an APPn or COM marker into the marker list */
|
||||
{
|
||||
my_marker_ptr marker = (my_marker_ptr) cinfo->marker;
|
||||
jpeg_saved_marker_ptr cur_marker = marker->cur_marker;
|
||||
unsigned int bytes_read, data_length;
|
||||
JOCTET FAR * data;
|
||||
INT32 length = 0;
|
||||
INPUT_VARS(cinfo);
|
||||
|
||||
if (cur_marker == NULL) {
|
||||
/* begin reading a marker */
|
||||
INPUT_2BYTES(cinfo, length, return FALSE);
|
||||
length -= 2;
|
||||
if (length >= 0) { /* watch out for bogus length word */
|
||||
/* figure out how much we want to save */
|
||||
unsigned int limit;
|
||||
if (cinfo->unread_marker == (int) M_COM)
|
||||
limit = marker->length_limit_COM;
|
||||
else
|
||||
limit = marker->length_limit_APPn[cinfo->unread_marker - (int) M_APP0];
|
||||
if ((unsigned int) length < limit)
|
||||
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);
|
||||
cur_marker->next = NULL;
|
||||
cur_marker->marker = (UINT8) cinfo->unread_marker;
|
||||
cur_marker->original_length = (unsigned int) length;
|
||||
cur_marker->data_length = limit;
|
||||
/* data area is just beyond the jpeg_marker_struct */
|
||||
data = cur_marker->data = (JOCTET FAR *) (cur_marker + 1);
|
||||
marker->cur_marker = cur_marker;
|
||||
marker->bytes_read = 0;
|
||||
bytes_read = 0;
|
||||
data_length = limit;
|
||||
} else {
|
||||
/* deal with bogus length word */
|
||||
bytes_read = data_length = 0;
|
||||
data = NULL;
|
||||
}
|
||||
} else {
|
||||
/* resume reading a marker */
|
||||
bytes_read = marker->bytes_read;
|
||||
data_length = cur_marker->data_length;
|
||||
data = cur_marker->data + bytes_read;
|
||||
}
|
||||
|
||||
while (bytes_read < data_length) {
|
||||
INPUT_SYNC(cinfo); /* move the restart point to here */
|
||||
marker->bytes_read = bytes_read;
|
||||
/* If there's not at least one byte in buffer, suspend */
|
||||
MAKE_BYTE_AVAIL(cinfo, return FALSE);
|
||||
/* Copy bytes with reasonable rapidity */
|
||||
while (bytes_read < data_length && bytes_in_buffer > 0) {
|
||||
*data++ = *next_input_byte++;
|
||||
bytes_in_buffer--;
|
||||
bytes_read++;
|
||||
}
|
||||
}
|
||||
|
||||
/* Done reading what we want to read */
|
||||
if (cur_marker != NULL) { /* will be NULL if bogus length word */
|
||||
/* Add new marker to end of list */
|
||||
if (cinfo->marker_list == NULL) {
|
||||
cinfo->marker_list = cur_marker;
|
||||
} else {
|
||||
jpeg_saved_marker_ptr prev = cinfo->marker_list;
|
||||
while (prev->next != NULL)
|
||||
prev = prev->next;
|
||||
prev->next = cur_marker;
|
||||
}
|
||||
/* Reset pointer & calc remaining data length */
|
||||
data = cur_marker->data;
|
||||
length = cur_marker->original_length - data_length;
|
||||
}
|
||||
/* Reset to initial state for next marker */
|
||||
marker->cur_marker = NULL;
|
||||
|
||||
/* Process the marker if interesting; else just make a generic trace msg */
|
||||
switch (cinfo->unread_marker) {
|
||||
case M_APP0:
|
||||
examine_app0(cinfo, data, data_length, length);
|
||||
break;
|
||||
case M_APP14:
|
||||
examine_app14(cinfo, data, data_length, length);
|
||||
break;
|
||||
default:
|
||||
TRACEMS2(cinfo, 1, JTRC_MISC_MARKER, cinfo->unread_marker,
|
||||
(int) (data_length + length));
|
||||
break;
|
||||
}
|
||||
|
||||
/* skip any remaining data -- could be lots */
|
||||
INPUT_SYNC(cinfo); /* do before skip_input_data */
|
||||
if (length > 0)
|
||||
(*cinfo->src->skip_input_data) (cinfo, (long) length);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
#endif /* SAVE_MARKERS_SUPPORTED */
|
||||
|
||||
|
||||
METHODDEF(boolean)
|
||||
skip_variable (j_decompress_ptr cinfo)
|
||||
/* Skip over an unknown or uninteresting variable-length marker */
|
||||
{
|
||||
@ -628,11 +847,13 @@ skip_variable (j_decompress_ptr cinfo)
|
||||
INPUT_VARS(cinfo);
|
||||
|
||||
INPUT_2BYTES(cinfo, length, return FALSE);
|
||||
length -= 2;
|
||||
|
||||
TRACEMS2(cinfo, 1, JTRC_MISC_MARKER, cinfo->unread_marker, (int) length);
|
||||
|
||||
INPUT_SYNC(cinfo); /* do before skip_input_data */
|
||||
(*cinfo->src->skip_input_data) (cinfo, (long) length - 2L);
|
||||
if (length > 0)
|
||||
(*cinfo->src->skip_input_data) (cinfo, (long) length);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
@ -647,7 +868,7 @@ skip_variable (j_decompress_ptr cinfo)
|
||||
* but it will never be 0 or FF.
|
||||
*/
|
||||
|
||||
LOCAL boolean
|
||||
LOCAL(boolean)
|
||||
next_marker (j_decompress_ptr cinfo)
|
||||
{
|
||||
int c;
|
||||
@ -694,7 +915,7 @@ next_marker (j_decompress_ptr cinfo)
|
||||
}
|
||||
|
||||
|
||||
LOCAL boolean
|
||||
LOCAL(boolean)
|
||||
first_marker (j_decompress_ptr cinfo)
|
||||
/* Like next_marker, but used to obtain the initial SOI marker. */
|
||||
/* For this marker, we do not allow preceding garbage or fill; otherwise,
|
||||
@ -725,7 +946,7 @@ first_marker (j_decompress_ptr cinfo)
|
||||
* JPEG_SUSPENDED, JPEG_REACHED_SOS, or JPEG_REACHED_EOI.
|
||||
*/
|
||||
|
||||
METHODDEF int
|
||||
METHODDEF(int)
|
||||
read_markers (j_decompress_ptr cinfo)
|
||||
{
|
||||
/* Outer loop repeats once for each marker. */
|
||||
@ -832,12 +1053,13 @@ read_markers (j_decompress_ptr cinfo)
|
||||
case M_APP13:
|
||||
case M_APP14:
|
||||
case M_APP15:
|
||||
if (! (*cinfo->marker->process_APPn[cinfo->unread_marker - (int) M_APP0]) (cinfo))
|
||||
if (! (*((my_marker_ptr) cinfo->marker)->process_APPn[
|
||||
cinfo->unread_marker - (int) M_APP0]) (cinfo))
|
||||
return JPEG_SUSPENDED;
|
||||
break;
|
||||
|
||||
case M_COM:
|
||||
if (! (*cinfo->marker->process_COM) (cinfo))
|
||||
if (! (*((my_marker_ptr) cinfo->marker)->process_COM) (cinfo))
|
||||
return JPEG_SUSPENDED;
|
||||
break;
|
||||
|
||||
@ -885,7 +1107,7 @@ read_markers (j_decompress_ptr cinfo)
|
||||
* it holds a marker which the decoder will be unable to read past.
|
||||
*/
|
||||
|
||||
METHODDEF boolean
|
||||
METHODDEF(boolean)
|
||||
read_restart_marker (j_decompress_ptr cinfo)
|
||||
{
|
||||
/* Obtain a marker unless we already did. */
|
||||
@ -898,7 +1120,7 @@ read_restart_marker (j_decompress_ptr cinfo)
|
||||
if (cinfo->unread_marker ==
|
||||
((int) M_RST0 + cinfo->marker->next_restart_num)) {
|
||||
/* Normal case --- swallow the marker and let entropy decoder continue */
|
||||
TRACEMS1(cinfo, 2, JTRC_RST, cinfo->marker->next_restart_num);
|
||||
TRACEMS1(cinfo, 3, JTRC_RST, cinfo->marker->next_restart_num);
|
||||
cinfo->unread_marker = 0;
|
||||
} else {
|
||||
/* Uh-oh, the restart markers have been messed up. */
|
||||
@ -964,7 +1186,7 @@ read_restart_marker (j_decompress_ptr cinfo)
|
||||
* any other marker would have to be bogus data in that case.
|
||||
*/
|
||||
|
||||
GLOBAL JRI_PUBLIC_API(boolean)
|
||||
GLOBAL(boolean)
|
||||
jpeg_resync_to_restart (j_decompress_ptr cinfo, int desired)
|
||||
{
|
||||
int marker = cinfo->unread_marker;
|
||||
@ -1014,15 +1236,18 @@ jpeg_resync_to_restart (j_decompress_ptr cinfo, int desired)
|
||||
* Reset marker processing state to begin a fresh datastream.
|
||||
*/
|
||||
|
||||
METHODDEF void
|
||||
METHODDEF(void)
|
||||
reset_marker_reader (j_decompress_ptr cinfo)
|
||||
{
|
||||
my_marker_ptr marker = (my_marker_ptr) cinfo->marker;
|
||||
|
||||
cinfo->comp_info = NULL; /* until allocated by get_sof */
|
||||
cinfo->input_scan_number = 0; /* no SOS seen yet */
|
||||
cinfo->unread_marker = 0; /* no pending marker */
|
||||
cinfo->marker->saw_SOI = FALSE; /* set internal state too */
|
||||
cinfo->marker->saw_SOF = FALSE;
|
||||
cinfo->marker->discarded_bytes = 0;
|
||||
marker->pub.saw_SOI = FALSE; /* set internal state too */
|
||||
marker->pub.saw_SOF = FALSE;
|
||||
marker->pub.discarded_bytes = 0;
|
||||
marker->cur_marker = NULL;
|
||||
}
|
||||
|
||||
|
||||
@ -1031,24 +1256,103 @@ reset_marker_reader (j_decompress_ptr cinfo)
|
||||
* This is called only once, when the decompression object is created.
|
||||
*/
|
||||
|
||||
GLOBAL void
|
||||
GLOBAL(void)
|
||||
jinit_marker_reader (j_decompress_ptr cinfo)
|
||||
{
|
||||
my_marker_ptr marker;
|
||||
int i;
|
||||
|
||||
/* Create subobject in permanent pool */
|
||||
cinfo->marker = (struct jpeg_marker_reader *)
|
||||
marker = (my_marker_ptr)
|
||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
|
||||
SIZEOF(struct jpeg_marker_reader));
|
||||
/* Initialize method pointers */
|
||||
cinfo->marker->reset_marker_reader = reset_marker_reader;
|
||||
cinfo->marker->read_markers = read_markers;
|
||||
cinfo->marker->read_restart_marker = read_restart_marker;
|
||||
cinfo->marker->process_COM = skip_variable;
|
||||
for (i = 0; i < 16; i++)
|
||||
cinfo->marker->process_APPn[i] = skip_variable;
|
||||
cinfo->marker->process_APPn[0] = get_app0;
|
||||
cinfo->marker->process_APPn[14] = get_app14;
|
||||
SIZEOF(my_marker_reader));
|
||||
cinfo->marker = (struct jpeg_marker_reader *) marker;
|
||||
/* Initialize public method pointers */
|
||||
marker->pub.reset_marker_reader = reset_marker_reader;
|
||||
marker->pub.read_markers = read_markers;
|
||||
marker->pub.read_restart_marker = read_restart_marker;
|
||||
/* Initialize COM/APPn processing.
|
||||
* By default, we examine and then discard APP0 and APP14,
|
||||
* but simply discard COM and all other APPn.
|
||||
*/
|
||||
marker->process_COM = skip_variable;
|
||||
marker->length_limit_COM = 0;
|
||||
for (i = 0; i < 16; i++) {
|
||||
marker->process_APPn[i] = skip_variable;
|
||||
marker->length_limit_APPn[i] = 0;
|
||||
}
|
||||
marker->process_APPn[0] = get_interesting_appn;
|
||||
marker->process_APPn[14] = get_interesting_appn;
|
||||
/* Reset marker processing state */
|
||||
reset_marker_reader(cinfo);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Control saving of COM and APPn markers into marker_list.
|
||||
*/
|
||||
|
||||
#ifdef SAVE_MARKERS_SUPPORTED
|
||||
|
||||
GLOBAL(void)
|
||||
jpeg_save_markers (j_decompress_ptr cinfo, int marker_code,
|
||||
unsigned int length_limit)
|
||||
{
|
||||
my_marker_ptr marker = (my_marker_ptr) cinfo->marker;
|
||||
long maxlength;
|
||||
jpeg_marker_parser_method processor;
|
||||
|
||||
/* Length limit mustn't be larger than what we can allocate
|
||||
* (should only be a concern in a 16-bit environment).
|
||||
*/
|
||||
maxlength = cinfo->mem->max_alloc_chunk - SIZEOF(struct jpeg_marker_struct);
|
||||
if (((long) length_limit) > maxlength)
|
||||
length_limit = (unsigned int) maxlength;
|
||||
|
||||
/* Choose processor routine to use.
|
||||
* APP0/APP14 have special requirements.
|
||||
*/
|
||||
if (length_limit) {
|
||||
processor = save_marker;
|
||||
/* If saving APP0/APP14, save at least enough for our internal use. */
|
||||
if (marker_code == (int) M_APP0 && length_limit < APP0_DATA_LEN)
|
||||
length_limit = APP0_DATA_LEN;
|
||||
else if (marker_code == (int) M_APP14 && length_limit < APP14_DATA_LEN)
|
||||
length_limit = APP14_DATA_LEN;
|
||||
} else {
|
||||
processor = skip_variable;
|
||||
/* If discarding APP0/APP14, use our regular on-the-fly processor. */
|
||||
if (marker_code == (int) M_APP0 || marker_code == (int) M_APP14)
|
||||
processor = get_interesting_appn;
|
||||
}
|
||||
|
||||
if (marker_code == (int) M_COM) {
|
||||
marker->process_COM = processor;
|
||||
marker->length_limit_COM = length_limit;
|
||||
} else if (marker_code >= (int) M_APP0 && marker_code <= (int) M_APP15) {
|
||||
marker->process_APPn[marker_code - (int) M_APP0] = processor;
|
||||
marker->length_limit_APPn[marker_code - (int) M_APP0] = length_limit;
|
||||
} else
|
||||
ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, marker_code);
|
||||
}
|
||||
|
||||
#endif /* SAVE_MARKERS_SUPPORTED */
|
||||
|
||||
|
||||
/*
|
||||
* Install a special processing method for COM or APPn markers.
|
||||
*/
|
||||
|
||||
GLOBAL(void)
|
||||
jpeg_set_marker_processor (j_decompress_ptr cinfo, int marker_code,
|
||||
jpeg_marker_parser_method routine)
|
||||
{
|
||||
my_marker_ptr marker = (my_marker_ptr) cinfo->marker;
|
||||
|
||||
if (marker_code == (int) M_COM)
|
||||
marker->process_COM = routine;
|
||||
else if (marker_code >= (int) M_APP0 && marker_code <= (int) M_APP15)
|
||||
marker->process_APPn[marker_code - (int) M_APP0] = routine;
|
||||
else
|
||||
ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, marker_code);
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* jdmaster.c
|
||||
*
|
||||
* Copyright (C) 1991-1995, Thomas G. Lane.
|
||||
* 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.
|
||||
*
|
||||
@ -40,7 +40,7 @@ typedef my_decomp_master * my_master_ptr;
|
||||
* CRUCIAL: this must match the actual capabilities of jdmerge.c!
|
||||
*/
|
||||
|
||||
LOCAL boolean
|
||||
LOCAL(boolean)
|
||||
use_merged_upsample (j_decompress_ptr cinfo)
|
||||
{
|
||||
#ifdef UPSAMPLE_MERGING_SUPPORTED
|
||||
@ -80,12 +80,14 @@ use_merged_upsample (j_decompress_ptr cinfo)
|
||||
* Also note that it may be called before the master module is initialized!
|
||||
*/
|
||||
|
||||
GLOBAL JRI_PUBLIC_API(void)
|
||||
GLOBAL(void)
|
||||
jpeg_calc_output_dimensions (j_decompress_ptr cinfo)
|
||||
/* Do computations that are needed before master selection phase */
|
||||
{
|
||||
#ifdef IDCT_SCALING_SUPPORTED
|
||||
int ci;
|
||||
jpeg_component_info *compptr;
|
||||
#endif
|
||||
|
||||
/* Prevent application from calling me at wrong times */
|
||||
if (cinfo->global_state != DSTATE_READY)
|
||||
@ -242,7 +244,7 @@ jpeg_calc_output_dimensions (j_decompress_ptr cinfo)
|
||||
* enough and used often enough to justify this.
|
||||
*/
|
||||
|
||||
LOCAL void
|
||||
LOCAL(void)
|
||||
prepare_range_limit_table (j_decompress_ptr cinfo)
|
||||
/* Allocate and fill in the sample_range_limit table */
|
||||
{
|
||||
@ -282,7 +284,7 @@ prepare_range_limit_table (j_decompress_ptr cinfo)
|
||||
* settings.
|
||||
*/
|
||||
|
||||
LOCAL void
|
||||
LOCAL(void)
|
||||
master_selection (j_decompress_ptr cinfo)
|
||||
{
|
||||
my_master_ptr master = (my_master_ptr) cinfo->master;
|
||||
@ -429,10 +431,10 @@ master_selection (j_decompress_ptr cinfo)
|
||||
* modules will be active during this pass and give them appropriate
|
||||
* start_pass calls. We also set is_dummy_pass to indicate whether this
|
||||
* is a "real" output pass or a dummy pass for color quantization.
|
||||
* (In the latter case, jdapi.c will crank the pass to completion.)
|
||||
* (In the latter case, jdapistd.c will crank the pass to completion.)
|
||||
*/
|
||||
|
||||
METHODDEF void
|
||||
METHODDEF(void)
|
||||
prepare_for_output_pass (j_decompress_ptr cinfo)
|
||||
{
|
||||
my_master_ptr master = (my_master_ptr) cinfo->master;
|
||||
@ -492,7 +494,7 @@ prepare_for_output_pass (j_decompress_ptr cinfo)
|
||||
* Finish up at end of an output pass.
|
||||
*/
|
||||
|
||||
METHODDEF void
|
||||
METHODDEF(void)
|
||||
finish_output_pass (j_decompress_ptr cinfo)
|
||||
{
|
||||
my_master_ptr master = (my_master_ptr) cinfo->master;
|
||||
@ -509,7 +511,7 @@ finish_output_pass (j_decompress_ptr cinfo)
|
||||
* Switch to a new external colormap between output passes.
|
||||
*/
|
||||
|
||||
GLOBAL void
|
||||
GLOBAL(void)
|
||||
jpeg_new_colormap (j_decompress_ptr cinfo)
|
||||
{
|
||||
my_master_ptr master = (my_master_ptr) cinfo->master;
|
||||
@ -537,7 +539,7 @@ jpeg_new_colormap (j_decompress_ptr cinfo)
|
||||
* This is performed at the start of jpeg_start_decompress.
|
||||
*/
|
||||
|
||||
GLOBAL void
|
||||
GLOBAL(void)
|
||||
jinit_master_decompress (j_decompress_ptr cinfo)
|
||||
{
|
||||
my_master_ptr master;
|
||||
|
@ -52,7 +52,7 @@
|
||||
__int64 const45 = 0x0000000000010000; // Cr_b Cr_g Cr_r Cr_b
|
||||
__int64 const55 = 0x0001FFFA00000001; // Cb_b Cb_g Cb_r Cb_b
|
||||
#endif
|
||||
|
||||
|
||||
/* Private subobject */
|
||||
|
||||
typedef struct {
|
||||
@ -63,9 +63,6 @@ typedef struct {
|
||||
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 */
|
||||
int * Cb_b_tab; /* => table for Cb to B conversion */
|
||||
@ -96,7 +93,7 @@ typedef my_upsampler * my_upsample_ptr;
|
||||
* This is taken directly from jdcolor.c; see that file for more info.
|
||||
*/
|
||||
|
||||
LOCAL void
|
||||
LOCAL(void)
|
||||
build_ycc_rgb_table (j_decompress_ptr cinfo)
|
||||
{
|
||||
my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
|
||||
@ -139,7 +136,7 @@ build_ycc_rgb_table (j_decompress_ptr cinfo)
|
||||
* Initialize for an upsampling pass.
|
||||
*/
|
||||
|
||||
METHODDEF void
|
||||
METHODDEF(void)
|
||||
start_pass_merged_upsample (j_decompress_ptr cinfo)
|
||||
{
|
||||
my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
|
||||
@ -157,7 +154,7 @@ start_pass_merged_upsample (j_decompress_ptr cinfo)
|
||||
* The control routine just handles the row buffering considerations.
|
||||
*/
|
||||
|
||||
METHODDEF void
|
||||
METHODDEF(void)
|
||||
merged_2v_upsample (j_decompress_ptr cinfo,
|
||||
JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
|
||||
JDIMENSION in_row_groups_avail,
|
||||
@ -206,7 +203,7 @@ merged_2v_upsample (j_decompress_ptr cinfo,
|
||||
}
|
||||
|
||||
|
||||
METHODDEF void
|
||||
METHODDEF(void)
|
||||
merged_1v_upsample (j_decompress_ptr cinfo,
|
||||
JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
|
||||
JDIMENSION in_row_groups_avail,
|
||||
@ -239,12 +236,14 @@ merged_1v_upsample (j_decompress_ptr cinfo,
|
||||
* Upsample and color convert for the case of 2:1 horizontal and 1:1 vertical.
|
||||
*/
|
||||
|
||||
METHODDEF void
|
||||
METHODDEF(void)
|
||||
h2v1_merged_upsample (j_decompress_ptr cinfo,
|
||||
JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
|
||||
JSAMPARRAY output_buf)
|
||||
{
|
||||
my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
|
||||
|
||||
|
||||
my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
|
||||
register int y, cred, cgreen, cblue;
|
||||
int cb, cr;
|
||||
register JSAMPROW outptr;
|
||||
@ -295,30 +294,30 @@ h2v1_merged_upsample (j_decompress_ptr cinfo,
|
||||
outptr[RGB_BLUE] = range_limit[y + cblue];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Upsample and color convert for the case of 2:1 horizontal and 2:1 vertical.
|
||||
*/
|
||||
|
||||
#ifdef XP_WIN32
|
||||
__inline METHODDEF void
|
||||
__inline METHODDEF(void)
|
||||
h2v2_merged_upsample_orig (j_decompress_ptr cinfo,
|
||||
JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
|
||||
JSAMPARRAY output_buf);
|
||||
__inline METHODDEF void
|
||||
__inline METHODDEF(void)
|
||||
h2v2_merged_upsample_mmx (j_decompress_ptr cinfo,
|
||||
JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
|
||||
JSAMPARRAY output_buf);
|
||||
#endif
|
||||
|
||||
METHODDEF void
|
||||
METHODDEF(void)
|
||||
h2v2_merged_upsample (j_decompress_ptr cinfo,
|
||||
JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
|
||||
JSAMPARRAY output_buf);
|
||||
|
||||
#ifdef XP_WIN32
|
||||
METHODDEF void
|
||||
METHODDEF(void)
|
||||
h2v2_merged_upsample (j_decompress_ptr cinfo,
|
||||
JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
|
||||
JSAMPARRAY output_buf)
|
||||
@ -330,11 +329,12 @@ else
|
||||
|
||||
}
|
||||
|
||||
__inline METHODDEF void
|
||||
__inline METHODDEF(void)
|
||||
h2v2_merged_upsample_orig (j_decompress_ptr cinfo,
|
||||
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;
|
||||
int cb, cr;
|
||||
@ -403,11 +403,10 @@ h2v2_merged_upsample_orig (j_decompress_ptr cinfo,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Upsample and color convert for the case of 2:1 horizontal and 2:1 vertical.
|
||||
*/
|
||||
__inline METHODDEF void
|
||||
__inline METHODDEF(void)
|
||||
h2v2_merged_upsample_mmx (j_decompress_ptr cinfo,
|
||||
JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
|
||||
JSAMPARRAY output_buf)
|
||||
@ -908,7 +907,7 @@ do_next16:
|
||||
#else
|
||||
|
||||
|
||||
METHODDEF void
|
||||
METHODDEF(void)
|
||||
h2v2_merged_upsample (j_decompress_ptr cinfo,
|
||||
JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
|
||||
JSAMPARRAY output_buf)
|
||||
@ -991,7 +990,7 @@ h2v2_merged_upsample (j_decompress_ptr cinfo,
|
||||
* of this module; no safety checks are made here.
|
||||
*/
|
||||
|
||||
GLOBAL void
|
||||
GLOBAL(void)
|
||||
jinit_merged_upsampler (j_decompress_ptr cinfo)
|
||||
{
|
||||
my_upsample_ptr upsample;
|
||||
@ -1023,4 +1022,3 @@ jinit_merged_upsampler (j_decompress_ptr cinfo)
|
||||
}
|
||||
|
||||
#endif /* UPSAMPLE_MERGING_SUPPORTED */
|
||||
|
||||
|
360
jpeg/jdphuff.c
360
jpeg/jdphuff.c
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* jdphuff.c
|
||||
*
|
||||
* Copyright (C) 1995, Thomas G. Lane.
|
||||
* 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.
|
||||
*
|
||||
@ -74,21 +74,21 @@ typedef struct {
|
||||
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,
|
||||
METHODDEF(boolean) decode_mcu_DC_first JPP((j_decompress_ptr cinfo,
|
||||
JBLOCKROW *MCU_data));
|
||||
METHODDEF boolean decode_mcu_AC_refine JPP((j_decompress_ptr cinfo,
|
||||
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
|
||||
METHODDEF(void)
|
||||
start_pass_phuff_decoder (j_decompress_ptr cinfo)
|
||||
{
|
||||
phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
|
||||
@ -119,6 +119,12 @@ start_pass_phuff_decoder (j_decompress_ptr cinfo)
|
||||
}
|
||||
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);
|
||||
@ -160,18 +166,12 @@ start_pass_phuff_decoder (j_decompress_ptr cinfo)
|
||||
if (is_DC_band) {
|
||||
if (cinfo->Ah == 0) { /* DC refinement needs no table */
|
||||
tbl = compptr->dc_tbl_no;
|
||||
if (tbl < 0 || tbl >= NUM_HUFF_TBLS ||
|
||||
cinfo->dc_huff_tbl_ptrs[tbl] == NULL)
|
||||
ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tbl);
|
||||
jpeg_make_d_derived_tbl(cinfo, cinfo->dc_huff_tbl_ptrs[tbl],
|
||||
jpeg_make_d_derived_tbl(cinfo, TRUE, tbl,
|
||||
& entropy->derived_tbls[tbl]);
|
||||
}
|
||||
} else {
|
||||
tbl = compptr->ac_tbl_no;
|
||||
if (tbl < 0 || tbl >= NUM_HUFF_TBLS ||
|
||||
cinfo->ac_huff_tbl_ptrs[tbl] == NULL)
|
||||
ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tbl);
|
||||
jpeg_make_d_derived_tbl(cinfo, cinfo->ac_huff_tbl_ptrs[tbl],
|
||||
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];
|
||||
@ -183,7 +183,7 @@ start_pass_phuff_decoder (j_decompress_ptr cinfo)
|
||||
/* Initialize bitread state variables */
|
||||
entropy->bitstate.bits_left = 0;
|
||||
entropy->bitstate.get_buffer = 0; /* unnecessary, but keeps Purify quiet */
|
||||
entropy->bitstate.printed_eod = FALSE;
|
||||
entropy->pub.insufficient_data = FALSE;
|
||||
|
||||
/* Initialize private state variables */
|
||||
entropy->saved.EOBRUN = 0;
|
||||
@ -224,7 +224,7 @@ static const int extend_offset[16] = /* entry n is (-1 << n) + 1 */
|
||||
* Returns FALSE if must suspend.
|
||||
*/
|
||||
|
||||
LOCAL boolean
|
||||
LOCAL(boolean)
|
||||
process_restart (j_decompress_ptr cinfo)
|
||||
{
|
||||
phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
|
||||
@ -248,8 +248,13 @@ process_restart (j_decompress_ptr cinfo)
|
||||
/* Reset restart counter */
|
||||
entropy->restarts_to_go = cinfo->restart_interval;
|
||||
|
||||
/* Next segment can get another out-of-data warning */
|
||||
entropy->bitstate.printed_eod = FALSE;
|
||||
/* 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;
|
||||
}
|
||||
@ -277,7 +282,7 @@ process_restart (j_decompress_ptr cinfo)
|
||||
* or first pass of successive approximation).
|
||||
*/
|
||||
|
||||
METHODDEF boolean
|
||||
METHODDEF(boolean)
|
||||
decode_mcu_DC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
|
||||
{
|
||||
phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
|
||||
@ -297,39 +302,45 @@ decode_mcu_DC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* Load up working state */
|
||||
BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
|
||||
ASSIGN_STATE(state, entropy->saved);
|
||||
/* 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) {
|
||||
|
||||
/* Outer loop handles each block in the MCU */
|
||||
/* Load up working state */
|
||||
BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
|
||||
ASSIGN_STATE(state, entropy->saved);
|
||||
|
||||
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];
|
||||
/* Outer loop handles each block in the MCU */
|
||||
|
||||
/* Decode a single block's worth of coefficients */
|
||||
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];
|
||||
|
||||
/* 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);
|
||||
/* 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);
|
||||
}
|
||||
|
||||
/* 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 DC 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);
|
||||
}
|
||||
|
||||
/* 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--;
|
||||
|
||||
@ -342,7 +353,7 @@ decode_mcu_DC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
|
||||
* or first pass of successive approximation).
|
||||
*/
|
||||
|
||||
METHODDEF boolean
|
||||
METHODDEF(boolean)
|
||||
decode_mcu_AC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
|
||||
{
|
||||
phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
|
||||
@ -361,53 +372,59 @@ decode_mcu_AC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* Load up working state.
|
||||
* We can avoid loading/saving bitread state if in an EOB run.
|
||||
/* 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.
|
||||
*/
|
||||
EOBRUN = entropy->saved.EOBRUN; /* only part of saved state we care about */
|
||||
if (! entropy->pub.insufficient_data) {
|
||||
|
||||
/* There is always only one block per MCU */
|
||||
/* 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 */
|
||||
|
||||
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;
|
||||
/* There is always only one block per MCU */
|
||||
|
||||
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 */
|
||||
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);
|
||||
}
|
||||
|
||||
BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
|
||||
/* Completed MCU, so update state */
|
||||
entropy->saved.EOBRUN = EOBRUN; /* only part of saved state we need */
|
||||
}
|
||||
|
||||
/* Completed MCU, so update state */
|
||||
entropy->saved.EOBRUN = EOBRUN; /* only part of saved state we care about */
|
||||
|
||||
/* Account for restart interval (no-op if not using restarts) */
|
||||
entropy->restarts_to_go--;
|
||||
|
||||
@ -421,7 +438,7 @@ decode_mcu_AC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
|
||||
* is not very clear on the point.
|
||||
*/
|
||||
|
||||
METHODDEF boolean
|
||||
METHODDEF(boolean)
|
||||
decode_mcu_DC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
|
||||
{
|
||||
phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
|
||||
@ -437,6 +454,10 @@ decode_mcu_DC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
|
||||
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);
|
||||
|
||||
@ -466,7 +487,7 @@ decode_mcu_DC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
|
||||
* MCU decoding for AC successive approximation refinement scan.
|
||||
*/
|
||||
|
||||
METHODDEF boolean
|
||||
METHODDEF(boolean)
|
||||
decode_mcu_AC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
|
||||
{
|
||||
phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
|
||||
@ -489,55 +510,93 @@ decode_mcu_AC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* Load up working state */
|
||||
BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
|
||||
EOBRUN = entropy->saved.EOBRUN; /* only part of saved state we care about */
|
||||
|
||||
/* 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 position to see if we already did it.
|
||||
/* If we've run out of data, don't modify the MCU.
|
||||
*/
|
||||
num_newnz = 0;
|
||||
if (! entropy->pub.insufficient_data) {
|
||||
|
||||
/* initialize coefficient loop counter to start of band */
|
||||
k = cinfo->Ss;
|
||||
/* Load up working state */
|
||||
BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
|
||||
EOBRUN = entropy->saved.EOBRUN; /* only part of saved state we need */
|
||||
|
||||
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;
|
||||
/* 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 */
|
||||
}
|
||||
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;
|
||||
}
|
||||
/* 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 (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.
|
||||
*/
|
||||
do {
|
||||
for (; k <= Se; k++) {
|
||||
thiscoef = *block + jpeg_natural_order[k];
|
||||
if (*thiscoef != 0) {
|
||||
CHECK_BIT_BUFFER(br_state, 1, goto undoit);
|
||||
@ -549,49 +608,16 @@ decode_mcu_AC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
|
||||
*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--;
|
||||
}
|
||||
/* 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 care about */
|
||||
/* 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--;
|
||||
@ -611,7 +637,7 @@ undoit:
|
||||
* Module initialization routine for progressive Huffman entropy decoding.
|
||||
*/
|
||||
|
||||
GLOBAL void
|
||||
GLOBAL(void)
|
||||
jinit_phuff_decoder (j_decompress_ptr cinfo)
|
||||
{
|
||||
phuff_entropy_ptr entropy;
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* jdpostct.c
|
||||
*
|
||||
* Copyright (C) 1994-1995, Thomas G. Lane.
|
||||
* Copyright (C) 1994-1996, Thomas G. Lane.
|
||||
* This file is part of the Independent JPEG Group's software.
|
||||
* For conditions of distribution and use, see the accompanying README file.
|
||||
*
|
||||
@ -43,20 +43,20 @@ typedef my_post_controller * my_post_ptr;
|
||||
|
||||
|
||||
/* Forward declarations */
|
||||
METHODDEF void post_process_1pass
|
||||
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));
|
||||
#ifdef QUANT_2PASS_SUPPORTED
|
||||
METHODDEF void post_process_prepass
|
||||
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));
|
||||
METHODDEF void post_process_2pass
|
||||
METHODDEF(void) post_process_2pass
|
||||
JPP((j_decompress_ptr cinfo,
|
||||
JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
|
||||
JDIMENSION in_row_groups_avail,
|
||||
@ -69,7 +69,7 @@ METHODDEF void post_process_2pass
|
||||
* Initialize for a processing pass.
|
||||
*/
|
||||
|
||||
METHODDEF void
|
||||
METHODDEF(void)
|
||||
start_pass_dpost (j_decompress_ptr cinfo, J_BUF_MODE pass_mode)
|
||||
{
|
||||
my_post_ptr post = (my_post_ptr) cinfo->post;
|
||||
@ -122,7 +122,7 @@ start_pass_dpost (j_decompress_ptr cinfo, J_BUF_MODE pass_mode)
|
||||
* This is used for color precision reduction as well as one-pass quantization.
|
||||
*/
|
||||
|
||||
METHODDEF void
|
||||
METHODDEF(void)
|
||||
post_process_1pass (j_decompress_ptr cinfo,
|
||||
JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
|
||||
JDIMENSION in_row_groups_avail,
|
||||
@ -154,7 +154,7 @@ post_process_1pass (j_decompress_ptr cinfo,
|
||||
* Process some data in the first pass of 2-pass quantization.
|
||||
*/
|
||||
|
||||
METHODDEF void
|
||||
METHODDEF(void)
|
||||
post_process_prepass (j_decompress_ptr cinfo,
|
||||
JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
|
||||
JDIMENSION in_row_groups_avail,
|
||||
@ -198,7 +198,7 @@ post_process_prepass (j_decompress_ptr cinfo,
|
||||
* Process some data in the second pass of 2-pass quantization.
|
||||
*/
|
||||
|
||||
METHODDEF void
|
||||
METHODDEF(void)
|
||||
post_process_2pass (j_decompress_ptr cinfo,
|
||||
JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
|
||||
JDIMENSION in_row_groups_avail,
|
||||
@ -246,7 +246,7 @@ post_process_2pass (j_decompress_ptr cinfo,
|
||||
* Initialize postprocessing controller.
|
||||
*/
|
||||
|
||||
GLOBAL void
|
||||
GLOBAL(void)
|
||||
jinit_d_post_controller (j_decompress_ptr cinfo, boolean need_full_buffer)
|
||||
{
|
||||
my_post_ptr post;
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* jdsample.c
|
||||
*
|
||||
* Copyright (C) 1991-1994, Thomas G. Lane.
|
||||
* Copyright (C) 1991-1996, Thomas G. Lane.
|
||||
* This file is part of the Independent JPEG Group's software.
|
||||
* For conditions of distribution and use, see the accompanying README file.
|
||||
*
|
||||
@ -65,7 +65,7 @@ typedef my_upsampler * my_upsample_ptr;
|
||||
* Initialize for an upsampling pass.
|
||||
*/
|
||||
|
||||
METHODDEF void
|
||||
METHODDEF(void)
|
||||
start_pass_upsample (j_decompress_ptr cinfo)
|
||||
{
|
||||
my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
|
||||
@ -85,7 +85,7 @@ start_pass_upsample (j_decompress_ptr cinfo)
|
||||
* color conversion a row at a time.
|
||||
*/
|
||||
|
||||
METHODDEF void
|
||||
METHODDEF(void)
|
||||
sep_upsample (j_decompress_ptr cinfo,
|
||||
JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
|
||||
JDIMENSION in_row_groups_avail,
|
||||
@ -153,7 +153,7 @@ sep_upsample (j_decompress_ptr cinfo,
|
||||
* "consumed" until we are done color converting and emitting it.
|
||||
*/
|
||||
|
||||
METHODDEF void
|
||||
METHODDEF(void)
|
||||
fullsize_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
||||
JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
|
||||
{
|
||||
@ -166,7 +166,7 @@ fullsize_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
||||
* These components will not be referenced by color conversion.
|
||||
*/
|
||||
|
||||
METHODDEF void
|
||||
METHODDEF(void)
|
||||
noop_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
||||
JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
|
||||
{
|
||||
@ -185,7 +185,7 @@ noop_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
||||
* you would be well advised to improve this code.
|
||||
*/
|
||||
|
||||
METHODDEF void
|
||||
METHODDEF(void)
|
||||
int_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
||||
JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
|
||||
{
|
||||
@ -229,7 +229,7 @@ int_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
||||
* It's still a box filter.
|
||||
*/
|
||||
|
||||
METHODDEF void
|
||||
METHODDEF(void)
|
||||
h2v1_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
||||
JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
|
||||
{
|
||||
@ -257,7 +257,7 @@ h2v1_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
||||
* It's still a box filter.
|
||||
*/
|
||||
|
||||
METHODDEF void
|
||||
METHODDEF(void)
|
||||
h2v2_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
||||
JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
|
||||
{
|
||||
@ -300,7 +300,7 @@ h2v2_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
||||
* alternate pixel locations (a simple ordered dither pattern).
|
||||
*/
|
||||
|
||||
METHODDEF void
|
||||
METHODDEF(void)
|
||||
h2v1_fancy_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
||||
JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
|
||||
{
|
||||
@ -341,7 +341,7 @@ h2v1_fancy_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
||||
* context from the main buffer controller (see initialization code).
|
||||
*/
|
||||
|
||||
METHODDEF void
|
||||
METHODDEF(void)
|
||||
h2v2_fancy_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
||||
JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
|
||||
{
|
||||
@ -395,7 +395,7 @@ h2v2_fancy_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
||||
* Module initialization routine for upsampling.
|
||||
*/
|
||||
|
||||
GLOBAL void
|
||||
GLOBAL(void)
|
||||
jinit_upsampler (j_decompress_ptr cinfo)
|
||||
{
|
||||
my_upsample_ptr upsample;
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* jerror.c
|
||||
*
|
||||
* Copyright (C) 1991-1994, Thomas G. Lane.
|
||||
* Copyright (C) 1991-1998, Thomas G. Lane.
|
||||
* This file is part of the Independent JPEG Group's software.
|
||||
* For conditions of distribution and use, see the accompanying README file.
|
||||
*
|
||||
@ -10,22 +10,40 @@
|
||||
* stderr is the right thing to do. Many applications will want to replace
|
||||
* some or all of these routines.
|
||||
*
|
||||
* If you define USE_WINDOWS_MESSAGEBOX in jconfig.h or in the makefile,
|
||||
* you get a Windows-specific hack to display error messages in a dialog box.
|
||||
* It ain't much, but it beats dropping error messages into the bit bucket,
|
||||
* which is what happens to output to stderr under most Windows C compilers.
|
||||
*
|
||||
* These routines are used by both the compression and decompression code.
|
||||
*/
|
||||
|
||||
/*
|
||||
* This file has been modified for the Mozilla/Netscape environment.
|
||||
* Modifications are distributed under the Netscape Public License and are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
/* this is not a core library module, so it doesn't define JPEG_INTERNALS */
|
||||
#include "jinclude.h"
|
||||
#include "jpeglib.h"
|
||||
#include "jversion.h"
|
||||
#include "jerror.h"
|
||||
|
||||
/* Mozilla addition */
|
||||
#if defined(DEBUG) && defined(__MWERKS__)
|
||||
# include "xp_trace.h"
|
||||
#endif
|
||||
|
||||
#ifdef USE_WINDOWS_MESSAGEBOX
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#ifndef EXIT_FAILURE /* define exit() codes if not provided */
|
||||
#define EXIT_FAILURE 1
|
||||
#endif
|
||||
|
||||
#if defined(DEBUG) && defined(__MWERKS__)
|
||||
# include "xp_trace.h"
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Create the message string table.
|
||||
@ -60,7 +78,7 @@ const char * const jpeg_std_message_table[] = {
|
||||
* or jpeg_destroy) at some point.
|
||||
*/
|
||||
|
||||
METHODDEF void
|
||||
METHODDEF(void)
|
||||
error_exit (j_common_ptr cinfo)
|
||||
{
|
||||
/* Always display the message */
|
||||
@ -69,10 +87,14 @@ error_exit (j_common_ptr cinfo)
|
||||
/* Let the memory manager delete any temp files before we die */
|
||||
jpeg_destroy(cinfo);
|
||||
|
||||
#if !defined(_WINDOWS) || defined(_WIN32)
|
||||
/* Mozilla mod: in some Windows environments, the exit() function doesn't
|
||||
* even exist, so don't compile a reference to it. Heaven help you if
|
||||
* you fail to provide a replacement error_exit function, because the
|
||||
* IJG library will NOT handle control returning from error_exit!
|
||||
*/
|
||||
|
||||
#ifndef XP_WIN
|
||||
exit(EXIT_FAILURE);
|
||||
#else
|
||||
/* XXX */
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -81,26 +103,28 @@ error_exit (j_common_ptr cinfo)
|
||||
* Actual output of an error or trace message.
|
||||
* Applications may override this method to send JPEG messages somewhere
|
||||
* other than stderr.
|
||||
*
|
||||
* On Windows, printing to stderr is generally completely useless,
|
||||
* so we provide optional code to produce an error-dialog popup.
|
||||
* Most Windows applications will still prefer to override this routine,
|
||||
* but if they don't, it'll do something at least marginally useful.
|
||||
*
|
||||
* NOTE: to use the library in an environment that doesn't support the
|
||||
* C stdio library, you may have to delete the call to fprintf() entirely,
|
||||
* not just not use this routine.
|
||||
*/
|
||||
|
||||
METHODDEF void
|
||||
METHODDEF(void)
|
||||
output_message (j_common_ptr cinfo)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
char buffer[JMSG_LENGTH_MAX];
|
||||
|
||||
/* Create the message */
|
||||
(*cinfo->err->format_message) (cinfo, buffer);
|
||||
|
||||
/* Send it to stderr, adding a newline */
|
||||
/* Mozilla mod: send JPEG library messages to XP_TRACE */
|
||||
|
||||
#if defined(_WINDOWS) && !defined(_WIN32)
|
||||
printf("%s\n", buffer);
|
||||
#elif __MWERKS__
|
||||
XP_TRACE(("%s\n", buffer));
|
||||
#else
|
||||
fprintf(stderr, "%s\n", buffer);
|
||||
#endif
|
||||
#endif
|
||||
/* XP_TRACE(("JPEG library: %s", buffer));*/
|
||||
}
|
||||
|
||||
|
||||
@ -115,10 +139,9 @@ output_message (j_common_ptr cinfo)
|
||||
* or change the policy about which messages to display.
|
||||
*/
|
||||
|
||||
METHODDEF void
|
||||
METHODDEF(void)
|
||||
emit_message (j_common_ptr cinfo, int msg_level)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
struct jpeg_error_mgr * err = cinfo->err;
|
||||
|
||||
if (msg_level < 0) {
|
||||
@ -126,20 +149,15 @@ emit_message (j_common_ptr cinfo, int msg_level)
|
||||
* the policy implemented here is to show only the first warning,
|
||||
* unless trace_level >= 3.
|
||||
*/
|
||||
#ifndef __MWERKS__ /* Mark Lanett is a pinhead. */
|
||||
if (err->num_warnings == 0 || err->trace_level >= 3)
|
||||
#endif
|
||||
(*err->output_message) (cinfo);
|
||||
/* Always count warnings in num_warnings. */
|
||||
err->num_warnings++;
|
||||
} else {
|
||||
/* It's a trace message. Show it if trace_level >= msg_level. */
|
||||
#ifndef __MWERKS__ /* Mark Lanett is a pinhead. */
|
||||
if (err->trace_level >= msg_level)
|
||||
#endif
|
||||
(*err->output_message) (cinfo);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@ -150,7 +168,7 @@ emit_message (j_common_ptr cinfo, int msg_level)
|
||||
* Few applications should need to override this method.
|
||||
*/
|
||||
|
||||
METHODDEF void
|
||||
METHODDEF(void)
|
||||
format_message (j_common_ptr cinfo, char * buffer)
|
||||
{
|
||||
struct jpeg_error_mgr * err = cinfo->err;
|
||||
@ -205,7 +223,7 @@ format_message (j_common_ptr cinfo, char * buffer)
|
||||
* this method if it has additional error processing state.
|
||||
*/
|
||||
|
||||
METHODDEF void
|
||||
METHODDEF(void)
|
||||
reset_error_mgr (j_common_ptr cinfo)
|
||||
{
|
||||
cinfo->err->num_warnings = 0;
|
||||
@ -224,7 +242,7 @@ reset_error_mgr (j_common_ptr cinfo)
|
||||
* after which the application may override some of the methods.
|
||||
*/
|
||||
|
||||
GLOBAL JRI_PUBLIC_API(struct jpeg_error_mgr *)
|
||||
GLOBAL(struct jpeg_error_mgr *)
|
||||
jpeg_std_error (struct jpeg_error_mgr * err)
|
||||
{
|
||||
err->error_exit = error_exit;
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* jerror.h
|
||||
*
|
||||
* Copyright (C) 1994-1995, Thomas G. Lane.
|
||||
* Copyright (C) 1994-1997, Thomas G. Lane.
|
||||
* This file is part of the Independent JPEG Group's software.
|
||||
* For conditions of distribution and use, see the accompanying README file.
|
||||
*
|
||||
@ -45,10 +45,14 @@ 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_DCT_COEF, "DCT coefficient out of range")
|
||||
JMESSAGE(JERR_BAD_DCTSIZE, "IDCT output block size %d not supported")
|
||||
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")
|
||||
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")
|
||||
@ -59,6 +63,8 @@ JMESSAGE(JERR_BAD_PROG_SCRIPT,
|
||||
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")
|
||||
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")
|
||||
@ -67,7 +73,6 @@ JMESSAGE(JERR_COMPONENT_COUNT, "Too many color components: %d, max %d")
|
||||
JMESSAGE(JERR_CONVERSION_NOTIMPL, "Unsupported color conversion request")
|
||||
JMESSAGE(JERR_DAC_INDEX, "Bogus DAC index %d")
|
||||
JMESSAGE(JERR_DAC_VALUE, "Bogus DAC value 0x%x")
|
||||
JMESSAGE(JERR_DHT_COUNTS, "Bogus DHT counts")
|
||||
JMESSAGE(JERR_DHT_INDEX, "Bogus DHT index %d")
|
||||
JMESSAGE(JERR_DQT_INDEX, "Bogus DQT index %d")
|
||||
JMESSAGE(JERR_EMPTY_IMAGE, "Empty JPEG image (DNL not supported)")
|
||||
@ -130,12 +135,13 @@ JMESSAGE(JTRC_EMS_CLOSE, "Freed EMS handle %u")
|
||||
JMESSAGE(JTRC_EMS_OPEN, "Obtained EMS handle %u")
|
||||
JMESSAGE(JTRC_EOI, "End Of Image")
|
||||
JMESSAGE(JTRC_HUFFBITS, " %3d %3d %3d %3d %3d %3d %3d %3d")
|
||||
JMESSAGE(JTRC_JFIF, "JFIF APP0 marker, density %dx%d %d")
|
||||
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")
|
||||
JMESSAGE(JTRC_JFIF_MINOR, "Unknown JFIF minor revision number %d.%02d")
|
||||
JMESSAGE(JTRC_JFIF_EXTENSION,
|
||||
"JFIF extension marker: type 0x%02x, length %u")
|
||||
JMESSAGE(JTRC_JFIF_THUMBNAIL, " with %d x %d thumbnail image")
|
||||
JMESSAGE(JTRC_MISC_MARKER, "Skipping marker 0x%02x, length %u")
|
||||
JMESSAGE(JTRC_MISC_MARKER, "Miscellaneous marker 0x%02x, length %u")
|
||||
JMESSAGE(JTRC_PARMLESS_MARKER, "Unexpected marker 0x%02x")
|
||||
JMESSAGE(JTRC_QUANTVALS, " %4u %4u %4u %4u %4u %4u %4u %4u")
|
||||
JMESSAGE(JTRC_QUANT_3_NCOLORS, "Quantizing to %d = %d*%d*%d colors")
|
||||
@ -153,6 +159,12 @@ JMESSAGE(JTRC_SOS_COMPONENT, " Component %d: dc=%d ac=%d")
|
||||
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")
|
||||
JMESSAGE(JTRC_THUMB_PALETTE,
|
||||
"JFIF extension marker: palette thumbnail image, length %u")
|
||||
JMESSAGE(JTRC_THUMB_RGB,
|
||||
"JFIF extension marker: RGB thumbnail image, length %u")
|
||||
JMESSAGE(JTRC_UNKNOWN_IDS,
|
||||
"Unrecognized component IDs %d %d %d, assuming YCbCr")
|
||||
JMESSAGE(JTRC_XMS_CLOSE, "Freed XMS handle %u")
|
||||
@ -259,6 +271,12 @@ JMESSAGE(JWRN_TOO_MUCH_DATA, "Application transferred too many scanlines")
|
||||
_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)); )
|
||||
#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); \
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* jfdctflt.c
|
||||
*
|
||||
* Copyright (C) 1994, Thomas G. Lane.
|
||||
* Copyright (C) 1994-1996, Thomas G. Lane.
|
||||
* This file is part of the Independent JPEG Group's software.
|
||||
* For conditions of distribution and use, see the accompanying README file.
|
||||
*
|
||||
@ -55,7 +55,7 @@
|
||||
* Perform the forward DCT on one block of samples.
|
||||
*/
|
||||
|
||||
GLOBAL void
|
||||
GLOBAL(void)
|
||||
jpeg_fdct_float (FAST_FLOAT * data)
|
||||
{
|
||||
FAST_FLOAT tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* jfdctfst.c
|
||||
*
|
||||
* Copyright (C) 1994, Thomas G. Lane.
|
||||
* Copyright (C) 1994-1996, Thomas G. Lane.
|
||||
* This file is part of the Independent JPEG Group's software.
|
||||
* For conditions of distribution and use, see the accompanying README file.
|
||||
*
|
||||
@ -110,7 +110,7 @@
|
||||
* Perform the forward DCT on one block of samples.
|
||||
*/
|
||||
|
||||
GLOBAL void
|
||||
GLOBAL(void)
|
||||
jpeg_fdct_ifast (DCTELEM * data)
|
||||
{
|
||||
DCTELEM tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* jfdctint.c
|
||||
*
|
||||
* Copyright (C) 1991-1994, Thomas G. Lane.
|
||||
* Copyright (C) 1991-1996, Thomas G. Lane.
|
||||
* This file is part of the Independent JPEG Group's software.
|
||||
* For conditions of distribution and use, see the accompanying README file.
|
||||
*
|
||||
@ -136,7 +136,7 @@
|
||||
* Perform the forward DCT on one block of samples.
|
||||
*/
|
||||
|
||||
GLOBAL void
|
||||
GLOBAL(void)
|
||||
jpeg_fdct_islow (DCTELEM * data)
|
||||
{
|
||||
INT32 tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* jidctflt.c
|
||||
*
|
||||
* Copyright (C) 1994, Thomas G. Lane.
|
||||
* 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.
|
||||
*
|
||||
@ -64,7 +64,7 @@
|
||||
* Perform dequantization and inverse DCT on one block of coefficients.
|
||||
*/
|
||||
|
||||
GLOBAL void
|
||||
GLOBAL(void)
|
||||
jpeg_idct_float (j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
||||
JCOEFPTR coef_block,
|
||||
JSAMPARRAY output_buf, JDIMENSION output_col)
|
||||
@ -96,9 +96,10 @@ jpeg_idct_float (j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
||||
* column DCT calculations can be simplified this way.
|
||||
*/
|
||||
|
||||
if ((inptr[DCTSIZE*1] | inptr[DCTSIZE*2] | inptr[DCTSIZE*3] |
|
||||
inptr[DCTSIZE*4] | inptr[DCTSIZE*5] | inptr[DCTSIZE*6] |
|
||||
inptr[DCTSIZE*7]) == 0) {
|
||||
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) {
|
||||
/* AC terms all zero */
|
||||
FAST_FLOAT dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* jidctfst.c
|
||||
*
|
||||
* Copyright (C) 1994-1996, Thomas G. Lane.
|
||||
* 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.
|
||||
*
|
||||
@ -32,7 +32,6 @@
|
||||
* quality-setting files than with low-quality ones.
|
||||
*/
|
||||
|
||||
|
||||
#define JPEG_INTERNALS
|
||||
#include "jinclude.h"
|
||||
#include "jpeglib.h"
|
||||
@ -162,24 +161,24 @@
|
||||
#endif
|
||||
|
||||
#ifdef XP_WIN32
|
||||
__inline GLOBAL void
|
||||
__inline GLOBAL(void)
|
||||
jpeg_idct_ifast_mmx (j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
||||
JCOEFPTR coef_block,
|
||||
JSAMPARRAY output_buf, JDIMENSION output_col);
|
||||
__inline GLOBAL void
|
||||
__inline GLOBAL(void)
|
||||
jpeg_idct_ifast_orig (j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
||||
JCOEFPTR coef_block,
|
||||
JSAMPARRAY output_buf, JDIMENSION output_col);
|
||||
#endif
|
||||
|
||||
GLOBAL void
|
||||
GLOBAL(void)
|
||||
jpeg_idct_ifast(j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
||||
JCOEFPTR coef_block,
|
||||
JSAMPARRAY output_buf, JDIMENSION output_col);
|
||||
|
||||
|
||||
#ifdef XP_WIN32
|
||||
GLOBAL void
|
||||
GLOBAL(void)
|
||||
jpeg_idct_ifast (j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
||||
JCOEFPTR coef_block,
|
||||
JSAMPARRAY output_buf, JDIMENSION output_col)
|
||||
@ -195,7 +194,7 @@ else
|
||||
* Perform dequantization and inverse DCT on one block of coefficients.
|
||||
*/
|
||||
|
||||
GLOBAL void
|
||||
GLOBAL (void)
|
||||
jpeg_idct_ifast (j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
||||
JCOEFPTR coef_block,
|
||||
JSAMPARRAY output_buf, JDIMENSION output_col)
|
||||
@ -205,11 +204,11 @@ jpeg_idct_ifast (j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
||||
DCTELEM z5, z10, z11, z12, z13;
|
||||
JCOEFPTR inptr;
|
||||
IFAST_MULT_TYPE * quantptr;
|
||||
int16 * wsptr;
|
||||
int * wsptr;
|
||||
JSAMPROW outptr;
|
||||
JSAMPLE *range_limit = IDCT_range_limit(cinfo);
|
||||
int ctr;
|
||||
int16 workspace[DCTSIZE2]; /* buffers data between passes */
|
||||
int workspace[DCTSIZE2]; /* buffers data between passes */
|
||||
SHIFT_TEMPS /* for DESCALE */
|
||||
ISHIFT_TEMPS /* for IDESCALE */
|
||||
|
||||
@ -228,9 +227,10 @@ jpeg_idct_ifast (j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
||||
* column DCT calculations can be simplified this way.
|
||||
*/
|
||||
|
||||
if ((inptr[DCTSIZE*1] | inptr[DCTSIZE*2] | inptr[DCTSIZE*3] |
|
||||
inptr[DCTSIZE*4] | inptr[DCTSIZE*5] | inptr[DCTSIZE*6] |
|
||||
inptr[DCTSIZE*7]) == 0) {
|
||||
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) {
|
||||
/* AC terms all zero */
|
||||
int dcval = (int) DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
|
||||
|
||||
@ -320,8 +320,8 @@ jpeg_idct_ifast (j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
||||
*/
|
||||
|
||||
#ifndef NO_ZERO_ROW_TEST
|
||||
if ((wsptr[1] | wsptr[2] | wsptr[3] | wsptr[4] | wsptr[5] | wsptr[6] |
|
||||
wsptr[7]) == 0) {
|
||||
if (wsptr[1] == 0 && wsptr[2] == 0 && wsptr[3] == 0 && wsptr[4] == 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];
|
||||
@ -394,12 +394,13 @@ jpeg_idct_ifast (j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
||||
wsptr += DCTSIZE; /* advance pointer to next row */
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef XP_WIN32
|
||||
|
||||
|
||||
_inline GLOBAL void
|
||||
_inline GLOBAL(void)
|
||||
jpeg_idct_ifast_orig (j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
||||
JCOEFPTR coef_block,
|
||||
JSAMPARRAY output_buf, JDIMENSION output_col)
|
||||
@ -608,7 +609,7 @@ jpeg_idct_ifast_orig (j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
||||
static __int64 const_0x0080 = 0x0080008000800080;
|
||||
|
||||
|
||||
__inline GLOBAL void
|
||||
__inline GLOBAL(void)
|
||||
jpeg_idct_ifast_mmx (j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
||||
JCOEFPTR inptr,
|
||||
JSAMPARRAY outptr, JDIMENSION output_col)
|
||||
@ -1646,6 +1647,4 @@ jpeg_idct_ifast_mmx (j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* DCT_IFAST_SUPPORTED */
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* jidctint.c
|
||||
*
|
||||
* Copyright (C) 1991-1994, Thomas G. Lane.
|
||||
* Copyright (C) 1991-1998, Thomas G. Lane.
|
||||
* This file is part of the Independent JPEG Group's software.
|
||||
* For conditions of distribution and use, see the accompanying README file.
|
||||
*
|
||||
@ -144,7 +144,7 @@
|
||||
* Perform dequantization and inverse DCT on one block of coefficients.
|
||||
*/
|
||||
|
||||
GLOBAL void
|
||||
GLOBAL(void)
|
||||
jpeg_idct_islow (j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
||||
JCOEFPTR coef_block,
|
||||
JSAMPARRAY output_buf, JDIMENSION output_col)
|
||||
@ -178,9 +178,10 @@ jpeg_idct_islow (j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
||||
* column DCT calculations can be simplified this way.
|
||||
*/
|
||||
|
||||
if ((inptr[DCTSIZE*1] | inptr[DCTSIZE*2] | inptr[DCTSIZE*3] |
|
||||
inptr[DCTSIZE*4] | inptr[DCTSIZE*5] | inptr[DCTSIZE*6] |
|
||||
inptr[DCTSIZE*7]) == 0) {
|
||||
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) {
|
||||
/* AC terms all zero */
|
||||
int dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]) << PASS1_BITS;
|
||||
|
||||
@ -284,8 +285,8 @@ jpeg_idct_islow (j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
||||
*/
|
||||
|
||||
#ifndef NO_ZERO_ROW_TEST
|
||||
if ((wsptr[1] | wsptr[2] | wsptr[3] | wsptr[4] | wsptr[5] | wsptr[6] |
|
||||
wsptr[7]) == 0) {
|
||||
if (wsptr[1] == 0 && wsptr[2] == 0 && wsptr[3] == 0 && wsptr[4] == 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];
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* jidctred.c
|
||||
*
|
||||
* Copyright (C) 1994, Thomas G. Lane.
|
||||
* 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.
|
||||
*
|
||||
@ -114,7 +114,7 @@
|
||||
* producing a reduced-size 4x4 output block.
|
||||
*/
|
||||
|
||||
GLOBAL void
|
||||
GLOBAL(void)
|
||||
jpeg_idct_4x4 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
||||
JCOEFPTR coef_block,
|
||||
JSAMPARRAY output_buf, JDIMENSION output_col)
|
||||
@ -139,8 +139,9 @@ jpeg_idct_4x4 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
||||
/* Don't bother to process column 4, because second pass won't use it */
|
||||
if (ctr == DCTSIZE-4)
|
||||
continue;
|
||||
if ((inptr[DCTSIZE*1] | inptr[DCTSIZE*2] | inptr[DCTSIZE*3] |
|
||||
inptr[DCTSIZE*5] | inptr[DCTSIZE*6] | inptr[DCTSIZE*7]) == 0) {
|
||||
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;
|
||||
|
||||
@ -198,8 +199,8 @@ jpeg_idct_4x4 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
||||
/* It's not clear whether a zero row test is worthwhile here ... */
|
||||
|
||||
#ifndef NO_ZERO_ROW_TEST
|
||||
if ((wsptr[1] | wsptr[2] | wsptr[3] | wsptr[5] | wsptr[6] |
|
||||
wsptr[7]) == 0) {
|
||||
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];
|
||||
@ -266,7 +267,7 @@ jpeg_idct_4x4 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
||||
* producing a reduced-size 2x2 output block.
|
||||
*/
|
||||
|
||||
GLOBAL void
|
||||
GLOBAL(void)
|
||||
jpeg_idct_2x2 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
||||
JCOEFPTR coef_block,
|
||||
JSAMPARRAY output_buf, JDIMENSION output_col)
|
||||
@ -290,8 +291,8 @@ jpeg_idct_2x2 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
||||
/* Don't bother to process columns 2,4,6 */
|
||||
if (ctr == DCTSIZE-2 || ctr == DCTSIZE-4 || ctr == DCTSIZE-6)
|
||||
continue;
|
||||
if ((inptr[DCTSIZE*1] | inptr[DCTSIZE*3] |
|
||||
inptr[DCTSIZE*5] | inptr[DCTSIZE*7]) == 0) {
|
||||
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;
|
||||
|
||||
@ -331,7 +332,7 @@ jpeg_idct_2x2 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
||||
/* It's not clear whether a zero row test is worthwhile here ... */
|
||||
|
||||
#ifndef NO_ZERO_ROW_TEST
|
||||
if ((wsptr[1] | wsptr[3] | wsptr[5] | wsptr[7]) == 0) {
|
||||
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];
|
||||
@ -374,7 +375,7 @@ jpeg_idct_2x2 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
||||
* producing a reduced-size 1x1 output block.
|
||||
*/
|
||||
|
||||
GLOBAL void
|
||||
GLOBAL(void)
|
||||
jpeg_idct_1x1 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
|
||||
JCOEFPTR coef_block,
|
||||
JSAMPARRAY output_buf, JDIMENSION output_col)
|
||||
|
@ -17,15 +17,7 @@
|
||||
|
||||
/* Include auto-config file to find out which system include files we need. */
|
||||
|
||||
#ifdef __MWERKS__
|
||||
# include "jconfig-mac-cw.h"
|
||||
#elif defined(_WINDOWS)
|
||||
# include "jwinfig.h"
|
||||
#elif defined(XP_OS2)
|
||||
# include "jos2fig.h"
|
||||
#else
|
||||
# include "jconfig.h" /* auto configuration options */
|
||||
#endif
|
||||
#include "jconfig.h" /* auto configuration options */
|
||||
#define JCONFIG_INCLUDED /* so that jpeglib.h doesn't do it again */
|
||||
|
||||
/*
|
||||
@ -53,15 +45,6 @@
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
/*
|
||||
* SunOS 4.x doesn't do a very good job providing prototypes.
|
||||
*/
|
||||
#ifdef SUNOS4
|
||||
int fread(void *, size_t, size_t, FILE *);
|
||||
void *memset(void *, int, size_t);
|
||||
int sscanf(const char *, const char *, ...);
|
||||
#endif
|
||||
|
||||
/*
|
||||
* We need memory copying and zeroing functions, plus strncpy().
|
||||
* ANSI and System V implementations declare these in <string.h>.
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* jmemansi.c
|
||||
*
|
||||
* Copyright (C) 1992-1994, Thomas G. Lane.
|
||||
* 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.
|
||||
*
|
||||
@ -32,13 +32,13 @@ extern void free JPP((void *ptr));
|
||||
* routines malloc() and free().
|
||||
*/
|
||||
|
||||
GLOBAL void *
|
||||
GLOBAL(void *)
|
||||
jpeg_get_small (j_common_ptr cinfo, size_t sizeofobject)
|
||||
{
|
||||
return (void *) malloc(sizeofobject);
|
||||
}
|
||||
|
||||
GLOBAL void
|
||||
GLOBAL(void)
|
||||
jpeg_free_small (j_common_ptr cinfo, void * object, size_t sizeofobject)
|
||||
{
|
||||
free(object);
|
||||
@ -52,13 +52,13 @@ jpeg_free_small (j_common_ptr cinfo, void * object, size_t sizeofobject)
|
||||
* you probably won't be able to process useful-size images in only 64KB.
|
||||
*/
|
||||
|
||||
GLOBAL void FAR *
|
||||
GLOBAL(void FAR *)
|
||||
jpeg_get_large (j_common_ptr cinfo, size_t sizeofobject)
|
||||
{
|
||||
return (void FAR *) malloc(sizeofobject);
|
||||
}
|
||||
|
||||
GLOBAL void
|
||||
GLOBAL(void)
|
||||
jpeg_free_large (j_common_ptr cinfo, void FAR * object, size_t sizeofobject)
|
||||
{
|
||||
free(object);
|
||||
@ -77,7 +77,7 @@ jpeg_free_large (j_common_ptr cinfo, void FAR * object, size_t sizeofobject)
|
||||
#define DEFAULT_MAX_MEM 1000000L /* default: one megabyte */
|
||||
#endif
|
||||
|
||||
GLOBAL long
|
||||
GLOBAL(long)
|
||||
jpeg_mem_available (j_common_ptr cinfo, long min_bytes_needed,
|
||||
long max_bytes_needed, long already_allocated)
|
||||
{
|
||||
@ -93,7 +93,7 @@ jpeg_mem_available (j_common_ptr cinfo, long min_bytes_needed,
|
||||
*/
|
||||
|
||||
|
||||
METHODDEF void
|
||||
METHODDEF(void)
|
||||
read_backing_store (j_common_ptr cinfo, backing_store_ptr info,
|
||||
void FAR * buffer_address,
|
||||
long file_offset, long byte_count)
|
||||
@ -106,7 +106,7 @@ read_backing_store (j_common_ptr cinfo, backing_store_ptr info,
|
||||
}
|
||||
|
||||
|
||||
METHODDEF void
|
||||
METHODDEF(void)
|
||||
write_backing_store (j_common_ptr cinfo, backing_store_ptr info,
|
||||
void FAR * buffer_address,
|
||||
long file_offset, long byte_count)
|
||||
@ -119,7 +119,7 @@ write_backing_store (j_common_ptr cinfo, backing_store_ptr info,
|
||||
}
|
||||
|
||||
|
||||
METHODDEF void
|
||||
METHODDEF(void)
|
||||
close_backing_store (j_common_ptr cinfo, backing_store_ptr info)
|
||||
{
|
||||
fclose(info->temp_file);
|
||||
@ -137,7 +137,7 @@ close_backing_store (j_common_ptr cinfo, backing_store_ptr info)
|
||||
* indeed, we can't even find out the actual name of the temp file.
|
||||
*/
|
||||
|
||||
GLOBAL void
|
||||
GLOBAL(void)
|
||||
jpeg_open_backing_store (j_common_ptr cinfo, backing_store_ptr info,
|
||||
long total_bytes_needed)
|
||||
{
|
||||
@ -154,13 +154,13 @@ jpeg_open_backing_store (j_common_ptr cinfo, backing_store_ptr info,
|
||||
* cleanup required.
|
||||
*/
|
||||
|
||||
GLOBAL long
|
||||
GLOBAL(long)
|
||||
jpeg_mem_init (j_common_ptr cinfo)
|
||||
{
|
||||
return DEFAULT_MAX_MEM; /* default for max_memory_to_use */
|
||||
}
|
||||
|
||||
GLOBAL void
|
||||
GLOBAL(void)
|
||||
jpeg_mem_term (j_common_ptr cinfo)
|
||||
{
|
||||
/* no work */
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* jmemdos.c
|
||||
*
|
||||
* Copyright (C) 1992-1994, Thomas G. Lane.
|
||||
* Copyright (C) 1992-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.
|
||||
*
|
||||
@ -77,6 +77,10 @@ extern char * getenv JPP((const char * name));
|
||||
#define READ_BINARY "rb"
|
||||
#endif
|
||||
|
||||
#ifndef USE_MSDOS_MEMMGR /* make sure user got configuration right */
|
||||
You forgot to define USE_MSDOS_MEMMGR in jconfig.h. /* deliberate syntax error */
|
||||
#endif
|
||||
|
||||
#if MAX_ALLOC_CHUNK >= 65535L /* make sure jconfig.h got this right */
|
||||
MAX_ALLOC_CHUNK should be less than 64K. /* deliberate syntax error */
|
||||
#endif
|
||||
@ -85,15 +89,11 @@ extern char * getenv JPP((const char * name));
|
||||
/*
|
||||
* Declarations for assembly-language support routines (see jmemdosa.asm).
|
||||
*
|
||||
* The functions are declared "far" as are all pointer arguments;
|
||||
* The functions are declared "far" as are all their pointer arguments;
|
||||
* this ensures the assembly source code will work regardless of the
|
||||
* compiler memory model. We assume "short" is 16 bits, "long" is 32.
|
||||
*/
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#define far
|
||||
#endif
|
||||
|
||||
typedef void far * XMSDRIVER; /* actually a pointer to code */
|
||||
typedef struct { /* registers for calling XMS driver */
|
||||
unsigned short ax, dx, bx;
|
||||
@ -104,17 +104,17 @@ typedef struct { /* registers for calling EMS driver */
|
||||
void far * ds_si;
|
||||
} EMScontext;
|
||||
|
||||
EXTERN short far jdos_open JPP((short far * handle, char far * filename));
|
||||
EXTERN short far jdos_close JPP((short handle));
|
||||
EXTERN short far jdos_seek JPP((short handle, long offset));
|
||||
EXTERN short far jdos_read JPP((short handle, void far * buffer,
|
||||
extern short far jdos_open JPP((short far * handle, char far * filename));
|
||||
extern short far jdos_close JPP((short handle));
|
||||
extern short far jdos_seek JPP((short handle, long offset));
|
||||
extern short far jdos_read JPP((short handle, void far * buffer,
|
||||
unsigned short count));
|
||||
EXTERN short far jdos_write JPP((short handle, void far * buffer,
|
||||
extern short far jdos_write JPP((short handle, void far * buffer,
|
||||
unsigned short count));
|
||||
EXTERN void far jxms_getdriver JPP((XMSDRIVER far *));
|
||||
EXTERN void far jxms_calldriver JPP((XMSDRIVER, XMScontext far *));
|
||||
EXTERN short far jems_available JPP((void));
|
||||
EXTERN void far jems_calldriver JPP((EMScontext far *));
|
||||
extern void far jxms_getdriver JPP((XMSDRIVER far *));
|
||||
extern void far jxms_calldriver JPP((XMSDRIVER, XMScontext far *));
|
||||
extern short far jems_available JPP((void));
|
||||
extern void far jems_calldriver JPP((EMScontext far *));
|
||||
|
||||
|
||||
/*
|
||||
@ -124,7 +124,7 @@ EXTERN void far jems_calldriver JPP((EMScontext far *));
|
||||
|
||||
static int next_file_num; /* to distinguish among several temp files */
|
||||
|
||||
LOCAL void
|
||||
LOCAL(void)
|
||||
select_file_name (char * fname)
|
||||
{
|
||||
const char * env;
|
||||
@ -162,13 +162,13 @@ select_file_name (char * fname)
|
||||
* routines malloc() and free().
|
||||
*/
|
||||
|
||||
GLOBAL void *
|
||||
GLOBAL(void *)
|
||||
jpeg_get_small (j_common_ptr cinfo, size_t sizeofobject)
|
||||
{
|
||||
return (void *) malloc(sizeofobject);
|
||||
}
|
||||
|
||||
GLOBAL void
|
||||
GLOBAL(void)
|
||||
jpeg_free_small (j_common_ptr cinfo, void * object, size_t sizeofobject)
|
||||
{
|
||||
free(object);
|
||||
@ -179,13 +179,13 @@ jpeg_free_small (j_common_ptr cinfo, void * object, size_t sizeofobject)
|
||||
* "Large" objects are allocated in far memory, if possible
|
||||
*/
|
||||
|
||||
GLOBAL void FAR *
|
||||
GLOBAL(void FAR *)
|
||||
jpeg_get_large (j_common_ptr cinfo, size_t sizeofobject)
|
||||
{
|
||||
return (void FAR *) far_malloc(sizeofobject);
|
||||
}
|
||||
|
||||
GLOBAL void
|
||||
GLOBAL(void)
|
||||
jpeg_free_large (j_common_ptr cinfo, void FAR * object, size_t sizeofobject)
|
||||
{
|
||||
far_free(object);
|
||||
@ -204,7 +204,7 @@ jpeg_free_large (j_common_ptr cinfo, void FAR * object, size_t sizeofobject)
|
||||
#define DEFAULT_MAX_MEM 300000L /* for total usage about 450K */
|
||||
#endif
|
||||
|
||||
GLOBAL long
|
||||
GLOBAL(long)
|
||||
jpeg_mem_available (j_common_ptr cinfo, long min_bytes_needed,
|
||||
long max_bytes_needed, long already_allocated)
|
||||
{
|
||||
@ -239,7 +239,7 @@ jpeg_mem_available (j_common_ptr cinfo, long min_bytes_needed,
|
||||
*/
|
||||
|
||||
|
||||
METHODDEF void
|
||||
METHODDEF(void)
|
||||
read_file_store (j_common_ptr cinfo, backing_store_ptr info,
|
||||
void FAR * buffer_address,
|
||||
long file_offset, long byte_count)
|
||||
@ -255,7 +255,7 @@ read_file_store (j_common_ptr cinfo, backing_store_ptr info,
|
||||
}
|
||||
|
||||
|
||||
METHODDEF void
|
||||
METHODDEF(void)
|
||||
write_file_store (j_common_ptr cinfo, backing_store_ptr info,
|
||||
void FAR * buffer_address,
|
||||
long file_offset, long byte_count)
|
||||
@ -271,7 +271,7 @@ write_file_store (j_common_ptr cinfo, backing_store_ptr info,
|
||||
}
|
||||
|
||||
|
||||
METHODDEF void
|
||||
METHODDEF(void)
|
||||
close_file_store (j_common_ptr cinfo, backing_store_ptr info)
|
||||
{
|
||||
jdos_close(info->handle.file_handle); /* close the file */
|
||||
@ -284,7 +284,7 @@ close_file_store (j_common_ptr cinfo, backing_store_ptr info)
|
||||
}
|
||||
|
||||
|
||||
LOCAL boolean
|
||||
LOCAL(boolean)
|
||||
open_file_store (j_common_ptr cinfo, backing_store_ptr info,
|
||||
long total_bytes_needed)
|
||||
{
|
||||
@ -329,7 +329,7 @@ typedef struct { /* XMS move specification structure */
|
||||
#define ODD(X) (((X) & 1L) != 0)
|
||||
|
||||
|
||||
METHODDEF void
|
||||
METHODDEF(void)
|
||||
read_xms_store (j_common_ptr cinfo, backing_store_ptr info,
|
||||
void FAR * buffer_address,
|
||||
long file_offset, long byte_count)
|
||||
@ -362,7 +362,7 @@ read_xms_store (j_common_ptr cinfo, backing_store_ptr info,
|
||||
}
|
||||
|
||||
|
||||
METHODDEF void
|
||||
METHODDEF(void)
|
||||
write_xms_store (j_common_ptr cinfo, backing_store_ptr info,
|
||||
void FAR * buffer_address,
|
||||
long file_offset, long byte_count)
|
||||
@ -397,7 +397,7 @@ write_xms_store (j_common_ptr cinfo, backing_store_ptr info,
|
||||
}
|
||||
|
||||
|
||||
METHODDEF void
|
||||
METHODDEF(void)
|
||||
close_xms_store (j_common_ptr cinfo, backing_store_ptr info)
|
||||
{
|
||||
XMScontext ctx;
|
||||
@ -410,7 +410,7 @@ close_xms_store (j_common_ptr cinfo, backing_store_ptr info)
|
||||
}
|
||||
|
||||
|
||||
LOCAL boolean
|
||||
LOCAL(boolean)
|
||||
open_xms_store (j_common_ptr cinfo, backing_store_ptr info,
|
||||
long total_bytes_needed)
|
||||
{
|
||||
@ -487,7 +487,7 @@ typedef union { /* EMS move specification structure */
|
||||
#define LOBYTE(W) ((W) & 0xFF)
|
||||
|
||||
|
||||
METHODDEF void
|
||||
METHODDEF(void)
|
||||
read_ems_store (j_common_ptr cinfo, backing_store_ptr info,
|
||||
void FAR * buffer_address,
|
||||
long file_offset, long byte_count)
|
||||
@ -512,7 +512,7 @@ read_ems_store (j_common_ptr cinfo, backing_store_ptr info,
|
||||
}
|
||||
|
||||
|
||||
METHODDEF void
|
||||
METHODDEF(void)
|
||||
write_ems_store (j_common_ptr cinfo, backing_store_ptr info,
|
||||
void FAR * buffer_address,
|
||||
long file_offset, long byte_count)
|
||||
@ -537,7 +537,7 @@ write_ems_store (j_common_ptr cinfo, backing_store_ptr info,
|
||||
}
|
||||
|
||||
|
||||
METHODDEF void
|
||||
METHODDEF(void)
|
||||
close_ems_store (j_common_ptr cinfo, backing_store_ptr info)
|
||||
{
|
||||
EMScontext ctx;
|
||||
@ -550,7 +550,7 @@ close_ems_store (j_common_ptr cinfo, backing_store_ptr info)
|
||||
}
|
||||
|
||||
|
||||
LOCAL boolean
|
||||
LOCAL(boolean)
|
||||
open_ems_store (j_common_ptr cinfo, backing_store_ptr info,
|
||||
long total_bytes_needed)
|
||||
{
|
||||
@ -595,7 +595,7 @@ open_ems_store (j_common_ptr cinfo, backing_store_ptr info,
|
||||
* Initial opening of a backing-store object.
|
||||
*/
|
||||
|
||||
GLOBAL void
|
||||
GLOBAL(void)
|
||||
jpeg_open_backing_store (j_common_ptr cinfo, backing_store_ptr info,
|
||||
long total_bytes_needed)
|
||||
{
|
||||
@ -619,14 +619,14 @@ jpeg_open_backing_store (j_common_ptr cinfo, backing_store_ptr info,
|
||||
* cleanup required.
|
||||
*/
|
||||
|
||||
GLOBAL long
|
||||
GLOBAL(long)
|
||||
jpeg_mem_init (j_common_ptr cinfo)
|
||||
{
|
||||
next_file_num = 0; /* initialize temp file name generator */
|
||||
return DEFAULT_MAX_MEM; /* default for max_memory_to_use */
|
||||
}
|
||||
|
||||
GLOBAL void
|
||||
GLOBAL(void)
|
||||
jpeg_mem_term (j_common_ptr cinfo)
|
||||
{
|
||||
/* Microsoft C, at least in v6.00A, will not successfully reclaim freed
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* jmemmgr.c
|
||||
*
|
||||
* Copyright (C) 1991-1995, Thomas G. Lane.
|
||||
* 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.
|
||||
*
|
||||
@ -182,7 +182,7 @@ struct jvirt_barray_control {
|
||||
|
||||
#ifdef MEM_STATS /* optional extra stuff for statistics */
|
||||
|
||||
LOCAL void
|
||||
LOCAL(void)
|
||||
print_mem_stats (j_common_ptr cinfo, int pool_id)
|
||||
{
|
||||
my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
|
||||
@ -213,7 +213,7 @@ print_mem_stats (j_common_ptr cinfo, int pool_id)
|
||||
#endif /* MEM_STATS */
|
||||
|
||||
|
||||
LOCAL void
|
||||
LOCAL(void)
|
||||
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 */
|
||||
@ -253,7 +253,7 @@ static const size_t extra_pool_slop[JPOOL_NUMPOOLS] =
|
||||
#define MIN_SLOP 50 /* greater than 0 to avoid futile looping */
|
||||
|
||||
|
||||
METHODDEF void *
|
||||
METHODDEF(void *)
|
||||
alloc_small (j_common_ptr cinfo, int pool_id, size_t sizeofobject)
|
||||
/* Allocate a "small" object */
|
||||
{
|
||||
@ -338,7 +338,7 @@ alloc_small (j_common_ptr cinfo, int pool_id, size_t sizeofobject)
|
||||
* deliberately bunch rows together to ensure a large request size.
|
||||
*/
|
||||
|
||||
METHODDEF void FAR *
|
||||
METHODDEF(void FAR *)
|
||||
alloc_large (j_common_ptr cinfo, int pool_id, size_t sizeofobject)
|
||||
/* Allocate a "large" object */
|
||||
{
|
||||
@ -391,7 +391,7 @@ alloc_large (j_common_ptr cinfo, int pool_id, size_t sizeofobject)
|
||||
* a virtual array.
|
||||
*/
|
||||
|
||||
METHODDEF JSAMPARRAY
|
||||
METHODDEF(JSAMPARRAY)
|
||||
alloc_sarray (j_common_ptr cinfo, int pool_id,
|
||||
JDIMENSION samplesperrow, JDIMENSION numrows)
|
||||
/* Allocate a 2-D sample array */
|
||||
@ -439,7 +439,7 @@ alloc_sarray (j_common_ptr cinfo, int pool_id,
|
||||
* This is essentially the same as the code for sample arrays, above.
|
||||
*/
|
||||
|
||||
METHODDEF JBLOCKARRAY
|
||||
METHODDEF(JBLOCKARRAY)
|
||||
alloc_barray (j_common_ptr cinfo, int pool_id,
|
||||
JDIMENSION blocksperrow, JDIMENSION numrows)
|
||||
/* Allocate a 2-D coefficient-block array */
|
||||
@ -519,7 +519,7 @@ alloc_barray (j_common_ptr cinfo, int pool_id,
|
||||
*/
|
||||
|
||||
|
||||
METHODDEF jvirt_sarray_ptr
|
||||
METHODDEF(jvirt_sarray_ptr)
|
||||
request_virt_sarray (j_common_ptr cinfo, int pool_id, boolean pre_zero,
|
||||
JDIMENSION samplesperrow, JDIMENSION numrows,
|
||||
JDIMENSION maxaccess)
|
||||
@ -549,7 +549,7 @@ request_virt_sarray (j_common_ptr cinfo, int pool_id, boolean pre_zero,
|
||||
}
|
||||
|
||||
|
||||
METHODDEF jvirt_barray_ptr
|
||||
METHODDEF(jvirt_barray_ptr)
|
||||
request_virt_barray (j_common_ptr cinfo, int pool_id, boolean pre_zero,
|
||||
JDIMENSION blocksperrow, JDIMENSION numrows,
|
||||
JDIMENSION maxaccess)
|
||||
@ -579,7 +579,7 @@ request_virt_barray (j_common_ptr cinfo, int pool_id, boolean pre_zero,
|
||||
}
|
||||
|
||||
|
||||
METHODDEF void
|
||||
METHODDEF(void)
|
||||
realize_virt_arrays (j_common_ptr cinfo)
|
||||
/* Allocate the in-memory buffers for any unrealized virtual arrays */
|
||||
{
|
||||
@ -686,7 +686,7 @@ realize_virt_arrays (j_common_ptr cinfo)
|
||||
}
|
||||
|
||||
|
||||
LOCAL void
|
||||
LOCAL(void)
|
||||
do_sarray_io (j_common_ptr cinfo, jvirt_sarray_ptr ptr, boolean writing)
|
||||
/* Do backing store read or write of a virtual sample array */
|
||||
{
|
||||
@ -719,7 +719,7 @@ do_sarray_io (j_common_ptr cinfo, jvirt_sarray_ptr ptr, boolean writing)
|
||||
}
|
||||
|
||||
|
||||
LOCAL void
|
||||
LOCAL(void)
|
||||
do_barray_io (j_common_ptr cinfo, jvirt_barray_ptr ptr, boolean writing)
|
||||
/* Do backing store read or write of a virtual coefficient-block array */
|
||||
{
|
||||
@ -752,7 +752,7 @@ do_barray_io (j_common_ptr cinfo, jvirt_barray_ptr ptr, boolean writing)
|
||||
}
|
||||
|
||||
|
||||
METHODDEF JSAMPARRAY
|
||||
METHODDEF(JSAMPARRAY)
|
||||
access_virt_sarray (j_common_ptr cinfo, jvirt_sarray_ptr ptr,
|
||||
JDIMENSION start_row, JDIMENSION num_rows,
|
||||
boolean writable)
|
||||
@ -837,7 +837,7 @@ access_virt_sarray (j_common_ptr cinfo, jvirt_sarray_ptr ptr,
|
||||
}
|
||||
|
||||
|
||||
METHODDEF JBLOCKARRAY
|
||||
METHODDEF(JBLOCKARRAY)
|
||||
access_virt_barray (j_common_ptr cinfo, jvirt_barray_ptr ptr,
|
||||
JDIMENSION start_row, JDIMENSION num_rows,
|
||||
boolean writable)
|
||||
@ -926,7 +926,7 @@ access_virt_barray (j_common_ptr cinfo, jvirt_barray_ptr ptr,
|
||||
* Release all objects belonging to a specified pool.
|
||||
*/
|
||||
|
||||
METHODDEF void
|
||||
METHODDEF(void)
|
||||
free_pool (j_common_ptr cinfo, int pool_id)
|
||||
{
|
||||
my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
|
||||
@ -998,7 +998,7 @@ free_pool (j_common_ptr cinfo, int pool_id)
|
||||
* Note that this cannot be called unless cinfo->mem is non-NULL.
|
||||
*/
|
||||
|
||||
METHODDEF void
|
||||
METHODDEF(void)
|
||||
self_destruct (j_common_ptr cinfo)
|
||||
{
|
||||
int pool;
|
||||
@ -1024,7 +1024,7 @@ self_destruct (j_common_ptr cinfo)
|
||||
* When this is called, only the error manager pointer is valid in cinfo!
|
||||
*/
|
||||
|
||||
GLOBAL void
|
||||
GLOBAL(void)
|
||||
jinit_memory_mgr (j_common_ptr cinfo)
|
||||
{
|
||||
my_mem_ptr mem;
|
||||
@ -1076,6 +1076,9 @@ jinit_memory_mgr (j_common_ptr cinfo)
|
||||
mem->pub.free_pool = free_pool;
|
||||
mem->pub.self_destruct = self_destruct;
|
||||
|
||||
/* Make MAX_ALLOC_CHUNK accessible to other modules */
|
||||
mem->pub.max_alloc_chunk = MAX_ALLOC_CHUNK;
|
||||
|
||||
/* Initialize working state */
|
||||
mem->pub.max_memory_to_use = max_to_use;
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* jmemname.c
|
||||
*
|
||||
* Copyright (C) 1992-1994, Thomas G. Lane.
|
||||
* Copyright (C) 1992-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.
|
||||
*
|
||||
@ -30,9 +30,14 @@ extern void free JPP((void *ptr));
|
||||
#define READ_BINARY "r"
|
||||
#define RW_BINARY "w+"
|
||||
#else
|
||||
#ifdef VMS /* VMS is very nonstandard */
|
||||
#define READ_BINARY "rb", "ctx=stm"
|
||||
#define RW_BINARY "w+b", "ctx=stm"
|
||||
#else /* standard ANSI-compliant case */
|
||||
#define READ_BINARY "rb"
|
||||
#define RW_BINARY "w+b"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
@ -86,7 +91,7 @@ extern int errno;
|
||||
#endif
|
||||
|
||||
|
||||
LOCAL void
|
||||
LOCAL(void)
|
||||
select_file_name (char * fname)
|
||||
{
|
||||
FILE * tfile;
|
||||
@ -117,7 +122,7 @@ select_file_name (char * fname)
|
||||
#define TEMP_FILE_NAME "%sJPG%dXXXXXX"
|
||||
#endif
|
||||
|
||||
LOCAL void
|
||||
LOCAL(void)
|
||||
select_file_name (char * fname)
|
||||
{
|
||||
next_file_num++; /* advance counter */
|
||||
@ -134,13 +139,13 @@ select_file_name (char * fname)
|
||||
* routines malloc() and free().
|
||||
*/
|
||||
|
||||
GLOBAL void *
|
||||
GLOBAL(void *)
|
||||
jpeg_get_small (j_common_ptr cinfo, size_t sizeofobject)
|
||||
{
|
||||
return (void *) malloc(sizeofobject);
|
||||
}
|
||||
|
||||
GLOBAL void
|
||||
GLOBAL(void)
|
||||
jpeg_free_small (j_common_ptr cinfo, void * object, size_t sizeofobject)
|
||||
{
|
||||
free(object);
|
||||
@ -154,13 +159,13 @@ jpeg_free_small (j_common_ptr cinfo, void * object, size_t sizeofobject)
|
||||
* you probably won't be able to process useful-size images in only 64KB.
|
||||
*/
|
||||
|
||||
GLOBAL void FAR *
|
||||
GLOBAL(void FAR *)
|
||||
jpeg_get_large (j_common_ptr cinfo, size_t sizeofobject)
|
||||
{
|
||||
return (void FAR *) malloc(sizeofobject);
|
||||
}
|
||||
|
||||
GLOBAL void
|
||||
GLOBAL(void)
|
||||
jpeg_free_large (j_common_ptr cinfo, void FAR * object, size_t sizeofobject)
|
||||
{
|
||||
free(object);
|
||||
@ -179,7 +184,7 @@ jpeg_free_large (j_common_ptr cinfo, void FAR * object, size_t sizeofobject)
|
||||
#define DEFAULT_MAX_MEM 1000000L /* default: one megabyte */
|
||||
#endif
|
||||
|
||||
GLOBAL long
|
||||
GLOBAL(long)
|
||||
jpeg_mem_available (j_common_ptr cinfo, long min_bytes_needed,
|
||||
long max_bytes_needed, long already_allocated)
|
||||
{
|
||||
@ -195,7 +200,7 @@ jpeg_mem_available (j_common_ptr cinfo, long min_bytes_needed,
|
||||
*/
|
||||
|
||||
|
||||
METHODDEF void
|
||||
METHODDEF(void)
|
||||
read_backing_store (j_common_ptr cinfo, backing_store_ptr info,
|
||||
void FAR * buffer_address,
|
||||
long file_offset, long byte_count)
|
||||
@ -208,7 +213,7 @@ read_backing_store (j_common_ptr cinfo, backing_store_ptr info,
|
||||
}
|
||||
|
||||
|
||||
METHODDEF void
|
||||
METHODDEF(void)
|
||||
write_backing_store (j_common_ptr cinfo, backing_store_ptr info,
|
||||
void FAR * buffer_address,
|
||||
long file_offset, long byte_count)
|
||||
@ -221,7 +226,7 @@ write_backing_store (j_common_ptr cinfo, backing_store_ptr info,
|
||||
}
|
||||
|
||||
|
||||
METHODDEF void
|
||||
METHODDEF(void)
|
||||
close_backing_store (j_common_ptr cinfo, backing_store_ptr info)
|
||||
{
|
||||
fclose(info->temp_file); /* close the file */
|
||||
@ -238,7 +243,7 @@ close_backing_store (j_common_ptr cinfo, backing_store_ptr info)
|
||||
* Initial opening of a backing-store object.
|
||||
*/
|
||||
|
||||
GLOBAL void
|
||||
GLOBAL(void)
|
||||
jpeg_open_backing_store (j_common_ptr cinfo, backing_store_ptr info,
|
||||
long total_bytes_needed)
|
||||
{
|
||||
@ -257,14 +262,14 @@ jpeg_open_backing_store (j_common_ptr cinfo, backing_store_ptr info,
|
||||
* cleanup required.
|
||||
*/
|
||||
|
||||
GLOBAL long
|
||||
GLOBAL(long)
|
||||
jpeg_mem_init (j_common_ptr cinfo)
|
||||
{
|
||||
next_file_num = 0; /* initialize temp file name generator */
|
||||
return DEFAULT_MAX_MEM; /* default for max_memory_to_use */
|
||||
}
|
||||
|
||||
GLOBAL void
|
||||
GLOBAL(void)
|
||||
jpeg_mem_term (j_common_ptr cinfo)
|
||||
{
|
||||
/* no work */
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* jmemnobs.c
|
||||
*
|
||||
* Copyright (C) 1992-1994, Thomas G. Lane.
|
||||
* 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.
|
||||
*
|
||||
@ -31,13 +31,13 @@ extern void free JPP((void *ptr));
|
||||
* routines malloc() and free().
|
||||
*/
|
||||
|
||||
GLOBAL void *
|
||||
GLOBAL(void *)
|
||||
jpeg_get_small (j_common_ptr cinfo, size_t sizeofobject)
|
||||
{
|
||||
return (void *) malloc(sizeofobject);
|
||||
}
|
||||
|
||||
GLOBAL void
|
||||
GLOBAL(void)
|
||||
jpeg_free_small (j_common_ptr cinfo, void * object, size_t sizeofobject)
|
||||
{
|
||||
free(object);
|
||||
@ -51,13 +51,13 @@ jpeg_free_small (j_common_ptr cinfo, void * object, size_t sizeofobject)
|
||||
* you probably won't be able to process useful-size images in only 64KB.
|
||||
*/
|
||||
|
||||
GLOBAL void FAR *
|
||||
GLOBAL(void FAR *)
|
||||
jpeg_get_large (j_common_ptr cinfo, size_t sizeofobject)
|
||||
{
|
||||
return (void FAR *) malloc(sizeofobject);
|
||||
}
|
||||
|
||||
GLOBAL void
|
||||
GLOBAL(void)
|
||||
jpeg_free_large (j_common_ptr cinfo, void FAR * object, size_t sizeofobject)
|
||||
{
|
||||
free(object);
|
||||
@ -69,7 +69,7 @@ jpeg_free_large (j_common_ptr cinfo, void FAR * object, size_t sizeofobject)
|
||||
* Here we always say, "we got all you want bud!"
|
||||
*/
|
||||
|
||||
GLOBAL long
|
||||
GLOBAL(long)
|
||||
jpeg_mem_available (j_common_ptr cinfo, long min_bytes_needed,
|
||||
long max_bytes_needed, long already_allocated)
|
||||
{
|
||||
@ -83,7 +83,7 @@ jpeg_mem_available (j_common_ptr cinfo, long min_bytes_needed,
|
||||
* this should never be called and we can just error out.
|
||||
*/
|
||||
|
||||
GLOBAL void
|
||||
GLOBAL(void)
|
||||
jpeg_open_backing_store (j_common_ptr cinfo, backing_store_ptr info,
|
||||
long total_bytes_needed)
|
||||
{
|
||||
@ -96,13 +96,13 @@ jpeg_open_backing_store (j_common_ptr cinfo, backing_store_ptr info,
|
||||
* cleanup required. Here, there isn't any.
|
||||
*/
|
||||
|
||||
GLOBAL long
|
||||
GLOBAL(long)
|
||||
jpeg_mem_init (j_common_ptr cinfo)
|
||||
{
|
||||
return 0; /* just set max_memory_to_use to 0 */
|
||||
}
|
||||
|
||||
GLOBAL void
|
||||
GLOBAL(void)
|
||||
jpeg_mem_term (j_common_ptr cinfo)
|
||||
{
|
||||
/* no work */
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* jmemsys.h
|
||||
*
|
||||
* Copyright (C) 1992-1994, Thomas G. Lane.
|
||||
* Copyright (C) 1992-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.
|
||||
*
|
||||
@ -14,7 +14,8 @@
|
||||
* in the IJG distribution. You may need to modify it if you write a
|
||||
* custom memory manager. If system-dependent changes are needed in
|
||||
* this file, the best method is to #ifdef them based on a configuration
|
||||
* symbol supplied in jconfig.h, as we have done with USE_MSDOS_MEMMGR.
|
||||
* symbol supplied in jconfig.h, as we have done with USE_MSDOS_MEMMGR
|
||||
* and USE_MAC_MEMMGR.
|
||||
*/
|
||||
|
||||
|
||||
@ -43,9 +44,9 @@
|
||||
* On an 80x86 machine using small-data memory model, these manage near heap.
|
||||
*/
|
||||
|
||||
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));
|
||||
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));
|
||||
|
||||
/*
|
||||
* These two functions are used to allocate and release large chunks of
|
||||
@ -56,9 +57,10 @@ EXTERN void jpeg_free_small JPP((j_common_ptr cinfo, void * object,
|
||||
* in case a different allocation strategy is desirable for large chunks.
|
||||
*/
|
||||
|
||||
EXTERN void FAR * jpeg_get_large JPP((j_common_ptr cinfo,size_t sizeofobject));
|
||||
EXTERN void jpeg_free_large JPP((j_common_ptr cinfo, void FAR * object,
|
||||
size_t sizeofobject));
|
||||
EXTERN(void FAR *) jpeg_get_large JPP((j_common_ptr cinfo,
|
||||
size_t sizeofobject));
|
||||
EXTERN(void) jpeg_free_large JPP((j_common_ptr cinfo, void FAR * object,
|
||||
size_t sizeofobject));
|
||||
|
||||
/*
|
||||
* The macro MAX_ALLOC_CHUNK designates the maximum number of bytes that may
|
||||
@ -98,10 +100,10 @@ EXTERN void jpeg_free_large JPP((j_common_ptr cinfo, void FAR * object,
|
||||
* Conversely, zero may be returned to always use the minimum amount of memory.
|
||||
*/
|
||||
|
||||
EXTERN long jpeg_mem_available JPP((j_common_ptr cinfo,
|
||||
long min_bytes_needed,
|
||||
long max_bytes_needed,
|
||||
long already_allocated));
|
||||
EXTERN(long) jpeg_mem_available JPP((j_common_ptr cinfo,
|
||||
long min_bytes_needed,
|
||||
long max_bytes_needed,
|
||||
long already_allocated));
|
||||
|
||||
|
||||
/*
|
||||
@ -113,6 +115,7 @@ EXTERN long jpeg_mem_available JPP((j_common_ptr cinfo,
|
||||
|
||||
#define TEMP_NAME_LENGTH 64 /* max length of a temporary file's name */
|
||||
|
||||
|
||||
#ifdef USE_MSDOS_MEMMGR /* DOS-specific junk */
|
||||
|
||||
typedef unsigned short XMSH; /* type of extended-memory handles */
|
||||
@ -126,6 +129,11 @@ typedef union {
|
||||
|
||||
#endif /* USE_MSDOS_MEMMGR */
|
||||
|
||||
#ifdef USE_MAC_MEMMGR /* Mac-specific junk */
|
||||
#include <Files.h>
|
||||
#endif /* USE_MAC_MEMMGR */
|
||||
|
||||
|
||||
typedef struct backing_store_struct * backing_store_ptr;
|
||||
|
||||
typedef struct backing_store_struct {
|
||||
@ -146,13 +154,21 @@ typedef struct backing_store_struct {
|
||||
/* For the MS-DOS manager (jmemdos.c), we need: */
|
||||
handle_union handle; /* reference to backing-store storage object */
|
||||
char temp_name[TEMP_NAME_LENGTH]; /* name if it's a file */
|
||||
#else
|
||||
#ifdef USE_MAC_MEMMGR
|
||||
/* For the Mac manager (jmemmac.c), we need: */
|
||||
short temp_file; /* file reference number to temp file */
|
||||
FSSpec tempSpec; /* the FSSpec for the temp file */
|
||||
char temp_name[TEMP_NAME_LENGTH]; /* name if it's a file */
|
||||
#else
|
||||
/* For a typical implementation with temp files, we need: */
|
||||
FILE * temp_file; /* stdio reference to temp file */
|
||||
char temp_name[TEMP_NAME_LENGTH]; /* name of temp file */
|
||||
#endif
|
||||
#endif
|
||||
} backing_store_info;
|
||||
|
||||
|
||||
/*
|
||||
* Initial opening of a backing-store object. This must fill in the
|
||||
* read/write/close pointers in the object. The read/write routines
|
||||
@ -161,9 +177,9 @@ typedef struct backing_store_struct {
|
||||
* just take an error exit.)
|
||||
*/
|
||||
|
||||
EXTERN void jpeg_open_backing_store JPP((j_common_ptr cinfo,
|
||||
backing_store_ptr info,
|
||||
long total_bytes_needed));
|
||||
EXTERN(void) jpeg_open_backing_store JPP((j_common_ptr cinfo,
|
||||
backing_store_ptr info,
|
||||
long total_bytes_needed));
|
||||
|
||||
|
||||
/*
|
||||
@ -178,5 +194,5 @@ EXTERN void jpeg_open_backing_store JPP((j_common_ptr cinfo,
|
||||
* all opened backing-store objects have been closed.
|
||||
*/
|
||||
|
||||
EXTERN long jpeg_mem_init JPP((j_common_ptr cinfo));
|
||||
EXTERN void jpeg_mem_term JPP((j_common_ptr cinfo));
|
||||
EXTERN(long) jpeg_mem_init JPP((j_common_ptr cinfo));
|
||||
EXTERN(void) jpeg_mem_term JPP((j_common_ptr cinfo));
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* jmorecfg.h
|
||||
*
|
||||
* Copyright (C) 1991-1995, Thomas G. Lane.
|
||||
* 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.
|
||||
*
|
||||
@ -9,8 +9,14 @@
|
||||
* JPEG software for special applications or support machine-dependent
|
||||
* optimizations. Most users will not need to touch this file.
|
||||
*/
|
||||
#ifndef __JMORECFG_H__
|
||||
#define __JMORECFG_H__
|
||||
|
||||
/*
|
||||
* This file has been modified for the Mozilla/Netscape environment.
|
||||
* Modifications are distributed under the Netscape Public License and are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* Define BITS_IN_JSAMPLE as either
|
||||
@ -174,21 +180,44 @@ typedef unsigned int JDIMENSION;
|
||||
#define JPEG_MAX_DIMENSION 65500L /* a tad under 64K to prevent overflows */
|
||||
|
||||
|
||||
/* These defines are used in all function definitions and extern declarations.
|
||||
* You could modify them if you need to change function linkage conventions.
|
||||
/* These macros are used in all function definitions and extern declarations.
|
||||
* You could modify them if you need to change function linkage conventions;
|
||||
* in particular, you'll need to do that to make the library a Windows DLL.
|
||||
* Another application is to make all functions global for use with debuggers
|
||||
* or code profilers that require it.
|
||||
*/
|
||||
|
||||
#define METHODDEF static /* a function called through method pointers */
|
||||
#define LOCAL static /* a function used only in its module */
|
||||
#define GLOBAL /* a function referenced thru EXTERNs */
|
||||
/* Mozilla mod: make external functions be DLL-able via JRI_PUBLIC_API(),
|
||||
* and supply extern "C" for C++ users of the C-compiled IJG library.
|
||||
*/
|
||||
|
||||
/* a function called through method pointers: */
|
||||
#define METHODDEF(type) static type
|
||||
/* a function used only in its module: */
|
||||
#define LOCAL(type) static type
|
||||
/* a function referenced thru EXTERNs: */
|
||||
#define GLOBAL(type) JRI_PUBLIC_API(type)
|
||||
/* a reference to a GLOBAL function: */
|
||||
#ifdef __cplusplus
|
||||
#define EXTERN extern "C" /* a reference to a GLOBAL function */
|
||||
#define EXTERN(type) extern "C" JRI_PUBLIC_API(type)
|
||||
#else
|
||||
#define EXTERN extern /* a reference to a GLOBAL function */
|
||||
#define EXTERN(type) extern JRI_PUBLIC_API(type)
|
||||
#endif
|
||||
|
||||
|
||||
/* This macro is used to declare a "method", that is, a function pointer.
|
||||
* We want to supply prototype parameters if the compiler can cope.
|
||||
* Note that the arglist parameter must be parenthesized!
|
||||
* Again, you can customize this if you need special linkage keywords.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_PROTOTYPES
|
||||
#define JMETHOD(type,methodname,arglist) type (*methodname) arglist
|
||||
#else
|
||||
#define JMETHOD(type,methodname,arglist) type (*methodname) ()
|
||||
#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
|
||||
@ -203,6 +232,7 @@ typedef unsigned int JDIMENSION;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* On a few systems, type boolean and/or its values FALSE, TRUE may appear
|
||||
* in standard header files. Or you may have conflicts with application-
|
||||
@ -210,8 +240,13 @@ typedef unsigned int JDIMENSION;
|
||||
* Defining HAVE_BOOLEAN before including jpeglib.h should make it work.
|
||||
*/
|
||||
|
||||
/* Mozilla mod: IJG distribution makes boolean = int, but on Windows
|
||||
* it's far safer to define boolean = unsigned char. Easier to switch
|
||||
* than fight.
|
||||
*/
|
||||
|
||||
#ifndef HAVE_BOOLEAN
|
||||
typedef int boolean;
|
||||
typedef unsigned char boolean;
|
||||
#endif
|
||||
#ifndef FALSE /* in case these macros already exist */
|
||||
#define FALSE 0 /* values of boolean */
|
||||
@ -243,13 +278,22 @@ typedef int boolean;
|
||||
* (You may HAVE to do that if your compiler doesn't like null source files.)
|
||||
*/
|
||||
|
||||
/*
|
||||
* Mozilla mods here: undef some features not actually used by the browser.
|
||||
* This reduces object code size and more importantly allows us to compile
|
||||
* even with broken compilers that crash when fed certain modules of the
|
||||
* IJG sources. Currently we undef:
|
||||
* DCT_FLOAT_SUPPORTED INPUT_SMOOTHING_SUPPORTED IDCT_SCALING_SUPPORTED
|
||||
* QUANT_1PASS_SUPPORTED QUANT_2PASS_SUPPORTED
|
||||
*/
|
||||
|
||||
/* 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 */
|
||||
#define DCT_IFAST_SUPPORTED /* faster, less accurate integer method */
|
||||
#define DCT_FLOAT_SUPPORTED /* floating-point: accurate, fast on fast HW */
|
||||
#undef DCT_FLOAT_SUPPORTED /* floating-point: accurate, fast on fast HW */
|
||||
|
||||
/* Encoder capability options: */
|
||||
|
||||
@ -265,19 +309,20 @@ typedef int boolean;
|
||||
* The exact same statements apply for progressive JPEG: the default tables
|
||||
* don't work for progressive mode. (This may get fixed, however.)
|
||||
*/
|
||||
#define INPUT_SMOOTHING_SUPPORTED /* Input image smoothing option? */
|
||||
#undef INPUT_SMOOTHING_SUPPORTED /* Input image smoothing option? */
|
||||
|
||||
/* Decoder capability options: */
|
||||
|
||||
#undef 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 SAVE_MARKERS_SUPPORTED /* jpeg_save_markers() needed? */
|
||||
#define BLOCK_SMOOTHING_SUPPORTED /* Block smoothing? (Progressive only) */
|
||||
#undef IDCT_SCALING_SUPPORTED /* Output rescaling via IDCT? */
|
||||
#undef 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? */
|
||||
#define QUANT_2PASS_SUPPORTED /* 2-pass color quantization? */
|
||||
#undef QUANT_1PASS_SUPPORTED /* 1-pass color quantization? */
|
||||
#undef QUANT_2PASS_SUPPORTED /* 2-pass color quantization? */
|
||||
|
||||
/* more capability options later, no doubt */
|
||||
|
||||
@ -310,6 +355,8 @@ typedef int boolean;
|
||||
* as the inline keyword; otherwise define it as empty.
|
||||
*/
|
||||
|
||||
/* Mozilla mods here: add more ways of defining INLINE */
|
||||
|
||||
#ifndef INLINE
|
||||
#ifdef __GNUC__ /* for instance, GNU C knows about inline */
|
||||
#define INLINE __inline__
|
||||
@ -318,16 +365,20 @@ typedef int boolean;
|
||||
#define INLINE _Inline
|
||||
#endif
|
||||
#ifndef INLINE
|
||||
#ifdef __cplusplus
|
||||
#define INLINE inline /* a C++ compiler should have it too */
|
||||
#else
|
||||
#define INLINE /* default is to define it as empty */
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
/* On some machines (notably 68000 series) "int" is 32 bits, but multiplying
|
||||
* two 16-bit shorts is faster than multiplying two ints. Define MULTIPLIER
|
||||
* as short on such a machine. MULTIPLIER must be at least 16 bits wide.
|
||||
*/
|
||||
/* Netscape modification: MULTIPLIER should be explicitly declared int16 */
|
||||
|
||||
#ifndef MULTIPLIER
|
||||
#define MULTIPLIER int16 /* type for fastest integer multiply */
|
||||
#endif
|
||||
@ -350,5 +401,3 @@ typedef int boolean;
|
||||
#endif
|
||||
|
||||
#endif /* JPEG_INTERNAL_OPTIONS */
|
||||
|
||||
#endif /* __JMORECFG_H__ */
|
||||
|
102
jpeg/jpegint.h
102
jpeg/jpegint.h
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* jpegint.h
|
||||
*
|
||||
* Copyright (C) 1991-1995, Thomas G. Lane.
|
||||
* 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.
|
||||
*
|
||||
@ -118,15 +118,16 @@ struct jpeg_entropy_encoder {
|
||||
|
||||
/* Marker writing */
|
||||
struct jpeg_marker_writer {
|
||||
/* write_any_marker is exported for use by applications */
|
||||
/* Probably only COM and APPn markers should be written */
|
||||
JMETHOD(void, write_any_marker, (j_compress_ptr cinfo, int marker,
|
||||
const JOCTET *dataptr, unsigned int datalen));
|
||||
JMETHOD(void, write_file_header, (j_compress_ptr cinfo));
|
||||
JMETHOD(void, write_frame_header, (j_compress_ptr cinfo));
|
||||
JMETHOD(void, write_scan_header, (j_compress_ptr cinfo));
|
||||
JMETHOD(void, write_file_trailer, (j_compress_ptr cinfo));
|
||||
JMETHOD(void, write_tables_only, (j_compress_ptr cinfo));
|
||||
/* 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));
|
||||
JMETHOD(void, write_marker_byte, (j_compress_ptr cinfo, int val));
|
||||
};
|
||||
|
||||
|
||||
@ -194,9 +195,6 @@ struct jpeg_marker_reader {
|
||||
JMETHOD(int, read_markers, (j_decompress_ptr cinfo));
|
||||
/* Read a restart marker --- exported for use by entropy decoder only */
|
||||
jpeg_marker_parser_method read_restart_marker;
|
||||
/* Application-overridable marker processing methods */
|
||||
jpeg_marker_parser_method process_COM;
|
||||
jpeg_marker_parser_method process_APPn[16];
|
||||
|
||||
/* State of marker reader --- nominally internal, but applications
|
||||
* supplying COM or APPn handlers might like to know the state.
|
||||
@ -212,6 +210,10 @@ 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 */
|
||||
};
|
||||
|
||||
/* Inverse DCT (also performs dequantization) */
|
||||
@ -329,53 +331,55 @@ struct jpeg_color_quantizer {
|
||||
|
||||
|
||||
/* Compression module initialization routines */
|
||||
EXTERN void jinit_compress_master JPP((j_compress_ptr cinfo));
|
||||
EXTERN void jinit_c_master_control JPP((j_compress_ptr cinfo,
|
||||
boolean transcode_only));
|
||||
EXTERN void jinit_c_main_controller JPP((j_compress_ptr cinfo,
|
||||
boolean need_full_buffer));
|
||||
EXTERN void jinit_c_prep_controller JPP((j_compress_ptr cinfo,
|
||||
boolean need_full_buffer));
|
||||
EXTERN void jinit_c_coef_controller JPP((j_compress_ptr cinfo,
|
||||
boolean need_full_buffer));
|
||||
EXTERN void jinit_color_converter JPP((j_compress_ptr cinfo));
|
||||
EXTERN void jinit_downsampler JPP((j_compress_ptr cinfo));
|
||||
EXTERN void jinit_forward_dct JPP((j_compress_ptr cinfo));
|
||||
EXTERN void jinit_huff_encoder JPP((j_compress_ptr cinfo));
|
||||
EXTERN void jinit_phuff_encoder JPP((j_compress_ptr cinfo));
|
||||
EXTERN void jinit_marker_writer JPP((j_compress_ptr cinfo));
|
||||
EXTERN(void) jinit_compress_master JPP((j_compress_ptr cinfo));
|
||||
EXTERN(void) jinit_c_master_control JPP((j_compress_ptr cinfo,
|
||||
boolean transcode_only));
|
||||
EXTERN(void) jinit_c_main_controller JPP((j_compress_ptr cinfo,
|
||||
boolean need_full_buffer));
|
||||
EXTERN(void) jinit_c_prep_controller JPP((j_compress_ptr cinfo,
|
||||
boolean need_full_buffer));
|
||||
EXTERN(void) jinit_c_coef_controller JPP((j_compress_ptr cinfo,
|
||||
boolean need_full_buffer));
|
||||
EXTERN(void) jinit_color_converter JPP((j_compress_ptr cinfo));
|
||||
EXTERN(void) jinit_downsampler JPP((j_compress_ptr cinfo));
|
||||
EXTERN(void) jinit_forward_dct JPP((j_compress_ptr cinfo));
|
||||
EXTERN(void) jinit_huff_encoder JPP((j_compress_ptr cinfo));
|
||||
EXTERN(void) jinit_phuff_encoder JPP((j_compress_ptr cinfo));
|
||||
EXTERN(void) jinit_marker_writer JPP((j_compress_ptr cinfo));
|
||||
/* Decompression module initialization routines */
|
||||
EXTERN void jinit_master_decompress JPP((j_decompress_ptr cinfo));
|
||||
EXTERN void jinit_d_main_controller JPP((j_decompress_ptr cinfo,
|
||||
boolean need_full_buffer));
|
||||
EXTERN void jinit_d_coef_controller JPP((j_decompress_ptr cinfo,
|
||||
boolean need_full_buffer));
|
||||
EXTERN void jinit_d_post_controller JPP((j_decompress_ptr cinfo,
|
||||
boolean need_full_buffer));
|
||||
EXTERN void jinit_input_controller JPP((j_decompress_ptr cinfo));
|
||||
EXTERN void jinit_marker_reader JPP((j_decompress_ptr cinfo));
|
||||
EXTERN void jinit_huff_decoder JPP((j_decompress_ptr cinfo));
|
||||
EXTERN void jinit_phuff_decoder JPP((j_decompress_ptr cinfo));
|
||||
EXTERN void jinit_inverse_dct JPP((j_decompress_ptr cinfo));
|
||||
EXTERN void jinit_upsampler JPP((j_decompress_ptr cinfo));
|
||||
EXTERN void jinit_color_deconverter JPP((j_decompress_ptr cinfo));
|
||||
EXTERN void jinit_1pass_quantizer JPP((j_decompress_ptr cinfo));
|
||||
EXTERN void jinit_2pass_quantizer JPP((j_decompress_ptr cinfo));
|
||||
EXTERN void jinit_merged_upsampler JPP((j_decompress_ptr cinfo));
|
||||
EXTERN(void) jinit_master_decompress JPP((j_decompress_ptr cinfo));
|
||||
EXTERN(void) jinit_d_main_controller JPP((j_decompress_ptr cinfo,
|
||||
boolean need_full_buffer));
|
||||
EXTERN(void) jinit_d_coef_controller JPP((j_decompress_ptr cinfo,
|
||||
boolean need_full_buffer));
|
||||
EXTERN(void) jinit_d_post_controller JPP((j_decompress_ptr cinfo,
|
||||
boolean need_full_buffer));
|
||||
EXTERN(void) jinit_input_controller JPP((j_decompress_ptr cinfo));
|
||||
EXTERN(void) jinit_marker_reader JPP((j_decompress_ptr cinfo));
|
||||
EXTERN(void) jinit_huff_decoder JPP((j_decompress_ptr cinfo));
|
||||
EXTERN(void) jinit_phuff_decoder JPP((j_decompress_ptr cinfo));
|
||||
EXTERN(void) jinit_inverse_dct JPP((j_decompress_ptr cinfo));
|
||||
EXTERN(void) jinit_upsampler JPP((j_decompress_ptr cinfo));
|
||||
EXTERN(void) jinit_color_deconverter JPP((j_decompress_ptr cinfo));
|
||||
EXTERN(void) jinit_1pass_quantizer JPP((j_decompress_ptr cinfo));
|
||||
EXTERN(void) jinit_2pass_quantizer JPP((j_decompress_ptr cinfo));
|
||||
EXTERN(void) jinit_merged_upsampler JPP((j_decompress_ptr cinfo));
|
||||
/* Memory manager initialization */
|
||||
EXTERN void jinit_memory_mgr JPP((j_common_ptr cinfo));
|
||||
EXTERN(void) jinit_memory_mgr JPP((j_common_ptr cinfo));
|
||||
|
||||
/* Utility routines in jutils.c */
|
||||
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));
|
||||
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));
|
||||
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));
|
||||
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));
|
||||
/* 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 */
|
||||
|
||||
/* Suppress undefined-structure complaints if necessary. */
|
||||
|
301
jpeg/jpeglib.h
301
jpeg/jpeglib.h
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* jpeglib.h
|
||||
*
|
||||
* Copyright (C) 1991-1995, Thomas G. Lane.
|
||||
* Copyright (C) 1991-1998, Thomas G. Lane.
|
||||
* This file is part of the Independent JPEG Group's software.
|
||||
* For conditions of distribution and use, see the accompanying README file.
|
||||
*
|
||||
@ -26,38 +26,17 @@
|
||||
* manual configuration options that most people need not worry about.
|
||||
*/
|
||||
|
||||
#ifndef _IMAGE_CONVERT
|
||||
#ifdef __MWERKS__
|
||||
#include "jinclude.h"
|
||||
#endif
|
||||
#ifndef JCONFIG_INCLUDED /* in case jinclude.h already did */
|
||||
#include "jconfig.h" /* widely used configuration options */
|
||||
#endif
|
||||
#include "jmorecfg.h" /* seldom changed options */
|
||||
#endif /*_IMAGE_CONVERT*/
|
||||
|
||||
#ifdef _IMAGE_CONVERT
|
||||
#ifndef JCONFIG_INCLUDED /* in case jinclude.h already did */
|
||||
#ifdef __MWERKS__
|
||||
#include "jcongig-mac-cw.h"
|
||||
#elif defined _WINDOWS
|
||||
#include "jwinfig.h"
|
||||
#elif defined XP_OS2
|
||||
#include "jos2fig.h"
|
||||
#else
|
||||
#include "jconfig.h" /* widely used configuration options */
|
||||
#endif
|
||||
#endif /*JCONFIG_INCLUDED*/
|
||||
#endif /*_IMAGE_CONVERT*/
|
||||
|
||||
#include "jconfig.h" /* widely used configuration options */
|
||||
#endif
|
||||
#include "jmorecfg.h" /* seldom changed options */
|
||||
#include "jri.h"
|
||||
|
||||
|
||||
/* Version ID for the JPEG library.
|
||||
* Might be useful for tests like "#if JPEG_LIB_VERSION >= 60".
|
||||
*/
|
||||
|
||||
#define JPEG_LIB_VERSION 60 /* Version 6 */
|
||||
#define JPEG_LIB_VERSION 62 /* Version 6b */
|
||||
|
||||
|
||||
/* Various constants determining the sizes of things.
|
||||
@ -85,18 +64,6 @@
|
||||
#endif
|
||||
|
||||
|
||||
/* This macro is used to declare a "method", that is, a function pointer.
|
||||
* We want to supply prototype parameters if the compiler can cope.
|
||||
* Note that the arglist parameter must be parenthesized!
|
||||
*/
|
||||
|
||||
#ifdef HAVE_PROTOTYPES
|
||||
#define JMETHOD(type,methodname,arglist) type (*methodname) arglist
|
||||
#else
|
||||
#define JMETHOD(type,methodname,arglist) type (*methodname) ()
|
||||
#endif
|
||||
|
||||
|
||||
/* Data structures for images (arrays of samples and of DCT coefficients).
|
||||
* On 80x86 machines, the image arrays are too big for near pointers,
|
||||
* but the pointer arrays can fit in near memory.
|
||||
@ -120,8 +87,9 @@ typedef JCOEF FAR *JCOEFPTR; /* useful in a couple of places */
|
||||
/* DCT coefficient quantization tables. */
|
||||
|
||||
typedef struct {
|
||||
/* This field directly represents the contents of a JPEG DQT marker.
|
||||
* Note: the values are always given in zigzag order.
|
||||
/* This array gives the coefficient quantizers in natural array order
|
||||
* (not the zigzag order in which they are stored in a JPEG DQT marker).
|
||||
* CAUTION: IJG versions prior to v6a kept this array in zigzag order.
|
||||
*/
|
||||
UINT16 quantval[DCTSIZE2]; /* quantization step for each coefficient */
|
||||
/* This field is used only during compression. It's initialized FALSE when
|
||||
@ -208,7 +176,7 @@ typedef struct {
|
||||
|
||||
/* Saved quantization table for component; NULL if none yet saved.
|
||||
* See jdinput.c comments about the need for this information.
|
||||
* This field is not currently used by the compressor.
|
||||
* This field is currently used only for decompression.
|
||||
*/
|
||||
JQUANT_TBL * quant_table;
|
||||
|
||||
@ -226,6 +194,18 @@ typedef struct {
|
||||
int Ah, Al; /* progressive JPEG successive approx. parms */
|
||||
} jpeg_scan_info;
|
||||
|
||||
/* The decompressor can save APPn and COM markers in a list of these: */
|
||||
|
||||
typedef struct jpeg_marker_struct FAR * jpeg_saved_marker_ptr;
|
||||
|
||||
struct jpeg_marker_struct {
|
||||
jpeg_saved_marker_ptr next; /* next in list, or NULL */
|
||||
UINT8 marker; /* marker code: JPEG_COM, or JPEG_APP0+n */
|
||||
unsigned int original_length; /* # bytes of data in the file */
|
||||
unsigned int data_length; /* # bytes of data saved at data[] */
|
||||
JOCTET FAR * data; /* the data contained in the marker */
|
||||
/* the marker length word is not counted in data_length or original_length */
|
||||
};
|
||||
|
||||
/* Known color spaces. */
|
||||
|
||||
@ -268,42 +248,14 @@ typedef enum {
|
||||
struct jpeg_error_mgr * err; /* Error handler module */\
|
||||
struct jpeg_memory_mgr * mem; /* Memory manager module */\
|
||||
struct jpeg_progress_mgr * progress; /* Progress monitor, or NULL if none */\
|
||||
boolean is_decompressor; /* so common code can tell which is which */\
|
||||
int global_state /* for checking call sequence validity */
|
||||
void * client_data; /* Available for use by application */\
|
||||
boolean is_decompressor; /* So common code can tell which is which */\
|
||||
int global_state /* For checking call sequence validity */
|
||||
|
||||
/* Routines that are to be used by both halves of the library are declared
|
||||
* to receive a pointer to this structure. There are no actual instances of
|
||||
* jpeg_common_struct, only of jpeg_compress_struct and jpeg_decompress_struct.
|
||||
*/
|
||||
struct jpeg_memory_mgr; /* Mac change to please our compiler */
|
||||
struct jpeg_error_mgr; /* Mac change to please our compiler */
|
||||
|
||||
/* forward declaration of globally-scoped structs */
|
||||
struct jpeg_c_coef_controller;
|
||||
struct jpeg_c_main_controller;
|
||||
struct jpeg_c_prep_controller;
|
||||
struct jpeg_color_converter;
|
||||
struct jpeg_color_deconverter;
|
||||
struct jpeg_color_quantizer;
|
||||
struct jpeg_comp_master;
|
||||
struct jpeg_d_main_controller;
|
||||
struct jpeg_d_coef_controller;
|
||||
struct jpeg_d_post_controller;
|
||||
struct jpeg_decomp_master;
|
||||
struct jpeg_destination_mgr;
|
||||
struct jpeg_downsampler;
|
||||
struct jpeg_entropy_decoder;
|
||||
struct jpeg_entropy_encoder;
|
||||
struct jpeg_error_mgr;
|
||||
struct jpeg_forward_dct;
|
||||
struct jpeg_inverse_dct;
|
||||
struct jpeg_marker_reader;
|
||||
struct jpeg_marker_writer;
|
||||
struct jpeg_memory_mgr;
|
||||
struct jpeg_progress_mgr;
|
||||
struct jpeg_source_mgr;
|
||||
struct jpeg_upsampler;
|
||||
|
||||
struct jpeg_common_struct {
|
||||
jpeg_common_fields; /* Fields common to both master struct types */
|
||||
/* Additional fields follow in an actual jpeg_compress_struct or
|
||||
@ -389,6 +341,8 @@ struct jpeg_compress_struct {
|
||||
/* Parameters controlling emission of special markers. */
|
||||
|
||||
boolean write_JFIF_header; /* should a JFIF marker be written? */
|
||||
UINT8 JFIF_major_version; /* What to write for the JFIF version number */
|
||||
UINT8 JFIF_minor_version;
|
||||
/* These three values are not used by the JPEG code, merely copied */
|
||||
/* into the JFIF APP0 marker. density_unit can be 0 for unknown, */
|
||||
/* 1 for dots/inch, or 2 for dots/cm. Note that the pixel aspect */
|
||||
@ -453,6 +407,8 @@ struct jpeg_compress_struct {
|
||||
struct jpeg_downsampler * downsample;
|
||||
struct jpeg_forward_dct * fdct;
|
||||
struct jpeg_entropy_encoder * entropy;
|
||||
jpeg_scan_info * script_space; /* workspace for jpeg_simple_progression */
|
||||
int script_space_size;
|
||||
};
|
||||
|
||||
|
||||
@ -598,7 +554,9 @@ struct jpeg_decompress_struct {
|
||||
* the JPEG library.
|
||||
*/
|
||||
boolean saw_JFIF_marker; /* TRUE iff a JFIF APP0 marker was found */
|
||||
/* Data copied from JFIF marker: */
|
||||
/* Data copied from JFIF marker; only valid if saw_JFIF_marker is TRUE: */
|
||||
UINT8 JFIF_major_version; /* JFIF version number */
|
||||
UINT8 JFIF_minor_version;
|
||||
UINT8 density_unit; /* JFIF code for pixel size units */
|
||||
UINT16 X_density; /* Horizontal pixel density */
|
||||
UINT16 Y_density; /* Vertical pixel density */
|
||||
@ -607,6 +565,12 @@ struct jpeg_decompress_struct {
|
||||
|
||||
boolean CCIR601_sampling; /* TRUE=first samples are cosited */
|
||||
|
||||
/* Aside from the specific data retained from APPn markers known to the
|
||||
* library, the uninterpreted contents of any or all APPn and COM markers
|
||||
* can be saved in a list for examination by the application.
|
||||
*/
|
||||
jpeg_saved_marker_ptr marker_list; /* Head of list of saved markers */
|
||||
|
||||
/* Remaining fields are known throughout decompressor, but generally
|
||||
* should not be touched by a surrounding application.
|
||||
*/
|
||||
@ -839,6 +803,9 @@ struct jpeg_memory_mgr {
|
||||
* after creating the JPEG object.
|
||||
*/
|
||||
long max_memory_to_use;
|
||||
|
||||
/* Maximum allocation request accepted by alloc_large. */
|
||||
long max_alloc_chunk;
|
||||
};
|
||||
|
||||
|
||||
@ -869,8 +836,8 @@ typedef JMETHOD(boolean, jpeg_marker_parser_method, (j_decompress_ptr cinfo));
|
||||
|
||||
#ifdef NEED_SHORT_EXTERNAL_NAMES
|
||||
#define jpeg_std_error jStdError
|
||||
#define jpeg_create_compress jCreaCompress
|
||||
#define jpeg_create_decompress jCreaDecompress
|
||||
#define jpeg_CreateCompress jCreaCompress
|
||||
#define jpeg_CreateDecompress jCreaDecompress
|
||||
#define jpeg_destroy_compress jDestCompress
|
||||
#define jpeg_destroy_decompress jDestDecompress
|
||||
#define jpeg_stdio_dest jStdDest
|
||||
@ -891,6 +858,8 @@ typedef JMETHOD(boolean, jpeg_marker_parser_method, (j_decompress_ptr cinfo));
|
||||
#define jpeg_finish_compress jFinCompress
|
||||
#define jpeg_write_raw_data jWrtRawData
|
||||
#define jpeg_write_marker jWrtMarker
|
||||
#define jpeg_write_m_header jWrtMHeader
|
||||
#define jpeg_write_m_byte jWrtMByte
|
||||
#define jpeg_write_tables jWrtTables
|
||||
#define jpeg_read_header jReadHeader
|
||||
#define jpeg_start_decompress jStrtDecompress
|
||||
@ -904,6 +873,7 @@ typedef JMETHOD(boolean, jpeg_marker_parser_method, (j_decompress_ptr cinfo));
|
||||
#define jpeg_new_colormap jNewCMap
|
||||
#define jpeg_consume_input jConsumeInput
|
||||
#define jpeg_calc_output_dimensions jCalcDimensions
|
||||
#define jpeg_save_markers jSaveMarkers
|
||||
#define jpeg_set_marker_processor jSetMarker
|
||||
#define jpeg_read_coefficients jReadCoefs
|
||||
#define jpeg_write_coefficients jWrtCoefs
|
||||
@ -913,77 +883,90 @@ typedef JMETHOD(boolean, jpeg_marker_parser_method, (j_decompress_ptr cinfo));
|
||||
#define jpeg_abort jAbort
|
||||
#define jpeg_destroy jDestroy
|
||||
#define jpeg_resync_to_restart jResyncRestart
|
||||
#define jpeg_file_dest jFileDest
|
||||
#define jpeg_close_file jCloseFile
|
||||
#endif /* NEED_SHORT_EXTERNAL_NAMES */
|
||||
|
||||
|
||||
/* Default error-management setup */
|
||||
JRI_PUBLIC_API(struct jpeg_error_mgr *)jpeg_std_error JPP((struct jpeg_error_mgr *err));
|
||||
EXTERN(struct jpeg_error_mgr *) jpeg_std_error
|
||||
JPP((struct jpeg_error_mgr * err));
|
||||
|
||||
/* Initialization and destruction of JPEG compression objects */
|
||||
/* NB: you must set up the error-manager BEFORE calling jpeg_create_xxx */
|
||||
JRI_PUBLIC_API(void) jpeg_create_compress JPP((j_compress_ptr cinfo));
|
||||
JRI_PUBLIC_API(void) jpeg_create_decompress JPP((j_decompress_ptr cinfo));
|
||||
JRI_PUBLIC_API(void) jpeg_destroy_compress JPP((j_compress_ptr cinfo));
|
||||
JRI_PUBLIC_API(void) jpeg_destroy_decompress JPP((j_decompress_ptr cinfo));
|
||||
/* Initialization of JPEG compression objects.
|
||||
* jpeg_create_compress() and jpeg_create_decompress() are the exported
|
||||
* names that applications should call. These expand to calls on
|
||||
* jpeg_CreateCompress and jpeg_CreateDecompress with additional information
|
||||
* passed for version mismatch checking.
|
||||
* NB: you must set up the error-manager BEFORE calling jpeg_create_xxx.
|
||||
*/
|
||||
#define jpeg_create_compress(cinfo) \
|
||||
jpeg_CreateCompress((cinfo), JPEG_LIB_VERSION, \
|
||||
(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))
|
||||
EXTERN(void) jpeg_CreateCompress JPP((j_compress_ptr cinfo,
|
||||
int version, size_t structsize));
|
||||
EXTERN(void) jpeg_CreateDecompress JPP((j_decompress_ptr cinfo,
|
||||
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));
|
||||
|
||||
/* Standard data source and destination managers: stdio streams. */
|
||||
/* Caller is responsible for opening the file before and closing after. */
|
||||
JRI_PUBLIC_API(void) jpeg_stdio_dest JPP((j_compress_ptr cinfo, FILE * outfile));
|
||||
EXTERN void jpeg_stdio_src JPP((j_decompress_ptr cinfo, FILE * infile));
|
||||
EXTERN(void) jpeg_stdio_dest JPP((j_compress_ptr cinfo, FILE * outfile));
|
||||
EXTERN(void) jpeg_stdio_src JPP((j_decompress_ptr cinfo, FILE * infile));
|
||||
|
||||
/* Default parameter setup for compression */
|
||||
JRI_PUBLIC_API(void) jpeg_set_defaults JPP((j_compress_ptr cinfo));
|
||||
EXTERN(void) jpeg_set_defaults JPP((j_compress_ptr cinfo));
|
||||
/* Compression parameter setup aids */
|
||||
EXTERN void jpeg_set_colorspace JPP((j_compress_ptr cinfo,
|
||||
J_COLOR_SPACE colorspace));
|
||||
EXTERN void jpeg_default_colorspace JPP((j_compress_ptr cinfo));
|
||||
JRI_PUBLIC_API(void) jpeg_set_quality JPP((j_compress_ptr cinfo, int quality,
|
||||
boolean force_baseline));
|
||||
EXTERN void jpeg_set_linear_quality JPP((j_compress_ptr cinfo,
|
||||
int scale_factor,
|
||||
boolean force_baseline));
|
||||
EXTERN void jpeg_add_quant_table JPP((j_compress_ptr cinfo, int which_tbl,
|
||||
const unsigned int *basic_table,
|
||||
int scale_factor,
|
||||
boolean force_baseline));
|
||||
EXTERN int jpeg_quality_scaling JPP((int quality));
|
||||
EXTERN void jpeg_simple_progression JPP((j_compress_ptr cinfo));
|
||||
EXTERN void jpeg_suppress_tables JPP((j_compress_ptr cinfo,
|
||||
boolean suppress));
|
||||
EXTERN JQUANT_TBL * jpeg_alloc_quant_table JPP((j_common_ptr cinfo));
|
||||
EXTERN JHUFF_TBL * jpeg_alloc_huff_table JPP((j_common_ptr cinfo));
|
||||
|
||||
/* new destination initializer to open file in DLL (win16)*/
|
||||
JRI_PUBLIC_API(void) jpeg_file_dest JPP( (j_compress_ptr cinfo, char * outfile));
|
||||
|
||||
/* in case of error app must close file with DLL that opened it. (win16)*/
|
||||
JRI_PUBLIC_API(void) jpeg_close_file JPP( (j_compress_ptr cinfo));
|
||||
EXTERN(void) jpeg_set_colorspace JPP((j_compress_ptr cinfo,
|
||||
J_COLOR_SPACE colorspace));
|
||||
EXTERN(void) jpeg_default_colorspace JPP((j_compress_ptr cinfo));
|
||||
EXTERN(void) jpeg_set_quality JPP((j_compress_ptr cinfo, int quality,
|
||||
boolean force_baseline));
|
||||
EXTERN(void) jpeg_set_linear_quality JPP((j_compress_ptr cinfo,
|
||||
int scale_factor,
|
||||
boolean force_baseline));
|
||||
EXTERN(void) jpeg_add_quant_table JPP((j_compress_ptr cinfo, int which_tbl,
|
||||
const unsigned int *basic_table,
|
||||
int scale_factor,
|
||||
boolean force_baseline));
|
||||
EXTERN(int) jpeg_quality_scaling JPP((int quality));
|
||||
EXTERN(void) jpeg_simple_progression JPP((j_compress_ptr cinfo));
|
||||
EXTERN(void) jpeg_suppress_tables JPP((j_compress_ptr cinfo,
|
||||
boolean suppress));
|
||||
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 */
|
||||
JRI_PUBLIC_API(void) jpeg_start_compress JPP((j_compress_ptr cinfo,
|
||||
boolean write_all_tables));
|
||||
JRI_PUBLIC_API(JDIMENSION) jpeg_write_scanlines JPP((j_compress_ptr cinfo,
|
||||
JSAMPARRAY scanlines,
|
||||
JDIMENSION num_lines));
|
||||
JRI_PUBLIC_API(void) jpeg_finish_compress JPP((j_compress_ptr cinfo));
|
||||
EXTERN(void) jpeg_start_compress JPP((j_compress_ptr cinfo,
|
||||
boolean write_all_tables));
|
||||
EXTERN(JDIMENSION) jpeg_write_scanlines JPP((j_compress_ptr cinfo,
|
||||
JSAMPARRAY scanlines,
|
||||
JDIMENSION num_lines));
|
||||
EXTERN(void) jpeg_finish_compress JPP((j_compress_ptr cinfo));
|
||||
|
||||
/* 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));
|
||||
EXTERN(JDIMENSION) jpeg_write_raw_data JPP((j_compress_ptr cinfo,
|
||||
JSAMPIMAGE data,
|
||||
JDIMENSION num_lines));
|
||||
|
||||
/* Write a special marker. See libjpeg.doc concerning safe usage. */
|
||||
EXTERN void jpeg_write_marker JPP((j_compress_ptr cinfo, int marker,
|
||||
const JOCTET *dataptr, unsigned int datalen));
|
||||
EXTERN(void) jpeg_write_marker
|
||||
JPP((j_compress_ptr cinfo, int marker,
|
||||
const JOCTET * dataptr, unsigned int datalen));
|
||||
/* Same, but piecemeal. */
|
||||
EXTERN(void) jpeg_write_m_header
|
||||
JPP((j_compress_ptr cinfo, int marker, unsigned int datalen));
|
||||
EXTERN(void) jpeg_write_m_byte
|
||||
JPP((j_compress_ptr cinfo, int val));
|
||||
|
||||
/* Alternate compression function: just write an abbreviated table file */
|
||||
EXTERN void jpeg_write_tables JPP((j_compress_ptr cinfo));
|
||||
EXTERN(void) jpeg_write_tables JPP((j_compress_ptr cinfo));
|
||||
|
||||
/* Decompression startup: read start of JPEG datastream to see what's there */
|
||||
JRI_PUBLIC_API(int) jpeg_read_header JPP((j_decompress_ptr cinfo,
|
||||
boolean require_image));
|
||||
EXTERN(int) jpeg_read_header JPP((j_decompress_ptr cinfo,
|
||||
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 */
|
||||
@ -995,25 +978,25 @@ JRI_PUBLIC_API(int) jpeg_read_header JPP((j_decompress_ptr cinfo,
|
||||
*/
|
||||
|
||||
/* Main entry points for decompression */
|
||||
JRI_PUBLIC_API(boolean) jpeg_start_decompress JPP((j_decompress_ptr cinfo));
|
||||
JRI_PUBLIC_API(JDIMENSION) jpeg_read_scanlines JPP((j_decompress_ptr cinfo,
|
||||
JSAMPARRAY scanlines,
|
||||
JDIMENSION max_lines));
|
||||
JRI_PUBLIC_API(boolean) jpeg_finish_decompress JPP((j_decompress_ptr cinfo));
|
||||
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));
|
||||
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));
|
||||
EXTERN(JDIMENSION) jpeg_read_raw_data JPP((j_decompress_ptr cinfo,
|
||||
JSAMPIMAGE data,
|
||||
JDIMENSION max_lines));
|
||||
|
||||
/* Additional entry points for buffered-image mode. */
|
||||
JRI_PUBLIC_API(boolean) jpeg_has_multiple_scans JPP((j_decompress_ptr cinfo));
|
||||
JRI_PUBLIC_API(boolean) jpeg_start_output JPP((j_decompress_ptr cinfo,
|
||||
int scan_number));
|
||||
JRI_PUBLIC_API(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));
|
||||
JRI_PUBLIC_API(int) jpeg_consume_input JPP((j_decompress_ptr cinfo));
|
||||
EXTERN(boolean) jpeg_has_multiple_scans JPP((j_decompress_ptr cinfo));
|
||||
EXTERN(boolean) jpeg_start_output JPP((j_decompress_ptr cinfo,
|
||||
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));
|
||||
EXTERN(int) jpeg_consume_input JPP((j_decompress_ptr cinfo));
|
||||
/* Return value is one of: */
|
||||
/* #define JPEG_SUSPENDED 0 Suspended due to lack of input data */
|
||||
#define JPEG_REACHED_SOS 1 /* Reached start of new scan */
|
||||
@ -1022,19 +1005,24 @@ JRI_PUBLIC_API(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. */
|
||||
JRI_PUBLIC_API(void) jpeg_calc_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));
|
||||
|
||||
/* Install a special processing method for COM or APPn markers. */
|
||||
JRI_PUBLIC_API(void) jpeg_set_marker_processor JPP((j_decompress_ptr cinfo,
|
||||
int marker_code,
|
||||
jpeg_marker_parser_method routine));
|
||||
EXTERN(void) jpeg_set_marker_processor
|
||||
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));
|
||||
EXTERN void jpeg_copy_critical_parameters JPP((j_decompress_ptr srcinfo,
|
||||
j_compress_ptr dstinfo));
|
||||
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));
|
||||
EXTERN(void) jpeg_copy_critical_parameters JPP((j_decompress_ptr srcinfo,
|
||||
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,
|
||||
@ -1042,18 +1030,18 @@ EXTERN void jpeg_copy_critical_parameters JPP((j_decompress_ptr srcinfo,
|
||||
* if you're done with the JPEG object, but if you want to clean it up and
|
||||
* reuse it, call this:
|
||||
*/
|
||||
EXTERN void jpeg_abort_compress JPP((j_compress_ptr cinfo));
|
||||
EXTERN void jpeg_abort_decompress JPP((j_decompress_ptr cinfo));
|
||||
EXTERN(void) jpeg_abort_compress JPP((j_compress_ptr cinfo));
|
||||
EXTERN(void) jpeg_abort_decompress JPP((j_decompress_ptr cinfo));
|
||||
|
||||
/* Generic versions of jpeg_abort and jpeg_destroy that work on either
|
||||
* flavor of JPEG object. These may be more convenient in some places.
|
||||
*/
|
||||
EXTERN void jpeg_abort JPP((j_common_ptr cinfo));
|
||||
EXTERN void jpeg_destroy JPP((j_common_ptr cinfo));
|
||||
EXTERN(void) jpeg_abort JPP((j_common_ptr cinfo));
|
||||
EXTERN(void) jpeg_destroy JPP((j_common_ptr cinfo));
|
||||
|
||||
/* Default restart-marker-resync procedure for use by data source modules */
|
||||
JRI_PUBLIC_API(boolean) jpeg_resync_to_restart JPP((j_decompress_ptr cinfo,
|
||||
int desired));
|
||||
EXTERN(boolean) jpeg_resync_to_restart JPP((j_decompress_ptr cinfo,
|
||||
int desired));
|
||||
|
||||
|
||||
/* These marker codes are exported since applications and data source modules
|
||||
@ -1111,7 +1099,4 @@ struct jpeg_color_quantizer { long dummy; };
|
||||
#include "jerror.h" /* fetch error codes too */
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#endif /* JPEGLIB_H */
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* jquant1.c
|
||||
*
|
||||
* Copyright (C) 1991-1995, Thomas G. Lane.
|
||||
* Copyright (C) 1991-1996, Thomas G. Lane.
|
||||
* This file is part of the Independent JPEG Group's software.
|
||||
* For conditions of distribution and use, see the accompanying README file.
|
||||
*
|
||||
@ -182,7 +182,7 @@ typedef my_cquantizer * my_cquantize_ptr;
|
||||
*/
|
||||
|
||||
|
||||
LOCAL int
|
||||
LOCAL(int)
|
||||
select_ncolors (j_decompress_ptr cinfo, int Ncolors[])
|
||||
/* Determine allocation of desired colors to components, */
|
||||
/* and fill in Ncolors[] array to indicate choice. */
|
||||
@ -241,7 +241,7 @@ select_ncolors (j_decompress_ptr cinfo, int Ncolors[])
|
||||
}
|
||||
|
||||
|
||||
LOCAL int
|
||||
LOCAL(int)
|
||||
output_value (j_decompress_ptr cinfo, int ci, int j, int maxj)
|
||||
/* Return j'th output value, where j will range from 0 to maxj */
|
||||
/* The output values must fall in 0..MAXJSAMPLE in increasing order */
|
||||
@ -255,29 +255,13 @@ output_value (j_decompress_ptr cinfo, int ci, int j, int maxj)
|
||||
}
|
||||
|
||||
|
||||
LOCAL int
|
||||
LOCAL(int)
|
||||
largest_input_value (j_decompress_ptr cinfo, int ci, int j, int maxj)
|
||||
/* Return largest input value that should map to j'th output value */
|
||||
/* Must have largest(j=0) >= 0, and largest(j=maxj) >= MAXJSAMPLE */
|
||||
{
|
||||
/* Breakpoints are halfway between values returned by output_value */
|
||||
#if defined(_WINDOWS) && !defined(_WIN32)
|
||||
int iRetval;
|
||||
INT32 lTemp;
|
||||
|
||||
iRetval = 0;
|
||||
lTemp = 2*j + 1;
|
||||
lTemp *= MAXJSAMPLE;
|
||||
lTemp += maxj;
|
||||
lTemp /= 2;
|
||||
lTemp /= maxj;
|
||||
|
||||
iRetval = (int)lTemp;
|
||||
|
||||
return(iRetval);
|
||||
#else
|
||||
return (int) (((INT32) (2*j + 1) * MAXJSAMPLE + maxj) / (2*maxj));
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@ -285,7 +269,7 @@ largest_input_value (j_decompress_ptr cinfo, int ci, int j, int maxj)
|
||||
* Create the colormap.
|
||||
*/
|
||||
|
||||
LOCAL void
|
||||
LOCAL(void)
|
||||
create_colormap (j_decompress_ptr cinfo)
|
||||
{
|
||||
my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
|
||||
@ -345,7 +329,7 @@ create_colormap (j_decompress_ptr cinfo)
|
||||
* Create the color index table.
|
||||
*/
|
||||
|
||||
LOCAL void
|
||||
LOCAL(void)
|
||||
create_colorindex (j_decompress_ptr cinfo)
|
||||
{
|
||||
my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
|
||||
@ -408,7 +392,7 @@ create_colorindex (j_decompress_ptr cinfo)
|
||||
* distinct output values.
|
||||
*/
|
||||
|
||||
LOCAL ODITHER_MATRIX_PTR
|
||||
LOCAL(ODITHER_MATRIX_PTR)
|
||||
make_odither_array (j_decompress_ptr cinfo, int ncolors)
|
||||
{
|
||||
ODITHER_MATRIX_PTR odither;
|
||||
@ -444,7 +428,7 @@ make_odither_array (j_decompress_ptr cinfo, int ncolors)
|
||||
* share a dither table.
|
||||
*/
|
||||
|
||||
LOCAL void
|
||||
LOCAL(void)
|
||||
create_odither_tables (j_decompress_ptr cinfo)
|
||||
{
|
||||
my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
|
||||
@ -471,7 +455,7 @@ create_odither_tables (j_decompress_ptr cinfo)
|
||||
* Map some rows of pixels to the output colormapped representation.
|
||||
*/
|
||||
|
||||
METHODDEF void
|
||||
METHODDEF(void)
|
||||
color_quantize (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
|
||||
JSAMPARRAY output_buf, int num_rows)
|
||||
/* General case, no dithering */
|
||||
@ -499,7 +483,7 @@ color_quantize (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
|
||||
}
|
||||
|
||||
|
||||
METHODDEF void
|
||||
METHODDEF(void)
|
||||
color_quantize3 (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
|
||||
JSAMPARRAY output_buf, int num_rows)
|
||||
/* Fast path for out_color_components==3, no dithering */
|
||||
@ -527,7 +511,7 @@ color_quantize3 (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
|
||||
}
|
||||
|
||||
|
||||
METHODDEF void
|
||||
METHODDEF(void)
|
||||
quantize_ord_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
|
||||
JSAMPARRAY output_buf, int num_rows)
|
||||
/* General case, with ordered dithering */
|
||||
@ -577,7 +561,7 @@ quantize_ord_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
|
||||
}
|
||||
|
||||
|
||||
METHODDEF void
|
||||
METHODDEF(void)
|
||||
quantize3_ord_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
|
||||
JSAMPARRAY output_buf, int num_rows)
|
||||
/* Fast path for out_color_components==3, with ordered dithering */
|
||||
@ -622,7 +606,7 @@ quantize3_ord_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
|
||||
}
|
||||
|
||||
|
||||
METHODDEF void
|
||||
METHODDEF(void)
|
||||
quantize_fs_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
|
||||
JSAMPARRAY output_buf, int num_rows)
|
||||
/* General case, with Floyd-Steinberg dithering */
|
||||
@ -734,7 +718,7 @@ quantize_fs_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
|
||||
* Allocate workspace for Floyd-Steinberg errors.
|
||||
*/
|
||||
|
||||
LOCAL void
|
||||
LOCAL(void)
|
||||
alloc_fs_workspace (j_decompress_ptr cinfo)
|
||||
{
|
||||
my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
|
||||
@ -753,7 +737,7 @@ alloc_fs_workspace (j_decompress_ptr cinfo)
|
||||
* Initialize for one-pass color quantization.
|
||||
*/
|
||||
|
||||
METHODDEF void
|
||||
METHODDEF(void)
|
||||
start_pass_1_quant (j_decompress_ptr cinfo, boolean is_pre_scan)
|
||||
{
|
||||
my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
|
||||
@ -810,7 +794,7 @@ start_pass_1_quant (j_decompress_ptr cinfo, boolean is_pre_scan)
|
||||
* Finish up at the end of the pass.
|
||||
*/
|
||||
|
||||
METHODDEF void
|
||||
METHODDEF(void)
|
||||
finish_pass_1_quant (j_decompress_ptr cinfo)
|
||||
{
|
||||
/* no work in 1-pass case */
|
||||
@ -822,7 +806,7 @@ finish_pass_1_quant (j_decompress_ptr cinfo)
|
||||
* Shouldn't get to this module!
|
||||
*/
|
||||
|
||||
METHODDEF void
|
||||
METHODDEF(void)
|
||||
new_color_map_1_quant (j_decompress_ptr cinfo)
|
||||
{
|
||||
ERREXIT(cinfo, JERR_MODE_CHANGE);
|
||||
@ -833,7 +817,7 @@ new_color_map_1_quant (j_decompress_ptr cinfo)
|
||||
* Module initialization routine for 1-pass color quantization.
|
||||
*/
|
||||
|
||||
GLOBAL void
|
||||
GLOBAL(void)
|
||||
jinit_1pass_quantizer (j_decompress_ptr cinfo)
|
||||
{
|
||||
my_cquantize_ptr cquantize;
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* jquant2.c
|
||||
*
|
||||
* Copyright (C) 1991-1995, Thomas G. Lane.
|
||||
* Copyright (C) 1991-1996, Thomas G. Lane.
|
||||
* This file is part of the Independent JPEG Group's software.
|
||||
* For conditions of distribution and use, see the accompanying README file.
|
||||
*
|
||||
@ -220,7 +220,7 @@ typedef my_cquantizer * my_cquantize_ptr;
|
||||
* NULL pointer).
|
||||
*/
|
||||
|
||||
METHODDEF void
|
||||
METHODDEF(void)
|
||||
prescan_quantize (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
|
||||
JSAMPARRAY output_buf, int num_rows)
|
||||
{
|
||||
@ -269,7 +269,7 @@ typedef struct {
|
||||
typedef box * boxptr;
|
||||
|
||||
|
||||
LOCAL boxptr
|
||||
LOCAL(boxptr)
|
||||
find_biggest_color_pop (boxptr boxlist, int numboxes)
|
||||
/* Find the splittable box with the largest color population */
|
||||
/* Returns NULL if no splittable boxes remain */
|
||||
@ -289,7 +289,7 @@ find_biggest_color_pop (boxptr boxlist, int numboxes)
|
||||
}
|
||||
|
||||
|
||||
LOCAL boxptr
|
||||
LOCAL(boxptr)
|
||||
find_biggest_volume (boxptr boxlist, int numboxes)
|
||||
/* Find the splittable box with the largest (scaled) volume */
|
||||
/* Returns NULL if no splittable boxes remain */
|
||||
@ -309,7 +309,7 @@ find_biggest_volume (boxptr boxlist, int numboxes)
|
||||
}
|
||||
|
||||
|
||||
LOCAL void
|
||||
LOCAL(void)
|
||||
update_box (j_decompress_ptr cinfo, boxptr boxp)
|
||||
/* Shrink the min/max bounds of a box to enclose only nonzero elements, */
|
||||
/* and recompute its volume and population */
|
||||
@ -420,7 +420,7 @@ update_box (j_decompress_ptr cinfo, boxptr boxp)
|
||||
}
|
||||
|
||||
|
||||
LOCAL int
|
||||
LOCAL(int)
|
||||
median_cut (j_decompress_ptr cinfo, boxptr boxlist, int numboxes,
|
||||
int desired_colors)
|
||||
/* Repeatedly select and split the largest box until we have enough boxes */
|
||||
@ -495,7 +495,7 @@ median_cut (j_decompress_ptr cinfo, boxptr boxlist, int numboxes,
|
||||
}
|
||||
|
||||
|
||||
LOCAL void
|
||||
LOCAL(void)
|
||||
compute_color (j_decompress_ptr cinfo, boxptr boxp, int icolor)
|
||||
/* Compute representative color for a box, put it in colormap[icolor] */
|
||||
{
|
||||
@ -535,7 +535,7 @@ compute_color (j_decompress_ptr cinfo, boxptr boxp, int icolor)
|
||||
}
|
||||
|
||||
|
||||
LOCAL void
|
||||
LOCAL(void)
|
||||
select_colors (j_decompress_ptr cinfo, int desired_colors)
|
||||
/* Master routine for color selection */
|
||||
{
|
||||
@ -642,7 +642,7 @@ select_colors (j_decompress_ptr cinfo, int desired_colors)
|
||||
* inner-loop variables.
|
||||
*/
|
||||
|
||||
LOCAL int
|
||||
LOCAL(int)
|
||||
find_nearby_colors (j_decompress_ptr cinfo, int minc0, int minc1, int minc2,
|
||||
JSAMPLE colorlist[])
|
||||
/* Locate the colormap entries close enough to an update box to be candidates
|
||||
@ -771,7 +771,7 @@ find_nearby_colors (j_decompress_ptr cinfo, int minc0, int minc1, int minc2,
|
||||
}
|
||||
|
||||
|
||||
LOCAL void
|
||||
LOCAL(void)
|
||||
find_best_colors (j_decompress_ptr cinfo, int minc0, int minc1, int minc2,
|
||||
int numcolors, JSAMPLE colorlist[], JSAMPLE bestcolor[])
|
||||
/* Find the closest colormap entry for each cell in the update box,
|
||||
@ -851,7 +851,7 @@ find_best_colors (j_decompress_ptr cinfo, int minc0, int minc1, int minc2,
|
||||
}
|
||||
|
||||
|
||||
LOCAL void
|
||||
LOCAL(void)
|
||||
fill_inverse_cmap (j_decompress_ptr cinfo, int c0, int c1, int c2)
|
||||
/* Fill the inverse-colormap entries in the update box that contains */
|
||||
/* histogram cell c0/c1/c2. (Only that one cell MUST be filled, but */
|
||||
@ -911,7 +911,7 @@ fill_inverse_cmap (j_decompress_ptr cinfo, int c0, int c1, int c2)
|
||||
* Map some rows of pixels to the output colormapped representation.
|
||||
*/
|
||||
|
||||
METHODDEF void
|
||||
METHODDEF(void)
|
||||
pass2_no_dither (j_decompress_ptr cinfo,
|
||||
JSAMPARRAY input_buf, JSAMPARRAY output_buf, int num_rows)
|
||||
/* This version performs no dithering */
|
||||
@ -945,7 +945,7 @@ pass2_no_dither (j_decompress_ptr cinfo,
|
||||
}
|
||||
|
||||
|
||||
METHODDEF void
|
||||
METHODDEF(void)
|
||||
pass2_fs_dither (j_decompress_ptr cinfo,
|
||||
JSAMPARRAY input_buf, JSAMPARRAY output_buf, int num_rows)
|
||||
/* This version performs Floyd-Steinberg dithering */
|
||||
@ -1104,7 +1104,7 @@ pass2_fs_dither (j_decompress_ptr cinfo,
|
||||
* to Aaron Giles for this idea.
|
||||
*/
|
||||
|
||||
LOCAL void
|
||||
LOCAL(void)
|
||||
init_error_limit (j_decompress_ptr cinfo)
|
||||
/* Allocate and fill in the error_limiter table */
|
||||
{
|
||||
@ -1139,7 +1139,7 @@ init_error_limit (j_decompress_ptr cinfo)
|
||||
* Finish up at the end of each pass.
|
||||
*/
|
||||
|
||||
METHODDEF void
|
||||
METHODDEF(void)
|
||||
finish_pass1 (j_decompress_ptr cinfo)
|
||||
{
|
||||
my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
|
||||
@ -1152,7 +1152,7 @@ finish_pass1 (j_decompress_ptr cinfo)
|
||||
}
|
||||
|
||||
|
||||
METHODDEF void
|
||||
METHODDEF(void)
|
||||
finish_pass2 (j_decompress_ptr cinfo)
|
||||
{
|
||||
/* no work */
|
||||
@ -1163,7 +1163,7 @@ finish_pass2 (j_decompress_ptr cinfo)
|
||||
* Initialize for each processing pass.
|
||||
*/
|
||||
|
||||
METHODDEF void
|
||||
METHODDEF(void)
|
||||
start_pass_2_quant (j_decompress_ptr cinfo, boolean is_pre_scan)
|
||||
{
|
||||
my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
|
||||
@ -1226,7 +1226,7 @@ start_pass_2_quant (j_decompress_ptr cinfo, boolean is_pre_scan)
|
||||
* Switch to a new external colormap between output passes.
|
||||
*/
|
||||
|
||||
METHODDEF void
|
||||
METHODDEF(void)
|
||||
new_color_map_2_quant (j_decompress_ptr cinfo)
|
||||
{
|
||||
my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
|
||||
@ -1240,7 +1240,7 @@ new_color_map_2_quant (j_decompress_ptr cinfo)
|
||||
* Module initialization routine for 2-pass color quantization.
|
||||
*/
|
||||
|
||||
GLOBAL void
|
||||
GLOBAL(void)
|
||||
jinit_2pass_quantizer (j_decompress_ptr cinfo)
|
||||
{
|
||||
my_cquantize_ptr cquantize;
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* jutils.c
|
||||
*
|
||||
* Copyright (C) 1991-1995, Thomas G. Lane.
|
||||
* Copyright (C) 1991-1996, Thomas G. Lane.
|
||||
* This file is part of the Independent JPEG Group's software.
|
||||
* For conditions of distribution and use, see the accompanying README file.
|
||||
*
|
||||
@ -21,6 +21,8 @@
|
||||
* of a DCT block read in natural order (left to right, top to bottom).
|
||||
*/
|
||||
|
||||
#if 0 /* This table is not actually needed in v6a */
|
||||
|
||||
const int jpeg_zigzag_order[DCTSIZE2] = {
|
||||
0, 1, 5, 6, 14, 15, 27, 28,
|
||||
2, 4, 7, 13, 16, 26, 29, 42,
|
||||
@ -32,6 +34,8 @@ const int jpeg_zigzag_order[DCTSIZE2] = {
|
||||
35, 36, 48, 49, 57, 58, 62, 63
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
* jpeg_natural_order[i] is the natural-order position of the i'th element
|
||||
* of zigzag order.
|
||||
@ -64,7 +68,7 @@ const int jpeg_natural_order[DCTSIZE2+16] = {
|
||||
* Arithmetic utilities
|
||||
*/
|
||||
|
||||
GLOBAL long
|
||||
GLOBAL(long)
|
||||
jdiv_round_up (long a, long b)
|
||||
/* Compute a/b rounded up to next integer, ie, ceil(a/b) */
|
||||
/* Assumes a >= 0, b > 0 */
|
||||
@ -73,7 +77,7 @@ jdiv_round_up (long a, long b)
|
||||
}
|
||||
|
||||
|
||||
GLOBAL long
|
||||
GLOBAL(long)
|
||||
jround_up (long a, long b)
|
||||
/* Compute a rounded up to next multiple of b, ie, ceil(a/b)*b */
|
||||
/* Assumes a >= 0, b > 0 */
|
||||
@ -103,7 +107,7 @@ jround_up (long a, long b)
|
||||
#endif
|
||||
|
||||
|
||||
GLOBAL void
|
||||
GLOBAL(void)
|
||||
jcopy_sample_rows (JSAMPARRAY input_array, int source_row,
|
||||
JSAMPARRAY output_array, int dest_row,
|
||||
int num_rows, JDIMENSION num_cols)
|
||||
@ -137,7 +141,7 @@ jcopy_sample_rows (JSAMPARRAY input_array, int source_row,
|
||||
}
|
||||
|
||||
|
||||
GLOBAL void
|
||||
GLOBAL(void)
|
||||
jcopy_block_row (JBLOCKROW input_row, JBLOCKROW output_row,
|
||||
JDIMENSION num_blocks)
|
||||
/* Copy a row of coefficient blocks from one place to another. */
|
||||
@ -157,7 +161,7 @@ jcopy_block_row (JBLOCKROW input_row, JBLOCKROW output_row,
|
||||
}
|
||||
|
||||
|
||||
GLOBAL void
|
||||
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. */
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* jversion.h
|
||||
*
|
||||
* Copyright (C) 1991-1995, Thomas G. Lane.
|
||||
* Copyright (C) 1991-1998, Thomas G. Lane.
|
||||
* This file is part of the Independent JPEG Group's software.
|
||||
* For conditions of distribution and use, see the accompanying README file.
|
||||
*
|
||||
@ -9,6 +9,6 @@
|
||||
*/
|
||||
|
||||
|
||||
#define JVERSION "6 2-Aug-95"
|
||||
#define JVERSION "6b 27-Mar-1998"
|
||||
|
||||
#define JCOPYRIGHT "Copyright (C) 1995, Thomas G. Lane"
|
||||
#define JCOPYRIGHT "Copyright (C) 1998, Thomas G. Lane"
|
||||
|
448
jpeg/libjpeg.doc
448
jpeg/libjpeg.doc
@ -1,6 +1,6 @@
|
||||
USING THE IJG JPEG LIBRARY
|
||||
|
||||
Copyright (C) 1994-1995, Thomas G. Lane.
|
||||
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.
|
||||
|
||||
@ -47,6 +47,7 @@ Advanced features:
|
||||
Really raw data: DCT coefficients
|
||||
Progress monitoring
|
||||
Memory management
|
||||
Memory usage
|
||||
Library compile-time options
|
||||
Portability considerations
|
||||
Notes for MS-DOS implementors
|
||||
@ -186,19 +187,20 @@ Before diving into procedural details, it is helpful to understand the
|
||||
image data format that the JPEG library expects or returns.
|
||||
|
||||
The standard input image format is a rectangular array of pixels, with each
|
||||
pixel having the same number of "component" values (color channels). You
|
||||
must specify how many components there are and the colorspace interpretation
|
||||
of the components. Most applications will use RGB data (three components
|
||||
per pixel) or grayscale data (one component per pixel). PLEASE NOTE THAT
|
||||
RGB DATA IS THREE SAMPLES PER PIXEL, GRAYSCALE ONLY ONE. A remarkable
|
||||
number of people manage to miss this, only to find that their programs don't
|
||||
work with grayscale JPEG files.
|
||||
pixel having the same number of "component" or "sample" values (color
|
||||
channels). You must specify how many components there are and the colorspace
|
||||
interpretation of the components. Most applications will use RGB data
|
||||
(three components per pixel) or grayscale data (one component per pixel).
|
||||
PLEASE NOTE THAT RGB DATA IS THREE SAMPLES PER PIXEL, GRAYSCALE ONLY ONE.
|
||||
A remarkable number of people manage to miss this, only to find that their
|
||||
programs don't work with grayscale JPEG files.
|
||||
|
||||
Note that there is no provision for colormapped input. You can feed in a
|
||||
colormapped image by expanding it to full-color format. However JPEG often
|
||||
doesn't work very well with colormapped source data, because of dithering
|
||||
noise. This is discussed in more detail in the JPEG FAQ and the other
|
||||
references mentioned in the README file.
|
||||
There is no provision for colormapped input. JPEG files are always full-color
|
||||
or full grayscale (or sometimes another colorspace such as CMYK). You can
|
||||
feed in a colormapped image by expanding it to full-color format. However
|
||||
JPEG often doesn't work very well with source data that has been colormapped,
|
||||
because of dithering noise. This is discussed in more detail in the JPEG FAQ
|
||||
and the other references mentioned in the README file.
|
||||
|
||||
Pixels are stored by scanlines, with each scanline running from left to
|
||||
right. The component values for each pixel are adjacent in the row; for
|
||||
@ -227,8 +229,11 @@ byte before passing it to the compressor. If you need to compress data
|
||||
that has more than 8 bits/channel, compile with BITS_IN_JSAMPLE = 12.
|
||||
(See "Library compile-time options", later.)
|
||||
|
||||
|
||||
The data format returned by the decompressor is the same in all details,
|
||||
except that colormapped data is supported. If you request colormapped
|
||||
except that colormapped output is supported. (Again, a JPEG file is never
|
||||
colormapped. But you can ask the decompressor to perform on-the-fly color
|
||||
quantization to deliver colormapped output.) If you request colormapped
|
||||
output then the returned data array contains a single JSAMPLE per pixel;
|
||||
its value is an index into a color map. The color map is represented as
|
||||
a 2-D JSAMPARRAY in which each row holds the values of one color component,
|
||||
@ -433,7 +438,7 @@ Typical code:
|
||||
jpeg_finish_compress(&cinfo);
|
||||
|
||||
If using the stdio destination manager, don't forget to close the output
|
||||
stdio stream if necessary.
|
||||
stdio stream (if necessary) afterwards.
|
||||
|
||||
If you have requested a multi-pass operating mode, such as Huffman code
|
||||
optimization, jpeg_finish_compress() will perform the additional passes using
|
||||
@ -459,12 +464,13 @@ you'll need to repeat all of step 3.
|
||||
7. Release the JPEG compression object.
|
||||
|
||||
When you are done with a JPEG compression object, destroy it by calling
|
||||
jpeg_destroy_compress(). This will free all subsidiary memory. Or you can
|
||||
call jpeg_destroy() which works for either compression or decompression
|
||||
objects --- this may be more convenient if you are sharing code between
|
||||
compression and decompression cases. (Actually, these routines are equivalent
|
||||
except for the declared type of the passed pointer. To avoid gripes from
|
||||
ANSI C compilers, jpeg_destroy() should be passed a j_common_ptr.)
|
||||
jpeg_destroy_compress(). This will free all subsidiary memory (regardless of
|
||||
the previous state of the object). Or you can call jpeg_destroy(), which
|
||||
works for either compression or decompression objects --- this may be more
|
||||
convenient if you are sharing code between compression and decompression
|
||||
cases. (Actually, these routines are equivalent except for the declared type
|
||||
of the passed pointer. To avoid gripes from ANSI C compilers, jpeg_destroy()
|
||||
should be passed a j_common_ptr.)
|
||||
|
||||
If you allocated the jpeg_compress_struct structure from malloc(), freeing
|
||||
it is your responsibility --- jpeg_destroy() won't. Ditto for the error
|
||||
@ -485,13 +491,19 @@ in either of two ways:
|
||||
legitimate at any point after calling jpeg_create_compress() --- in fact,
|
||||
it's safe even if jpeg_create_compress() fails.
|
||||
|
||||
* If you want to re-use the JPEG object, call jpeg_abort_compress(), or
|
||||
* If you want to re-use the JPEG object, call jpeg_abort_compress(), or call
|
||||
jpeg_abort() which works on both compression and decompression objects.
|
||||
This will return the object to an idle state, releasing any working memory.
|
||||
jpeg_abort() is allowed at any time after successful object creation.
|
||||
|
||||
Note that cleaning up the data destination, if required, is your
|
||||
responsibility.
|
||||
responsibility; neither of these routines will call term_destination().
|
||||
(See "Compressed data handling", below, for more about that.)
|
||||
|
||||
jpeg_destroy() and jpeg_abort() are the only safe calls to make on a JPEG
|
||||
object that has reported an error by calling error_exit (see "Error handling"
|
||||
for more info). The internal state of such an object is likely to be out of
|
||||
whack. Either of these two routines will return the object to a known state.
|
||||
|
||||
|
||||
Decompression details
|
||||
@ -666,12 +678,13 @@ The return value always equals the change in the value of output_scanline.
|
||||
|
||||
If you don't use a suspending data source, it is safe to assume that
|
||||
jpeg_read_scanlines() reads at least one scanline per call, until the
|
||||
bottom of the image has been reached. If you use a buffer larger than one
|
||||
scanline, it is NOT safe to assume that jpeg_read_scanlines() fills it.
|
||||
(The current implementation won't return more than cinfo.rec_outbuf_height
|
||||
scanlines per call, no matter how large a buffer you pass.) So you must
|
||||
always provide a loop that calls jpeg_read_scanlines() repeatedly until
|
||||
the whole image has been read.
|
||||
bottom of the image has been reached.
|
||||
|
||||
If you use a buffer larger than one scanline, it is NOT safe to assume that
|
||||
jpeg_read_scanlines() fills it. (The current implementation returns only a
|
||||
few scanlines per call, no matter how large a buffer you pass.) So you must
|
||||
always provide a loop that calls jpeg_read_scanlines() repeatedly until the
|
||||
whole image has been read.
|
||||
|
||||
|
||||
7. jpeg_finish_decompress(...);
|
||||
@ -688,7 +701,7 @@ If using the stdio source manager, don't forget to close the source stdio
|
||||
stream if necessary.
|
||||
|
||||
It is an error to call jpeg_finish_decompress() before reading the correct
|
||||
total number of scanlines. If you wish to abort compression, call
|
||||
total number of scanlines. If you wish to abort decompression, call
|
||||
jpeg_abort() as discussed below.
|
||||
|
||||
After completing a decompression cycle, you may dispose of the JPEG object as
|
||||
@ -739,6 +752,17 @@ library (only compression or only decompression), only that much code will be
|
||||
included from the library, unless your linker is hopelessly brain-damaged.
|
||||
The supplied makefiles build libjpeg.a automatically (see install.doc).
|
||||
|
||||
While you can build the JPEG library as a shared library if the whim strikes
|
||||
you, we don't really recommend it. The trouble with shared libraries is that
|
||||
at some point you'll probably try to substitute a new version of the library
|
||||
without recompiling the calling applications. That generally doesn't work
|
||||
because the parameter struct declarations usually change with each new
|
||||
version. In other words, the library's API is *not* guaranteed binary
|
||||
compatible across versions; we only try to ensure source-code compatibility.
|
||||
(In hindsight, it might have been smarter to hide the parameter structs from
|
||||
applications and introduce a ton of access functions instead. Too late now,
|
||||
however.)
|
||||
|
||||
On some systems your application may need to set up a signal handler to ensure
|
||||
that temporary files are deleted if the program is interrupted. This is most
|
||||
critical if you are on MS-DOS and use the jmemdos.c memory manager back end;
|
||||
@ -831,9 +855,14 @@ jpeg_add_quant_table (j_compress_ptr cinfo, int which_tbl,
|
||||
int scale_factor, boolean force_baseline)
|
||||
Allows an arbitrary quantization table to be created. which_tbl
|
||||
indicates which table slot to fill. basic_table points to an array
|
||||
of 64 unsigned ints given in JPEG zigzag order. These values are
|
||||
of 64 unsigned ints given in normal array order. These values are
|
||||
multiplied by scale_factor/100 and then clamped to the range 1..65535
|
||||
(or to 1..255 if force_baseline is TRUE).
|
||||
CAUTION: prior to library version 6a, jpeg_add_quant_table expected
|
||||
the basic table to be given in JPEG zigzag order. If you need to
|
||||
write code that works with either older or newer versions of this
|
||||
routine, you must check the library version number. Something like
|
||||
"#if JPEG_LIB_VERSION >= 61" is the right test.
|
||||
|
||||
jpeg_simple_progression (j_compress_ptr cinfo)
|
||||
Generates a default scan script for writing a progressive-JPEG file.
|
||||
@ -883,6 +912,11 @@ int restart_in_rows
|
||||
Set restart_in_rows to specify the interval in MCU rows. (If
|
||||
restart_in_rows is not 0, then restart_interval is set after the
|
||||
image width in MCUs is computed.) Defaults are zero (no restarts).
|
||||
One restart marker per MCU row is often a good choice.
|
||||
NOTE: the overhead of restart markers is higher in grayscale JPEG
|
||||
files than in color files, and MUCH higher in progressive JPEGs.
|
||||
If you use restarts, you may want to use larger intervals in those
|
||||
cases.
|
||||
|
||||
const jpeg_scan_info * scan_info
|
||||
int num_scans
|
||||
@ -906,6 +940,13 @@ boolean write_JFIF_header
|
||||
jpeg_set_colorspace() set this TRUE if a JFIF-legal JPEG color space
|
||||
(ie, YCbCr or grayscale) is selected, otherwise FALSE.
|
||||
|
||||
UINT8 JFIF_major_version
|
||||
UINT8 JFIF_minor_version
|
||||
The version number to be written into the JFIF marker.
|
||||
jpeg_set_defaults() initializes the version to 1.01 (major=minor=1).
|
||||
You should set it to 1.02 (major=1, minor=2) if you plan to write
|
||||
any JFIF 1.02 extension markers.
|
||||
|
||||
UINT8 density_unit
|
||||
UINT16 X_density
|
||||
UINT16 Y_density
|
||||
@ -1003,6 +1044,8 @@ JDIMENSION image_height
|
||||
int num_components Number of color components
|
||||
J_COLOR_SPACE jpeg_color_space Colorspace of image
|
||||
boolean saw_JFIF_marker TRUE if a JFIF APP0 marker was seen
|
||||
UINT8 JFIF_major_version Version information from JFIF marker
|
||||
UINT8 JFIF_minor_version
|
||||
UINT8 density_unit Resolution data from JFIF marker
|
||||
UINT16 X_density
|
||||
UINT16 Y_density
|
||||
@ -1134,6 +1177,8 @@ copying. In high-quality modes, rec_outbuf_height is always 1, but some
|
||||
faster, lower-quality modes set it to larger values (typically 2 to 4).
|
||||
If you are going to ask for a high-speed processing mode, you may as well
|
||||
go to the trouble of honoring rec_outbuf_height so as to avoid data copying.
|
||||
(An output buffer larger than rec_outbuf_height lines is OK, but won't
|
||||
provide any material speed improvement over that height.)
|
||||
|
||||
|
||||
Special color spaces
|
||||
@ -1194,8 +1239,11 @@ set out_color_space to override this. Again, you must select a supported
|
||||
transformation. jdcolor.c currently supports
|
||||
YCbCr => GRAYSCALE
|
||||
YCbCr => RGB
|
||||
GRAYSCALE => RGB
|
||||
YCCK => CMYK
|
||||
as well as the null transforms.
|
||||
as well as the null transforms. (Since GRAYSCALE=>RGB is provided, an
|
||||
application can force grayscale JPEGs to look like color JPEGs if it only
|
||||
wants to handle one case.)
|
||||
|
||||
The two-pass color quantizer, jquant2.c, is specialized to handle RGB data
|
||||
(it weights distances appropriately for RGB colors). You'll need to modify
|
||||
@ -1254,7 +1302,10 @@ additional data which is not known to the JPEG library or the standard error
|
||||
handler. The most convenient way to do this is to embed either the JPEG
|
||||
object or the jpeg_error_mgr struct in a larger structure that contains
|
||||
additional fields; then casting the passed pointer provides access to the
|
||||
additional fields. Again, see example.c for one way to do it.
|
||||
additional fields. Again, see example.c for one way to do it. (Beginning
|
||||
with IJG version 6b, there is also a void pointer "client_data" in each
|
||||
JPEG object, which the application can also use to find related data.
|
||||
The library does not touch client_data at all.)
|
||||
|
||||
The individual methods that you might wish to override are:
|
||||
|
||||
@ -1593,19 +1644,27 @@ fill_input_buffer() knows that no more data is available, it can set the
|
||||
pointer/count to point to a dummy EOI marker and then return TRUE just as
|
||||
though it had read more data in a non-suspending situation.
|
||||
|
||||
The decompressor does not attempt to suspend within any JPEG marker; it will
|
||||
backtrack to the start of the marker. Hence the input buffer must be large
|
||||
enough to hold the longest marker in the file. We recommend at least a 2K
|
||||
buffer. The buffer would need to be 64K to allow for arbitrary COM or APPn
|
||||
markers, but the decompressor does not actually try to read these; it just
|
||||
skips them by calling skip_input_data(). If you provide a special marker
|
||||
handling routine that does look at such markers, coping with buffer overflow
|
||||
is your problem. Ordinary JPEG markers should normally not exceed a few
|
||||
hundred bytes each (DHT tables are typically the longest). For robustness
|
||||
against damaged marker length counts, you may wish to insert a test in your
|
||||
application for the case that the input buffer is completely full and yet the
|
||||
decoder has suspended without consuming any data --- otherwise, if this
|
||||
situation did occur, it would lead to an endless loop.
|
||||
The decompressor does not attempt to suspend within standard JPEG markers;
|
||||
instead it will backtrack to the start of the marker and reprocess the whole
|
||||
marker next time. Hence the input buffer must be large enough to hold the
|
||||
longest standard marker in the file. Standard JPEG markers should normally
|
||||
not exceed a few hundred bytes each (DHT tables are typically the longest).
|
||||
We recommend at least a 2K buffer for performance reasons, which is much
|
||||
larger than any correct marker is likely to be. For robustness against
|
||||
damaged marker length counts, you may wish to insert a test in your
|
||||
application for the case that the input buffer is completely full and yet
|
||||
the decoder has suspended without consuming any data --- otherwise, if this
|
||||
situation did occur, it would lead to an endless loop. (The library can't
|
||||
provide this test since it has no idea whether "the buffer is full", or
|
||||
even whether there is a fixed-size input buffer.)
|
||||
|
||||
The input buffer would need to be 64K to allow for arbitrary COM or APPn
|
||||
markers, but these are handled specially: they are either saved into allocated
|
||||
memory, or skipped over by calling skip_input_data(). In the former case,
|
||||
suspension is handled correctly, and in the latter case, the problem of
|
||||
buffer overrun is placed on skip_input_data's shoulders, as explained above.
|
||||
Note that if you provide your own marker handling routine for large markers,
|
||||
you should consider how to deal with buffer overflow.
|
||||
|
||||
Multiple-buffer management:
|
||||
|
||||
@ -1825,7 +1884,7 @@ JPEG_REACHED_EOI.
|
||||
The target scan number passed to jpeg_start_output() is saved in the
|
||||
cinfo.output_scan_number field. The library's output processing calls
|
||||
jpeg_consume_input() whenever the current input scan number and row within
|
||||
the scan is less than or equal to the current output scan number and row.
|
||||
that scan is less than or equal to the current output scan number and row.
|
||||
Thus, input processing can "get ahead" of the output processing but is not
|
||||
allowed to "fall behind". You can achieve several different effects by
|
||||
manipulating this interlock rule. For example, if you pass a target scan
|
||||
@ -1844,10 +1903,26 @@ processor to simply display whatever it finds in the image buffer, without
|
||||
waiting for input. (However, the library will not accept a target scan
|
||||
number less than one, so you can't avoid waiting for the first scan.)
|
||||
|
||||
When using jpeg_consume_input(), you'll typically want to be sure that you
|
||||
perform a final output pass after receiving all the data; otherwise your last
|
||||
display may not be full quality across the whole screen. So the right outer
|
||||
loop logic is something like this:
|
||||
When data is arriving faster than the output display processing can advance
|
||||
through the image, jpeg_consume_input() will store data into the buffered
|
||||
image beyond the point at which the output processing is reading data out
|
||||
again. If the input arrives fast enough, it may "wrap around" the buffer to
|
||||
the point where the input is more than one whole scan ahead of the output.
|
||||
If the output processing simply proceeds through its display pass without
|
||||
paying attention to the input, the effect seen on-screen is that the lower
|
||||
part of the image is one or more scans better in quality than the upper part.
|
||||
Then, when the next output scan is started, you have a choice of what target
|
||||
scan number to use. The recommended choice is to use the current input scan
|
||||
number at that time, which implies that you've skipped the output scans
|
||||
corresponding to the input scans that were completed while you processed the
|
||||
previous output scan. In this way, the decoder automatically adapts its
|
||||
speed to the arriving data, by skipping output scans as necessary to keep up
|
||||
with the arriving data.
|
||||
|
||||
When using this strategy, you'll want to be sure that you perform a final
|
||||
output pass after receiving all the data; otherwise your last display may not
|
||||
be full quality across the whole screen. So the right outer loop logic is
|
||||
something like this:
|
||||
do {
|
||||
absorb any waiting input by calling jpeg_consume_input()
|
||||
final_pass = jpeg_input_complete(&cinfo);
|
||||
@ -1869,15 +1944,15 @@ the final pass, the right loop logic is like this:
|
||||
cinfo.input_scan_number == cinfo.output_scan_number)
|
||||
break;
|
||||
}
|
||||
In this case you don't need to know in advance whether an output pass is
|
||||
the last one, so it's not necessary to have reached EOF before starting the
|
||||
final output pass; rather, what you want to test is whether the output pass
|
||||
was performed in sync with the final input scan. This form of the loop
|
||||
will avoid an extra output pass whenever the decoder is able (or nearly
|
||||
able) to keep up with the incoming data.
|
||||
In this case you don't need to know in advance whether an output pass is to
|
||||
be the last one, so it's not necessary to have reached EOF before starting
|
||||
the final output pass; rather, what you want to test is whether the output
|
||||
pass was performed in sync with the final input scan. This form of the loop
|
||||
will avoid an extra output pass whenever the decoder is able (or nearly able)
|
||||
to keep up with the incoming data.
|
||||
|
||||
When the data transmission speed is high, you might begin a display pass,
|
||||
then find that much or all of the image has arrived before you can complete
|
||||
then find that much or all of the file has arrived before you can complete
|
||||
the pass. (You can detect this by noting the JPEG_REACHED_EOI return code
|
||||
from jpeg_consume_input(), or equivalently by testing jpeg_input_complete().)
|
||||
In this situation you may wish to abort the current display pass and start a
|
||||
@ -1916,10 +1991,10 @@ routines:
|
||||
* jpeg_read_scanlines(), as always, returns the number of scanlines that it
|
||||
was able to produce before suspending.
|
||||
* jpeg_finish_output() will read any markers following the target scan,
|
||||
up to the end of the image or the SOS marker that begins another scan.
|
||||
up to the end of the file or the SOS marker that begins another scan.
|
||||
(But it reads no input if jpeg_consume_input() has already reached the
|
||||
end of the image or a SOS marker beyond the target output scan.)
|
||||
* jpeg_finish_decompress() will read until the end of image, and thus can
|
||||
end of the file or a SOS marker beyond the target output scan.)
|
||||
* jpeg_finish_decompress() will read until the end of file, and thus can
|
||||
suspend if the end hasn't already been reached (as can be tested by
|
||||
calling jpeg_input_complete()).
|
||||
jpeg_start_output(), jpeg_finish_output(), and jpeg_finish_decompress()
|
||||
@ -2153,17 +2228,49 @@ In some cases you might want to compress an image using tables which are
|
||||
not stored in the application, but are defined in an interchange or
|
||||
tables-only file readable by the application. This can be done by setting up
|
||||
a JPEG decompression object to read the specification file, then copying the
|
||||
tables into your compression object.
|
||||
tables into your compression object. See jpeg_copy_critical_parameters()
|
||||
for an example of copying quantization tables.
|
||||
|
||||
|
||||
To read abbreviated image files, you simply need to load the proper tables
|
||||
into the decompression object before trying to read the abbreviated image.
|
||||
If the proper tables are stored in the application program, you can just
|
||||
allocate the table structs and fill in their contents directly. More commonly
|
||||
you'd want to read the tables from a tables-only file. The jpeg_read_header()
|
||||
call is sufficient to read a tables-only file. You must pass a second
|
||||
parameter of FALSE to indicate that you do not require an image to be present.
|
||||
Thus, the typical scenario is
|
||||
allocate the table structs and fill in their contents directly. For example,
|
||||
to load a fixed quantization table into table slot "n":
|
||||
|
||||
if (cinfo.quant_tbl_ptrs[n] == NULL)
|
||||
cinfo.quant_tbl_ptrs[n] = jpeg_alloc_quant_table((j_common_ptr) &cinfo);
|
||||
quant_ptr = cinfo.quant_tbl_ptrs[n]; /* quant_ptr is JQUANT_TBL* */
|
||||
for (i = 0; i < 64; i++) {
|
||||
/* Qtable[] is desired quantization table, in natural array order */
|
||||
quant_ptr->quantval[i] = Qtable[i];
|
||||
}
|
||||
|
||||
Code to load a fixed Huffman table is typically (for AC table "n"):
|
||||
|
||||
if (cinfo.ac_huff_tbl_ptrs[n] == NULL)
|
||||
cinfo.ac_huff_tbl_ptrs[n] = jpeg_alloc_huff_table((j_common_ptr) &cinfo);
|
||||
huff_ptr = cinfo.ac_huff_tbl_ptrs[n]; /* huff_ptr is JHUFF_TBL* */
|
||||
for (i = 1; i <= 16; i++) {
|
||||
/* counts[i] is number of Huffman codes of length i bits, i=1..16 */
|
||||
huff_ptr->bits[i] = counts[i];
|
||||
}
|
||||
for (i = 0; i < 256; i++) {
|
||||
/* symbols[] is the list of Huffman symbols, in code-length order */
|
||||
huff_ptr->huffval[i] = symbols[i];
|
||||
}
|
||||
|
||||
(Note that trying to set cinfo.quant_tbl_ptrs[n] to point directly at a
|
||||
constant JQUANT_TBL object is not safe. If the incoming file happened to
|
||||
contain a quantization table definition, your master table would get
|
||||
overwritten! Instead allocate a working table copy and copy the master table
|
||||
into it, as illustrated above. Ditto for Huffman tables, of course.)
|
||||
|
||||
You might want to read the tables from a tables-only file, rather than
|
||||
hard-wiring them into your application. The jpeg_read_header() call is
|
||||
sufficient to read a tables-only file. You must pass a second parameter of
|
||||
FALSE to indicate that you do not require an image to be present. Thus, the
|
||||
typical scenario is
|
||||
|
||||
create JPEG decompression object
|
||||
set source to tables-only file
|
||||
@ -2237,6 +2344,7 @@ the selected colorspace is RGB, CMYK, or YCCK. You can disable this, but
|
||||
we don't recommend it. The decompression library will recognize JFIF and
|
||||
Adobe markers and will set the JPEG colorspace properly when one is found.
|
||||
|
||||
|
||||
You can write special markers immediately following the datastream header by
|
||||
calling jpeg_write_marker() after jpeg_start_compress() and before the first
|
||||
call to jpeg_write_scanlines(). When you do this, the markers appear after
|
||||
@ -2246,18 +2354,96 @@ all else. Specify the marker type parameter as "JPEG_COM" for COM or
|
||||
any marker type, but we don't recommend writing any other kinds of marker.)
|
||||
For example, to write a user comment string pointed to by comment_text:
|
||||
jpeg_write_marker(cinfo, JPEG_COM, comment_text, strlen(comment_text));
|
||||
Or if you prefer to synthesize the marker byte sequence yourself, you can
|
||||
just cram it straight into the data destination module.
|
||||
|
||||
For decompression, you can supply your own routine to process COM or APPn
|
||||
markers by calling jpeg_set_marker_processor(). Usually you'd call this
|
||||
after creating a decompression object and before calling jpeg_read_header(),
|
||||
because the markers of interest will normally be scanned by jpeg_read_header.
|
||||
Once you've supplied a routine, it will be used for the life of that
|
||||
decompression object. A separate routine may be registered for COM and for
|
||||
each APPn marker code.
|
||||
If it's not convenient to store all the marker data in memory at once,
|
||||
you can instead call jpeg_write_m_header() followed by multiple calls to
|
||||
jpeg_write_m_byte(). If you do it this way, it's your responsibility to
|
||||
call jpeg_write_m_byte() exactly the number of times given in the length
|
||||
parameter to jpeg_write_m_header(). (This method lets you empty the
|
||||
output buffer partway through a marker, which might be important when
|
||||
using a suspending data destination module. In any case, if you are using
|
||||
a suspending destination, you should flush its buffer after inserting
|
||||
any special markers. See "I/O suspension".)
|
||||
|
||||
A marker processor routine must have the signature
|
||||
Or, if you prefer to synthesize the marker byte sequence yourself,
|
||||
you can just cram it straight into the data destination module.
|
||||
|
||||
If you are writing JFIF 1.02 extension markers (thumbnail images), don't
|
||||
forget to set cinfo.JFIF_minor_version = 2 so that the encoder will write the
|
||||
correct JFIF version number in the JFIF header marker. The library's default
|
||||
is to write version 1.01, but that's wrong if you insert any 1.02 extension
|
||||
markers. (We could probably get away with just defaulting to 1.02, but there
|
||||
used to be broken decoders that would complain about unknown minor version
|
||||
numbers. To reduce compatibility risks it's safest not to write 1.02 unless
|
||||
you are actually using 1.02 extensions.)
|
||||
|
||||
|
||||
When reading, two methods of handling special markers are available:
|
||||
1. You can ask the library to save the contents of COM and/or APPn markers
|
||||
into memory, and then examine them at your leisure afterwards.
|
||||
2. You can supply your own routine to process COM and/or APPn markers
|
||||
on-the-fly as they are read.
|
||||
The first method is simpler to use, especially if you are using a suspending
|
||||
data source; writing a marker processor that copes with input suspension is
|
||||
not easy (consider what happens if the marker is longer than your available
|
||||
input buffer). However, the second method conserves memory since the marker
|
||||
data need not be kept around after it's been processed.
|
||||
|
||||
For either method, you'd normally set up marker handling after creating a
|
||||
decompression object and before calling jpeg_read_header(), because the
|
||||
markers of interest will typically be near the head of the file and so will
|
||||
be scanned by jpeg_read_header. Once you've established a marker handling
|
||||
method, it will be used for the life of that decompression object
|
||||
(potentially many datastreams), unless you change it. Marker handling is
|
||||
determined separately for COM markers and for each APPn marker code.
|
||||
|
||||
|
||||
To save the contents of special markers in memory, call
|
||||
jpeg_save_markers(cinfo, marker_code, length_limit)
|
||||
where marker_code is the marker type to save, JPEG_COM or JPEG_APP0+n.
|
||||
(To arrange to save all the special marker types, you need to call this
|
||||
routine 17 times, for COM and APP0-APP15.) If the incoming marker is longer
|
||||
than length_limit data bytes, only length_limit bytes will be saved; this
|
||||
parameter allows you to avoid chewing up memory when you only need to see the
|
||||
first few bytes of a potentially large marker. If you want to save all the
|
||||
data, set length_limit to 0xFFFF; that is enough since marker lengths are only
|
||||
16 bits. As a special case, setting length_limit to 0 prevents that marker
|
||||
type from being saved at all. (That is the default behavior, in fact.)
|
||||
|
||||
After jpeg_read_header() completes, you can examine the special markers by
|
||||
following the cinfo->marker_list pointer chain. All the special markers in
|
||||
the file appear in this list, in order of their occurrence in the file (but
|
||||
omitting any markers of types you didn't ask for). Both the original data
|
||||
length and the saved data length are recorded for each list entry; the latter
|
||||
will not exceed length_limit for the particular marker type. Note that these
|
||||
lengths exclude the marker length word, whereas the stored representation
|
||||
within the JPEG file includes it. (Hence the maximum data length is really
|
||||
only 65533.)
|
||||
|
||||
It is possible that additional special markers appear in the file beyond the
|
||||
SOS marker at which jpeg_read_header stops; if so, the marker list will be
|
||||
extended during reading of the rest of the file. This is not expected to be
|
||||
common, however. If you are short on memory you may want to reset the length
|
||||
limit to zero for all marker types after finishing jpeg_read_header, to
|
||||
ensure that the max_memory_to_use setting cannot be exceeded due to addition
|
||||
of later markers.
|
||||
|
||||
The marker list remains stored until you call jpeg_finish_decompress or
|
||||
jpeg_abort, at which point the memory is freed and the list is set to empty.
|
||||
(jpeg_destroy also releases the storage, of course.)
|
||||
|
||||
Note that the library is internally interested in APP0 and APP14 markers;
|
||||
if you try to set a small nonzero length limit on these types, the library
|
||||
will silently force the length up to the minimum it wants. (But you can set
|
||||
a zero length limit to prevent them from being saved at all.) Also, in a
|
||||
16-bit environment, the maximum length limit may be constrained to less than
|
||||
65533 by malloc() limitations. It is therefore best not to assume that the
|
||||
effective length limit is exactly what you set it to be.
|
||||
|
||||
|
||||
If you want to supply your own marker-reading routine, you do it by calling
|
||||
jpeg_set_marker_processor(). A marker processor routine must have the
|
||||
signature
|
||||
boolean jpeg_marker_parser_method (j_decompress_ptr cinfo)
|
||||
Although the marker code is not explicitly passed, the routine can find it
|
||||
in cinfo->unread_marker. At the time of call, the marker proper has been
|
||||
@ -2271,9 +2457,16 @@ use a suspending data source.)
|
||||
If you override the default APP0 or APP14 processors, it is up to you to
|
||||
recognize JFIF and Adobe markers if you want colorspace recognition to occur
|
||||
properly. We recommend copying and extending the default processors if you
|
||||
want to do that.
|
||||
want to do that. (A better idea is to save these marker types for later
|
||||
examination by calling jpeg_save_markers(); that method doesn't interfere
|
||||
with the library's own processing of these markers.)
|
||||
|
||||
jpeg_set_marker_processor() and jpeg_save_markers() are mutually exclusive
|
||||
--- if you call one it overrides any previous call to the other, for the
|
||||
particular marker type specified.
|
||||
|
||||
A simple example of an external COM processor can be found in djpeg.c.
|
||||
Also, see jpegtran.c for an example of using jpeg_save_markers.
|
||||
|
||||
|
||||
Raw (downsampled) image data
|
||||
@ -2419,6 +2612,15 @@ and also read structure.doc's discussion of virtual array handling). Or,
|
||||
for simple transcoding to a different JPEG file format, the array list can
|
||||
just be handed directly to jpeg_write_coefficients().
|
||||
|
||||
Each block in the block arrays contains quantized coefficient values in
|
||||
normal array order (not JPEG zigzag order). The block arrays contain only
|
||||
DCT blocks containing real data; any entirely-dummy blocks added to fill out
|
||||
interleaved MCUs at the right or bottom edges of the image are discarded
|
||||
during reading and are not stored in the block arrays. (The size of each
|
||||
block array can be determined from the width_in_blocks and height_in_blocks
|
||||
fields of the component's comp_info entry.) This is also the data format
|
||||
expected by jpeg_write_coefficients().
|
||||
|
||||
When you are done using the virtual arrays, call jpeg_finish_decompress()
|
||||
to release the array storage and return the decompression object to an idle
|
||||
state; or just call jpeg_destroy() if you don't need to reuse the object.
|
||||
@ -2428,14 +2630,14 @@ NULL if it is forced to suspend; a non-NULL return value indicates successful
|
||||
completion. You need not test for a NULL return value when using a
|
||||
non-suspending data source.
|
||||
|
||||
Each block in the block arrays contains quantized coefficient values in
|
||||
normal array order (not JPEG zigzag order). The block arrays contain only
|
||||
DCT blocks containing real data; any entirely-dummy blocks added to fill out
|
||||
interleaved MCUs at the right or bottom edges of the image are discarded
|
||||
during reading and are not stored in the block arrays. (The size of each
|
||||
block array can be determined from the width_in_blocks and height_in_blocks
|
||||
fields of the component's comp_info entry.) This is also the data format
|
||||
expected by jpeg_write_coefficients().
|
||||
It is also possible to call jpeg_read_coefficients() to obtain access to the
|
||||
decoder's coefficient arrays during a normal decode cycle in buffered-image
|
||||
mode. This frammish might be useful for progressively displaying an incoming
|
||||
image and then re-encoding it without loss. To do this, decode in buffered-
|
||||
image mode as discussed previously, then call jpeg_read_coefficients() after
|
||||
the last jpeg_finish_output() call. The arrays will be available for your use
|
||||
until you call jpeg_finish_decompress().
|
||||
|
||||
|
||||
To write the contents of a JPEG file as DCT coefficients, you must provide
|
||||
the DCT coefficients stored in virtual block arrays. You can either pass
|
||||
@ -2603,8 +2805,55 @@ DOS will require a reboot to recover the memory.) Thus, with these memory
|
||||
managers, it's a good idea to provide a signal handler that will trap any
|
||||
early exit from your program. The handler should call either jpeg_abort()
|
||||
or jpeg_destroy() for any active JPEG objects. A handler is not needed with
|
||||
jmemnobs.c, and shouldn't be necessary with jmemansi.c either, since the C
|
||||
library is supposed to take care of deleting files made with tmpfile().
|
||||
jmemnobs.c, and shouldn't be necessary with jmemansi.c or jmemmac.c either,
|
||||
since the C library is supposed to take care of deleting files made with
|
||||
tmpfile().
|
||||
|
||||
|
||||
Memory usage
|
||||
------------
|
||||
|
||||
Working memory requirements while performing compression or decompression
|
||||
depend on image dimensions, image characteristics (such as colorspace and
|
||||
JPEG process), and operating mode (application-selected options).
|
||||
|
||||
As of v6b, the decompressor requires:
|
||||
1. About 24K in more-or-less-fixed-size data. This varies a bit depending
|
||||
on operating mode and image characteristics (particularly color vs.
|
||||
grayscale), but it doesn't depend on image dimensions.
|
||||
2. Strip buffers (of size proportional to the image width) for IDCT and
|
||||
upsampling results. The worst case for commonly used sampling factors
|
||||
is about 34 bytes * width in pixels for a color image. A grayscale image
|
||||
only needs about 8 bytes per pixel column.
|
||||
3. A full-image DCT coefficient buffer is needed to decode a multi-scan JPEG
|
||||
file (including progressive JPEGs), or whenever you select buffered-image
|
||||
mode. This takes 2 bytes/coefficient. At typical 2x2 sampling, that's
|
||||
3 bytes per pixel for a color image. Worst case (1x1 sampling) requires
|
||||
6 bytes/pixel. For grayscale, figure 2 bytes/pixel.
|
||||
4. To perform 2-pass color quantization, the decompressor also needs a
|
||||
128K color lookup table and a full-image pixel buffer (3 bytes/pixel).
|
||||
This does not count any memory allocated by the application, such as a
|
||||
buffer to hold the final output image.
|
||||
|
||||
The above figures are valid for 8-bit JPEG data precision and a machine with
|
||||
32-bit ints. For 12-bit JPEG data, double the size of the strip buffers and
|
||||
quantization pixel buffer. The "fixed-size" data will be somewhat smaller
|
||||
with 16-bit ints, larger with 64-bit ints. Also, CMYK or other unusual
|
||||
color spaces will require different amounts of space.
|
||||
|
||||
The full-image coefficient and pixel buffers, if needed at all, do not
|
||||
have to be fully RAM resident; you can have the library use temporary
|
||||
files instead when the total memory usage would exceed a limit you set.
|
||||
(But if your OS supports virtual memory, it's probably better to just use
|
||||
jmemnobs and let the OS do the swapping.)
|
||||
|
||||
The compressor's memory requirements are similar, except that it has no need
|
||||
for color quantization. Also, it needs a full-image DCT coefficient buffer
|
||||
if Huffman-table optimization is asked for, even if progressive mode is not
|
||||
requested.
|
||||
|
||||
If you need more detailed information about memory usage in a particular
|
||||
situation, you can enable the MEM_STATS code in jmemmgr.c.
|
||||
|
||||
|
||||
Library compile-time options
|
||||
@ -2613,7 +2862,7 @@ Library compile-time options
|
||||
A number of compile-time options are available by modifying jmorecfg.h.
|
||||
|
||||
The JPEG standard provides for both the baseline 8-bit DCT process and
|
||||
a 12-bit DCT process. 12-bit lossy JPEG is supported if you define
|
||||
a 12-bit DCT process. The IJG code supports 12-bit lossy JPEG if you define
|
||||
BITS_IN_JSAMPLE as 12 rather than 8. Note that this causes JSAMPLE to be
|
||||
larger than a char, so it affects the surrounding application's image data.
|
||||
The sample applications cjpeg and djpeg can support 12-bit mode only for PPM
|
||||
@ -2630,6 +2879,9 @@ Note that a 12-bit library always compresses in Huffman optimization mode,
|
||||
in order to generate valid Huffman tables. This is necessary because our
|
||||
default Huffman tables only cover 8-bit data. If you need to output 12-bit
|
||||
files in one pass, you'll have to supply suitable default Huffman tables.
|
||||
You may also want to supply your own DCT quantization tables; the existing
|
||||
quality-scaling code has been developed for 8-bit use, and probably doesn't
|
||||
generate especially good tables for 12-bit.
|
||||
|
||||
The maximum number of components (color channels) in the image is determined
|
||||
by MAX_COMPONENTS. The JPEG standard allows up to 255 components, but we
|
||||
@ -2646,6 +2898,16 @@ to burn.
|
||||
You can reduce the size of the library by compiling out various optional
|
||||
functions. To do this, undefine xxx_SUPPORTED symbols as necessary.
|
||||
|
||||
You can also save a few K by not having text error messages in the library;
|
||||
the standard error message table occupies about 5Kb. This is particularly
|
||||
reasonable for embedded applications where there's no good way to display
|
||||
a message anyway. To do this, remove the creation of the message table
|
||||
(jpeg_std_message_table[]) from jerror.c, and alter format_message to do
|
||||
something reasonable without it. You could output the numeric value of the
|
||||
message code number, for example. If you do this, you can also save a couple
|
||||
more K by modifying the TRACEMSn() macros in jerror.h to expand to nothing;
|
||||
you don't need trace capability anyway, right?
|
||||
|
||||
|
||||
Portability considerations
|
||||
--------------------------
|
||||
@ -2656,9 +2918,9 @@ the design goals in this area. (If you encounter any bugs that cause the
|
||||
library to be less portable than is claimed here, we'd appreciate hearing
|
||||
about them.)
|
||||
|
||||
The code works fine on both ANSI and pre-ANSI C compilers, using any of the
|
||||
popular system include file setups, and some not-so-popular ones too. See
|
||||
install.doc for configuration procedures.
|
||||
The code works fine on ANSI C, C++, and pre-ANSI C compilers, using any of
|
||||
the popular system include file setups, and some not-so-popular ones too.
|
||||
See install.doc for configuration procedures.
|
||||
|
||||
The code is not dependent on the exact sizes of the C data types. As
|
||||
distributed, we make the assumptions that
|
||||
@ -2735,7 +2997,7 @@ Far data space may also be a tight resource when you are dealing with large
|
||||
images. The most memory-intensive case is decompression with two-pass color
|
||||
quantization, or single-pass quantization to an externally supplied color
|
||||
map. This requires a 128Kb color lookup table plus strip buffers amounting
|
||||
to about 50 bytes per column for typical sampling ratios (eg, about 32000
|
||||
to about 40 bytes per column for typical sampling ratios (eg, about 25600
|
||||
bytes for a 640-pixel-wide image). You may not be able to process wide
|
||||
images if you have large data structures of your own.
|
||||
|
||||
|
@ -63,10 +63,6 @@ DEFFILE=$(DLLNAME).def
|
||||
LCFLAGS = -Zi -GM
|
||||
LINCS = -I$(PUBLIC)/java
|
||||
|
||||
!if "$(MOZ_BITS)"=="32" && defined(MOZ_DEBUG) && defined(GLOWCODE)
|
||||
LLIBS=$(LLIBS) $(GLOWDIR)\glowcode.lib
|
||||
!endif
|
||||
|
||||
#//------------------------------------------------------------------------
|
||||
#//
|
||||
#// Define the files necessary to build the target (ie. OBJS)
|
||||
|
@ -647,9 +647,16 @@ The underlying type is at least a 16-bit signed integer; while "short" is big
|
||||
enough on all machines of interest, on some machines it is preferable to use
|
||||
"int" for speed reasons, despite the storage cost. Coefficients are grouped
|
||||
into 8x8 blocks (but we always use #defines DCTSIZE and DCTSIZE2 rather than
|
||||
"8" and "64"). The contents of a block may be either in "natural" or
|
||||
zigzagged order, and may be true values or divided by the quantization
|
||||
coefficients, depending on where the block is in the processing pipeline.
|
||||
"8" and "64").
|
||||
|
||||
The contents of a coefficient block may be in either "natural" or zigzagged
|
||||
order, and may be true values or divided by the quantization coefficients,
|
||||
depending on where the block is in the processing pipeline. In the current
|
||||
library, coefficient blocks are kept in natural order everywhere; the entropy
|
||||
codecs zigzag or dezigzag the data as it is written or read. The blocks
|
||||
contain quantized coefficients everywhere outside the DCT/IDCT subsystems.
|
||||
(This latter decision may need to be revisited to support variable
|
||||
quantization a la JPEG Part 3.)
|
||||
|
||||
Notice that the allocation unit is now a row of 8x8 blocks, corresponding to
|
||||
eight rows of samples. Otherwise the structure is much the same as for
|
||||
|
139
jpeg/usage.doc
139
jpeg/usage.doc
@ -57,7 +57,7 @@ or
|
||||
This syntax works on all systems, so it is useful for scripts.
|
||||
|
||||
The currently supported image file formats are: PPM (PBMPLUS color format),
|
||||
PGM (PBMPLUS gray-scale format), BMP, GIF, Targa, and RLE (Utah Raster Toolkit
|
||||
PGM (PBMPLUS gray-scale format), BMP, Targa, and RLE (Utah Raster Toolkit
|
||||
format). (RLE is supported only if the URT library is available.)
|
||||
cjpeg recognizes the input image format automatically, with the exception
|
||||
of some Targa-format files. You have to tell djpeg which format to generate.
|
||||
@ -67,7 +67,7 @@ less widely used JPEG-based file formats, but we don't support them.
|
||||
|
||||
All switch names may be abbreviated; for example, -grayscale may be written
|
||||
-gray or -gr. Most of the "basic" switches can be abbreviated to as little as
|
||||
one letter. Upper and lower case are equivalent (-GIF is the same as -gif).
|
||||
one letter. Upper and lower case are equivalent (-BMP is the same as -bmp).
|
||||
British spellings are also accepted (e.g., -greyscale), though for brevity
|
||||
these are not mentioned below.
|
||||
|
||||
@ -82,8 +82,8 @@ The basic command line switches for cjpeg are:
|
||||
|
||||
-grayscale Create monochrome JPEG file from color input.
|
||||
Be sure to use this switch when compressing a grayscale
|
||||
GIF file, because cjpeg isn't bright enough to notice
|
||||
whether a GIF file uses only shades of gray. By
|
||||
BMP file, because cjpeg isn't bright enough to notice
|
||||
whether a BMP file uses only shades of gray. By
|
||||
saying -grayscale, you'll get a smaller JPEG file that
|
||||
takes less time to process.
|
||||
|
||||
@ -177,16 +177,19 @@ restart markers occupy extra space. We recommend -restart 1 for images that
|
||||
will be transmitted across unreliable networks such as Usenet.
|
||||
|
||||
The -smooth option filters the input to eliminate fine-scale noise. This is
|
||||
often useful when converting GIF files to JPEG: a moderate smoothing factor of
|
||||
10 to 50 gets rid of dithering patterns in the input file, resulting in a
|
||||
smaller JPEG file and a better-looking image. Too large a smoothing factor
|
||||
will visibly blur the image, however.
|
||||
often useful when converting dithered images to JPEG: a moderate smoothing
|
||||
factor of 10 to 50 gets rid of dithering patterns in the input file, resulting
|
||||
in a smaller JPEG file and a better-looking image. Too large a smoothing
|
||||
factor will visibly blur the image, however.
|
||||
|
||||
Switches for wizards:
|
||||
|
||||
-baseline Force a baseline JPEG file to be generated. This
|
||||
clamps quantization values to 8 bits even at low
|
||||
quality settings.
|
||||
-baseline Force baseline-compatible quantization tables to be
|
||||
generated. This clamps quantization values to 8 bits
|
||||
even at low quality settings. (This switch is poorly
|
||||
named, since it does not ensure that the output is
|
||||
actually baseline JPEG. For example, you can use
|
||||
-baseline and -progressive together.)
|
||||
|
||||
-qtables file Use the quantization tables given in the specified
|
||||
text file.
|
||||
@ -329,6 +332,10 @@ quality settings to make very small JPEG files; the percentage improvement
|
||||
is often a lot more than it is on larger files. (At present, -optimize
|
||||
mode is always selected when generating progressive JPEG files.)
|
||||
|
||||
GIF input files are no longer supported, to avoid the Unisys LZW patent.
|
||||
Use a Unisys-licensed program if you need to read a GIF file. (Conversion
|
||||
of GIF files to JPEG is usually a bad idea anyway.)
|
||||
|
||||
|
||||
HINTS FOR DJPEG
|
||||
|
||||
@ -354,6 +361,9 @@ it may run out of memory even with -maxmemory 0. In that case you can still
|
||||
decompress, with some loss of image quality, by specifying -onepass for
|
||||
one-pass quantization.
|
||||
|
||||
To avoid the Unisys LZW patent, djpeg produces uncompressed GIF files. These
|
||||
are larger than they should be, but are readable by standard GIF decoders.
|
||||
|
||||
|
||||
HINTS FOR BOTH PROGRAMS
|
||||
|
||||
@ -390,27 +400,104 @@ and do not need you to specify -maxmemory.
|
||||
|
||||
JPEGTRAN
|
||||
|
||||
jpegtran translates JPEG files from one variant of JPEG to another, for
|
||||
example from baseline JPEG to progressive JPEG or vice versa. The
|
||||
transformation is lossless: no image degradation occurs, which would not
|
||||
be true if you used djpeg followed by cjpeg. However, you cannot alter
|
||||
the image quality, because that would not be a lossless operation.
|
||||
jpegtran performs various useful transformations of JPEG files.
|
||||
It can translate the coded representation from one variant of JPEG to another,
|
||||
for example from baseline JPEG to progressive JPEG or vice versa. It can also
|
||||
perform some rearrangements of the image data, for example turning an image
|
||||
from landscape to portrait format by rotation.
|
||||
|
||||
jpegtran operates similarly to cjpeg, except that it reads a JPEG file
|
||||
and writes another JPEG file.
|
||||
jpegtran works by rearranging the compressed data (DCT coefficients), without
|
||||
ever fully decoding the image. Therefore, its transformations are lossless:
|
||||
there is no image degradation at all, which would not be true if you used
|
||||
djpeg followed by cjpeg to accomplish the same conversion. But by the same
|
||||
token, jpegtran cannot perform lossy operations such as changing the image
|
||||
quality.
|
||||
|
||||
jpegtran uses a command line syntax similar to cjpeg or djpeg.
|
||||
On Unix-like systems, you say:
|
||||
jpegtran [switches] [inputfile] >outputfile
|
||||
On most non-Unix systems, you say:
|
||||
jpegtran [switches] inputfile outputfile
|
||||
where both the input and output files are JPEG files.
|
||||
|
||||
To specify the coded JPEG representation used in the output file,
|
||||
jpegtran accepts a subset of the switches recognized by cjpeg:
|
||||
-optimize Perform optimization of entropy encoding parameters.
|
||||
-progressive Create progressive JPEG file.
|
||||
-restart N Emit a JPEG restart marker every N MCU rows, or every
|
||||
N MCU blocks if "B" is attached to the number.
|
||||
-scans file Use the scan script given in the specified text file.
|
||||
See the previous discussion of cjpeg for more details about these switches.
|
||||
If you specify none of these switches, you get a plain baseline-JPEG output
|
||||
file. The quality setting and so forth are determined by the input file.
|
||||
|
||||
The image can be losslessly transformed by giving one of these switches:
|
||||
-flip horizontal Mirror image horizontally (left-right).
|
||||
-flip vertical Mirror image vertically (top-bottom).
|
||||
-rotate 90 Rotate image 90 degrees clockwise.
|
||||
-rotate 180 Rotate image 180 degrees.
|
||||
-rotate 270 Rotate image 270 degrees clockwise (or 90 ccw).
|
||||
-transpose Transpose image (across UL-to-LR axis).
|
||||
-transverse Transverse transpose (across UR-to-LL axis).
|
||||
|
||||
The transpose transformation has no restrictions regarding image dimensions.
|
||||
The other transformations operate rather oddly if the image dimensions are not
|
||||
a multiple of the iMCU size (usually 8 or 16 pixels), because they can only
|
||||
transform complete blocks of DCT coefficient data in the desired way.
|
||||
|
||||
jpegtran's default behavior when transforming an odd-size image is designed
|
||||
to preserve exact reversibility and mathematical consistency of the
|
||||
transformation set. As stated, transpose is able to flip the entire image
|
||||
area. Horizontal mirroring leaves any partial iMCU column at the right edge
|
||||
untouched, but is able to flip all rows of the image. Similarly, vertical
|
||||
mirroring leaves any partial iMCU row at the bottom edge untouched, but is
|
||||
able to flip all columns. The other transforms can be built up as sequences
|
||||
of transpose and flip operations; for consistency, their actions on edge
|
||||
pixels are defined to be the same as the end result of the corresponding
|
||||
transpose-and-flip sequence.
|
||||
|
||||
For practical use, you may prefer to discard any untransformable edge pixels
|
||||
rather than having a strange-looking strip along the right and/or bottom edges
|
||||
of a transformed image. To do this, add the -trim switch:
|
||||
-trim Drop non-transformable edge blocks.
|
||||
Obviously, a transformation with -trim is not reversible, so strictly speaking
|
||||
jpegtran with this switch is not lossless. Also, the expected mathematical
|
||||
equivalences between the transformations no longer hold. For example,
|
||||
"-rot 270 -trim" trims only the bottom edge, but "-rot 90 -trim" followed by
|
||||
"-rot 180 -trim" trims both edges.
|
||||
|
||||
Another not-strictly-lossless transformation switch is:
|
||||
-grayscale Force grayscale output.
|
||||
This option discards the chrominance channels if the input image is YCbCr
|
||||
(ie, a standard color JPEG), resulting in a grayscale JPEG file. The
|
||||
luminance channel is preserved exactly, so this is a better method of reducing
|
||||
to grayscale than decompression, conversion, and recompression. This switch
|
||||
is particularly handy for fixing a monochrome picture that was mistakenly
|
||||
encoded as a color JPEG. (In such a case, the space savings from getting rid
|
||||
of the near-empty chroma channels won't be large; but the decoding time for
|
||||
a grayscale JPEG is substantially less than that for a color JPEG.)
|
||||
|
||||
jpegtran also recognizes these switches that control what to do with "extra"
|
||||
markers, such as comment blocks:
|
||||
-copy none Copy no extra markers from source file. This setting
|
||||
suppresses all comments and other excess baggage
|
||||
present in the source file.
|
||||
-copy comments Copy only comment markers. This setting copies
|
||||
comments from the source file, but discards
|
||||
any other inessential data.
|
||||
-copy all Copy all extra markers. This setting preserves
|
||||
miscellaneous markers found in the source file, such
|
||||
as JFIF thumbnails and Photoshop settings. In some
|
||||
files these extra markers can be sizable.
|
||||
The default behavior is -copy comments. (Note: in IJG releases v6 and v6a,
|
||||
jpegtran always did the equivalent of -copy none.)
|
||||
|
||||
Additional switches recognized by jpegtran are:
|
||||
-outfile filename
|
||||
-optimize
|
||||
-progressive
|
||||
-restart N
|
||||
-scans file
|
||||
-maxmemory N
|
||||
-verbose
|
||||
-debug
|
||||
See the previous discussion of cjpeg for details about these switches.
|
||||
|
||||
If you specify no switches, you get a plain baseline-JPEG output file.
|
||||
These work the same as in cjpeg or djpeg.
|
||||
|
||||
|
||||
THE COMMENT UTILITIES
|
||||
@ -454,7 +541,7 @@ where both input and output file names must be given explicitly.
|
||||
wrjpgcom understands three switches:
|
||||
-replace Delete any existing COM blocks from the file.
|
||||
-comment "Comment text" Supply new COM text on command line.
|
||||
-cfile name Read text for new COM block from named file.
|
||||
-cfile name Read text for new COM block from named file.
|
||||
(Switch names can be abbreviated.) If you have only one line of comment text
|
||||
to add, you can provide it on the command line with -comment. The comment
|
||||
text must be surrounded with quotes so that it is treated as a single
|
||||
|
@ -137,14 +137,18 @@ JPEG SOF marker, with the first component being numbered 0. (Note that these
|
||||
indexes are not the "component ID" codes assigned to the components, just
|
||||
positional indexes.)
|
||||
|
||||
If the progression parameters Ss,Se,Ah,Al are omitted, the values 0,63,0,0
|
||||
are used, producing a sequential JPEG file. cjpeg automatically determines
|
||||
whether the script represents a progressive or sequential file, by observing
|
||||
whether Ss and Se values other than 0 and 63 appear. (The -progressive
|
||||
switch is unnecessary and is ignored when -scans appears.) When specifying
|
||||
progression parameters, the user must follow the JPEG restrictions on
|
||||
progression parameters. (cjpeg checks that the spec's requirements are
|
||||
obeyed.)
|
||||
The progression parameters for each scan are:
|
||||
Ss Zigzag index of first coefficient included in scan
|
||||
Se Zigzag index of last coefficient included in scan
|
||||
Ah Zero for first scan of a coefficient, else Al of prior scan
|
||||
Al Successive approximation low bit position for scan
|
||||
If the progression parameters are omitted, the values 0,63,0,0 are used,
|
||||
producing a sequential JPEG file. cjpeg automatically determines whether
|
||||
the script represents a progressive or sequential file, by observing whether
|
||||
Ss and Se values other than 0 and 63 appear. (The -progressive switch is
|
||||
not needed to specify this; in fact, it is ignored when -scans appears.)
|
||||
The scan script must meet the JPEG restrictions on progression sequences.
|
||||
(cjpeg checks that the spec's requirements are obeyed.)
|
||||
|
||||
Scan script files are free format, in that arbitrary whitespace can appear
|
||||
between numbers and around punctuation. Also, comments can be included: a
|
||||
|
Loading…
Reference in New Issue
Block a user